Skip to content

Commit

Permalink
Fix #46 for hmac
Browse files Browse the repository at this point in the history
  • Loading branch information
brycx committed Dec 22, 2018
1 parent 42a82d6 commit 982b84c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/hazardous/hash/blake2b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,3 +611,18 @@ fn reset_after_update_correct_resets() {
assert_eq!(state_1.is_keyed, state_2.is_keyed);
assert_eq!(state_1.size, state_2.size);
}

#[test]
fn reset_after_update_correct_resets_and_verify() {
let mut state_1 = init(None, 64).unwrap();
state_1.update(b"Tests").unwrap();
let d1 = state_1.finalize().unwrap();

let mut state_2 = init(None, 64).unwrap();
state_2.update(b"Tests").unwrap();
state_2.reset(None).unwrap();
state_2.update(b"Tests").unwrap();
let d2 = state_2.finalize().unwrap();

assert_eq!(d1, d2);
}
18 changes: 18 additions & 0 deletions src/hazardous/mac/hmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ impl Hmac {

/// Reset to `init()` state.
pub fn reset(&mut self) {
self.ipad_hasher = Sha512::default();
self.ipad_hasher.input(self.ipad.as_ref());
self.is_finalized = false;
}
Expand Down Expand Up @@ -361,3 +362,20 @@ fn reset_after_update_correct_resets() {
assert_eq!(state_1.ipad[..], state_2.ipad[..]);
assert_eq!(state_1.is_finalized, state_2.is_finalized);
}

#[test]
fn reset_after_update_correct_resets_and_verify() {
let secret_key = SecretKey::from_slice("Jefe".as_bytes());

let mut state_1 = init(&secret_key);
state_1.update(b"Tests").unwrap();
let d1 = state_1.finalize().unwrap();

let mut state_2 = init(&secret_key);
state_2.update(b"Tests").unwrap();
state_2.reset();
state_2.update(b"Tests").unwrap();
let d2 = state_2.finalize().unwrap();

assert_eq!(d1, d2);
}
17 changes: 17 additions & 0 deletions src/hazardous/mac/poly1305.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,20 @@ fn reset_after_update_correct_resets() {
assert_eq!(state_1.buffer[..], state_2.buffer[..]);
assert_eq!(state_1.is_finalized, state_2.is_finalized);
}

#[test]
fn reset_after_update_correct_resets_and_verify() {
let secret_key = OneTimeKey::from_slice(&[0u8; 32]).unwrap();

let mut state_1 = init(&secret_key);
state_1.update(b"Tests").unwrap();
let d1 = state_1.finalize().unwrap();

let mut state_2 = init(&secret_key);
state_2.update(b"Tests").unwrap();
state_2.reset();
state_2.update(b"Tests").unwrap();
let d2 = state_2.finalize().unwrap();

assert_eq!(d1, d2);
}

0 comments on commit 982b84c

Please sign in to comment.