Debian – GPG key generator does *not* use entropy

debiangpglinuxpgp

I'm trying to generate a GPG key on Ubuntu 16.10 and GPG is taking forever.

I googled a bit and found some websites, including some questions on StackExchange, suggesting to run an entropy generator like rngd to help the system generate random numbers faster.

Some of these websites also encouraged to check /proc/sys/kernel/random/entropy_avail, stating that, on their systems, it reported four-digit numbers before running GPG, and two to one-digit numbers while it was running.

I'm currently running GPG on my computer; it's been running for at least half an hour, and I'm getting this

$ cat /proc/sys/kernel/random/entropy_avail 
3644

The number increases over time, and decreases very seldom by small amounts (after writing this sentence it's at 3801). I'm not running any random number generator. Actually, if I try to run one (e.g. sudo rngd -fr /dev/random, it drops to around 50; if I use /dev/urandom it stays around 3000).

Can anybody help me figure out what the hell is wrong with my system?

I'm on Linux 4.8.0-37-generic, gpg (GnuPG) 2.1.15, libgcrypt 1.7.2-beta.

Best Answer

I had a similar problem recently after upgrading to Debian 9. Some of the programs that depend on random numbers have had their source code/random generator routines changed in recent Linux versions that make them more dependent on the entropy of the system.

Installing the daemon haveged seems to provide a consistent pool of random numbers. So do it:

sudo apt-get install haveged

The haveged daemon is now required by disparate programs requiring entropy, especially in VMs and iOTs (e.g. raspberry, others) where the entropy is normally low.

From man haveged:

NAME
haveged - Generate random numbers and feed Linux's random device.

DESCRIPTION
haveged generates an unpredictable stream of random numbers harvested from the indirect effects of hardware events on hidden processor state (caches, branch predictors, memory translation tables, etc) using the HAVEGE (HArdware Volatile Entropy Gathering and Expansion) algorithm. The algorithm operates in user space, no special privilege is required for file system access to the output stream.

Linux pools randomness for distribution by the /dev/random and /dev/urandom device interfaces. The standard mechanisms of filling the /dev/random pool may not be sufficient to meet demand on systems with high needs or limited user interaction. In those circumstances, haveged may be run as a privileged daemon to fill the /dev/random pool whenever the supply of random bits in /dev/random falls below the low water mark of the device.

Related Question