Skip to main content

embedded_cal_rustcrypto/
rng.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2// SPDX-FileCopyrightText: Inria-AIO, Cryspen, and Christian Amsüss
3
4use super::RustcryptoCalExtender;
5use embedded_cal::Cal;
6
7/// An implementation based on `getrandom`.
8///
9/// Unlike lakers, we just require that getrandom is provided; Ariel OS's random module shows that
10/// this can be done also on embedded platforms.
11// FIXME: We should probably have some fast CSPRNG in self that is just seeded from getrandom.
12impl<Base: Cal + rand_core::TryCryptoRng> rand_core::TryCryptoRng for RustcryptoCalExtender<Base> {}
13
14impl<Base: Cal + rand_core::TryRng> rand_core::TryRng for RustcryptoCalExtender<Base> {
15    type Error = Base::Error;
16
17    fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
18        self.base.try_next_u32()
19    }
20
21    fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
22        self.base.try_next_u64()
23    }
24
25    fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), Self::Error> {
26        self.base.try_fill_bytes(dst)
27    }
28}