Changeset View
Changeset View
Standalone View
Standalone View
src/random.cpp
| Show First 20 Lines • Show All 683 Lines • ▼ Show 20 Lines | if (requires_seed) { | ||||
| RandomSeed(); | RandomSeed(); | ||||
| } | } | ||||
| uint256 ret; | uint256 ret; | ||||
| rng.Keystream(MakeWritableByteSpan(ret)); | rng.Keystream(MakeWritableByteSpan(ret)); | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| template <typename B> std::vector<B> FastRandomContext::randbytes(size_t len) { | template <typename B> std::vector<B> FastRandomContext::randbytes(size_t len) { | ||||
| if (requires_seed) { | |||||
| RandomSeed(); | |||||
| } | |||||
| std::vector<B> ret(len); | std::vector<B> ret(len); | ||||
| if (len > 0) { | fillrand(MakeWritableByteSpan(ret)); | ||||
| rng.Keystream(MakeWritableByteSpan(ret)); | |||||
| } | |||||
| return ret; | return ret; | ||||
| } | } | ||||
| template std::vector<uint8_t> FastRandomContext::randbytes(size_t); | template std::vector<uint8_t> FastRandomContext::randbytes(size_t); | ||||
| template std::vector<std::byte> FastRandomContext::randbytes(size_t); | template std::vector<std::byte> FastRandomContext::randbytes(size_t); | ||||
| void FastRandomContext::fillrand(Span<std::byte> output) { | |||||
| if (requires_seed) { | |||||
| RandomSeed(); | |||||
| } | |||||
| rng.Keystream(output); | |||||
| } | |||||
| FastRandomContext::FastRandomContext(const uint256 &seed) noexcept | FastRandomContext::FastRandomContext(const uint256 &seed) noexcept | ||||
| : requires_seed(false), bitbuf_size(0) { | : requires_seed(false), bitbuf_size(0) { | ||||
| rng.SetKey(MakeByteSpan(seed)); | rng.SetKey(MakeByteSpan(seed)); | ||||
| } | } | ||||
| bool Random_SanityCheck() { | bool Random_SanityCheck() { | ||||
| uint64_t start = GetPerformanceCounter(); | uint64_t start = GetPerformanceCounter(); | ||||
| ▲ Show 20 Lines • Show All 88 Lines • Show Last 20 Lines | |||||