diff --git a/eax/src/lib.rs b/eax/src/lib.rs index 7b81063d..d2e6c7f0 100644 --- a/eax/src/lib.rs +++ b/eax/src/lib.rs @@ -133,8 +133,7 @@ pub use cipher; use aead::{TagPosition, inout::InOutBuf}; use cipher::{ - BlockCipherEncrypt, BlockSizeUser, InnerIvInit, StreamCipherCore, array::Array, - common::OutputSizeUser, consts::U16, typenum::Unsigned, + BlockCipherEncrypt, BlockSizeUser, InnerIvInit, StreamCipherCore, array::Array, consts::U16, }; use cmac::{Cmac, Mac, digest::Output}; use core::marker::PhantomData; @@ -159,9 +158,6 @@ pub type Nonce = Array; /// EAX tags pub type Tag = Array; -// TODO: Drop that once https://github.com/RustCrypto/traits/pull/1533 releases. -type OutputSize = ::OutputSize; - pub mod online; /// Counter mode with a 128-bit big endian counter. @@ -251,17 +247,8 @@ where let c = Self::cmac_with_iv(&self.key, 2, buffer.get_out()); // 5. tag ← n ^ h ^ c - // (^ means xor) - let full_tag: Array<_, OutputSize>> = n - .into_iter() - .zip(h) - .map(|(a, b)| a ^ b) - .zip(c) - .map(|(a, b)| a ^ b) - .take(OutputSize::>::to_usize()) - .collect(); - - let tag = Tag::::try_from(&full_tag[..M::to_usize()]).expect("tag size mismatch"); + let tag = Array::::from_fn(|i| n[i] ^ h[i] ^ c[i]); + Ok(tag) } @@ -286,17 +273,7 @@ where let c = Self::cmac_with_iv(&self.key, 2, buffer.get_in()); // 5. tag ← n ^ h ^ c - // (^ means xor) - let expected_tag: Array<_, OutputSize>> = n - .into_iter() - .zip(h) - .map(|(a, b)| a ^ b) - .zip(c) - .map(|(a, b)| a ^ b) - .take(OutputSize::>::to_usize()) - .collect(); - - let expected_tag = &expected_tag[..tag.len()]; + let expected_tag = Array::::from_fn(|i| n[i] ^ h[i] ^ c[i]); // Constant-time MAC comparison use subtle::ConstantTimeEq;