mirror of
https://github.com/veracrypt/VeraCrypt
synced 2024-11-27 21:43:29 +01:00
Windows Driver: Use KeQueryInterruptTimePrecise on Windows 8.1 and newer as better seed for internal RNG compared to KeQueryInterruptTime
This commit is contained in:
parent
5234c479a4
commit
5192eac233
@ -305,6 +305,10 @@ typedef NTSTATUS (NTAPI *ExGetFirmwareEnvironmentVariableFn) (
|
|||||||
PULONG Attributes
|
PULONG Attributes
|
||||||
);
|
);
|
||||||
|
|
||||||
|
typedef ULONG64 (NTAPI *KeQueryInterruptTimePreciseFn)(
|
||||||
|
PULONG64 QpcTimeStamp
|
||||||
|
);
|
||||||
|
|
||||||
typedef BOOLEAN (NTAPI *KeAreAllApcsDisabledFn) ();
|
typedef BOOLEAN (NTAPI *KeAreAllApcsDisabledFn) ();
|
||||||
|
|
||||||
typedef void (NTAPI *KeSetSystemGroupAffinityThreadFn)(
|
typedef void (NTAPI *KeSetSystemGroupAffinityThreadFn)(
|
||||||
|
@ -145,6 +145,7 @@ static BOOL RamEncryptionActivated = FALSE;
|
|||||||
static KeSaveExtendedProcessorStateFn KeSaveExtendedProcessorStatePtr = NULL;
|
static KeSaveExtendedProcessorStateFn KeSaveExtendedProcessorStatePtr = NULL;
|
||||||
static KeRestoreExtendedProcessorStateFn KeRestoreExtendedProcessorStatePtr = NULL;
|
static KeRestoreExtendedProcessorStateFn KeRestoreExtendedProcessorStatePtr = NULL;
|
||||||
static ExGetFirmwareEnvironmentVariableFn ExGetFirmwareEnvironmentVariablePtr = NULL;
|
static ExGetFirmwareEnvironmentVariableFn ExGetFirmwareEnvironmentVariablePtr = NULL;
|
||||||
|
static KeQueryInterruptTimePreciseFn KeQueryInterruptTimePrecisePtr = NULL;
|
||||||
static KeAreAllApcsDisabledFn KeAreAllApcsDisabledPtr = NULL;
|
static KeAreAllApcsDisabledFn KeAreAllApcsDisabledPtr = NULL;
|
||||||
static KeSetSystemGroupAffinityThreadFn KeSetSystemGroupAffinityThreadPtr = NULL;
|
static KeSetSystemGroupAffinityThreadFn KeSetSystemGroupAffinityThreadPtr = NULL;
|
||||||
static KeQueryActiveGroupCountFn KeQueryActiveGroupCountPtr = NULL;
|
static KeQueryActiveGroupCountFn KeQueryActiveGroupCountPtr = NULL;
|
||||||
@ -238,8 +239,17 @@ void GetDriverRandomSeed (unsigned char* pbRandSeed, size_t cbRandSeed)
|
|||||||
iSeed = KeQueryPerformanceCounter (&iSeed2);
|
iSeed = KeQueryPerformanceCounter (&iSeed2);
|
||||||
WHIRLPOOL_add ((unsigned char *) &(iSeed.QuadPart), sizeof(iSeed.QuadPart), &tctx);
|
WHIRLPOOL_add ((unsigned char *) &(iSeed.QuadPart), sizeof(iSeed.QuadPart), &tctx);
|
||||||
WHIRLPOOL_add ((unsigned char *) &(iSeed2.QuadPart), sizeof(iSeed2.QuadPart), &tctx);
|
WHIRLPOOL_add ((unsigned char *) &(iSeed2.QuadPart), sizeof(iSeed2.QuadPart), &tctx);
|
||||||
|
if (KeQueryInterruptTimePrecisePtr)
|
||||||
|
{
|
||||||
|
iSeed.QuadPart = KeQueryInterruptTimePrecisePtr (&iSeed2.QuadPart);
|
||||||
|
WHIRLPOOL_add ((unsigned char *) &(iSeed.QuadPart), sizeof(iSeed.QuadPart), &tctx);
|
||||||
|
WHIRLPOOL_add ((unsigned char *) &(iSeed2.QuadPart), sizeof(iSeed2.QuadPart), &tctx);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
iSeed.QuadPart = KeQueryInterruptTime ();
|
iSeed.QuadPart = KeQueryInterruptTime ();
|
||||||
WHIRLPOOL_add ((unsigned char *) &(iSeed.QuadPart), sizeof(iSeed.QuadPart), &tctx);
|
WHIRLPOOL_add ((unsigned char *) &(iSeed.QuadPart), sizeof(iSeed.QuadPart), &tctx);
|
||||||
|
}
|
||||||
|
|
||||||
/* use JitterEntropy library to get good quality random bytes based on CPU timing jitter */
|
/* use JitterEntropy library to get good quality random bytes based on CPU timing jitter */
|
||||||
if (0 == jent_entropy_init ())
|
if (0 == jent_entropy_init ())
|
||||||
@ -339,6 +349,14 @@ NTSTATUS DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
|
|||||||
ExGetFirmwareEnvironmentVariablePtr = (ExGetFirmwareEnvironmentVariableFn) MmGetSystemRoutineAddress(&funcName);
|
ExGetFirmwareEnvironmentVariablePtr = (ExGetFirmwareEnvironmentVariableFn) MmGetSystemRoutineAddress(&funcName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// KeQueryInterruptTimePrecise is available starting from Windows 8.1
|
||||||
|
if ((OsMajorVersion > 6) || (OsMajorVersion == 6 && OsMinorVersion >= 3))
|
||||||
|
{
|
||||||
|
UNICODE_STRING funcName;
|
||||||
|
RtlInitUnicodeString(&funcName, L"KeQueryInterruptTimePrecise");
|
||||||
|
KeQueryInterruptTimePrecisePtr = (KeQueryInterruptTimePreciseFn) MmGetSystemRoutineAddress(&funcName);
|
||||||
|
}
|
||||||
|
|
||||||
// Load dump filter if the main driver is already loaded
|
// Load dump filter if the main driver is already loaded
|
||||||
if (NT_SUCCESS (TCDeviceIoControl (NT_ROOT_PREFIX, TC_IOCTL_GET_DRIVER_VERSION, NULL, 0, &version, sizeof (version))))
|
if (NT_SUCCESS (TCDeviceIoControl (NT_ROOT_PREFIX, TC_IOCTL_GET_DRIVER_VERSION, NULL, 0, &version, sizeof (version))))
|
||||||
return DumpFilterEntry ((PFILTER_EXTENSION) DriverObject, (PFILTER_INITIALIZATION_DATA) RegistryPath);
|
return DumpFilterEntry ((PFILTER_EXTENSION) DriverObject, (PFILTER_INITIALIZATION_DATA) RegistryPath);
|
||||||
|
Loading…
Reference in New Issue
Block a user