# When to use /dev/random over /dev/urandom in Linux

In my response to my question "what does the letter 'u' mean in /dev/urandom?" the myths about /dev/urandom page was posted in two comments and an answer.

The myths about /dev/urandom page is trying to steer people heavily into using /dev/urandom over dev/random.

This guy knows more than I do, so it would be easy for me to nod and accept, but I'd like to post it here so that other people who also know more than I do could comment.

• The two devices still have a differing behaviour depending on the size of the entropy pool
• There are no use cases given where /dev/random is the better choice (which seems unbalanced)

I note that cryptsetup has an option --use-random:

NOTES ON RANDOM NUMBER GENERATORS

Using /dev/random on a system without enough entropy sources can cause luksFormat to block until the requested amount of random data is gathered. In a low-entropy situation (embedded system), this can take a very long time and potentially forever. At the same time, using /dev/urandom in a low-entropy situation will produce low-quality keys. This is a serious problem, but solving it is out of scope for a mere man-page. See urandom(4) for more information.

So my question is:

In which practical situations would one want to use /dev/random in preference to /dev/urandom, and why?

## locked by e-sushiNov 25 '16 at 17:24

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. See the help center for guidance on writing a good question.

• If this is about Linux, you should say so, as the answer may be different for other OSes. – fkraiem Nov 17 '16 at 5:17
• – Gilles 'SO- stop being evil' Nov 18 '16 at 22:46
• – Tom Hale Nov 19 '16 at 8:50
• Please do not cross-post the same question accross SE networks! Doing so can and will result in the closure of one of the two. Also, your usage/implementation question does not seem to be related to cryptography as defined in our help center; which makes it off-topic here. – e-sushi Nov 25 '16 at 17:17

In which practical situations would one want to use /dev/random in preference to /dev/urandom, and why?

Basically none on a typical desktop or server system. Assuming the PRNG produces cryptographically secure random numbers, there is no reason to use /dev/random instead.

There are a couple of corner cases, however:

1. You use the random numbers for a one-time pad. In that case if you wanted information theoretic security you should not use pseudorandom numbers. (No real reason to do that in my opinion.)

2. Early boot on a very low entropy device. The /dev/urandom device cannot guarantee that it has received enough initial entropy, while when using /dev/random that is guaranteed (even if it may block). However, in this case you could use the newer getrandom interface (man page) instead.

Running cryptsetup on first boot of an embedded device is the kind of thing where you would need to consider your options. (Modern desktop and server CPUs tend to include hardware random number generators which are used to seed /dev/urandom.)

There is some work underway to make /dev/urandom block when initial entropy is insufficient, but it may not be possible due to programs which assume it will never block. (See e.g. this LKML thread.)

Assuming enough entropy was collected to seed the pseudo-random number generator, there is no reason to use the potentially blocking /dev/random. In general, a well studied PRNG (/dev/urandom), that is seeded properly should be the way to go.

They both produce the same pseudo random numbers based on a repetitive SHA1 hashing of a small quasi-entropy pool.

There is a clear use case for one over the other. The number of numbers it produces. /dev/random is very very slow. I've timed it producing random numbers in the order of <0.1 bytes /sec. That means that after consuming the initial 128 (or so) available bytes, it effectively stops. The only effective way to increase the generation rate is to do the typing monkey thing and hammer away at the key board. On a server, you're stuffed.

Consequently, unless you have access to an external hardware entropy source, you can't really use /dev/random for anything productive. You can't even use it realistically for generating one time pads for anything longer than a single sentence. Thus you're left with /dev/urandom where I guess the "u" stands for unlimited.

So the answer is that there is no practical use for /dev/random. If you want to see this for yourself, type

cat /dev/random | hexdump


and watch it do nothing much at all...

• It would be interesting to know the origins of /dev/random and what the design use cases were. – Paul Uszak Nov 17 '16 at 22:02
• Oops on both fronts! See this question for the historical background of /dev/random and /dev/urandom – Tom Hale Nov 18 '16 at 15:34