Use C++ dynamic initialization if available

pull/877/head
Jeffrey Walton 2019-08-12 00:11:41 -04:00
parent 2d6895acb4
commit 34e49627b7
1 changed files with 4 additions and 0 deletions

View File

@ -148,7 +148,11 @@ 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_DYNAMIC_INIT)
static const MicrosoftCryptoProvider hProvider = MicrosoftCryptoProvider();
# else
const MicrosoftCryptoProvider &hProvider = Singleton<MicrosoftCryptoProvider>().Ref();
# endif
# if defined(USE_MS_CRYPTOAPI)
if (!CryptGenRandom(hProvider.GetProviderHandle(), (DWORD)size, output))
throw OS_RNG_Err("CryptGenRandom");