aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / vendor / digest / src / dev.rs
| 1 | //! Development-related functionality |
| 2 | |
| 3 | pub use blobby; |
| 4 | |
| 5 | mod fixed; |
| 6 | mod mac; |
| 7 | mod rng; |
| 8 | mod variable; |
| 9 | mod xof; |
| 10 | |
| 11 | pub use fixed::*; |
| 12 | pub use mac::*; |
| 13 | pub use variable::*; |
| 14 | pub use xof::*; |
| 15 | |
| 16 | /// Define hash function test |
| 17 | #[macro_export] |
| 18 | #[cfg_attr(docsrs, doc(cfg(feature = "dev")))] |
| 19 | macro_rules! new_test { |
| 20 | ($name:ident, $test_name:expr, $hasher:ty, $test_func:ident $(,)?) => { |
| 21 | #[test] |
| 22 | fn $name() { |
| 23 | use digest::dev::blobby::Blob2Iterator; |
| 24 | let data = include_bytes!(concat!("data/", $test_name, ".blb")); |
| 25 | |
| 26 | for (i, row) in Blob2Iterator::new(data).unwrap().enumerate() { |
| 27 | let [input, output] = row.unwrap(); |
| 28 | if let Some(desc) = $test_func::<$hasher>(input, output) { |
| 29 | panic!( |
| 30 | "\n\ |
| 31 | Failed test №{}: {}\n\ |
| 32 | input:\t{:?}\n\ |
| 33 | output:\t{:?}\n", |
| 34 | i, desc, input, output, |
| 35 | ); |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | }; |
| 40 | } |
| 41 | |
| 42 | /// Define [`Update`][crate::Update] impl benchmark |
| 43 | #[macro_export] |
| 44 | #[cfg_attr(docsrs, doc(cfg(feature = "dev")))] |
| 45 | macro_rules! bench_update { |
| 46 | ( |
| 47 | $init:expr; |
| 48 | $($name:ident $bs:expr;)* |
| 49 | ) => { |
| 50 | $( |
| 51 | #[bench] |
| 52 | fn $name(b: &mut Bencher) { |
| 53 | let mut d = $init; |
| 54 | let data = [0; $bs]; |
| 55 | |
| 56 | b.iter(|| { |
| 57 | digest::Update::update(&mut d, &data[..]); |
| 58 | }); |
| 59 | |
| 60 | b.bytes = $bs; |
| 61 | } |
| 62 | )* |
| 63 | }; |
| 64 | } |
| 65 | |
| 66 | /// Feed ~1 MiB of pseudorandom data to an updatable state. |
| 67 | pub fn feed_rand_16mib<D: crate::Update>(d: &mut D) { |
| 68 | let buf = &mut [0u8; 1024]; |
| 69 | let mut rng = rng::RNG; |
| 70 | let n = 16 * (1 << 20) / buf.len(); |
| 71 | for _ in 0..n { |
| 72 | rng.fill(buf); |
| 73 | d.update(buf); |
| 74 | // additional byte, so size of fed data |
| 75 | // will not be multiple of block size |
| 76 | d.update(&[42]); |
| 77 | } |
| 78 | } |