pub struct Trng<'d, M: Mode> { /* private fields */ }Expand description
True Random Number Generator Driver for RP2350
This driver provides async and blocking options.
See Config for configuration details.
Usage example:
use embassy_executor::Spawner;
use embassy_rp::trng::Trng;
use embassy_rp::peripherals::TRNG;
use embassy_rp::bind_interrupts;
bind_interrupts!(struct Irqs {
TRNG_IRQ => embassy_rp::trng::InterruptHandler<TRNG>;
});
#[embassy_executor::main]
async fn main(spawner: Spawner) {
let peripherals = embassy_rp::init(Default::default());
let mut trng = Trng::new(peripherals.TRNG, Irqs, embassy_rp::trng::Config::default());
let mut randomness = [0u8; 58];
loop {
trng.fill_bytes(&mut randomness).await;
assert_ne!(randomness, [0u8; 58]);
}
}Implementations§
Source§impl<'d> Trng<'d, Blocking>
impl<'d> Trng<'d, Blocking>
Sourcepub fn new_blocking<T: Instance>(_trng: Peri<'d, T>, config: Config) -> Self
pub fn new_blocking<T: Instance>(_trng: Peri<'d, T>, config: Config) -> Self
Create a new TRNG driver in blocking mode.
Source§impl<'d> Trng<'d, Async>
impl<'d> Trng<'d, Async>
Sourcepub async fn fill_bytes(&mut self, destination: &mut [u8])
pub async fn fill_bytes(&mut self, destination: &mut [u8])
Fill the buffer with random bytes.
Source§impl<'d, M: Mode> Trng<'d, M>
impl<'d, M: Mode> Trng<'d, M>
Sourcepub fn blocking_fill_bytes(&mut self, destination: &mut [u8])
pub fn blocking_fill_bytes(&mut self, destination: &mut [u8])
Fill the buffer with random bytes, blocking version.
Sourcepub fn blocking_next_u32(&mut self) -> u32
pub fn blocking_next_u32(&mut self) -> u32
Return a random u32, blocking.
Sourcepub fn blocking_next_u64(&mut self) -> u64
pub fn blocking_next_u64(&mut self) -> u64
Return a random u64, blocking.
Trait Implementations§
impl<'d, M: Mode> TryCryptoRng for Trng<'d, M>
Auto Trait Implementations§
impl<'d, M> !RefUnwindSafe for Trng<'d, M>
impl<'d, M> !UnwindSafe for Trng<'d, M>
impl<'d, M> Freeze for Trng<'d, M>
impl<'d, M> Send for Trng<'d, M>
impl<'d, M> Sync for Trng<'d, M>
impl<'d, M> Unpin for Trng<'d, M>
impl<'d, M> UnsafeUnpin for Trng<'d, M>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more