diff options
author | beck <> | 2014-07-08 09:24:27 +0000 |
---|---|---|
committer | beck <> | 2014-07-08 09:24:27 +0000 |
commit | 51f59d99602fb922af863ded116b420c942501b4 (patch) | |
tree | 3da619e322eb3fc21a121ee9e4588747dce257e3 | |
parent | c5ec62bcb78f8eaf6e96ecf6368697815f196216 (diff) | |
download | openbsd-51f59d99602fb922af863ded116b420c942501b4.tar.gz openbsd-51f59d99602fb922af863ded116b420c942501b4.tar.bz2 openbsd-51f59d99602fb922af863ded116b420c942501b4.zip |
unbreak last commit - but same intent, make re-seed less expensive
-rw-r--r-- | src/lib/libcrypto/arc4random/getentropy_linux.c | 28 | ||||
-rw-r--r-- | src/lib/libcrypto/crypto/getentropy_linux.c | 28 |
2 files changed, 32 insertions, 24 deletions
diff --git a/src/lib/libcrypto/arc4random/getentropy_linux.c b/src/lib/libcrypto/arc4random/getentropy_linux.c index a7f5991201..a76604fe77 100644 --- a/src/lib/libcrypto/arc4random/getentropy_linux.c +++ b/src/lib/libcrypto/arc4random/getentropy_linux.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: getentropy_linux.c,v 1.15 2014/07/08 08:33:43 deraadt Exp $ */ | 1 | /* $OpenBSD: getentropy_linux.c,v 1.16 2014/07/08 09:24:27 beck Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org> | 4 | * Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org> |
@@ -288,7 +288,7 @@ static int | |||
288 | getentropy_fallback(void *buf, size_t len) | 288 | getentropy_fallback(void *buf, size_t len) |
289 | { | 289 | { |
290 | uint8_t results[SHA512_DIGEST_LENGTH]; | 290 | uint8_t results[SHA512_DIGEST_LENGTH]; |
291 | int save_errno = errno, e, m, pgs = getpagesize(), repeat = 0; | 291 | int save_errno = errno, e, m, pgs = getpagesize(), faster = 0, repeat; |
292 | static int cnt; | 292 | static int cnt; |
293 | struct timespec ts; | 293 | struct timespec ts; |
294 | struct timeval tv; | 294 | struct timeval tv; |
@@ -298,19 +298,21 @@ getentropy_fallback(void *buf, size_t len) | |||
298 | SHA512_CTX ctx; | 298 | SHA512_CTX ctx; |
299 | static pid_t lastpid; | 299 | static pid_t lastpid; |
300 | pid_t pid; | 300 | pid_t pid; |
301 | size_t i, ii; | 301 | size_t i, j, ii; |
302 | char *p; | 302 | char *p; |
303 | 303 | ||
304 | pid = getpid(); | 304 | pid = getpid(); |
305 | if (lastpid == getpid()) | 305 | if (lastpid == pid) { |
306 | repeat = REPEAT - 1; | 306 | faster = 1; |
307 | else | 307 | repeat = 2; |
308 | } else { | ||
309 | faster = 0; | ||
308 | lastpid = pid; | 310 | lastpid = pid; |
309 | 311 | repeat = REPEAT; | |
312 | } | ||
310 | for (i = 0; i < len; ) { | 313 | for (i = 0; i < len; ) { |
311 | SHA512_Init(&ctx); | 314 | SHA512_Init(&ctx); |
312 | for (; repeat < REPEAT; repeat++) { | 315 | for (j = 0; j < repeat; j++) { |
313 | |||
314 | HX((e = gettimeofday(&tv, NULL)) == -1, tv); | 316 | HX((e = gettimeofday(&tv, NULL)) == -1, tv); |
315 | if (e != -1) { | 317 | if (e != -1) { |
316 | cnt += (int)tv.tv_sec; | 318 | cnt += (int)tv.tv_sec; |
@@ -326,9 +328,11 @@ getentropy_fallback(void *buf, size_t len) | |||
326 | HX((pid = getpgid(0)) == -1, pid); | 328 | HX((pid = getpgid(0)) == -1, pid); |
327 | HX((m = getpriority(0, 0)) == -1, m); | 329 | HX((m = getpriority(0, 0)) == -1, m); |
328 | 330 | ||
329 | ts.tv_sec = 0; | 331 | if (!faster) { |
330 | ts.tv_nsec = 1; | 332 | ts.tv_sec = 0; |
331 | (void) nanosleep(&ts, NULL); | 333 | ts.tv_nsec = 1; |
334 | (void) nanosleep(&ts, NULL); | ||
335 | } | ||
332 | 336 | ||
333 | HX(sigpending(&sigset) == -1, sigset); | 337 | HX(sigpending(&sigset) == -1, sigset); |
334 | HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1, | 338 | HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1, |
diff --git a/src/lib/libcrypto/crypto/getentropy_linux.c b/src/lib/libcrypto/crypto/getentropy_linux.c index a7f5991201..a76604fe77 100644 --- a/src/lib/libcrypto/crypto/getentropy_linux.c +++ b/src/lib/libcrypto/crypto/getentropy_linux.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: getentropy_linux.c,v 1.15 2014/07/08 08:33:43 deraadt Exp $ */ | 1 | /* $OpenBSD: getentropy_linux.c,v 1.16 2014/07/08 09:24:27 beck Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org> | 4 | * Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org> |
@@ -288,7 +288,7 @@ static int | |||
288 | getentropy_fallback(void *buf, size_t len) | 288 | getentropy_fallback(void *buf, size_t len) |
289 | { | 289 | { |
290 | uint8_t results[SHA512_DIGEST_LENGTH]; | 290 | uint8_t results[SHA512_DIGEST_LENGTH]; |
291 | int save_errno = errno, e, m, pgs = getpagesize(), repeat = 0; | 291 | int save_errno = errno, e, m, pgs = getpagesize(), faster = 0, repeat; |
292 | static int cnt; | 292 | static int cnt; |
293 | struct timespec ts; | 293 | struct timespec ts; |
294 | struct timeval tv; | 294 | struct timeval tv; |
@@ -298,19 +298,21 @@ getentropy_fallback(void *buf, size_t len) | |||
298 | SHA512_CTX ctx; | 298 | SHA512_CTX ctx; |
299 | static pid_t lastpid; | 299 | static pid_t lastpid; |
300 | pid_t pid; | 300 | pid_t pid; |
301 | size_t i, ii; | 301 | size_t i, j, ii; |
302 | char *p; | 302 | char *p; |
303 | 303 | ||
304 | pid = getpid(); | 304 | pid = getpid(); |
305 | if (lastpid == getpid()) | 305 | if (lastpid == pid) { |
306 | repeat = REPEAT - 1; | 306 | faster = 1; |
307 | else | 307 | repeat = 2; |
308 | } else { | ||
309 | faster = 0; | ||
308 | lastpid = pid; | 310 | lastpid = pid; |
309 | 311 | repeat = REPEAT; | |
312 | } | ||
310 | for (i = 0; i < len; ) { | 313 | for (i = 0; i < len; ) { |
311 | SHA512_Init(&ctx); | 314 | SHA512_Init(&ctx); |
312 | for (; repeat < REPEAT; repeat++) { | 315 | for (j = 0; j < repeat; j++) { |
313 | |||
314 | HX((e = gettimeofday(&tv, NULL)) == -1, tv); | 316 | HX((e = gettimeofday(&tv, NULL)) == -1, tv); |
315 | if (e != -1) { | 317 | if (e != -1) { |
316 | cnt += (int)tv.tv_sec; | 318 | cnt += (int)tv.tv_sec; |
@@ -326,9 +328,11 @@ getentropy_fallback(void *buf, size_t len) | |||
326 | HX((pid = getpgid(0)) == -1, pid); | 328 | HX((pid = getpgid(0)) == -1, pid); |
327 | HX((m = getpriority(0, 0)) == -1, m); | 329 | HX((m = getpriority(0, 0)) == -1, m); |
328 | 330 | ||
329 | ts.tv_sec = 0; | 331 | if (!faster) { |
330 | ts.tv_nsec = 1; | 332 | ts.tv_sec = 0; |
331 | (void) nanosleep(&ts, NULL); | 333 | ts.tv_nsec = 1; |
334 | (void) nanosleep(&ts, NULL); | ||
335 | } | ||
332 | 336 | ||
333 | HX(sigpending(&sigset) == -1, sigset); | 337 | HX(sigpending(&sigset) == -1, sigset); |
334 | HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1, | 338 | HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1, |