Fix PRNG seeding to resist guessing

We seed it with value of time().  It's the traditional way, but it
provides only a few bits of effective entropy when an attacker has a
rough idea when the program started.

Instead, seed with a kernel random number.  If we can't get one, fall
back to a hash of gettimeofday() and getpid().  This should happen
only on old systems or Windows.  Far worse than a kernel random
number, but far better than using time().

Note that fairland used to seed with time() + getpid() until commit
331aac2a (v4.2.20) dropped the getpid(), claiming it didn't improve
the randomness.  Perhaps it didn't under Windows then, but it
certainly did elsewhere, so it was a regression.
This commit is contained in:
Markus Armbruster 2012-12-29 15:06:29 +01:00
parent 39c26f4238
commit 9102ecce54
4 changed files with 68 additions and 2 deletions

View file

@ -143,7 +143,8 @@ main(int argc, char **argv)
char *config_file = NULL;
int force_bad_state = 0;
int op, idx, sig;
unsigned seed = time(NULL);
unsigned seed = 0;
int seed_set = 0;
oops_handler = ignore;
@ -194,6 +195,7 @@ main(int argc, char **argv)
break;
case 'R':
seed = strtoul(optarg, NULL, 10);
seed_set = 1;
break;
case 'v':
printf("%s\n\n%s", version, legal);
@ -254,6 +256,8 @@ main(int argc, char **argv)
return install_service(program_name, service_name, config_file);
#endif /* _WIN32 */
if (!seed_set)
seed = pick_seed();
init_server(seed, force_bad_state);
#if defined(_WIN32)