Tuesday, April 07, 2015
Just use /dev/urandom and be done with it
I noticed one of the developers at The Ft. Lauderdale Office of The Corporation using the time of day to seed a random number generator,
which is borderline okay
(depending on how the resulting random numbers will be used)
there are better ways to generate a random seed,
at least on a modern POSIX system—read data from /dev/urandom
.
My fellow cow-orker B,
with whom I was having this discussion,
mentioned this borderline paranoid approach to reading /dev/urandom
.
But I think that if you have to call fstat()
to make sure the file is actually /dev/urandom
then you have more things to worry about
(really—if a cracker can substitute /dev/urandom
with known data,
it's pretty much game over—B agreed with that statement,
by the way).
Besides,
the author wasn't paranoid enough! Who's to say there isn't some extra code in there
(say,
via $LD_PRELOAD
or ptrace()
or maybe even through some ELF magic on the executable)
that intercepts the read()
function to return “random data” when reading from /dev/urandom
?
Hmmmm?
(about the only thing you can do to counter that is nuke the site from orbit—it's the only way to be sure)
But in the mean time,
just use /dev/urandom
.