Skip to content

Commit

Permalink
Merge pull request sfackler#2090 from sfackler/revert-2088-block-size…
Browse files Browse the repository at this point in the history
…-off-by-one

Revert "Correct off-by-one in minimum output buffer size computation"
  • Loading branch information
sfackler committed Nov 19, 2023
2 parents 730aaed + 09b46d2 commit 2d9458e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions openssl/src/cipher_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,11 @@ impl CipherCtxRef {
output: Option<&mut [u8]>,
) -> Result<usize, ErrorStack> {
if let Some(output) = &output {
let block_size = self.block_size();
let min_output_size = input.len() + block_size - 1;
let mut block_size = self.block_size();
if block_size == 1 {
block_size = 0;
}
let min_output_size = input.len() + block_size;
assert!(
output.len() >= min_output_size,
"Output buffer size should be at least {} bytes.",
Expand Down Expand Up @@ -907,19 +910,19 @@ mod test {
}

#[test]
#[should_panic(expected = "Output buffer size should be at least 32 bytes.")]
#[should_panic(expected = "Output buffer size should be at least 33 bytes.")]
fn full_block_updates_aes_128() {
output_buffer_too_small(Cipher::aes_128_cbc());
}

#[test]
#[should_panic(expected = "Output buffer size should be at least 32 bytes.")]
#[should_panic(expected = "Output buffer size should be at least 33 bytes.")]
fn full_block_updates_aes_256() {
output_buffer_too_small(Cipher::aes_256_cbc());
}

#[test]
#[should_panic(expected = "Output buffer size should be at least 16 bytes.")]
#[should_panic(expected = "Output buffer size should be at least 17 bytes.")]
fn full_block_updates_3des() {
output_buffer_too_small(Cipher::des_ede3_cbc());
}
Expand Down

0 comments on commit 2d9458e

Please sign in to comment.