Skip to content

Commit

Permalink
Make MAC equality check more idiomatic
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFeickert committed Feb 5, 2024
1 parent 9ed0d7e commit 004d526
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions base_layer/key_manager/src/cipher_seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,16 @@ impl CipherSeed {
let expected_mac = Self::generate_mac(&birthday_bytes, entropy.reveal(), version, salt.as_ref(), &mac_key)?;

// Verify the MAC in constant time to avoid leaking data
if mac.ct_eq(&expected_mac).unwrap_u8() == 0 {
return Err(KeyManagerError::DecryptionFailed);
if mac.ct_eq(&expected_mac).into() {
Ok(Self {
version,
birthday,
entropy: Box::from(*entropy.reveal()),
salt,
})
} else {
Err(KeyManagerError::DecryptionFailed)
}

Ok(Self {
version,
birthday,
entropy: Box::from(*entropy.reveal()),
salt,
})
}

/// Encrypt or decrypt data using ChaCha20
Expand Down

0 comments on commit 004d526

Please sign in to comment.