diff --git a/configure.in b/configure.in index 2b5fadc..814dbde 100644 --- a/configure.in +++ b/configure.in @@ -6,6 +6,6 @@ AC_PATH_PROG(MV, mv, mv) AC_PATH_PROG(RM, rm, rm) AC_PATH_PROG(SED, sed, sed) AC_PATH_PROG(PERL, perl, perl) -AC_CHECK_FUNCS(drand48 getopt_long) +AC_CHECK_FUNCS(getopt_long) AC_CHECK_HEADERS(getopt.h) AC_OUTPUT(Makefile) diff --git a/randnum.c b/randnum.c index 036e092..05e2af4 100644 --- a/randnum.c +++ b/randnum.c @@ -7,6 +7,7 @@ * License. */ +#include #include #include #include @@ -28,29 +29,13 @@ static int get_random_fd() { struct timeval tv; static int fd = -2; - int i; if (fd == -2) { gettimeofday(&tv, 0); fd = open("/dev/urandom", O_RDONLY); if (fd == -1) fd = open("/dev/random", O_RDONLY | O_NONBLOCK); -#ifdef HAVE_DRAND48 - srand48((tv.tv_sec<<9) ^ (getpgrp()<<15) ^ - (getpid()) ^ (tv.tv_usec>>11)); -#else - srandom((getpid() << 16) ^ (getpgrp() << 8) ^ getuid() - ^ tv.tv_sec ^ tv.tv_usec); -#endif } - /* Crank the random number generator a few times */ - gettimeofday(&tv, 0); - for (i = (tv.tv_sec ^ tv.tv_usec) & 0x1F; i > 0; i--) -#ifdef HAVE_DRAND48 - drand48(); -#else - random(); -#endif return fd; } @@ -85,11 +70,8 @@ int pw_random_number(max_num) if (nbytes == 0) return (rand_num % max_num); - /* OK, we weren't able to use /dev/random, fall back to rand/rand48 */ + /* We weren't able to use /dev/random, fail hard */ -#ifdef HAVE_DRAND48 - return ((int) ((drand48() * max_num))); -#else - return ((int) (random() / ((float) RAND_MAX) * max_num)); -#endif + fprintf(stderr, "No entropy available!\n"); + exit(1); }