Commit 165086e8 authored by Nirbheek Chauhan's avatar Nirbheek Chauhan 🐜

rand: Use crypto libs instead of CryptGenRandom()

We will always have either openssl or gnutls, which are better sources
for random nonces. Also, CryptGenRandom is deprecated API that's not
available on WinRT/UWP.
parent b67df589
......@@ -39,36 +39,7 @@
#include "rand.h"
#ifdef _WIN32
#include <windows.h>
#include <wincrypt.h>
void nice_RAND_nonce (uint8_t *dst, int len)
{
HCRYPTPROV hCryptProv;
LPCSTR container = "Libnice key container";
if(!CryptAcquireContext(&hCryptProv, container, NULL, PROV_RSA_FULL, 0)) {
/* non existing container. try to create a new one */
// I hope this cast here doesn't cause issues
// gcc was complaining about comparing signed and unsigned values
if (GetLastError() == (DWORD) NTE_BAD_KEYSET) {
if(!CryptAcquireContext(&hCryptProv, container, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET)) {
return;
}
}
return;
}
CryptGenRandom (hCryptProv, len, dst);
CryptReleaseContext(hCryptProv,0);
}
#else
#ifdef HAVE_OPENSSL
#if defined(HAVE_OPENSSL)
#include <openssl/rand.h>
......@@ -77,7 +48,7 @@ void nice_RAND_nonce (uint8_t *dst, int len)
RAND_bytes (dst, len);
}
#else
#elif defined(HAVE_GNUTLS)
#include <sys/types.h>
#include <gnutls/gnutls.h>
......@@ -88,6 +59,4 @@ void nice_RAND_nonce (uint8_t *dst, int len)
gnutls_rnd (GNUTLS_RND_NONCE, dst, len);
}
#endif /* HAVE_OPENSSL */
#endif /* _WIN32 */
#endif
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