From 57ce7aab7be0ca2c3e990eaf7d9cf3691efd1ea0 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Wed, 28 Sep 2016 00:14:05 +0200 Subject: Use properly aligned memory in code using Streebog hash implementation that uses SSE. --- src/Platform/Memory.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/Platform/Memory.cpp') 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 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 + } } -- cgit v1.2.3