Get entropy from the windows system provider and give to SSL

This commit is contained in:
JoelKatz
2012-04-29 13:26:29 -07:00
parent daf696042d
commit 83d4280035

38
src/PlatRand.cpp Normal file
View File

@@ -0,0 +1,38 @@
#ifdef WIN32
#include <windows.h>
#include <wincrypt.h>
#include <openssl/rand.h>
bool AddSystemEntropy()
{ // Get entropy from the Windows crypto provider
char name[512], rand[128];
DWORD count = 500;
HCRYPTOPROV cryptoHandle;
if (!CryptGetDefaultProvider(PROV_RSA_FULL, NULL, CRYPT_MACHINE_DEFAULT, name, &count))
return false;
if (!CryptAcquireContext(&cryptoHandle, NULL, name, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
return false;
if(!CryptGenRandom(cryptoHandle, 128, reinterpret_cast<BYTE*> rand))
{
CryptReleaseContext(cryptoHandle, 0);
return false;
}
CryptReleaseContext(cryptoHandle, 0);
RAND_seed(rand, 128);
return true;
}
#else
bool AddSystemEntropy()
{ // Stub for implementing on other platforms
return false;
}
#endif