Re: Should we upgrade to a new PRNG in core?
[email protected] (Russ Allbery)
| Newsgroups | perl.perl5.porters |
|---|---|
| Organization | The Eyrie |
| Message-ID | <[email protected]> |
Darren Duncan <[email protected]> writes: > Assuming that the reason to change the PRNG is better security or > similar benefits, I feel that it would be good for Perl to have the most > secure option by default so users who don't know better get the > benefits. I know I made this point in previous discussions and I don't want to belabor it, but because I work in this field and I am worried that this knowledge is not widespread: The most secure option is to not use any type of pseudo-random number generator and instead rely on /dev/random [1]. If your concern is security, you should not use rand() and you should not use any other new algorithm that similarly does not use /dev/random. There are various other problems involved in making /dev/random as close to really random as possible, and they can be quite complicated, but at least other people are working on that for you and may have access to hardware sources of randomness. This is not the case for a mathematical algorithm built into Perl. The primary reason to use rand() is if you need predictable (i.e., not actually random) random numbers for test suites, reproducible randomized algorithms, and other similar purposes, or as a fallback on platforms without /dev/random or some equivalent. If /dev/random is available and you want random numbers for security purposes, you should just use it via Crypt::URandom, Crypt::Random, etc. [1] Differences between /dev/urandom and /dev/random elided for simplicity. Thankfully on modern Linux (and I think on some other operating systems now?) you no longer have to care about this distinction except in very narrow cases during system boot that Perl scripts usually do not have to deal with, and can just use /dev/random without worrying about blocking. -- #!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker $^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD, 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{ rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print