MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / GetStrongRandBytes

Function GetStrongRandBytes

src/random.cpp:318–351  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

316}
317
318void GetStrongRandBytes(unsigned char* out, int num)
319{
320 assert(num <= 32);
321 CSHA512 hasher;
322 unsigned char buf[64];
323
324 // First source: OpenSSL's RNG
325 RandAddSeedPerfmon();
326 GetRandBytes(buf, 32);
327 hasher.Write(buf, 32);
328
329 // Second source: OS RNG
330 GetOSRand(buf);
331 hasher.Write(buf, 32);
332
333 // Third source: HW RNG, if available.
334 if (GetHWRand(buf)) {
335 hasher.Write(buf, 32);
336 }
337
338 // Combine with and update state
339 {
340 std::unique_lock<std::mutex> lock(cs_rng_state);
341 hasher.Write(rng_state, sizeof(rng_state));
342 hasher.Write((const unsigned char*)&rng_counter, sizeof(rng_counter));
343 ++rng_counter;
344 hasher.Finalize(buf);
345 memcpy(rng_state, buf + 32, 32);
346 }
347
348 // Produce output
349 memcpy(out, buf, num);
350 memory_cleanse(buf, 64);
351}
352
353uint64_t GetRand(uint64_t nMax)
354{

Callers 2

MakeNewKeyMethod · 0.85
EncryptWalletMethod · 0.85

Calls 8

RandAddSeedPerfmonFunction · 0.85
GetRandBytesFunction · 0.85
GetOSRandFunction · 0.85
GetHWRandFunction · 0.85
memcpyFunction · 0.85
memory_cleanseFunction · 0.85
WriteMethod · 0.45
FinalizeMethod · 0.45

Tested by

no test coverage detected