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

Commit

Permalink
Merge pull request #43 from rust-bitcoin/2019-05-hmac-engine
Browse files Browse the repository at this point in the history
hmac: make `Midstate` type be something we can actually construct an engine from
  • Loading branch information
apoelstra authored May 2, 2019
2 parents 690c76a + f14f4b1 commit 5a80597
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/hmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ use {Error, Hash, HashEngine};
#[derive(Copy, Clone, PartialEq, Eq, Default, PartialOrd, Ord, Hash)]
pub struct Hmac<T: Hash>(T);

/// Pair of underlying hash midstates which represent the current state
/// of an `HmacEngine`
pub struct HmacMidState<T: Hash> {
/// Midstate of the inner hash engine
pub inner: <T::Engine as HashEngine>::MidState,
/// Midstate of the outer hash engine
pub outer: <T::Engine as HashEngine>::MidState,
}

/// Pair of underyling hash engines, used for the inner and outer hash of HMAC
#[derive(Clone)]
pub struct HmacEngine<T: Hash> {
Expand Down Expand Up @@ -73,10 +82,13 @@ impl<T: Hash> HmacEngine<T> {
}

impl<T: Hash> HashEngine for HmacEngine<T> {
type MidState = <<T as Hash>::Engine as HashEngine>::MidState;
type MidState = HmacMidState<T>;

fn midstate(&self) -> Self::MidState {
self.iengine.midstate()
HmacMidState {
inner: self.iengine.midstate(),
outer: self.oengine.midstate(),
}
}

const BLOCK_SIZE: usize = T::Engine::BLOCK_SIZE;
Expand Down

0 comments on commit 5a80597

Please sign in to comment.