Skip to content

Commit

Permalink
feat(extensions/crypto): implement verify() for HMAC (#11387)
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy authored Aug 4, 2021
1 parent 2ac031d commit 87de8e8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 33 deletions.
10 changes: 10 additions & 0 deletions extensions/crypto/00_crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"verify": {
"RSASSA-PKCS1-v1_5": null,
"RSA-PSS": "RsaPssParams",
"HMAC": null,
},
"importKey": {
"HMAC": "HmacImportParams",
Expand Down Expand Up @@ -690,6 +691,15 @@
signature,
}, data);
}
case "HMAC": {
const hash = key[_algorithm].hash.name;
return await core.opAsync("op_crypto_verify_key", {
key: keyData,
algorithm: "HMAC",
hash,
signature,
}, data);
}
}

throw new TypeError("unreachable");
Expand Down
5 changes: 5 additions & 0 deletions extensions/crypto/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,11 @@ pub async fn op_crypto_verify_key(
.verify(padding, &hashed, &*args.signature)
.is_ok()
}
Algorithm::Hmac => {
let hash: HmacAlgorithm = args.hash.ok_or_else(not_supported)?.into();
let key = HmacKey::new(hash, &*args.key.data);
ring::hmac::verify(&key, data, &*args.signature).is_ok()
}
_ => return Err(type_error("Unsupported algorithm".to_string())),
};

Expand Down
34 changes: 1 addition & 33 deletions tools/wpt/expectation.json
Original file line number Diff line number Diff line change
Expand Up @@ -15303,39 +15303,7 @@
"generate wrong key step: HMAC with SHA-1 verifying with wrong algorithm name",
"generate wrong key step: HMAC with SHA-256 verifying with wrong algorithm name",
"generate wrong key step: HMAC with SHA-384 verifying with wrong algorithm name",
"generate wrong key step: HMAC with SHA-512 verifying with wrong algorithm name",
"HMAC with SHA-1 verification",
"HMAC with SHA-256 verification",
"HMAC with SHA-384 verification",
"HMAC with SHA-512 verification",
"HMAC with SHA-1 verification with altered signature after call",
"HMAC with SHA-256 verification with altered signature after call",
"HMAC with SHA-384 verification with altered signature after call",
"HMAC with SHA-512 verification with altered signature after call",
"HMAC with SHA-1 with altered plaintext after call",
"HMAC with SHA-256 with altered plaintext after call",
"HMAC with SHA-384 with altered plaintext after call",
"HMAC with SHA-512 with altered plaintext after call",
"HMAC with SHA-1 no verify usage",
"HMAC with SHA-256 no verify usage",
"HMAC with SHA-384 no verify usage",
"HMAC with SHA-512 no verify usage",
"HMAC with SHA-1 round trip",
"HMAC with SHA-256 round trip",
"HMAC with SHA-384 round trip",
"HMAC with SHA-512 round trip",
"HMAC with SHA-1 verification failure due to wrong plaintext",
"HMAC with SHA-256 verification failure due to wrong plaintext",
"HMAC with SHA-384 verification failure due to wrong plaintext",
"HMAC with SHA-512 verification failure due to wrong plaintext",
"HMAC with SHA-1 verification failure due to wrong signature",
"HMAC with SHA-256 verification failure due to wrong signature",
"HMAC with SHA-384 verification failure due to wrong signature",
"HMAC with SHA-512 verification failure due to wrong signature",
"HMAC with SHA-1 verification failure due to short signature",
"HMAC with SHA-256 verification failure due to short signature",
"HMAC with SHA-384 verification failure due to short signature",
"HMAC with SHA-512 verification failure due to short signature"
"generate wrong key step: HMAC with SHA-512 verifying with wrong algorithm name"
],
"rsa_pkcs.https.any.html": [
"importVectorKeys step: RSASSA-PKCS1-v1_5 with SHA-1 verification",
Expand Down

0 comments on commit 87de8e8

Please sign in to comment.