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:
@@ -144,6 +144,7 @@ void initialize_srand(void) {
|
||||
#if HAVE_SYS_AUXV_H
|
||||
const void *auxv;
|
||||
#endif
|
||||
uint64_t k;
|
||||
|
||||
if (srand_called)
|
||||
return;
|
||||
@@ -164,6 +165,9 @@ void initialize_srand(void) {
|
||||
x ^= (unsigned) now(CLOCK_REALTIME);
|
||||
x ^= (unsigned) gettid();
|
||||
|
||||
if (rdrand64(&k) >= 0)
|
||||
x ^= (unsigned) k;
|
||||
|
||||
srand(x);
|
||||
srand_called = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user