From 3bbd25102866a9aa1a05732ee5b487032f99632f Mon Sep 17 00:00:00 2001 From: brycx Date: Sun, 23 Dec 2018 12:36:27 +0100 Subject: [PATCH] Tests: As blake2b and cshake have multiple paramter combinations on their init(), this adds tests to verify that the recent bug #46 is fixed on all init() input combinations --- src/hazardous/hash/blake2b.rs | 15 +++++++++++++++ src/hazardous/xof/cshake.rs | 29 ++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/hazardous/hash/blake2b.rs b/src/hazardous/hash/blake2b.rs index e9d86fe5..a57e70b5 100644 --- a/src/hazardous/hash/blake2b.rs +++ b/src/hazardous/hash/blake2b.rs @@ -614,6 +614,7 @@ fn reset_after_update_correct_resets() { #[test] fn reset_after_update_correct_resets_and_verify() { + // In non-keyed mode let mut state_1 = init(None, 64).unwrap(); state_1.update(b"Tests").unwrap(); let d1 = state_1.finalize().unwrap(); @@ -625,4 +626,18 @@ fn reset_after_update_correct_resets_and_verify() { let d2 = state_2.finalize().unwrap(); assert_eq!(d1, d2); + + // In keyed mode + let key = SecretKey::from_slice(&[0u8; 64]).unwrap(); + let mut state_1 = init(Some(&key), 64).unwrap(); + state_1.update(b"Tests").unwrap(); + let d1 = state_1.finalize().unwrap(); + + let mut state_2 = init(Some(&key), 64).unwrap(); + state_2.update(b"Tests").unwrap(); + state_2.reset(Some(&key)).unwrap(); + state_2.update(b"Tests").unwrap(); + let d2 = state_2.finalize().unwrap(); + + assert_eq!(d1, d2); } diff --git a/src/hazardous/xof/cshake.rs b/src/hazardous/xof/cshake.rs index 24d41d2d..b717f98e 100644 --- a/src/hazardous/xof/cshake.rs +++ b/src/hazardous/xof/cshake.rs @@ -481,11 +481,12 @@ mod test { #[test] fn reset_after_update_correct_resets() { let input = b"\x00\x01\x02\x03"; - let custom = b""; + let custom = b"Hello world"; let name = b"Email Signature"; let mut out = [0u8; 64]; let mut out2 = [0u8; 64]; + // With optional name paramter and non-empty custom let mut cshake = init(custom, Some(name)).unwrap(); cshake.update(input).unwrap(); cshake.finalize(&mut out).unwrap(); @@ -497,5 +498,31 @@ mod test { cshake2.finalize(&mut out2).unwrap(); assert!(out[..] == out2[..]); + + // With optional name paramter and empty custom + let mut cshake = init(b"", Some(name)).unwrap(); + cshake.update(input).unwrap(); + cshake.finalize(&mut out).unwrap(); + + let mut cshake2 = init(b"", Some(name)).unwrap(); + cshake2.update(input).unwrap(); + cshake2.reset(); + cshake2.update(input).unwrap(); + cshake2.finalize(&mut out2).unwrap(); + + assert!(out[..] == out2[..]); + + // Without optional name parameter + let mut cshake = init(custom, None).unwrap(); + cshake.update(input).unwrap(); + cshake.finalize(&mut out).unwrap(); + + let mut cshake2 = init(custom, None).unwrap(); + cshake2.update(input).unwrap(); + cshake2.reset(); + cshake2.update(input).unwrap(); + cshake2.finalize(&mut out2).unwrap(); + + assert!(out[..] == out2[..]); } }