2
$\begingroup$

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 ?

$\endgroup$
2
  • 3
    $\begingroup$ Yes. Hence the name pseudo-random generator. You should read your entropy (ie. your seed) from /dev/urandom if working on *nix. See this answer for more. $\endgroup$
    – rath
    Commented Aug 26, 2013 at 9:51
  • 1
    $\begingroup$ rath, can you expand your comment a little bit and post it as an answer? $\endgroup$
    – pg1989
    Commented Aug 27, 2013 at 19:24

1 Answer 1

5
$\begingroup$

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.

$\endgroup$
1
  • 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$
    – orlp
    Commented Sep 26, 2013 at 23:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.