Skip to content

Commit 945339b

Browse files
authored
Migrate to digest v0.11.1 (#249)
1 parent 551f89d commit 945339b

9 files changed

Lines changed: 98 additions & 84 deletions

File tree

Cargo.lock

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

belt-mac/src/block_api.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ use digest::{
66
array::{Array, ArraySize},
77
block_api::{
88
AlgorithmName, Block, BlockSizeUser, Buffer, BufferKindUser, FixedOutputCore, Lazy,
9-
UpdateCore,
9+
SmallBlockSizeUser, UpdateCore,
1010
},
11-
common::{BlockSizes, InnerInit, InnerUser},
11+
block_buffer::BlockSizes,
12+
common::{InnerInit, InnerUser},
1213
};
1314

1415
#[cfg(feature = "zeroize")]
@@ -18,7 +19,7 @@ use digest::zeroize::{Zeroize, ZeroizeOnDrop};
1819
#[derive(Clone)]
1920
pub struct BeltMacCore<C = BeltBlock>
2021
where
21-
C: BlockCipherEncrypt + Clone,
22+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
2223
{
2324
cipher: C,
2425
state: Block<C>,
@@ -27,30 +28,30 @@ where
2728

2829
impl<C> BlockSizeUser for BeltMacCore<C>
2930
where
30-
C: BlockCipherEncrypt + Clone,
31+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
3132
{
3233
type BlockSize = C::BlockSize;
3334
}
3435

3536
impl<C> OutputSizeUser for BeltMacCore<C>
3637
where
37-
C: BlockCipherEncrypt + Clone,
38+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
3839
{
3940
type OutputSize = C::BlockSize;
4041
}
4142

4243
impl<C> InnerUser for BeltMacCore<C>
4344
where
44-
C: BlockCipherEncrypt + Clone,
45+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
4546
{
4647
type Inner = C;
4748
}
4849

49-
impl<C> MacMarker for BeltMacCore<C> where C: BlockCipherEncrypt + Clone {}
50+
impl<C> MacMarker for BeltMacCore<C> where C: BlockCipherEncrypt + SmallBlockSizeUser + Clone {}
5051

5152
impl<C> InnerInit for BeltMacCore<C>
5253
where
53-
C: BlockCipherEncrypt + Clone,
54+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
5455
{
5556
#[inline]
5657
fn inner_init(cipher: C) -> Self {
@@ -63,14 +64,14 @@ where
6364

6465
impl<C> BufferKindUser for BeltMacCore<C>
6566
where
66-
C: BlockCipherEncrypt + Clone,
67+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
6768
{
6869
type BufferKind = Lazy;
6970
}
7071

7172
impl<C> UpdateCore for BeltMacCore<C>
7273
where
73-
C: BlockCipherEncrypt + Clone,
74+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
7475
{
7576
#[inline]
7677
fn update_blocks(&mut self, blocks: &[Block<Self>]) {
@@ -100,7 +101,7 @@ where
100101

101102
impl<C> Reset for BeltMacCore<C>
102103
where
103-
C: BlockCipherEncrypt + Clone,
104+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
104105
{
105106
#[inline(always)]
106107
fn reset(&mut self) {
@@ -110,7 +111,7 @@ where
110111

111112
impl<C> FixedOutputCore for BeltMacCore<C>
112113
where
113-
C: BlockCipherEncrypt + Clone,
114+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
114115
{
115116
#[inline]
116117
fn finalize_fixed_core(&mut self, buffer: &mut Buffer<Self>, out: &mut Output<Self>) {
@@ -147,7 +148,7 @@ where
147148

148149
impl<C> AlgorithmName for BeltMacCore<C>
149150
where
150-
C: BlockCipherEncrypt + Clone,
151+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
151152
{
152153
fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result {
153154
f.write_str("BeltMac")
@@ -156,7 +157,7 @@ where
156157

157158
impl<C> fmt::Debug for BeltMacCore<C>
158159
where
159-
C: BlockCipherEncrypt + Clone,
160+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
160161
{
161162
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
162163
f.write_str("BeltMacCore { ... }")
@@ -166,15 +167,18 @@ where
166167
#[cfg(feature = "zeroize")]
167168
impl<C> Drop for BeltMacCore<C>
168169
where
169-
C: BlockCipherEncrypt + Clone,
170+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
170171
{
171172
fn drop(&mut self) {
172173
self.state.zeroize();
173174
}
174175
}
175176

176177
#[cfg(feature = "zeroize")]
177-
impl<C> ZeroizeOnDrop for BeltMacCore<C> where C: BlockCipherEncrypt + Clone + ZeroizeOnDrop {}
178+
impl<C> ZeroizeOnDrop for BeltMacCore<C> where
179+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone + ZeroizeOnDrop
180+
{
181+
}
178182

179183
#[inline(always)]
180184
fn xor<N: ArraySize>(buf: &mut Array<u8, N>, data: &Array<u8, N>) {

belt-mac/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ pub use digest::{self, KeyInit, Mac};
1414
pub mod block_api;
1515

1616
use cipher::BlockCipherEncrypt;
17+
use digest::block_api::SmallBlockSizeUser;
1718

1819
digest::buffer_fixed!(
1920
/// BeltMac instance generic over block cipher.
20-
pub struct GenericBeltMac<C: BlockCipherEncrypt + Clone>(block_api::BeltMacCore<C>);
21+
pub struct GenericBeltMac<C: BlockCipherEncrypt + SmallBlockSizeUser + Clone>(block_api::BeltMacCore<C>);
2122
impl: ResetMacTraits AlgorithmName InnerInit;
2223
);
2324

cbc-mac/src/block_api.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ use digest::{
55
array::{Array, ArraySize},
66
block_api::{
77
AlgorithmName, Block, BlockSizeUser, Buffer, BufferKindUser, Eager, FixedOutputCore,
8-
UpdateCore,
8+
SmallBlockSizeUser, UpdateCore,
99
},
10-
common::{BlockSizes, InnerInit, InnerUser},
10+
block_buffer::BlockSizes,
11+
common::{InnerInit, InnerUser},
1112
};
1213

1314
#[cfg(feature = "zeroize")]
@@ -17,38 +18,38 @@ use digest::zeroize::{Zeroize, ZeroizeOnDrop};
1718
#[derive(Clone)]
1819
pub struct CbcMacCore<C>
1920
where
20-
C: BlockCipherEncrypt + Clone,
21+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
2122
{
2223
cipher: C,
2324
state: Block<C>,
2425
}
2526

2627
impl<C> BlockSizeUser for CbcMacCore<C>
2728
where
28-
C: BlockCipherEncrypt + Clone,
29+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
2930
{
3031
type BlockSize = C::BlockSize;
3132
}
3233

3334
impl<C> OutputSizeUser for CbcMacCore<C>
3435
where
35-
C: BlockCipherEncrypt + Clone,
36+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
3637
{
3738
type OutputSize = C::BlockSize;
3839
}
3940

4041
impl<C> InnerUser for CbcMacCore<C>
4142
where
42-
C: BlockCipherEncrypt + Clone,
43+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
4344
{
4445
type Inner = C;
4546
}
4647

47-
impl<C> MacMarker for CbcMacCore<C> where C: BlockCipherEncrypt + Clone {}
48+
impl<C> MacMarker for CbcMacCore<C> where C: BlockCipherEncrypt + SmallBlockSizeUser + Clone {}
4849

4950
impl<C> InnerInit for CbcMacCore<C>
5051
where
51-
C: BlockCipherEncrypt + Clone,
52+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
5253
{
5354
#[inline]
5455
fn inner_init(cipher: C) -> Self {
@@ -59,14 +60,14 @@ where
5960

6061
impl<C> BufferKindUser for CbcMacCore<C>
6162
where
62-
C: BlockCipherEncrypt + Clone,
63+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
6364
{
6465
type BufferKind = Eager;
6566
}
6667

6768
impl<C> UpdateCore for CbcMacCore<C>
6869
where
69-
C: BlockCipherEncrypt + Clone,
70+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
7071
{
7172
#[inline]
7273
fn update_blocks(&mut self, blocks: &[Block<Self>]) {
@@ -96,7 +97,7 @@ where
9697

9798
impl<C> Reset for CbcMacCore<C>
9899
where
99-
C: BlockCipherEncrypt + Clone,
100+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
100101
{
101102
#[inline(always)]
102103
fn reset(&mut self) {
@@ -106,7 +107,7 @@ where
106107

107108
impl<C> FixedOutputCore for CbcMacCore<C>
108109
where
109-
C: BlockCipherEncrypt + Clone,
110+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
110111
{
111112
#[inline]
112113
fn finalize_fixed_core(&mut self, buffer: &mut Buffer<Self>, out: &mut Output<Self>) {
@@ -122,7 +123,7 @@ where
122123

123124
impl<C> AlgorithmName for CbcMacCore<C>
124125
where
125-
C: BlockCipherEncrypt + Clone + AlgorithmName,
126+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone + AlgorithmName,
126127
{
127128
fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result {
128129
f.write_str("CbcMac<")?;
@@ -133,7 +134,7 @@ where
133134

134135
impl<C> fmt::Debug for CbcMacCore<C>
135136
where
136-
C: BlockCipherEncrypt + Clone + AlgorithmName,
137+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone + AlgorithmName,
137138
{
138139
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
139140
f.write_str("CbcMacCore<")?;
@@ -145,15 +146,18 @@ where
145146
#[cfg(feature = "zeroize")]
146147
impl<C> Drop for CbcMacCore<C>
147148
where
148-
C: BlockCipherEncrypt + Clone,
149+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone,
149150
{
150151
fn drop(&mut self) {
151152
self.state.zeroize();
152153
}
153154
}
154155

155156
#[cfg(feature = "zeroize")]
156-
impl<C> ZeroizeOnDrop for CbcMacCore<C> where C: BlockCipherEncrypt + Clone + ZeroizeOnDrop {}
157+
impl<C> ZeroizeOnDrop for CbcMacCore<C> where
158+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone + ZeroizeOnDrop
159+
{
160+
}
157161

158162
#[inline(always)]
159163
fn xor<N: ArraySize>(buf: &mut Array<u8, N>, data: &Array<u8, N>) {

cbc-mac/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#![forbid(unsafe_code)]
99
#![warn(missing_docs)]
1010

11-
pub use digest::{self, KeyInit, Mac};
11+
pub use digest::{self, KeyInit, Mac, block_api::SmallBlockSizeUser};
1212

1313
mod block_api;
1414

@@ -18,13 +18,13 @@ use digest::block_api::CoreProxy;
1818

1919
digest::buffer_fixed!(
2020
/// Generic CBC-MAC instance.
21-
pub struct CbcMac<C: BlockCipherEncrypt + Clone>(block_api::CbcMacCore<C>);
21+
pub struct CbcMac<C: BlockCipherEncrypt + SmallBlockSizeUser + Clone>(block_api::CbcMacCore<C>);
2222
impl: ResetMacTraits InnerInit;
2323
);
2424

2525
impl<C> AlgorithmName for CbcMac<C>
2626
where
27-
C: BlockCipherEncrypt + Clone + AlgorithmName,
27+
C: BlockCipherEncrypt + SmallBlockSizeUser + Clone + AlgorithmName,
2828
{
2929
fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result {
3030
<Self as CoreProxy>::Core::write_alg_name(f)

cmac/src/block_api.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ use digest::{
66
array::{Array, ArraySize},
77
block_api::{
88
AlgorithmName, Block, BlockSizeUser, Buffer, BufferKindUser, FixedOutputCore, Lazy,
9-
UpdateCore,
9+
SmallBlockSizeUser, UpdateCore,
1010
},
11-
common::{BlockSizes, InnerInit, InnerUser},
11+
block_buffer::BlockSizes,
12+
common::{InnerInit, InnerUser},
1213
};
1314

1415
#[cfg(feature = "zeroize")]
@@ -139,14 +140,14 @@ fn xor<N: ArraySize>(buf: &mut Array<u8, N>, data: &Array<u8, N>) {
139140
}
140141

141142
/// Helper trait implemented for cipher supported by CMAC
142-
pub trait CmacCipher: BlockSizeUser + BlockCipherEncrypt + Clone {
143+
pub trait CmacCipher: SmallBlockSizeUser + BlockCipherEncrypt + Clone {
143144
/// Double block. See the [`Dbl`] trait docs for more information.
144145
fn dbl(block: Block<Self>) -> Block<Self>;
145146
}
146147

147148
impl<C> CmacCipher for C
148149
where
149-
Self: BlockSizeUser + BlockCipherEncrypt + Clone,
150+
Self: SmallBlockSizeUser + BlockCipherEncrypt + Clone,
150151
Block<Self>: Dbl,
151152
{
152153
fn dbl(block: Block<Self>) -> Block<Self> {

0 commit comments

Comments
 (0)