From 053dd57da26bcda9f03180758fce81fffe7747c8 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 31 May 2020 13:44:04 +0200 Subject: [PATCH] getrandom: Simplify the determination of the random number devices. Suggested by Paul Eggert in . * lib/getrandom.c (NAME_OF_RANDOM_DEVICE, NAME_OF_NONCE_DEVICE): New macros. * modules/getrandom (Depends-on): Remove crypto/gc-random. --- ChangeLog | 9 +++++++++ lib/getrandom.c | 19 +++++++++++++++++++ modules/getrandom | 1 - 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index cacd4c0f5c..f7c9b4dfb0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2020-05-31 Bruno Haible + + getrandom: Simplify the determination of the random number devices. + Suggested by Paul Eggert in + . + * lib/getrandom.c (NAME_OF_RANDOM_DEVICE, NAME_OF_NONCE_DEVICE): New + macros. + * modules/getrandom (Depends-on): Remove crypto/gc-random. + 2020-05-31 Bruno Haible crypto/gc-random: Fix list of crypto devices for Solaris. diff --git a/lib/getrandom.c b/lib/getrandom.c index f20ffe0112..0cc3dc3d85 100644 --- a/lib/getrandom.c +++ b/lib/getrandom.c @@ -27,6 +27,25 @@ #include "minmax.h" +/* These devices exist on all platforms except native Windows. */ +#if !(defined _WIN32 && ! defined __CYGWIN__) + +/* Name of a device through which the kernel returns high quality random + numbers, from an entropy pool. When the pool is empty, the call blocks + until entropy sources have added enough bits of entropy. */ +# ifndef NAME_OF_RANDOM_DEVICE +# define NAME_OF_RANDOM_DEVICE "/dev/random" +# endif + +/* Name of a device through which the kernel returns random or pseudo-random + numbers. It uses an entropy pool, but, in order to avoid blocking, adds + bits generated by a pseudo-random number generator, as needed. */ +# ifndef NAME_OF_NONCE_DEVICE +# define NAME_OF_NONCE_DEVICE "/dev/urandom" +# endif + +#endif + /* Set BUFFER (of size LENGTH) to random bytes under the control of FLAGS. Return the number of bytes written, or -1 on error. */ ssize_t diff --git a/modules/getrandom b/modules/getrandom index e94686d6ff..8aa4be2b78 100644 --- a/modules/getrandom +++ b/modules/getrandom @@ -7,7 +7,6 @@ m4/getrandom.m4 Depends-on: sys_random -crypto/gc-random [test $HAVE_GETRANDOM = 0] fcntl-h [test $HAVE_GETRANDOM = 0 || test $REPLACE_GETRANDOM = 1] minmax [test $HAVE_GETRANDOM = 0 || test $REPLACE_GETRANDOM = 1] open [test $HAVE_GETRANDOM = 0 || test $REPLACE_GETRANDOM = 1] -- 2.39.5