aboutsummaryrefslogtreecommitdiff
path: root/src/random.cpp
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2022-02-02 15:35:26 +0100
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2022-02-02 15:35:26 +0100
commit5cd15ffdceace3a077d4719ef7c1704336d602e1 (patch)
tree9d8400ed9548c349d61e9e9d802143b206aa55f9 /src/random.cpp
parenta41976ab770d4453ccb043f72e48a6eb15a7106a (diff)
downloadbitcoin-5cd15ffdceace3a077d4719ef7c1704336d602e1.tar.xz
random: use arc4random on OpenBSD
Following best practices on OpenBSD. The getentropy(2) man page states: "getentropy() is not intended for regular code; please use the arc4random(3) family of functions instead."
Diffstat (limited to 'src/random.cpp')
-rw-r--r--src/random.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/random.cpp b/src/random.cpp
index 5dae80fe31..fa53a0f7b9 100644
--- a/src/random.cpp
+++ b/src/random.cpp
@@ -305,16 +305,14 @@ void GetOSRand(unsigned char *ent32)
RandFailure();
}
}
-#elif defined(HAVE_GETENTROPY) && defined(__OpenBSD__)
- /* On OpenBSD this can return up to 256 bytes of entropy, will return an
- * error if more are requested.
- * The call cannot return less than the requested number of bytes.
- getentropy is explicitly limited to openbsd here, as a similar (but not
- the same) function may exist on other platforms via glibc.
+#elif defined(__OpenBSD__)
+ /* OpenBSD. From the arc4random(3) man page:
+ "Use of these functions is encouraged for almost all random number
+ consumption because the other interfaces are deficient in either
+ quality, portability, standardization, or availability."
+ The function call is always successful.
*/
- if (getentropy(ent32, NUM_OS_RANDOM_BYTES) != 0) {
- RandFailure();
- }
+ arc4random_buf(ent32, NUM_OS_RANDOM_BYTES);
// Silence a compiler warning about unused function.
(void)GetDevURandom;
#elif defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX)