Allow FastRandomContext::randbytes for all byte types

pull/28012/head
MarcoFalke 1 year ago
parent 2cd71d3a13
commit fade43edc4
No known key found for this signature in database

@ -589,15 +589,18 @@ uint256 FastRandomContext::rand256() noexcept
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();
std::vector<unsigned char> ret(len);
std::vector<B> ret(len);
if (len > 0) {
rng.Keystream(ret.data(), len);
rng.Keystream(UCharCast(ret.data()), len);
}
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)
{

@ -211,7 +211,8 @@ public:
}
/** 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. */
void fillrand(Span<std::byte> output);

Loading…
Cancel
Save