]> git.ipfire.org Git - thirdparty/util-linux.git/commit
lib/randutils: improve getrandom() usage
authorKarel Zak <kzak@redhat.com>
Mon, 14 Aug 2017 08:33:06 +0000 (10:33 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 14 Aug 2017 08:33:06 +0000 (10:33 +0200)
commit5264aebb4f822fa9147ee576562a4961ca97261d
tree1a4aac80fe48add7395e9cf1e8cb093ce0dc3e26
parent60eedb0a53f14aa1169713a72325421db8e1c647
lib/randutils: improve getrandom() usage

The getrandom() does not have to return all requested bytes (missing
entropy or when interrupted by signal). The current implementation in
util-linux stupidly asks for all random data again, rather than only
for missing bytes.

The current code also does not care if we repeat our requests for
ever; that's bad.

This patch uses the same way as we already use for reading from
/dev/urandom. It means:

 * repeat getrandom() for only missing bytes
 * limit number of unsuccessful request (16 times)
 * fallback to /dev/urandom on ENOSYS (old kernel or so...)

Addresses: https://github.com/karelzak/util-linux/issues/496
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/randutils.c