Skip to content

Commit aa33d7b

Browse files
Rust wrapper: chacha20_poly1305: add debug_assert checking in-place operation maximum length
1 parent 444f905 commit aa33d7b

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

wrapper/rust/wolfssl-wolfcrypt/src/chacha20_poly1305.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ impl aead::AeadInPlace for XChaCha20Poly1305Aead {
470470
// single output buffer. Use a stack buffer to hold both, then split
471471
// the tag out and copy the ciphertext back over the caller's buffer.
472472
const MAX_INLINE: usize = 4096;
473+
debug_assert!(buffer.len() <= MAX_INLINE, "Maximum of 4096 bytes supported");
473474
if buffer.len() > MAX_INLINE {
474475
return Err(aead::Error);
475476
}
@@ -495,6 +496,7 @@ impl aead::AeadInPlace for XChaCha20Poly1305Aead {
495496
Ok(tag)
496497
}
497498

499+
// This function can decrypt a maximum of 4096 bytes.
498500
fn decrypt_in_place_detached(
499501
&self,
500502
nonce: &aead::Nonce<Self>,
@@ -505,6 +507,7 @@ impl aead::AeadInPlace for XChaCha20Poly1305Aead {
505507
// wc_XChaCha20Poly1305_Decrypt expects the auth tag appended after the
506508
// ciphertext. Build a combined [ciphertext | tag] buffer on the stack.
507509
const MAX_INLINE: usize = 4096;
510+
debug_assert!(buffer.len() <= MAX_INLINE, "Maximum of 4096 bytes supported");
508511
if buffer.len() > MAX_INLINE {
509512
return Err(aead::Error);
510513
}

0 commit comments

Comments
 (0)