I have found information that
/proc/sys/kernel/random/entropy_avail indicates number of bits available in
/dev/random. I wanted to check whether the next reading from
/dev/random will block and my naive approach was just to compare
entropy_avail and number of required random bits but it does not work well. When I did a simple stupid experiment I realized that the entropy is buffered. 64-bit entropy buffer provides 6 bytes of random data.
I monitored the
entropy_avail via this simple command:
while true; do cat /proc/sys/kernel/random/entropy_avail sleep 1 done
And I was trying to get a random byte via command
dd if=/dev/random bs=1 count=1 > /dev/null
dd command is blocked if entropy is 63 or lower. When entropy reaches 64 and I read a byte then entropy decreases to 0 but I can read another 5 bytes without blocking. Then
dd blocks again till entropy reaches 64.
What is the exact meaning of the
entropy_avail and how can I detect real number of available random bits?