summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>2014-07-08 09:24:28 +0000
committerBob Beck <beck@cvs.openbsd.org>2014-07-08 09:24:28 +0000
commit7827b31862b5d0fb34d8ef9828c2cf08a4be0b38 (patch)
tree9da888c83410f2e51d6efdceba445401a5ea113f /lib
parentc3ed64f9681bd3f23f1ad14be3ecdeba81abcc00 (diff)
unbreak last commit - but same intent, make re-seed less expensive
Diffstat (limited to 'lib')
-rw-r--r--lib/libcrypto/crypto/getentropy_linux.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/lib/libcrypto/crypto/getentropy_linux.c b/lib/libcrypto/crypto/getentropy_linux.c
index a7f5991201b..a76604fe77a 100644
--- a/lib/libcrypto/crypto/getentropy_linux.c
+++ b/lib/libcrypto/crypto/getentropy_linux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getentropy_linux.c,v 1.15 2014/07/08 08:33:43 deraadt Exp $ */
+/* $OpenBSD: getentropy_linux.c,v 1.16 2014/07/08 09:24:27 beck Exp $ */
/*
* Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org>
@@ -288,7 +288,7 @@ static int
getentropy_fallback(void *buf, size_t len)
{
uint8_t results[SHA512_DIGEST_LENGTH];
- int save_errno = errno, e, m, pgs = getpagesize(), repeat = 0;
+ int save_errno = errno, e, m, pgs = getpagesize(), faster = 0, repeat;
static int cnt;
struct timespec ts;
struct timeval tv;
@@ -298,19 +298,21 @@ getentropy_fallback(void *buf, size_t len)
SHA512_CTX ctx;
static pid_t lastpid;
pid_t pid;
- size_t i, ii;
+ size_t i, j, ii;
char *p;
pid = getpid();
- if (lastpid == getpid())
- repeat = REPEAT - 1;
- else
+ if (lastpid == pid) {
+ faster = 1;
+ repeat = 2;
+ } else {
+ faster = 0;
lastpid = pid;
-
+ repeat = REPEAT;
+ }
for (i = 0; i < len; ) {
SHA512_Init(&ctx);
- for (; repeat < REPEAT; repeat++) {
-
+ for (j = 0; j < repeat; j++) {
HX((e = gettimeofday(&tv, NULL)) == -1, tv);
if (e != -1) {
cnt += (int)tv.tv_sec;
@@ -326,9 +328,11 @@ getentropy_fallback(void *buf, size_t len)
HX((pid = getpgid(0)) == -1, pid);
HX((m = getpriority(0, 0)) == -1, m);
- ts.tv_sec = 0;
- ts.tv_nsec = 1;
- (void) nanosleep(&ts, NULL);
+ if (!faster) {
+ ts.tv_sec = 0;
+ ts.tv_nsec = 1;
+ (void) nanosleep(&ts, NULL);
+ }
HX(sigpending(&sigset) == -1, sigset);
HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1,