summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/crypto/getentropy_linux.c
diff options
context:
space:
mode:
authorbeck <>2014-06-25 16:29:30 +0000
committerbeck <>2014-06-25 16:29:30 +0000
commit7ffc775f69f7ed331b65c715f952ce9cf05a51a3 (patch)
treef4a66f7707d19d5ed1dfb204435d34d8e299530e /src/lib/libcrypto/crypto/getentropy_linux.c
parent69d2f36faae2eadd4be09546d27257594f86a13a (diff)
downloadopenbsd-7ffc775f69f7ed331b65c715f952ce9cf05a51a3.tar.gz
openbsd-7ffc775f69f7ed331b65c715f952ce9cf05a51a3.tar.bz2
openbsd-7ffc775f69f7ed331b65c715f952ce9cf05a51a3.zip
Possibly obtain a little bit of entropy from addresses returned
by getauxval if we have it. ok deraadt@
Diffstat (limited to 'src/lib/libcrypto/crypto/getentropy_linux.c')
-rw-r--r--src/lib/libcrypto/crypto/getentropy_linux.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/lib/libcrypto/crypto/getentropy_linux.c b/src/lib/libcrypto/crypto/getentropy_linux.c
index 8166131899..da86137e5a 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.9 2014/06/25 15:53:56 beck Exp $ */ 1/* $OpenBSD: getentropy_linux.c,v 1.10 2014/06/25 16:29:30 beck 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>
@@ -45,6 +45,9 @@
45 45
46#include <linux/random.h> 46#include <linux/random.h>
47#include <linux/sysctl.h> 47#include <linux/sysctl.h>
48#ifdef HAVE_GETAUXVAL
49#include <sys/auxv.h>
50#endif
48#include <sys/vfs.h> 51#include <sys/vfs.h>
49 52
50#define REPEAT 5 53#define REPEAT 5
@@ -58,7 +61,8 @@
58 HD(b); \ 61 HD(b); \
59 } while (0) 62 } while (0)
60 63
61#define HD(xxx) (SHA512_Update(&ctx, (char *)&(xxx), sizeof (xxx))) 64#define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l)))
65#define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x)))
62 66
63int getentropy(void *buf, size_t len); 67int getentropy(void *buf, size_t len);
64 68
@@ -446,6 +450,23 @@ getentropy_fallback(void *buf, size_t len)
446 450
447 HD(cnt); 451 HD(cnt);
448 } 452 }
453#ifdef AT_RANDOM
454 /* Not as random as you think but we take what we are given */
455 p = (char *) getauxval(AT_RANDOM);
456 if (p)
457 HR(p, 16);
458#endif
459#ifdef AT_SYSINFO_EHDR
460 p = (char *) getauxval(AT_SYSINFO_EHDR);
461 if (p)
462 HR(p, sizeof(p));
463#endif
464#ifdef AT_BASE
465 p = (char *) getauxval(AT_BASE);
466 if (p)
467 HR(p, sizeof(p));
468#endif
469
449 SHA512_Final(results, &ctx); 470 SHA512_Final(results, &ctx);
450 memcpy(buf + i, results, min(sizeof(results), len - i)); 471 memcpy(buf + i, results, min(sizeof(results), len - i));
451 i += min(sizeof(results), len - i); 472 i += min(sizeof(results), len - i);