How is entropy gathered for /dev/random in Precise

Solution 1:

This is complicated question. I will answer by quoting from few sources.

From Linux manpage

The character special files /dev/random and /dev/urandom (present since Linux 1.3.30) provide an interface to the kernel's random number generator. File /dev/random has major device number 1 and minor device number 8. File /dev/urandom has major device number 1 and minor device number 9.

The random number generator gathers environmental noise from device drivers and other sources into an entropy pool. The generator also keeps an estimate of the number of bits of noise in the entropy pool. From this entropy pool random numbers are created.

In Ubuntu 12.04 default kernel is 3.11.

From wiki

The Linux kernel generates entropy from keyboard timings, mouse movements, and IDE timings and makes the random character data available to other operating system processes through the special files /dev/random and /dev/urandom. This capability was introduced in Linux version 1.3.30.

From Linux manpage

When read, the /dev/random device will only return random bytes within the estimated number of bits of noise in the entropy pool. /dev/random should be suitable for uses that need very high quality randomness such as one-time pad or key generation. When the entropy pool is empty, reads from /dev/random will block until additional environmental noise is gathered.

Quote from random sources, from kernel 3.11.10.10

 * Theory of operation
 * ===================
 *
 * Computers are very predictable devices.  Hence it is extremely hard
 * to produce truly random numbers on a computer --- as opposed to
 * pseudo-random numbers, which can easily generated by using a
 * algorithm.  Unfortunately, it is very easy for attackers to guess
 * the sequence of pseudo-random number generators, and for some
 * applications this is not acceptable.  So instead, we must try to
 * gather "environmental noise" from the computer's environment, which
 * must be hard for outside attackers to observe, and use that to
 * generate random numbers.  In a Unix environment, this is best done
 * from inside the kernel.
 *
 * Sources of randomness from the environment include inter-keyboard
 * timings, inter-interrupt timings from some interrupts, and other
 * events which are both (a) non-deterministic and (b) hard for an
 * outside observer to measure.  Randomness from these sources are
 * added to an "entropy pool", which is mixed using a CRC-like function.
 * This is not cryptographically strong, but it is adequate assuming
 * the randomness is not chosen maliciously, and it is fast enough that
 * the overhead of doing it on every interrupt is very reasonable.
 * As random bytes are mixed into the entropy pool, the routines keep
 * an *estimate* of how many bits of randomness have been stored into
 * the random number generator's internal state.

Yes it is smart enough to use user based sources, but you can configure more if you want.

There are kernels with random generators that have more entropy sources such including noise on audio inputs and others like video, coolers censors, etc. Look here if interesting in audio entropy. I hope you will find others kernels by yourself.

But /dev/random should be enough for most tasks by default.

Also read this question on stackoverflow

Solution 2:

True randomness comes from the physical world, not from deterministic pseudo-random number generators. The Linux kernel collects random timings and adds information to its entropy pool. I would recommend going into the kernel sources

Input entropy refer to the the function call's: add_interrupt_randomness(irq) handlers registered SA_SAMPLE_RANDOM, timing between interrupts is the source of noise, add_keyboard_randomness(scancode) and add_mouse_randomness(mouse_data) ===> all these functions call add_timer_randomness()

Output entropy: Kernel space: [get_random_bytes(buf, number)]( Refer to LXR => linux/drivers/char/random.c) User space: /dev/random /dev/urandom

Refer to LXR => linux/drivers/char/random.c