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

rand_core v0.9 support #466

Open
EricZHANG1688 opened this issue Jan 28, 2025 · 3 comments
Open

rand_core v0.9 support #466

EricZHANG1688 opened this issue Jan 28, 2025 · 3 comments

Comments

@EricZHANG1688
Copy link

So with v 0.9.0 for rand and rand_core, will get a error like 'error[E0277]: the trait bound ThreadRng: CryptoRngCore is not satisfied".

@c410-f3r
Copy link

c410-f3r commented Feb 11, 2025

With the possible addition of rust-lang/rust#130703 it would be nice to avoid hard-coding rand in public interfaces.

For example, some functions could provide a callback where the user is responsible for providing entropy.

pub fn encrypt(msg: &[u8], cb: impl FnOnce(&mut [u8])) -> Result<Vec<u8>> {
  ...
}

let mut rng = thread_rng();
encrypt(&[1, 2, 3, 4], |slice| {
  rng.fill_bytes(slice);
})?;

@Its-Just-Nans
Copy link

Related to RustCrypto/traits#1642

@tarcieri
Copy link
Member

tarcieri commented Feb 11, 2025

@c410-f3r the nice thing about CryptoRng is it provides a type-safe interface for ensuring the supplied RNG is actually safe to use for cryptography. A "just make some bytes" API like that can be easily misused with RNGs which are unsuitable for cryptographic use.

In the next set of releases of the https://github.com/rustcrypto/traits crates, we're also providing (and pushing people towards) a non-parameterized random generation APIs which avoids compatibility problems between crate versions and explicit RNGs: RustCrypto/traits#1371

@tarcieri tarcieri changed the title CryptoRngCore was removed from the latest version of rand_core rand_core v0.9 support Feb 12, 2025
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

No branches or pull requests

4 participants