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 support in libcore #353

Closed
tarcieri opened this issue Jun 4, 2019 · 9 comments
Closed

RNG support in libcore #353

tarcieri opened this issue Jun 4, 2019 · 9 comments

Comments

@tarcieri
Copy link

tarcieri commented Jun 4, 2019

Of interest to this WG are some developments on rust-random, namely the new getrandom crate and plans to integrate it into std:

rust-random/getrandom#21

There's an open issue about no_std support for getrandom in general, including various ways it could potentially be integrated into core instead of std:

rust-random/getrandom#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 existing rand_core API may actually be a better fit.

@michalfita
Copy link

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.

@therealprof
Copy link
Contributor

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.

@michalfita
Copy link

@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.

@therealprof
Copy link
Contributor

@michalfita So what prevents you from using that directly?

@michalfita
Copy link

@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.

@ryankurte
Copy link
Contributor

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.

@newpavlov
Copy link

@ryankurte
Note that this getrandom feature is part of the (currently unreleased) v0.2 and is not present in v0.1.

@jannic
Copy link
Member

jannic commented Jun 11, 2024

rust-lang/rust#62079 (comment) 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.

@jamesmunns
Copy link
Member

Agreeing with @jannic, and closing as part of the 2024 triage efforts.

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

7 participants