From 761a976d0cafdbc20c32d901eaab6f97a2bd1ee0 Mon Sep 17 00:00:00 2001 From: David Garske Date: Thu, 13 Jul 2023 12:39:34 -0700 Subject: [PATCH] Add support for MemUse Entropy on Windows. --- wolfcrypt/src/random.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index 8658c8e5e..8e850cda9 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -983,6 +983,29 @@ static void Entropy_StopThread(void) } } /* end if defined(HAVE_PTHREAD) */ + +#elif defined(_WIN32) /* USE_WINDOWS_API */ + +/* Get the high resolution time counter. + * + * @return 64-bit time that is the nanoseconds of current time. + */ +static WC_INLINE word64 Entropy_TimeHiRes(void) +{ + static int init = 0; + static LARGE_INTEGER freq; + LARGE_INTEGER count; + + if (!init) { + QueryPerformanceFrequency(&freq); + init = 1; + } + + QueryPerformanceCounter(&count); + + return (word64)(count.QuadPart / (freq.QuadPart / 1000 / 1000)); +} + #else #error "No high precision time available for MemUse Entropy." @@ -1283,7 +1306,7 @@ static int Entropy_HealthTest_Proportion(byte noise) } else { /* Get first value in queue - value to test. */ - byte val = prop_samples[prop_first]; + byte val = (byte)prop_samples[prop_first]; /* Store new sample in queue. */ prop_samples[prop_last] = noise; /* Update first index now that we have removed in from the queue. */