MCPcopy Create free account
hub / github.com/ElementsProject/elements / ProcRand

Function ProcRand

src/random.cpp:552–579  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

550};
551
552static void ProcRand(unsigned char* out, int num, RNGLevel level) noexcept
553{
554 // Make sure the RNG is initialized first (as all Seed* function possibly need hwrand to be available).
555 RNGState& rng = GetRNGState();
556
557 assert(num <= 32);
558
559 CSHA512 hasher;
560 switch (level) {
561 case RNGLevel::FAST:
562 SeedFast(hasher);
563 break;
564 case RNGLevel::SLOW:
565 SeedSlow(hasher, rng);
566 break;
567 case RNGLevel::PERIODIC:
568 SeedPeriodic(hasher, rng);
569 break;
570 }
571
572 // Combine with and update state
573 if (!rng.MixExtract(out, num, std::move(hasher), false)) {
574 // On the first invocation, also seed with SeedStartup().
575 CSHA512 startup_hasher;
576 SeedStartup(startup_hasher, rng);
577 rng.MixExtract(out, num, std::move(startup_hasher), true);
578 }
579}
580
581void GetRandBytes(unsigned char* buf, int num) noexcept { ProcRand(buf, num, RNGLevel::FAST); }
582void GetStrongRandBytes(unsigned char* buf, int num) noexcept { ProcRand(buf, num, RNGLevel::SLOW); }

Callers 4

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

Calls 5

SeedFastFunction · 0.85
SeedSlowFunction · 0.85
SeedPeriodicFunction · 0.85
SeedStartupFunction · 0.85
MixExtractMethod · 0.80

Tested by

no test coverage detected