diff --git a/mm2src/crypto/src/key_derivation.rs b/mm2src/crypto/src/key_derivation.rs index 74500c3d52..876852ff75 100644 --- a/mm2src/crypto/src/key_derivation.rs +++ b/mm2src/crypto/src/key_derivation.rs @@ -133,7 +133,12 @@ pub(crate) fn derive_keys_for_mnemonic( /// Splits a path into its components and derives a key for each component. fn derive_key_from_path(master_node: &[u8], path: &str) -> MmResult<[u8; 32], KeyDerivationError> { + if master_node.len() < 64 { + return MmError::err(KeyDerivationError::InvalidKeyLength); + } + let mut current_key_material = master_node.to_vec(); + for segment in path.split('/').filter(|s| !s.is_empty()) { let mut mac = HmacSha512::new_from_slice(¤t_key_material[..32]) .map_err(|_| KeyDerivationError::HmacInitialization)?;