X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/baf5b59c8aad82395688f0a96efcfba4e16b8fc2..6d4416ccb0bbe02105c4b9dfa1442b9198c0d923:/rand/noise.c diff --git a/rand/noise.c b/rand/noise.c index b59fd8ad..2c30c13c 100644 --- a/rand/noise.c +++ b/rand/noise.c @@ -172,6 +172,9 @@ int noise_devrandom(rand_pool *r) fd_set infd; struct timeval tv = { 0, 0 }; #endif +#ifdef HAVE_GETENTROPY + size_t nn; +#endif #if defined(HAVE_LINUX_RANDOM_H) && \ defined(GRND_NONBLOCK) && \ @@ -189,6 +192,18 @@ int noise_devrandom(rand_pool *r) if (n == sizeof(buf)) goto win; #endif +#ifdef HAVE_GETENTROPY + /* --- OpenBSD-flavoured shinies --- */ + + while (n < sizeof(buf)) { + nn = sizeof(buf) - nn; + if (nn > 256) nn = 256; + if (getentropy(buf + n, nn)) break; + n += nn; + } + if (n == sizeof(buf)) goto win; +#endif + #ifdef __linux__ /* --- Don't take from `/dev/urandom' if `/dev/random' would block --- */