Use both getrandom() and /dev/urandom by default on Linux.
authorKurt Roeckx <kurt@roeckx.be>
Fri, 9 Feb 2018 23:30:29 +0000 (00:30 +0100)
committerKurt Roeckx <kurt@roeckx.be>
Tue, 13 Feb 2018 20:15:30 +0000 (21:15 +0100)
getrandom() is now used on Linux by default when using Linux >= 3.17
and glibc >= 2.25

Reviewed-by: Rich Salz <rsalz@openssl.org>
GH: #5314

crypto/rand/rand_unix.c

index f5a59cb28a66879a44c706b5216fa3d74dcd2a2f..bfd7ef045552bc47c6a85efc896453d7af21d33b 100644 (file)
 #include "rand_lcl.h"
 #include <stdio.h>
 
-#ifdef OPENSSL_RAND_SEED_GETRANDOM
-# include <linux/random.h>
-#endif
-
 #if (defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI)) && \
         !defined(OPENSSL_RAND_SEED_NONE)
 # error "UEFI and VXWorks only support seeding NONE"
@@ -123,11 +119,19 @@ size_t RAND_POOL_acquire_entropy(RAND_POOL *pool)
 #  endif
 
 #  if defined(OPENSSL_RAND_SEED_OS)
-#   if defined(DEVRANDOM)
-#    define OPENSSL_RAND_SEED_DEVRANDOM
-#   else
+#   if !defined(DEVRANDOM)
 #    error "OS seeding requires DEVRANDOM to be configured"
 #   endif
+#   define OPENSSL_RAND_SEED_DEVRANDOM
+#   if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#    if __GLIBC_PREREQ(2, 25)
+#     define OPENSSL_RAND_SEED_GETRANDOM
+#    endif
+#   endif
+#  endif
+
+#  ifdef OPENSSL_RAND_SEED_GETRANDOM
+#   include <sys/random.h>
 #  endif
 
 #  if defined(OPENSSL_RAND_SEED_LIBRANDOM)