Commit d66d6d15 by Janne Blomqvist

Use getentropy() for seeding PRNG

The getentropy function, found on Linux, OpenBSD, and recently also
FreeBSD, can be used to get random bytes to initialize the PRNG.  It
is similar to the traditional way of reading from /dev/urandom, but
being a system call rather than a special file, it doesn't suffer from
problems like running out of file descriptors, or failure when running
in a container where /dev/urandom may not be available.

Regtested on x86_64-pc-linux-gnu, Ok for trunk?

2018-08-13  Janne Blomqvist  <jb@gcc.gnu.org>

	* configure.ac: Check for getentropy.
	* intrinsics/random.c (getosrandom): Use getentropy if available.
	* config.h.in: Regenerated.
	* configure: Regenerated.

From-SVN: r263522
parent 72217988
2018-08-13 Janne Blomqvist <jb@gcc.gnu.org>
* configure.ac: Check for getentropy.
* intrinsics/random.c (getosrandom): Use getentropy if available.
* config.h.in: Regenerated.
* configure: Regenerated.
2018-07-31 Andre Vieira <andre.simoesdiasvieira@arm.com> 2018-07-31 Andre Vieira <andre.simoesdiasvieira@arm.com>
Revert 'AsyncI/O patch committed' Revert 'AsyncI/O patch committed'
......
...@@ -453,6 +453,9 @@ ...@@ -453,6 +453,9 @@
/* Define to 1 if you have the `getegid' function. */ /* Define to 1 if you have the `getegid' function. */
#undef HAVE_GETEGID #undef HAVE_GETEGID
/* Define to 1 if you have the `getentropy' function. */
#undef HAVE_GETENTROPY
/* Define to 1 if you have the `geteuid' function. */ /* Define to 1 if you have the `geteuid' function. */
#undef HAVE_GETEUID #undef HAVE_GETEUID
......
...@@ -2570,6 +2570,7 @@ as_fn_append ac_func_list " snprintf" ...@@ -2570,6 +2570,7 @@ as_fn_append ac_func_list " snprintf"
as_fn_append ac_func_list " ftruncate" as_fn_append ac_func_list " ftruncate"
as_fn_append ac_func_list " chsize" as_fn_append ac_func_list " chsize"
as_fn_append ac_func_list " chdir" as_fn_append ac_func_list " chdir"
as_fn_append ac_func_list " getentropy"
as_fn_append ac_func_list " getlogin" as_fn_append ac_func_list " getlogin"
as_fn_append ac_func_list " gethostname" as_fn_append ac_func_list " gethostname"
as_fn_append ac_func_list " kill" as_fn_append ac_func_list " kill"
...@@ -12512,7 +12513,7 @@ else ...@@ -12512,7 +12513,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF cat > conftest.$ac_ext <<_LT_EOF
#line 12515 "configure" #line 12516 "configure"
#include "confdefs.h" #include "confdefs.h"
#if HAVE_DLFCN_H #if HAVE_DLFCN_H
...@@ -12618,7 +12619,7 @@ else ...@@ -12618,7 +12619,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF cat > conftest.$ac_ext <<_LT_EOF
#line 12621 "configure" #line 12622 "configure"
#include "confdefs.h" #include "confdefs.h"
#if HAVE_DLFCN_H #if HAVE_DLFCN_H
...@@ -16778,6 +16779,8 @@ done ...@@ -16778,6 +16779,8 @@ done
fi fi
# Check strerror_r, cannot be above as versions with two and three arguments exist # Check strerror_r, cannot be above as versions with two and three arguments exist
......
...@@ -312,7 +312,8 @@ if test "${hardwire_newlib:-0}" -eq 1; then ...@@ -312,7 +312,8 @@ if test "${hardwire_newlib:-0}" -eq 1; then
fi fi
else else
AC_CHECK_FUNCS_ONCE(getrusage times mkstemp strtof strtold snprintf \ AC_CHECK_FUNCS_ONCE(getrusage times mkstemp strtof strtold snprintf \
ftruncate chsize chdir getlogin gethostname kill link symlink sleep ttyname \ ftruncate chsize chdir getentropy getlogin gethostname kill link symlink \
sleep ttyname \
alarm access fork setmode fcntl \ alarm access fork setmode fcntl \
gettimeofday stat fstat lstat getpwuid vsnprintf dup \ gettimeofday stat fstat lstat getpwuid vsnprintf dup \
getcwd localtime_r gmtime_r getpwuid_r ttyname_r clock_gettime \ getcwd localtime_r gmtime_r getpwuid_r ttyname_r clock_gettime \
......
...@@ -310,11 +310,10 @@ getosrandom (void *buf, size_t buflen) ...@@ -310,11 +310,10 @@ getosrandom (void *buf, size_t buflen)
rand_s (&b[i]); rand_s (&b[i]);
return buflen; return buflen;
#else #else
/* #ifdef HAVE_GETENTROPY
TODO: When glibc adds a wrapper for the getrandom() system call if (getentropy (buf, buflen) == 0)
on Linux, one could use that. return 0;
#endif
TODO: One could use getentropy() on OpenBSD. */
int flags = O_RDONLY; int flags = O_RDONLY;
#ifdef O_CLOEXEC #ifdef O_CLOEXEC
flags |= O_CLOEXEC; flags |= O_CLOEXEC;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment