diff --git a/osrng.cpp b/osrng.cpp index bb92e832f..8367144e9 100644 --- a/osrng.cpp +++ b/osrng.cpp @@ -177,14 +177,14 @@ NonblockingRng::~NonblockingRng() #endif } -void NonblockingRng::GenerateBlock(byte *output, size_t size) +void NonblockingRng::GenerateBlock(byte* output, size_t size) { #ifdef CRYPTOPP_WIN32_AVAILABLE // Acquiring a provider is expensive. Do it once and retain the reference. # if defined(CRYPTOPP_CXX11_STATIC_INIT) static const MicrosoftCryptoProvider hProvider = MicrosoftCryptoProvider(); # else - const MicrosoftCryptoProvider &hProvider = Singleton().Ref(); + const MicrosoftCryptoProvider& hProvider = Singleton().Ref(); # endif # if defined(USE_MS_CRYPTOAPI) DWORD dwSize; @@ -206,7 +206,11 @@ void NonblockingRng::GenerateBlock(byte *output, size_t size) SetLastError(ERROR_INCORRECT_SIZE); throw OS_RNG_Err("GenerateBlock size"); } +#if WINVER >= 0x0A00 + NTSTATUS ret = BCryptGenRandom(BCRYPT_RNG_ALG_HANDLE, output, ulSize, 0); +#else NTSTATUS ret = BCryptGenRandom(hProvider.GetProviderHandle(), output, ulSize, 0); +#endif CRYPTOPP_ASSERT(BCRYPT_SUCCESS(ret)); if (!(BCRYPT_SUCCESS(ret))) {