diff --git a/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c b/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c index 970ce750..374ff4d6 100644 --- a/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +++ b/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c @@ -25,8 +25,13 @@ #ifdef _WIN32 # include -# include # include +# define RtlGenRandom SystemFunction036 +# if defined(__cplusplus) +extern "C" +# endif +BOOLEAN NTAPI RtlGenRandom(PVOID RandomBuffer, ULONG RandomBufferLength); +# pragma comment(lib, "advapi32.lib") #endif #define SALSA20_RANDOM_BLOCK_SIZE crypto_core_salsa20_OUTPUTBYTES @@ -41,9 +46,6 @@ typedef struct Salsa20Random_ { size_t rnd32_outleft; #ifndef _MSC_VER pid_t pid; -#endif -#ifdef _WIN32 - HCRYPTPROV hcrypt_prov; #endif int random_data_source_fd; int initialized; @@ -153,11 +155,6 @@ randombytes_salsa20_random_init(void) { stream.nonce = sodium_hrtime(); assert(stream.nonce != (uint64_t) 0U); - - if (! CryptAcquireContextW(&stream.hcrypt_prov, NULL, NULL, - PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { - abort(); - } } #endif @@ -187,7 +184,7 @@ randombytes_salsa20_random_stir(void) abort(); } #else /* _WIN32 */ - if (! CryptGenRandom(stream.hcrypt_prov, sizeof m0, (BYTE *) m0)) { + if (! RtlGenRandom((PVOID) m0, (ULONG) sizeof m0)) { abort(); } #endif @@ -255,8 +252,7 @@ randombytes_salsa20_random_close(void) ret = 0; } #else /* _WIN32 */ - if (stream.initialized != 0 && - CryptReleaseContext(stream.hcrypt_prov, 0)) { + if (stream.initialized != 0) { stream.initialized = 0; ret = 0; } diff --git a/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c b/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c index efb7dbef..0ffcc2e9 100644 --- a/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c +++ b/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c @@ -22,7 +22,12 @@ #ifdef _WIN32 # include -# include +# define RtlGenRandom SystemFunction036 +# if defined(__cplusplus) +extern "C" +# endif +BOOLEAN NTAPI RtlGenRandom(PVOID RandomBuffer, ULONG RandomBufferLength); +# pragma comment(lib, "advapi32.lib") #endif #ifdef __OpenBSD__ @@ -59,9 +64,6 @@ randombytes_sysrandom_close(void) #else /* __OpenBSD__ */ typedef struct SysRandom_ { -#ifdef _WIN32 - HCRYPTPROV hcrypt_prov; -#endif int random_data_source_fd; int initialized; } SysRandom; @@ -140,10 +142,6 @@ randombytes_sysrandom_init(void) static void randombytes_sysrandom_init(void) { - if (! CryptAcquireContextW(&stream.hcrypt_prov, NULL, NULL, - PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { - abort(); - } } #endif @@ -177,8 +175,7 @@ randombytes_sysrandom_close(void) ret = 0; } #else /* _WIN32 */ - if (stream.initialized != 0 && - CryptReleaseContext(stream.hcrypt_prov, 0)) { + if (stream.initialized != 0) { stream.initialized = 0; ret = 0; } @@ -212,7 +209,7 @@ randombytes_sysrandom_buf(void * const buf, const size_t size) if (size > 0xffffffff) { abort(); } - if (! CryptGenRandom(stream.hcrypt_prov, (DWORD) size, (BYTE *) buf)) { + if (! RtlGenRandom((PVOID) buf, (ULONG) size)) { abort(); } #endif