summaryrefslogtreecommitdiffstats
path: root/lib/libcrypto/crypto/getentropy_linux.c
diff options
context:
space:
mode:
authorbeck <beck@openbsd.org>2014-06-25 16:29:30 +0000
committerbeck <beck@openbsd.org>2014-06-25 16:29:30 +0000
commit4f735644523a5d80d05c626d1c08fe994ca620fc (patch)
tree2a0ce51d9399e2d9cb01ca37ab2fe7ca3928df41 /lib/libcrypto/crypto/getentropy_linux.c
parentpf_translate doesn't use the mbuf argument anymore. (diff)
downloadwireguard-openbsd-4f735644523a5d80d05c626d1c08fe994ca620fc.tar.xz
wireguard-openbsd-4f735644523a5d80d05c626d1c08fe994ca620fc.zip
Possibly obtain a little bit of entropy from addresses returned
by getauxval if we have it. ok deraadt@
Diffstat (limited to 'lib/libcrypto/crypto/getentropy_linux.c')
-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);