interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / digest / src / dev.rs

78 lines · 2002 bytes Raw Blame History
1//! Development-related functionality
2
3pub use blobby;
4
5mod fixed;
6mod mac;
7mod rng;
8mod variable;
9mod xof;
10
11pub use fixed::*;
12pub use mac::*;
13pub use variable::*;
14pub use xof::*;
15
16/// Define hash function test
17#[macro_export]
18#[cfg_attr(docsrs, doc(cfg(feature = "dev")))]
19macro_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")))]
45macro_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.
67pub 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}