Remove old legnth check, as the new one using an internal idx state and checked_add checks for the same limitations. Remove last iteration check to simplify the loop
@@ -112,34 +112,22 @@ pub fn derive_key(
if iterations < 1 {
return Err(UnknownCryptoError);
}
- if dk_out.len() > 274_877_906_880 {
- return Err(UnknownCryptoError);
- }
if dk_out.is_empty() {
return Err(UnknownCryptoError);
}
let mut hmac = hmac::init(password);
- let dk_len = dk_out.len();
for (idx, dk_block) in dk_out.chunks_mut(HLEN).enumerate() {
let block_len = dk_block.len();
- assert!(block_len <= dk_len);
-
let block_idx = (1_u32).checked_add(idx as u32);
if block_idx.is_some() {
function_f(salt, iterations, block_idx.unwrap(), dk_block, block_len, &mut hmac);
+ hmac.reset();
} else {
return Err(UnknownCryptoError);
}
-
- // Check if it's the last iteration, if yes don't process anything
- if block_len < HLEN || (block_len * (idx + 1) == dk_len) {
- break;
- } else {
- hmac.reset();
- }
}
Ok(())
