X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/0f00dc4c8eb47e67bc0f148c2dd109f73a451e0a..57354275bd678ce002781f7a64204c9a45b1928c:/rand/noise.c?ds=inline diff --git a/rand/noise.c b/rand/noise.c index 6ab1070f..00f036a8 100644 --- a/rand/noise.c +++ b/rand/noise.c @@ -156,6 +156,7 @@ int noise_devrandom(rand_pool *r) int fd; octet buf[RAND_POOLSZ]; ssize_t len; + size_t n = 0; int ret = 0; /* --- Be nice to other clients of the random device --- * @@ -169,11 +170,13 @@ int noise_devrandom(rand_pool *r) if ((fd = open("/dev/urandom", O_RDONLY | O_NONBLOCK)) >= 0 || (fd = open("/dev/arandom", O_RDONLY | O_NONBLOCK)) >= 0 || (fd = open("/dev/random", O_RDONLY | O_NONBLOCK)) >= 0) { - if ((len = read(fd, buf, sizeof(buf))) > 0) { - rand_add(r, buf, len, len * 8); - BURN(buf); - ret = 1; + while (n < sizeof(buf)) { + if ((len = read(fd, buf + n, sizeof(buf) - n)) <= 0) break; + n += len; } + rand_add(r, buf, n, n * 8); + BURN(buf); + if (n == sizeof(buf)) ret = 1; close(fd); } noise_timer(r);