Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ocb3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ where
buffer: InOutBuf<'_, '_, u8>,
) -> aead::Result<aead::Tag<Self>> {
let max_len = 1 << (L_TABLE_SIZE + 4);
if (buffer.len() > max_len) || (associated_data.len() > max_len) {
if (buffer.len() >= max_len) || (associated_data.len() >= max_len) {
return Err(aead::Error);
}

Expand Down
14 changes: 14 additions & 0 deletions ocb3/tests/len_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,17 @@ fn ocb3_len_check() {
.encrypt_inout_detached(&nonce, &[], (&mut buf[..MAX_SIZE - 1]).into())
.unwrap();
}

#[test]
fn ocb3_len_check_decrypt() {
let key = hex!("000102030405060708090A0B0C0D0E0F").into();
let nonce = hex!("BBAA9988776655443322110F").into();
let cipher = Ocb3::<Aes128, U12, U16, L_SIZE>::new(&key);

// Buffer length equal to MAX_SIZE must be rejected with an error, not panic.
let mut buf = vec![0u8; MAX_SIZE];
let tag = aead::Tag::<Ocb3<Aes128, U12, U16, L_SIZE>>::default();
cipher
.decrypt_inout_detached(&nonce, &[], (&mut buf[..]).into(), &tag)
.unwrap_err();
}