//! DomiStream's randomness comes from the caller; the probe hands it the OS generator. use domistream::RandomSource; use ring::rand::{SecureRandom, SystemRandom}; /// The operating system's cryptographic generator. pub struct OsRandom(SystemRandom); impl OsRandom { pub fn new() -> Self { Self(SystemRandom::new()) } } impl RandomSource for OsRandom { fn fill(&mut self, dest: &mut [u8]) { // Keys, salts and the PIN depend on this; without the OS generator nothing may go on. if self.0.fill(dest).is_err() { eprintln!("probe: the OS random generator failed; stopping"); std::process::exit(1); } } } /// SHA-256 of `data`, as lower-case hex (certificate fingerprints in the log). pub fn sha256_hex(data: &[u8]) -> String { crate::log::hex(ring::digest::digest(&ring::digest::SHA256, data).as_ref()) }