|
|
@ -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, |
|
|
|