No user space program should need to use rdrand directly at all.
No user space program should need to use rdrand directly at all.
Indeed, because RDSEED is actually what most people want anyway.
Its an assembly instruction that gets the job done. People should be expecting that the assembly instructions of their CPUs work as intended. No different than using AVX-intrinsics or hand-crafted assembly in x264 / x265 code.
In any case, RDSEED is the assembly instruction for gathering entropy (aka: setting a random number generator should use RDSEED), while RDRAND is an older assembly instruction for purely getting a cryptographic random number. Its slightly different amounts of entropy involved in RDSEED vs RDRAND. So this is a very subtle issue that requires a lot of understanding of the x86 assembly instruction set.
But if you understand these details, then by golly you should use the instructions!
That doesn't explain why systemd uses it, of course.
[1]: https://elixir.bootlin.com/linux/v5.3.6/source/drivers/char/...
In comparison get_random_u32() is safe to call at any point — including early boot — and does not affect global entropy pool. At worst it may return low-quality numbers, but that can be easily fixed by running your own peudo-random generator on top of it (which is a good idea anyway because you don't want your kernel module to contend with other parties for RNG ownership).