diff options
author | Jakob Schlyter <jakob@cvs.openbsd.org> | 2003-11-18 14:14:09 +0000 |
---|---|---|
committer | Jakob Schlyter <jakob@cvs.openbsd.org> | 2003-11-18 14:14:09 +0000 |
commit | a3684c7a7fae3c0a0ad3d9641d29affc2b8aed03 (patch) | |
tree | bd1bf1ed050890b02d624a1468c39c2822f5ce45 /usr.sbin/bind/lib/isc/random.c | |
parent | 2177e8980dbcbd0b8006b290bb9de8e8565df3ba (diff) |
update to BIND v9.2.3. ok todd@
Diffstat (limited to 'usr.sbin/bind/lib/isc/random.c')
-rw-r--r-- | usr.sbin/bind/lib/isc/random.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/usr.sbin/bind/lib/isc/random.c b/usr.sbin/bind/lib/isc/random.c index d74873aaa78..6d7ec5835e8 100644 --- a/usr.sbin/bind/lib/isc/random.c +++ b/usr.sbin/bind/lib/isc/random.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1999-2001 Internet Software Consortium. + * Copyright (C) 1999-2001, 2003 Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -15,12 +15,18 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $ISC: random.c,v 1.15 2001/01/09 21:56:22 bwelling Exp $ */ +/* $ISC: random.c,v 1.15.2.4 2003/10/09 07:32:49 marka Exp $ */ #include <config.h> #include <stdlib.h> #include <time.h> /* Required for time(). */ +#ifdef HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif #include <isc/mutex.h> #include <isc/once.h> @@ -34,7 +40,15 @@ static void initialize_rand(void) { #ifndef HAVE_ARC4RANDOM - srand(time(NULL)); + unsigned int pid = getpid(); + + /* + * The low bits of pid generally change faster. + * Xor them with the high bits of time which change slowly. + */ + pid = ((pid << 16) & 0xffff0000) | ((pid >> 16) & 0xffff); + + srand(time(NULL) ^ pid); #endif } @@ -64,7 +78,11 @@ isc_random_get(isc_uint32_t *val) initialize(); #ifndef HAVE_ARC4RANDOM - *val = rand(); + /* + * rand()'s lower bits are not random. + * rand()'s upper bit is zero. + */ + *val = ((rand() >> 4) & 0xffff) | ((rand() << 12) & 0xffff0000) ; #else *val = arc4random(); #endif |