From fade43edc4405e7c51cec9325d8502f3786f7438 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Fri, 30 Jun 2023 11:30:59 +0200 Subject: [PATCH] Allow FastRandomContext::randbytes for all byte types --- src/random.cpp | 9 ++++++--- src/random.h | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/random.cpp b/src/random.cpp index 39ceae42063..5ff6f573b8e 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -589,15 +589,18 @@ uint256 FastRandomContext::rand256() noexcept return ret; } -std::vector FastRandomContext::randbytes(size_t len) +template +std::vector FastRandomContext::randbytes(size_t len) { if (requires_seed) RandomSeed(); - std::vector ret(len); + std::vector ret(len); if (len > 0) { - rng.Keystream(ret.data(), len); + rng.Keystream(UCharCast(ret.data()), len); } return ret; } +template std::vector FastRandomContext::randbytes(size_t); +template std::vector FastRandomContext::randbytes(size_t); void FastRandomContext::fillrand(Span output) { diff --git a/src/random.h b/src/random.h index 50f56ed9117..3b15477ae94 100644 --- a/src/random.h +++ b/src/random.h @@ -211,7 +211,8 @@ public: } /** Generate random bytes. */ - std::vector randbytes(size_t len); + template + std::vector randbytes(size_t len); /** Fill a byte Span with random bytes. */ void fillrand(Span output);