1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

Process::GetRandomNumber(): fix insecure RNG

This could have generated non-random output under error conditions in release
builds.

llvm-svn: 210065
This commit is contained in:
Alp Toker 2014-06-03 03:01:03 +00:00
parent 87cd774844
commit 7425836c09

View File

@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/Allocator.h"
#include "llvm/Support/ErrorHandling.h"
#include <malloc.h>
// The Windows.h header must be after LLVM and standard headers.
@ -363,12 +364,12 @@ unsigned Process::GetRandomNumber() {
HCRYPTPROV HCPC;
if (!::CryptAcquireContextW(&HCPC, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT))
assert(false && "Could not acquire a cryptographic context");
report_fatal_error("Could not acquire a cryptographic context");
ScopedCryptContext CryptoProvider(HCPC);
unsigned Ret;
if (!::CryptGenRandom(CryptoProvider, sizeof(Ret),
reinterpret_cast<BYTE *>(&Ret)))
assert(false && "Could not generate a random number");
report_fatal_error("Could not generate a random number");
return Ret;
}