Skip to content

Commit 34fc14f

Browse files
committed
Fix
1 parent 1d44782 commit 34fc14f

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/aead.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ mod recprot {
309309
.len()
310310
.checked_sub(super::TAG_LEN)
311311
.ok_or_else(|| Error::from(SEC_ERROR_BAD_DATA))?;
312+
let mut tag = [0u8; super::TAG_LEN];
313+
tag.copy_from_slice(&data[ct_len..]);
312314
let data_ptr = data.as_mut_ptr();
313315
let out_len = unsafe {
314316
aead_op(
@@ -318,7 +320,7 @@ mod recprot {
318320
aad,
319321
data_ptr,
320322
data.len(),
321-
data_ptr.add(ct_len),
323+
tag.as_mut_ptr(),
322324
data_ptr.cast_const(),
323325
ct_len,
324326
)

tests/aead.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ fn roundtrip(cipher: Cipher) {
163163
.decrypt(42, AAD, ct, &mut pt_buf[..ct.len()])
164164
.expect("decrypt");
165165
assert_eq!(pt, PLAINTEXT);
166+
167+
let mut ip_buf = Vec::from(PLAINTEXT);
168+
ip_buf.resize(PLAINTEXT.len() + aead.expansion(), 0);
169+
let enc_len = aead.encrypt_in_place(42, AAD, &mut ip_buf).unwrap();
170+
assert_eq!(enc_len, ip_buf.len());
171+
let dec_len = aead.decrypt_in_place(42, AAD, &mut ip_buf).unwrap();
172+
assert_eq!(&ip_buf[..dec_len], PLAINTEXT);
166173
}
167174

168175
#[test]

0 commit comments

Comments
 (0)