Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit 5a80597

Browse files
authored
Merge pull request #43 from rust-bitcoin/2019-05-hmac-engine
hmac: make `Midstate` type be something we can actually construct an engine from
2 parents 690c76a + f14f4b1 commit 5a80597

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/hmac.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ use {Error, Hash, HashEngine};
2929
#[derive(Copy, Clone, PartialEq, Eq, Default, PartialOrd, Ord, Hash)]
3030
pub struct Hmac<T: Hash>(T);
3131

32+
/// Pair of underlying hash midstates which represent the current state
33+
/// of an `HmacEngine`
34+
pub struct HmacMidState<T: Hash> {
35+
/// Midstate of the inner hash engine
36+
pub inner: <T::Engine as HashEngine>::MidState,
37+
/// Midstate of the outer hash engine
38+
pub outer: <T::Engine as HashEngine>::MidState,
39+
}
40+
3241
/// Pair of underyling hash engines, used for the inner and outer hash of HMAC
3342
#[derive(Clone)]
3443
pub struct HmacEngine<T: Hash> {
@@ -73,10 +82,13 @@ impl<T: Hash> HmacEngine<T> {
7382
}
7483

7584
impl<T: Hash> HashEngine for HmacEngine<T> {
76-
type MidState = <<T as Hash>::Engine as HashEngine>::MidState;
85+
type MidState = HmacMidState<T>;
7786

7887
fn midstate(&self) -> Self::MidState {
79-
self.iengine.midstate()
88+
HmacMidState {
89+
inner: self.iengine.midstate(),
90+
outer: self.oengine.midstate(),
91+
}
8092
}
8193

8294
const BLOCK_SIZE: usize = T::Engine::BLOCK_SIZE;

0 commit comments

Comments
 (0)