mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 11:08:02 -06:00
Linux/MacOSX: Add missing JitterEntropy implementation
This commit is contained in:
@@ -46,6 +46,16 @@ namespace VeraCrypt
|
|||||||
|
|
||||||
throw_sys_sub_if (read (random, buffer, buffer.Size()) == -1 && errno != EAGAIN, L"/dev/random");
|
throw_sys_sub_if (read (random, buffer, buffer.Size()) == -1 && errno != EAGAIN, L"/dev/random");
|
||||||
AddToPool (buffer);
|
AddToPool (buffer);
|
||||||
|
|
||||||
|
/* use JitterEntropy library to get good quality random bytes based on CPU timing jitter */
|
||||||
|
if (JitterRngCtx)
|
||||||
|
{
|
||||||
|
ssize_t rndLen = jent_read_entropy (JitterRngCtx, (char*) buffer.Ptr(), buffer.Size());
|
||||||
|
if (rndLen > 0)
|
||||||
|
{
|
||||||
|
AddToPool (buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -81,6 +91,12 @@ namespace VeraCrypt
|
|||||||
size_t bufferLen = buffer.Size(), loopLen;
|
size_t bufferLen = buffer.Size(), loopLen;
|
||||||
byte* pbBuffer = buffer.Get();
|
byte* pbBuffer = buffer.Get();
|
||||||
|
|
||||||
|
// Initialize JitterEntropy RNG for this call
|
||||||
|
if (0 == jent_entropy_init ())
|
||||||
|
{
|
||||||
|
JitterRngCtx = jent_entropy_collector_alloc (1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
// Poll system for data
|
// Poll system for data
|
||||||
AddSystemDataToPool (fast);
|
AddSystemDataToPool (fast);
|
||||||
HashMixPool();
|
HashMixPool();
|
||||||
@@ -127,6 +143,12 @@ namespace VeraCrypt
|
|||||||
|
|
||||||
pbBuffer += loopLen;
|
pbBuffer += loopLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (JitterRngCtx)
|
||||||
|
{
|
||||||
|
jent_entropy_collector_free (JitterRngCtx);
|
||||||
|
JitterRngCtx = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr <Hash> RandomNumberGenerator::GetHash ()
|
shared_ptr <Hash> RandomNumberGenerator::GetHash ()
|
||||||
@@ -232,4 +254,5 @@ namespace VeraCrypt
|
|||||||
size_t RandomNumberGenerator::ReadOffset;
|
size_t RandomNumberGenerator::ReadOffset;
|
||||||
bool RandomNumberGenerator::Running = false;
|
bool RandomNumberGenerator::Running = false;
|
||||||
size_t RandomNumberGenerator::WriteOffset;
|
size_t RandomNumberGenerator::WriteOffset;
|
||||||
|
struct rand_data *RandomNumberGenerator::JitterRngCtx = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "Platform/Platform.h"
|
#include "Platform/Platform.h"
|
||||||
#include "Volume/Hash.h"
|
#include "Volume/Hash.h"
|
||||||
#include "Common/Random.h"
|
#include "Common/Random.h"
|
||||||
|
#include "Crypto/jitterentropy.h"
|
||||||
|
|
||||||
namespace VeraCrypt
|
namespace VeraCrypt
|
||||||
{
|
{
|
||||||
@@ -53,6 +54,7 @@ namespace VeraCrypt
|
|||||||
static size_t ReadOffset;
|
static size_t ReadOffset;
|
||||||
static bool Running;
|
static bool Running;
|
||||||
static size_t WriteOffset;
|
static size_t WriteOffset;
|
||||||
|
static struct rand_data *JitterRngCtx;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ static VC_INLINE void jent_get_nstime(__u64 *out)
|
|||||||
#define EAX_EDX_RET(val, low, high) "=A" (val)
|
#define EAX_EDX_RET(val, low, high) "=A" (val)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static VC_INLINE void jent_get_nstime(__u64 *out)
|
VC_INLINE void jent_get_nstime(__u64 *out)
|
||||||
{
|
{
|
||||||
DECLARE_ARGS(val, low, high);
|
DECLARE_ARGS(val, low, high);
|
||||||
asm volatile("rdtsc" : EAX_EDX_RET(val, low, high));
|
asm volatile("rdtsc" : EAX_EDX_RET(val, low, high));
|
||||||
@@ -97,7 +97,10 @@ static VC_INLINE void jent_get_nstime(__u64 *out)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static VC_INLINE void *jent_zalloc(size_t len)
|
#ifdef _MSC_VER
|
||||||
|
static
|
||||||
|
#endif
|
||||||
|
VC_INLINE void *jent_zalloc(size_t len)
|
||||||
{
|
{
|
||||||
void *tmp = NULL;
|
void *tmp = NULL;
|
||||||
tmp = TCalloc(len);
|
tmp = TCalloc(len);
|
||||||
@@ -111,7 +114,10 @@ static VC_INLINE void *jent_zalloc(size_t len)
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VC_INLINE void jent_zfree(void *ptr, unsigned int len)
|
#ifdef _MSC_VER
|
||||||
|
static
|
||||||
|
#endif
|
||||||
|
VC_INLINE void jent_zfree(void *ptr, unsigned int len)
|
||||||
{
|
{
|
||||||
if (len % 8)
|
if (len % 8)
|
||||||
burn(ptr, len);
|
burn(ptr, len);
|
||||||
@@ -123,7 +129,10 @@ static VC_INLINE void jent_zfree(void *ptr, unsigned int len)
|
|||||||
TCfree(ptr);
|
TCfree(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VC_INLINE int jent_fips_enabled(void)
|
#ifdef _MSC_VER
|
||||||
|
static
|
||||||
|
#endif
|
||||||
|
VC_INLINE int jent_fips_enabled(void)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ OBJS += ../Crypto/GostCipher.o
|
|||||||
OBJS += ../Crypto/Streebog.o
|
OBJS += ../Crypto/Streebog.o
|
||||||
OBJS += ../Crypto/kuznyechik.o
|
OBJS += ../Crypto/kuznyechik.o
|
||||||
OBJS += ../Crypto/kuznyechik_simd.o
|
OBJS += ../Crypto/kuznyechik_simd.o
|
||||||
|
OBJS += ../Crypto/jitterentropy-base.o
|
||||||
|
|
||||||
OBJS += ../Common/Crc.o
|
OBJS += ../Common/Crc.o
|
||||||
OBJS += ../Common/Endian.o
|
OBJS += ../Common/Endian.o
|
||||||
|
|||||||
Reference in New Issue
Block a user