diff --git a/sha1-checked/tests/mod.rs b/sha1-checked/tests/mod.rs index 72708117..7f09ab45 100644 --- a/sha1-checked/tests/mod.rs +++ b/sha1-checked/tests/mod.rs @@ -30,6 +30,7 @@ fn shambles_1() { &include_bytes!("./data/sha-mbles-1.bin")[..], hex!("8ac60ba76f1999a1ab70223f225aefdc78d4ddc0"), hex!("4f3d9be4a472c4dae83c6314aa6c36a064c1fd14"), + None, false, ); } @@ -40,6 +41,7 @@ fn shambles_2() { &include_bytes!("./data/sha-mbles-2.bin")[..], hex!("8ac60ba76f1999a1ab70223f225aefdc78d4ddc0"), hex!("9ed5d77a4f48be1dbf3e9e15650733eb850897f2"), + None, false, ); } @@ -50,6 +52,7 @@ fn shattered_1() { &include_bytes!("./data/shattered-1.pdf")[..], hex!("38762cf7f55934b34d179ae6a4c80cadccbb7f0a"), hex!("16e96b70000dd1e7c85b8368ee197754400e58ec"), + Some(hex!("d3a1d09969c3b57113fd17b23e01dd3de74a99bb")), false, ); } @@ -60,6 +63,7 @@ fn shattered_2() { &include_bytes!("./data/shattered-2.pdf")[..], hex!("38762cf7f55934b34d179ae6a4c80cadccbb7f0a"), hex!("e1761773e6a35916d99f891b77663e6405313587"), + Some(hex!("92246b0b718f4c704d37bb025717cbc66babf102")), false, ); } @@ -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. @@ -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); + } }