Skip to content

Commit cf0c4ed

Browse files
committed
digest: move EagerHash from hmac
Originally added in RustCrypto/MACs#151 The situation is `ecdsa` has a trait for the "default" hash function to use for a particular curve, which we want to work with RFC6979 and ergo HMAC, so we would like to use an `EagerHash` bound. But `rfc6979` is an optional dependency, so we can't depend on its transitive accessibility to `rfc6979::hmac`. This PR added `hmac` as a dependency gated on the `digest` feature of `ecdsa`: RustCrypto/signatures#1076 But as I was looking at `EagerHash` I noticed there's nothing HMAC-specific about it at all and it can easily be moved to `digest`, so we're able to use it in bounds without any other dependencies besides `digest`, which would be nice.
1 parent f2bf913 commit cf0c4ed

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

digest/src/block_api.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! Usage of traits in this module in user code is discouraged. Instead use
44
//! core algorithm wrapped by the wrapper types, which implement the
55
//! higher-level traits.
6-
use crate::InvalidOutputSize;
6+
use crate::{Digest, HashMarker, InvalidOutputSize};
77

88
pub use block_buffer::{Eager, Lazy};
99
pub use crypto_common::{AlgorithmName, Block, BlockSizeUser, OutputSizeUser, Reset};
@@ -30,6 +30,32 @@ pub trait BufferKindUser: BlockSizeUser {
3030
type BufferKind: BufferKind;
3131
}
3232

33+
/// Trait implemented by eager hashes which expose their block-level core.
34+
pub trait EagerHash: BlockSizeUser + Digest {
35+
/// Block-level core type of the hash.
36+
type Core: HashMarker
37+
+ UpdateCore
38+
+ FixedOutputCore
39+
+ BlockSizeUser<BlockSize = <Self as BlockSizeUser>::BlockSize>
40+
+ BufferKindUser<BufferKind = Eager>
41+
+ Default
42+
+ Clone;
43+
}
44+
45+
impl<T> EagerHash for T
46+
where
47+
T: CoreProxy + BlockSizeUser + Digest,
48+
<T as CoreProxy>::Core: HashMarker
49+
+ UpdateCore
50+
+ FixedOutputCore
51+
+ BlockSizeUser<BlockSize = <Self as BlockSizeUser>::BlockSize>
52+
+ BufferKindUser<BufferKind = Eager>
53+
+ Default
54+
+ Clone,
55+
{
56+
type Core = T::Core;
57+
}
58+
3359
/// Core trait for hash functions with fixed output size.
3460
pub trait FixedOutputCore: UpdateCore + BufferKindUser + OutputSizeUser {
3561
/// Finalize state using remaining data stored in the provided block buffer,

0 commit comments

Comments
 (0)