VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Driver/DriveFilter.c
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2019-02-08 00:48:12 (GMT)
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2019-02-08 00:50:12 (GMT)
commitba5da0946c3abaa93d1161ca512c3c326cda3736 (patch)
tree128c238dea40ac0de0c7de8e0b02810eabc8e564 /src/Driver/DriveFilter.c
parente5b9cee8681dc45340321f759079b344a3b2676c (diff)
downloadVeraCrypt-ba5da0946c3abaa93d1161ca512c3c326cda3736.zip
VeraCrypt-ba5da0946c3abaa93d1161ca512c3c326cda3736.tar.gz
Windows: Add implementation of ChaCha20 based random generator. Use it for driver need of random bytes (currently only wipe bytes but more to come later).
Diffstat (limited to 'src/Driver/DriveFilter.c')
-rw-r--r--src/Driver/DriveFilter.c42
1 files changed, 9 insertions, 33 deletions
diff --git a/src/Driver/DriveFilter.c b/src/Driver/DriveFilter.c
index 6228009..3c7687f 100644
--- a/src/Driver/DriveFilter.c
+++ b/src/Driver/DriveFilter.c
@@ -29,6 +29,7 @@
#include "Boot/Windows/BootCommon.h"
#include "cpu.h"
#include "rdrand.h"
+#include "chachaRng.h"
static BOOL DeviceFilterActive = FALSE;
@@ -1521,42 +1522,17 @@ 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
+ ChaCha20RngCtx rngCtx;
+ byte pbSeed[CHACHA20RNG_KEYSZ + CHACHA20RNG_IVSZ];
- KeQuerySystemTime( &iSeed );
- WHIRLPOOL_init (&tctx);
- WHIRLPOOL_add ((unsigned char *) &(iSeed.QuadPart), sizeof(iSeed.QuadPart), &tctx);
- // use RDSEED or RDRAND from CPU as source of entropy if enabled
- if ( IsCpuRngEnabled() &&
- ( (HasRDSEED() && RDSEED_getBytes (digest, sizeof (digest)))
- || (HasRDRAND() && RDRAND_getBytes (digest, sizeof (digest)))
- ))
- {
- WHIRLPOOL_add (digest, sizeof(digest), &tctx);
- }
- WHIRLPOOL_finalize (&tctx, digest);
+ GetDriverRandomSeed (pbSeed, sizeof (pbSeed));
+ ChaCha20RngInit (&rngCtx, pbSeed, GetDriverRandomSeed, 0);
-#if !defined (_WIN64)
- if (NT_SUCCESS (saveStatus))
- KeRestoreFloatingPointState (&floatingPointState);
-#endif
-
- memcpy (wipeRandChars, digest, TC_WIPE_RAND_CHAR_COUNT);
- memcpy (wipeRandCharsUpdate, &digest[WHIRLPOOL_DIGESTSIZE - TC_WIPE_RAND_CHAR_COUNT], TC_WIPE_RAND_CHAR_COUNT);
+ ChaCha20RngGetBytes (&rngCtx, wipeRandChars, TC_WIPE_RAND_CHAR_COUNT);
+ ChaCha20RngGetBytes (&rngCtx, wipeRandCharsUpdate, TC_WIPE_RAND_CHAR_COUNT);
- burn (digest, WHIRLPOOL_DIGESTSIZE);
- burn (&tctx, sizeof (tctx));
-
- burn (&iSeed, sizeof(iSeed));
+ burn (&rngCtx, sizeof (rngCtx));
+ FAST_ERASE64 (pbSeed, sizeof (pbSeed));
SetupResult = STATUS_UNSUCCESSFUL;