Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto-mac v0.9 #217

Merged
merged 6 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/crypto-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
toolchain: ${{ matrix.rust }}
- run: cargo check --all-features
- run: cargo test --release
- run: cargo test --features block-cipher --release
- run: cargo test --features dev --release
- run: cargo test --features std --release
- run: cargo test --all-features --release
54 changes: 32 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions crypto-mac/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.9.0 (2020-08-10)
### Added
- `FromBlockCipher` trait and blanket implementation of the `NewMac` trait
for it ([#217])

### Changed
- Updated test vectors storage to `blobby v0.3` ([#217])

### Removed
- `impl_write!` macro ([#217])

[#217]: https://github.com/RustCrypto/traits/pull/217

## 0.8.0 (2020-06-04)
### Added
- `impl_write!` macro ([#134])
Expand Down
5 changes: 3 additions & 2 deletions crypto-mac/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "crypto-mac"
description = "Trait for Message Authentication Code (MAC) algorithms"
version = "0.8.0"
version = "0.9.0"
authors = ["RustCrypto Developers"]
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand All @@ -13,8 +13,9 @@ categories = ["cryptography", "no-std"]

[dependencies]
generic-array = "0.14"
block-cipher = { version = "0.8", optional = true }
subtle = { version = "2", default-features = false }
blobby = { version = "0.2", optional = true }
blobby = { version = "0.3", optional = true }

[features]
dev = ["blobby"]
Expand Down
4 changes: 1 addition & 3 deletions crypto-mac/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ macro_rules! new_test {
let data = include_bytes!(concat!("data/", $test_name, ".blb"));

for (i, row) in Blob3Iterator::new(data).unwrap().enumerate() {
let key = row[0];
let input = row[1];
let tag = row[2];
let [key, input, tag] = row.unwrap();
if let Some(desc) = run_test(key, input, tag) {
panic!(
"\n\
Expand Down
49 changes: 33 additions & 16 deletions crypto-mac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#[cfg(feature = "std")]
extern crate std;

#[cfg(feature = "block-cipher")]
use block_cipher::{BlockCipher, NewBlockCipher};

#[cfg(feature = "dev")]
#[cfg_attr(docsrs, doc(cfg(feature = "dev")))]
pub mod dev;
Expand Down Expand Up @@ -118,20 +121,34 @@ impl<M: Mac> PartialEq for Output<M> {

impl<M: Mac> Eq for Output<M> {}

#[macro_export]
/// Implements `std::io::Write` trait for implementer of [`Mac`]
macro_rules! impl_write {
($mac:ident) => {
#[cfg(feature = "std")]
impl std::io::Write for $mac {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
Mac::update(self, buf);
Ok(buf.len())
}

fn flush(&mut self) -> std::io::Result<()> {
Ok(())
}
}
};
#[cfg(feature = "block-cipher")]
#[cfg_attr(docsrs, doc(cfg(feature = "block-cipher")))]
/// Trait for MAC functions which can be created from block cipher.
pub trait FromBlockCipher {
/// Block cipher type
type Cipher: BlockCipher;

/// Create new MAC isntance from provided block cipher.
fn from_cipher(cipher: Self::Cipher) -> Self;
}

#[cfg(feature = "block-cipher")]
#[cfg_attr(docsrs, doc(cfg(feature = "block-cipher")))]
impl<T> NewMac for T
where
T: FromBlockCipher,
T::Cipher: NewBlockCipher,
{
type KeySize = <<Self as FromBlockCipher>::Cipher as NewBlockCipher>::KeySize;

fn new(key: &Key<Self>) -> Self {
let cipher = <Self as FromBlockCipher>::Cipher::new(key);
Self::from_cipher(cipher)
}

fn new_varkey(key: &[u8]) -> Result<Self, InvalidKeyLength> {
<Self as FromBlockCipher>::Cipher::new_varkey(key)
.map_err(|_| InvalidKeyLength)
.map(Self::from_cipher)
}
}
2 changes: 1 addition & 1 deletion cryptography/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ aead = { version = "0.3", optional = true, path = "../aead" }
block-cipher = { version = "0.8", optional = true, path = "../block-cipher" }
digest = { version = "0.9", optional = true, path = "../digest" }
elliptic-curve = { version = "= 0.5.0-pre", optional = true, path = "../elliptic-curve" }
mac = { version = "0.8", package = "crypto-mac", optional = true, path = "../crypto-mac" }
mac = { version = "0.9", package = "crypto-mac", optional = true, path = "../crypto-mac" }
signature = { version = "1.1.0", optional = true, default-features = false, path = "../signature" }
stream-cipher = { version = "0.6", optional = true, path = "../stream-cipher" }
universal-hash = { version = "0.4", optional = true, path = "../universal-hash" }
Expand Down