diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-07-03 20:39:47 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-07-03 20:45:48 +0200 |
commit | be4f3cd7c2df12f219d3e6a40559602a053df4e2 (patch) | |
tree | 9d05ae03f7b7064d22d6646f2b06103db41c7f24 /src/genkey.c | |
parent | wg: improve error reporting and detection (diff) | |
download | wireguard-tools-be4f3cd7c2df12f219d3e6a40559602a053df4e2.tar.xz wireguard-tools-be4f3cd7c2df12f219d3e6a40559602a053df4e2.zip |
wg: always fallback to /dev/urandom
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r-- | src/genkey.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/genkey.c b/src/genkey.c index 8e63108..a312b46 100644 --- a/src/genkey.c +++ b/src/genkey.c @@ -6,31 +6,29 @@ #include <sys/types.h> #include <sys/stat.h> #include <syscall.h> -#include <unistd.h> #include <string.h> +#include <fcntl.h> #include "curve25519.h" #include "base64.h" #include "subcommands.h" -#ifdef __NR_getrandom -static inline ssize_t get_random_bytes(uint8_t *out, size_t len) -{ - return syscall(__NR_getrandom, out, len, 0); -} -#else -#include <fcntl.h> static inline ssize_t get_random_bytes(uint8_t *out, size_t len) { ssize_t ret; - int fd = open("/dev/urandom", O_RDONLY); + int fd; +#ifdef __NR_getrandom + ret = syscall(__NR_getrandom, out, len, 0); + if (ret >= 0) + return ret; +#endif + fd = open("/dev/urandom", O_RDONLY); if (fd < 0) return fd; ret = read(fd, out, len); close(fd); return ret; } -#endif int genkey_main(int argc, char *argv[]) { |