From 14a9cd5627982cb65587a1c1e62dd7853fe6904f Mon Sep 17 00:00:00 2001 From: radik878 Date: Thu, 12 Feb 2026 01:02:19 +0200 Subject: [PATCH] refactor: remove redundant heap allocation in OAEP decrypt_inner --- src/algorithms/oaep.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/algorithms/oaep.rs b/src/algorithms/oaep.rs index 6ac1f027..0b9693c5 100644 --- a/src/algorithms/oaep.rs +++ b/src/algorithms/oaep.rs @@ -162,9 +162,9 @@ where return Err(Error::Decryption); } - let (out, index) = res.unwrap(); + let index = res.unwrap(); - Ok(out[index as usize..].to_vec()) + Ok(em[index as usize..].to_vec()) } ///Decrypts OAEP padding. @@ -205,9 +205,9 @@ where return Err(Error::Decryption); } - let (out, index) = res.unwrap(); + let index = res.unwrap(); - Ok(out[index as usize..].to_vec()) + Ok(em[index as usize..].to_vec()) } /// Decrypts OAEP padding. It returns one or zero in valid that indicates whether the @@ -219,7 +219,7 @@ fn decrypt_inner( expected_p_hash: &[u8], k: usize, mut mgf: MGF, -) -> Result, u32)>> { +) -> Result> { if k < 11 { return Err(Error::Decryption); } @@ -256,8 +256,5 @@ fn decrypt_inner( let valid = first_byte_is_zero & hash_are_equal & !nonzero_before_one & !looking_for_index; - Ok(CtOption::new( - (em.to_vec(), index + 2 + (h_size * 2) as u32), - valid, - )) + Ok(CtOption::new(index + 2 + (h_size * 2) as u32, valid)) }