~mdw
/
catacomb
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
rand/noise.c (noise_devrandom): Use OpenBSD system call `getentropy'.
[catacomb]
/
rand
/
noise.c
diff --git
a/rand/noise.c
b/rand/noise.c
index
b59fd8a
..
2c30c13
100644
(file)
--- 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
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) && \
#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
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 --- */
#ifdef __linux__
/* --- Don't take from `/dev/urandom' if `/dev/random' would block --- */