os_unix: Seed random() for os_random()

While the users of os_random() do not really need strong pseudo random
numebrs, there is no significant harm in seeding random() with data from
os_get_random(), i.e., /dev/urandom, to get different sequence of not so
strong pseudo random values from os_random() for each time the process
is started.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2020-02-28 22:54:36 +02:00
parent 54bc5db16e
commit 167205d455

View file

@ -337,6 +337,8 @@ char * os_rel2abs_path(const char *rel_path)
int os_program_init(void)
{
unsigned int seed;
#ifdef ANDROID
/*
* We ignore errors here since errors are normal if we
@ -365,6 +367,9 @@ int os_program_init(void)
capset(&header, &cap);
#endif /* ANDROID */
os_get_random((unsigned char *) &seed, sizeof(seed));
srandom(seed);
return 0;
}