Skip to content

Commit

Permalink
test: add more reduced rounds hash test
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Mar 4, 2024
1 parent ac3024c commit 98e498e
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions sha1-checked/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fn shambles_1() {
&include_bytes!("./data/sha-mbles-1.bin")[..],
hex!("8ac60ba76f1999a1ab70223f225aefdc78d4ddc0"),
hex!("4f3d9be4a472c4dae83c6314aa6c36a064c1fd14"),
None,
false,
);
}
Expand All @@ -40,6 +41,7 @@ fn shambles_2() {
&include_bytes!("./data/sha-mbles-2.bin")[..],
hex!("8ac60ba76f1999a1ab70223f225aefdc78d4ddc0"),
hex!("9ed5d77a4f48be1dbf3e9e15650733eb850897f2"),
None,
false,
);
}
Expand All @@ -50,6 +52,7 @@ fn shattered_1() {
&include_bytes!("./data/shattered-1.pdf")[..],
hex!("38762cf7f55934b34d179ae6a4c80cadccbb7f0a"),
hex!("16e96b70000dd1e7c85b8368ee197754400e58ec"),
Some(hex!("d3a1d09969c3b57113fd17b23e01dd3de74a99bb")),
false,
);
}
Expand All @@ -60,6 +63,7 @@ fn shattered_2() {
&include_bytes!("./data/shattered-2.pdf")[..],
hex!("38762cf7f55934b34d179ae6a4c80cadccbb7f0a"),
hex!("e1761773e6a35916d99f891b77663e6405313587"),
Some(hex!("92246b0b718f4c704d37bb025717cbc66babf102")),
false,
);
}
Expand All @@ -70,11 +74,18 @@ fn reducedsha_coll() {
&include_bytes!("./data/sha1_reducedsha_coll.bin")[..],
hex!("a56374e1cf4c3746499bc7c0acb39498ad2ee185"),
hex!("dd39885a2a5d8f59030b451e00cb45da9f9d3828"),
Some(hex!("dd39885a2a5d8f59030b451e00cb45da9f9d3828")),
true,
)
);
}

fn collision_test(input: &[u8], hash: [u8; 20], mitigated_hash: [u8; 20], reduced_rounds: bool) {
fn collision_test(
input: &[u8],
hash: [u8; 20],
mitigated_hash: [u8; 20],
reduced_rounds_mitigated: Option<[u8; 20]>,
reduced_rounds: bool,
) {
let has_collision = true;

// No detection.
Expand Down Expand Up @@ -114,4 +125,12 @@ fn collision_test(input: &[u8], hash: [u8; 20], mitigated_hash: [u8; 20], reduce
let d = ctx.try_finalize();
assert_eq!(d.has_collision(), has_collision);
assert_eq!(&d.hash()[..], mitigated_hash);

if let Some(rr) = reduced_rounds_mitigated {
let mut ctx = Sha1::builder().reduced_round_collision(true).build();
ctx.update(input);
let d = ctx.try_finalize();
assert_eq!(d.has_collision(), has_collision);
assert_eq!(&d.hash()[..], rr);
}
}

0 comments on commit 98e498e

Please sign in to comment.