Skip to content

Use CSPRNG for Math.random()Β #60013

@oerdnj

Description

@oerdnj

What is the problem this feature will solve?

Copying from libuv/libuv#4872 (comment)

During the discussion about libuv changes, it was pointed out that Math.random() uses PRNG, and not CSPRNG. This is wrong because most people actually don't understand when they should use PRNG and when they should use CSPRNG. More on this in the above mentioned issue and also for example here: https://sortingsearching.com/2023/11/25/random.html

What is the feature you are proposing to solve the problem?

Using ChaCha20 would be a very conservative choice, but Jean-Philippe Aumasson (@veorq) argues that using ChaCha20 is actually waste of CPU cycles and using ChaCha12 would be fine both technically and socially, and using ChaCha8 would be also ok technically.

GoLang uses ChaCha8 (I would trust both Russ Cox and Filippo Valsorda on the choice), and Rust uses ChaCha12.

Since Math.random() doesn't claim it is CSPRNG, using ChaCha8 would be ok both technically and socially, and would be a great improvement over the currently used Xorshift-based PRNG.

I am offering ChaCha implementation in C licensed under MIT + whatever you need for the parts that I wrote, and I would be willing to implement this in C++. But that language is unfamiliar to me (you would have to kill me to say "C/C++"), so I am going to need some guidance here.

What alternatives have you considered?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.

    Type

    No type

    Projects

    Status

    Awaiting Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions