From 629611f186f8b34d79733472a0fde032b4284734 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sat, 30 Jul 2022 12:29:26 -0600 Subject: [PATCH] eax: bump `cipher` to v0.4 --- Cargo.lock | 70 ++++++++++------------------------------------- eax/Cargo.toml | 8 +++--- eax/src/lib.rs | 48 ++++++++++++++++---------------- eax/src/online.rs | 54 ++++++++++++++---------------------- 4 files changed, 62 insertions(+), 118 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 30dad87a..b10166ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,18 +15,6 @@ dependencies = [ "heapless", ] -[[package]] -name = "aes" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" -dependencies = [ - "cfg-if", - "cipher 0.3.0", - "cpufeatures", - "opaque-debug", -] - [[package]] name = "aes" version = "0.8.1" @@ -43,9 +31,9 @@ name = "aes-gcm" version = "0.10.0-pre.2" dependencies = [ "aead", - "aes 0.8.1", + "aes", "cipher 0.4.3", - "ctr 0.9.1", + "ctr", "ghash", "hex-literal 0.3.4", "subtle", @@ -57,9 +45,9 @@ name = "aes-gcm-siv" version = "0.11.0-pre.2" dependencies = [ "aead", - "aes 0.8.1", + "aes", "cipher 0.4.3", - "ctr 0.9.1", + "ctr", "polyval", "subtle", "zeroize", @@ -70,11 +58,11 @@ name = "aes-siv" version = "0.7.0" dependencies = [ "aead", - "aes 0.8.1", + "aes", "blobby", "cipher 0.4.3", - "cmac 0.7.1", - "ctr 0.9.1", + "cmac", + "ctr", "dbl", "digest", "hex-literal 0.3.4", @@ -159,9 +147,9 @@ name = "ccm" version = "0.5.0" dependencies = [ "aead", - "aes 0.8.1", + "aes", "cipher 0.4.3", - "ctr 0.9.1", + "ctr", "hex-literal 0.3.4", "subtle", ] @@ -214,16 +202,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "cmac" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b70e37282d9624283878ffda1d1e53883bcf868cf441bddda44127620b39572d" -dependencies = [ - "crypto-mac", - "dbl", -] - [[package]] name = "cmac" version = "0.7.1" @@ -279,26 +257,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "crypto-mac" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" -dependencies = [ - "cipher 0.3.0", - "generic-array", - "subtle", -] - -[[package]] -name = "ctr" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "049bb91fb4aaf0e3c7efa6cd5ef877dbbbd15b39dad06d9948de4ec8a75761ea" -dependencies = [ - "cipher 0.3.0", -] - [[package]] name = "ctr" version = "0.9.1" @@ -322,7 +280,7 @@ name = "deoxys" version = "0.1.0-pre.1" dependencies = [ "aead", - "aes 0.8.1", + "aes", "hex-literal 0.3.4", "subtle", "zeroize", @@ -344,10 +302,10 @@ name = "eax" version = "0.5.0-pre.1" dependencies = [ "aead", - "aes 0.7.5", - "cipher 0.3.0", - "cmac 0.6.0", - "ctr 0.8.0", + "aes", + "cipher 0.4.3", + "cmac", + "ctr", "subtle", ] diff --git a/eax/Cargo.toml b/eax/Cargo.toml index 3b2d4a56..e3b8435c 100644 --- a/eax/Cargo.toml +++ b/eax/Cargo.toml @@ -21,14 +21,14 @@ rust-version = "1.56" [dependencies] aead = { version = "0.5", default-features = false } -cipher = "0.3" -cmac = "0.6" -ctr = "0.8" +cipher = "0.4" +cmac = "0.7" +ctr = "0.9" subtle = { version = "2", default-features = false } [dev-dependencies] aead = { version = "0.5", features = ["dev"], default-features = false } -aes = "0.7" +aes = "0.8" [features] default = ["alloc", "getrandom"] diff --git a/eax/src/lib.rs b/eax/src/lib.rs index c708e4ce..3a967c43 100644 --- a/eax/src/lib.rs +++ b/eax/src/lib.rs @@ -117,16 +117,16 @@ #![deny(unsafe_code)] #![warn(missing_docs, rust_2018_idioms)] -pub use aead::{self, AeadCore, AeadInPlace, Error, KeyInit, KeySizeUser}; +pub use aead::{self, AeadCore, AeadInPlace, Error, Key, KeyInit, KeySizeUser}; pub use cipher; use cipher::{ consts::{U0, U16}, - generic_array::{functional::FunctionalSequence, ArrayLength, GenericArray}, - Block, BlockCipher, BlockCipherKey, BlockEncrypt, FromBlockCipher, NewBlockCipher, - StreamCipher, + crypto_common::OutputSizeUser, + generic_array::{functional::FunctionalSequence, GenericArray}, + BlockCipher, BlockEncrypt, InnerIvInit, StreamCipherCore, }; -use cmac::{crypto_mac::NewMac, Cmac, Mac}; +use cmac::{Cmac, Mac}; use core::marker::PhantomData; mod traits; @@ -151,6 +151,9 @@ pub type Tag = GenericArray; pub mod online; +/// Counter mode with a 128-bit big endian counter. +type Ctr128BE = ctr::CtrCore; + /// EAX: generic over an underlying block cipher implementation. /// /// This type is generic to support substituting alternative cipher @@ -164,19 +167,17 @@ pub mod online; #[derive(Clone)] pub struct Eax where - Cipher: BlockCipher + BlockEncrypt + NewBlockCipher + Clone, - Cipher::ParBlocks: ArrayLength>, + Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, M: TagSize, { /// Encryption key - key: BlockCipherKey, + key: Key, _tag_size: PhantomData, } impl KeySizeUser for Eax where - Cipher: BlockCipher + BlockEncrypt + NewBlockCipher + Clone, - Cipher::ParBlocks: ArrayLength>, + Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, M: TagSize, { type KeySize = Cipher::KeySize; @@ -184,11 +185,10 @@ where impl KeyInit for Eax where - Cipher: BlockCipher + BlockEncrypt + NewBlockCipher + Clone, - Cipher::ParBlocks: ArrayLength>, + Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, M: TagSize, { - fn new(key: &BlockCipherKey) -> Self { + fn new(key: &Key) -> Self { Self { key: key.clone(), _tag_size: PhantomData, @@ -198,8 +198,7 @@ where impl AeadCore for Eax where - Cipher: BlockCipher + BlockEncrypt + NewBlockCipher + Clone, - Cipher::ParBlocks: ArrayLength>, + Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, M: TagSize, { type NonceSize = Cipher::BlockSize; @@ -209,8 +208,7 @@ where impl AeadInPlace for Eax where - Cipher: BlockCipher + BlockEncrypt + NewBlockCipher + Clone, - Cipher::ParBlocks: ArrayLength>, + Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, M: TagSize, { fn encrypt_in_place_detached( @@ -235,8 +233,8 @@ where let h = Self::cmac_with_iv(&self.key, 1, associated_data); // 3. enc ← CTR(M) using n as iv - let mut cipher = ctr::Ctr128BE::::from_block_cipher(Cipher::new(&self.key), &n); - cipher.apply_keystream(buffer); + Ctr128BE::::inner_iv_init(Cipher::new(&self.key), &n) + .apply_keystream_partial(buffer.into()); // 4. c ← OMAC(2 || enc) let c = Self::cmac_with_iv(&self.key, 2, buffer); @@ -278,8 +276,9 @@ where use subtle::ConstantTimeEq; if expected_tag.ct_eq(tag).into() { // Decrypt - let mut cipher = ctr::Ctr128BE::::from_block_cipher(Cipher::new(&self.key), &n); - cipher.apply_keystream(buffer); + Ctr128BE::::inner_iv_init(Cipher::new(&self.key), &n) + .apply_keystream_partial(buffer.into()); + Ok(()) } else { Err(Error) @@ -289,8 +288,7 @@ where impl Eax where - Cipher: BlockCipher + BlockEncrypt + NewBlockCipher + Clone, - Cipher::ParBlocks: ArrayLength>, + Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, M: TagSize, { /// CMAC/OMAC1 @@ -301,8 +299,8 @@ where key: &GenericArray, iv: u8, data: &[u8], - ) -> GenericArray as Mac>::OutputSize> { - let mut mac = Cmac::::new(key); + ) -> GenericArray as OutputSizeUser>::OutputSize> { + let mut mac = as Mac>::new(key); mac.update(&[0; 15]); mac.update(&[iv]); mac.update(data); diff --git a/eax/src/online.rs b/eax/src/online.rs index 4f02ac7b..12ab75a0 100644 --- a/eax/src/online.rs +++ b/eax/src/online.rs @@ -57,13 +57,13 @@ //! [`Decrypt`]: struct.Decrypt.html //! [`finish`]: #method.finish -use crate::{Block, Cmac, Error, Nonce, Tag, TagSize}; +use crate::{Cmac, Error, Nonce, Tag, TagSize}; use aead::consts::U16; use cipher::{ - generic_array::{functional::FunctionalSequence, ArrayLength}, - BlockCipher, BlockCipherKey, BlockEncrypt, FromBlockCipher, NewBlockCipher, StreamCipher, + generic_array::functional::FunctionalSequence, BlockCipher, BlockEncrypt, Key, KeyInit, + KeyIvInit, StreamCipher, }; -use cmac::{Mac, NewMac}; +use cmac::Mac; use core::marker::PhantomData; pub use Eax as EaxOnline; @@ -150,8 +150,7 @@ impl CipherOp for Decrypt {} /// [`finish`]: #method.finish pub struct Eax where - Cipher: BlockCipher + BlockEncrypt + NewBlockCipher + Clone, - Cipher::ParBlocks: ArrayLength>, + Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, Op: CipherOp, M: TagSize, { @@ -162,17 +161,13 @@ where impl Eax where - Cipher: BlockCipher + BlockEncrypt + NewBlockCipher + Clone, - Cipher::ParBlocks: ArrayLength>, + Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, Op: CipherOp, M: TagSize, { /// Creates a stateful EAX instance that is capable of processing both /// the associated data and the plaintext in an "on-line" fashion. - pub fn with_key_and_nonce( - key: &BlockCipherKey, - nonce: &Nonce, - ) -> Self { + pub fn with_key_and_nonce(key: &Key, nonce: &Nonce) -> Self { let imp = EaxImpl::::with_key_and_nonce(key, nonce); Self { @@ -201,8 +196,7 @@ where impl Eax where - Cipher: BlockCipher + BlockEncrypt + NewBlockCipher + Clone, - Cipher::ParBlocks: ArrayLength>, + Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, M: TagSize, { /// Applies encryption to the plaintext. @@ -223,8 +217,7 @@ where impl Eax where - Cipher: BlockCipher + BlockEncrypt + NewBlockCipher + Clone, - Cipher::ParBlocks: ArrayLength>, + Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, M: TagSize, { /// Applies decryption to the ciphertext **without** verifying the @@ -272,8 +265,8 @@ where #[doc(hidden)] struct EaxImpl where - Cipher: BlockCipher + BlockEncrypt + NewBlockCipher + Clone, - Cipher::ParBlocks: ArrayLength>, + Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, + M: TagSize, { nonce: Nonce, @@ -282,21 +275,20 @@ where ctr: ctr::Ctr128BE, // HACK: Needed for the test harness due to AEAD trait online/offline interface mismatch #[cfg(test)] - key: BlockCipherKey, + key: Key, _tag_size: PhantomData, } impl EaxImpl where - Cipher: BlockCipher + BlockEncrypt + NewBlockCipher + Clone, - Cipher::ParBlocks: ArrayLength>, + Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, M: TagSize, { /// Creates a stateful EAX instance that is capable of processing both /// the associated data and the plaintext in an "on-line" fashion. - fn with_key_and_nonce(key: &BlockCipherKey, nonce: &Nonce) -> Self { + fn with_key_and_nonce(key: &Key, nonce: &Nonce) -> Self { let prepend_cmac = |key, init_val, data| { - let mut cmac = Cmac::::new(key); + let mut cmac = as Mac>::new(key); cmac.update(&[0; 15]); cmac.update(&[init_val]); cmac.update(data); @@ -318,7 +310,7 @@ where // 3. c ← OMAC(2 || enc) let c = prepend_cmac(key, 2, &[]); - let cipher = ctr::Ctr128BE::::from_block_cipher(Cipher::new(key), &n); + let cipher = ctr::Ctr128BE::::new(key, &n); Self { nonce: n, @@ -400,8 +392,7 @@ mod test_impl { impl KeySizeUser for EaxImpl where - Cipher: BlockCipher + BlockEncrypt + NewBlockCipher + Clone, - Cipher::ParBlocks: ArrayLength>, + Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, M: TagSize, { type KeySize = Cipher::KeySize; @@ -409,11 +400,10 @@ mod test_impl { impl KeyInit for EaxImpl where - Cipher: BlockCipher + BlockEncrypt + NewBlockCipher + Clone, - Cipher::ParBlocks: ArrayLength>, + Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, M: TagSize, { - fn new(key: &BlockCipherKey) -> Self { + fn new(key: &Key) -> Self { // HACK: The nonce will be initialized by the appropriate // decrypt/encrypt functions from `AeadMutInPlace` implementation. // This is currently done so because that trait only implements @@ -427,8 +417,7 @@ mod test_impl { impl AeadCore for super::EaxImpl where - Cipher: BlockCipher + BlockEncrypt + NewBlockCipher + Clone, - Cipher::ParBlocks: ArrayLength>, + Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, M: TagSize, { type NonceSize = Cipher::BlockSize; @@ -438,8 +427,7 @@ mod test_impl { impl AeadMutInPlace for super::EaxImpl where - Cipher: BlockCipher + BlockEncrypt + NewBlockCipher + Clone, - Cipher::ParBlocks: ArrayLength>, + Cipher: BlockCipher + BlockEncrypt + Clone + KeyInit, M: TagSize, { fn encrypt_in_place_detached(