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:
parent
2cd71d3a13
commit
fade43edc4
2 changed files with 8 additions and 4 deletions
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Add table
Reference in a new issue