VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2019-02-12 18:49:12 +0100
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2019-02-12 19:06:14 +0100
commit86f0fde6e7914f055c5872bf7f2f565cc09977fc (patch)
treefea427f46509ccaa1cb77ec233cb2ab41157576e /src/Common
parenta5943c07fbc2754e0785cfa3d4645e96ae87b405 (diff)
downloadVeraCrypt-86f0fde6e7914f055c5872bf7f2f565cc09977fc.tar.gz
VeraCrypt-86f0fde6e7914f055c5872bf7f2f565cc09977fc.zip
Windows: Use Hardware RNG based on CPU timing jitter "Jitterentropy" by Stephan Mueller as a good alternative to RDRAND (http://www.chronox.de/jent.html, smueller@chronox.de)
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Random.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Common/Random.c b/src/Common/Random.c
index c8655b56..1c6b9530 100644
--- a/src/Common/Random.c
+++ b/src/Common/Random.c
@@ -15,6 +15,7 @@
#include "Crc.h"
#include "Random.h"
#include "Crypto\cpu.h"
+#include "Crypto\jitterentropy.h"
#include "Crypto\rdrand.h"
#include <Strsafe.h>
@@ -776,6 +777,19 @@ BOOL SlowPoll (void)
return FALSE;
}
+ /* use JitterEntropy library to get good quality random bytes based on CPU timing jitter */
+ if (0 == jent_entropy_init ())
+ {
+ struct rand_data *ec = jent_entropy_collector_alloc (1, 0);
+ if (ec)
+ {
+ ssize_t rndLen = jent_read_entropy (ec, (char*) buffer, sizeof (buffer));
+ if (rndLen > 0)
+ RandaddBuf (buffer, (int) rndLen);
+ jent_entropy_collector_free (ec);
+ }
+ }
+
// use RDSEED or RDRAND from CPU as source of entropy if present
if ( IsCpuRngEnabled() &&
( (HasRDSEED() && RDSEED_getBytes (buffer, sizeof (buffer)))
@@ -908,6 +922,19 @@ BOOL FastPoll (void)
return FALSE;
}
+ /* use JitterEntropy library to get good quality random bytes based on CPU timing jitter */
+ if (0 == jent_entropy_init ())
+ {
+ struct rand_data *ec = jent_entropy_collector_alloc (1, 0);
+ if (ec)
+ {
+ ssize_t rndLen = jent_read_entropy (ec, (char*) buffer, sizeof (buffer));
+ if (rndLen > 0)
+ RandaddBuf (buffer, (int) rndLen);
+ jent_entropy_collector_free (ec);
+ }
+ }
+
// use RDSEED or RDRAND from CPU as source of entropy if enabled
if ( IsCpuRngEnabled() &&
( (HasRDSEED() && RDSEED_getBytes (buffer, sizeof (buffer)))