Skip to content

Commit

Permalink
Testing: Remove CAVP SHAVS Monte Carlo tests.
Browse files Browse the repository at this point in the history
They are slow and they don't add much value.
  • Loading branch information
briansmith committed Oct 4, 2024
1 parent 25cc803 commit 88974ea
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 1,603 deletions.
59 changes: 1 addition & 58 deletions cavp/tests/shavs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod digest_shavs {
( $file_name:ident, $algorithm_name:ident ) => {
#[allow(non_snake_case)]
mod $algorithm_name {
use super::{run_known_answer_test, run_monte_carlo_test};
use super::run_known_answer_test;
use ring::{digest, test_file};

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
Expand Down Expand Up @@ -77,67 +77,10 @@ mod digest_shavs {
)),
);
}

#[test]
fn monte_carlo_test() {
run_monte_carlo_test(
&digest::$algorithm_name,
test_file!(concat!(
"../third_party/NIST/SHAVS/",
stringify!($file_name),
"Monte.rsp"
)),
);
}
}
};
}

fn run_monte_carlo_test(digest_alg: &'static digest::Algorithm, test_file: test::File) {
let section_name = &format!("L = {}", digest_alg.output_len());

let mut expected_count: isize = -1;
let mut seed = Vec::with_capacity(digest_alg.output_len());

test::run(test_file, |section, test_case| {
assert_eq!(section_name, section);

if expected_count == -1 {
seed.extend(test_case.consume_bytes("Seed"));
expected_count = 0;
return Ok(());
}

assert!(expected_count >= 0);
let actual_count = test_case.consume_usize("COUNT");
assert_eq!(expected_count as usize, actual_count);
expected_count += 1;

let expected_md = test_case.consume_bytes("MD");

let mut mds = Vec::with_capacity(4);
mds.push(seed.clone());
mds.push(seed.clone());
mds.push(seed.clone());
for _ in 0..1000 {
let mut ctx = digest::Context::new(digest_alg);
ctx.update(&mds[0]);
ctx.update(&mds[1]);
ctx.update(&mds[2]);
let md_i = ctx.finish();
let _ = mds.remove(0);
mds.push(Vec::from(md_i.as_ref()));
}
let md_j = mds.last().unwrap();
assert_eq!(&expected_md, md_j);
seed.clone_from(md_j);

Ok(())
});

assert_eq!(expected_count, 100);
}

shavs_tests!(SHA1, SHA1_FOR_LEGACY_USE_ONLY);
shavs_tests!(SHA256, SHA256);
shavs_tests!(SHA384, SHA384);
Expand Down
309 changes: 0 additions & 309 deletions cavp/third_party/NIST/SHAVS/SHA1Monte.rsp

This file was deleted.

Loading

0 comments on commit 88974ea

Please sign in to comment.