From 6b980d96962a1aadd90c7b802d591b99994d647a Mon Sep 17 00:00:00 2001 From: Ruslan Piasetskyi Date: Mon, 27 Jun 2022 23:01:16 +0200 Subject: [PATCH] ccm: update dependencies (#432) - bump cipher and ctr dependencies to use it with the latest aes crate. - bump hex-literal. - change MSRV to 1.56.0. - remove separate job "heapless" in github workflow. Co-authored-by: Ruslan Piasetskyi --- .github/workflows/ccm.yml | 25 +--- Cargo.lock | 249 +++++++++++++++++++++++++++++++++++--- ccm/Cargo.toml | 10 +- ccm/README.md | 2 +- ccm/src/lib.rs | 41 +++---- 5 files changed, 260 insertions(+), 67 deletions(-) diff --git a/.github/workflows/ccm.yml b/.github/workflows/ccm.yml index b3e56d03..7d72b035 100644 --- a/.github/workflows/ccm.yml +++ b/.github/workflows/ccm.yml @@ -22,7 +22,7 @@ jobs: strategy: matrix: rust: - - 1.41.0 # MSRV + - 1.56.0 # MSRV - stable target: - thumbv7em-none-eabi @@ -44,7 +44,7 @@ jobs: include: # 32-bit Linux - target: i686-unknown-linux-gnu - rust: 1.49.0 # MSRV + rust: 1.56.0 # MSRV deps: sudo apt update && sudo apt install gcc-multilib - target: i686-unknown-linux-gnu rust: stable @@ -52,7 +52,7 @@ jobs: # 64-bit Linux - target: x86_64-unknown-linux-gnu - rust: 1.49.0 # MSRV + rust: 1.56.0 # MSRV - target: x86_64-unknown-linux-gnu rust: stable steps: @@ -65,22 +65,5 @@ jobs: profile: minimal - run: ${{ matrix.deps }} - run: cargo test --target ${{ matrix.target }} --release - - run: cargo test --target ${{ matrix.target }} --release --features stream,std + - run: cargo test --target ${{ matrix.target }} --release --all-features - run: cargo build --target ${{ matrix.target }} --benches - - # TODO(tarcieri): re-unify this with `test` when MSRV is 1.51+ - heapless: - runs-on: ubuntu-latest - strategy: - matrix: - rust: - - 1.51.0 # MSRV for `heapless` - - stable - steps: - - uses: actions/checkout@v1 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.rust }} - override: true - - run: cargo test --release --all-features diff --git a/Cargo.lock b/Cargo.lock index defc1860..3f0d1cec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -82,6 +82,57 @@ dependencies = [ "zeroize", ] +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + +[[package]] +name = "atomic-polyfill" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14bf7b4f565e5e717d7a7a65b2a05c0b8c96e4db636d6f780f03b15108cdd1b" +dependencies = [ + "critical-section", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bare-metal" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3" +dependencies = [ + "rustc_version 0.2.3", +] + +[[package]] +name = "bare-metal" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fe8f5a8a398345e52358e18ff07cc17a568fbca5c6f73873d3a62056309603" + +[[package]] +name = "bit_field" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4" + +[[package]] +name = "bitfield" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719" + [[package]] name = "blobby" version = "0.3.1" @@ -99,10 +150,10 @@ name = "ccm" version = "0.4.4" dependencies = [ "aead", - "aes 0.7.5", - "cipher 0.3.0", - "ctr 0.8.0", - "hex-literal 0.2.2", + "aes 0.8.1", + "cipher 0.4.3", + "ctr 0.9.1", + "hex-literal 0.3.4", "subtle", ] @@ -164,6 +215,18 @@ dependencies = [ "dbl", ] +[[package]] +name = "cortex-m" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd20d4ac4aa86f4f75f239d59e542ef67de87cce2c282818dc6e84155d3ea126" +dependencies = [ + "bare-metal 0.2.5", + "bitfield", + "embedded-hal", + "volatile-register", +] + [[package]] name = "cpufeatures" version = "0.2.2" @@ -173,6 +236,18 @@ dependencies = [ "libc", ] +[[package]] +name = "critical-section" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95da181745b56d4bd339530ec393508910c909c784e8962d15d722bacf0bcbcd" +dependencies = [ + "bare-metal 1.0.0", + "cfg-if", + "cortex-m", + "riscv", +] + [[package]] name = "crypto-common" version = "0.1.3" @@ -244,6 +319,16 @@ dependencies = [ "subtle", ] +[[package]] +name = "embedded-hal" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35949884794ad573cf46071e41c9b60efb0cb311e3ca01f7af807af1debc66ff" +dependencies = [ + "nb 0.1.3", + "void", +] + [[package]] name = "generic-array" version = "0.14.5" @@ -256,9 +341,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.5" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77" +checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" dependencies = [ "cfg-if", "libc", @@ -286,11 +371,13 @@ dependencies = [ [[package]] name = "heapless" -version = "0.7.10" +version = "0.7.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d076121838e03f862871315477528debffdb7462fb229216ecef91b1a3eb31eb" +checksum = "065681e99f9ef7e0e813702a0326aedbcbbde7db5e55f097aedd1bf50b9dca43" dependencies = [ + "atomic-polyfill", "hash32", + "rustc_version 0.4.0", "spin", "stable_deref_trait", ] @@ -322,9 +409,9 @@ dependencies = [ [[package]] name = "inout" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1f03d4ab4d5dc9ec2d219f86c15d2a15fc08239d1cd3b2d6a19717c0a2f443" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" dependencies = [ "generic-array", ] @@ -338,18 +425,25 @@ dependencies = [ "cipher 0.3.0", ] +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "libc" -version = "0.2.120" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad5c14e80759d0939d013e6ca49930e59fc53dd8e5009132f76240c179380c09" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" [[package]] name = "lock_api" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b" +checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" dependencies = [ + "autocfg", "scopeguard", ] @@ -363,6 +457,12 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + [[package]] name = "mgm" version = "0.4.6" @@ -377,6 +477,21 @@ dependencies = [ "subtle", ] +[[package]] +name = "nb" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f" +dependencies = [ + "nb 1.0.0", +] + +[[package]] +name = "nb" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "546c37ac5d9e56f55e73b677106873d9d9f5190605e41a856503623648488cae" + [[package]] name = "opaque-debug" version = "0.3.0" @@ -431,6 +546,62 @@ dependencies = [ "getrandom", ] +[[package]] +name = "regex" +version = "1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" + +[[package]] +name = "riscv" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6907ccdd7a31012b70faf2af85cd9e5ba97657cc3987c4f13f8e4d2c2a088aba" +dependencies = [ + "bare-metal 1.0.0", + "bit_field", + "riscv-target", +] + +[[package]] +name = "riscv-target" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88aa938cda42a0cf62a20cfe8d139ff1af20c2e681212b5b34adb5a58333f222" +dependencies = [ + "lazy_static", + "regex", +] + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver 0.9.0", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver 1.0.10", +] + [[package]] name = "salsa20" version = "0.10.2" @@ -446,11 +617,32 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a41d061efea015927ac527063765e73601444cdc344ba855bc7bd44578b25e1c" + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + [[package]] name = "spin" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "511254be0c5bcf062b019a6c89c01a664aa359ded62f78aa72c6fc137c0590e5" +checksum = "c530c2b0d0bf8b69304b39fe2001993e267461948b890cd037d8ad4293fa1a0d" dependencies = [ "lock_api", ] @@ -483,17 +675,38 @@ dependencies = [ "subtle", ] +[[package]] +name = "vcell" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002" + [[package]] name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + +[[package]] +name = "volatile-register" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ee8f19f9d74293faf70901bc20ad067dc1ad390d2cbf1e3f75f721ffee908b6" +dependencies = [ + "vcell", +] + [[package]] name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "xsalsa20poly1305" diff --git a/ccm/Cargo.toml b/ccm/Cargo.toml index 3faeb977..d8e46935 100644 --- a/ccm/Cargo.toml +++ b/ccm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ccm" -version = "0.4.4" +version = "0.5.0-pre" description = "Generic implementation of the Counter with CBC-MAC (CCM) mode" authors = ["RustCrypto Developers"] edition = "2018" @@ -14,14 +14,14 @@ keywords = ["encryption", "aead"] [dependencies] aead = { version = "0.4", default-features = false } -cipher = { version = "0.3", default-features = false } -ctr = { version = "0.8", default-features = false } +cipher = { version = "0.4.3", default-features = false } +ctr = { version = "0.9.1", default-features = false } subtle = { version = "2", default-features = false } [dev-dependencies] aead = { version = "0.4", features = ["dev"], default-features = false } -aes = { version = "0.7", features = ["force-soft"] } # Uses `force-soft` for MSRV 1.41 -hex-literal = "0.2" +aes = { version = "0.8.1" } +hex-literal = "0.3.4" [features] default = ["alloc"] diff --git a/ccm/README.md b/ccm/README.md index 6bd935c8..cbc47443 100644 --- a/ccm/README.md +++ b/ccm/README.md @@ -44,7 +44,7 @@ dual licensed as above, without any additional terms or conditions. [docs-image]: https://docs.rs/ccm/badge.svg [docs-link]: https://docs.rs/ccm [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg -[rustc-image]: https://img.shields.io/badge/rustc-1.41+-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.56+-blue.svg [codecov-image]: https://codecov.io/gh/RustCrypto/AEADs/branch/master/graph/badge.svg [codecov-link]: https://codecov.io/gh/RustCrypto/AEADs [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg diff --git a/ccm/src/lib.rs b/ccm/src/lib.rs index a54e5783..c66c68d2 100644 --- a/ccm/src/lib.rs +++ b/ccm/src/lib.rs @@ -51,9 +51,12 @@ use aead::{ generic_array::{typenum::Unsigned, ArrayLength, GenericArray}, AeadCore, AeadInPlace, Error, Key, NewAead, }; -use cipher::{Block, BlockCipher, BlockEncrypt, FromBlockCipher, NewBlockCipher, StreamCipher}; +use cipher::{ + Block, BlockCipher, BlockEncrypt, BlockSizeUser, InnerIvInit, KeyInit, StreamCipher, + StreamCipherSeek, +}; use core::marker::PhantomData; -use ctr::{Ctr32BE, Ctr64BE}; +use ctr::{Ctr32BE, Ctr64BE, CtrCore}; use subtle::ConstantTimeEq; mod private; @@ -95,8 +98,7 @@ impl NonceSize for T {} #[derive(Clone)] pub struct Ccm where - C: BlockCipher + BlockEncrypt, - C::ParBlocks: ArrayLength>, + C: BlockCipher + BlockSizeUser + BlockEncrypt, M: ArrayLength + TagSize, N: ArrayLength + NonceSize, { @@ -106,8 +108,7 @@ where impl Ccm where - C: BlockCipher + BlockEncrypt, - C::ParBlocks: ArrayLength>, + C: BlockCipher + BlockSizeUser + BlockEncrypt, M: ArrayLength + TagSize, N: ArrayLength + NonceSize, { @@ -173,8 +174,7 @@ where impl From for Ccm where - C: BlockCipher + BlockEncrypt + NewBlockCipher, - C::ParBlocks: ArrayLength>, + C: BlockCipher + BlockSizeUser + BlockEncrypt, M: ArrayLength + TagSize, N: ArrayLength + NonceSize, { @@ -188,8 +188,7 @@ where impl NewAead for Ccm where - C: BlockCipher + BlockEncrypt + NewBlockCipher, - C::ParBlocks: ArrayLength>, + C: BlockCipher + BlockSizeUser + BlockEncrypt + KeyInit, M: ArrayLength + TagSize, N: ArrayLength + NonceSize, { @@ -202,8 +201,7 @@ where impl AeadCore for Ccm where - C: BlockCipher + BlockEncrypt, - C::ParBlocks: ArrayLength>, + C: BlockCipher + BlockSizeUser + BlockEncrypt, M: ArrayLength + TagSize, N: ArrayLength + NonceSize, { @@ -214,8 +212,7 @@ where impl AeadInPlace for Ccm where - C: BlockCipher + BlockEncrypt, - C::ParBlocks: ArrayLength>, + C: BlockCipher + BlockSizeUser + BlockEncrypt, M: ArrayLength + TagSize, N: ArrayLength + NonceSize, { @@ -232,11 +229,11 @@ where let cb = C::BlockSize::USIZE - N::USIZE - 1; if cb > 4 { - let mut ctr = Ctr64BE::from_block_cipher(&self.cipher, &ext_nonce); + let mut ctr = Ctr64BE::from_core(CtrCore::inner_iv_init(&self.cipher, &ext_nonce)); ctr.apply_keystream(&mut full_tag); ctr.apply_keystream(buffer); } else { - let mut ctr = Ctr32BE::from_block_cipher(&self.cipher, &ext_nonce); + let mut ctr = Ctr32BE::from_core(CtrCore::inner_iv_init(&self.cipher, &ext_nonce)); ctr.apply_keystream(&mut full_tag); ctr.apply_keystream(buffer); } @@ -256,22 +253,22 @@ where let cb = C::BlockSize::USIZE - N::USIZE - 1; if cb > 4 { - let mut ctr = Ctr64BE::from_block_cipher(&self.cipher, &ext_nonce); - ctr.seek_block(1); + let mut ctr = Ctr64BE::from_core(CtrCore::inner_iv_init(&self.cipher, &ext_nonce)); + ctr.seek(C::BlockSize::USIZE); ctr.apply_keystream(buffer); } else { - let mut ctr = Ctr32BE::from_block_cipher(&self.cipher, &ext_nonce); - ctr.seek_block(1); + let mut ctr = Ctr32BE::from_core(CtrCore::inner_iv_init(&self.cipher, &ext_nonce)); + ctr.seek(C::BlockSize::USIZE); ctr.apply_keystream(buffer); } let mut full_tag = self.calc_mac(nonce, adata, buffer)?; if cb > 4 { - let mut ctr = Ctr64BE::from_block_cipher(&self.cipher, &ext_nonce); + let mut ctr = Ctr64BE::from_core(CtrCore::inner_iv_init(&self.cipher, &ext_nonce)); ctr.apply_keystream(&mut full_tag); } else { - let mut ctr = Ctr32BE::from_block_cipher(&self.cipher, &ext_nonce); + let mut ctr = Ctr32BE::from_core(CtrCore::inner_iv_init(&self.cipher, &ext_nonce)); ctr.apply_keystream(&mut full_tag); }