Where does /dev/urandom gather these variables from.
Everywhere it can, primarily interrupt timing. For example, if you have a network card, the precise time a packet arrives will be affected by the offset between the crystal timebase on the network card and the crystal timebase that clocks the CPU. The offset between two quartz crystal oscillators is affected by microscopic zone temperature variations that are believed to be truly physically random.
If you have a rotating disk, the time reads will complete is dependent on the speed the disk rotates. This is affected by turbulent shear force between the disk surface and the air inside the disk assembly. While this is not believed to be true physical randomness, it is entirely unpredictable or repeatable by any known mechanism.
And if you have two machines set to the same time (down to the millisecond-if possible) and have the same speed, OS, etc...and take a hexdump of /dev/random with X number of bytes, will they have the same exact value (because the time was the same)?
Well, millisecond wouldn't be nearly good enough. You'd need to be at the same level the CPU measures time -- billionths of a second. But, of course, that is how it must be. Otherwise, if you saw the state of one machine, you could know with 100% certainty that the other machine could not have that same state. And since the state is supposed to be random, you should not be able to look at any other machine and know anything about the state with 100% certainty. So long as the odds this could be accomplished are sufficiently low (say, less than one in 2^100), then it's perfectly fine.
Even if you roll two dice, each with a billion sides, they may come up the same. Provided they only do so once every billion times, then that's as it should be.
Do you have a reference for the network card example? I don't see it in the kernel sources, and that method isn't documented in
drivers/char/random.c. The hard disk example seems to be theadd_disk_randomnesscall inblock/blk-core.cAFAICT. – Daniel Beck – 2013-01-13T20:14:18.390It's built into the interrupt handler, through
handle_IRQ_event. – David Schwartz – 2013-01-13T20:31:44.867