random-util: initialize srand() from RDRAND

It's cheap to get RDRAND and given that srand() is anyway not really
useful for trusted randomness let's use RDRAND for it, after all we have
all the hard work for that already in place.
This commit is contained in:
Lennart Poettering 2018-11-06 12:08:26 +01:00
parent 54bf23151f
commit 92025e8f52

View file

@ -144,6 +144,7 @@ void initialize_srand(void) {
#if HAVE_SYS_AUXV_H #if HAVE_SYS_AUXV_H
const void *auxv; const void *auxv;
#endif #endif
uint64_t k;
if (srand_called) if (srand_called)
return; return;
@ -164,6 +165,9 @@ void initialize_srand(void) {
x ^= (unsigned) now(CLOCK_REALTIME); x ^= (unsigned) now(CLOCK_REALTIME);
x ^= (unsigned) gettid(); x ^= (unsigned) gettid();
if (rdrand64(&k) >= 0)
x ^= (unsigned) k;
srand(x); srand(x);
srand_called = true; srand_called = true;
} }