From 75facb67608dd72ef636d8c12e109d6cd9ec4dbb Mon Sep 17 00:00:00 2001 From: Ben Wolsieffer Date: Fri, 16 Apr 2021 18:56:40 -0400 Subject: [PATCH] eax: use 4-byte nonce instead of block size This is a hack until https://github.com/RustCrypto/AEADs/issues/239 is fixed. --- eax/src/lib.rs | 4 ++-- eax/src/online.rs | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/eax/src/lib.rs b/eax/src/lib.rs index ae34b7d9..57d69447 100644 --- a/eax/src/lib.rs +++ b/eax/src/lib.rs @@ -83,7 +83,7 @@ pub use cipher; use cipher::{ block::{Block, BlockCipher, Key, NewBlockCipher}, - consts::{U0, U16}, + consts::{U0, U4, U16}, generic_array::{functional::FunctionalSequence, ArrayLength, GenericArray}, stream::{FromBlockCipher, SyncStreamCipher}, }; @@ -137,7 +137,7 @@ where Cipher: BlockCipher + NewBlockCipher + Clone, Cipher::ParBlocks: ArrayLength>, { - type NonceSize = Cipher::BlockSize; + type NonceSize = U4; type TagSize = as Mac>::OutputSize; type CiphertextOverhead = U0; diff --git a/eax/src/online.rs b/eax/src/online.rs index 2618f935..57756d49 100644 --- a/eax/src/online.rs +++ b/eax/src/online.rs @@ -60,6 +60,7 @@ use crate::*; use core::marker::PhantomData; +use cipher::consts::U4; pub use Eax as EaxOnline; @@ -160,7 +161,7 @@ where { /// 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: &Key, nonce: &Nonce) -> Self { + pub fn with_key_and_nonce(key: &Key, nonce: &Nonce) -> Self { let imp = EaxImpl::::with_key_and_nonce(key, nonce); Self { @@ -261,7 +262,7 @@ where Cipher: BlockCipher + NewBlockCipher + Clone, Cipher::ParBlocks: ArrayLength>, { - nonce: Nonce, + nonce: Nonce, data: Cmac, message: Cmac, ctr: ctr::Ctr128, @@ -277,7 +278,7 @@ where { /// 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: &Key, 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); cmac.update(&[0; 15]); @@ -400,7 +401,7 @@ mod test_impl { Cipher: BlockCipher + NewBlockCipher + Clone, Cipher::ParBlocks: ArrayLength>, { - type NonceSize = Cipher::BlockSize; + type NonceSize = U4; type TagSize = as Mac>::OutputSize; type CiphertextOverhead = U0;