Skip to content

Commit 41767cd

Browse files
committed
rename column from name to crate
1 parent 38f608c commit 41767cd

File tree

3 files changed

+97
-15
lines changed

3 files changed

+97
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Collection of [Message Authentication Code][1] (MAC) algorithms written in pure
44

55
## Crates
66

7-
| Algorithm | Name | Crates.io | Documentation | MSRV |
7+
| Algorithm | Crate | Crates.io | Documentation | MSRV |
88
|-----------|--------|---------------|---------------|------|
99
| [CMAC] | `cmac` | [![crates.io](https://img.shields.io/crates/v/cmac.svg)](https://crates.io/crates/cmac) | [![Documentation](https://docs.rs/cmac/badge.svg)](https://docs.rs/cmac) | ![Minimum Supported Rust Version][msrv-1.41] |
1010
| [DAA] | `daa` | [![crates.io](https://img.shields.io/crates/v/daa.svg)](https://crates.io/crates/daa) | [![Documentation](https://docs.rs/daa/badge.svg)](https://docs.rs/daa) | ![Minimum Supported Rust Version][msrv-1.41] |

hmac/Cargo.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hmac"
3-
version = "0.11.0"
3+
version = "0.12.0"
44
description = "Generic implementation of Hash-based Message Authentication Code (HMAC)"
55
authors = ["RustCrypto Developers"]
66
license = "MIT OR Apache-2.0"
@@ -12,14 +12,12 @@ readme = "README.md"
1212
edition = "2018"
1313

1414
[dependencies]
15-
crypto-mac = "0.11"
16-
digest = "0.9"
15+
digest = { version = "0.10", features = ["mac"] }
1716

1817
[dev-dependencies]
19-
crypto-mac = { version = "0.11", features = ["dev"] }
2018
md-5 = { version = "0.9", default-features = false }
2119
sha2 = { version = "0.9", default-features = false }
2220
streebog = { version = "0.9", default-features = false }
2321

2422
[features]
25-
std = ["crypto-mac/std"]
23+
std = ["digest/std"]

hmac/src/lib.rs

Lines changed: 93 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,30 +63,113 @@
6363
#[cfg(feature = "std")]
6464
extern crate std;
6565

66-
pub use crypto_mac::{self, Mac, NewMac};
6766
pub use digest;
6867

6968
use core::{cmp::min, fmt};
70-
use crypto_mac::{
69+
use digest::core_api::{Block, BlockSizeUser, BufferUser, FixedOutputCore, UpdateCore};
70+
use digest::{
71+
block_buffer::BlockBuffer,
72+
crypto_common::{Key, KeySizeUser},
7173
generic_array::{sequence::GenericSequence, ArrayLength, GenericArray},
72-
InvalidKeyLength, Output,
74+
InvalidLength, KeyInit, Output,
7375
};
74-
use digest::{BlockInput, FixedOutput, Reset, Update};
7576

7677
const IPAD: u8 = 0x36;
7778
const OPAD: u8 = 0x5C;
7879

79-
/// The `Hmac` struct represents an HMAC using a given hash function `D`.
80-
pub struct Hmac<D>
80+
/// Core HMAC operating over blocks.
81+
#[derive(Clone)]
82+
pub struct HmacCore<D>
8183
where
82-
D: Update + BlockInput + FixedOutput + Reset + Default + Clone,
83-
D::BlockSize: ArrayLength<u8>,
84+
D: UpdateCore + FixedOutputCore + BufferUser<Buffer = BlockBuffer<_>> + Default,
8485
{
8586
digest: D,
8687
i_key_pad: GenericArray<u8, D::BlockSize>,
8788
opad_digest: D,
8889
}
90+
/*
91+
impl<D> KeySizeUser for HmacCore<D>
92+
where
93+
D: UpdateCore + FixedOutputCore + BufferUser<Buffer = BlockBuffer<Self::BlockSize>> + Default,
94+
{
95+
type KeySize = D::BlockSize;
96+
}
97+
98+
impl<D> BlockSizeUser for HmacCore<D>
99+
where
100+
D: UpdateCore + FixedOutputCore + Default,
101+
{
102+
type BlockSize = D::BlockSize;
103+
}
104+
105+
106+
impl<D> KeyInit for HmacCore<D>
107+
where
108+
D: UpdateCore + FixedOutputCore + Default,
109+
{
110+
fn new(key: &Key<Self>) -> Self {
111+
Self::new_from_slice(key.as_slice()).unwrap()
112+
}
113+
114+
#[inline]
115+
fn new_from_slice(key: &[u8]) -> Result<Self, InvalidLength> {
116+
let mut der_key = Block::<Self>::default();
117+
if key.len() <= der_key.len() {
118+
der_key.copy_from_slice(key);
119+
} else {
120+
// TODO digest key
121+
}
122+
123+
for b in der_key.iter_mut() {
124+
125+
}
126+
let mut opad_digest = D::default();
127+
opad_digest.update_blocks(slice::from_ref(&der_key));
128+
129+
panic!();
130+
/*
131+
let mut hmac = Self {
132+
digest: Default::default(),
133+
i_key_pad: GenericArray::generate(|_| IPAD),
134+
opad_digest: Default::default(),
135+
};
136+
137+
138+
let mut opad = GenericArray::<u8, D::BlockSize>::generate(|_| OPAD);
139+
debug_assert!(hmac.i_key_pad.len() == opad.len());
140+
141+
// The key that Hmac processes must be the same as the block size of the
142+
// underlying Digest. If the provided key is smaller than that, we just
143+
// pad it with zeros. If its larger, we hash it and then pad it with
144+
// zeros.
145+
if key.len() <= hmac.i_key_pad.len() {
146+
for (k_idx, k_itm) in key.iter().enumerate() {
147+
hmac.i_key_pad[k_idx] ^= *k_itm;
148+
opad[k_idx] ^= *k_itm;
149+
}
150+
} else {
151+
let mut digest = D::default();
152+
digest.update(key);
153+
let output = digest.finalize_fixed();
154+
// `n` is calculated at compile time and will equal
155+
// D::OutputSize. This is used to ensure panic-free code
156+
let n = min(output.len(), hmac.i_key_pad.len());
157+
for idx in 0..n {
158+
hmac.i_key_pad[idx] ^= output[idx];
159+
opad[idx] ^= output[idx];
160+
}
161+
}
162+
163+
hmac.digest.update(&hmac.i_key_pad);
164+
hmac.opad_digest.update(&opad);
165+
166+
Ok(hmac)
167+
*/
168+
}
169+
}
170+
*/
89171

172+
/*
90173
impl<D> Clone for Hmac<D>
91174
where
92175
D: Update + BlockInput + FixedOutput + Reset + Default + Clone,
@@ -128,7 +211,7 @@ where
128211
}
129212
130213
#[inline]
131-
fn new_from_slice(key: &[u8]) -> Result<Self, InvalidKeyLength> {
214+
fn new_from_slice(key: &[u8]) -> Result<Self, InvalidLength> {
132215
let mut hmac = Self {
133216
digest: Default::default(),
134217
i_key_pad: GenericArray::generate(|_| IPAD),
@@ -211,3 +294,4 @@ where
211294
Ok(())
212295
}
213296
}
297+
*/

0 commit comments

Comments
 (0)