diff options
author | Nicholas Tay <nick@windblume.net> | 2022-01-11 19:55:23 +1100 |
---|---|---|
committer | Nicholas Tay <nick@windblume.net> | 2022-01-11 19:55:26 +1100 |
commit | d8a6d22ad110c22929873d716735e6bede1e7441 (patch) | |
tree | 57d679421a63bb8b4545ee8ab29565f7e49947c5 /passgen.c | |
parent | a15a4c774ec8358ffd74a1bed199fa49cf38ee9c (diff) | |
download | passgen-d8a6d22ad110c22929873d716735e6bede1e7441.tar.gz passgen-d8a6d22ad110c22929873d716735e6bede1e7441.tar.bz2 passgen-d8a6d22ad110c22929873d716735e6bede1e7441.zip |
BSD support for getentropy()
Diffstat (limited to 'passgen.c')
-rw-r--r-- | passgen.c | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -5,9 +5,20 @@ #include <stdbool.h> #include <string.h> +#if defined (__linux__) \ + || defined (__APPLE__) \ + || defined (__FreeBSD__) \ + || defined (__OpenBSD__) +# define USE_GETENTROPY 1 +#endif + /* getentropy() vs rand()+time()+getpid() */ +#ifdef USE_GETENTROPY #if defined (__linux__) || defined (__APPLE__) -#include <sys/random.h> +# include <sys/random.h> +#else +# include <unistd.h> +#endif #else #include <time.h> @@ -76,7 +87,7 @@ int main(int argc, char *argv[]) } password[grammar_size] = 0; -#if ! defined (__linux__) && ! defined (__APPLE__) +#ifndef USE_GETENTROPY /* * TODO: seed better RNG * this isn't very good, but it's enough(?) for now @@ -113,7 +124,7 @@ int main(int argc, char *argv[]) } do { -#if defined (__linux__) || defined (__APPLE__) +#ifdef USE_GETENTROPY unsigned int r; getentropy(&r, sizeof(r)); #else |