From 09b46d2499fbe5ac3aea1f3ab92bc6191d6866a3 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sun, 5 Nov 2023 19:50:19 -0500 Subject: [PATCH] Revert "Correct off-by-one in minimum output buffer size computation" --- openssl/src/cipher_ctx.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/openssl/src/cipher_ctx.rs b/openssl/src/cipher_ctx.rs index 754539c7e9..1769ee9716 100644 --- a/openssl/src/cipher_ctx.rs +++ b/openssl/src/cipher_ctx.rs @@ -556,8 +556,11 @@ impl CipherCtxRef { output: Option<&mut [u8]>, ) -> Result { 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.", @@ -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()); }