X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/ecc296ebb74bb17cfb9998972a4bc28b91e82da0..baf5b59c8aad82395688f0a96efcfba4e16b8fc2:/rand/noise.c diff --git a/rand/noise.c b/rand/noise.c index 6458f92d..b59fd8ad 100644 --- a/rand/noise.c +++ b/rand/noise.c @@ -29,6 +29,7 @@ #include "config.h" +#include #include #include #include @@ -46,6 +47,11 @@ # include #endif +#if defined(HAVE_LINUX_RANDOM_H) +# include +# include +#endif + #include #include #include @@ -167,6 +173,22 @@ int noise_devrandom(rand_pool *r) struct timeval tv = { 0, 0 }; #endif +#if defined(HAVE_LINUX_RANDOM_H) && \ + defined(GRND_NONBLOCK) && \ + defined(SYS_getrandom) + /* --- Use the new shinies if available --- */ + + while (n < sizeof(buf)) { + if ((len = syscall(SYS_getrandom, buf + n, sizeof(buf) - n, + GRND_NONBLOCK)) <= 0) { + if (errno == ENOSYS) break; + else goto done; + } + n += len; + } + if (n == sizeof(buf)) goto win; +#endif + #ifdef __linux__ /* --- Don't take from `/dev/urandom' if `/dev/random' would block --- */