diff --git a/pkg/ent/configure b/pkg/ent/configure index 3e98a5108..8171293f3 100755 --- a/pkg/ent/configure +++ b/pkg/ent/configure @@ -7,6 +7,7 @@ log () { for impl in ENT_GETENTROPY_UNISTD \ ENT_GETENTROPY_SYSRANDOM \ ENT_GETRANDOM_SYSCALL \ + ENT_GETENTROPY_BCRYPTGENRANDOM \ ENT_DEV_URANDOM do export IMPL=$impl diff --git a/pkg/ent/ent.c b/pkg/ent/ent.c index 7aee7f48d..e7309ff33 100644 --- a/pkg/ent/ent.c +++ b/pkg/ent/ent.c @@ -57,6 +57,16 @@ int ent_getentropy(void* buf, size_t len) { return 0; } + +// Use `BCryptGenRandom` on Windows //////////////////////////////////////////// + +#elif defined(ENT_GETENTROPY_BCRYPTGENRANDOM) +#include +#include +int ent_getentropy(void* buf, size_t len) { + return BCryptGenRandom(NULL, (PUCHAR)buf, len, BCRYPT_USE_SYSTEM_PREFERRED_RNG); +} + #else -#error "One of these must be set: ENT_DEV_URANDOM, ENT_GETENTROPY_UNISTD, ENT_GETENTROPY_SYSRANDOM, ENT_GETRANDOM_SYSCALL" +#error "One of these must be set: ENT_GETENTROPY_BCRYPTGENRANDOM, ENT_DEV_URANDOM, ENT_GETENTROPY_UNISTD, ENT_GETENTROPY_SYSRANDOM, ENT_GETRANDOM_SYSCALL" #endif