Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B3FB2200D40 for ; Sat, 4 Nov 2017 01:12:51 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id B2737160BFC; Sat, 4 Nov 2017 00:12:51 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 042DF160BFB for ; Sat, 4 Nov 2017 01:12:50 +0100 (CET) Received: (qmail 89938 invoked by uid 500); 4 Nov 2017 00:12:50 -0000 Mailing-List: contact commits-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: Reply-To: dev@apr.apache.org List-Id: Delivered-To: mailing list commits@apr.apache.org Received: (qmail 89928 invoked by uid 99); 4 Nov 2017 00:12:50 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 04 Nov 2017 00:12:50 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 78CE23A0158 for ; Sat, 4 Nov 2017 00:12:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1814240 - in /apr/apr/trunk: configure.in misc/unix/rand.c Date: Sat, 04 Nov 2017 00:12:45 -0000 To: commits@apr.apache.org From: ylavic@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20171104001248.78CE23A0158@svn01-us-west.apache.org> archived-at: Sat, 04 Nov 2017 00:12:51 -0000 Author: ylavic Date: Sat Nov 4 00:12:45 2017 New Revision: 1814240 URL: http://svn.apache.org/viewvc?rev=1814240&view=rev Log: rand: add support for getrandom() on Linux as an entropy source. Use it for apr_generate_random_bytes() when available, reading from the urandom source, and non-blocking such that the call fails with EINVAL if there is not enough entropy on the system (which shouldn't be the case in userspace). 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=1814240&r1=1814239&r2=1814240&view=diff ============================================================================== --- apr/apr/trunk/configure.in (original) +++ apr/apr/trunk/configure.in Sat Nov 4 00:12:45 2017 @@ -2453,6 +2453,9 @@ else fi dnl ----------------------------- Checking for /dev/random +AC_CHECK_HEADERS(sys/random.h) +AC_CHECK_FUNCS(getrandom) + AC_CHECK_FUNCS(arc4random_buf) AC_MSG_CHECKING(for entropy source) @@ -2473,6 +2476,13 @@ AC_ARG_WITH(egd, ]) if test "$rand" != "1"; then + if test "$ac_cv_func_getrandom" = yes; then + AC_MSG_RESULT(getrandom) + rand="1" + fi +fi + +if test "$rand" != "1"; then if test "$ac_cv_func_arc4random_buf" = yes; then AC_MSG_RESULT(arc4random) rand="1" Modified: apr/apr/trunk/misc/unix/rand.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/misc/unix/rand.c?rev=1814240&r1=1814239&r2=1814240&view=diff ============================================================================== --- apr/apr/trunk/misc/unix/rand.c (original) +++ apr/apr/trunk/misc/unix/rand.c Sat Nov 4 00:12:45 2017 @@ -42,6 +42,9 @@ #elif defined(HAVE_SYS_UUID_H) #include #endif +#ifdef HAVE_GETRANDOM +#include +#endif #ifndef SHUT_RDWR #define SHUT_RDWR 2 @@ -87,7 +90,24 @@ 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) { -#if defined(HAVE_ARC4RANDOM) +#if defined(HAVE_GETRANDOM) + + do { + int rc; + + rc = getrandom(buf, length, GRND_NONBLOCK); + if (rc == -1) { + if (errno == EINTR) { + continue; + } + return errno; + } + + buf += rc; + length -= rc; + } while (length > 0); + +#elif defined(HAVE_ARC4RANDOM) arc4random_buf(buf, length);