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 #335

Open
xdevs23 opened this issue Feb 21, 2025 · 3 comments
Open

rand_core v0.9 support #335

xdevs23 opened this issue Feb 21, 2025 · 3 comments

Comments

@xdevs23
Copy link

xdevs23 commented Feb 21, 2025

I'm trying to use rand_chacha to generate an SSH key but it does not accept it as ssh_key::rand_core::CryptoRngCore even though it implements rand_core::CryptoRng.
To me it seems like these are seen as different traits because of parameter mismatch due to ssh_key having its own rand_core re-export.

Code:

    let chacha = ChaCha20Rng::from_os_rng();
    PrivateKey::random(&mut chacha, ssh_key::Algorithm::Ed25519);

Error:

error[E0277]: the trait bound `ChaCha20Rng: CryptoRngCore` is not satisfied
   --> src/main.rs:41:24
    |
41  |     PrivateKey::random(&mut chacha, ssh_key::Algorithm::Ed25519);
    |     ------------------ ^^^^^^^^^^^ the trait `ssh_key::rand_core::CryptoRng` is not implemented for `ChaCha20Rng`, which is required by `ChaCha20Rng: CryptoRngCore`
    |     |
    |     required by a bound introduced by this call
    |
    = help: the following other types implement trait `ssh_key::rand_core::CryptoRng`:
              &'a mut R
              ssh_key::rand_core::block::BlockRng<R>
    = note: required for `ChaCha20Rng` to implement `CryptoRngCore`
note: required by a bound in `PrivateKey::random`
   --> /home/simao/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ssh-key-0.6.7/src/private.rs:488:34
    |
488 |     pub fn random(rng: &mut impl CryptoRngCore, algorithm: Algorithm) -> Result<Self> {
    |                                  ^^^^^^^^^^^^^ required by this bound in `PrivateKey::random`

The rand_core this is using appears to be rand_core 0.6.4.

Cargo.toml dependencies:

tokio = { version = "1.43.0", features = ["full"] }
clap = { version = "4.5.28", features = ["derive", "unicode"] }
hcloud = "0.21.0"
structured-logger = "1.0.3"
strum = "0.27"
strum_macros = "0.27"
log = "0.4.25"
thiserror = "2.0.11"
anyhow = "1.0.95"
ssh-key = { version = "0.6.7", features = ["ed25519"] }
rand_chacha = { version = "0.9.0", features = ["os_rng", "std"] }

Adding rand_core = { version = "0.9.1", features = ["os_rng", "std"] } does not help.

Is there a way to convert between ssh_key::rand_core and rand_core variants?

@tarcieri tarcieri changed the title Can't use CSPRNG from rand_chacha rand_core v0.9 support Feb 21, 2025
@tarcieri
Copy link
Member

We are in the process of upgrading all of the crates in the @RustCrypto org to rand_core v0.9. You can track upstream progress here: RustCrypto/traits#1642

@xdevs23
Copy link
Author

xdevs23 commented Feb 22, 2025

Oh that's great, thanks for letting me know. Is this going to be an ongoing issue where upgrades to rand_core could cause these issues? Or is it only when an API change happens?
I'm guessing when rand_core reaches v1 it would only break on v2.
Would you recommend using v0.6.4 in the meantime?

@tarcieri
Copy link
Member

Yes, this problem comes up every time there’s a breaking release to rand_core

For now you can use v0.6

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

2 participants