diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/net/res_random.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/lib/libc/net/res_random.c b/src/lib/libc/net/res_random.c index d1cb0a0cf4..78cd2c3bb0 100644 --- a/src/lib/libc/net/res_random.c +++ b/src/lib/libc/net/res_random.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: res_random.c,v 1.18 2013/03/26 17:29:04 eric Exp $ */ | 1 | /* $OpenBSD: res_random.c,v 1.19 2013/04/17 03:07:40 deraadt Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> | 4 | * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> |
| @@ -100,7 +100,7 @@ static u_int16_t ru_g; | |||
| 100 | static u_int16_t ru_counter = 0; | 100 | static u_int16_t ru_counter = 0; |
| 101 | static u_int16_t ru_msb = 0; | 101 | static u_int16_t ru_msb = 0; |
| 102 | static struct prf_ctx *ru_prf = NULL; | 102 | static struct prf_ctx *ru_prf = NULL; |
| 103 | static long ru_reseed; | 103 | static time_t ru_reseed; |
| 104 | 104 | ||
| 105 | static u_int16_t pmod(u_int16_t, u_int16_t, u_int16_t); | 105 | static u_int16_t pmod(u_int16_t, u_int16_t, u_int16_t); |
| 106 | static void res_initid(void); | 106 | static void res_initid(void); |
| @@ -174,7 +174,7 @@ res_initid(void) | |||
| 174 | u_int16_t j, i; | 174 | u_int16_t j, i; |
| 175 | u_int32_t tmp; | 175 | u_int32_t tmp; |
| 176 | int noprime = 1; | 176 | int noprime = 1; |
| 177 | struct timeval tv; | 177 | struct timespec ts; |
| 178 | 178 | ||
| 179 | ru_x = arc4random_uniform(RU_M); | 179 | ru_x = arc4random_uniform(RU_M); |
| 180 | 180 | ||
| @@ -218,23 +218,23 @@ res_initid(void) | |||
| 218 | if (ru_prf != NULL) | 218 | if (ru_prf != NULL) |
| 219 | arc4random_buf(ru_prf, sizeof(*ru_prf)); | 219 | arc4random_buf(ru_prf, sizeof(*ru_prf)); |
| 220 | 220 | ||
| 221 | gettimeofday(&tv, NULL); | 221 | clock_gettime(CLOCK_MONOTONIC, &ts); |
| 222 | ru_reseed = tv.tv_sec + RU_OUT; | 222 | ru_reseed = ts.tv_sec + RU_OUT; |
| 223 | ru_msb = ru_msb == 0x8000 ? 0 : 0x8000; | 223 | ru_msb = ru_msb == 0x8000 ? 0 : 0x8000; |
| 224 | } | 224 | } |
| 225 | 225 | ||
| 226 | u_int | 226 | u_int |
| 227 | res_randomid(void) | 227 | res_randomid(void) |
| 228 | { | 228 | { |
| 229 | struct timeval tv; | 229 | struct timespec ts; |
| 230 | u_int r; | 230 | u_int r; |
| 231 | _THREAD_PRIVATE_MUTEX(random); | 231 | _THREAD_PRIVATE_MUTEX(random); |
| 232 | 232 | ||
| 233 | gettimeofday(&tv, NULL); | 233 | clock_gettime(CLOCK_MONOTONIC, &ts); |
| 234 | 234 | ||
| 235 | _THREAD_PRIVATE_MUTEX_LOCK(random); | 235 | _THREAD_PRIVATE_MUTEX_LOCK(random); |
| 236 | 236 | ||
| 237 | if (ru_counter >= RU_MAX || tv.tv_sec > ru_reseed) | 237 | if (ru_counter >= RU_MAX || ts.tv_sec > ru_reseed) |
| 238 | res_initid(); | 238 | res_initid(); |
| 239 | 239 | ||
| 240 | /* Linear Congruential Generator */ | 240 | /* Linear Congruential Generator */ |
