From f14f4b1ae6142a4a58581ebc490787569076a353 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Thu, 2 May 2019 14:40:04 +0000 Subject: [PATCH] hmac: make `Midstate` type be something we can actually construct a midstate from --- src/hmac.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/hmac.rs b/src/hmac.rs index 17977e3..ebf46cd 100644 --- a/src/hmac.rs +++ b/src/hmac.rs @@ -29,6 +29,15 @@ use {Error, Hash, HashEngine}; #[derive(Copy, Clone, PartialEq, Eq, Default, PartialOrd, Ord, Hash)] pub struct Hmac(T); +/// Pair of underlying hash midstates which represent the current state +/// of an `HmacEngine` +pub struct HmacMidState { + /// Midstate of the inner hash engine + pub inner: ::MidState, + /// Midstate of the outer hash engine + pub outer: ::MidState, +} + /// Pair of underyling hash engines, used for the inner and outer hash of HMAC #[derive(Clone)] pub struct HmacEngine { @@ -73,10 +82,13 @@ impl HmacEngine { } impl HashEngine for HmacEngine { - type MidState = <::Engine as HashEngine>::MidState; + type MidState = HmacMidState; 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;