test: update WPT for WebCryptoAPI to 03a1476844

PR-URL: https://github.com/nodejs/node/pull/63900
Backport-PR-URL: https://github.com/nodejs/node/pull/64629
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
Node.js GitHub Bot authored and Antoine du Hamel committed 2026-07-30 13:51:52 +02:00
1 parent 824ec11c05
commit 2d29628b5b
10 files changed
+457 -98

No files matched your search

+2 -2
View File
@@ -29,12 +29,12 @@ Last update:
- resources: https://github.com/web-platform-tests/wpt/tree/6a2f322376/resources
- streams: https://github.com/web-platform-tests/wpt/tree/f8f26a372f/streams
- url: https://github.com/web-platform-tests/wpt/tree/d4598eba09/url
- urlpattern: https://github.com/web-platform-tests/wpt/tree/23aac92784/urlpattern
- urlpattern: https://github.com/web-platform-tests/wpt/tree/11a459a2b1/urlpattern
- user-timing: https://github.com/web-platform-tests/wpt/tree/5ae85bf826/user-timing
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
- web-locks: https://github.com/web-platform-tests/wpt/tree/10a122a6bc/web-locks
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/97bbc7247a/WebCryptoAPI
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/03a1476844/WebCryptoAPI
- webidl: https://github.com/web-platform-tests/wpt/tree/63ca529a02/webidl
- webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/2f96fa1996/webidl/ecmascript-binding/es-exceptions
- webmessaging/broadcastchannel: https://github.com/web-platform-tests/wpt/tree/6495c91853/webmessaging/broadcastchannel
@@ -163,7 +163,7 @@ Object.keys(digestedData).forEach(function (alg) {
Object.keys(sourceData).forEach(function (size) {
promise_test(function (test) {
return crypto.subtle
.digest({ name: alg, length: length }, sourceData[size])
.digest({ name: alg, outputLength: length }, sourceData[size])
.then(function (result) {
assert_true(
equalBuffers(result, digestedData[alg][length][size]),
@@ -184,7 +184,7 @@ Object.keys(digestedData).forEach(function (alg) {
buffer[0] = sourceData[size][0];
return alg;
},
length
outputLength: length
}, buffer)
.then(function (result) {
assert_true(
@@ -197,7 +197,7 @@ Object.keys(digestedData).forEach(function (alg) {
promise_test(function (test) {
var buffer = new Uint8Array(sourceData[size]);
var promise = crypto.subtle
.digest({ name: alg, length: length }, buffer)
.digest({ name: alg, outputLength: length }, buffer)
.then(function (result) {
assert_true(
equalBuffers(result, digestedData[alg][length][size]),
@@ -218,7 +218,7 @@ Object.keys(digestedData).forEach(function (alg) {
buffer.buffer.transfer();
return alg;
},
length
outputLength: length
}, buffer)
.then(function (result) {
assert_true(
@@ -231,7 +231,7 @@ Object.keys(digestedData).forEach(function (alg) {
promise_test(function (test) {
var buffer = new Uint8Array(sourceData[size]);
var promise = crypto.subtle
.digest({ name: alg, length: length }, buffer)
.digest({ name: alg, outputLength: length }, buffer)
.then(function (result) {
assert_true(
equalBuffers(result, digestedData[alg][length][size]),
@@ -61,6 +61,42 @@ const algorithms = [
generateKeyParams: { name: "X25519" },
usages: ["deriveKey", "deriveBits"],
publicKeyUsages: []
},
{
name: "ML-DSA-44",
generateKeyParams: { name: "ML-DSA-44" },
usages: ["sign", "verify"],
publicKeyUsages: ["verify"]
},
{
name: "ML-DSA-65",
generateKeyParams: { name: "ML-DSA-65" },
usages: ["sign", "verify"],
publicKeyUsages: ["verify"]
},
{
name: "ML-DSA-87",
generateKeyParams: { name: "ML-DSA-87" },
usages: ["sign", "verify"],
publicKeyUsages: ["verify"]
},
{
name: "ML-KEM-512",
generateKeyParams: { name: "ML-KEM-512" },
usages: ["encapsulateBits", "encapsulateKey", "decapsulateBits", "decapsulateKey"],
publicKeyUsages: ["encapsulateBits", "encapsulateKey"]
},
{
name: "ML-KEM-768",
generateKeyParams: { name: "ML-KEM-768" },
usages: ["encapsulateBits", "encapsulateKey", "decapsulateBits", "decapsulateKey"],
publicKeyUsages: ["encapsulateBits", "encapsulateKey"]
},
{
name: "ML-KEM-1024",
generateKeyParams: { name: "ML-KEM-1024" },
usages: ["encapsulateBits", "encapsulateKey", "decapsulateBits", "decapsulateKey"],
publicKeyUsages: ["encapsulateBits", "encapsulateKey"]
}
];
@@ -59,6 +59,20 @@ function runTests(algorithmName) {
testFormat(format, algorithm, data, keyData.length * 8, usages, extractable);
});
testEmptyUsages(format, algorithm, data, keyData.length * 8, extractable);
// Verify the key data is copied only after the algorithm is
// normalized (per spec, "get a copy of the bytes held by the
// keyData parameter" follows "normalize an algorithm"). A
// getter on the algorithm name mutates the key data during
// normalization; the imported key must reflect the restored
// bytes. Checked for BufferSource formats (jwk key data is
// not a BufferSource) when the key is extractable, so the
// imported bytes can be read back and compared.
if (extractable && format !== "jwk") {
allValidUsages(vector.legalUsages).forEach(function(usages) {
testKeyDataAlteredDuringCall(format, algorithm, keyData, keyData.length * 8, usages);
});
}
});
});
@@ -111,6 +125,35 @@ function runTests(algorithmName) {
}, "Empty Usages: " + keySize.toString() + " bits " + parameterString(format, keyData, algorithm, extractable, usages));
}
// Test that importKey copies the key data only after the algorithm has been
// normalized. The spec normalizes the algorithm (which can run author
// getters on the algorithm dictionary) before getting a copy of the bytes
// held by the keyData parameter. Here a getter on the algorithm's name
// mutates the key data during normalization and then restores it, so a
// spec-compliant implementation imports the restored (original) bytes.
function testKeyDataAlteredDuringCall(format, algorithm, keyData, keySize, usages) {
promise_test(function(test) {
var alteredKeyData = copyBuffer(keyData);
alteredKeyData[0] = 255 - alteredKeyData[0];
var algorithmWithGetter = {
...algorithm,
get name() {
alteredKeyData[0] = keyData[0];
return algorithm.name;
}
};
return subtle.importKey(format, alteredKeyData, algorithmWithGetter, true, usages).
then(function(key) {
return subtle.exportKey(format, key);
}).
then(function(result) {
assert_true(equalBuffers(keyData, result), "Imported key reflects the key data as it was after normalization");
}, function(err) {
assert_unreached("Threw an unexpected error: " + err.toString());
});
}, "Key data altered during call: " + keySize.toString() + " bits " + parameterString(format, keyData, algorithm, true, usages));
}
// Helper methods follow:
+18 -18
View File
@@ -15,7 +15,7 @@ function run_test() {
var promise = importVectorKeys(vector, ["verify", "sign"])
.then(function(vector) {
promise_test(function(test) {
var algorithmParams = {name: vector.algorithm, length: vector.length};
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
if (vector.customization !== undefined) {
algorithmParams.customization = vector.customization;
}
@@ -48,7 +48,7 @@ function run_test() {
var signature = copyBuffer(vector.signature);
signature[0] = 255 - signature[0];
var algorithmParams = {
length: vector.length,
outputLength: vector.outputLength,
get name() {
signature[0] = vector.signature[0];
return vector.algorithm;
@@ -81,7 +81,7 @@ function run_test() {
.then(function(vector) {
promise_test(function(test) {
var signature = copyBuffer(vector.signature);
var algorithmParams = {name: vector.algorithm, length: vector.length};
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
if (vector.customization !== undefined) {
algorithmParams.customization = vector.customization;
}
@@ -115,7 +115,7 @@ function run_test() {
signature.buffer.transfer();
return vector.algorithm;
},
length: vector.length
outputLength: vector.outputLength
};
if (vector.customization !== undefined) {
algorithmParams.customization = vector.customization;
@@ -144,7 +144,7 @@ function run_test() {
.then(function(vector) {
promise_test(function(test) {
var signature = copyBuffer(vector.signature);
var algorithmParams = {name: vector.algorithm, length: vector.length};
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
if (vector.customization !== undefined) {
algorithmParams.customization = vector.customization;
}
@@ -175,7 +175,7 @@ function run_test() {
var plaintext = copyBuffer(vector.plaintext);
plaintext[0] = 255 - plaintext[0];
var algorithmParams = {
length: vector.length,
outputLength: vector.outputLength,
get name() {
plaintext[0] = vector.plaintext[0];
return vector.algorithm;
@@ -208,7 +208,7 @@ function run_test() {
.then(function(vector) {
promise_test(function(test) {
var plaintext = copyBuffer(vector.plaintext);
var algorithmParams = {name: vector.algorithm, length: vector.length};
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
if (vector.customization !== undefined) {
algorithmParams.customization = vector.customization;
}
@@ -242,7 +242,7 @@ function run_test() {
plaintext.buffer.transfer();
return vector.algorithm;
},
length: vector.length
outputLength: vector.outputLength
};
if (vector.customization !== undefined) {
algorithmParams.customization = vector.customization;
@@ -271,7 +271,7 @@ function run_test() {
.then(function(vector) {
promise_test(function(test) {
var plaintext = copyBuffer(vector.plaintext);
var algorithmParams = {name: vector.algorithm, length: vector.length};
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
if (vector.customization !== undefined) {
algorithmParams.customization = vector.customization;
}
@@ -301,7 +301,7 @@ function run_test() {
var promise = importVectorKeys(vector, ["sign"])
.then(function(vector) {
promise_test(function(test) {
var algorithmParams = {name: vector.algorithm, length: vector.length};
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
if (vector.customization !== undefined) {
algorithmParams.customization = vector.customization;
}
@@ -326,7 +326,7 @@ function run_test() {
var promise = importVectorKeys(vector, ["verify", "sign"])
.then(function(vectors) {
promise_test(function(test) {
var algorithmParams = {name: vector.algorithm, length: vector.length};
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
if (vector.customization !== undefined) {
algorithmParams.customization = vector.customization;
}
@@ -363,7 +363,7 @@ function run_test() {
return importVectorKeys(vector, ["verify", "sign"])
.then(function(vectors) {
promise_test(function(test) {
var algorithmParams = {name: vector.algorithm, length: vector.length};
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
if (vector.customization !== undefined) {
algorithmParams.customization = vector.customization;
}
@@ -401,7 +401,7 @@ function run_test() {
return importVectorKeys(vector, ["verify", "sign"])
.then(function(vector) {
promise_test(function(test) {
var algorithmParams = {name: vector.algorithm, length: vector.length};
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
if (vector.customization !== undefined) {
algorithmParams.customization = vector.customization;
}
@@ -438,7 +438,7 @@ function run_test() {
var plaintext = copyBuffer(vector.plaintext);
plaintext[0] = 255 - plaintext[0];
promise_test(function(test) {
var algorithmParams = {name: vector.algorithm, length: vector.length};
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
if (vector.customization !== undefined) {
algorithmParams.customization = vector.customization;
}
@@ -470,7 +470,7 @@ function run_test() {
var signature = copyBuffer(vector.signature);
signature[0] = 255 - signature[0];
promise_test(function(test) {
var algorithmParams = {name: vector.algorithm, length: vector.length};
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
if (vector.customization !== undefined) {
algorithmParams.customization = vector.customization;
}
@@ -501,7 +501,7 @@ function run_test() {
.then(function(vector) {
var signature = vector.signature.slice(1); // Drop first byte
promise_test(function(test) {
var algorithmParams = {name: vector.algorithm, length: vector.length};
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
if (vector.customization !== undefined) {
algorithmParams.customization = vector.customization;
}
@@ -531,8 +531,8 @@ function run_test() {
var promise = importVectorKeys(vector, ["verify", "sign"])
.then(function(vector) {
promise_test(function(test) {
var differentLength = vector.length === 256 ? 512 : 256;
var algorithmParams = {name: vector.algorithm, length: differentLength};
var differentLength = vector.outputLength === 256 ? 512 : 256;
var algorithmParams = {name: vector.algorithm, outputLength: differentLength};
if (vector.customization !== undefined) {
algorithmParams.customization = vector.customization;
}
+6 -6
View File
@@ -6,7 +6,7 @@ function getTestVectors() {
// Sample #1 - KMAC128, no customization
name: "KMAC128 with no customization",
algorithm: "KMAC128",
length: 256,
outputLength: 256,
keyBuffer: new Uint8Array([
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
@@ -25,7 +25,7 @@ function getTestVectors() {
// Sample #2 - KMAC128, with customization
name: "KMAC128 with customization",
algorithm: "KMAC128",
length: 256,
outputLength: 256,
keyBuffer: new Uint8Array([
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
@@ -47,7 +47,7 @@ function getTestVectors() {
// Sample #3 - KMAC128, large data, with customization
name: "KMAC128 with large data and customization",
algorithm: "KMAC128",
length: 256,
outputLength: 256,
keyBuffer: new Uint8Array([
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
@@ -69,7 +69,7 @@ function getTestVectors() {
// Sample #4 - KMAC256, with customization, 512-bit output
name: "KMAC256 with customization and 512-bit output",
algorithm: "KMAC256",
length: 512,
outputLength: 512,
keyBuffer: new Uint8Array([
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
@@ -94,7 +94,7 @@ function getTestVectors() {
// Sample #5 - KMAC256, large data, no customization, 512-bit output
name: "KMAC256 with large data and no customization",
algorithm: "KMAC256",
length: 512,
outputLength: 512,
keyBuffer: new Uint8Array([
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
@@ -116,7 +116,7 @@ function getTestVectors() {
// Sample #6 - KMAC256, large data, with customization, 512-bit output
name: "KMAC256 with large data and customization",
algorithm: "KMAC256",
length: 512,
outputLength: 512,
keyBuffer: new Uint8Array([
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
@@ -0,0 +1,160 @@
// META: title=WebCrypto API: supports method tests for algorithms in https://wicg.github.io/webcrypto-modern-algos/
// META: script=util/helpers.js
'use strict';
const modernAlgorithms = {
// Asymmetric algorithms
'ML-DSA-44': {
operations: ['generateKey', 'importKey', 'sign', 'verify', 'getPublicKey'],
},
'ML-DSA-65': {
operations: ['generateKey', 'importKey', 'sign', 'verify', 'getPublicKey'],
},
'ML-DSA-87': {
operations: ['generateKey', 'importKey', 'sign', 'verify', 'getPublicKey'],
},
'ML-KEM-512': {
operations: [
'generateKey', 'importKey', 'encapsulateKey', 'encapsulateBits',
'decapsulateKey', 'decapsulateBits', 'getPublicKey'
],
},
'ML-KEM-768': {
operations: [
'generateKey', 'importKey', 'encapsulateKey', 'encapsulateBits',
'decapsulateKey', 'decapsulateBits', 'getPublicKey'
],
},
'ML-KEM-1024': {
operations: [
'generateKey', 'importKey', 'encapsulateKey', 'encapsulateBits',
'decapsulateKey', 'decapsulateBits', 'getPublicKey'
],
},
// Symmetric algorithms
'ChaCha20-Poly1305': {
operations: ['generateKey', 'importKey', 'encrypt', 'decrypt'],
encryptParams: {name: 'ChaCha20-Poly1305', iv: new Uint8Array(12)},
},
};
const operations = [
'generateKey',
'importKey',
'sign',
'verify',
'encrypt',
'decrypt',
'deriveBits',
'digest',
'encapsulateKey',
'encapsulateBits',
'decapsulateKey',
'decapsulateBits',
'getPublicKey',
];
// Test that supports method exists and is a static method
test(() => {
assert_true(
typeof SubtleCrypto.supports === 'function',
'SubtleCrypto.supports should be a function');
}, 'SubtleCrypto.supports method exists');
// Test standard WebCrypto algorithms for requested operations
for (const [algorithmName, algorithmInfo] of Object.entries(modernAlgorithms)) {
for (const operation of operations) {
promise_test(async (t) => {
const isSupported = algorithmInfo.operations.includes(operation);
// Use appropriate algorithm parameters for each operation
let algorithm;
let lengthOrAdditionalAlgorithm;
switch (operation) {
case 'generateKey':
algorithm = algorithmInfo.keyGenParams || algorithmName;
break;
case 'importKey':
algorithm = algorithmInfo.importParams || algorithmName;
break;
case 'sign':
case 'verify':
algorithm = algorithmInfo.signParams || algorithmName;
break;
case 'encrypt':
case 'decrypt':
algorithm = algorithmInfo.encryptParams || algorithmName;
break;
case 'deriveBits':
algorithm = algorithmInfo.deriveBitsParams || algorithmName;
if (algorithm?.public instanceof Promise) {
algorithm.public = (await algorithm.public).publicKey;
}
if (algorithmName === 'PBKDF2' || algorithmName === 'HKDF') {
lengthOrAdditionalAlgorithm = 256;
}
break;
case 'digest':
algorithm = algorithmName;
break;
case 'encapsulateKey':
case 'encapsulateBits':
case 'decapsulateKey':
case 'decapsulateBits':
algorithm = algorithmName;
if (operation === 'encapsulateKey' || operation === 'decapsulateKey') {
lengthOrAdditionalAlgorithm = { name: 'AES-GCM', length: 256 };
}
break;
default:
algorithm = algorithmName;
}
const result = SubtleCrypto.supports(operation, algorithm, lengthOrAdditionalAlgorithm);
if (isSupported) {
assert_true(result, `${algorithmName} should support ${operation}`);
} else {
assert_false(
result, `${algorithmName} should not support ${operation}`);
}
}, `supports(${operation}, ${algorithmName})`);
}
}
// Test some algorithm objects with valid parameters
test(() => {
assert_true(
SubtleCrypto.supports('encrypt', {
name: 'ChaCha20-Poly1305',
iv: new Uint8Array(12),
tagLength: 128,
}),
'ChaCha20-Poly1305 encrypt with valid tagLength');
}, 'supports returns true for algorithm objects with valid parameters');
// Test some algorithm objects with invalid parameters
test(() => {
assert_false(
SubtleCrypto.supports('encrypt', {
name: 'ChaCha20-Poly1305',
iv: new Uint8Array(12),
tagLength: 100,
}),
'ChaCha20-Poly1305 encrypt with invalid tagLength');
assert_false(
SubtleCrypto.supports('encrypt', {
name: 'ChaCha20-Poly1305',
iv: new Uint8Array(10),
tagLength: 128,
}),
'ChaCha20-Poly1305 encrypt with invalid iv');
}, 'supports returns false for algorithm objects with invalid parameters');
done();
@@ -6,7 +6,7 @@
const standardAlgorithms = {
// Asymmetric algorithms
'RSASSA-PKCS1-v1_5': {
operations: ['generateKey', 'importKey', 'sign', 'verify'],
operations: ['generateKey', 'importKey', 'sign', 'verify', 'getPublicKey'],
keyGenParams: {
name: 'RSASSA-PKCS1-v1_5',
modulusLength: 2048,
@@ -17,7 +17,7 @@ const standardAlgorithms = {
signParams: { name: 'RSASSA-PKCS1-v1_5' },
},
'RSA-PSS': {
operations: ['generateKey', 'importKey', 'sign', 'verify'],
operations: ['generateKey', 'importKey', 'sign', 'verify', 'getPublicKey'],
keyGenParams: {
name: 'RSA-PSS',
modulusLength: 2048,
@@ -28,7 +28,7 @@ const standardAlgorithms = {
signParams: { name: 'RSA-PSS', saltLength: 32 },
},
'RSA-OAEP': {
operations: ['generateKey', 'importKey', 'encrypt', 'decrypt'],
operations: ['generateKey', 'importKey', 'encrypt', 'decrypt', 'getPublicKey'],
keyGenParams: {
name: 'RSA-OAEP',
modulusLength: 2048,
@@ -39,13 +39,13 @@ const standardAlgorithms = {
encryptParams: { name: 'RSA-OAEP' },
},
ECDSA: {
operations: ['generateKey', 'importKey', 'sign', 'verify'],
operations: ['generateKey', 'importKey', 'sign', 'verify', 'getPublicKey'],
keyGenParams: { name: 'ECDSA', namedCurve: 'P-256' },
importParams: { name: 'ECDSA', namedCurve: 'P-256' },
signParams: { name: 'ECDSA', hash: 'SHA-256' },
},
ECDH: {
operations: ['generateKey', 'importKey', 'deriveBits'],
operations: ['generateKey', 'importKey', 'deriveBits', 'getPublicKey'],
keyGenParams: { name: 'ECDH', namedCurve: 'P-256' },
importParams: { name: 'ECDH', namedCurve: 'P-256' },
deriveBitsParams: {
@@ -58,12 +58,12 @@ const standardAlgorithms = {
},
},
Ed25519: {
operations: ['generateKey', 'importKey', 'sign', 'verify'],
operations: ['generateKey', 'importKey', 'sign', 'verify', 'getPublicKey'],
keyGenParams: null,
signParams: { name: 'Ed25519' },
},
X25519: {
operations: ['generateKey', 'importKey', 'deriveBits'],
operations: ['generateKey', 'importKey', 'deriveBits', 'getPublicKey'],
keyGenParams: null,
deriveBitsParams: {
name: 'X25519',
@@ -152,6 +152,7 @@ const operations = [
'decrypt',
'deriveBits',
'digest',
'getPublicKey',
];
// Test that supports method exists and is a static method
@@ -268,6 +269,137 @@ test(() => {
}),
'Invalid hash parameter should return false'
);
assert_false(
SubtleCrypto.supports(
'encrypt', {name: 'AES-CBC', iv: new Uint8Array(10)}),
'Invalid IV for AES-CBC should return false');
assert_false(
SubtleCrypto.supports('encrypt', {
name: 'AES-CTR',
counter: new Uint8Array(10),
length: 128,
}),
'Invalid IV for AES-CTR should return false');
assert_false(
SubtleCrypto.supports('encrypt', {
name: 'AES-CTR',
counter: new Uint8Array(16),
length: 0,
}),
'Invalid length=0 for AES-CTR should return false');
assert_false(
SubtleCrypto.supports('encrypt', {
name: 'AES-CTR',
counter: new Uint8Array(16),
length: 129,
}),
'Invalid length=129 for AES-CTR should return false');
assert_false(
SubtleCrypto.supports('encrypt', {
name: 'AES-GCM',
iv: new Uint8Array(16),
tagLength: 100,
}),
'Invalid tag length for AES-GCM should return false');
assert_false(
SubtleCrypto.supports('generateKey', {name: 'ECDH', namedCurve: 'P-51'}),
'Invalid curve for ECDH should return false');
assert_false(
SubtleCrypto.supports(
'deriveBits', {
name: 'HKDF',
hash: 'SHA-25',
salt: new Uint8Array(16),
info: new Uint8Array(0),
},
8),
'Invalid hash for HKDF should return false');
assert_false(
SubtleCrypto.supports(
'deriveBits', {
name: 'HKDF',
hash: 'SHA-256',
salt: new Uint8Array(16),
info: new Uint8Array(0),
},
11),
'Invalid length for HKDF should return false');
assert_false(
SubtleCrypto.supports(
'deriveBits', {
name: 'HKDF',
hash: 'SHA-256',
salt: new Uint8Array(16),
info: new Uint8Array(0),
}),
'null length for HKDF should return false');
assert_false(
SubtleCrypto.supports('generateKey', {
name: 'HMAC',
hash: 'SHA-25',
}),
'Invalid hash for HMAC should return false');
assert_false(
SubtleCrypto.supports('generateKey', {
name: 'HMAC',
hash: 'SHA-256',
length: 0,
}),
'Invalid length for HMAC should return false');
assert_false(
SubtleCrypto.supports(
'deriveBits', {
name: 'PBKDF2',
hash: 'SHA-25',
salt: new Uint8Array(16),
iterations: 100000,
},
8),
'Invalid hash for PBKDF2 should return false');
assert_false(
SubtleCrypto.supports(
'deriveBits', {
name: 'PBKDF2',
hash: 'SHA-256',
salt: new Uint8Array(16),
iterations: 100000,
},
11),
'Invalid length for PBKDF2 should return false');
assert_false(
SubtleCrypto.supports(
'deriveBits', {
name: 'PBKDF2',
hash: 'SHA-256',
salt: new Uint8Array(16),
iterations: 100000,
}),
'null length for PBKDF2 should return false');
assert_false(
SubtleCrypto.supports('generateKey', {
name: 'RSASSA-PKCS1-v1_5',
modulusLength: 2048,
publicExponent: new Uint8Array([1, 0, 1]),
hash: 'SHA-56',
}),
'Invalid hash for RSA PKCS1 should return false');
assert_false(
SubtleCrypto.supports('generateKey', {
name: 'RSA-PSS',
modulusLength: 2048,
publicExponent: new Uint8Array([1, 0, 1]),
hash: 'SHA-56',
}),
'Invalid hash for RSA PSS should return false');
assert_false(
SubtleCrypto.supports('generateKey', {
name: 'RSA-OAEP',
modulusLength: 2048,
publicExponent: new Uint8Array([1, 0, 1]),
hash: 'SHA-26',
}),
'Invalid hash for RSA OAEP should return false');
}, 'supports returns false for algorithm objects with invalid parameters');
// Test some specific combinations that should work
@@ -394,4 +526,49 @@ test(() => {
);
}, 'Invalid algorithm and operation combinations fail');
// Test supports for deriveKey op
test(() => {
assert_true(
SubtleCrypto.supports(
'deriveKey', {
name: 'HKDF',
hash: 'SHA-256',
salt: new Uint8Array(16),
info: new Uint8Array(0),
},
{name: 'HMAC', hash: 'SHA-256'}),
'deriveKey HKDF-HMAC should pass');
}, 'deriveKey tests');
promise_test(async (t) => {
let keypair = await crypto.subtle.generateKey(
{
name: 'X25519',
},
false, ['deriveKey', 'deriveBits']);
assert_true(
SubtleCrypto.supports(
'deriveKey', {
name: 'X25519',
public: keypair.publicKey,
},
{name: 'AES-GCM', length: 256}),
'deriveKey X25519-AES-GCM-256 should pass');
assert_false(
SubtleCrypto.supports(
'deriveKey', {
name: 'X25519',
public: keypair.publicKey,
},
{name: 'HMAC', hash: 'SHA-256'}),
'deriveKey X25519-HMAC-SHA-256 should fail');
}, 'deriveKey promise tests');
done();
+1 -1
View File
@@ -96,7 +96,7 @@
"path": "web-locks"
},
"WebCryptoAPI": {
"commit": "97bbc7247a16231f4744a47a1d9b3d29633d5292",
"commit": "03a14768441c1ce2a31678d0dc080e81dc449d0a",
"path": "WebCryptoAPI"
},
"webidl": {
+2 -59
View File
@@ -62,6 +62,7 @@ if (!hasOpenSSL(3, 5) && !process.features.openssl_is_boringssl) {
'sign_verify/mldsa.tentative.https.any.js');
skipSubtests(
['getPublicKey.tentative.https.any.js', /ml-(?:kem|dsa)/i],
['supports-modern.tentative.https.any.js', /ml-(?:kem|dsa)/i]);
}
@@ -88,6 +89,7 @@ if (process.features.openssl_is_boringssl) {
['encap_decap/encap_decap_keys.tentative.https.any.js', /ml-kem-512/i],
['generateKey/failures_ML-KEM.tentative.https.any.js', /ml-kem-512/i],
['generateKey/successes_ML-KEM.tentative.https.any.js', /ml-kem-512/i],
['getPublicKey.tentative.https.any.js', /(?:ed448|x448|ml-kem-512)/i],
['import_export/ML-KEM_importKey.tentative.https.any.js', /ml-kem-512/i],
['serialization/mlkem.tentative.https.any.js', /ml-kem-512/i],
['supports-modern.tentative.https.any.js', /ml-kem-512/i]);
@@ -104,53 +106,6 @@ function assertNoOverlap(fileSkips, subtestSkips) {
assertNoOverlap(conditionalFileSkips, conditionalSubtestSkips);
const cshakeExpectedFailures = ['cSHAKE128', 'cSHAKE256'].flatMap((algorithm) => {
return [0, 256, 384, 512].flatMap((length) => {
return ['empty', 'short', 'medium'].flatMap((size) => {
const base = `${algorithm} with ${length} bit output and ${size} source data`;
return [
base,
].concat(size !== 'empty' ? [
`${base} and altered buffer after call`,
`${base} and altered buffer during call`,
`${base} and transferred buffer after call`,
`${base} and transferred buffer during call`,
] : []);
});
});
});
const kmacVectorNames = [
'KMAC128 with no customization',
'KMAC128 with customization',
'KMAC128 with large data and customization',
'KMAC256 with customization and 512-bit output',
'KMAC256 with large data and no customization',
'KMAC256 with large data and customization',
];
const kmacExpectedFailures = kmacVectorNames.flatMap((name) => {
return [
`${name} verification`,
`${name} verification with transferred signature during call`,
`${name} verification with transferred signature after call`,
`${name} verification with altered signature during call`,
`${name} verification with altered signature after call`,
`${name} with altered plaintext during call`,
`${name} with altered plaintext after call`,
`${name} with transferred plaintext during call`,
`${name} with transferred plaintext after call`,
`${name} no verify usage`,
`${name} round trip`,
`${name} verification failure due to wrong plaintext`,
`${name} verification failure due to wrong signature`,
`${name} verification failure due to short signature`,
`${name} verification failure due to wrong length parameter`,
`${name} signing with wrong algorithm name`,
`${name} verifying with wrong algorithm name`,
];
});
module.exports = {
...conditionalFileSkips,
...conditionalSubtestSkips,
@@ -191,16 +146,4 @@ module.exports = {
],
},
},
'digest/cshake.tentative.https.any.js': conditionalFileSkips['digest/cshake.tentative.https.any.js'] ?? {
'fail': {
'note': 'WPT still uses CShakeParams.length; implementation moved to CShakeParams.outputLength',
'expected': cshakeExpectedFailures,
},
},
'sign_verify/kmac.tentative.https.any.js': conditionalFileSkips['sign_verify/kmac.tentative.https.any.js'] ?? {
'fail': {
'note': 'WPT still uses KmacParams.length; implementation moved to KmacParams.outputLength',
'expected': kmacExpectedFailures,
},
},
};