summaryrefslogtreecommitdiff
path: root/lib/libcrypto/crypto
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>2014-06-25 16:29:31 +0000
committerBob Beck <beck@cvs.openbsd.org>2014-06-25 16:29:31 +0000
commit19487d669912f904a9817a11a780084741153367 (patch)
treea2f4a6e63384bf9ba95000f17669a01be0dc9402 /lib/libcrypto/crypto
parent05217d13b86ccb11dd51eab9383f02c728521f39 (diff)
Possibly obtain a little bit of entropy from addresses returned
by getauxval if we have it. ok deraadt@
Diffstat (limited to 'lib/libcrypto/crypto')
-rw-r--r--lib/libcrypto/crypto/getentropy_linux.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/libcrypto/crypto/getentropy_linux.c b/lib/libcrypto/crypto/getentropy_linux.c
index 81661318995..da86137e5a0 100644
--- a/lib/libcrypto/crypto/getentropy_linux.c
+++ b/lib/libcrypto/crypto/getentropy_linux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getentropy_linux.c,v 1.9 2014/06/25 15:53:56 beck Exp $ */
+/* $OpenBSD: getentropy_linux.c,v 1.10 2014/06/25 16:29:30 beck Exp $ */
/*
* Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org>
@@ -45,6 +45,9 @@
#include <linux/random.h>
#include <linux/sysctl.h>
+#ifdef HAVE_GETAUXVAL
+#include <sys/auxv.h>
+#endif
#include <sys/vfs.h>
#define REPEAT 5
@@ -58,7 +61,8 @@
HD(b); \
} while (0)
-#define HD(xxx) (SHA512_Update(&ctx, (char *)&(xxx), sizeof (xxx)))
+#define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l)))
+#define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x)))
int getentropy(void *buf, size_t len);
@@ -446,6 +450,23 @@ getentropy_fallback(void *buf, size_t len)
HD(cnt);
}
+#ifdef AT_RANDOM
+ /* Not as random as you think but we take what we are given */
+ p = (char *) getauxval(AT_RANDOM);
+ if (p)
+ HR(p, 16);
+#endif
+#ifdef AT_SYSINFO_EHDR
+ p = (char *) getauxval(AT_SYSINFO_EHDR);
+ if (p)
+ HR(p, sizeof(p));
+#endif
+#ifdef AT_BASE
+ p = (char *) getauxval(AT_BASE);
+ if (p)
+ HR(p, sizeof(p));
+#endif
+
SHA512_Final(results, &ctx);
memcpy(buf + i, results, min(sizeof(results), len - i));
i += min(sizeof(results), len - i);