| 550 | }; |
| 551 | |
| 552 | static 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 | |
| 581 | void GetRandBytes(unsigned char* buf, int num) noexcept { ProcRand(buf, num, RNGLevel::FAST); } |
| 582 | void GetStrongRandBytes(unsigned char* buf, int num) noexcept { ProcRand(buf, num, RNGLevel::SLOW); } |
no test coverage detected