3 ms·
> inexplicably, instead of actually fixing /dev/(u)random, the Linux engineers decide to add a new getrandom() syscall which implements the correct behaviour of
by masklinn 7y ago
> inexplicably, instead of actually fixing /dev/(u)random, the Linux engineers decide to add a new getrandom() syscall which implements the correct behaviour of only blocking if the PRNG hasn't been seeded.
FWIW the OpenBSD folks first implemented getentropy() and recommended that Linux do the same[0], because devices causes various issues (e.g. chrooting, attacker-controlled FD exhaustion, …) having a reliable syscall is extremely valuable.
Sadly the Linux folks way over-engineered the thing with all kinds of tuning knobs so that you can get any preexisting behaviour you want: by default getrandom will read from the "urandom source" but block until the entropy pool has been initialised once.
However, you can also:
* GRND_RANDOM to have it read from the "random source" and block if "no random bytes are available"
* GRND_NONBLOCK to have it never block on lack of entropy, whether from the entropy pool not being initialised at all (!GRND_RANDOM) or because "there are no random bytes" (GRND_RANDOM), in which case it can also fail (getentropy should only fail if you give it an invalid buffer address or you request more than 256 bytes)
[0] https://www.openbsd.org/papers/hackfest2014-arc4random/mgp00041.html https://www.openbsd.org/papers/hackfest2014-arc4random/mgp00... also through the libressl project complaining about the lack of safe way to get good random data[1]
[1] https://github.com/libressl-portable/openbsd/blob/4e9048830a68da79247f30aba182b1599da139b9/src/lib/libcrypto/crypto/getentropy_linux.c#L87 https://github.com/libressl-portable/openbsd/blob/4e9048830a...