mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Get entropy from the windows system provider and give to SSL
This commit is contained in:
38
src/PlatRand.cpp
Normal file
38
src/PlatRand.cpp
Normal 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
|
||||
Reference in New Issue
Block a user