summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/crypto/getentropy_osx.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/crypto/getentropy_osx.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/lib/libcrypto/crypto/getentropy_osx.c b/src/lib/libcrypto/crypto/getentropy_osx.c
index 67583f9e13..c7e09c78a5 100644
--- a/src/lib/libcrypto/crypto/getentropy_osx.c
+++ b/src/lib/libcrypto/crypto/getentropy_osx.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: getentropy_osx.c,v 1.3 2014/07/12 14:48:00 deraadt Exp $ */ 1/* $OpenBSD: getentropy_osx.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>
@@ -70,6 +70,7 @@
70 70
71#define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l))) 71#define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l)))
72#define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x))) 72#define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x)))
73#define HF(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (void*)))
73 74
74int getentropy(void *buf, size_t len); 75int getentropy(void *buf, size_t len);
75 76
@@ -184,7 +185,7 @@ start:
184 } 185 }
185 for (i = 0; i < len; ) { 186 for (i = 0; i < len; ) {
186 size_t wanted = len - i; 187 size_t wanted = len - i;
187 ssize_t ret = read(fd, buf + i, wanted); 188 ssize_t ret = read(fd, (char *)buf + i, wanted);
188 189
189 if (ret == -1) { 190 if (ret == -1) {
190 if (errno == EAGAIN || errno == EINTR) 191 if (errno == EAGAIN || errno == EINTR)
@@ -214,7 +215,7 @@ static int
214getentropy_fallback(void *buf, size_t len) 215getentropy_fallback(void *buf, size_t len)
215{ 216{
216 uint8_t results[SHA512_DIGEST_LENGTH]; 217 uint8_t results[SHA512_DIGEST_LENGTH];
217 int save_errno = errno, e, m, pgs = getpagesize(), faster = 0, repeat; 218 int save_errno = errno, e, pgs = getpagesize(), faster = 0, repeat;
218 static int cnt; 219 static int cnt;
219 struct timespec ts; 220 struct timespec ts;
220 struct timeval tv; 221 struct timeval tv;
@@ -224,7 +225,7 @@ getentropy_fallback(void *buf, size_t len)
224 SHA512_CTX ctx; 225 SHA512_CTX ctx;
225 static pid_t lastpid; 226 static pid_t lastpid;
226 pid_t pid; 227 pid_t pid;
227 size_t i, ii; 228 size_t i, ii, m;
228 char *p; 229 char *p;
229 struct tcpstat tcpstat; 230 struct tcpstat tcpstat;
230 struct udpstat udpstat; 231 struct udpstat udpstat;
@@ -279,7 +280,7 @@ getentropy_fallback(void *buf, size_t len)
279 HX((pid = getsid(pid)) == -1, pid); 280 HX((pid = getsid(pid)) == -1, pid);
280 HX((pid = getppid()) == -1, pid); 281 HX((pid = getppid()) == -1, pid);
281 HX((pid = getpgid(0)) == -1, pid); 282 HX((pid = getpgid(0)) == -1, pid);
282 HX((m = getpriority(0, 0)) == -1, m); 283 HX((e = getpriority(0, 0)) == -1, e);
283 284
284 if (!faster) { 285 if (!faster) {
285 ts.tv_sec = 0; 286 ts.tv_sec = 0;
@@ -291,9 +292,9 @@ getentropy_fallback(void *buf, size_t len)
291 HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1, 292 HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1,
292 sigset); 293 sigset);
293 294
294 HD(main); /* an addr in program */ 295 HF(main); /* an addr in program */
295 HD(getentropy); /* an addr in this library */ 296 HF(getentropy); /* an addr in this library */
296 HD(printf); /* an addr in libc */ 297 HF(printf); /* an addr in libc */
297 p = (char *)&p; 298 p = (char *)&p;
298 HD(p); /* an addr on stack */ 299 HD(p); /* an addr on stack */
299 p = (char *)&errno; 300 p = (char *)&errno;
@@ -413,7 +414,7 @@ getentropy_fallback(void *buf, size_t len)
413 } 414 }
414 415
415 SHA512_Final(results, &ctx); 416 SHA512_Final(results, &ctx);
416 memcpy(buf + i, results, min(sizeof(results), len - i)); 417 memcpy((char *)buf + i, results, min(sizeof(results), len - i));
417 i += min(sizeof(results), len - i); 418 i += min(sizeof(results), len - i);
418 } 419 }
419 memset(results, 0, sizeof results); 420 memset(results, 0, sizeof results);