diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/random.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/random.c b/src/random.c index 5057a62..d474a53 100644 --- a/src/random.c +++ b/src/random.c @@ -168,16 +168,10 @@ If we cannot get good randomness, we fall back to weak randomness based on a tim #if defined(_WIN32) -#if !defined(MI_USE_RTLGENRANDOM) -// We prefer to use BCryptGenRandom instead of RtlGenRandom but it can lead to a deadlock -// under the VS debugger when using dynamic overriding. -#pragma comment (lib,"bcrypt.lib") -#include <bcrypt.h> -static bool os_random_buf(void* buf, size_t buf_len) { - return (BCryptGenRandom(NULL, (PUCHAR)buf, (ULONG)buf_len, BCRYPT_USE_SYSTEM_PREFERRED_RNG) >= 0); -} -#else -// Use (unofficial) RtlGenRandom +#if defined(MI_USE_RTLGENRANDOM) || defined(__cplusplus) +// We prefer to use BCryptGenRandom instead of (the unofficial) RtlGenRandom but when using +// dynamic overriding, we observed it can raise an exception when compiled with C++, and +// sometimes deadlocks when also running under the VS debugger. #pragma comment (lib,"advapi32.lib") #define RtlGenRandom SystemFunction036 #ifdef __cplusplus @@ -190,6 +184,12 @@ BOOLEAN NTAPI RtlGenRandom(PVOID RandomBuffer, ULONG RandomBufferLength); static bool os_random_buf(void* buf, size_t buf_len) { return (RtlGenRandom(buf, (ULONG)buf_len) != 0); } +#else +#pragma comment (lib,"bcrypt.lib") +#include <bcrypt.h> +static bool os_random_buf(void* buf, size_t buf_len) { + return (BCryptGenRandom(NULL, (PUCHAR)buf, (ULONG)buf_len, BCRYPT_USE_SYSTEM_PREFERRED_RNG) >= 0); +} #endif #elif defined(__APPLE__) |