diff options
author | Jakob Schlyter <jakob@cvs.openbsd.org> | 2003-01-20 21:30:08 +0000 |
---|---|---|
committer | Jakob Schlyter <jakob@cvs.openbsd.org> | 2003-01-20 21:30:08 +0000 |
commit | 1cc2cddc4e82d73456d0eaa4aa4648a1c2371eea (patch) | |
tree | 6d5f59b1d674bfda270d15b4ef715c4f2592c9c6 /usr.sbin/bind/lib | |
parent | 80ca516330904d2aee1365d9f69019bebaad352a (diff) |
use arc4random() instead of rand() if availible
Diffstat (limited to 'usr.sbin/bind/lib')
-rw-r--r-- | usr.sbin/bind/lib/isc/random.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/usr.sbin/bind/lib/isc/random.c b/usr.sbin/bind/lib/isc/random.c index e9b06c31913..d74873aaa78 100644 --- a/usr.sbin/bind/lib/isc/random.c +++ b/usr.sbin/bind/lib/isc/random.c @@ -33,7 +33,9 @@ static isc_once_t once = ISC_ONCE_INIT; static void initialize_rand(void) { +#ifndef HAVE_ARC4RANDOM srand(time(NULL)); +#endif } static void @@ -47,7 +49,11 @@ isc_random_seed(isc_uint32_t seed) { initialize(); +#ifndef HAVE_ARC4RANDOM srand(seed); +#else + arc4random_addrandom((u_char *) &seed, sizeof(isc_uint32_t)); +#endif } void @@ -57,7 +63,11 @@ isc_random_get(isc_uint32_t *val) initialize(); +#ifndef HAVE_ARC4RANDOM *val = rand(); +#else + *val = arc4random(); +#endif } isc_uint32_t @@ -66,5 +76,9 @@ isc_random_jitter(isc_uint32_t max, isc_uint32_t jitter) { if (jitter == 0) return (max); else +#ifndef HAVE_ARC4RANDOM return (max - rand() % jitter); +#else + return (max - arc4random() % jitter); +#endif } |