Skip to content

Rng API #38

Closed
Closed
@therealprof

Description

@therealprof

I'd like to suggest to suggest a new Rng API for a common way of getting random numbers from devices with some source of randomness.

I've already implemented this as a proof-of-concept in my nrf51-hal crate (https://github.com/therealprof/nrf51-hal) and an example use in my microbit crate (https://github.com/therealprof/microbit).

The suggested (blocking) API is similar to the I2c API in that a mutable u8 slice is passed as parameter which will be filled with the random data and a Result is returned:

//! Blocking hardware random number generator

/// Blocking read
pub trait Read {
    /// Error type
    type Error;

    /// Reads enough bytes from hardware random number generator to fill `buffer`
    fn read(&mut self, buffer: &mut [u8]) -> Result<(), Self::Error>;
}

Potentially this could also use an implementation for other (or even variable) array types, e.g. the rand crate requires a u32 slice as a seed.

I'd be happy to supply a PR for the the implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions