It was, unfortunately, filled with badgers.
* Don't take short reads for an answer. Loop until the read actually
fails, or we've filled the buffer.
* If we didn't actually read enough to fill the buffer, then don't
return success! The fallback collectors will engage and hopefully
save our bacon.
int fd;
octet buf[RAND_POOLSZ];
ssize_t len;
int fd;
octet buf[RAND_POOLSZ];
ssize_t len;
int ret = 0;
/* --- Be nice to other clients of the random device --- *
int ret = 0;
/* --- Be nice to other clients of the random device --- *
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 ((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);
close(fd);
}
noise_timer(r);