mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 02:33:24 -03: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:
parent
a41976ab77
commit
5cd15ffdce
1 changed files with 7 additions and 9 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue