0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-09 10:43:19 -05:00

Allow FastRandomContext::randbytes for all byte types

This commit is contained in:
MarcoFalke 2023-06-30 11:30:59 +02:00
parent 2cd71d3a13
commit fade43edc4
No known key found for this signature in database
2 changed files with 8 additions and 4 deletions

View file

@ -589,15 +589,18 @@ uint256 FastRandomContext::rand256() noexcept
return ret; return ret;
} }
std::vector<unsigned char> FastRandomContext::randbytes(size_t len) template <typename B>
std::vector<B> FastRandomContext::randbytes(size_t len)
{ {
if (requires_seed) RandomSeed(); if (requires_seed) RandomSeed();
std::vector<unsigned char> ret(len); std::vector<B> ret(len);
if (len > 0) { if (len > 0) {
rng.Keystream(ret.data(), len); rng.Keystream(UCharCast(ret.data()), len);
} }
return ret; return ret;
} }
template std::vector<unsigned char> FastRandomContext::randbytes(size_t);
template std::vector<std::byte> FastRandomContext::randbytes(size_t);
void FastRandomContext::fillrand(Span<std::byte> output) void FastRandomContext::fillrand(Span<std::byte> output)
{ {

View file

@ -211,7 +211,8 @@ public:
} }
/** Generate random bytes. */ /** Generate random bytes. */
std::vector<unsigned char> randbytes(size_t len); template <typename B = unsigned char>
std::vector<B> randbytes(size_t len);
/** Fill a byte Span with random bytes. */ /** Fill a byte Span with random bytes. */
void fillrand(Span<std::byte> output); void fillrand(Span<std::byte> output);