]> 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>
Wed, 20 Sep 2017 12:16:43 +0000 (14:16 +0200)
commitfa949792072530b49ef5760d7ecd6d250c66e35f
treedc83cd56c00f61d79ab4aa26d46618498f9265a8
parent0e10ad091968dd9277274353fb6353f52fffe89e
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