Closed tarcieri closed 5 months ago
One example from my backyard is entropy for encryption (TLS). While getrandom
's source is OS, I wonder how reaching TRNG peripheral of some of MCU could work in such case? If I correctly understand proposal from rust-random/getrandom#4 it would require own implementation to let the further code use a standard API. That's definitely worth consideration.
One thing that works is instantiate some seedable RNG (like ChaChaRng
) and either seed it with TRNG data when booting up or periodically feed it with some entry e.g. using an interrupt.
@therealprof TRNG in ATSAMS70Q21 is fast enough to use directly as source of random numbers, we drop the need for cycles to calculate any PRNG.
@michalfita So what prevents you from using that directly?
@therealprof My point was about finding good pattern how to use the peripheral by the abstraction layer, so the use of standardised functions would still work. I'm mostly thinking about portability of the code.
i ran into this recently and ended up with a bunch of mutex and rng_core
faff to support global use of rand_core::Rng
objects while supporting platform initialisation. Unsure how to manage periodic re-seeding atm but it's here if it's useful ryankurte/rust-rand-facade.
i also completely missed that getrandom
has a feature for defining a global random function getrandom#109, which may have done the job, but isn't obvious from any documentation, so leaving that here in case anyone else runs into it.
@ryankurte
Note that this getrandom
feature is part of the (currently unreleased) v0.2 and is not present in v0.1.
https://github.com/rust-lang/rust/issues/62079#issuecomment-2148180934 suggests closing the ticket for std.
For no_std applications, https://crates.io/crates/rand_core provides good support, and implementations can be provided by HALs.
So I think this ticket can be closed.
Agreeing with @jannic, and closing as part of the 2024 triage efforts.
Of interest to this WG are some developments on rust-random, namely the new getrandom crate and plans to integrate it into
std
:https://github.com/rust-random/getrandom/issues/21
There's an open issue about
no_std
support forgetrandom
in general, including various ways it could potentially be integrated intocore
instead ofstd
:https://github.com/rust-random/getrandom/issues/4
One approach might be the addition of a new lang item.
Curious of anyone has thoughts on this for embedded device use cases. Since
embedded-hal
generally eschews global state for things like device peripherals, I'm wondering if the existingrand_core
API may actually be a better fit.