Groups | Search | Server Info | Login | Register


Groups > perl.perl5.porters > #99822

Re: Should we upgrade to a new PRNG in core?

Newsgroups perl.perl5.porters
Subject Re: Should we upgrade to a new PRNG in core?
Organization The Eyrie
References <e1f40576-0937-4dc3-908c-4c02e44e35a5@perturb.org> <2b77a5db-96c1-4f28-82e8-a19f86ffe41f@darrenduncan.net>
Date 2026-01-23 19:44 -0800
Message-ID <87pl6zfzdd.fsf@hope.eyrie.org> (permalink)
From eagle@eyrie.org (Russ Allbery)

Show all headers | View raw


Darren Duncan <darren@darrenduncan.net> 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

Back to perl.perl5.porters | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Should we upgrade to a new PRNG in core? scott@perturb.org (Scott Baker) - 2026-01-23 14:02 -0800
  Re: Should we upgrade to a new PRNG in core? darren@darrenduncan.net (Darren Duncan) - 2026-01-23 19:30 -0800
    Re: Should we upgrade to a new PRNG in core? eagle@eyrie.org (Russ Allbery) - 2026-01-23 19:44 -0800
      Re: Should we upgrade to a new PRNG in core? perl5-porters@perl.org (Aristotle Pagaltzis via perl5-porters) - 2026-01-24 09:34 +0100
        Re: Should we upgrade to a new PRNG in core? eagle@eyrie.org (Russ Allbery) - 2026-01-24 12:20 -0800
          Re: Should we upgrade to a new PRNG in core? scott@perturb.org (Scott Baker) - 2026-01-24 13:56 -0800
  Should we upgrade to a new PRNG in core? dj.p5p@avoiding.work (Diab Jerius) - 2026-02-07 12:03 -0500

csiph-web