]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
wg: always fallback to /dev/urandom
authorJason A. Donenfeld <Jason@zx2c4.com>
Sun, 3 Jul 2016 18:39:47 +0000 (20:39 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sun, 3 Jul 2016 18:45:48 +0000 (20:45 +0200)
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
src/genkey.c

index 8e6310861248fcc8f79af8afb9d557e9e1e04425..a312b46f9f222f69c8c1eceba420175bd10c86b1 100644 (file)
@@ -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[])
 {