Skip to content

Commit a2764d4

Browse files
nodejs-github-botRafaelGSS
authored andcommitted
test: update WPT for WebCryptoAPI to c58b6f4e0e
PR-URL: #60702 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Richard Lau <richard.lau@ibm.com>
1 parent a731463 commit a2764d4

51 files changed

Lines changed: 7693 additions & 240 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎test/fixtures/wpt/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Last update:
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/ff26d9b307/WebCryptoAPI
37+
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/c58b6f4e0e/WebCryptoAPI
3838
- webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/2f96fa1996/webidl/ecmascript-binding/es-exceptions
3939
- webmessaging/broadcastchannel: https://github.com/web-platform-tests/wpt/tree/6495c91853/webmessaging/broadcastchannel
4040
- webstorage: https://github.com/web-platform-tests/wpt/tree/1d2c5fb36a/webstorage
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
functiondefine_tests(){
2+
varsubtle=self.crypto.subtle;
3+
4+
vartestData=getTestData();
5+
vartestVectors=testData.testVectors;
6+
7+
returnsetUpBaseKeys().then(function(allKeys){
8+
varbaseKeys=allKeys.baseKeys;
9+
10+
testVectors.forEach(function(vector){
11+
varalgorithmName=vector.algorithm;
12+
varparams=vector.params;
13+
varexpected=vector.expected;
14+
15+
vartestName=algorithmName+' deriveBits';
16+
17+
// Test deriveBits
18+
subsetTest(
19+
promise_test,
20+
function(test){
21+
varalgorithm=Object.assign({name: algorithmName},params);
22+
returnsubtle
23+
.deriveBits(algorithm,baseKeys[algorithmName],256)
24+
.then(
25+
function(derivation){
26+
assert_true(
27+
equalBuffers(derivation,expected),
28+
'Derived correct key'
29+
);
30+
},
31+
function(err){
32+
assert_unreached(
33+
'deriveBits failed with error '+
34+
err.name+
35+
': '+
36+
err.message
37+
);
38+
}
39+
);
40+
},
41+
testName
42+
);
43+
});
44+
});
45+
46+
functionsetUpBaseKeys(){
47+
varpromises=[];
48+
varbaseKeys={};
49+
50+
testVectors.forEach(function(vector){
51+
varalgorithmName=vector.algorithm;
52+
varpassword=vector.password;
53+
54+
// Key for normal operations
55+
promises.push(
56+
subtle
57+
.importKey('raw-secret',password,algorithmName,false,[
58+
'deriveBits',
59+
])
60+
.then(function(key){
61+
baseKeys[algorithmName]=key;
62+
})
63+
);
64+
});
65+
66+
returnPromise.all(promises).then(function(){
67+
return{
68+
baseKeys: baseKeys,
69+
};
70+
});
71+
}
72+
}
73+
74+
functionequalBuffers(a,b){
75+
if(a.byteLength!==b.byteLength){
76+
returnfalse;
77+
}
78+
79+
varaView=newUint8Array(a);
80+
varbView=newUint8Array(b);
81+
82+
for(vari=0;i<aView.length;i++){
83+
if(aView[i]!==bView[i]){
84+
returnfalse;
85+
}
86+
}
87+
88+
returntrue;
89+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// META: title=WebCryptoAPI: deriveBits() Using Argon2
2+
// META: timeout=long
3+
// META: script=/common/subset-tests.js
4+
// META: script=argon2_vectors.js
5+
// META: script=argon2.js
6+
7+
promise_test(define_tests,'setup - define tests');
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
functiongetTestData(){
2+
// Test vectors from RFC 9106
3+
// https://www.rfc-editor.org/rfc/rfc9106
4+
5+
// Test vectors from RFC 9106
6+
vartestVectors=[
7+
// Argon2d test vector
8+
{
9+
algorithm: 'Argon2d',
10+
password: newUint8Array(32).fill(0x01),
11+
params: {
12+
memory: 32,
13+
passes: 3,
14+
parallelism: 4,
15+
nonce: newUint8Array(16).fill(0x02),
16+
secretValue: newUint8Array(8).fill(0x03),
17+
associatedData: newUint8Array(12).fill(0x04),
18+
},
19+
expected: newUint8Array([
20+
0x51,0x2b,0x39,0x1b,0x6f,0x11,0x62,0x97,0x53,0x71,0xd3,0x09,
21+
0x19,0x73,0x42,0x94,0xf8,0x68,0xe3,0xbe,0x39,0x84,0xf3,0xc1,
22+
0xa1,0x3a,0x4d,0xb9,0xfa,0xbe,0x4a,0xcb,
23+
]),
24+
},
25+
// Argon2i test vector
26+
{
27+
algorithm: 'Argon2i',
28+
password: newUint8Array(32).fill(0x01),
29+
params: {
30+
memory: 32,
31+
passes: 3,
32+
parallelism: 4,
33+
nonce: newUint8Array(16).fill(0x02),
34+
secretValue: newUint8Array(8).fill(0x03),
35+
associatedData: newUint8Array(12).fill(0x04),
36+
},
37+
expected: newUint8Array([
38+
0xc8,0x14,0xd9,0xd1,0xdc,0x7f,0x37,0xaa,0x13,0xf0,0xd7,0x7f,
39+
0x24,0x94,0xbd,0xa1,0xc8,0xde,0x6b,0x01,0x6d,0xd3,0x88,0xd2,
40+
0x99,0x52,0xa4,0xc4,0x67,0x2b,0x6c,0xe8,
41+
]),
42+
},
43+
// Argon2id test vector
44+
{
45+
algorithm: 'Argon2id',
46+
password: newUint8Array(32).fill(0x01),
47+
params: {
48+
memory: 32,
49+
passes: 3,
50+
parallelism: 4,
51+
nonce: newUint8Array(16).fill(0x02),
52+
secretValue: newUint8Array(8).fill(0x03),
53+
associatedData: newUint8Array(12).fill(0x04),
54+
},
55+
expected: newUint8Array([
56+
0x0d,0x64,0x0d,0xf5,0x8d,0x78,0x76,0x6c,0x08,0xc0,0x37,0xa3,
57+
0x4a,0x8b,0x53,0xc9,0xd0,0x1e,0xf0,0x45,0x2d,0x75,0xb6,0x5e,
58+
0xb5,0x25,0x20,0xe9,0x6b,0x01,0xe6,0x59,
59+
]),
60+
},
61+
];
62+
63+
return{
64+
testVectors: testVectors,
65+
};
66+
}
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
// META: title=WebCryptoAPI: digest() cSHAKE algorithms
2+
// META: timeout=long
3+
4+
varsubtle=crypto.subtle;// Change to test prefixed implementations
5+
6+
varsourceData={
7+
empty: newUint8Array(0),
8+
short: newUint8Array([
9+
21,110,234,124,193,76,86,203,148,219,3,10,74,157,149,255,
10+
]),
11+
medium: newUint8Array([
12+
182,200,249,223,100,140,208,136,183,15,56,231,65,151,177,140,
13+
184,30,30,67,80,213,11,204,184,251,90,115,121,200,123,178,
14+
227,214,237,84,97,237,30,159,54,243,64,163,150,42,68,107,
15+
129,91,121,75,75,212,58,68,3,80,32,119,178,37,108,200,7,
16+
131,127,58,172,209,24,235,75,156,43,174,184,151,6,134,37,
17+
171,172,161,147,
18+
]),
19+
};
20+
21+
// Test different output lengths for cSHAKE
22+
vardigestLengths=[0,256,384,512];
23+
24+
vardigestedData={
25+
cSHAKE128: {
26+
0: {
27+
empty: newUint8Array([]),
28+
short: newUint8Array([]),
29+
medium: newUint8Array([]),
30+
},
31+
256: {
32+
empty: newUint8Array([
33+
127,156,43,164,232,143,130,125,97,96,69,80,118,5,133,62,
34+
215,59,128,147,246,239,188,136,235,26,110,172,250,102,239,
35+
38,
36+
]),
37+
short: newUint8Array([
38+
222,166,45,115,230,181,156,247,37,208,50,13,102,0,137,
39+
164,71,92,187,211,184,83,158,54,105,31,21,13,71,85,103,
40+
148,
41+
]),
42+
medium: newUint8Array([
43+
177,172,213,58,3,231,106,34,30,82,234,87,142,4,47,104,
44+
106,104,195,209,201,131,42,177,130,133,207,79,48,76,163,
45+
45,
46+
]),
47+
},
48+
384: {
49+
empty: newUint8Array([
50+
127,156,43,164,232,143,130,125,97,96,69,80,118,5,133,62,
51+
215,59,128,147,246,239,188,136,235,26,110,172,250,102,239,
52+
38,60,177,238,169,136,0,75,147,16,60,251,10,238,253,42,
53+
104,
54+
]),
55+
short: newUint8Array([
56+
222,166,45,115,230,181,156,247,37,208,50,13,102,0,137,
57+
164,71,92,187,211,184,83,158,54,105,31,21,13,71,85,103,
58+
148,240,55,64,1,183,136,138,188,54,152,212,11,137,174,49,
59+
52,
60+
]),
61+
medium: newUint8Array([
62+
177,172,213,58,3,231,106,34,30,82,234,87,142,4,47,104,
63+
106,104,195,209,201,131,42,177,130,133,207,79,48,76,163,
64+
45,63,170,9,252,130,170,225,66,211,223,205,121,5,138,93,
65+
92,
66+
]),
67+
},
68+
512: {
69+
empty: newUint8Array([
70+
127,156,43,164,232,143,130,125,97,96,69,80,118,5,133,62,
71+
215,59,128,147,246,239,188,136,235,26,110,172,250,102,239,
72+
38,60,177,238,169,136,0,75,147,16,60,251,10,238,253,42,
73+
104,110,1,250,74,88,232,163,99,156,168,161,227,249,174,
74+
87,226,
75+
]),
76+
short: newUint8Array([
77+
222,166,45,115,230,181,156,247,37,208,50,13,102,0,137,
78+
164,71,92,187,211,184,83,158,54,105,31,21,13,71,85,103,
79+
148,240,55,64,1,183,136,138,188,54,152,212,11,137,174,49,
80+
52,233,51,245,26,132,202,127,218,136,12,59,253,217,220,
81+
58,94,
82+
]),
83+
medium: newUint8Array([
84+
177,172,213,58,3,231,106,34,30,82,234,87,142,4,47,104,
85+
106,104,195,209,201,131,42,177,130,133,207,79,48,76,163,
86+
45,63,170,9,252,130,170,225,66,211,223,205,121,5,138,93,
87+
92,60,17,189,45,17,195,248,169,51,31,98,172,221,186,225,
88+
93,
89+
]),
90+
},
91+
},
92+
cSHAKE256: {
93+
0: {
94+
empty: newUint8Array([]),
95+
short: newUint8Array([]),
96+
medium: newUint8Array([]),
97+
},
98+
256: {
99+
empty: newUint8Array([
100+
70,185,221,43,11,168,141,19,35,59,63,235,116,62,235,36,
101+
63,205,82,234,98,184,27,130,181,12,39,100,110,213,118,47,
102+
]),
103+
short: newUint8Array([
104+
23,56,17,63,90,187,62,229,50,14,225,138,162,102,195,97,
105+
122,116,117,219,216,237,154,152,89,148,253,221,97,18,173,
106+
153,
107+
]),
108+
medium: newUint8Array([
109+
65,70,193,61,134,217,188,24,107,11,48,154,182,161,36,238,
110+
12,116,186,38,184,198,13,204,123,62,213,5,150,154,168,
111+
209,
112+
]),
113+
},
114+
384: {
115+
empty: newUint8Array([
116+
70,185,221,43,11,168,141,19,35,59,63,235,116,62,235,36,
117+
63,205,82,234,98,184,27,130,181,12,39,100,110,213,118,47,
118+
215,93,196,221,216,192,242,0,203,5,1,157,103,181,146,246,
119+
]),
120+
short: newUint8Array([
121+
23,56,17,63,90,187,62,229,50,14,225,138,162,102,195,97,
122+
122,116,117,219,216,237,154,152,89,148,253,221,97,18,173,
123+
153,158,200,226,235,223,234,251,150,231,111,107,179,163,
124+
173,186,67,
125+
]),
126+
medium: newUint8Array([
127+
65,70,193,61,134,217,188,24,107,11,48,154,182,161,36,238,
128+
12,116,186,38,184,198,13,204,123,62,213,5,150,154,168,
129+
209,144,40,198,49,121,153,160,133,177,230,182,167,133,206,
130+
79,246,
131+
]),
132+
},
133+
512: {
134+
empty: newUint8Array([
135+
70,185,221,43,11,168,141,19,35,59,63,235,116,62,235,36,
136+
63,205,82,234,98,184,27,130,181,12,39,100,110,213,118,47,
137+
215,93,196,221,216,192,242,0,203,5,1,157,103,181,146,246,
138+
252,130,28,73,71,154,180,134,64,41,46,172,179,183,196,
139+
190,
140+
]),
141+
short: newUint8Array([
142+
23,56,17,63,90,187,62,229,50,14,225,138,162,102,195,97,
143+
122,116,117,219,216,237,154,152,89,148,253,221,97,18,173,
144+
153,158,200,226,235,223,234,251,150,231,111,107,179,163,
145+
173,186,67,218,96,240,12,209,36,150,223,90,243,226,138,
146+
230,211,222,66,
147+
]),
148+
medium: newUint8Array([
149+
65,70,193,61,134,217,188,24,107,11,48,154,182,161,36,238,
150+
12,116,186,38,184,198,13,204,123,62,213,5,150,154,168,
151+
209,144,40,198,49,121,153,160,133,177,230,182,167,133,206,
152+
79,246,50,174,178,116,147,34,126,68,35,47,183,179,149,33,
153+
65,123,
154+
]),
155+
},
156+
},
157+
};
158+
159+
// Test cSHAKE digest algorithms with variable output lengths
160+
Object.keys(digestedData).forEach(function(alg){
161+
digestLengths.forEach(function(length){
162+
Object.keys(sourceData).forEach(function(size){
163+
promise_test(function(test){
164+
returncrypto.subtle
165+
.digest({name: alg,length: length},sourceData[size])
166+
.then(function(result){
167+
assert_true(
168+
equalBuffers(result,digestedData[alg][length][size]),
169+
'digest matches expected'
170+
);
171+
});
172+
},alg+' with '+length+' bit output and '+size+' source data');
173+
174+
promise_test(function(test){
175+
varbuffer=newUint8Array(sourceData[size]);
176+
returncrypto.subtle
177+
.digest({name: alg,length: length},buffer)
178+
.then(function(result){
179+
// Alter the buffer after calling digest
180+
if(buffer.length>0){
181+
buffer[0]=~buffer[0];
182+
}
183+
assert_true(
184+
equalBuffers(result,digestedData[alg][length][size]),
185+
'digest matches expected'
186+
);
187+
});
188+
},alg+
189+
' with '+
190+
length+
191+
' bit output and '+
192+
size+
193+
' source data and altered buffer after call');
194+
});
195+
});
196+
});
197+
198+
functionequalBuffers(a,b){
199+
if(a.byteLength!==b.byteLength){
200+
returnfalse;
201+
}
202+
varaBytes=newUint8Array(a);
203+
varbBytes=newUint8Array(b);
204+
for(vari=0;i<a.byteLength;i++){
205+
if(aBytes[i]!==bBytes[i]){
206+
returnfalse;
207+
}
208+
}
209+
returntrue;
210+
}

0 commit comments

Comments
 (0)