aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac6
-rw-r--r--src/utils.c12
2 files changed, 8 insertions, 10 deletions
diff --git a/configure.ac b/configure.ac
index eeb6634..6d907bd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -149,11 +149,7 @@ dnl Check for more secure randomization functions
AC_CHECK_HEADERS([bsd/stdlib.h],, [random_enabled=yes])
AC_SEARCH_LIBS([arc4random], [bsd],,,)
AC_CHECK_FUNCS([arc4random], [random_enabled=],)
-if test x"${random_enabled}" != x; then
- AC_CHECK_FUNCS([timespec_get srandom random],
- [random_enabled=yes],
- [random_enabled=])
-else
+if test x"${random_enabled}" = x; then
arc4random_enabled=yes
fi
diff --git a/src/utils.c b/src/utils.c
index bd3ea0e..7e8adb1 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -161,11 +161,13 @@ int pt_random(void) {
#ifndef TIME_UTC
#define TIME_UTC 1
#endif
- struct timespec ts;
-
- assert(timespec_get(&ts, TIME_UTC));
- srandom(ts.tv_nsec ^ ts.tv_sec);
- return random();
+ static int rng_fd = -1;
+ int rnd_val;
+ if (rng_fd < 0)
+ rng_fd = open("/dev/random", O_RDONLY);
+ assert(rng_fd >= 0);
+ assert( read(rng_fd, &rnd_val, sizeof rnd_val) == sizeof rnd_val ):
+ return rnd_val;
#else
srand(time(0));
return rand();