summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/crypto/getentropy_solaris.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/crypto/getentropy_solaris.c')
-rw-r--r--src/lib/libcrypto/crypto/getentropy_solaris.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/lib/libcrypto/crypto/getentropy_solaris.c b/src/lib/libcrypto/crypto/getentropy_solaris.c
index 83cc30aac2..cfd5b70475 100644
--- a/src/lib/libcrypto/crypto/getentropy_solaris.c
+++ b/src/lib/libcrypto/crypto/getentropy_solaris.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: getentropy_solaris.c,v 1.3 2014/07/12 14:46:31 deraadt Exp $ */ 1/* $OpenBSD: getentropy_solaris.c,v 1.4 2014/07/12 20:41:47 wouter 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>
@@ -60,6 +60,7 @@
60 60
61#define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l))) 61#define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l)))
62#define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x))) 62#define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x)))
63#define HF(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (void*)))
63 64
64int getentropy(void *buf, size_t len); 65int getentropy(void *buf, size_t len);
65 66
@@ -194,7 +195,7 @@ start:
194 } 195 }
195 for (i = 0; i < len; ) { 196 for (i = 0; i < len; ) {
196 size_t wanted = len - i; 197 size_t wanted = len - i;
197 ssize_t ret = read(fd, buf + i, wanted); 198 ssize_t ret = read(fd, (char *)buf + i, wanted);
198 199
199 if (ret == -1) { 200 if (ret == -1) {
200 if (errno == EAGAIN || errno == EINTR) 201 if (errno == EAGAIN || errno == EINTR)
@@ -243,7 +244,7 @@ static int
243getentropy_fallback(void *buf, size_t len) 244getentropy_fallback(void *buf, size_t len)
244{ 245{
245 uint8_t results[SHA512_DIGEST_LENGTH]; 246 uint8_t results[SHA512_DIGEST_LENGTH];
246 int save_errno = errno, e, m, pgs = getpagesize(), faster = 0, repeat; 247 int save_errno = errno, e, pgs = getpagesize(), faster = 0, repeat;
247 static int cnt; 248 static int cnt;
248 struct timespec ts; 249 struct timespec ts;
249 struct timeval tv; 250 struct timeval tv;
@@ -254,7 +255,7 @@ getentropy_fallback(void *buf, size_t len)
254 SHA512_CTX ctx; 255 SHA512_CTX ctx;
255 static pid_t lastpid; 256 static pid_t lastpid;
256 pid_t pid; 257 pid_t pid;
257 size_t i, ii; 258 size_t i, ii, m;
258 char *p; 259 char *p;
259 260
260 pid = getpid(); 261 pid = getpid();
@@ -283,7 +284,7 @@ getentropy_fallback(void *buf, size_t len)
283 HX((pid = getsid(pid)) == -1, pid); 284 HX((pid = getsid(pid)) == -1, pid);
284 HX((pid = getppid()) == -1, pid); 285 HX((pid = getppid()) == -1, pid);
285 HX((pid = getpgid(0)) == -1, pid); 286 HX((pid = getpgid(0)) == -1, pid);
286 HX((m = getpriority(0, 0)) == -1, m); 287 HX((e = getpriority(0, 0)) == -1, e);
287 HX((getloadavg(loadavg, 3) == -1), loadavg); 288 HX((getloadavg(loadavg, 3) == -1), loadavg);
288 289
289 if (!faster) { 290 if (!faster) {
@@ -296,9 +297,9 @@ getentropy_fallback(void *buf, size_t len)
296 HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1, 297 HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1,
297 sigset); 298 sigset);
298 299
299 HD(main); /* an addr in program */ 300 HF(main); /* an addr in program */
300 HD(getentropy); /* an addr in this library */ 301 HF(getentropy); /* an addr in this library */
301 HD(printf); /* an addr in libc */ 302 HF(printf); /* an addr in libc */
302 p = (char *)&p; 303 p = (char *)&p;
303 HD(p); /* an addr on stack */ 304 HD(p); /* an addr on stack */
304 p = (char *)&errno; 305 p = (char *)&errno;
@@ -416,7 +417,7 @@ getentropy_fallback(void *buf, size_t len)
416 HD(cnt); 417 HD(cnt);
417 } 418 }
418 SHA512_Final(results, &ctx); 419 SHA512_Final(results, &ctx);
419 memcpy(buf + i, results, min(sizeof(results), len - i)); 420 memcpy((char *)buf + i, results, min(sizeof(results), len - i));
420 i += min(sizeof(results), len - i); 421 i += min(sizeof(results), len - i);
421 } 422 }
422 memset(results, 0, sizeof results); 423 memset(results, 0, sizeof results);