From 86f0fde6e7914f055c5872bf7f2f565cc09977fc Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Tue, 12 Feb 2019 18:49:12 +0100 Subject: 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) --- src/Driver/Driver.vcxproj | 1 + src/Driver/Driver.vcxproj.filters | 3 +++ src/Driver/Ntdriver.c | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) (limited to 'src/Driver') diff --git a/src/Driver/Driver.vcxproj b/src/Driver/Driver.vcxproj index 7104be84..5744934b 100644 --- a/src/Driver/Driver.vcxproj +++ b/src/Driver/Driver.vcxproj @@ -196,6 +196,7 @@ BuildDriver.cmd -rebuild -debug -x64 "$(SolutionDir)\Common" "$(SolutionDir)\Cry + diff --git a/src/Driver/Driver.vcxproj.filters b/src/Driver/Driver.vcxproj.filters index 20227b48..a6f5da3c 100644 --- a/src/Driver/Driver.vcxproj.filters +++ b/src/Driver/Driver.vcxproj.filters @@ -123,6 +123,9 @@ Source Files\Crypto + + Source Files\Crypto + diff --git a/src/Driver/Ntdriver.c b/src/Driver/Ntdriver.c index 9719c91b..ba2de477 100644 --- a/src/Driver/Ntdriver.c +++ b/src/Driver/Ntdriver.c @@ -32,6 +32,7 @@ #include "VolumeFilter.h" #include "cpu.h" #include "rdrand.h" +#include "jitterentropy.h" #include #include @@ -162,7 +163,7 @@ void GetDriverRandomSeed (unsigned char* pbRandSeed, size_t cbRandSeed) while (cbRandSeed) { WHIRLPOOL_init (&tctx); - // we hash current content of digest buffer which is initialized the first time + // we hash current content of digest buffer which is uninitialized the first time WHIRLPOOL_add (digest, WHIRLPOOL_DIGESTSIZE, &tctx); // we use various time information as source of entropy @@ -174,6 +175,19 @@ void GetDriverRandomSeed (unsigned char* pbRandSeed, size_t cbRandSeed) iSeed.QuadPart = KeQueryInterruptTime (); WHIRLPOOL_add ((unsigned char *) &(iSeed.QuadPart), sizeof(iSeed.QuadPart), &tctx); + /* 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*) digest, sizeof (digest)); + if (rndLen > 0) + WHIRLPOOL_add (digest, (unsigned int) rndLen, &tctx); + jent_entropy_collector_free (ec); + } + } + // use RDSEED or RDRAND from CPU as source of entropy if enabled if ( IsCpuRngEnabled() && ( (HasRDSEED() && RDSEED_getBytes (digest, sizeof (digest))) -- cgit v1.2.3