Skip to content

Commit 83140c5

Browse files
authored
Merge pull request #2088 from alex/block-size-off-by-one
Correct off-by-one in minimum output buffer size computation
2 parents d009660 + e097a02 commit 83140c5

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

openssl/src/cipher_ctx.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,8 @@ impl CipherCtxRef {
556556
output: Option<&mut [u8]>,
557557
) -> Result<usize, ErrorStack> {
558558
if let Some(output) = &output {
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;
559+
let block_size = self.block_size();
560+
let min_output_size = input.len() + block_size - 1;
564561
assert!(
565562
output.len() >= min_output_size,
566563
"Output buffer size should be at least {} bytes.",
@@ -910,19 +907,19 @@ mod test {
910907
}
911908

912909
#[test]
913-
#[should_panic(expected = "Output buffer size should be at least 33 bytes.")]
910+
#[should_panic(expected = "Output buffer size should be at least 32 bytes.")]
914911
fn full_block_updates_aes_128() {
915912
output_buffer_too_small(Cipher::aes_128_cbc());
916913
}
917914

918915
#[test]
919-
#[should_panic(expected = "Output buffer size should be at least 33 bytes.")]
916+
#[should_panic(expected = "Output buffer size should be at least 32 bytes.")]
920917
fn full_block_updates_aes_256() {
921918
output_buffer_too_small(Cipher::aes_256_cbc());
922919
}
923920

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

0 commit comments

Comments
 (0)