Skip to content

Commit 753d50e

Browse files
tarcieribaloo
authored andcommitted
Migrate to AeadInOut
Replaces the previous `AeadInPlaceDetached` impls with `AeadInOut`, which was introduced in RustCrypto/traits#1793
1 parent 725bdab commit 753d50e

File tree

26 files changed

+183
-326
lines changed

26 files changed

+183
-326
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ members = [
44
"aes-gcm",
55
"aes-gcm-siv",
66
"aes-siv",
7-
"ascon-aead",
8-
"ccm",
9-
"chacha20poly1305",
10-
"deoxys",
11-
"eax",
12-
"ocb3",
7+
#"ascon-aead",
8+
#"ccm",
9+
#"chacha20poly1305",
10+
#"deoxys",
11+
#"eax",
12+
#"ocb3",
1313
"xaes-256-gcm",
1414
]
1515
resolver = "2"
@@ -18,8 +18,8 @@ resolver = "2"
1818
aead-stream = { path = "./aead-stream" }
1919
aes-gcm = { path = "./aes-gcm" }
2020

21-
aead = { git = "https://github.com/RustCrypto/traits.git" }
22-
crypto-common = { git = "https://github.com/RustCrypto/traits.git" }
21+
aead = { git = "https://github.com/baloo/traits.git", branch = "baloo/aead/bicephalbuffer" }
22+
crypto-common = { git = "https://github.com/baloo/traits.git", branch = "baloo/aead/bicephalbuffer" }
2323

2424
chacha20 = { git = "https://github.com/RustCrypto/stream-ciphers.git" }
2525

aes-gcm-siv/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ categories = ["cryptography", "no-std"]
1717
rust-version = "1.85"
1818

1919
[dependencies]
20-
aead = { version = "0.6.0-rc.0", default-features = false }
20+
aead = { version = "0.6.0-rc.0", default-features = false, features = ["inout"] }
2121
aes = { version = "=0.9.0-pre.3", optional = true }
2222
cipher = "=0.5.0-pre.8"
2323
ctr = "0.10.0-pre.2"

aes-gcm-siv/src/lib.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@
7878
//! provide an impl of [`aead::Buffer`] for `bytes::BytesMut` (re-exported from the
7979
//! [`aead`] crate as [`aead::bytes::BytesMut`]).
8080
81-
pub use aead::{self, AeadCore, AeadInPlaceDetached, Error, Key, KeyInit, KeySizeUser};
81+
pub use aead::{self, AeadCore, AeadInOut, Error, Key, KeyInit, KeySizeUser};
8282

8383
#[cfg(feature = "aes")]
8484
pub use aes;
8585

86-
use aead::PostfixTagged;
86+
use aead::{PostfixTagged, inout::InOutBuf};
8787
use cipher::{
8888
BlockCipherEncrypt, BlockSizeUser, InnerIvInit, StreamCipherCore,
8989
array::Array,
@@ -165,28 +165,28 @@ where
165165

166166
impl<Aes> PostfixTagged for AesGcmSiv<Aes> {}
167167

168-
impl<Aes> AeadInPlaceDetached for AesGcmSiv<Aes>
168+
impl<Aes> AeadInOut for AesGcmSiv<Aes>
169169
where
170170
Aes: BlockSizeUser<BlockSize = U16> + BlockCipherEncrypt + KeyInit,
171171
{
172-
fn encrypt_in_place_detached(
172+
fn encrypt_inout_detached(
173173
&self,
174174
nonce: &Nonce,
175175
associated_data: &[u8],
176-
buffer: &mut [u8],
176+
buffer: InOutBuf<'_, '_, u8>,
177177
) -> Result<Tag, Error> {
178178
Cipher::<Aes>::new(&self.key_generating_key, nonce)
179-
.encrypt_in_place_detached(associated_data, buffer)
179+
.encrypt_inout_detached(associated_data, buffer)
180180
}
181181

182-
fn decrypt_in_place_detached(
182+
fn decrypt_inout_detached(
183183
&self,
184184
nonce: &Nonce,
185185
associated_data: &[u8],
186-
buffer: &mut [u8],
186+
buffer: InOutBuf<'_, '_, u8>,
187187
tag: &Tag,
188188
) -> Result<(), Error> {
189-
Cipher::<Aes>::new(&self.key_generating_key, nonce).decrypt_in_place_detached(
189+
Cipher::<Aes>::new(&self.key_generating_key, nonce).decrypt_inout_detached(
190190
associated_data,
191191
buffer,
192192
tag,
@@ -268,30 +268,30 @@ where
268268
}
269269

270270
/// Encrypt the given message in-place, returning the authentication tag.
271-
pub(crate) fn encrypt_in_place_detached(
271+
pub(crate) fn encrypt_inout_detached(
272272
mut self,
273273
associated_data: &[u8],
274-
buffer: &mut [u8],
274+
buffer: InOutBuf<'_, '_, u8>,
275275
) -> Result<Tag, Error> {
276276
if buffer.len() as u64 > P_MAX || associated_data.len() as u64 > A_MAX {
277277
return Err(Error);
278278
}
279279

280280
self.polyval.update_padded(associated_data);
281-
self.polyval.update_padded(buffer);
281+
self.polyval.update_padded(buffer.get_in());
282282

283283
let tag = self.finish_tag(associated_data.len(), buffer.len());
284-
init_ctr(&self.enc_cipher, &tag).apply_keystream_partial(buffer.into());
284+
init_ctr(&self.enc_cipher, &tag).apply_keystream_partial(buffer);
285285

286286
Ok(tag)
287287
}
288288

289289
/// Decrypt the given message, first authenticating ciphertext integrity
290290
/// and returning an error if it's been tampered with.
291-
pub(crate) fn decrypt_in_place_detached(
291+
pub(crate) fn decrypt_inout_detached(
292292
mut self,
293293
associated_data: &[u8],
294-
buffer: &mut [u8],
294+
mut buffer: InOutBuf<'_, '_, u8>,
295295
tag: &Tag,
296296
) -> Result<(), Error> {
297297
if buffer.len() as u64 > C_MAX || associated_data.len() as u64 > A_MAX {
@@ -301,8 +301,8 @@ where
301301
self.polyval.update_padded(associated_data);
302302

303303
// TODO(tarcieri): interleave decryption and authentication
304-
init_ctr(&self.enc_cipher, tag).apply_keystream_partial(buffer.into());
305-
self.polyval.update_padded(buffer);
304+
init_ctr(&self.enc_cipher, tag).apply_keystream_partial(buffer.reborrow());
305+
self.polyval.update_padded(buffer.get_out());
306306

307307
let expected_tag = self.finish_tag(associated_data.len(), buffer.len());
308308

@@ -312,7 +312,7 @@ where
312312
} else {
313313
// On MAC verify failure, re-encrypt the plaintext buffer to
314314
// prevent accidental exposure.
315-
init_ctr(&self.enc_cipher, tag).apply_keystream_partial(buffer.into());
315+
init_ctr(&self.enc_cipher, tag).apply_keystream_partial(buffer);
316316
Err(Error)
317317
}
318318
}

0 commit comments

Comments
 (0)