-
-
Notifications
You must be signed in to change notification settings - Fork 490
Description
For the original post see below the line. Deliverables tracker:
- Update the book (see here)
- Remove automatic (delayed) reseed-on-fork #1379
-
zeroizefeature? - Forward secrecy / key-erasure?
- Replacing rand_chacha with chacha20 #934 (separate issue)
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,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).
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
zeroizearoundThreadRngstate - Add
fn rand::secret_rngto access the inner RNG (bypassThreadRng's cache)