Commit 5c8b413f authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Use /dev/urandom on all platforms.

/dev/arandom, which was previously used on OpenBSD, is not useful since
we're only using it for seeding the prng.
parent e59fa382
...@@ -77,32 +77,24 @@ gettime(struct timeval *tv) ...@@ -77,32 +77,24 @@ gettime(struct timeval *tv)
return rc; return rc;
} }
#if defined(__linux) /* If /dev/urandom doesn't exist, this will fail with ENOENT, which the
#define RND_DEV "/dev/urandom" caller will deal with gracefully. */
#elif defined (__OpenBSD__)
#define RND_DEV "/dev/arandom"
#endif
int int
read_random_bytes(void *buf, size_t len) read_random_bytes(void *buf, size_t len)
{ {
int rfd; int fd;
int rc; int rc;
#ifdef RND_DEV fd = open("/dev/urandom", O_RDONLY);
rfd = open(RND_DEV, O_RDONLY); if(fd < 0) {
if(rfd < 0) {
rc = -1; rc = -1;
} else { } else {
rc = read(rfd, buf, len); rc = read(fd, buf, len);
if(rc < len) if(rc < len)
rc = -1; rc = -1;
close(rfd); close(fd);
} }
#else
rc = -1;
errno = ENOSYS;
#endif
return rc; return rc;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment