Skip to content

Commit 526c47d

Browse files
committed
chore(deps): bump digest pin
digest doesn't provide `std` feature anymore
1 parent cf73665 commit 526c47d

File tree

11 files changed

+87
-91
lines changed

11 files changed

+87
-91
lines changed

Cargo.lock

Lines changed: 7 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,15 @@ members = [
1111

1212
[profile.dev]
1313
opt-level = 2
14+
15+
[patch.crates-io]
16+
# https://github.com/RustCrypto/traits/pull/1844
17+
crypto-common = { git = "https://github.com/baloo/traits.git", branch = "baloo/digest/newtype-bufferkinduser" }
18+
cipher = { git = "https://github.com/baloo/traits.git", branch = "baloo/digest/newtype-bufferkinduser" }
19+
digest = { git = "https://github.com/baloo/traits.git", branch = "baloo/digest/newtype-bufferkinduser" }
20+
21+
streebog = { git = "https://github.com/RustCrypto/hashes.git", branch = "newtype" }
22+
md-5 = { git = "https://github.com/RustCrypto/hashes.git", branch = "newtype" }
23+
sha1 = { git = "https://github.com/RustCrypto/hashes.git", branch = "newtype" }
24+
sha2 = { git = "https://github.com/RustCrypto/hashes.git", branch = "newtype" }
25+

belt-mac/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ digest = { version = "=0.11.0-pre.10", features = ["dev"] }
2222
hex-literal = "1"
2323

2424
[features]
25-
std = ["digest/std"]
2625
zeroize = ["cipher/zeroize"]
2726

2827
[package.metadata.docs.rs]

cbc-mac/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ aes = "0.9.0-pre.3"
2323
des = "0.9.0-pre.3"
2424

2525
[features]
26-
std = ["digest/std"]
2726
zeroize = ["cipher/zeroize"]
2827

2928
[package.metadata.docs.rs]

cmac/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ kuznyechik = "0.9.0-pre.3"
2828
magma = "0.10.0-pre.3"
2929

3030
[features]
31-
std = ["digest/std"]
3231
zeroize = ["cipher/zeroize"]
3332

3433
[package.metadata.docs.rs]

hmac/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ streebog = { version = "=0.11.0-pre.5", default-features = false }
2424
hex-literal = "1"
2525

2626
[features]
27-
std = ["digest/std"]
27+
std = []
2828
reset = [] # Enable ability to reset HMAC instances
2929

3030
[package.metadata.docs.rs]

hmac/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ use digest::{
103103
mod optim;
104104
mod simple;
105105

106-
pub use optim::{EagerHash, Hmac, HmacCore};
106+
pub use optim::{EagerHash, Hmac};
107107
pub use simple::SimpleHmac;
108108

109109
const IPAD: u8 = 0x36;

hmac/src/optim.rs

Lines changed: 63 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,35 @@
11
use super::{IPAD, OPAD, get_der_key};
2-
use core::{fmt, slice};
2+
use core::fmt;
33
use digest::{
4-
HashMarker, InvalidLength, KeyInit, MacMarker, Output,
4+
FixedOutput, HashMarker, InvalidLength, KeyInit, MacMarker, Output, Update,
55
block_buffer::Eager,
6-
core_api::{
7-
AlgorithmName, Block, BlockSizeUser, Buffer, BufferKindUser, CoreWrapper, FixedOutputCore,
8-
OutputSizeUser, UpdateCore,
9-
},
6+
core_api::{AlgorithmName, BlockSizeUser, BufferKindUser, OutputSizeUser},
107
crypto_common::{Key, KeySizeUser},
118
};
129

13-
/// Generic HMAC instance.
14-
pub type Hmac<D> = CoreWrapper<HmacCore<D>>;
10+
///// Generic HMAC instance.
11+
//pub type Hmac<D> = CoreWrapper<HmacCore<D>>;
1512

1613
/// Trait implemented by eager hashes which expose their block-level core.
17-
pub trait EagerHash {
18-
/// Block-level core type of the hash.
19-
type Core: HashMarker
20-
+ UpdateCore
21-
+ FixedOutputCore
22-
+ BufferKindUser<BufferKind = Eager>
23-
+ Default
24-
+ Clone;
14+
pub trait EagerHash:
15+
HashMarker + Update + FixedOutput + BufferKindUser<BufferKind = Eager> + Default + Clone
16+
{
2517
}
2618

27-
impl<C> EagerHash for CoreWrapper<C>
28-
where
29-
C: HashMarker
30-
+ UpdateCore
31-
+ FixedOutputCore
32-
+ BufferKindUser<BufferKind = Eager>
33-
+ Default
34-
+ Clone,
19+
impl<D> EagerHash for D where
20+
D: HashMarker + Update + FixedOutput + BufferKindUser<BufferKind = Eager> + Default + Clone
3521
{
36-
type Core = C;
3722
}
3823

3924
/// Generic core HMAC instance, which operates over blocks.
40-
pub struct HmacCore<D: EagerHash> {
41-
digest: D::Core,
42-
opad_digest: D::Core,
25+
pub struct Hmac<D: EagerHash> {
26+
digest: D,
27+
opad_digest: D,
4328
#[cfg(feature = "reset")]
44-
ipad_digest: D::Core,
29+
ipad_digest: D,
4530
}
4631

47-
impl<D: EagerHash> Clone for HmacCore<D> {
32+
impl<D: EagerHash> Clone for Hmac<D> {
4833
fn clone(&self) -> Self {
4934
Self {
5035
digest: self.digest.clone(),
@@ -55,45 +40,45 @@ impl<D: EagerHash> Clone for HmacCore<D> {
5540
}
5641
}
5742

58-
impl<D: EagerHash> MacMarker for HmacCore<D> {}
43+
impl<D: EagerHash> MacMarker for Hmac<D> {}
5944

60-
impl<D: EagerHash> BufferKindUser for HmacCore<D> {
45+
impl<D: EagerHash> BufferKindUser for Hmac<D> {
6146
type BufferKind = Eager;
6247
}
6348

64-
impl<D: EagerHash> KeySizeUser for HmacCore<D> {
65-
type KeySize = <<D as EagerHash>::Core as BlockSizeUser>::BlockSize;
49+
impl<D: EagerHash> KeySizeUser for Hmac<D> {
50+
type KeySize = <D as BlockSizeUser>::BlockSize;
6651
}
6752

68-
impl<D: EagerHash> BlockSizeUser for HmacCore<D> {
69-
type BlockSize = <<D as EagerHash>::Core as BlockSizeUser>::BlockSize;
53+
impl<D: EagerHash> BlockSizeUser for Hmac<D> {
54+
type BlockSize = <D as BlockSizeUser>::BlockSize;
7055
}
7156

72-
impl<D: EagerHash> OutputSizeUser for HmacCore<D> {
73-
type OutputSize = <<D as EagerHash>::Core as OutputSizeUser>::OutputSize;
57+
impl<D: EagerHash> OutputSizeUser for Hmac<D> {
58+
type OutputSize = <D as OutputSizeUser>::OutputSize;
7459
}
7560

76-
impl<D: EagerHash> KeyInit for HmacCore<D> {
61+
impl<D: EagerHash> KeyInit for Hmac<D> {
7762
#[inline(always)]
7863
fn new(key: &Key<Self>) -> Self {
7964
Self::new_from_slice(key.as_slice()).unwrap()
8065
}
8166

8267
#[inline(always)]
8368
fn new_from_slice(key: &[u8]) -> Result<Self, InvalidLength> {
84-
let mut buf = get_der_key::<CoreWrapper<D::Core>>(key);
69+
let mut buf = get_der_key::<D>(key);
8570
for b in buf.iter_mut() {
8671
*b ^= IPAD;
8772
}
88-
let mut digest = D::Core::default();
89-
digest.update_blocks(slice::from_ref(&buf));
73+
let mut digest = D::default();
74+
digest.update(buf.as_slice());
9075

9176
for b in buf.iter_mut() {
9277
*b ^= IPAD ^ OPAD;
9378
}
9479

95-
let mut opad_digest = D::Core::default();
96-
opad_digest.update_blocks(slice::from_ref(&buf));
80+
let mut opad_digest = D::default();
81+
opad_digest.update(buf.as_slice());
9782

9883
Ok(Self {
9984
#[cfg(feature = "reset")]
@@ -104,57 +89,67 @@ impl<D: EagerHash> KeyInit for HmacCore<D> {
10489
}
10590
}
10691

107-
impl<D: EagerHash> UpdateCore for HmacCore<D> {
92+
impl<D: EagerHash> Update for Hmac<D> {
10893
#[inline(always)]
109-
fn update_blocks(&mut self, blocks: &[Block<Self>]) {
110-
self.digest.update_blocks(blocks);
94+
fn update(&mut self, data: &[u8]) {
95+
self.digest.update(data);
11196
}
11297
}
11398

114-
impl<D: EagerHash> FixedOutputCore for HmacCore<D> {
99+
impl<D: EagerHash> FixedOutput for Hmac<D> {
115100
#[inline(always)]
116-
fn finalize_fixed_core(&mut self, buffer: &mut Buffer<Self>, out: &mut Output<Self>) {
117-
let mut hash = Output::<D::Core>::default();
118-
self.digest.finalize_fixed_core(buffer, &mut hash);
119-
// finalize_fixed_core should reset the buffer as well, but
120-
// to be extra safe we reset it explicitly again.
121-
buffer.reset();
122-
#[cfg(not(feature = "reset"))]
123-
let h = &mut self.opad_digest;
124-
#[cfg(feature = "reset")]
125-
let mut h = self.opad_digest.clone();
126-
buffer.digest_blocks(&hash, |b| h.update_blocks(b));
127-
h.finalize_fixed_core(buffer, out);
101+
fn finalize_into(self, out: &mut Output<Self>) {
102+
let mut hash = Output::<D>::default();
103+
104+
let Self {
105+
digest,
106+
mut opad_digest,
107+
..
108+
} = self;
109+
digest.finalize_into(&mut hash);
110+
111+
opad_digest.update(&hash);
112+
opad_digest.finalize_into(out);
128113
}
129114
}
130115

131116
#[cfg(feature = "reset")]
132117
#[cfg_attr(docsrs, doc(cfg(feature = "reset")))]
133-
impl<D: EagerHash> digest::Reset for HmacCore<D> {
118+
impl<D: EagerHash> digest::Reset for Hmac<D> {
134119
#[inline(always)]
135120
fn reset(&mut self) {
136121
self.digest = self.ipad_digest.clone();
137122
}
138123
}
139124

140-
impl<D: EagerHash> AlgorithmName for HmacCore<D>
125+
#[cfg(feature = "reset")]
126+
#[cfg_attr(docsrs, doc(cfg(feature = "reset")))]
127+
impl<D: EagerHash> digest::FixedOutputReset for Hmac<D> {
128+
#[inline(always)]
129+
fn finalize_into_reset(&mut self, out: &mut Output<Self>) {
130+
self.clone().finalize_into(out);
131+
<Self as digest::Reset>::reset(self);
132+
}
133+
}
134+
135+
impl<D: EagerHash> AlgorithmName for Hmac<D>
141136
where
142-
D::Core: AlgorithmName,
137+
D: AlgorithmName,
143138
{
144139
fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result {
145140
f.write_str("Hmac<")?;
146-
<D::Core as AlgorithmName>::write_alg_name(f)?;
141+
<D as AlgorithmName>::write_alg_name(f)?;
147142
f.write_str(">")
148143
}
149144
}
150145

151-
impl<D: EagerHash> fmt::Debug for HmacCore<D>
146+
impl<D: EagerHash> fmt::Debug for Hmac<D>
152147
where
153-
D::Core: AlgorithmName,
148+
D: AlgorithmName,
154149
{
155150
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
156-
f.write_str("HmacCore<")?;
157-
<D::Core as AlgorithmName>::write_alg_name(f)?;
151+
f.write_str("Hmac<")?;
152+
<D as AlgorithmName>::write_alg_name(f)?;
158153
f.write_str("> { ... }")
159154
}
160155
}

hmac/tests/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use digest::new_mac_test as test;
33
#[cfg(feature = "reset")]
44
use digest::new_resettable_mac_test as test;
5-
use hmac::{Hmac, HmacCore, SimpleHmac};
5+
use hmac::{Hmac, /* HmacCore,*/ SimpleHmac};
66
use sha1::Sha1;
77
use sha2::{Sha224, Sha256, Sha384, Sha512};
88
use streebog::{Streebog256, Streebog512};
@@ -12,7 +12,7 @@ fn test_debug_impls() {
1212
fn needs_debug<T: std::fmt::Debug>() {}
1313

1414
needs_debug::<Hmac<Sha256>>();
15-
needs_debug::<HmacCore<Sha256>>();
15+
//needs_debug::<HmacCore<Sha256>>();
1616
needs_debug::<SimpleHmac<Sha256>>();
1717
}
1818

pmac/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ aes = "0.9.0-pre.3"
2222
digest = { version = "=0.11.0-pre.10", features = ["dev"] }
2323

2424
[features]
25-
std = ["digest/std"]
25+
std = []
2626
zeroize = ["cipher/zeroize"]
2727

2828
[package.metadata.docs.rs]

retail-mac/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ aes = "0.9.0-pre.2"
2323
des = "0.9.0-pre.2"
2424

2525
[features]
26-
std = ["digest/std"]
2726
zeroize = ["cipher/zeroize"]
2827

2928
[package.metadata.docs.rs]

0 commit comments

Comments
 (0)