MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ProcRand

Function ProcRand

src/random.cpp:562–589  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

560};
561
562void ProcRand(unsigned char* out, int num, RNGLevel level, bool always_use_real_rng) noexcept
563{
564 // Make sure the RNG is initialized first (as all Seed* function possibly need hwrand to be available).
565 RNGState& rng = GetRNGState();
566
567 assert(num <= 32);
568
569 CSHA512 hasher;
570 switch (level) {
571 case RNGLevel::FAST:
572 SeedFast(hasher);
573 break;
574 case RNGLevel::SLOW:
575 SeedSlow(hasher, rng);
576 break;
577 case RNGLevel::PERIODIC:
578 SeedPeriodic(hasher, rng);
579 break;
580 }
581
582 // Combine with and update state
583 if (!rng.MixExtract(out, num, std::move(hasher), false, always_use_real_rng)) {
584 // On the first invocation, also seed with SeedStartup().
585 CSHA512 startup_hasher;
586 SeedStartup(startup_hasher, rng);
587 rng.MixExtract(out, num, std::move(startup_hasher), true, always_use_real_rng);
588 }
589}
590
591} // namespace
592

Callers 4

GetRandBytesFunction · 0.85
GetStrongRandBytesFunction · 0.85
RandAddPeriodicFunction · 0.85
RandomInitFunction · 0.85

Calls 4

SeedFastFunction · 0.85
SeedSlowFunction · 0.85
SeedPeriodicFunction · 0.85
SeedStartupFunction · 0.85

Tested by

no test coverage detected