Skip to content

Commit fc095b6

Browse files
authored
Merge commit from fork
security: make HS256 validation constant-time
2 parents 49583c1 + 381bc66 commit fc095b6

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

httpsig/src/crypto/symmetric.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ impl super::SigningKey for SharedKey {
5353
impl super::VerifyingKey for SharedKey {
5454
/// Verify the mac
5555
fn verify(&self, data: &[u8], expected_mac: &[u8]) -> HttpSigResult<()> {
56-
use super::SigningKey;
57-
debug!("Verify HmacSha256");
58-
let calcurated_mac = self.sign(data)?;
59-
if calcurated_mac == expected_mac {
60-
Ok(())
61-
} else {
62-
Err(HttpSigError::InvalidSignature("Invalid MAC".to_string()))
56+
match self {
57+
SharedKey::HmacSha256(key) => {
58+
debug!("Verify HmacSha256");
59+
let mut mac = HmacSha256::new_from_slice(key).unwrap();
60+
mac.update(data);
61+
mac.verify_slice(expected_mac)
62+
.map_err(|_| HttpSigError::InvalidSignature("Invalid MAC".to_string()))
63+
}
6364
}
6465
}
6566

0 commit comments

Comments
 (0)