diff options
author | Roderick Schertler <roderick@argon.org> | 1998-09-09 19:52:48 -0400 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1998-09-23 10:18:31 +0000 |
commit | 73c6029944b44f3e88040c33146d1e133b187ca4 (patch) | |
tree | 2a46fbd7edd26ff7215487f9807066d4a57b398f /pp.c | |
parent | e71965beff694bc98c9ae45ee14f91c321298f5b (diff) | |
download | perl-73c6029944b44f3e88040c33146d1e133b187ca4.tar.gz |
seed srand from /dev/urandom when possible
Message-ID: <20567.905399568@eeyore.ibcinc.com>
p4raw-id: //depot/perl@1847
Diffstat (limited to 'pp.c')
-rw-r--r-- | pp.c | 33 |
1 files changed, 31 insertions, 2 deletions
@@ -1638,21 +1638,50 @@ seed(void) #define SEED_C5 26107 dTHR; +#ifndef PERL_NO_DEV_RANDOM + int fd; +#endif U32 u; #ifdef VMS # include <starlet.h> /* when[] = (low 32 bits, high 32 bits) of time since epoch * in 100-ns units, typically incremented ever 10 ms. */ unsigned int when[2]; +#else +# ifdef HAS_GETTIMEOFDAY + struct timeval when; +# else + Time_t when; +# endif +#endif + +/* This test is an escape hatch, this symbol isn't set by Configure. */ +#ifndef PERL_NO_DEV_RANDOM +#ifndef PERL_RANDOM_DEVICE + /* /dev/random isn't used by default because reads from it will block + * if there isn't enough entropy available. You can compile with + * PERL_RANDOM_DEVICE to it if you'd prefer Perl to block until there + * is enough real entropy to fill the seed. */ +# define PERL_RANDOM_DEVICE "/dev/urandom" +#endif + fd = PerlLIO_open(PERL_RANDOM_DEVICE, 0); + if (fd != -1) { + if (PerlLIO_read(fd, &u, sizeof u) != sizeof u) + u = 0; + PerlLIO_close(fd); + if (u) + return u; + } +#endif + +#ifdef VMS _ckvmssts(sys$gettim(when)); u = (U32)SEED_C1 * when[0] + (U32)SEED_C2 * when[1]; #else # ifdef HAS_GETTIMEOFDAY - struct timeval when; gettimeofday(&when,(struct timezone *) 0); u = (U32)SEED_C1 * when.tv_sec + (U32)SEED_C2 * when.tv_usec; # else - Time_t when; (void)time(&when); u = (U32)SEED_C1 * when; # endif |