Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make MAC equality check more idiomatic #6123

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading