Skip to content

Commit

Permalink
eax: use 4-byte nonce instead of block size
Browse files Browse the repository at this point in the history
This is a hack until RustCrypto#239 is fixed.
  • Loading branch information
lopsided98 committed Dec 22, 2022
1 parent 3e927d0 commit ab3b06a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions eax/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub use aead::{self, AeadCore, AeadInPlace, Error, Key, KeyInit, KeySizeUser};
pub use cipher;

use cipher::{
consts::{U0, U16},
consts::{U0, U4, U16},
generic_array::{functional::FunctionalSequence, GenericArray},
BlockCipher, BlockEncrypt, InnerIvInit, StreamCipherCore,
};
Expand Down Expand Up @@ -200,7 +200,7 @@ where
Cipher: BlockCipher<BlockSize = U16> + BlockEncrypt + Clone + KeyInit,
M: TagSize,
{
type NonceSize = Cipher::BlockSize;
type NonceSize = U4;
type TagSize = M;
type CiphertextOverhead = U0;
}
Expand Down
7 changes: 4 additions & 3 deletions eax/src/online.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ use cipher::{
};
use cmac::Mac;
use core::marker::PhantomData;
use cipher::consts::U4;

pub use Eax as EaxOnline;

Expand Down Expand Up @@ -167,7 +168,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<Cipher>, nonce: &Nonce<Cipher::BlockSize>) -> Self {
pub fn with_key_and_nonce(key: &Key<Cipher>, nonce: &Nonce<U4>) -> Self {
let imp = EaxImpl::<Cipher, M>::with_key_and_nonce(key, nonce);

Self {
Expand Down Expand Up @@ -286,7 +287,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<Cipher>, nonce: &Nonce<Cipher::BlockSize>) -> Self {
fn with_key_and_nonce(key: &Key<Cipher>, nonce: &Nonce<U4>) -> Self {
let prepend_cmac = |key, init_val, data| {
let mut cmac = <Cmac<Cipher> as Mac>::new(key);
cmac.update(&[0; 15]);
Expand Down Expand Up @@ -420,7 +421,7 @@ mod test_impl {
Cipher: BlockCipher<BlockSize = U16> + BlockEncrypt + Clone + KeyInit,
M: TagSize,
{
type NonceSize = Cipher::BlockSize;
type NonceSize = U4;
type TagSize = M;
type CiphertextOverhead = U0;
}
Expand Down

0 comments on commit ab3b06a

Please sign in to comment.