30#define DEBUG_TYPE "rng"
43RandomNumberGenerator::RandomNumberGenerator(
StringRef Salt) {
45 <<
"Warning! Using unseeded random number generator.\n");
52 std::vector<uint32_t>
Data;
59 std::seed_seq SeedSeq(
Data.begin(),
Data.end());
60 Generator.seed(SeedSeq);
71 if (CryptAcquireContext(&hProvider, 0, 0, PROV_RSA_FULL,
72 CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
74 if (CryptGenRandom(hProvider,
Size,
static_cast<BYTE *
>(Buffer)))
75 return std::error_code();
77 return std::error_code(GetLastError(), std::system_category());
79 int Fd = open(
"/dev/urandom", O_RDONLY);
82 ssize_t BytesRead = read(Fd, Buffer,
Size);
84 Ret = std::error_code(errno, std::system_category());
85 else if (BytesRead !=
static_cast<ssize_t
>(
Size))
86 Ret = std::error_code(EIO, std::system_category());
88 Ret = std::error_code(errno, std::system_category());
92 return std::error_code(errno, std::system_category());
static ManagedStatic< cl::opt< uint64_t >, CreateSeed > Seed
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
generator_type::result_type result_type
result_type operator()()
Returns a random number in the range [0, Max).
StringRef - Represent a constant reference to a string, i.e.
constexpr size_t size() const
size - Get the string size.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void initRandomSeedOptions()
std::error_code getRandomBytes(void *Buffer, size_t Size)
OutputIt copy(R &&Range, OutputIt Out)