For the original post see below the line. Deliverables tracker:
Cross-posting from here for visibility — the book may document policy, but it affects the whole project.
I've seen a few projects use rand in security sensitive code.
A reviewer may eventually point them to this warning in the book:
https://github.com/rust-random/book/blame/master/src/guide-rngs.md#L263-L271
Inferring that rand does not provide cryptographically secure prngs and they should use a different random library.
Well,
- Rand is not in any way certified for cryptographic security.
SeedableRng::from_entropy, OsRng and the getrandom crate attempt to offer strong seeding from an external source
CryptoRng and CryptoBlockRng are type-level documentation that implementers are supposed to be cryptographically secure (unpredictable given past outputs), but don't require any direct protection of their state (e.g. I don't think our implementations attempt to zero their state on destruction)
ThreadRng builds on the above and includes periodic reseeding and periodic fork-detection, but this may be insufficient in some cases (e.g. perhaps we should add a method to force immediate fork-detection for use before key-generation or even allow bypassing its buffer for when secrecy is more important than performance).
Is this warning out of date?
Not really; we don't have a formal policy.
Instead Rand attempts to choose reasonable compromises between performance, security and usability for a general audience. It is not marketed as a cryptographic product, but is hopefully good enough not to be a major security flaw in case it is (mis)used as one.
I'm not sure if Rand should go beyond this, unless it were to move from a volunteer project to a professional one. That said, I do have some possible ideas for improvements:
- Use
zeroize around ThreadRng state
- Add
fn rand::secret_rng to access the inner RNG (bypass ThreadRng's cache)
See also #543, #882, #463
CC @vks @newpavlov @josephlr @joshlf @tarcieri
For the original post see below the line. Deliverables tracker:
zeroizefeature?Cross-posting from here for visibility — the book may document policy, but it affects the whole project.
Well,
SeedableRng::from_entropy,OsRngand thegetrandomcrate attempt to offer strong seeding from an external sourceCryptoRngandCryptoBlockRngare type-level documentation that implementers are supposed to be cryptographically secure (unpredictable given past outputs), but don't require any direct protection of their state (e.g. I don't think our implementations attempt to zero their state on destruction)ThreadRngbuilds on the above and includes periodic reseeding and periodic fork-detection, but this may be insufficient in some cases (e.g. perhaps we should add a method to force immediate fork-detection for use before key-generation or even allow bypassing its buffer for when secrecy is more important than performance).Not really; we don't have a formal policy.
Instead Rand attempts to choose reasonable compromises between performance, security and usability for a general audience. It is not marketed as a cryptographic product, but is hopefully good enough not to be a major security flaw in case it is (mis)used as one.
I'm not sure if Rand should go beyond this, unless it were to move from a volunteer project to a professional one. That said, I do have some possible ideas for improvements:
zeroizearoundThreadRngstatefn rand::secret_rngto access the inner RNG (bypassThreadRng's cache)See also #543, #882, #463
CC @vks @newpavlov @josephlr @joshlf @tarcieri