1
mirror of https://github.com/bitcoin/bitcoin synced 2024-07-21 23:34:19 +02:00

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."
This commit is contained in:
Sebastian Falbesoner 2022-02-02 15:35:26 +01:00
parent a41976ab77
commit 5cd15ffdce

View File

@ -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)