mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-04 08:35:31 +00:00
1405. [func] Use arc4random() if available.
from: jakob@crt.se reviewed: marka
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: random.c,v 1.15 2001/01/09 21:56:22 bwelling Exp $ */
|
||||
/* $Id: random.c,v 1.16 2002/12/04 01:19:28 marka Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user