diff options
author | MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> | 2023-06-30 11:30:59 +0200 |
---|---|---|
committer | MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> | 2023-06-30 12:09:44 +0200 |
commit | fade43edc4405e7c51cec9325d8502f3786f7438 (patch) | |
tree | c4ddd2bd82013650bdcde2f0ec21def7f985cb03 /src | |
parent | 2cd71d3a13a344bfddf210c85e5411dd4e8afdb5 (diff) |
Allow FastRandomContext::randbytes for all byte types
Diffstat (limited to 'src')
-rw-r--r-- | src/random.cpp | 9 | ||||
-rw-r--r-- | src/random.h | 3 |
2 files changed, 8 insertions, 4 deletions
diff --git a/src/random.cpp b/src/random.cpp index 39ceae4206..5ff6f573b8 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -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) { diff --git a/src/random.h b/src/random.h index 50f56ed911..3b15477ae9 100644 --- a/src/random.h +++ b/src/random.h @@ -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); |