Skip to content

Commit a3cd3f4

Browse files
committed
eax
1 parent 435acb8 commit a3cd3f4

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ members = [
88
"ccm",
99
"chacha20poly1305",
1010
#"deoxys",
11-
#"eax",
11+
"eax",
1212
#"ocb3",
1313
#"xaes-256-gcm",
1414
]

eax/src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
//! buffer.extend_from_slice(b"plaintext message");
111111
//!
112112
//! // Encrypt `buffer` in-place, replacing the plaintext contents with ciphertext
113-
//! let tag = cipher.encrypt_inout_detached(nonce, b"", &mut buffer).expect("encryption failure!");
113+
//! let tag = cipher.encrypt_inout_detached(nonce, b"", buffer.as_mut_slice().into()).expect("encryption failure!");
114114
//!
115115
//! // The tag has only 8 bytes, compared to the usual 16 bytes
116116
//! assert_eq!(tag.len(), 8);
@@ -119,20 +119,20 @@
119119
//! assert_ne!(&buffer, b"plaintext message");
120120
//!
121121
//! // Decrypt `buffer` in-place, replacing its ciphertext context with the original plaintext
122-
//! cipher.decrypt_inout_detached(nonce, b"", &mut buffer, &tag).expect("decryption failure!");
122+
//! cipher.decrypt_inout_detached(nonce, b"", buffer.as_mut_slice().into(), &tag).expect("decryption failure!");
123123
//! assert_eq!(&buffer, b"plaintext message");
124124
//! # }
125125
//! ```
126126
127127
pub use aead::{self, AeadCore, AeadInOut, Error, Key, KeyInit, KeySizeUser};
128128
pub use cipher;
129129

130-
use aead::{PostfixTagged, inout::InOutBuf};
130+
use aead::{inout::InOutBuf, PostfixTagged};
131131
use cipher::{
132-
BlockCipherEncrypt, BlockSizeUser, InnerIvInit, StreamCipherCore, array::Array, consts::U16,
133-
crypto_common::OutputSizeUser, typenum::Unsigned,
132+
array::Array, consts::U16, crypto_common::OutputSizeUser, typenum::Unsigned,
133+
BlockCipherEncrypt, BlockSizeUser, InnerIvInit, StreamCipherCore,
134134
};
135-
use cmac::{Cmac, Mac, digest::Output};
135+
use cmac::{digest::Output, Cmac, Mac};
136136
use core::marker::PhantomData;
137137

138138
mod traits;
@@ -228,7 +228,7 @@ where
228228
&self,
229229
nonce: &Nonce<Self::NonceSize>,
230230
associated_data: &[u8],
231-
buffer: InOutBuf<'_, '_, u8>,
231+
mut buffer: InOutBuf<'_, '_, u8>,
232232
) -> Result<Tag<M>, Error> {
233233
if buffer.len() as u64 > P_MAX || associated_data.len() as u64 > A_MAX {
234234
return Err(Error);
@@ -247,10 +247,10 @@ where
247247

248248
// 3. enc ← CTR(M) using n as iv
249249
Ctr128BE::<Cipher>::inner_iv_init(Cipher::new(&self.key), &n)
250-
.apply_keystream_partial(buffer.into());
250+
.apply_keystream_partial(buffer.reborrow());
251251

252252
// 4. c ← OMAC(2 || enc)
253-
let c = Self::cmac_with_iv(&self.key, 2, buffer);
253+
let c = Self::cmac_with_iv(&self.key, 2, buffer.get_out());
254254

255255
// 5. tag ← n ^ h ^ c
256256
// (^ means xor)
@@ -285,7 +285,7 @@ where
285285
let h = Self::cmac_with_iv(&self.key, 1, associated_data);
286286

287287
// 4. c ← OMAC(2 || enc)
288-
let c = Self::cmac_with_iv(&self.key, 2, buffer);
288+
let c = Self::cmac_with_iv(&self.key, 2, buffer.get_in());
289289

290290
// 5. tag ← n ^ h ^ c
291291
// (^ means xor)
@@ -305,7 +305,7 @@ where
305305
if expected_tag.ct_eq(tag).into() {
306306
// Decrypt
307307
Ctr128BE::<Cipher>::inner_iv_init(Cipher::new(&self.key), &n)
308-
.apply_keystream_partial(buffer.into());
308+
.apply_keystream_partial(buffer);
309309

310310
Ok(())
311311
} else {

0 commit comments

Comments
 (0)