Skip to content

Simplify the recommended alternatives to rand() #22873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: blead
Choose a base branch
from

Conversation

robrwo
Copy link
Contributor

@robrwo robrwo commented Dec 23, 2024

The CPAN Security Group (CPANSec) is currently working on guides to generating security-quality random data. We are focusing on modules that have secure defaults and are fairly lightweight.

We would like to change the recommended modules to ones that we think are better options.

Crypt::URandom has fewer prerequisites than Crypt::Random, and works with Windows. (Older versions were pure-Perl.)

Crypt::PRNG has secure defaults and methods for generating different kinds of random data.

Math::Random::Secure has a lot of prerequisites and in the end is just relying on /dev/urandom, like Crypt::URandom does.

Math::TrulyRandom is from 1996, and it's unclear how well that technique will work on modern systems, especially VMs and containers.

Data::Entropy has recently updated to fix security issues, and has been marked as deprecated.

@jkeenan
Copy link
Contributor

jkeenan commented Dec 24, 2024

We will need to get this p.r. to pass t/porting/podcheck.t before we can proceed further.

@robrwo
Copy link
Contributor Author

robrwo commented Dec 25, 2024

We will need to get this p.r. to pass t/porting/podcheck.t before we can proceed further.

The podchecker utility installed with Perl says it's ok.

When I run it I get a compilation error that seems to have nothing to do with my change:

porting/podcheck.t .. Can't locate Carp.pm in @inc (you may need to install the Carp module) (@inc entries checked: ../lib) at porting/podcheck.t line 17.
BEGIN failed--compilation aborted at porting/podcheck.t line 17.

@Grinnz
Copy link
Contributor

Grinnz commented Dec 25, 2024

The failure is noted in the github actions run, it is because the pod checker must be told about the new non-core modules you are linking to:

#   "Apparent broken link"
#     to "Crypt::URandom" near line 6672 of pod/perlfunc.pod
#     to "Crypt::PRNG" near line 6674 of pod/perlfunc.pod
# See end of this test output for your options on silencing this
# 
# HOW TO GET porting/podcheck.t TO PASS
# 
# There was 1 file that had new potential problems identified.
# Some of them may be real, and some of them may be false positives because
# this program isn't as smart as it likes to think it is.  You can teach this
# program to ignore the issues it has identified, and hence pass, by doing the
# following:
# 
# 1) If a problem is about a link to an unknown module or man page that
#    you know exists, re-run the command something like:
#       ./perl -I../lib porting/podcheck.t --add-link { MODULE | man_page ... }

@robrwo
Copy link
Contributor Author

robrwo commented Dec 26, 2024

I've updated it, and also updated other references to Math::TrulyRandom.

@robrwo
Copy link
Contributor Author

robrwo commented Dec 28, 2024

The only failing tests are cygwin, which I think has nothing to do with the POD changes.

@robrwo robrwo force-pushed the rrwo/rand-recommendations branch from 0364e87 to de0535c Compare January 7, 2025 09:25
robrwo added 2 commits March 31, 2025 09:51
The CPAN Security Group (CPANSec) is currently working on guides to
generating security-quality random data [1]. We are focusing on modules
that have secure defaults and are fairly lightweight.

We would like to change the recommended modules to ones that we think
are better options.

Crypt::URandom is portable, has fewer prerequisites than Crypt::Random,
Math::Random::Secure or Data::Entropy, and works with Windows.

Crypt::PRNG has secure defaults and methods for generating different
kinds of random data.

Math::TrulyRandom hasn't been updated since 1996, and is a solution
intended for systems without something like /dev/random.

Data::Entropy had a security issue that was recently fixed, and the
latest version is marked as deprecated.

[1] https://security.metacpan.org/docs/guides/random-data-for-security.html
@robrwo robrwo force-pushed the rrwo/rand-recommendations branch from de0535c to dbce05a Compare March 31, 2025 08:54
Copy link
Contributor

@jkeenan jkeenan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perlfaq is maintained upstream on CPAN. So changes to its text should first be submitted to that distribution's issue tracker.

@robrwo
Copy link
Contributor Author

robrwo commented Apr 2, 2025

perlfaq is maintained upstream on CPAN. So changes to its text should first be submitted to that distribution's issue tracker.

Ok. perl-doc-cats/perlfaq#143

@robrwo robrwo force-pushed the rrwo/rand-recommendations branch from dbce05a to 0b731e1 Compare April 2, 2025 15:44
@robrwo robrwo requested a review from jkeenan April 2, 2025 15:46
@jkeenan
Copy link
Contributor

jkeenan commented Apr 2, 2025

I'm now satisfied with the structure of the pull request. I don't know enough about rand() to comment on the content.

@robrwo
Copy link
Contributor Author

robrwo commented Apr 8, 2025

perlfaq is maintained upstream on CPAN. So changes to its text should first be submitted to that distribution's issue tracker.

Ok. perl-doc-cats/perlfaq#143

This has been merged.

@khwilliamson
Copy link
Contributor

@robrwo Please do cd t; ./perl -I../lib porting/podcheck.t --regen and commit the changes, and repush

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants