forked from ryankurte/rngcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Based on an example provided by Ryan in [1] [1]: ryankurte#1 (comment)
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use rand::{RngCore, rngs::OsRng}; | ||
use rngcheck::{nist::*, helpers::*}; | ||
|
||
fn main() { | ||
let mut rng = OsRng; | ||
|
||
// Fetch random bytes for tests | ||
let mut a = [0xFF; 100]; | ||
rng.fill_bytes(&mut a); | ||
|
||
// Check we filled -something- before attempting more in-depth tests | ||
if &a[..2] == &[0xFF; 2] && &a[a.len() - 2..] == &[0xFF; 2] { | ||
panic!("RNG seems to have no-op'ed"); | ||
} | ||
|
||
// Run NIST frequency checks | ||
println!("Monobit result: {:?}", nist_freq_monobit(BitIter::new(&a))); | ||
println!("Freq block result: {:?}", nist_freq_block(BitIter::new(&a), 10)); | ||
} |