VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/Random.c
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2019-01-31 01:05:19 +0100
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2019-02-01 00:35:50 +0100
commit61c1baa4bf5a97675187a37cf203e1937a060daa (patch)
treedbf4cba079f6497740fecd325b22bf47f6a03731 /src/Common/Random.c
parent915855f43b6bd30c2e01a49e261f813ccc7a0237 (diff)
downloadVeraCrypt-61c1baa4bf5a97675187a37cf203e1937a060daa.tar.gz
VeraCrypt-61c1baa4bf5a97675187a37cf203e1937a060daa.zip
Windows: use CPU RDRAND or RDSEED as an additional entropy source for our random generator when available
Diffstat (limited to 'src/Common/Random.c')
-rw-r--r--src/Common/Random.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/Common/Random.c b/src/Common/Random.c
index 6c95cf6a..12e9d9af 100644
--- a/src/Common/Random.c
+++ b/src/Common/Random.c
@@ -14,6 +14,8 @@
#include "Tcdefs.h"
#include "Crc.h"
#include "Random.h"
+#include "Crypto\cpu.h"
+#include "Crypto\rdrand.h"
#include <Strsafe.h>
static unsigned __int8 buffer[RNG_POOL_SIZE];
@@ -766,10 +768,6 @@ BOOL SlowPoll (void)
if (CryptGenRandom (hCryptProv, sizeof (buffer), buffer))
{
RandaddBuf (buffer, sizeof (buffer));
-
- burn(buffer, sizeof (buffer));
- Randmix();
- return TRUE;
}
else
{
@@ -777,6 +775,19 @@ BOOL SlowPoll (void)
CryptoAPILastError = GetLastError ();
return FALSE;
}
+
+ // use RDSEED or RDRAND from CPU as source of entropy if present
+ if ( (HasRDSEED() && RDSEED_getBytes (buffer, sizeof (buffer)))
+ || (HasRDRAND() && RDRAND_getBytes (buffer, sizeof (buffer)))
+ )
+ {
+ RandaddBuf (buffer, sizeof (buffer));
+ }
+
+ burn(buffer, sizeof (buffer));
+ Randmix();
+
+ return TRUE;
}
@@ -888,7 +899,6 @@ BOOL FastPoll (void)
if (CryptGenRandom (hCryptProv, sizeof (buffer), buffer))
{
RandaddBuf (buffer, sizeof (buffer));
- burn (buffer, sizeof(buffer));
}
else
{
@@ -897,6 +907,16 @@ BOOL FastPoll (void)
return FALSE;
}
+ // use RDSEED or RDRAND from CPU as source of entropy if present
+ if ( (HasRDSEED() && RDSEED_getBytes (buffer, sizeof (buffer)))
+ || (HasRDRAND() && RDRAND_getBytes (buffer, sizeof (buffer)))
+ )
+ {
+ RandaddBuf (buffer, sizeof (buffer));
+ }
+
+ burn (buffer, sizeof(buffer));
+
/* Apply the pool mixing function */
Randmix();