Skip to content

Commit e60132f

Browse files
test: update WPT for WebCryptoAPI to e87deca336
PR-URL: #67330 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jason Zhang <xzha4350@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent b8f905a commit e60132f

3 files changed

Lines changed: 49 additions & 2 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// META: title=WebCryptoAPI: AES-CBC decryption ciphertext lengths
2+
// META: global=window,dedicatedworker
3+
4+
/*
5+
* Copyright (C) 2026 Jonathan Powers. All rights reserved.
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions
9+
* are met:
10+
* 1. Redistributions of source code must retain the above copyright
11+
* notice, this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS IS'' AND ANY
17+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS CONTRIBUTORS BE LIABLE FOR ANY
20+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
28+
// https://w3c.github.io/webcrypto/#aes-cbc-operations
29+
// Decryption requires a nonempty ciphertext whose length is a multiple of 16 bytes.
30+
for (const keyLength of [128, 192, 256]) {
31+
for (const cipherTextLength of [0, 1, 15, 17, 31, 33]) {
32+
promise_test(async t => {
33+
const key = await crypto.subtle.importKey("raw", new Uint8Array(keyLength / 8), "AES-CBC", false, ["decrypt"]);
34+
const parameters = { name: "AES-CBC", iv: new Uint8Array(16) };
35+
await promise_rejects_dom(t, "OperationError", crypto.subtle.decrypt(parameters, key, new Uint8Array(cipherTextLength)));
36+
}, `AES-CBC with a ${keyLength}-bit key rejects ${cipherTextLength}-byte ciphertext with OperationError`);
37+
}
38+
39+
promise_test(async () => {
40+
const key = await crypto.subtle.importKey("raw", new Uint8Array(keyLength / 8), "AES-CBC", false, ["encrypt", "decrypt"]);
41+
const parameters = { name: "AES-CBC", iv: new Uint8Array(16) };
42+
const cipherText = await crypto.subtle.encrypt(parameters, key, new Uint8Array(0));
43+
assert_equals(cipherText.byteLength, 16, "Encrypting empty plaintext produces a full padding block");
44+
const plainText = await crypto.subtle.decrypt(parameters, key, cipherText);
45+
assert_equals(plainText.byteLength, 0, "Decrypting a full padding block produces empty plaintext");
46+
}, `AES-CBC with a ${keyLength}-bit key decrypts a padded empty message`);
47+
}

‎test/fixtures/wpt/WebCryptoAPI/encrypt_decrypt/aes_cbc_vectors.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function getTestVectors() {
194194
["zeroPadChar", "bigPadChar", "inconsistentPadChars"].forEach(function(paddingProblem) {
195195
var badCiphertext = new Uint8Array(ciphertext[keyLength].byteLength);
196196
badCiphertext.set(ciphertext[keyLength].slice(0, ciphertext[keyLength].byteLength - 16));
197-
badCiphertext.set(badPadding[keyLength][paddingProblem]);
197+
badCiphertext.set(badPadding[keyLength][paddingProblem], ciphertext[keyLength].byteLength - 16);
198198

199199
decryptionFailing.push({
200200
name: "AES-CBC " + keyLength.toString() + "-bit key, " + paddingProblem,

‎test/fixtures/wpt/versions.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"path": "web-locks"
101101
},
102102
"WebCryptoAPI": {
103-
"commit": "e15690d276ae50728b9d557f4e04f894588d34a0",
103+
"commit": "e87deca3369c630ca2ade57734c5a42adbbc7e48",
104104
"path": "WebCryptoAPI"
105105
},
106106
"webidl": {

0 commit comments

Comments
 (0)