experiment with bcrypt api again

This commit is contained in:
daan 2020-09-06 08:33:27 -07:00
parent e740242978
commit f7b94fe21c
2 changed files with 3 additions and 4 deletions

View File

@ -191,7 +191,7 @@ endif()
# extra needed libraries # extra needed libraries
if(WIN32) if(WIN32)
list(APPEND mi_libraries psapi shell32 user32 advapi32) list(APPEND mi_libraries psapi shell32 user32 advapi32 bcrypt)
else() else()
if(NOT ${CMAKE_C_COMPILER} MATCHES "android") if(NOT ${CMAKE_C_COMPILER} MATCHES "android")
list(APPEND mi_libraries pthread) list(APPEND mi_libraries pthread)

View File

@ -162,14 +162,13 @@ If we cannot get good randomness, we fall back to weak randomness based on a tim
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
#if defined(_WIN32) #if defined(_WIN32)
/*
// We prefer BCryptGenRandom over RtlGenRandom but it leads to a crash a when using dynamic override combined with the C++ runtime :-( // We prefer BCryptGenRandom over RtlGenRandom but it leads to a crash a when using dynamic override combined with the C++ runtime :-(
#pragma comment (lib,"bcrypt.lib") #pragma comment (lib,"bcrypt.lib")
#include <bcrypt.h> #include <bcrypt.h>
static bool os_random_buf(void* buf, size_t buf_len) { 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); return (BCryptGenRandom(NULL, (PUCHAR)buf, (ULONG)buf_len, BCRYPT_USE_SYSTEM_PREFERRED_RNG) >= 0);
} }
*/ /*
#pragma comment (lib,"advapi32.lib") #pragma comment (lib,"advapi32.lib")
#define RtlGenRandom SystemFunction036 #define RtlGenRandom SystemFunction036
#ifdef __cplusplus #ifdef __cplusplus
@ -185,7 +184,7 @@ static bool os_random_buf(void* buf, size_t buf_len) {
bool ok = (RtlGenRandom(buf, (ULONG)buf_len) != 0); bool ok = (RtlGenRandom(buf, (ULONG)buf_len) != 0);
return ok; return ok;
} }
*/
#elif defined(ANDROID) || defined(XP_DARWIN) || defined(__APPLE__) || defined(__DragonFly__) || \ #elif defined(ANDROID) || defined(XP_DARWIN) || defined(__APPLE__) || defined(__DragonFly__) || \
defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
defined(__sun) || defined(__wasi__) defined(__sun) || defined(__wasi__)