summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/crypto/getentropy_linux.c
diff options
context:
space:
mode:
authorwouter <>2014-07-12 20:41:47 +0000
committerwouter <>2014-07-12 20:41:47 +0000
commit7e5def1fdfe6823f73bf90b40c67dda803608ade (patch)
tree9b680c598783f224f36f39f6030e4d4cd59fc56b /src/lib/libcrypto/crypto/getentropy_linux.c
parent88f737c074f7fdc1e089af4d15ae3c420ff0d092 (diff)
downloadopenbsd-7e5def1fdfe6823f73bf90b40c67dda803608ade.tar.gz
openbsd-7e5def1fdfe6823f73bf90b40c67dda803608ade.tar.bz2
openbsd-7e5def1fdfe6823f73bf90b40c67dda803608ade.zip
Remove signed/unsigned warning, statement before declaration and
add a function to use function pointers that does not take sizeof(fptr). OK beck@
Diffstat (limited to 'src/lib/libcrypto/crypto/getentropy_linux.c')
-rw-r--r--src/lib/libcrypto/crypto/getentropy_linux.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/lib/libcrypto/crypto/getentropy_linux.c b/src/lib/libcrypto/crypto/getentropy_linux.c
index 294b23037f..f550a9d365 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.20 2014/07/12 15:43:49 beck Exp $ */ 1/* $OpenBSD: getentropy_linux.c,v 1.21 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>
@@ -65,6 +65,7 @@
65 65
66#define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l))) 66#define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l)))
67#define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x))) 67#define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x)))
68#define HF(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (void*)))
68 69
69int getentropy(void *buf, size_t len); 70int getentropy(void *buf, size_t len);
70 71
@@ -209,7 +210,7 @@ start:
209 } 210 }
210 for (i = 0; i < len; ) { 211 for (i = 0; i < len; ) {
211 size_t wanted = len - i; 212 size_t wanted = len - i;
212 ssize_t ret = read(fd, buf + i, wanted); 213 ssize_t ret = read(fd, (char *)buf + i, wanted);
213 214
214 if (ret == -1) { 215 if (ret == -1) {
215 if (errno == EAGAIN || errno == EINTR) 216 if (errno == EAGAIN || errno == EINTR)
@@ -234,11 +235,11 @@ static int
234getentropy_sysctl(void *buf, size_t len) 235getentropy_sysctl(void *buf, size_t len)
235{ 236{
236 static int mib[] = { CTL_KERN, KERN_RANDOM, RANDOM_UUID }; 237 static int mib[] = { CTL_KERN, KERN_RANDOM, RANDOM_UUID };
237 size_t i, chunk; 238 size_t i;
238 int save_errno = errno; 239 int save_errno = errno;
239 240
240 for (i = 0; i < len; ) { 241 for (i = 0; i < len; ) {
241 chunk = min(len - i, 16); 242 size_t chunk = min(len - i, 16);
242 243
243 /* SYS__sysctl because some systems already removed sysctl() */ 244 /* SYS__sysctl because some systems already removed sysctl() */
244 struct __sysctl_args args = { 245 struct __sysctl_args args = {
@@ -290,7 +291,7 @@ static int
290getentropy_fallback(void *buf, size_t len) 291getentropy_fallback(void *buf, size_t len)
291{ 292{
292 uint8_t results[SHA512_DIGEST_LENGTH]; 293 uint8_t results[SHA512_DIGEST_LENGTH];
293 int save_errno = errno, e, m, pgs = getpagesize(), faster = 0, repeat; 294 int save_errno = errno, e, pgs = getpagesize(), faster = 0, repeat;
294 static int cnt; 295 static int cnt;
295 struct timespec ts; 296 struct timespec ts;
296 struct timeval tv; 297 struct timeval tv;
@@ -300,7 +301,7 @@ getentropy_fallback(void *buf, size_t len)
300 SHA512_CTX ctx; 301 SHA512_CTX ctx;
301 static pid_t lastpid; 302 static pid_t lastpid;
302 pid_t pid; 303 pid_t pid;
303 size_t i, ii; 304 size_t i, ii, m;
304 char *p; 305 char *p;
305 306
306 pid = getpid(); 307 pid = getpid();
@@ -329,7 +330,7 @@ getentropy_fallback(void *buf, size_t len)
329 HX((pid = getsid(pid)) == -1, pid); 330 HX((pid = getsid(pid)) == -1, pid);
330 HX((pid = getppid()) == -1, pid); 331 HX((pid = getppid()) == -1, pid);
331 HX((pid = getpgid(0)) == -1, pid); 332 HX((pid = getpgid(0)) == -1, pid);
332 HX((m = getpriority(0, 0)) == -1, m); 333 HX((e = getpriority(0, 0)) == -1, e);
333 334
334 if (!faster) { 335 if (!faster) {
335 ts.tv_sec = 0; 336 ts.tv_sec = 0;
@@ -341,9 +342,9 @@ getentropy_fallback(void *buf, size_t len)
341 HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1, 342 HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1,
342 sigset); 343 sigset);
343 344
344 HD(main); /* an addr in program */ 345 HF(main); /* an addr in program */
345 HD(getentropy); /* an addr in this library */ 346 HF(getentropy); /* an addr in this library */
346 HD(printf); /* an addr in libc */ 347 HF(printf); /* an addr in libc */
347 p = (char *)&p; 348 p = (char *)&p;
348 HD(p); /* an addr on stack */ 349 HD(p); /* an addr on stack */
349 p = (char *)&errno; 350 p = (char *)&errno;
@@ -483,7 +484,7 @@ getentropy_fallback(void *buf, size_t len)
483#endif 484#endif
484 485
485 SHA512_Final(results, &ctx); 486 SHA512_Final(results, &ctx);
486 memcpy(buf + i, results, min(sizeof(results), len - i)); 487 memcpy((char *)buf + i, results, min(sizeof(results), len - i));
487 i += min(sizeof(results), len - i); 488 i += min(sizeof(results), len - i);
488 } 489 }
489 memset(results, 0, sizeof results); 490 memset(results, 0, sizeof results);