random-seed: hash together old seed and new seed before writing out file
authorJason A. Donenfeld <Jason@zx2c4.com>
Mon, 3 Jan 2022 17:11:32 +0000 (18:11 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 4 Jan 2022 22:47:56 +0000 (22:47 +0000)
commitda2862ef06f22fc8d31dafced6d2d6dc14f2ee0b
tree7c8ed56621f2a844eb3346882cc3c2e516dbdd78
parent948d085e899273f3a34376665414d1ecd1858978
random-seed: hash together old seed and new seed before writing out file

If we're consuming an on-disk seed, we usually write out a new one after
consuming it. In that case, we might be at early boot and the randomness
could be rather poor, and the kernel doesn't guarantee that it'll use
the new randomness right away for us. In order to prevent the new
entropy from getting any worse, hash together the old seed and the new
seed, and replace the final bytes of the new seed with the hash output.
This way, entropy strictly increases and never regresses.

Fixes: https://github.com/systemd/systemd/issues/21983
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
src/random-seed/random-seed.c