random: getentropy on macOS does not need unistd.h

change sys/random.h to random.h in AC_MSG_CHECK
remove definitions that are applicable to macos which include unistd.h
additionally change comparator argument from NULL to nullptr when evaluating &getentropy

Inspired by: c13c97dbf846cf0e6a5581ac414ef96a215b0dc6
This commit is contained in:
xanimo 2023-05-19 10:14:35 +01:00
parent 743c3acd3d
commit d693d4a008
No known key found for this signature in database
GPG Key ID: 6E8F17C1B1BCDCBE
2 changed files with 4 additions and 4 deletions

View File

@ -655,8 +655,8 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>]],
[ AC_MSG_RESULT(no)] [ AC_MSG_RESULT(no)]
) )
AC_MSG_CHECKING(for getentropy via random.h) AC_MSG_CHECKING([for getentropy via sys/random.h])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h> AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/random.h>]], #include <sys/random.h>]],
[[ getentropy(nullptr, 32) ]])], [[ 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(yes); AC_DEFINE(HAVE_GETENTROPY_RAND, 1,[Define this symbol if the BSD getentropy system call is available with sys/random.h]) ],

View File

@ -25,7 +25,7 @@
#include <sys/syscall.h> #include <sys/syscall.h>
#include <linux/random.h> #include <linux/random.h>
#endif #endif
#if defined(HAVE_GETENTROPY) || (defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX)) #if defined(HAVE_GETENTROPY)
#include <unistd.h> #include <unistd.h>
#endif #endif
#if defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX) #if defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX)
@ -169,7 +169,7 @@ void GetOSRand(unsigned char *ent32)
} }
#elif defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX) #elif defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX)
// We need a fallback for OSX < 10.12 // We need a fallback for OSX < 10.12
if (&getentropy != NULL) { if (&getentropy != nullptr) {
if (getentropy(ent32, NUM_OS_RANDOM_BYTES) != 0) { if (getentropy(ent32, NUM_OS_RANDOM_BYTES) != 0) {
RandFailure(); RandFailure();
} }