aboutsummaryrefslogtreecommitdiff
path: root/src/random.h
diff options
context:
space:
mode:
authorpracticalswift <practicalswift@users.noreply.github.com>2020-03-28 08:56:38 +0000
committerpracticalswift <practicalswift@users.noreply.github.com>2020-03-29 13:17:04 +0000
commit11a520f6793e21e0a8a9301f5ec4c28a48131b85 (patch)
tree5b647e835f3a5dd934688fad64043818fde440d2 /src/random.h
parent64d277bbbcbd464b2a795bae011ee808298a42ca (diff)
downloadbitcoin-11a520f6793e21e0a8a9301f5ec4c28a48131b85.tar.xz
tests: Add fuzzing harness for functions/classes in random.h
Diffstat (limited to 'src/random.h')
-rw-r--r--src/random.h14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/random.h b/src/random.h
index 518a5cd3e3..4e4597cff6 100644
--- a/src/random.h
+++ b/src/random.h
@@ -103,7 +103,8 @@ void RandAddEvent(const uint32_t event_info) noexcept;
*
* This class is not thread-safe.
*/
-class FastRandomContext {
+class FastRandomContext
+{
private:
bool requires_seed;
ChaCha20 rng;
@@ -155,7 +156,8 @@ public:
}
/** Generate a random (bits)-bit integer. */
- uint64_t randbits(int bits) noexcept {
+ uint64_t randbits(int bits) noexcept
+ {
if (bits == 0) {
return 0;
} else if (bits > 32) {
@@ -169,7 +171,9 @@ public:
}
}
- /** Generate a random integer in the range [0..range). */
+ /** Generate a random integer in the range [0..range).
+ * Precondition: range > 0.
+ */
uint64_t randrange(uint64_t range) noexcept
{
assert(range);
@@ -210,7 +214,7 @@ public:
* debug mode detects and panics on. This is a known issue, see
* https://stackoverflow.com/questions/22915325/avoiding-self-assignment-in-stdshuffle
*/
-template<typename I, typename R>
+template <typename I, typename R>
void Shuffle(I first, I last, R&& rng)
{
while (first != last) {
@@ -233,7 +237,7 @@ static const int NUM_OS_RANDOM_BYTES = 32;
/** Get 32 bytes of system entropy. Do not use this in application code: use
* GetStrongRandBytes instead.
*/
-void GetOSRand(unsigned char *ent32);
+void GetOSRand(unsigned char* ent32);
/** Check that OS randomness is available and returning the requested number
* of bytes.