Skip to content

RNG support in libcore #353

Closed
Closed

Description

@tarcieri

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.

Activity

  1. michalfita commented on Jul 10, 2019

    @michalfita

    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.

  2. therealprof commented on Jul 10, 2019

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

  3. michalfita commented on Jul 11, 2019

    @michalfita

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

  4. therealprof commented on Jul 11, 2019

    @therealprof
    Contributor

    @michalfita So what prevents you from using that directly?

  5. michalfita commented on Jul 11, 2019

    @michalfita

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

  6. ryankurte commented on Jul 13, 2020

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

  7. newpavlov commented on Jul 13, 2020

    @newpavlov

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

  8. jannic commented on Jun 11, 2024

    @jannic
    Member

    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.

  9. jamesmunns commented on Jun 11, 2024

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions