# Entropy estimation by Linux Kernel when adding entropy from TRNG

As per resources given below, after adding the bits to entropy pool, the Linux RNG estimates the amount of entropy for "credit_entropy_bits" function. It is estimating the amount of entropy of an event as a function of its timing. Initially, the estimator calculates the jiffies differences on three levels. Then, estimator takes the minimum of the differences absolute values and finally, it assigns it a value between 0 and 11.

I am using a TRNG for supplying entropy to Linux entropy pool. The output of TRNG is 160 bits i.e. the entropy of source is 160 bits. In case of TRNG, What will be value of entropy for "credit_entropy_bits" function ? Will it be 160 bits ?

I have pointed the "rng_current" to "rng-caam". I am running "rngd" with r option i.e. "rngd -r /dev/hwrng".

• How are you supplying the entropy? By writing to /dev/random? That does not increase the entropy count at all. You can increase it (as a privileged user) by using the RNDADDENTROPY ioctl. – otus Aug 1 '16 at 7:42
• @otus , I have pointed the "rng_current" to "rng-caam". I am running "rngd" with r option i.e. "rngd -r /dev/hwrng". Killing and re-running rngd with trace program i.e. "strace rngd -r /dev/hwrng" confirms that it is reading/getting 8 bytes. – user2363993 Aug 1 '16 at 8:00
• If you have a TRNG, why do you want to obfuscate it's output by injecting the entropy into the /dev/random pool? Why not use the entropy directly? – Paul Uszak Aug 15 '16 at 10:58
• @Paul Uszak , It was the build in function of chip. I am already looking at directly using the TRNG's output. – user2363993 Aug 16 '16 at 9:34

When you are adding entropy from outside the kernel, the kernel's entropy estimation functions are not used. Instead the entropy count is either not updated (e.g. if you just write data to /dev/random) or is updated according to the entropy count given to the kernel (e.g. through the RNDADDENTROPY ioctl).
• @user2363993, the kernel has no way of knowing the source entropy, so it relies on what it is told by (in this case) rngd. If you know the device only generates 160 bits at a time, you can tell rngd to use only that much with -s 20, but it will credit the full amount each time it mixes in entropy. – otus Aug 1 '16 at 9:45
• Regarding papers/books, I don't know of any good ones. Any that exist may be/become quickly outdated – e.g. the next kernel version will overhaul how /dev/urandom works. – otus Aug 1 '16 at 9:48