Skip to content
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

README: rand is not a crypto library #1514

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

dhardy
Copy link
Member

@dhardy dhardy commented Oct 16, 2024

Closes #1358 by documenting what Rand is not.

@dhardy dhardy mentioned this pull request Oct 16, 2024
5 tasks
@newpavlov
Copy link
Member

newpavlov commented Oct 16, 2024

I think it's worth to explicitly state that ThreadRng is suitable for generation of cryptographic material (keys, nonces, salts, seeds, etc.), but users should account for the listed security caveats and use OsRng when in doubt. It's also worth to add that ThreadRng does not provide forward secrecy guarantees in time between re-seedings.

@dhardy
Copy link
Member Author

dhardy commented Oct 17, 2024

Updated.

Ultimately, I'm not comfortable with saying definitively that it is is suitable for XYZ. I attempted to document things such that users get the right message and can decide for themselves.

@tarcieri and @dcmiddle may have comments?

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
/// - Not to leak internal state through [`Debug`] or serialization
/// implementations.
/// - No further protections exist to in-memory state. In particular, the
/// implementation is not required to zero memory on exit (of the process or

Choose a reason for hiding this comment

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

Just curious.. is that because it's onerous to implement or causes a performance hit or something else?

Copy link
Member Author

Choose a reason for hiding this comment

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

zeroize? It's just not been done (so far). It has been implemented by the chacha20 crate, so we gain this feature when we switch (with a little adjustment to ThreadRng).

Copy link

@dcmiddle dcmiddle left a comment

Choose a reason for hiding this comment

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

These are useful clarifications that address the substance of #1358. Thanks for working through these.

dhardy and others added 2 commits October 17, 2024 17:17
Co-authored-by: Dan <[email protected]>
@dhardy
Copy link
Member Author

dhardy commented Oct 17, 2024

Thanks for the review!

[`zeroize`](https://crates.io/crates/zeroize) used buffers and generators.
We do not automatically reseed on fork (see
[`ThreadRng`](https://docs.rs/rand/latest/rand/rngs/struct.ThreadRng.html)).
Rand cannot provide any guarantees of security.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we can recommend using getrandom directly if you need guarantees? Most crypto applications don't need a userspace CSPRNG, and I think this is what crypto libraries like ring do.

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

Successfully merging this pull request may close these issues.

Policy: "not a crypto library"?
4 participants