Skip to content

Commit

Permalink
rename column from name to crate
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Nov 12, 2021
1 parent 38f608c commit 41767cd
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Collection of [Message Authentication Code][1] (MAC) algorithms written in pure

## Crates

| Algorithm | Name | Crates.io | Documentation | MSRV |
| Algorithm | Crate | Crates.io | Documentation | MSRV |
|-----------|--------|---------------|---------------|------|
| [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] |
| [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] |
Expand Down
8 changes: 3 additions & 5 deletions hmac/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hmac"
version = "0.11.0"
version = "0.12.0"
description = "Generic implementation of Hash-based Message Authentication Code (HMAC)"
authors = ["RustCrypto Developers"]
license = "MIT OR Apache-2.0"
Expand All @@ -12,14 +12,12 @@ readme = "README.md"
edition = "2018"

[dependencies]
crypto-mac = "0.11"
digest = "0.9"
digest = { version = "0.10", features = ["mac"] }

[dev-dependencies]
crypto-mac = { version = "0.11", features = ["dev"] }
md-5 = { version = "0.9", default-features = false }
sha2 = { version = "0.9", default-features = false }
streebog = { version = "0.9", default-features = false }

[features]
std = ["crypto-mac/std"]
std = ["digest/std"]
102 changes: 93 additions & 9 deletions hmac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,113 @@
#[cfg(feature = "std")]
extern crate std;

pub use crypto_mac::{self, Mac, NewMac};
pub use digest;

use core::{cmp::min, fmt};
use crypto_mac::{
use digest::core_api::{Block, BlockSizeUser, BufferUser, FixedOutputCore, UpdateCore};
use digest::{
block_buffer::BlockBuffer,
crypto_common::{Key, KeySizeUser},
generic_array::{sequence::GenericSequence, ArrayLength, GenericArray},
InvalidKeyLength, Output,
InvalidLength, KeyInit, Output,
};
use digest::{BlockInput, FixedOutput, Reset, Update};

const IPAD: u8 = 0x36;
const OPAD: u8 = 0x5C;

/// The `Hmac` struct represents an HMAC using a given hash function `D`.
pub struct Hmac<D>
/// Core HMAC operating over blocks.
#[derive(Clone)]
pub struct HmacCore<D>
where
D: Update + BlockInput + FixedOutput + Reset + Default + Clone,
D::BlockSize: ArrayLength<u8>,
D: UpdateCore + FixedOutputCore + BufferUser<Buffer = BlockBuffer<_>> + Default,
{
digest: D,
i_key_pad: GenericArray<u8, D::BlockSize>,
opad_digest: D,
}
/*
impl<D> KeySizeUser for HmacCore<D>
where
D: UpdateCore + FixedOutputCore + BufferUser<Buffer = BlockBuffer<Self::BlockSize>> + Default,
{
type KeySize = D::BlockSize;
}
impl<D> BlockSizeUser for HmacCore<D>
where
D: UpdateCore + FixedOutputCore + Default,
{
type BlockSize = D::BlockSize;
}
impl<D> KeyInit for HmacCore<D>
where
D: UpdateCore + FixedOutputCore + Default,
{
fn new(key: &Key<Self>) -> Self {
Self::new_from_slice(key.as_slice()).unwrap()
}
#[inline]
fn new_from_slice(key: &[u8]) -> Result<Self, InvalidLength> {
let mut der_key = Block::<Self>::default();
if key.len() <= der_key.len() {
der_key.copy_from_slice(key);
} else {
// TODO digest key
}
for b in der_key.iter_mut() {
}
let mut opad_digest = D::default();
opad_digest.update_blocks(slice::from_ref(&der_key));
panic!();
/*
let mut hmac = Self {
digest: Default::default(),
i_key_pad: GenericArray::generate(|_| IPAD),
opad_digest: Default::default(),
};
let mut opad = GenericArray::<u8, D::BlockSize>::generate(|_| OPAD);
debug_assert!(hmac.i_key_pad.len() == opad.len());
// The key that Hmac processes must be the same as the block size of the
// underlying Digest. If the provided key is smaller than that, we just
// pad it with zeros. If its larger, we hash it and then pad it with
// zeros.
if key.len() <= hmac.i_key_pad.len() {
for (k_idx, k_itm) in key.iter().enumerate() {
hmac.i_key_pad[k_idx] ^= *k_itm;
opad[k_idx] ^= *k_itm;
}
} else {
let mut digest = D::default();
digest.update(key);
let output = digest.finalize_fixed();
// `n` is calculated at compile time and will equal
// D::OutputSize. This is used to ensure panic-free code
let n = min(output.len(), hmac.i_key_pad.len());
for idx in 0..n {
hmac.i_key_pad[idx] ^= output[idx];
opad[idx] ^= output[idx];
}
}
hmac.digest.update(&hmac.i_key_pad);
hmac.opad_digest.update(&opad);
Ok(hmac)
*/
}
}
*/

/*
impl<D> Clone for Hmac<D>
where
D: Update + BlockInput + FixedOutput + Reset + Default + Clone,
Expand Down Expand Up @@ -128,7 +211,7 @@ where
}
#[inline]
fn new_from_slice(key: &[u8]) -> Result<Self, InvalidKeyLength> {
fn new_from_slice(key: &[u8]) -> Result<Self, InvalidLength> {
let mut hmac = Self {
digest: Default::default(),
i_key_pad: GenericArray::generate(|_| IPAD),
Expand Down Expand Up @@ -211,3 +294,4 @@ where
Ok(())
}
}
*/

0 comments on commit 41767cd

Please sign in to comment.