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

RNG in no_std #150

Open
xFranv8 opened this issue Feb 23, 2025 · 2 comments
Open

RNG in no_std #150

xFranv8 opened this issue Feb 23, 2025 · 2 comments
Labels
question Further information is requested

Comments

@xFranv8
Copy link

xFranv8 commented Feb 23, 2025

Hello,

I am trying to connect to a Mqtt broker with TLS from my rp pico with rust.

let mut rng = RoscRng;
let mut tls_connection: TlsConnection<_, Aes256GcmSha384> =
        TlsConnection::new(tcp_socket, &mut record_read_buf, &mut record_write_buf);

  tls_connection
      .open(TlsContext::new(
          &tls_config,
          UnsecureProvider::new::<Aes256GcmSha384>(rng),
      ))
      .await
      .unwrap();

I am using

use embassy_rp::clocks::RoscRng;
use rand::RngCore;

But receive the following error:

error[E0277]: the trait bound `RoscRng: CryptoRng` is not satisfied
   --> src/main.rs:177:5
    |
177 | /     tls_connection
178 | |         .open(TlsContext::new(
179 | |             &tls_config,
180 | |             UnsecureProvider::new::<Aes256GcmSha384>(rng),
181 | |         ))
    | |__________^ the trait `CryptoRng` is not implemented for `RoscRng`
    |
    = help: the following other types implement trait `CryptoRng`:
              &'a mut R
              rand_core::block::BlockRng<R>
    = note: required for `RoscRng` to implement `CryptoRngCore`
    = note: required for `UnsecureProvider<Aes256GcmSha384, RoscRng>` to implement `CryptoProvider`
note: required by a bound in `embedded_tls::TlsConnection::<'a, Socket, CipherSuite>::open`
   --> /Users/xfranv8/.cargo/git/checkouts/embedded-tls-6ca93bdfa1e2460b/7936bc1/src/asynch.rs:78:19
    |
73  |     pub async fn open<'v, Provider>(
    |                  ---- required by a bound in this associated function
...
78  |         Provider: CryptoProvider<CipherSuite = CipherSuite>,
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `TlsConnection::<'a, Socket, CipherSuite>::open`

Any help you could provide?

Thanks!!

@newAM
Copy link
Collaborator

newAM commented Feb 23, 2025

rand_core had a major update recently. Perhaps there are two incompatible versions here?

@newAM newAM added the question Further information is requested label Feb 23, 2025
@xFranv8
Copy link
Author

xFranv8 commented Feb 24, 2025

I solved modifying embassy_rp::clocks::RoscRng as follows:

impl rand_core::CryptoRng for RoscRng {}

However, now I am not able to connect to my wifi, as I get stuck waiting for a DHCP IP.

I can still connect if I comment this part:

tls_connection
        .open(TlsContext::new(
            &tls_config,
            UnsecureProvider::new::<Aes256GcmSha384>(rng),
        ))
        .await
        .unwrap();
log::info!("TLS connection opened");

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

No branches or pull requests

2 participants