VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Driver/DriveFilter.c
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2019-01-31 00:10:38 (GMT)
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2019-01-31 23:36:19 (GMT)
commit5571a8ba6b258decb9c9a109d3a8562e3d2ea5fa (patch)
treef5e52ea212bb8e2a9cec5e0b8ea532e6b8cce494 /src/Driver/DriveFilter.c
parent61c1baa4bf5a97675187a37cf203e1937a060daa (diff)
downloadVeraCrypt-5571a8ba6b258decb9c9a109d3a8562e3d2ea5fa.zip
VeraCrypt-5571a8ba6b258decb9c9a109d3a8562e3d2ea5fa.tar.gz
Windows driver: better randomness for wipe bytes by always using Whirlpool hash of current time and random bytes retrieved using CPU RDRAND/RDSEED if available.
Diffstat (limited to 'src/Driver/DriveFilter.c')
-rw-r--r--src/Driver/DriveFilter.c47
1 files changed, 28 insertions, 19 deletions
diff --git a/src/Driver/DriveFilter.c b/src/Driver/DriveFilter.c
index c17410d..a02ca3e 100644
--- a/src/Driver/DriveFilter.c
+++ b/src/Driver/DriveFilter.c
@@ -28,6 +28,7 @@
#include "DriveFilter.h"
#include "Boot/Windows/BootCommon.h"
#include "cpu.h"
+#include "rdrand.h"
static BOOL DeviceFilterActive = FALSE;
@@ -1521,30 +1522,38 @@ static VOID SetupThreadProc (PVOID threadArg)
// generate real random values for wipeRandChars and
// wipeRandCharsUpdate instead of relying on uninitialized stack memory
LARGE_INTEGER iSeed;
+ byte digest[WHIRLPOOL_DIGESTSIZE];
+ WHIRLPOOL_CTX tctx;
+
+#ifndef _WIN64
+ KFLOATING_SAVE floatingPointState;
+ NTSTATUS saveStatus = STATUS_INVALID_PARAMETER;
+ if (HasISSE())
+ saveStatus = KeSaveFloatingPointState (&floatingPointState);
+#endif
+
KeQuerySystemTime( &iSeed );
- if (KeGetCurrentIrql() < DISPATCH_LEVEL)
+ WHIRLPOOL_init (&tctx);
+ WHIRLPOOL_add ((unsigned char *) &(iSeed.QuadPart), sizeof(iSeed.QuadPart), &tctx);
+ // use RDSEED or RDRAND from CPU as source of entropy if present
+ if ( (HasRDSEED() && RDSEED_getBytes (digest, sizeof (digest)))
+ || (HasRDRAND() && RDRAND_getBytes (digest, sizeof (digest)))
+ )
{
- ULONG ulRandom;
- ulRandom = RtlRandomEx( &iSeed.LowPart );
- memcpy (wipeRandChars, &ulRandom, TC_WIPE_RAND_CHAR_COUNT);
- ulRandom = RtlRandomEx( &ulRandom );
- memcpy (wipeRandCharsUpdate, &ulRandom, TC_WIPE_RAND_CHAR_COUNT);
- burn (&ulRandom, sizeof(ulRandom));
+ WHIRLPOOL_add (digest, sizeof(digest), &tctx);
}
- else
- {
- byte digest[SHA512_DIGESTSIZE];
- sha512_ctx tctx;
- sha512_begin (&tctx);
- sha512_hash ((unsigned char *) &(iSeed.QuadPart), sizeof(iSeed.QuadPart), &tctx);
- sha512_end (digest, &tctx);
+ WHIRLPOOL_finalize (&tctx, digest);
+
+#if !defined (_WIN64)
+ if (NT_SUCCESS (saveStatus))
+ KeRestoreFloatingPointState (&floatingPointState);
+#endif
- memcpy (wipeRandChars, digest, TC_WIPE_RAND_CHAR_COUNT);
- memcpy (wipeRandCharsUpdate, &digest[SHA512_DIGESTSIZE - TC_WIPE_RAND_CHAR_COUNT], TC_WIPE_RAND_CHAR_COUNT);
+ memcpy (wipeRandChars, digest, TC_WIPE_RAND_CHAR_COUNT);
+ memcpy (wipeRandCharsUpdate, &digest[WHIRLPOOL_DIGESTSIZE - TC_WIPE_RAND_CHAR_COUNT], TC_WIPE_RAND_CHAR_COUNT);
- burn (digest, SHA512_DIGESTSIZE);
- burn (&tctx, sizeof (tctx));
- }
+ burn (digest, WHIRLPOOL_DIGESTSIZE);
+ burn (&tctx, sizeof (tctx));
burn (&iSeed, sizeof(iSeed));