Take the 2-minute tour ×
Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

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 ?

share|improve this question
3  
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. –  rath Aug 26 '13 at 9:51
1  
rath, can you expand your comment a little bit and post it as an answer? –  pg1989 Aug 27 '13 at 19:24
add comment

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.

share|improve this answer
2  
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. –  nightcracker Sep 26 '13 at 23:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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