Commit de80c72a authored by Youness Alaoui's avatar Youness Alaoui

fix random number generation for windows

parent 1ae8e58d
...@@ -42,24 +42,26 @@ ...@@ -42,24 +42,26 @@
#ifdef _WIN32 #ifdef _WIN32
#include <Wincrypt.h> #include <windows.h>
void RAND_bytes (uint8_t *dst, int len) void RAND_bytes (uint8_t *dst, int len)
{ {
HCRYPTPROV hCryptProv = NULL; HCRYPTPROV hCryptProv;
LPCSTR container = "Libnice key container"; LPCSTR container = "Libnice key container";
if(!CryptAcquireContext(&hCryptProv, container, NULL, PROV_RSA_FULL, 0)) { if(!CryptAcquireContext(&hCryptProv, container, NULL, PROV_RSA_FULL, 0)) {
/* non existing container. try to create a new one */ /* non existing container. try to create a new one */
if (GetLastError() == NTE_BAD_KEYSET) { if (GetLastError() == NTE_BAD_KEYSET) {
if(!CryptAcquireContext(&hCryptProv, container, NULL, CRYPT_NEWKEYSET)) { if(!CryptAcquireContext(&hCryptProv, container, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET)) {
return; return;
} }
} }
return; return;
} }
CryptGenRandom (&hCryptProv, len, dst); CryptGenRandom (hCryptProv, len, dst);
CryptReleaseContext(hCryptProv,0);
} }
#else #else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment