From 6570d30f963be94189cf8ed0bf0b751f28bd0051 Mon Sep 17 00:00:00 2001 From: Nicholas Tay Date: Thu, 2 Dec 2021 18:10:16 +1100 Subject: Less syscalls the better? Call getrandom() every generation Seems to hang every few executions if we getrandom one big chunk. Probably not enough entropy? --- passgen.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'passgen.c') diff --git a/passgen.c b/passgen.c index 3f1e59e..2c560b0 100644 --- a/passgen.c +++ b/passgen.c @@ -56,11 +56,7 @@ int main(int argc, char *argv[]) char password[grammar_size+1]; password[grammar_size] = 0; -#ifdef __linux__ - // Reduce syscalls by generating a bunch and then doing it - unsigned int entropy[grammar_size]; - getrandom(&entropy, sizeof(entropy), 0); -#else +#ifndef __linux__ // seed RNG; this isn't very good, but it's enough(?) srand(time(NULL) + getpid() % 420 - 69); #endif @@ -87,7 +83,8 @@ int main(int argc, char *argv[]) do { #ifdef __linux__ - unsigned int r = entropy[i]; + unsigned int r; + getrandom(&r, sizeof(r), 0); #else long r = rand(); #endif -- cgit