VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Platform/Memory.cpp
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2016-09-28 00:14:05 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2016-10-17 18:40:19 +0200
commit57ce7aab7be0ca2c3e990eaf7d9cf3691efd1ea0 (patch)
tree3cfd2715c14b191f2817f1bac60f8236a12cb870 /src/Platform/Memory.cpp
parent3e029b0dde5326a4f1221c86a2050aafceaafa3e (diff)
downloadVeraCrypt-57ce7aab7be0ca2c3e990eaf7d9cf3691efd1ea0.tar.gz
VeraCrypt-57ce7aab7be0ca2c3e990eaf7d9cf3691efd1ea0.zip
Use properly aligned memory in code using Streebog hash implementation that uses SSE.
Diffstat (limited to 'src/Platform/Memory.cpp')
-rw-r--r--src/Platform/Memory.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/Platform/Memory.cpp b/src/Platform/Memory.cpp
index c8c04766..1184d466 100644
--- a/src/Platform/Memory.cpp
+++ b/src/Platform/Memory.cpp
@@ -13,6 +13,7 @@
#include "Common/Tcdefs.h"
#include "Memory.h"
#include "Exception.h"
+#include <stdlib.h>
namespace VeraCrypt
{
@@ -27,6 +28,23 @@ namespace VeraCrypt
return bufPtr;
}
+
+ void *Memory::AllocateAligned (std::size_t size, std::size_t alignment)
+ {
+ if (size < 1)
+ throw ParameterIncorrect (SRC_POS);
+#ifdef TC_WINDOWS
+ void *bufPtr = _aligned_malloc (size, alignment);
+#else
+ void *bufPtr = NULL;
+ if (0 != posix_memalign (&bufPtr, alignment, size))
+ bufPtr = NULL;
+#endif
+ if (!bufPtr)
+ throw bad_alloc();
+
+ return bufPtr;
+ }
int Memory::Compare (const void *memory1, size_t size1, const void *memory2, size_t size2)
{
@@ -59,4 +77,14 @@ namespace VeraCrypt
assert (memory != nullptr);
free (memory);
}
+
+ void Memory::FreeAligned (void *memory)
+ {
+ assert (memory != nullptr);
+#ifdef TC_WINDOWS
+ _aligned_free (memory);
+#else
+ free (memory);
+#endif
+ }
}