Skip to content

Commit 2d9458e

Browse files
authored
Merge pull request #2090 from sfackler/revert-2088-block-size-off-by-one
Revert "Correct off-by-one in minimum output buffer size computation"
2 parents 730aaed + 09b46d2 commit 2d9458e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

openssl/src/cipher_ctx.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,11 @@ impl CipherCtxRef {
556556
output: Option<&mut [u8]>,
557557
) -> Result<usize, ErrorStack> {
558558
if let Some(output) = &output {
559-
let block_size = self.block_size();
560-
let min_output_size = input.len() + block_size - 1;
559+
let mut block_size = self.block_size();
560+
if block_size == 1 {
561+
block_size = 0;
562+
}
563+
let min_output_size = input.len() + block_size;
561564
assert!(
562565
output.len() >= min_output_size,
563566
"Output buffer size should be at least {} bytes.",
@@ -907,19 +910,19 @@ mod test {
907910
}
908911

909912
#[test]
910-
#[should_panic(expected = "Output buffer size should be at least 32 bytes.")]
913+
#[should_panic(expected = "Output buffer size should be at least 33 bytes.")]
911914
fn full_block_updates_aes_128() {
912915
output_buffer_too_small(Cipher::aes_128_cbc());
913916
}
914917

915918
#[test]
916-
#[should_panic(expected = "Output buffer size should be at least 32 bytes.")]
919+
#[should_panic(expected = "Output buffer size should be at least 33 bytes.")]
917920
fn full_block_updates_aes_256() {
918921
output_buffer_too_small(Cipher::aes_256_cbc());
919922
}
920923

921924
#[test]
922-
#[should_panic(expected = "Output buffer size should be at least 16 bytes.")]
925+
#[should_panic(expected = "Output buffer size should be at least 17 bytes.")]
923926
fn full_block_updates_3des() {
924927
output_buffer_too_small(Cipher::des_ede3_cbc());
925928
}

0 commit comments

Comments
 (0)