From b456e4bd8268c39198065b88084bf72170018e59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C5=93ur?= Date: Sat, 26 Oct 2024 20:46:41 +0200 Subject: [PATCH] Use arc4random_stir over deprecated arc4random_addrandom (#1631) Co-authored-by: Azat Khuzhin --- CMakeLists.txt | 2 +- configure.ac | 2 +- event-config.h.cmake | 4 ++-- evutil_rand.c | 4 +++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d31d69b..8d631852 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -540,8 +540,8 @@ else() list(APPEND SYMBOLS_TO_CHECK accept4 arc4random - arc4random_addrandom arc4random_buf + arc4random_stir epoll_create epoll_create1 epoll_ctl diff --git a/configure.ac b/configure.ac index 6d6b4b5b..5f2d87df 100644 --- a/configure.ac +++ b/configure.ac @@ -249,7 +249,7 @@ dnl Checks for typedefs, structures, and compiler characteristics. AC_C_INLINE dnl Checks for library functions. -AC_CHECK_FUNCS([accept4 arc4random arc4random_addrandom arc4random_buf epoll_create1 epoll_pwait2 eventfd fcntl getegid geteuid getifaddrs getrandom gettimeofday issetugid mach_absolute_time mmap mmap64 nanosleep pipe pipe2 pread putenv sendfile setenv setrlimit sigaction signal socketpair strlcpy strsep strsignal strtok_r strtoll sysctl timerfd_create umask unsetenv usleep]) +AC_CHECK_FUNCS([accept4 arc4random arc4random_buf arc4random_stir epoll_create1 epoll_pwait2 eventfd fcntl getegid geteuid getifaddrs getrandom gettimeofday issetugid mach_absolute_time mmap mmap64 nanosleep pipe pipe2 pread putenv sendfile setenv setrlimit sigaction signal socketpair strlcpy strsep strsignal strtok_r strtoll sysctl timerfd_create umask unsetenv usleep]) AS_IF([test "$bwin32" = "true"], AC_CHECK_FUNCS(_gmtime64_s, , [AC_CHECK_FUNCS(_gmtime64)]) diff --git a/event-config.h.cmake b/event-config.h.cmake index 04669bd7..a6375141 100644 --- a/event-config.h.cmake +++ b/event-config.h.cmake @@ -53,8 +53,8 @@ /* Define to 1 if you have the `arc4random_buf' function. */ #cmakedefine EVENT__HAVE_ARC4RANDOM_BUF 1 -/* Define to 1 if you have the `arc4random_addrandom' function. */ -#cmakedefine EVENT__HAVE_ARC4RANDOM_ADDRANDOM 1 +/* Define to 1 if you have the `arc4random_stir' function. */ +#cmakedefine EVENT__HAVE_ARC4RANDOM_STIR 1 /* Define to 1 if you have the header file. */ #cmakedefine EVENT__HAVE_ARPA_INET_H 1 diff --git a/evutil_rand.c b/evutil_rand.c index c32ac1af..0263fee5 100644 --- a/evutil_rand.c +++ b/evutil_rand.c @@ -193,9 +193,11 @@ evutil_secure_rng_get_bytes(void *buf, size_t n) void evutil_secure_rng_add_bytes(const char *buf, size_t n) { -#if !defined(EVENT__HAVE_ARC4RANDOM) || defined(EVENT__HAVE_ARC4RANDOM_ADDRANDOM) +#if !defined(EVENT__HAVE_ARC4RANDOM) arc4random_addrandom((unsigned char*)buf, n>(size_t)INT_MAX ? INT_MAX : (int)n); +#elif defined(EVENT__HAVE_ARC4RANDOM_STIR) + arc4random_stir(); #endif }