VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/Random.c
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2019-01-31 00:05:19 (GMT)
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2019-01-31 23:35:50 (GMT)
commit61c1baa4bf5a97675187a37cf203e1937a060daa (patch)
treedbf4cba079f6497740fecd325b22bf47f6a03731 /src/Common/Random.c
parent915855f43b6bd30c2e01a49e261f813ccc7a0237 (diff)
downloadVeraCrypt-61c1baa4bf5a97675187a37cf203e1937a060daa.zip
VeraCrypt-61c1baa4bf5a97675187a37cf203e1937a060daa.tar.gz
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 6c95cf6..12e9d9a 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();