diff --git a/src/PlatRand.cpp b/src/PlatRand.cpp new file mode 100644 index 000000000..8b0d4dfc6 --- /dev/null +++ b/src/PlatRand.cpp @@ -0,0 +1,38 @@ + +#ifdef WIN32 + +#include +#include + +#include + +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 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