Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update osrng.cpp #1232

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions osrng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MicrosoftCryptoProvider>().Ref();
const MicrosoftCryptoProvider& hProvider = Singleton<MicrosoftCryptoProvider>().Ref();
# endif
# if defined(USE_MS_CRYPTOAPI)
DWORD dwSize;
Expand All @@ -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)))
{
Expand Down