| 560 | }; |
| 561 | |
| 562 | void 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 |
no test coverage detected