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 May 7, 2021
1 parent 1e121c8 commit 75facb6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions eax/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -137,7 +137,7 @@ where
Cipher: BlockCipher<BlockSize = U16> + NewBlockCipher + Clone,
Cipher::ParBlocks: ArrayLength<Block<Cipher>>,
{
type NonceSize = Cipher::BlockSize;
type NonceSize = U4;
type TagSize = <Cmac<Cipher> as Mac>::OutputSize;
type CiphertextOverhead = U0;

Expand Down
9 changes: 5 additions & 4 deletions eax/src/online.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
use crate::*;

use core::marker::PhantomData;
use cipher::consts::U4;

pub use Eax as EaxOnline;

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

Self {
Expand Down Expand Up @@ -261,7 +262,7 @@ where
Cipher: BlockCipher<BlockSize = U16> + NewBlockCipher + Clone,
Cipher::ParBlocks: ArrayLength<Block<Cipher>>,
{
nonce: Nonce<Cipher::BlockSize>,
nonce: Nonce<U4>,
data: Cmac<Cipher>,
message: Cmac<Cipher>,
ctr: ctr::Ctr128<Cipher>,
Expand All @@ -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<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>::new(key);
cmac.update(&[0; 15]);
Expand Down Expand Up @@ -400,7 +401,7 @@ mod test_impl {
Cipher: BlockCipher<BlockSize = U16> + NewBlockCipher + Clone,
Cipher::ParBlocks: ArrayLength<Block<Cipher>>,
{
type NonceSize = Cipher::BlockSize;
type NonceSize = U4;
type TagSize = <Cmac<Cipher> as Mac>::OutputSize;
type CiphertextOverhead = U0;

Expand Down

0 comments on commit 75facb6

Please sign in to comment.