I'm working with openssl cryptographic libraries, I'm new to all these cryptographic stuffs and slowly I'm learning all these. I have a doubt regarding random number generator, I'm using RAND_pseudo_bytes()
for generating a pseudo random number. I'm providing a seed to it with my required entropy. But my doubt is if we provide same seed twice, will the random number generator generate the same random number ?
1 Answer
I recommend against using RAND_pseudo_bytes()
. OpenSSL's CPRNG does not provide better pseudo-random numbers than /dev/urandom but it is much harder to use right. It has a couple of known flaws, for example it doesn't handle fork() very well. The standard PRNG is not very well designed, too. The FIPS mode PRNG is a bit better, though.
/dev/urandom
(Linux, BSD, Solaris) are about as fast as RAND_pseudo_bytes()
. You don't have to take care of seeding, fork hooks, thread locks and other stuff that makes the PRNG hard to use. You can just read as many bytes from /dev/urandom
as you need. Windows has CryptGenRandom()
.
No matter what some people or documents say: ignore /dev/random
. /dev/urandom
is fine for everything you are going to do.
-
4$\begingroup$ I think saying "No matter what some people or documents say: ignore
/dev/random
." is a pretty bald statement, especially considering you do not provide argumentation. $\endgroup$– orlpCommented Sep 26, 2013 at 23:35
/dev/urandom
if working on *nix. See this answer for more. $\endgroup$