diff --git a/lib/hcrypto/rand-unix.c b/lib/hcrypto/rand-unix.c index 001ef606c..2d6013eb3 100644 --- a/lib/hcrypto/rand-unix.c +++ b/lib/hcrypto/rand-unix.c @@ -68,8 +68,33 @@ _hc_unix_device_fd(int flags, const char **fn) } static void -unix_seed(const void *indata, int size) +unix_seed(const void *p, int size) { + const unsigned char *indata = p; + ssize_t count; + int fd; + + if (size < 0) + return; + else if (size == 0) + return; + + fd = _hc_unix_device_fd(O_RDONLY, NULL); + if (fd < 0) + return; + + while (size > 0) { + count = write(fd, indata, size); + if (count < 0 && errno == EINTR) + continue; + else if (count <= 0) { + close(fd); + return; + } + indata += count; + size -= count; + } + close(fd); }