diff --git a/hashes/src/macros.rs b/hashes/src/macros.rs index dc134577a..12ca01520 100644 --- a/hashes/src/macros.rs +++ b/hashes/src/macros.rs @@ -33,11 +33,7 @@ macro_rules! sha256t_tag { $crate::sha256t_tag_struct!($tag_vis, $tag, stringify!($hash_name), $(#[$($tag_attr)*])*); impl $crate::sha256t::Tag for $tag { - #[inline] - fn engine() -> $crate::sha256::HashEngine { - const MIDSTATE: $crate::sha256::Midstate = $crate::sha256t_tag_constructor!($constructor, $($tag_value)+); - $crate::sha256::HashEngine::from_midstate(MIDSTATE) - } + const MIDSTATE: $crate::sha256::Midstate = $crate::sha256t_tag_constructor!($constructor, $($tag_value)+); } } } diff --git a/hashes/src/sha256t/mod.rs b/hashes/src/sha256t/mod.rs index 2e7ddf89d..4a4ce84ee 100644 --- a/hashes/src/sha256t/mod.rs +++ b/hashes/src/sha256t/mod.rs @@ -11,8 +11,13 @@ type HashEngine = sha256::HashEngine; /// Trait representing a tag that can be used as a context for SHA256t hashes. pub trait Tag { + /// The [`Midstate`] after pre-tagging the hash engine. + const MIDSTATE: sha256::Midstate; + /// Returns a hash engine that is pre-tagged and is ready to be used for the data. - fn engine() -> sha256::HashEngine; + fn engine() -> sha256::HashEngine { + sha256::HashEngine::from_midstate(Self::MIDSTATE) + } } /// Output of the SHA256t hash function. @@ -190,11 +195,7 @@ mod tests { pub struct TestHashTag; impl sha256t::Tag for TestHashTag { - fn engine() -> sha256::HashEngine { - // The TapRoot TapLeaf midstate. - let midstate = sha256::Midstate::new(TEST_MIDSTATE, 64); - sha256::HashEngine::from_midstate(midstate) - } + const MIDSTATE: sha256::Midstate = sha256::Midstate::new(TEST_MIDSTATE, 64); } // We support manually implementing `Tag` and creating a tagged hash from it. diff --git a/hashes/tests/regression.rs b/hashes/tests/regression.rs index 0b6856794..a4ffddc2f 100644 --- a/hashes/tests/regression.rs +++ b/hashes/tests/regression.rs @@ -40,10 +40,7 @@ impl_regression_test! { pub struct RegHashTag; impl sha256t::Tag for RegHashTag { - fn engine() -> sha256::HashEngine { - let midstate = sha256::Midstate::new([0xab; 32], 64); - sha256::HashEngine::from_midstate(midstate) - } + const MIDSTATE: sha256::Midstate = sha256::Midstate::new([0xab; 32], 64); } type RegHash = sha256t::Hash;