diff --git a/src/Native/Unix/Common/pal_config.h.in b/src/Native/Unix/Common/pal_config.h.in index 6099d2f32ca6..157cb4bf782b 100644 --- a/src/Native/Unix/Common/pal_config.h.in +++ b/src/Native/Unix/Common/pal_config.h.in @@ -28,6 +28,7 @@ #cmakedefine01 HAVE_TIOCGWINSZ #cmakedefine01 HAVE_SCHED_GETAFFINITY #cmakedefine01 HAVE_SCHED_SETAFFINITY +#cmakedefine01 HAVE_ARC4RANDOM #cmakedefine01 KEVENT_HAS_VOID_UDATA #cmakedefine01 HAVE_FDS_BITS #cmakedefine01 HAVE_PRIVATE_FDS_BITS diff --git a/src/Native/Unix/System.Native/pal_random.cpp b/src/Native/Unix/System.Native/pal_random.cpp index e6bda4490ab0..d0b3330f7338 100644 --- a/src/Native/Unix/System.Native/pal_random.cpp +++ b/src/Native/Unix/System.Native/pal_random.cpp @@ -11,6 +11,7 @@ #include #include +#include "pal_config.h" /* Generate random bytes. The generated bytes are not cryptographically strong. @@ -20,6 +21,9 @@ extern "C" void SystemNative_GetNonCryptographicallySecureRandomBytes(uint8_t* b { assert(buffer != NULL); +#if HAVE_ARC4RANDOM + arc4random_buf(buffer, (size_t)bufferLength); +#else static volatile int rand_des = -1; long num = 0; static bool sMissingDevURandom; @@ -93,4 +97,5 @@ extern "C" void SystemNative_GetNonCryptographicallySecureRandomBytes(uint8_t* b *(buffer + i) ^= num; num >>= 8; } +#endif // HAS_ARC4RANDOM } diff --git a/src/Native/Unix/configure.cmake b/src/Native/Unix/configure.cmake index 7b885239bdfc..f4a30ad6cb29 100644 --- a/src/Native/Unix/configure.cmake +++ b/src/Native/Unix/configure.cmake @@ -140,6 +140,10 @@ check_function_exists( sched_setaffinity HAVE_SCHED_SETAFFINITY) +check_function_exists( + arc4random + HAVE_ARC4RANDOM) + check_symbol_exists( TIOCGWINSZ "sys/ioctl.h"