apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yla...@apache.org
Subject svn commit: r1814239 - in /apr/apr/trunk: configure.in misc/unix/rand.c
Date Fri, 03 Nov 2017 23:28:21 GMT
Author: ylavic
Date: Fri Nov  3 23:28:21 2017
New Revision: 1814239

URL: http://svn.apache.org/viewvc?rev=1814239&view=rev
Log:
rand: add support for the arc4random API as an entropy source.

The arc4random API originates from OpenBSD where it supersedes random(3),
rand(3), and files in the /dev filesystem.
Use it for apr_generate_random_bytes().

Proposed by: Christian Weisgerber
Reviewed by: ylavic


Modified:
    apr/apr/trunk/configure.in
    apr/apr/trunk/misc/unix/rand.c

Modified: apr/apr/trunk/configure.in
URL: http://svn.apache.org/viewvc/apr/apr/trunk/configure.in?rev=1814239&r1=1814238&r2=1814239&view=diff
==============================================================================
--- apr/apr/trunk/configure.in (original)
+++ apr/apr/trunk/configure.in Fri Nov  3 23:28:21 2017
@@ -2453,6 +2453,8 @@ else
 fi
 
 dnl ----------------------------- Checking for /dev/random 
+AC_CHECK_FUNCS(arc4random_buf)
+
 AC_MSG_CHECKING(for entropy source)
 
 why_no_rand=""
@@ -2471,6 +2473,13 @@ AC_ARG_WITH(egd,
   ])
 
 if test "$rand" != "1"; then
+  if test "$ac_cv_func_arc4random_buf" = yes; then
+    AC_MSG_RESULT(arc4random)
+    rand="1"
+  fi
+fi
+
+if test "$rand" != "1"; then
   AC_ARG_WITH(devrandom,
     [  --with-devrandom[[=DEV]]  use /dev/random or compatible [[searches by default]]],
     [ apr_devrandom="$withval" ], [ apr_devrandom="yes" ])

Modified: apr/apr/trunk/misc/unix/rand.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/misc/unix/rand.c?rev=1814239&r1=1814238&r2=1814239&view=diff
==============================================================================
--- apr/apr/trunk/misc/unix/rand.c (original)
+++ apr/apr/trunk/misc/unix/rand.c Fri Nov  3 23:28:21 2017
@@ -87,7 +87,11 @@ APR_DECLARE(apr_status_t) apr_os_uuid_ge
 APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char *buf, 
                                                     apr_size_t length)
 {
-#ifdef DEV_RANDOM
+#if defined(HAVE_ARC4RANDOM)
+
+    arc4random_buf(buf, length);
+
+#elif defined(DEV_RANDOM)
 
     int fd = -1;
 



Mime
View raw message