aboutsummaryrefslogtreecommitdiff
path: root/src/random.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2017-05-02 11:04:31 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2017-06-05 12:44:44 -0700
commit37e864eb9fee4b592bd61c5ec3555b00a2de2cf7 (patch)
tree901f97994d5a2e5aebf5f3e41d27698b780ac152 /src/random.cpp
parent9fec4da0bec93a49798b5f5e92cf76e900759ee4 (diff)
downloadbitcoin-37e864eb9fee4b592bd61c5ec3555b00a2de2cf7.tar.xz
Add FastRandomContext::rand256() and ::randbytes()
FastRandomContext now provides all functionality that the real Rand* functions provide.
Diffstat (limited to 'src/random.cpp')
-rw-r--r--src/random.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/random.cpp b/src/random.cpp
index de7553c825..e1ccfa5f24 100644
--- a/src/random.cpp
+++ b/src/random.cpp
@@ -304,6 +304,26 @@ void FastRandomContext::RandomSeed()
requires_seed = false;
}
+uint256 FastRandomContext::rand256()
+{
+ if (bytebuf_size < 32) {
+ FillByteBuffer();
+ }
+ uint256 ret;
+ memcpy(ret.begin(), bytebuf + 64 - bytebuf_size, 32);
+ bytebuf_size -= 32;
+ return ret;
+}
+
+std::vector<unsigned char> FastRandomContext::randbytes(size_t len)
+{
+ std::vector<unsigned char> ret(len);
+ if (len > 0) {
+ rng.Output(&ret[0], len);
+ }
+ return ret;
+}
+
FastRandomContext::FastRandomContext(const uint256& seed) : requires_seed(false), bytebuf_size(0), bitbuf_size(0)
{
rng.SetKey(seed.begin(), 32);