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

WebCryptoAPI: add default generated HMAC key length tests #36348

Merged
merged 1 commit into from Oct 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 25 additions & 6 deletions WebCryptoAPI/util/helpers.js
Expand Up @@ -110,7 +110,22 @@ function assert_goodCryptoKey(key, algorithm, extractable, usages, kind) {
assert_equals(key.extractable, extractable, "Extractability is correct");

assert_equals(key.algorithm.name, registeredAlgorithmName, "Correct algorithm name");
assert_equals(key.algorithm.length, algorithm.length, "Correct length");
if (key.algorithm.name.toUpperCase() === "HMAC" && algorithm.length === undefined) {
switch (key.algorithm.hash.name.toUpperCase()) {
case 'SHA-1':
case 'SHA-256':
assert_equals(key.algorithm.length, 512, "Correct length");
break;
case 'SHA-384':
case 'SHA-512':
assert_equals(key.algorithm.length, 1024, "Correct length");
break;
default:
assert_unreached("Unrecognized hash");
}
} else {
assert_equals(key.algorithm.length, algorithm.length, "Correct length");
}
if (["HMAC", "RSASSA-PKCS1-v1_5", "RSA-PSS"].includes(registeredAlgorithmName)) {
assert_equals(key.algorithm.hash.name.toUpperCase(), algorithm.hash.toUpperCase(), "Correct hash function");
}
Expand Down Expand Up @@ -166,12 +181,16 @@ function allAlgorithmSpecifiersFor(algorithmName) {
});
} else if (algorithmName.toUpperCase() === "HMAC") {
[
{name: "SHA-1", length: 160},
{name: "SHA-256", length: 256},
{name: "SHA-384", length: 384},
{name: "SHA-512", length: 512}
{hash: "SHA-1", length: 160},
{hash: "SHA-256", length: 256},
{hash: "SHA-384", length: 384},
{hash: "SHA-512", length: 512},
{hash: "SHA-1"},
{hash: "SHA-256"},
{hash: "SHA-384"},
{hash: "SHA-512"},
].forEach(function(hashAlgorithm) {
results.push({name: algorithmName, hash: hashAlgorithm.name, length: hashAlgorithm.length});
results.push({name: algorithmName, ...hashAlgorithm});
});
} else if (algorithmName.toUpperCase().substring(0, 3) === "RSA") {
hashes.forEach(function(hashName) {
Expand Down