diff options
author | James Hilliard <james.hilliard1@gmail.com> | 2017-07-27 15:34:09 +0300 |
---|---|---|
committer | James Hilliard <james.hilliard1@gmail.com> | 2017-07-27 15:34:09 +0300 |
commit | ee2d10ad0c0e04d0b9da4535a6fff265ac2501e5 (patch) | |
tree | 3818176646573cda7792fdf472408e345c7e33c3 | |
parent | ba1bbb049b8f3ad295f36b060f775591b1fed8c1 (diff) | |
download | bitcoin-ee2d10ad0c0e04d0b9da4535a6fff265ac2501e5.tar.xz |
Check if sys/random.h is required for getentropy on OSX.
-rw-r--r-- | configure.ac | 8 | ||||
-rw-r--r-- | src/random.cpp | 14 |
2 files changed, 21 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index aea5d7160c..1fc4e3219e 100644 --- a/configure.ac +++ b/configure.ac @@ -675,6 +675,14 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>]], [ AC_MSG_RESULT(no)] ) +AC_MSG_CHECKING(for getentropy via random.h) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h> + #include <sys/random.h>]], + [[ getentropy(nullptr, 32) ]])], + [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_GETENTROPY_RAND, 1,[Define this symbol if the BSD getentropy system call is available with sys/random.h]) ], + [ AC_MSG_RESULT(no)] +) + AC_MSG_CHECKING(for sysctl KERN_ARND) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h> #include <sys/sysctl.h>]], diff --git a/src/random.cpp b/src/random.cpp index b308e8f4a1..e07ef44471 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -27,9 +27,12 @@ #include <sys/syscall.h> #include <linux/random.h> #endif -#ifdef HAVE_GETENTROPY +#if defined(HAVE_GETENTROPY) || (defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX)) #include <unistd.h> #endif +#if defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX) +#include <sys/random.h> +#endif #ifdef HAVE_SYSCTL_ARND #include <sys/sysctl.h> #endif @@ -237,6 +240,15 @@ void GetOSRand(unsigned char *ent32) if (getentropy(ent32, NUM_OS_RANDOM_BYTES) != 0) { RandFailure(); } +#elif defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX) + // We need a fallback for OSX < 10.12 + if (&getentropy != NULL) { + if (getentropy(ent32, NUM_OS_RANDOM_BYTES) != 0) { + RandFailure(); + } + } else { + GetDevURandom(ent32); + } #elif defined(HAVE_SYSCTL_ARND) /* FreeBSD and similar. It is possible for the call to return less * bytes than requested, so need to read in a loop. |