Skip to content

Commit

Permalink
Tests: As blake2b and cshake have multiple paramter combinations on t…
Browse files Browse the repository at this point in the history
…heir init(), this adds tests to verify that the recent bug #46 is fixed on all init() input combinations
  • Loading branch information
brycx committed Dec 23, 2018
1 parent 982b84c commit 3bbd251
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/hazardous/hash/blake2b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
29 changes: 28 additions & 1 deletion src/hazardous/xof/cshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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[..]);
}
}

0 comments on commit 3bbd251

Please sign in to comment.