### Collect Entropy Data for NIST SP 800-90B Source: https://github.com/rust-random/rngs/blob/master/rand_jitter/README.md This example demonstrates how to collect entropy data using `JitterRng::new_with_timer` and `timer_stats` for use with the NIST SP 800-90B Entropy Estimation Suite. It collects a specified number of timer deltas and saves them to binary files. ```rust use rand_jitter::JitterRng; use std::error::Error; use std::fs::File; use std::io::Write; fn get_nstime() -> u64 { use std::time::{SystemTime, UNIX_EPOCH}; let dur = SystemTime::now().duration_since(UNIX_EPOCH).unwrap(); // The correct way to calculate the current time is // `dur.as_secs() * 1_000_000_000 + dur.subsec_nanos() as u64` // But this is faster, and the difference in terms of entropy is // negligible (log2(10^9) == 29.9). dur.as_secs() << 30 | dur.subsec_nanos() as u64 } fn main() -> Result<(), Box> { let mut rng = JitterRng::new_with_timer(get_nstime); // 1_000_000 results are required for the // NIST SP 800-90B Entropy Estimation Suite const ROUNDS: usize = 1_000_000; let mut deltas_variable: Vec = Vec::with_capacity(ROUNDS); let mut deltas_minimal: Vec = Vec::with_capacity(ROUNDS); for _ in 0..ROUNDS { deltas_variable.push(rng.timer_stats(true) as u8); deltas_minimal.push(rng.timer_stats(false) as u8); } // Write out after the statistics collection loop, to not disturb the // test results. File::create("jitter_rng_var.bin")?.write(&deltas_variable)?; File::create("jitter_rng_min.bin")?.write(&deltas_minimal)?; Ok(()) } ``` -------------------------------- ### Estimate Entropy with NIST SP 800-90B (Shell) Source: https://github.com/rust-random/rngs/blob/master/rand_jitter/README.md These shell commands demonstrate how to use the NIST SP 800-90B Entropy Estimation Suite with the collected jitter RNG data. They cover estimating entropy with variable noise sources, and with minimal noise sources. ```sh python noniid_main.py -v jitter_rng_var.bin 8 restart.py -v jitter_rng_var.bin 8 ``` ```sh python noniid_main.py -v -u 4 jitter_rng_var.bin 4 restart.py -v -u 4 jitter_rng_var.bin 4 ``` ```sh python noniid_main.py -v -u 4 jitter_rng_min.bin 4 restart.py -v -u 4 jitter_rng_min.bin 4 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.