1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-12 19:38:26 -06:00

Use properly aligned memory in code using Streebog hash implementation that uses SSE.

This commit is contained in:
Mounir IDRASSI
2016-09-28 00:14:05 +02:00
parent 3e029b0dde
commit 57ce7aab7b
7 changed files with 65 additions and 23 deletions

View File

@@ -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
}
}