rust-random / rust-random/rand
The future of `ThreadRng`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 2.1k
- Forks
- 512
- Avg merge
- 3d 9h
- Merged PRs (30d)
- 7
Description
Can we have one generator to do it all (excepting reproducibility)? ThreadRng attempts to achieve this:
- It's fairly fast
- It only requires 320 bytes + overhead (
Rcandthread_local) per thread - It's unpredictable
- It has periodic reseeding
Put another way, there are reasons that this is sub-optimal:
SmallRngis significantly faster (very roughly double the performance) and much smaller (32 bytes) while being good enough for many usesThreadRngdoes not currently have forward secrecy. We could tack this on for approx 10-25% performance overhead.
Plan
ThreadRng has quite a few users, so I do not believe we should just abandon it. Instead, I propose:
- Re-add
ReseedingRngnot as a generic wrapper but as a concrete struct overChaCha12with periodic reseeding and fast erasure. - Add
StrongRng(name?) as a handle to aMutex<ReseedingRng>in static memory (feature-gated, default off). - Add
SmallThreadRngas a thread-localSmallRngand mayberand::fast_rng()to access it (feature-gated, default off). - If possible,
#[deprecate]the existingThreadRngand methods after adding replacements before the next breaking release.
Note: the fast-erasure (forward secrecy) addition requires breaking changes to rand_core. The rest should be possible to add in a patch release.
Note: this is very much a tentative plan. Feedback welcome!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing ThreadRng and rand_core interfaces, then compare the proposed ReseedingRng over ChaCha12, StrongRng, and SmallThreadRng entry points. Done means the tentative replacement and deprecation plan is resolved and implemented, with the required forward-secrecy changes to rand_core accounted for.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cryptography
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100