From 15fc1b9d230162523b4e778a0835bb88721e3d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Wed, 15 Jul 2020 03:23:56 +0300 Subject: [PATCH 1/5] crypto-mac v0.9 --- .github/workflows/crypto-mac.yml | 1 + Cargo.lock | 18 +++++++++--- crypto-mac/CHANGELOG.md | 13 +++++++++ crypto-mac/Cargo.toml | 5 ++-- crypto-mac/src/dev.rs | 4 +-- crypto-mac/src/lib.rs | 49 +++++++++++++++++++++----------- cryptography/Cargo.toml | 2 +- 7 files changed, 66 insertions(+), 26 deletions(-) diff --git a/.github/workflows/crypto-mac.yml b/.github/workflows/crypto-mac.yml index 32333fc8b..490dc7cfa 100644 --- a/.github/workflows/crypto-mac.yml +++ b/.github/workflows/crypto-mac.yml @@ -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 diff --git a/Cargo.lock b/Cargo.lock index b3471b3ec..424fea0f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -49,6 +49,15 @@ dependencies = [ "generic-array 0.14.3", ] +[[package]] +name = "block-cipher" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f337a3e6da609650eb74e02bc9fac7b735049f7623ab12f2e4c719316fcc7e80" +dependencies = [ + "generic-array 0.14.3", +] + [[package]] name = "byteorder" version = "1.3.4" @@ -69,9 +78,10 @@ checksum = "6d375c433320f6c5057ae04a04376eef4d04ce2801448cf8863a78da99107be4" [[package]] name = "crypto-mac" -version = "0.8.0" +version = "0.9.0" dependencies = [ - "blobby 0.2.0", + "blobby 0.3.0", + "block-cipher 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "generic-array 0.14.3", "subtle", ] @@ -81,7 +91,7 @@ name = "cryptography" version = "0.2.0" dependencies = [ "aead", - "block-cipher", + "block-cipher 0.8.0", "crypto-mac", "digest 0.9.0", "elliptic-curve", @@ -266,7 +276,7 @@ name = "stream-cipher" version = "0.6.0" dependencies = [ "blobby 0.3.0", - "block-cipher", + "block-cipher 0.8.0", "generic-array 0.14.3", ] diff --git a/crypto-mac/CHANGELOG.md b/crypto-mac/CHANGELOG.md index b0eb5094b..eb4e1faa4 100644 --- a/crypto-mac/CHANGELOG.md +++ b/crypto-mac/CHANGELOG.md @@ -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-07-15) +### Added +- Blanket `NewMac` implementation for types constructible from +block ciphers ([#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]) diff --git a/crypto-mac/Cargo.toml b/crypto-mac/Cargo.toml index ff5c9313d..b8350c22e 100644 --- a/crypto-mac/Cargo.toml +++ b/crypto-mac/Cargo.toml @@ -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" @@ -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"] diff --git a/crypto-mac/src/dev.rs b/crypto-mac/src/dev.rs index f338cab74..e2348501e 100644 --- a/crypto-mac/src/dev.rs +++ b/crypto-mac/src/dev.rs @@ -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\ diff --git a/crypto-mac/src/lib.rs b/crypto-mac/src/lib.rs index 8b4768d6a..ebf19e54c 100644 --- a/crypto-mac/src/lib.rs +++ b/crypto-mac/src/lib.rs @@ -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; @@ -118,20 +121,34 @@ impl PartialEq for Output { impl Eq for Output {} -#[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 { - 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 NewMac for T + where + T: FromBlockCipher, + T::Cipher: NewBlockCipher +{ + type KeySize = <::Cipher as NewBlockCipher>::KeySize; + + fn new(key: &Key) -> Self { + let cipher = ::Cipher::new(key); + Self::from_cipher(cipher) + } + + fn new_varkey(key: &[u8]) -> Result { + ::Cipher::new_varkey(key) + .map_err(|_| InvalidKeyLength) + .map(Self::from_cipher) + } } diff --git a/cryptography/Cargo.toml b/cryptography/Cargo.toml index 38b0afe16..a0895e936 100644 --- a/cryptography/Cargo.toml +++ b/cryptography/Cargo.toml @@ -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" } From 13e2c7e9ee3707ae910eedd8e3a227ccec1e094a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Wed, 15 Jul 2020 03:34:59 +0300 Subject: [PATCH 2/5] fmt --- crypto-mac/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crypto-mac/src/lib.rs b/crypto-mac/src/lib.rs index ebf19e54c..6a44060ab 100644 --- a/crypto-mac/src/lib.rs +++ b/crypto-mac/src/lib.rs @@ -135,9 +135,9 @@ pub trait FromBlockCipher { #[cfg(feature = "block-cipher")] #[cfg_attr(docsrs, doc(cfg(feature = "block-cipher")))] impl NewMac for T - where - T: FromBlockCipher, - T::Cipher: NewBlockCipher +where + T: FromBlockCipher, + T::Cipher: NewBlockCipher, { type KeySize = <::Cipher as NewBlockCipher>::KeySize; From 7571efc6aa4ca14414dc32634f73e12ea2155b54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Wed, 15 Jul 2020 03:37:59 +0300 Subject: [PATCH 3/5] update changelog --- crypto-mac/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto-mac/CHANGELOG.md b/crypto-mac/CHANGELOG.md index eb4e1faa4..18fdf6910 100644 --- a/crypto-mac/CHANGELOG.md +++ b/crypto-mac/CHANGELOG.md @@ -7,8 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 0.9.0 (2020-07-15) ### Added -- Blanket `NewMac` implementation for types constructible from -block ciphers ([#217]) +- `FromBlockCipher` trait and blanket implementation of the `NewMac` trait +for it ([#217]) ### Changed - Updated test vectors storage to `blobby v0.3` ([#217]) From 8ac5a134c943b8ef4591a318245a309ed852ddc1 Mon Sep 17 00:00:00 2001 From: Artyom Pavlov Date: Mon, 10 Aug 2020 17:38:50 +0000 Subject: [PATCH 4/5] update release date --- crypto-mac/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto-mac/CHANGELOG.md b/crypto-mac/CHANGELOG.md index 18fdf6910..867676934 100644 --- a/crypto-mac/CHANGELOG.md +++ b/crypto-mac/CHANGELOG.md @@ -5,7 +5,7 @@ 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-07-15) +## 0.9.0 (2020-08-10) ### Added - `FromBlockCipher` trait and blanket implementation of the `NewMac` trait for it ([#217]) From 5dd1d45de210ef684c033ffe74cc05f2a7f90584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Mon, 10 Aug 2020 20:50:48 +0300 Subject: [PATCH 5/5] update lock file --- Cargo.lock | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8d5478769..d80a03485 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -55,7 +55,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f337a3e6da609650eb74e02bc9fac7b735049f7623ab12f2e4c719316fcc7e80" dependencies = [ - "generic-array 0.14.3", + "generic-array 0.14.4", ] [[package]] @@ -78,9 +78,9 @@ checksum = "a2d9162b7289a46e86208d6af2c686ca5bfde445878c41a458a9fac706252d0b" [[package]] name = "cpuid-bool" -version = "0.1.0" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d375c433320f6c5057ae04a04376eef4d04ce2801448cf8863a78da99107be4" +checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" [[package]] name = "crypto-mac" @@ -195,9 +195,9 @@ dependencies = [ [[package]] name = "hex-literal-impl" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d4c5c844e2fee0bf673d54c2c177f1713b3d2af2ff6e666b49cb7572e6cf42d" +checksum = "853f769599eb31de176303197b7ba4973299c38c7a7604a6bc88c3eef05b9b46" dependencies = [ "proc-macro-hack", ] @@ -210,24 +210,24 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "proc-macro-hack" -version = "0.5.15" +version = "0.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d659fe7c6d27f25e9d80a1a094c223f5246f6a6596453e09d7229bf42750b63" +checksum = "99c605b9a0adc77b7211c6b1f722dcb613d68d66859a44f3d485a6da332b0598" [[package]] name = "proc-macro2" -version = "1.0.12" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8872cf6f48eee44265156c111456a700ab3483686b3f96df4cf5481c89157319" +checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" dependencies = [ "unicode-xid", ] [[package]] name = "quote" -version = "1.0.4" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c1f4b0efa5fc5e8ceb705136bfee52cfdb6a4e3509f770b478cd6ed434232a7" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" dependencies = [ "proc-macro2", ] @@ -274,17 +274,17 @@ dependencies = [ [[package]] name = "stable_deref_trait" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "stream-cipher" version = "0.6.0" dependencies = [ "blobby 0.3.0", - "block-cipher", - "generic-array 0.14.4",release date + "block-cipher 0.8.0", + "generic-array 0.14.4", ] [[package]] @@ -295,9 +295,9 @@ checksum = "502d53007c02d7605a05df1c1a73ee436952781653da5d0bf57ad608f66932c1" [[package]] name = "syn" -version = "1.0.19" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8e5aa70697bb26ee62214ae3288465ecec0000f05182f039b477001f08f5ae7" +checksum = "e69abc24912995b3038597a7a593be5053eb0fb44f3cc5beec0deb421790c1f4" dependencies = [ "proc-macro2", "quote", @@ -306,9 +306,9 @@ dependencies = [ [[package]] name = "synstructure" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" +checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" dependencies = [ "proc-macro2", "quote", @@ -324,9 +324,9 @@ checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" [[package]] name = "unicode-xid" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] name = "universal-hash"