mirror of
https://github.com/systemd/systemd
synced 2024-10-05 07:40:42 +00:00
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:
parent
54bf23151f
commit
92025e8f52
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue