Skip to content

Commit 5a356ac

Browse files
nodejs-github-botaduh95
authored andcommitted
test: update WPT for WebCryptoAPI to 03a1476844
PR-URL: #63900 Backport-PR-URL: #64629 Reviewed-By: Antoine du Hamel <[email protected]>
1 parent b88f7b4 commit 5a356ac

10 files changed

Lines changed: 457 additions & 98 deletions

File tree

test/fixtures/wpt/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ Last update:
2929
- resources: https://github.com/web-platform-tests/wpt/tree/6a2f322376/resources
3030
- streams: https://github.com/web-platform-tests/wpt/tree/f8f26a372f/streams
3131
- url: https://github.com/web-platform-tests/wpt/tree/d4598eba09/url
32-
- urlpattern: https://github.com/web-platform-tests/wpt/tree/23aac92784/urlpattern
32+
- urlpattern: https://github.com/web-platform-tests/wpt/tree/11a459a2b1/urlpattern
3333
- user-timing: https://github.com/web-platform-tests/wpt/tree/5ae85bf826/user-timing
3434
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi
3535
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
3636
- web-locks: https://github.com/web-platform-tests/wpt/tree/10a122a6bc/web-locks
37-
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/97bbc7247a/WebCryptoAPI
37+
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/03a1476844/WebCryptoAPI
3838
- webidl: https://github.com/web-platform-tests/wpt/tree/63ca529a02/webidl
3939
- webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/2f96fa1996/webidl/ecmascript-binding/es-exceptions
4040
- webmessaging/broadcastchannel: https://github.com/web-platform-tests/wpt/tree/6495c91853/webmessaging/broadcastchannel

test/fixtures/wpt/WebCryptoAPI/digest/cshake.tentative.https.any.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Object.keys(digestedData).forEach(function (alg) {
163163
Object.keys(sourceData).forEach(function (size) {
164164
promise_test(function (test) {
165165
return crypto.subtle
166-
.digest({ name: alg, length: length }, sourceData[size])
166+
.digest({ name: alg, outputLength: length }, sourceData[size])
167167
.then(function (result) {
168168
assert_true(
169169
equalBuffers(result, digestedData[alg][length][size]),
@@ -184,7 +184,7 @@ Object.keys(digestedData).forEach(function (alg) {
184184
buffer[0] = sourceData[size][0];
185185
return alg;
186186
},
187-
length
187+
outputLength: length
188188
}, buffer)
189189
.then(function (result) {
190190
assert_true(
@@ -197,7 +197,7 @@ Object.keys(digestedData).forEach(function (alg) {
197197
promise_test(function (test) {
198198
var buffer = new Uint8Array(sourceData[size]);
199199
var promise = crypto.subtle
200-
.digest({ name: alg, length: length }, buffer)
200+
.digest({ name: alg, outputLength: length }, buffer)
201201
.then(function (result) {
202202
assert_true(
203203
equalBuffers(result, digestedData[alg][length][size]),
@@ -218,7 +218,7 @@ Object.keys(digestedData).forEach(function (alg) {
218218
buffer.buffer.transfer();
219219
return alg;
220220
},
221-
length
221+
outputLength: length
222222
}, buffer)
223223
.then(function (result) {
224224
assert_true(
@@ -231,7 +231,7 @@ Object.keys(digestedData).forEach(function (alg) {
231231
promise_test(function (test) {
232232
var buffer = new Uint8Array(sourceData[size]);
233233
var promise = crypto.subtle
234-
.digest({ name: alg, length: length }, buffer)
234+
.digest({ name: alg, outputLength: length }, buffer)
235235
.then(function (result) {
236236
assert_true(
237237
equalBuffers(result, digestedData[alg][length][size]),

test/fixtures/wpt/WebCryptoAPI/getPublicKey.tentative.https.any.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,42 @@ const algorithms = [
6161
generateKeyParams: { name: "X25519" },
6262
usages: ["deriveKey", "deriveBits"],
6363
publicKeyUsages: []
64+
},
65+
{
66+
name: "ML-DSA-44",
67+
generateKeyParams: { name: "ML-DSA-44" },
68+
usages: ["sign", "verify"],
69+
publicKeyUsages: ["verify"]
70+
},
71+
{
72+
name: "ML-DSA-65",
73+
generateKeyParams: { name: "ML-DSA-65" },
74+
usages: ["sign", "verify"],
75+
publicKeyUsages: ["verify"]
76+
},
77+
{
78+
name: "ML-DSA-87",
79+
generateKeyParams: { name: "ML-DSA-87" },
80+
usages: ["sign", "verify"],
81+
publicKeyUsages: ["verify"]
82+
},
83+
{
84+
name: "ML-KEM-512",
85+
generateKeyParams: { name: "ML-KEM-512" },
86+
usages: ["encapsulateBits", "encapsulateKey", "decapsulateBits", "decapsulateKey"],
87+
publicKeyUsages: ["encapsulateBits", "encapsulateKey"]
88+
},
89+
{
90+
name: "ML-KEM-768",
91+
generateKeyParams: { name: "ML-KEM-768" },
92+
usages: ["encapsulateBits", "encapsulateKey", "decapsulateBits", "decapsulateKey"],
93+
publicKeyUsages: ["encapsulateBits", "encapsulateKey"]
94+
},
95+
{
96+
name: "ML-KEM-1024",
97+
generateKeyParams: { name: "ML-KEM-1024" },
98+
usages: ["encapsulateBits", "encapsulateKey", "decapsulateBits", "decapsulateKey"],
99+
publicKeyUsages: ["encapsulateBits", "encapsulateKey"]
64100
}
65101
];
66102

test/fixtures/wpt/WebCryptoAPI/import_export/symmetric_importKey.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ function runTests(algorithmName) {
5959
testFormat(format, algorithm, data, keyData.length * 8, usages, extractable);
6060
});
6161
testEmptyUsages(format, algorithm, data, keyData.length * 8, extractable);
62+
63+
// Verify the key data is copied only after the algorithm is
64+
// normalized (per spec, "get a copy of the bytes held by the
65+
// keyData parameter" follows "normalize an algorithm"). A
66+
// getter on the algorithm name mutates the key data during
67+
// normalization; the imported key must reflect the restored
68+
// bytes. Checked for BufferSource formats (jwk key data is
69+
// not a BufferSource) when the key is extractable, so the
70+
// imported bytes can be read back and compared.
71+
if (extractable && format !== "jwk") {
72+
allValidUsages(vector.legalUsages).forEach(function(usages) {
73+
testKeyDataAlteredDuringCall(format, algorithm, keyData, keyData.length * 8, usages);
74+
});
75+
}
6276
});
6377
});
6478

@@ -111,6 +125,35 @@ function runTests(algorithmName) {
111125
}, "Empty Usages: " + keySize.toString() + " bits " + parameterString(format, keyData, algorithm, extractable, usages));
112126
}
113127

128+
// Test that importKey copies the key data only after the algorithm has been
129+
// normalized. The spec normalizes the algorithm (which can run author
130+
// getters on the algorithm dictionary) before getting a copy of the bytes
131+
// held by the keyData parameter. Here a getter on the algorithm's name
132+
// mutates the key data during normalization and then restores it, so a
133+
// spec-compliant implementation imports the restored (original) bytes.
134+
function testKeyDataAlteredDuringCall(format, algorithm, keyData, keySize, usages) {
135+
promise_test(function(test) {
136+
var alteredKeyData = copyBuffer(keyData);
137+
alteredKeyData[0] = 255 - alteredKeyData[0];
138+
var algorithmWithGetter = {
139+
...algorithm,
140+
get name() {
141+
alteredKeyData[0] = keyData[0];
142+
return algorithm.name;
143+
}
144+
};
145+
return subtle.importKey(format, alteredKeyData, algorithmWithGetter, true, usages).
146+
then(function(key) {
147+
return subtle.exportKey(format, key);
148+
}).
149+
then(function(result) {
150+
assert_true(equalBuffers(keyData, result), "Imported key reflects the key data as it was after normalization");
151+
}, function(err) {
152+
assert_unreached("Threw an unexpected error: " + err.toString());
153+
});
154+
}, "Key data altered during call: " + keySize.toString() + " bits " + parameterString(format, keyData, algorithm, true, usages));
155+
}
156+
114157

115158

116159
// Helper methods follow:

test/fixtures/wpt/WebCryptoAPI/sign_verify/kmac.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function run_test() {
1515
var promise = importVectorKeys(vector, ["verify", "sign"])
1616
.then(function(vector) {
1717
promise_test(function(test) {
18-
var algorithmParams = {name: vector.algorithm, length: vector.length};
18+
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
1919
if (vector.customization !== undefined) {
2020
algorithmParams.customization = vector.customization;
2121
}
@@ -48,7 +48,7 @@ function run_test() {
4848
var signature = copyBuffer(vector.signature);
4949
signature[0] = 255 - signature[0];
5050
var algorithmParams = {
51-
length: vector.length,
51+
outputLength: vector.outputLength,
5252
get name() {
5353
signature[0] = vector.signature[0];
5454
return vector.algorithm;
@@ -81,7 +81,7 @@ function run_test() {
8181
.then(function(vector) {
8282
promise_test(function(test) {
8383
var signature = copyBuffer(vector.signature);
84-
var algorithmParams = {name: vector.algorithm, length: vector.length};
84+
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
8585
if (vector.customization !== undefined) {
8686
algorithmParams.customization = vector.customization;
8787
}
@@ -115,7 +115,7 @@ function run_test() {
115115
signature.buffer.transfer();
116116
return vector.algorithm;
117117
},
118-
length: vector.length
118+
outputLength: vector.outputLength
119119
};
120120
if (vector.customization !== undefined) {
121121
algorithmParams.customization = vector.customization;
@@ -144,7 +144,7 @@ function run_test() {
144144
.then(function(vector) {
145145
promise_test(function(test) {
146146
var signature = copyBuffer(vector.signature);
147-
var algorithmParams = {name: vector.algorithm, length: vector.length};
147+
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
148148
if (vector.customization !== undefined) {
149149
algorithmParams.customization = vector.customization;
150150
}
@@ -175,7 +175,7 @@ function run_test() {
175175
var plaintext = copyBuffer(vector.plaintext);
176176
plaintext[0] = 255 - plaintext[0];
177177
var algorithmParams = {
178-
length: vector.length,
178+
outputLength: vector.outputLength,
179179
get name() {
180180
plaintext[0] = vector.plaintext[0];
181181
return vector.algorithm;
@@ -208,7 +208,7 @@ function run_test() {
208208
.then(function(vector) {
209209
promise_test(function(test) {
210210
var plaintext = copyBuffer(vector.plaintext);
211-
var algorithmParams = {name: vector.algorithm, length: vector.length};
211+
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
212212
if (vector.customization !== undefined) {
213213
algorithmParams.customization = vector.customization;
214214
}
@@ -242,7 +242,7 @@ function run_test() {
242242
plaintext.buffer.transfer();
243243
return vector.algorithm;
244244
},
245-
length: vector.length
245+
outputLength: vector.outputLength
246246
};
247247
if (vector.customization !== undefined) {
248248
algorithmParams.customization = vector.customization;
@@ -271,7 +271,7 @@ function run_test() {
271271
.then(function(vector) {
272272
promise_test(function(test) {
273273
var plaintext = copyBuffer(vector.plaintext);
274-
var algorithmParams = {name: vector.algorithm, length: vector.length};
274+
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
275275
if (vector.customization !== undefined) {
276276
algorithmParams.customization = vector.customization;
277277
}
@@ -301,7 +301,7 @@ function run_test() {
301301
var promise = importVectorKeys(vector, ["sign"])
302302
.then(function(vector) {
303303
promise_test(function(test) {
304-
var algorithmParams = {name: vector.algorithm, length: vector.length};
304+
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
305305
if (vector.customization !== undefined) {
306306
algorithmParams.customization = vector.customization;
307307
}
@@ -326,7 +326,7 @@ function run_test() {
326326
var promise = importVectorKeys(vector, ["verify", "sign"])
327327
.then(function(vectors) {
328328
promise_test(function(test) {
329-
var algorithmParams = {name: vector.algorithm, length: vector.length};
329+
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
330330
if (vector.customization !== undefined) {
331331
algorithmParams.customization = vector.customization;
332332
}
@@ -363,7 +363,7 @@ function run_test() {
363363
return importVectorKeys(vector, ["verify", "sign"])
364364
.then(function(vectors) {
365365
promise_test(function(test) {
366-
var algorithmParams = {name: vector.algorithm, length: vector.length};
366+
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
367367
if (vector.customization !== undefined) {
368368
algorithmParams.customization = vector.customization;
369369
}
@@ -401,7 +401,7 @@ function run_test() {
401401
return importVectorKeys(vector, ["verify", "sign"])
402402
.then(function(vector) {
403403
promise_test(function(test) {
404-
var algorithmParams = {name: vector.algorithm, length: vector.length};
404+
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
405405
if (vector.customization !== undefined) {
406406
algorithmParams.customization = vector.customization;
407407
}
@@ -438,7 +438,7 @@ function run_test() {
438438
var plaintext = copyBuffer(vector.plaintext);
439439
plaintext[0] = 255 - plaintext[0];
440440
promise_test(function(test) {
441-
var algorithmParams = {name: vector.algorithm, length: vector.length};
441+
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
442442
if (vector.customization !== undefined) {
443443
algorithmParams.customization = vector.customization;
444444
}
@@ -470,7 +470,7 @@ function run_test() {
470470
var signature = copyBuffer(vector.signature);
471471
signature[0] = 255 - signature[0];
472472
promise_test(function(test) {
473-
var algorithmParams = {name: vector.algorithm, length: vector.length};
473+
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
474474
if (vector.customization !== undefined) {
475475
algorithmParams.customization = vector.customization;
476476
}
@@ -501,7 +501,7 @@ function run_test() {
501501
.then(function(vector) {
502502
var signature = vector.signature.slice(1); // Drop first byte
503503
promise_test(function(test) {
504-
var algorithmParams = {name: vector.algorithm, length: vector.length};
504+
var algorithmParams = {name: vector.algorithm, outputLength: vector.outputLength};
505505
if (vector.customization !== undefined) {
506506
algorithmParams.customization = vector.customization;
507507
}
@@ -531,8 +531,8 @@ function run_test() {
531531
var promise = importVectorKeys(vector, ["verify", "sign"])
532532
.then(function(vector) {
533533
promise_test(function(test) {
534-
var differentLength = vector.length === 256 ? 512 : 256;
535-
var algorithmParams = {name: vector.algorithm, length: differentLength};
534+
var differentLength = vector.outputLength === 256 ? 512 : 256;
535+
var algorithmParams = {name: vector.algorithm, outputLength: differentLength};
536536
if (vector.customization !== undefined) {
537537
algorithmParams.customization = vector.customization;
538538
}

test/fixtures/wpt/WebCryptoAPI/sign_verify/kmac_vectors.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function getTestVectors() {
66
// Sample #1 - KMAC128, no customization
77
name: "KMAC128 with no customization",
88
algorithm: "KMAC128",
9-
length: 256,
9+
outputLength: 256,
1010
keyBuffer: new Uint8Array([
1111
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
1212
0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
@@ -25,7 +25,7 @@ function getTestVectors() {
2525
// Sample #2 - KMAC128, with customization
2626
name: "KMAC128 with customization",
2727
algorithm: "KMAC128",
28-
length: 256,
28+
outputLength: 256,
2929
keyBuffer: new Uint8Array([
3030
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
3131
0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
@@ -47,7 +47,7 @@ function getTestVectors() {
4747
// Sample #3 - KMAC128, large data, with customization
4848
name: "KMAC128 with large data and customization",
4949
algorithm: "KMAC128",
50-
length: 256,
50+
outputLength: 256,
5151
keyBuffer: new Uint8Array([
5252
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
5353
0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
@@ -69,7 +69,7 @@ function getTestVectors() {
6969
// Sample #4 - KMAC256, with customization, 512-bit output
7070
name: "KMAC256 with customization and 512-bit output",
7171
algorithm: "KMAC256",
72-
length: 512,
72+
outputLength: 512,
7373
keyBuffer: new Uint8Array([
7474
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
7575
0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
@@ -94,7 +94,7 @@ function getTestVectors() {
9494
// Sample #5 - KMAC256, large data, no customization, 512-bit output
9595
name: "KMAC256 with large data and no customization",
9696
algorithm: "KMAC256",
97-
length: 512,
97+
outputLength: 512,
9898
keyBuffer: new Uint8Array([
9999
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
100100
0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
@@ -116,7 +116,7 @@ function getTestVectors() {
116116
// Sample #6 - KMAC256, large data, with customization, 512-bit output
117117
name: "KMAC256 with large data and customization",
118118
algorithm: "KMAC256",
119-
length: 512,
119+
outputLength: 512,
120120
keyBuffer: new Uint8Array([
121121
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
122122
0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,

0 commit comments

Comments
 (0)