aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/compat
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-06-12 16:32:59 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2017-06-12 17:02:12 +0200
commit401294f7526de40a15c06997fceae58278807d22 (patch)
tree0b800c0a7c23f8cc7cf5cdea21ac13d3b84402e4 /src/compat
parentversion: bump snapshot (diff)
downloadwireguard-monolithic-historical-401294f7526de40a15c06997fceae58278807d22.tar.xz
wireguard-monolithic-historical-401294f7526de40a15c06997fceae58278807d22.zip
random: wait for random bytes when generating nonces and ephemerals
We can let userspace configure wireguard interfaces before the RNG is fully initialized, since what we mostly care about is having good randomness for ephemerals and xchacha nonces. By deferring the wait to actually asking for the randomness, we give a lot more opportunity for gathering entropy. This won't cover entropy for hash table secrets or cookie secrets (which rotate anyway), but those have far less catastrophic failure modes, so ensuring good randomness for elliptic curve points and nonces should be sufficient.
Diffstat (limited to 'src/compat')
-rw-r--r--src/compat/compat.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/compat/compat.h b/src/compat/compat.h
index 68d62b9..6c1bfa3 100644
--- a/src/compat/compat.h
+++ b/src/compat/compat.h
@@ -265,6 +265,16 @@ static inline int wait_for_random_bytes(void)
return 0;
}
#endif
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 13, 0)
+static inline int get_random_bytes_wait(void *buf, int nbytes)
+{
+ int ret = wait_for_random_bytes();
+ if (unlikely(ret))
+ return ret;
+ get_random_bytes(buf, nbytes);
+ return 0;
+}
+#endif
/* https://lkml.org/lkml/2015/6/12/415 */
#include <linux/netdevice.h>