From c33a043cb6a9ff5431d050a095f7900d9303a6e1 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sun, 17 Feb 2019 21:53:57 +0100 Subject: Seed with real random number --- bin/ykfde.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'bin') diff --git a/bin/ykfde.c b/bin/ykfde.c index 34674cc..2dfd5d7 100644 --- a/bin/ykfde.c +++ b/bin/ykfde.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include @@ -112,7 +112,7 @@ int main(int argc, char **argv) { char challengefilename[sizeof(CHALLENGEDIR) + 11 /* "/challenge-" */ + 10 /* unsigned int in char */ + 1], challengefiletmpname[sizeof(CHALLENGEDIR) + 11 /* "/challenge-" */ + 10 /* unsigned int in char */ + 7 /* -XXXXXX */ + 1]; int challengefile = 0, challengefiletmp = 0; - struct timeval tv; + unsigned int seed; int i; size_t len; int8_t rc = EXIT_FAILURE; @@ -196,10 +196,12 @@ int main(int argc, char **argv) { if (version > 0 || help > 0) return EXIT_SUCCESS; - /* initialize random seed */ - gettimeofday(&tv, NULL); - srand(tv.tv_usec * tv.tv_sec); + if (getrandom(&seed, 4, GRND_RANDOM) != 4) { + fprintf(stderr, "Initializing random seed failed.\n"); + goto out10; + } + srand(seed); /* initialize static buffers */ memset(challenge_old, 0, CHALLENGELEN + 1); -- cgit v1.2.3-70-g09d2