Skip to content

Commit c9e9558

Browse files
hubertchaochromium-wpt-export-bot
authored andcommitted
[WebCrypto] ChaCha20-Poly1305 implementation
Implements components/webcrypto layer going directly to boringssl, tests in WPT in a virtual test suite, and minor fixes in third_party/blink that were missed in the first CL. based on spec at https://wicg.github.io/webcrypto-modern-algos/ Change-Id: I3b6cf19ae9f8103f2b8a7bcb38bc19d34d2cbede Bug: 450627018 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7055745 Commit-Queue: Hubert Chao <hchao@chromium.org> Reviewed-by: David Benjamin <davidben@chromium.org> Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org> Cr-Commit-Position: refs/heads/main@{#1594908}
1 parent ca9bf3e commit c9e9558

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

WebCryptoAPI/wrapKey_unwrapKey/wrapKey_unwrapKey.https.any.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
name: "AES-KW",
4141
importParameters: {name: "AES-KW", length: 128},
4242
wrapParameters: {name: "AES-KW"}
43+
},
44+
{
45+
name: 'ChaCha20-Poly1305',
46+
importParameters: {name: "ChaCha20-Poly1305"},
47+
wrapParameters: {name: "ChaCha20-Poly1305", iv: new Uint8Array(12), additionalData: new Uint8Array(16)}
4348
}
4449
];
4550

@@ -57,7 +62,8 @@
5762
{algorithm: {name: "AES-CBC", length: 128}, usages: ["encrypt", "decrypt"]},
5863
{algorithm: {name: "AES-GCM", length: 128}, usages: ["encrypt", "decrypt"]},
5964
{algorithm: {name: "AES-KW", length: 128}, usages: ["wrapKey", "unwrapKey"]},
60-
{algorithm: {name: "HMAC", length: 128, hash: "SHA-256"}, usages: ["sign", "verify"]}
65+
{algorithm: {name: "HMAC", length: 128, hash: "SHA-256"}, usages: ["sign", "verify"]},
66+
{algorithm: {name: "ChaCha20-Poly1305"}, usages: ['encrypt', 'decrypt']}
6167
];
6268

6369
// Import all the keys needed, then iterate over all combinations
@@ -106,9 +112,15 @@
106112
.then(function(key) {
107113
wrappers["RSA-OAEP"].unwrappingKey = key;
108114
}));
115+
} else if (params.name === "ChaCha20-Poly1305") {
116+
var algorithm = {name: params.name};
117+
promises.push(subtle.importKey("raw", wrappingKeyData["SYMMETRIC256"].raw, algorithm, true, ["wrapKey", "unwrapKey"])
118+
.then(function(key) {
119+
wrappers[params.name] = {wrappingKey: key, unwrappingKey: key, parameters: params};
120+
}));
109121
} else {
110122
var algorithm = {name: params.name};
111-
promises.push(subtle.importKey("raw", wrappingKeyData["SYMMETRIC"].raw, algorithm, true, ["wrapKey", "unwrapKey"])
123+
promises.push(subtle.importKey("raw", wrappingKeyData["SYMMETRIC128"].raw, algorithm, true, ["wrapKey", "unwrapKey"])
112124
.then(function(key) {
113125
wrappers[params.name] = {wrappingKey: key, unwrappingKey: key, parameters: params};
114126
}));
@@ -151,9 +163,12 @@
151163
var keyData = toWrapKeyDataFromAlg(params.algorithm.name);
152164
promises.push(importAndExport("spki", keyData.spki, params.algorithm, params.publicUsages, "public key "));
153165
promises.push(importAndExport("pkcs8", keyData.pkcs8, params.algorithm, params.privateUsages, "private key "));
166+
} else if (params.algorithm.name === "ChaCha20-Poly1305") {
167+
keys[params.algorithm.name] = {};
168+
promises.push(importAndExport("raw", toWrapKeyData["SYMMETRIC256"].raw, params.algorithm, params.usages, ""));
154169
} else {
155170
keys[params.algorithm.name] = {};
156-
promises.push(importAndExport("raw", toWrapKeyData["SYMMETRIC"].raw, params.algorithm, params.usages, ""));
171+
promises.push(importAndExport("raw", toWrapKeyData["SYMMETRIC128"].raw, params.algorithm, params.usages, ""));
157172
}
158173
});
159174
// Using allSettled to skip unsupported test cases.
@@ -432,6 +447,9 @@
432447
case "ECDH" :
433448
deriveParams = {name: "ECDH"};
434449
break;
450+
case "ChaCha20-Poly1305":
451+
cryptParams = {name: "ChaCha20-Poly1305", iv: new Uint8Array(12)};
452+
break;
435453
default:
436454
throw new Error("Unsupported algorithm for key comparison");
437455
}

WebCryptoAPI/wrapKey_unwrapKey/wrapKey_unwrapKey_vectors.js

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)