summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt')
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes.js325
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_cbc.https.any.js6
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_cbc_vectors.js261
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_ctr.https.any.js6
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_gcm.https.any.js7
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_gcm_256_iv.https.any.js7
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_gcm_256_iv_fixtures.js210
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_gcm_96_iv_fixtures.js209
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_gcm_vectors.js76
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/rsa.js378
-rw-r--r--testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/rsa_oaep.https.any.js6
11 files changed, 1491 insertions, 0 deletions
diff --git a/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes.js b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes.js
new file mode 100644
index 0000000000..fdeb7963f7
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes.js
@@ -0,0 +1,325 @@
+
+function run_test() {
+ var subtle = self.crypto.subtle; // Change to test prefixed implementations
+
+ // When are all these tests really done? When all the promises they use have resolved.
+ var all_promises = [];
+
+ // Source file aes_XXX_vectors.js provides the getTestVectors method
+ // for the AES-XXX algorithm that drives these tests.
+ var vectors = getTestVectors();
+ var passingVectors = vectors.passing;
+ var failingVectors = vectors.failing;
+ var decryptionFailingVectors = vectors.decryptionFailing;
+
+ // Check for successful encryption.
+ passingVectors.forEach(function(vector) {
+ var promise = importVectorKey(vector, ["encrypt", "decrypt"])
+ .then(function(vector) {
+ promise_test(function(test) {
+ return subtle.encrypt(vector.algorithm, vector.key, vector.plaintext)
+ .then(function(result) {
+ assert_true(equalBuffers(result, vector.result), "Should return expected result");
+ }, function(err) {
+ assert_unreached("encrypt error for test " + vector.name + ": " + err.message);
+ });
+ }, vector.name);
+ }, function(err) {
+ // We need a failed test if the importVectorKey operation fails, so
+ // we know we never tested encryption
+ promise_test(function(test) {
+ assert_unreached("importKey failed for " + vector.name);
+ }, "importKey step: " + vector.name);
+ });
+
+ all_promises.push(promise);
+ });
+
+ // Check for successful encryption even if the buffer is changed after calling encrypt.
+ passingVectors.forEach(function(vector) {
+ var plaintext = copyBuffer(vector.plaintext);
+ var promise = importVectorKey(vector, ["encrypt", "decrypt"])
+ .then(function(vector) {
+ promise_test(function(test) {
+ var operation = subtle.encrypt(vector.algorithm, vector.key, plaintext)
+ .then(function(result) {
+ assert_true(equalBuffers(result, vector.result), "Should return expected result");
+ }, function(err) {
+ assert_unreached("encrypt error for test " + vector.name + ": " + err.message);
+ });
+ plaintext[0] = 255 - plaintext[0];
+ return operation;
+ }, vector.name + " with altered plaintext");
+ }, function(err) {
+ // We need a failed test if the importVectorKey operation fails, so
+ // we know we never tested encryption
+ promise_test(function(test) {
+ assert_unreached("importKey failed for " + vector.name);
+ }, "importKey step: " + vector.name + " with altered plaintext");
+ });
+
+ all_promises.push(promise);
+ });
+
+ // Check for successful decryption.
+ passingVectors.forEach(function(vector) {
+ var promise = importVectorKey(vector, ["encrypt", "decrypt"])
+ .then(function(vector) {
+ promise_test(function(test) {
+ return subtle.decrypt(vector.algorithm, vector.key, vector.result)
+ .then(function(result) {
+ assert_true(equalBuffers(result, vector.plaintext), "Should return expected result");
+ }, function(err) {
+ assert_unreached("decrypt error for test " + vector.name + ": " + err.message);
+ });
+ }, vector.name + " decryption");
+ }, function(err) {
+ // We need a failed test if the importVectorKey operation fails, so
+ // we know we never tested encryption
+ promise_test(function(test) {
+ assert_unreached("importKey failed for " + vector.name);
+ }, "importKey step for decryption: " + vector.name);
+ });
+
+ all_promises.push(promise);
+ });
+
+ // Check for successful decryption even if ciphertext is altered.
+ passingVectors.forEach(function(vector) {
+ var ciphertext = copyBuffer(vector.result);
+ var promise = importVectorKey(vector, ["encrypt", "decrypt"])
+ .then(function(vector) {
+ promise_test(function(test) {
+ var operation = subtle.decrypt(vector.algorithm, vector.key, ciphertext)
+ .then(function(result) {
+ assert_true(equalBuffers(result, vector.plaintext), "Should return expected result");
+ }, function(err) {
+ assert_unreached("decrypt error for test " + vector.name + ": " + err.message);
+ });
+ ciphertext[0] = 255 - ciphertext[0];
+ return operation;
+ }, vector.name + " decryption with altered ciphertext");
+ }, function(err) {
+ // We need a failed test if the importVectorKey operation fails, so
+ // we know we never tested encryption
+ promise_test(function(test) {
+ assert_unreached("importKey failed for " + vector.name);
+ }, "importKey step for decryption: " + vector.name + " with altered ciphertext");
+ });
+
+ all_promises.push(promise);
+ });
+
+ // Everything that succeeded should fail if no "encrypt" usage.
+ passingVectors.forEach(function(vector) {
+ // Don't want to overwrite key being used for success tests!
+ var badVector = Object.assign({}, vector);
+ badVector.key = null;
+
+ var promise = importVectorKey(badVector, ["decrypt"])
+ .then(function(vector) {
+ promise_test(function(test) {
+ return subtle.encrypt(vector.algorithm, vector.key, vector.plaintext)
+ .then(function(result) {
+ assert_unreached("should have thrown exception for test " + vector.name);
+ }, function(err) {
+ assert_equals(err.name, "InvalidAccessError", "Should throw an InvalidAccessError instead of " + err.message)
+ });
+ }, vector.name + " without encrypt usage");
+ }, function(err) {
+ // We need a failed test if the importVectorKey operation fails, so
+ // we know we never tested encryption
+ promise_test(function(test) {
+ assert_unreached("importKey failed for " + vector.name);
+ }, "importKey step: " + vector.name + " without encrypt usage");
+ });
+
+ all_promises.push(promise);
+ });
+
+ // Encryption should fail if algorithm of key doesn't match algorithm of function call.
+ passingVectors.forEach(function(vector) {
+ var algorithm = Object.assign({}, vector.algorithm);
+ if (algorithm.name === "AES-CBC") {
+ algorithm.name = "AES-CTR";
+ algorithm.counter = new Uint8Array(16);
+ algorithm.length = 64;
+ } else {
+ algorithm.name = "AES-CBC";
+ algorithm.iv = new Uint8Array(16); // Need syntactically valid parameter to get to error being checked.
+ }
+
+ var promise = importVectorKey(vector, ["encrypt", "decrypt"])
+ .then(function(vector) {
+ promise_test(function(test) {
+ return subtle.encrypt(algorithm, vector.key, vector.plaintext)
+ .then(function(result) {
+ assert_unreached("encrypt succeeded despite mismatch " + vector.name + ": " + err.message);
+ }, function(err) {
+ assert_equals(err.name, "InvalidAccessError", "Mismatch should cause InvalidAccessError instead of " + err.message);
+ });
+ }, vector.name + " with mismatched key and algorithm");
+ }, function(err) {
+ // We need a failed test if the importVectorKey operation fails, so
+ // we know we never tested encryption
+ promise_test(function(test) {
+ assert_unreached("importKey failed for " + vector.name);
+ }, "importKey step: " + vector.name + " with mismatched key and algorithm");
+ });
+
+ all_promises.push(promise);
+ });
+
+ // Everything that succeeded decrypting should fail if no "decrypt" usage.
+ passingVectors.forEach(function(vector) {
+ // Don't want to overwrite key being used for success tests!
+ var badVector = Object.assign({}, vector);
+ badVector.key = null;
+
+ var promise = importVectorKey(badVector, ["encrypt"])
+ .then(function(vector) {
+ promise_test(function(test) {
+ return subtle.decrypt(vector.algorithm, vector.key, vector.result)
+ .then(function(result) {
+ assert_unreached("should have thrown exception for test " + vector.name);
+ }, function(err) {
+ assert_equals(err.name, "InvalidAccessError", "Should throw an InvalidAccessError instead of " + err.message)
+ });
+ }, vector.name + " without decrypt usage");
+ }, function(err) {
+ // We need a failed test if the importVectorKey operation fails, so
+ // we know we never tested encryption
+ promise_test(function(test) {
+ assert_unreached("importKey failed for " + vector.name);
+ }, "importKey step: " + vector.name + " without decrypt usage");
+ });
+
+ all_promises.push(promise);
+ });
+
+ // Check for OperationError due to data lengths.
+ failingVectors.forEach(function(vector) {
+ var promise = importVectorKey(vector, ["encrypt", "decrypt"])
+ .then(function(vector) {
+ promise_test(function(test) {
+ return subtle.encrypt(vector.algorithm, vector.key, vector.plaintext)
+ .then(function(result) {
+ assert_unreached("should have thrown exception for test " + vector.name);
+ }, function(err) {
+ assert_equals(err.name, "OperationError", "Should throw an OperationError instead of " + err.message)
+ });
+ }, vector.name);
+ }, function(err) {
+ // We need a failed test if the importVectorKey operation fails, so
+ // we know we never tested encryption
+ promise_test(function(test) {
+ assert_unreached("importKey failed for " + vector.name);
+ }, "importKey step: " + vector.name);
+ });
+
+ all_promises.push(promise);
+ });
+
+ // Check for OperationError due to data lengths for decryption, too.
+ failingVectors.forEach(function(vector) {
+ var promise = importVectorKey(vector, ["encrypt", "decrypt"])
+ .then(function(vector) {
+ promise_test(function(test) {
+ return subtle.decrypt(vector.algorithm, vector.key, vector.result)
+ .then(function(result) {
+ assert_unreached("should have thrown exception for test " + vector.name);
+ }, function(err) {
+ assert_equals(err.name, "OperationError", "Should throw an OperationError instead of " + err.message)
+ });
+ }, vector.name + " decryption");
+ }, function(err) {
+ // We need a failed test if the importVectorKey operation fails, so
+ // we know we never tested encryption
+ promise_test(function(test) {
+ assert_unreached("importKey failed for " + vector.name);
+ }, "importKey step: decryption " + vector.name);
+ });
+
+ all_promises.push(promise);
+ });
+
+ // Check for decryption failing for algorithm-specific reasons (such as bad
+ // padding for AES-CBC).
+ decryptionFailingVectors.forEach(function(vector) {
+ var promise = importVectorKey(vector, ["encrypt", "decrypt"])
+ .then(function(vector) {
+ promise_test(function(test) {
+ return subtle.decrypt(vector.algorithm, vector.key, vector.result)
+ .then(function(result) {
+ assert_unreached("should have thrown exception for test " + vector.name);
+ }, function(err) {
+ assert_equals(err.name, "OperationError", "Should throw an OperationError instead of " + err.message)
+ });
+ }, vector.name);
+ }, function(err) {
+ // We need a failed test if the importVectorKey operation fails, so
+ // we know we never tested encryption
+ promise_test(function(test) {
+ assert_unreached("importKey failed for " + vector.name);
+ }, "importKey step: decryption " + vector.name);
+ });
+
+ all_promises.push(promise);
+ });
+
+ promise_test(function() {
+ return Promise.all(all_promises)
+ .then(function() {done();})
+ .catch(function() {done();})
+ }, "setup");
+
+ // A test vector has all needed fields for encryption, EXCEPT that the
+ // key field may be null. This function replaces that null with the Correct
+ // CryptoKey object.
+ //
+ // Returns a Promise that yields an updated vector on success.
+ function importVectorKey(vector, usages) {
+ if (vector.key !== null) {
+ return new Promise(function(resolve, reject) {
+ resolve(vector);
+ });
+ } else {
+ return subtle.importKey("raw", vector.keyBuffer, {name: vector.algorithm.name}, false, usages)
+ .then(function(key) {
+ vector.key = key;
+ return vector;
+ });
+ }
+ }
+
+ // Returns a copy of the sourceBuffer it is sent.
+ function copyBuffer(sourceBuffer) {
+ var source = new Uint8Array(sourceBuffer);
+ var copy = new Uint8Array(sourceBuffer.byteLength)
+
+ for (var i=0; i<source.byteLength; i++) {
+ copy[i] = source[i];
+ }
+
+ return copy;
+ }
+
+ function equalBuffers(a, b) {
+ if (a.byteLength !== b.byteLength) {
+ return false;
+ }
+
+ var aBytes = new Uint8Array(a);
+ var bBytes = new Uint8Array(b);
+
+ for (var i=0; i<a.byteLength; i++) {
+ if (aBytes[i] !== bBytes[i]) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ return;
+}
diff --git a/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_cbc.https.any.js b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_cbc.https.any.js
new file mode 100644
index 0000000000..35637a46af
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_cbc.https.any.js
@@ -0,0 +1,6 @@
+// META: title=WebCryptoAPI: encrypt() Using AES-CBC
+// META: script=aes_cbc_vectors.js
+// META: script=aes.js
+// META: timeout=long
+
+run_test();
diff --git a/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_cbc_vectors.js b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_cbc_vectors.js
new file mode 100644
index 0000000000..96445a9632
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_cbc_vectors.js
@@ -0,0 +1,261 @@
+
+// aes_cbc_vectors.js
+
+// The following function returns an array of test vectors
+// for the subtleCrypto encrypt method.
+//
+// Each test vector has the following fields:
+// name - a unique name for this vector
+// keyBuffer - an arrayBuffer with the key data in raw form
+// key - a CryptoKey object for the keyBuffer. INITIALLY null! You must fill this in first to use it!
+// algorithm - the value of the AlgorithmIdentifier parameter to provide to encrypt
+// plaintext - the text to encrypt
+// result - the expected result (usually just ciphertext, sometimes with added authentication)
+function getTestVectors() {
+ // Before we can really start, we need to fill a bunch of buffers with data
+ var plaintext = new Uint8Array([84, 104, 105, 115, 32, 115,
+ 112, 101, 99, 105, 102, 105, 99, 97, 116, 105, 111, 110,
+ 32, 100, 101, 115, 99, 114, 105, 98, 101, 115, 32, 97, 32,
+ 74, 97, 118, 97, 83, 99, 114, 105, 112, 116, 32, 65, 80,
+ 73, 32, 102, 111, 114, 32, 112, 101, 114, 102, 111, 114,
+ 109, 105, 110, 103, 32, 98, 97, 115, 105, 99, 32, 99, 114,
+ 121, 112, 116, 111, 103, 114, 97, 112, 104, 105, 99, 32,
+ 111, 112, 101, 114, 97, 116, 105, 111, 110, 115, 32, 105,
+ 110, 32, 119, 101, 98, 32, 97, 112, 112, 108, 105, 99, 97,
+ 116, 105, 111, 110, 115, 44, 32, 115, 117, 99, 104, 32, 97,
+ 115, 32, 104, 97, 115, 104, 105, 110, 103, 44, 32, 115,
+ 105, 103, 110, 97, 116, 117, 114, 101, 32, 103, 101, 110,
+ 101, 114, 97, 116, 105, 111, 110, 32, 97, 110, 100, 32,
+ 118, 101, 114, 105, 102, 105, 99, 97, 116, 105, 111, 110,
+ 44, 32, 97, 110, 100, 32, 101, 110, 99, 114, 121, 112,
+ 116, 105, 111, 110, 32, 97, 110, 100, 32, 100, 101, 99,
+ 114, 121, 112, 116, 105, 111, 110, 46, 32, 65, 100, 100,
+ 105, 116, 105, 111, 110, 97, 108, 108, 121, 44, 32, 105,
+ 116, 32, 100, 101, 115, 99, 114, 105, 98, 101, 115, 32, 97,
+ 110, 32, 65, 80, 73, 32, 102, 111, 114, 32, 97, 112, 112,
+ 108, 105, 99, 97, 116, 105, 111, 110, 115, 32, 116, 111,
+ 32, 103, 101, 110, 101, 114, 97, 116, 101, 32, 97, 110,
+ 100, 47, 111, 114, 32, 109, 97, 110, 97, 103, 101, 32, 116,
+ 104, 101, 32, 107, 101, 121, 105, 110, 103, 32, 109, 97,
+ 116, 101, 114, 105, 97, 108, 32, 110, 101, 99, 101, 115,
+ 115, 97, 114, 121, 32, 116, 111, 32, 112, 101, 114, 102,
+ 111, 114, 109, 32, 116, 104, 101, 115, 101, 32, 111, 112,
+ 101, 114, 97, 116, 105, 111, 110, 115, 46, 32, 85, 115,
+ 101, 115, 32, 102, 111, 114, 32, 116, 104, 105, 115, 32,
+ 65, 80, 73, 32, 114, 97, 110, 103, 101, 32, 102, 114, 111,
+ 109, 32, 117, 115, 101, 114, 32, 111, 114, 32, 115, 101,
+ 114, 118, 105, 99, 101, 32, 97, 117, 116, 104, 101, 110,
+ 116, 105, 99, 97, 116, 105, 111, 110, 44, 32, 100, 111,
+ 99, 117, 109, 101, 110, 116, 32, 111, 114, 32, 99, 111,
+ 100, 101, 32, 115, 105, 103, 110, 105, 110, 103, 44, 32,
+ 97, 110, 100, 32, 116, 104, 101, 32, 99, 111, 110, 102,
+ 105, 100, 101, 110, 116, 105, 97, 108, 105, 116, 121, 32,
+ 97, 110, 100, 32, 105, 110, 116, 101, 103, 114, 105, 116,
+ 121, 32, 111, 102, 32, 99, 111, 109, 109, 117, 110, 105,
+ 99, 97, 116, 105, 111, 110, 115, 46]);
+
+ // We want some random key bytes of various sizes.
+ // These were randomly generated from a script.
+ var keyBytes = {
+ 128: new Uint8Array([222, 192, 212, 252, 191, 60, 71,
+ 65, 200, 146, 218, 189, 28, 212, 192, 78]),
+ 192: new Uint8Array([208, 238, 131, 65, 63, 68, 196, 63, 186, 208,
+ 61, 207, 166, 18, 99, 152, 29, 109, 221, 95, 240, 30, 28, 246]),
+ 256: new Uint8Array([103, 105, 56, 35, 251, 29, 88, 7, 63, 145, 236,
+ 233, 204, 58, 249, 16, 229, 83, 38, 22, 164, 210, 123, 19, 235, 123, 116,
+ 216, 0, 11, 191, 48])
+ }
+
+ // AES-CBC needs a 16 byte (128 bit) IV.
+ var iv = new Uint8Array([85, 170, 248, 155, 168, 148, 19, 213, 78, 167, 39,
+ 167, 108, 39, 162, 132]);
+
+
+ // Results. These were created using the Python cryptography module.
+
+ // AES-CBC produces ciphertext
+ var ciphertext = {
+ 128: new Uint8Array([35, 127, 3, 254, 231, 8, 114, 231, 143, 174, 193,
+ 72, 221, 189, 1, 189, 119, 203, 150, 227, 56, 30, 244, 236, 226, 175,
+ 234, 23, 167, 175, 211, 124, 203, 228, 97, 223, 156, 77, 88, 174,
+ 166, 187, 186, 225, 176, 92, 250, 177, 225, 41, 135, 124, 215, 86,
+ 198, 134, 124, 49, 154, 60, 224, 93, 165, 12, 190, 245, 241, 164,
+ 247, 220, 227, 69, 242, 105, 208, 108, 222, 193, 223, 0, 226, 217,
+ 39, 160, 78, 147, 191, 38, 153, 232, 206, 221, 254, 25, 185, 249, 7,
+ 181, 215, 104, 98, 163, 194, 161, 103, 161, 237, 167, 10, 242, 37,
+ 80, 2, 255, 173, 96, 20, 106, 170, 110, 80, 38, 136, 127, 16, 85,
+ 244, 78, 172, 56, 106, 3, 115, 130, 58, 186, 129, 236, 255, 251,
+ 178, 112, 24, 159, 82, 252, 1, 178, 132, 92, 40, 125, 18, 135, 116,
+ 64, 178, 31, 174, 87, 114, 114, 218, 78, 111, 0, 239, 252, 79, 63,
+ 119, 58, 118, 78, 55, 249, 36, 130, 225, 205, 13, 76, 97, 214, 250,
+ 174, 232, 67, 103, 211, 178, 206, 32, 129, 188, 243, 100, 71, 63,
+ 154, 159, 200, 125, 34, 138, 39, 73, 130, 75, 97, 203, 204, 111,
+ 244, 75, 186, 181, 43, 207, 175, 146, 98, 207, 27, 23, 90, 144, 161,
+ 19, 235, 199, 93, 98, 238, 72, 134, 157, 220, 207, 66, 167, 236, 94,
+ 57, 0, 3, 202, 250, 55, 26, 163, 20, 133, 191, 67, 20, 63, 150, 203,
+ 87, 216, 44, 57, 188, 236, 64, 80, 111, 68, 26, 12, 10, 163, 82, 3,
+ 191, 19, 71, 186, 196, 177, 84, 244, 7, 78, 41, 172, 203, 27, 225,
+ 231, 108, 206, 141, 221, 253, 204, 220, 134, 20, 130, 54, 113, 81,
+ 127, 197, 27, 101, 121, 159, 223, 193, 115, 190, 12, 153, 174, 231,
+ 196, 92, 142, 156, 61, 189, 3, 18, 153, 206, 190, 58, 255, 154, 115,
+ 66, 23, 107, 94, 220, 156, 220, 228, 241, 66, 6, 184, 44, 238, 249,
+ 51, 240, 109, 142, 208, 189, 11, 117, 70, 170, 217, 170, 216, 66,
+ 231, 18, 175, 121, 221, 16, 29, 139, 55, 103, 91, 239, 111, 29, 108,
+ 94, 179, 138, 134, 73, 130, 29, 69, 182, 192, 249, 150, 165, 79, 47,
+ 91, 203, 226, 63, 87, 52, 60, 172, 191, 190, 179, 171, 155, 205, 88,
+ 172, 111, 59, 40, 198, 250, 209, 148, 177, 115, 200, 40, 43, 165,
+ 167, 67, 116, 64, 159, 240, 81, 253, 235, 137, 132, 49, 223, 214,
+ 172, 53, 7, 47, 184, 223, 120, 59, 51, 33, 124, 147, 221, 27, 60,
+ 16, 254, 24, 115, 115, 214, 75, 73, 97, 136, 214, 209, 177, 106, 71,
+ 254, 211, 94, 57, 104, 170, 168, 35, 37, 93, 203, 199, 38, 28, 84]),
+
+ 192: new Uint8Array([131, 160, 2, 14, 214, 229, 41, 230, 47, 99, 83,
+ 193, 62, 133, 172, 195, 127, 61, 247, 80, 71, 167, 37, 184, 230,
+ 207, 168, 163, 139, 145, 18, 225, 205, 134, 87, 138, 80, 247, 166,
+ 176, 177, 18, 71, 88, 193, 56, 45, 96, 36, 78, 134, 212, 9, 250, 217,
+ 24, 207, 215, 111, 72, 114, 203, 27, 188, 122, 34, 212, 191, 88, 72,
+ 22, 194, 224, 217, 236, 201, 191, 236, 214, 231, 90, 244, 100, 153,
+ 211, 35, 182, 205, 128, 84, 79, 161, 53, 166, 236, 196, 181, 163,
+ 140, 255, 80, 59, 49, 71, 170, 118, 14, 100, 40, 105, 184, 187, 41,
+ 198, 180, 135, 69, 211, 69, 74, 132, 243, 76, 144, 102, 90, 155,
+ 243, 125, 140, 190, 20, 9, 232, 188, 198, 221, 148, 13, 53, 155, 91,
+ 34, 235, 24, 121, 109, 48, 242, 142, 8, 160, 223, 242, 163, 98, 198,
+ 131, 164, 160, 79, 27, 210, 216, 192, 228, 27, 4, 254, 222, 195, 14,
+ 77, 72, 225, 151, 114, 38, 130, 143, 6, 17, 138, 229, 193, 114, 169,
+ 2, 108, 225, 35, 37, 232, 200, 167, 147, 251, 210, 138, 243, 44, 48,
+ 12, 84, 192, 169, 108, 0, 113, 77, 160, 218, 96, 4, 138, 171, 207,
+ 20, 189, 146, 255, 206, 68, 160, 87, 127, 3, 83, 182, 203, 116, 59,
+ 24, 186, 79, 68, 220, 161, 85, 227, 29, 118, 134, 128, 187, 29, 128,
+ 121, 120, 64, 211, 30, 255, 52, 187, 185, 216, 151, 30, 10, 165,
+ 203, 148, 39, 224, 14, 173, 199, 57, 0, 194, 79, 115, 206, 159, 43,
+ 13, 36, 169, 97, 144, 32, 0, 207, 230, 16, 162, 156, 166, 34, 150,
+ 12, 93, 141, 164, 181, 194, 10, 47, 139, 82, 75, 42, 23, 224, 3, 92,
+ 151, 154, 249, 170, 57, 141, 113, 32, 52, 158, 218, 49, 242, 134,
+ 65, 69, 203, 71, 19, 133, 125, 117, 1, 207, 210, 224, 130, 45, 37,
+ 42, 181, 139, 34, 85, 8, 67, 165, 249, 180, 89, 3, 60, 152, 1, 231,
+ 49, 1, 124, 243, 81, 44, 72, 232, 239, 129, 75, 108, 4, 169, 132,
+ 73, 183, 21, 29, 46, 94, 138, 83, 190, 131, 146, 65, 104, 107, 251,
+ 218, 95, 227, 94, 145, 70, 0, 2, 252, 59, 188, 58, 150, 203, 148,
+ 100, 219, 36, 182, 81, 237, 138, 160, 83, 151, 119, 11, 216, 122,
+ 134, 189, 246, 251, 192, 41, 158, 125, 247, 190, 32, 173, 104, 9,
+ 58, 223, 97, 212, 48, 62, 3, 112, 21, 74, 206, 87, 182, 110, 197,
+ 67, 68, 155, 189, 223, 136, 2, 239, 137, 151, 138, 252, 162, 141,
+ 255, 209, 25, 4, 146, 24, 221, 43, 148, 120, 26, 228, 208, 200, 198,
+ 192, 4, 96, 70, 227, 237, 104, 17, 67, 9, 211]),
+
+ 256: new Uint8Array([41, 213, 121, 140, 181, 227, 200, 97, 100, 133, 58,
+ 227, 106, 115, 25, 63, 77, 51, 26, 57, 238, 140, 99, 63, 71, 211,
+ 128, 84, 115, 26, 236, 52, 103, 81, 145, 14, 101, 161, 181, 58, 135,
+ 193, 56, 167, 214, 220, 5, 52, 85, 222, 183, 27, 101, 134, 86, 155,
+ 64, 148, 124, 212, 219, 251, 65, 42, 32, 44, 128, 2, 50, 128, 221,
+ 22, 238, 56, 189, 83, 28, 122, 121, 157, 215, 135, 151, 128, 233,
+ 193, 65, 190, 86, 148, 191, 140, 196, 120, 8, 172, 100, 166, 254,
+ 41, 245, 75, 56, 6, 166, 244, 178, 111, 234, 23, 4, 107, 6, 22, 132,
+ 187, 230, 17, 71, 172, 113, 238, 73, 4, 180, 90, 103, 77, 37, 51,
+ 118, 112, 129, 238, 199, 7, 222, 122, 173, 30, 232, 178, 233, 234,
+ 144, 98, 14, 234, 112, 77, 68, 62, 62, 159, 230, 101, 98, 43, 2,
+ 204, 69, 156, 86, 104, 128, 34, 128, 7, 173, 90, 120, 33, 104, 59,
+ 45, 251, 93, 51, 240, 232, 60, 94, 189, 134, 90, 20, 184, 122, 29,
+ 225, 85, 213, 38, 116, 159, 80, 69, 106, 168, 236, 201, 69, 140, 98,
+ 240, 45, 160, 133, 225, 106, 45, 245, 212, 160, 176, 128, 27, 114,
+ 153, 182, 144, 145, 214, 72, 196, 138, 183, 87, 61, 245, 150, 56,
+ 82, 158, 224, 50, 114, 125, 122, 172, 161, 129, 234, 70, 63, 245,
+ 136, 30, 136, 9, 128, 220, 229, 157, 222, 195, 149, 189, 70, 8, 71,
+ 40, 195, 93, 27, 7, 234, 164, 175, 102, 201, 149, 115, 248, 179,
+ 125, 66, 122, 194, 26, 61, 218, 198, 181, 152, 140, 199, 48, 148,
+ 31, 14, 241, 197, 3, 70, 128, 239, 32, 86, 15, 215, 86, 245, 190,
+ 95, 141, 41, 111, 0, 232, 28, 152, 67, 87, 197, 255, 118, 13, 251,
+ 71, 84, 22, 231, 134, 188, 175, 115, 138, 37, 199, 5, 238, 199, 2,
+ 99, 203, 75, 62, 231, 21, 150, 239, 94, 201, 185, 219, 58, 210, 228,
+ 151, 131, 76, 148, 104, 60, 74, 82, 6, 168, 49, 251, 182, 3, 232,
+ 173, 210, 201, 19, 101, 166, 7, 94, 11, 194, 211, 146, 229, 75, 241,
+ 15, 50, 187, 36, 175, 78, 227, 98, 224, 3, 95, 209, 93, 126, 112,
+ 178, 29, 18, 108, 241, 232, 79, 210, 41, 2, 238, 208, 190, 171, 134,
+ 147, 188, 191, 229, 122, 32, 209, 166, 118, 129, 223, 130, 214, 195,
+ 89, 67, 94, 218, 155, 185, 0, 144, 255, 132, 213, 25, 59, 83, 242,
+ 57, 69, 148, 109, 133, 61, 163, 30, 214, 254, 54, 169, 3, 217, 77,
+ 66, 123, 193, 204, 199, 109, 123, 49, 186, 223, 229, 8, 230, 164,
+ 171, 196, 145, 225, 10, 111, 248, 111, 164, 216, 54, 225, 253])
+ };
+
+ // Replace the last block of each ciphertext with bad padding below for decryption errors
+ var badPadding = {
+ 128: {
+ "zeroPadChar": new Uint8Array([238, 27, 248, 169, 218, 138, 164, 86, 207, 102, 36, 223, 6, 166, 77, 14]),
+ "bigPadChar": new Uint8Array([91, 67, 119, 104, 252, 238, 175, 144, 17, 75, 12, 163, 212, 52, 46, 51]),
+ "inconsistentPadChars": new Uint8Array([135, 101, 112, 208, 3, 106, 226, 20, 25, 219, 79, 94, 58, 212, 242, 192])
+ },
+ 192: {
+ "zeroPadChar": new Uint8Array([22, 158, 50, 15, 168, 47, 19, 194, 182, 133, 184, 65, 36, 43, 177, 254]),
+ "bigPadChar": new Uint8Array([207, 110, 28, 160, 165, 213, 48, 213, 163, 242, 15, 78, 96, 117, 106, 87]),
+ "inconsistentPadChars": new Uint8Array([143, 227, 12, 112, 216, 207, 136, 167, 78, 137, 93, 30, 50, 75, 102, 101])
+ },
+ 256: {
+ "zeroPadChar": new Uint8Array([1, 253, 141, 214, 30, 193, 254, 68, 140, 200, 157, 110, 200, 89, 177, 129]),
+ "bigPadChar": new Uint8Array([88, 7, 110, 221, 74, 34, 97, 109, 99, 25, 189, 222, 94, 90, 27, 60]),
+ "inconsistentPadChars": new Uint8Array([152, 54, 60, 148, 59, 136, 193, 21, 77, 140, 170, 67, 120, 74, 106, 62])
+ }
+ };
+
+ var keyLengths = [128, 192, 256];
+
+ // All the scenarios that should succeed, if the key has "encrypt" usage
+ var passing = [];
+ keyLengths.forEach(function(keyLength) {
+ passing.push({
+ name: "AES-CBC " + keyLength.toString() + "-bit key",
+ keyBuffer: keyBytes[keyLength],
+ key: null,
+ algorithm: {name: "AES-CBC", iv: iv},
+ plaintext: plaintext,
+ result: ciphertext[keyLength]
+ });
+ });
+
+ // Scenarios that should fail because of a bad iv length, causing an OperationError
+ var failing = [];
+ keyLengths.forEach(function(keyLength) {
+ var shortIv = iv.slice(0, 8);
+ failing.push({
+ name: "AES-CBC " + keyLength.toString() + "-bit key, 64-bit IV",
+ keyBuffer: keyBytes[keyLength],
+ key: null,
+ algorithm: {name: "AES-CBC", iv: shortIv},
+ plaintext: plaintext,
+ result: ciphertext[keyLength]
+ });
+
+ var longIv = new Uint8Array(24);
+ longIv.set(iv, 0);
+ longIv.set(iv.slice(0, 8), 16);
+ failing.push({
+ name: "AES-CBC " + keyLength.toString() + "-bit key, 192-bit IV",
+ keyBuffer: keyBytes[keyLength],
+ key: null,
+ algorithm: {name: "AES-CBC", iv: longIv},
+ plaintext: plaintext,
+ result: ciphertext[keyLength]
+ });
+ });
+
+ // Scenarios that should fail decryption because of bad padding
+ var decryptionFailing = [];
+ keyLengths.forEach(function(keyLength) {
+ ["zeroPadChar", "bigPadChar", "inconsistentPadChars"].forEach(function(paddingProblem) {
+ var badCiphertext = new Uint8Array(ciphertext[keyLength].byteLength);
+ badCiphertext.set(ciphertext[keyLength].slice(0, ciphertext[keyLength].byteLength - 16));
+ badCiphertext.set(badPadding[keyLength][paddingProblem]);
+
+ decryptionFailing.push({
+ name: "AES-CBC " + keyLength.toString() + "-bit key, " + paddingProblem,
+ keyBuffer: keyBytes[keyLength],
+ key: null,
+ algorithm: {name: "AES-CBC", iv: iv},
+ plaintext: plaintext,
+ result: badCiphertext
+ });
+ });
+ });
+
+ return {passing: passing, failing: failing, decryptionFailing: decryptionFailing};
+}
diff --git a/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_ctr.https.any.js b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_ctr.https.any.js
new file mode 100644
index 0000000000..9f0c66900e
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_ctr.https.any.js
@@ -0,0 +1,6 @@
+// META: title=WebCryptoAPI: encrypt() Using AES-CTR
+// META: script=aes_ctr_vectors.js
+// META: script=aes.js
+// META: timeout=long
+
+run_test();
diff --git a/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_gcm.https.any.js b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_gcm.https.any.js
new file mode 100644
index 0000000000..6e3a6efb12
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_gcm.https.any.js
@@ -0,0 +1,7 @@
+// META: title=WebCryptoAPI: encrypt() Using AES-GCM w/ 96-bit iv
+// META: script=aes_gcm_96_iv_fixtures.js
+// META: script=aes_gcm_vectors.js
+// META: script=aes.js
+// META: timeout=long
+
+run_test();
diff --git a/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_gcm_256_iv.https.any.js b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_gcm_256_iv.https.any.js
new file mode 100644
index 0000000000..92900fb13a
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_gcm_256_iv.https.any.js
@@ -0,0 +1,7 @@
+// META: title=WebCryptoAPI: encrypt() Using AES-GCM w/ 256-bit iv
+// META: script=aes_gcm_256_iv_fixtures.js
+// META: script=aes_gcm_vectors.js
+// META: script=aes.js
+// META: timeout=long
+
+run_test();
diff --git a/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_gcm_256_iv_fixtures.js b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_gcm_256_iv_fixtures.js
new file mode 100644
index 0000000000..9cdbbbb790
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_gcm_256_iv_fixtures.js
@@ -0,0 +1,210 @@
+function getFixtures() {
+ // Before we can really start, we need to fill a bunch of buffers with data
+ var plaintext = new Uint8Array([
+ 84, 104, 105, 115, 32, 115, 112, 101, 99, 105, 102, 105, 99, 97, 116, 105,
+ 111, 110, 32, 100, 101, 115, 99, 114, 105, 98, 101, 115, 32, 97, 32, 74, 97,
+ 118, 97, 83, 99, 114, 105, 112, 116, 32, 65, 80, 73, 32, 102, 111, 114, 32,
+ 112, 101, 114, 102, 111, 114, 109, 105, 110, 103, 32, 98, 97, 115, 105, 99,
+ 32, 99, 114, 121, 112, 116, 111, 103, 114, 97, 112, 104, 105, 99, 32, 111,
+ 112, 101, 114, 97, 116, 105, 111, 110, 115, 32, 105, 110, 32, 119, 101, 98,
+ 32, 97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 115, 44, 32, 115,
+ 117, 99, 104, 32, 97, 115, 32, 104, 97, 115, 104, 105, 110, 103, 44, 32,
+ 115, 105, 103, 110, 97, 116, 117, 114, 101, 32, 103, 101, 110, 101, 114, 97,
+ 116, 105, 111, 110, 32, 97, 110, 100, 32, 118, 101, 114, 105, 102, 105, 99,
+ 97, 116, 105, 111, 110, 44, 32, 97, 110, 100, 32, 101, 110, 99, 114, 121,
+ 112, 116, 105, 111, 110, 32, 97, 110, 100, 32, 100, 101, 99, 114, 121, 112,
+ 116, 105, 111, 110, 46, 32, 65, 100, 100, 105, 116, 105, 111, 110, 97, 108,
+ 108, 121, 44, 32, 105, 116, 32, 100, 101, 115, 99, 114, 105, 98, 101, 115,
+ 32, 97, 110, 32, 65, 80, 73, 32, 102, 111, 114, 32, 97, 112, 112, 108, 105,
+ 99, 97, 116, 105, 111, 110, 115, 32, 116, 111, 32, 103, 101, 110, 101, 114,
+ 97, 116, 101, 32, 97, 110, 100, 47, 111, 114, 32, 109, 97, 110, 97, 103,
+ 101, 32, 116, 104, 101, 32, 107, 101, 121, 105, 110, 103, 32, 109, 97, 116,
+ 101, 114, 105, 97, 108, 32, 110, 101, 99, 101, 115, 115, 97, 114, 121, 32,
+ 116, 111, 32, 112, 101, 114, 102, 111, 114, 109, 32, 116, 104, 101, 115,
+ 101, 32, 111, 112, 101, 114, 97, 116, 105, 111, 110, 115, 46, 32, 85, 115,
+ 101, 115, 32, 102, 111, 114, 32, 116, 104, 105, 115, 32, 65, 80, 73, 32,
+ 114, 97, 110, 103, 101, 32, 102, 114, 111, 109, 32, 117, 115, 101, 114, 32,
+ 111, 114, 32, 115, 101, 114, 118, 105, 99, 101, 32, 97, 117, 116, 104, 101,
+ 110, 116, 105, 99, 97, 116, 105, 111, 110, 44, 32, 100, 111, 99, 117, 109,
+ 101, 110, 116, 32, 111, 114, 32, 99, 111, 100, 101, 32, 115, 105, 103, 110,
+ 105, 110, 103, 44, 32, 97, 110, 100, 32, 116, 104, 101, 32, 99, 111, 110,
+ 102, 105, 100, 101, 110, 116, 105, 97, 108, 105, 116, 121, 32, 97, 110, 100,
+ 32, 105, 110, 116, 101, 103, 114, 105, 116, 121, 32, 111, 102, 32, 99, 111,
+ 109, 109, 117, 110, 105, 99, 97, 116, 105, 111, 110, 115, 46,
+ ]);
+
+ // We want some random key bytes of various sizes.
+ // These were randomly generated from a script.
+ var keyBytes = {
+ 128: new Uint8Array([
+ 222, 192, 212, 252, 191, 60, 71, 65, 200, 146, 218, 189, 28, 212, 192, 78,
+ ]),
+ 192: new Uint8Array([
+ 208, 238, 131, 65, 63, 68, 196, 63, 186, 208, 61, 207, 166, 18, 99, 152,
+ 29, 109, 221, 95, 240, 30, 28, 246,
+ ]),
+ 256: new Uint8Array([
+ 103, 105, 56, 35, 251, 29, 88, 7, 63, 145, 236, 233, 204, 58, 249, 16,
+ 229, 83, 38, 22, 164, 210, 123, 19, 235, 123, 116, 216, 0, 11, 191, 48,
+ ]),
+ };
+
+ // AES-GCM needs an IV of no more than 2^64 - 1 bytes. Arbitrary 32 bytes is okay then.
+ var iv = new Uint8Array([
+ 58, 146, 115, 42, 166, 234, 57, 191, 57, 134, 224, 199, 63, 169, 32, 0, 32,
+ 33, 117, 56, 94, 248, 173, 234, 194, 200, 115, 53, 235, 146, 141, 212,
+ ]);
+
+ // Authenticated encryption via AES-GCM requires additional data that
+ // will be checked. We use the ASCII encoded Editorial Note
+ // following the Abstract of the Web Cryptography API recommendation.
+ var additionalData = new Uint8Array([
+ 84, 104, 101, 114, 101, 32, 97, 114, 101, 32, 55, 32, 102, 117, 114, 116,
+ 104, 101, 114, 32, 101, 100, 105, 116, 111, 114, 105, 97, 108, 32, 110, 111,
+ 116, 101, 115, 32, 105, 110, 32, 116, 104, 101, 32, 100, 111, 99, 117, 109,
+ 101, 110, 116, 46,
+ ]);
+
+ // The length of the tag defaults to 16 bytes (128 bit).
+ var tag = {
+ 128: new Uint8Array([
+ 194, 226, 198, 253, 239, 28, 197, 240, 123, 216, 176, 151, 239, 200, 184,
+ 183,
+ ]),
+ 192: new Uint8Array([
+ 183, 57, 32, 144, 164, 76, 121, 77, 58, 86, 62, 132, 53, 130, 96, 225,
+ ]),
+ 256: new Uint8Array([
+ 188, 239, 241, 48, 159, 21, 213, 0, 241, 42, 85, 76, 194, 28, 49, 60,
+ ]),
+ };
+
+ var tag_with_empty_ad = {
+ 128: new Uint8Array([
+ 222, 51, 11, 23, 36, 222, 250, 248, 27, 98, 30, 81, 150, 35, 220, 198,
+ ]),
+ 192: new Uint8Array([
+ 243, 11, 130, 112, 169, 239, 114, 238, 185, 219, 93, 1, 95, 108, 184, 183,
+ ]),
+ 256: new Uint8Array([
+ 244, 186, 86, 203, 154, 37, 191, 248, 246, 57, 139, 130, 224, 47, 217,
+ 238,
+ ]),
+ };
+
+ // Results. These were created using the Python cryptography module.
+
+ // AES-GCM produces ciphertext and a tag.
+ var ciphertext = {
+ 128: new Uint8Array([
+ 180, 241, 40, 183, 105, 52, 147, 238, 224, 175, 175, 236, 168, 244, 241,
+ 121, 9, 202, 225, 237, 56, 216, 253, 254, 186, 102, 111, 207, 228, 190,
+ 130, 177, 159, 246, 6, 53, 249, 113, 228, 254, 81, 126, 253, 191, 100, 43,
+ 251, 147, 107, 91, 166, 231, 201, 241, 180, 214, 112, 47, 123, 164, 186,
+ 134, 54, 65, 22, 181, 201, 82, 236, 59, 52, 139, 172, 39, 41, 89, 123, 62,
+ 102, 167, 82, 150, 250, 93, 96, 169, 135, 89, 245, 255, 164, 192, 169,
+ 159, 25, 16, 139, 145, 76, 4, 144, 131, 148, 197, 204, 46, 23, 110, 193,
+ 228, 127, 120, 242, 24, 54, 240, 181, 162, 98, 244, 249, 68, 134, 122,
+ 126, 151, 38, 108, 116, 68, 150, 109, 38, 194, 21, 159, 140, 205, 183, 35,
+ 97, 151, 186, 120, 145, 22, 235, 22, 210, 223, 187, 143, 162, 183, 93,
+ 196, 104, 51, 96, 53, 234, 250, 184, 76, 237, 157, 37, 203, 226, 87, 222,
+ 75, 240, 95, 218, 222, 64, 81, 165, 75, 201, 216, 190, 13, 116, 217, 69,
+ 66, 47, 161, 68, 247, 74, 253, 157, 181, 162, 121, 53, 32, 91, 124, 230,
+ 105, 224, 17, 187, 50, 61, 77, 103, 79, 71, 57, 163, 116, 234, 149, 27,
+ 105, 24, 31, 159, 3, 128, 130, 42, 94, 125, 200, 142, 251, 148, 201, 17,
+ 149, 232, 84, 50, 17, 18, 203, 186, 226, 164, 227, 202, 76, 65, 16, 163,
+ 224, 132, 52, 31, 101, 129, 72, 171, 159, 42, 177, 253, 98, 86, 201, 95,
+ 117, 62, 12, 205, 78, 36, 126, 196, 121, 89, 185, 37, 161, 66, 181, 117,
+ 186, 71, 124, 132, 110, 120, 27, 246, 163, 18, 13, 90, 200, 127, 82, 209,
+ 241, 170, 73, 247, 137, 96, 244, 254, 251, 119, 71, 156, 27, 107, 53, 33,
+ 45, 22, 0, 144, 48, 32, 11, 116, 21, 125, 246, 217, 171, 158, 224, 142,
+ 234, 141, 242, 168, 89, 154, 66, 227, 161, 182, 96, 1, 88, 78, 12, 7, 239,
+ 30, 206, 31, 89, 111, 107, 42, 37, 241, 148, 232, 1, 8, 251, 117, 146,
+ 183, 9, 48, 39, 94, 59, 70, 230, 26, 165, 97, 156, 140, 141, 31, 62, 10,
+ 206, 55, 48, 207, 0, 197, 202, 197, 108, 133, 175, 80, 4, 16, 154, 223,
+ 255, 4, 196, 188, 178, 240, 29, 13, 120, 5, 225, 202, 3, 35, 225, 158, 92,
+ 152, 73, 205, 107, 157, 224, 245, 99, 194, 171, 156, 245, 247, 183, 165,
+ 40, 62, 200, 110, 29, 151, 206, 100, 175, 88, 36, 242, 90, 4, 82, 73, 250,
+ 140, 245, 217, 9, 153, 35, 242, 206, 78, 197, 121, 115, 15, 80, 128, 101,
+ 191, 240, 91, 151, 249, 62, 62, 244, 18, 3, 17, 135, 222, 210, 93, 149,
+ 123,
+ ]),
+
+ 192: new Uint8Array([
+ 126, 160, 166, 112, 227, 212, 106, 186, 175, 70, 24, 28, 86, 149, 31, 154,
+ 156, 190, 244, 132, 44, 61, 149, 242, 105, 67, 17, 136, 7, 146, 153, 170,
+ 200, 214, 142, 205, 170, 225, 85, 44, 241, 159, 255, 234, 10, 13, 37, 48,
+ 255, 21, 141, 176, 60, 117, 73, 130, 247, 204, 144, 102, 167, 89, 203,
+ 235, 229, 129, 122, 253, 124, 179, 115, 118, 163, 157, 67, 141, 122, 146,
+ 209, 11, 112, 5, 230, 117, 123, 184, 243, 99, 83, 10, 31, 166, 96, 1, 121,
+ 44, 10, 241, 24, 43, 184, 187, 25, 239, 246, 176, 108, 230, 127, 25, 42,
+ 67, 202, 140, 179, 104, 159, 75, 103, 43, 248, 98, 166, 179, 67, 0, 163,
+ 227, 84, 40, 129, 227, 198, 205, 7, 156, 16, 185, 24, 166, 59, 218, 197,
+ 114, 74, 34, 126, 22, 226, 226, 85, 212, 69, 83, 163, 185, 68, 109, 182,
+ 54, 209, 237, 96, 184, 32, 53, 127, 175, 13, 146, 141, 115, 164, 184, 98,
+ 245, 174, 223, 46, 32, 167, 39, 103, 19, 210, 80, 131, 254, 103, 249, 247,
+ 29, 120, 31, 105, 241, 103, 169, 249, 93, 153, 74, 56, 53, 239, 157, 132,
+ 236, 169, 246, 242, 24, 113, 97, 128, 238, 152, 148, 31, 84, 8, 52, 105,
+ 198, 116, 103, 132, 48, 199, 23, 90, 24, 29, 63, 41, 117, 191, 57, 31,
+ 209, 128, 60, 119, 175, 84, 141, 177, 165, 169, 195, 35, 163, 105, 146,
+ 157, 209, 93, 149, 105, 160, 93, 231, 78, 201, 92, 235, 200, 89, 37, 50,
+ 181, 30, 213, 242, 59, 156, 219, 19, 158, 17, 224, 81, 108, 52, 87, 248,
+ 101, 23, 39, 107, 67, 151, 103, 230, 126, 202, 184, 118, 226, 18, 29, 93,
+ 37, 208, 40, 82, 113, 35, 157, 145, 152, 50, 253, 140, 47, 141, 192, 1,
+ 148, 114, 40, 10, 112, 79, 227, 16, 105, 247, 31, 49, 102, 195, 75, 183,
+ 172, 254, 188, 42, 89, 77, 38, 104, 1, 180, 106, 61, 71, 70, 35, 160, 103,
+ 101, 244, 26, 226, 37, 159, 155, 4, 107, 222, 219, 136, 37, 24, 246, 44,
+ 23, 44, 248, 132, 108, 59, 179, 99, 145, 132, 82, 53, 203, 111, 150, 55,
+ 123, 51, 214, 165, 108, 124, 179, 131, 174, 139, 224, 114, 96, 218, 181,
+ 243, 128, 198, 98, 115, 92, 95, 165, 23, 229, 108, 146, 14, 244, 162, 37,
+ 85, 201, 33, 44, 92, 106, 112, 185, 16, 189, 42, 114, 109, 59, 124, 131,
+ 16, 211, 31, 97, 29, 135, 61, 150, 75, 250, 207, 129, 38, 205, 187, 186,
+ 55, 207, 232, 24, 48, 232, 49, 226, 16, 12, 27, 70, 31, 124, 128, 218,
+ 100, 91, 200, 184, 78, 252, 100, 235, 62, 43, 69, 214, 163, 65, 14, 44,
+ 180,
+ ]),
+
+ 256: new Uint8Array([
+ 8, 97, 235, 113, 70, 32, 135, 131, 210, 209, 124, 160, 255, 182, 9, 29,
+ 125, 193, 27, 240, 129, 46, 2, 137, 169, 142, 61, 7, 145, 54, 170, 207,
+ 159, 111, 39, 95, 87, 63, 162, 27, 6, 18, 219, 215, 116, 34, 90, 57, 114,
+ 244, 102, 145, 67, 6, 51, 152, 247, 165, 242, 116, 100, 219, 177, 72, 177,
+ 17, 110, 67, 93, 219, 100, 217, 20, 207, 89, 154, 45, 37, 105, 83, 67,
+ 162, 140, 235, 129, 40, 177, 202, 174, 54, 148, 55, 156, 193, 232, 249,
+ 134, 163, 195, 51, 114, 116, 65, 38, 73, 99, 96, 249, 224, 69, 17, 119,
+ 186, 188, 181, 43, 78, 156, 76, 138, 226, 63, 5, 248, 9, 94, 26, 1, 2,
+ 235, 39, 174, 74, 47, 183, 22, 40, 47, 47, 13, 100, 119, 12, 67, 178, 184,
+ 56, 167, 238, 143, 13, 44, 208, 185, 151, 108, 6, 17, 52, 122, 182, 210,
+ 207, 42, 219, 37, 74, 94, 126, 36, 249, 37, 32, 4, 218, 44, 238, 69, 56,
+ 219, 31, 77, 173, 46, 187, 103, 36, 112, 213, 252, 40, 87, 164, 240, 163,
+ 159, 32, 129, 125, 178, 108, 47, 28, 31, 36, 42, 115, 36, 14, 145, 195,
+ 156, 191, 46, 163, 249, 181, 31, 90, 73, 30, 72, 57, 223, 63, 60, 79, 140,
+ 14, 117, 31, 145, 222, 156, 121, 237, 32, 145, 143, 96, 12, 254, 35, 21,
+ 21, 59, 168, 171, 154, 217, 0, 59, 202, 175, 103, 214, 192, 175, 26, 18,
+ 43, 54, 176, 222, 75, 22, 7, 122, 253, 224, 145, 61, 42, 208, 73, 237, 84,
+ 141, 209, 213, 228, 46, 244, 59, 9, 68, 6, 35, 88, 189, 10, 62, 9, 85, 28,
+ 44, 82, 19, 153, 160, 178, 240, 56, 160, 244, 201, 173, 77, 61, 20, 227,
+ 30, 180, 167, 16, 105, 185, 193, 95, 207, 41, 23, 134, 78, 198, 182, 93,
+ 24, 89, 247, 231, 75, 233, 194, 137, 242, 114, 194, 190, 130, 138, 238,
+ 94, 137, 193, 194, 115, 137, 190, 207, 169, 83, 155, 14, 210, 160, 129,
+ 195, 161, 234, 221, 255, 114, 67, 98, 12, 93, 41, 65, 183, 244, 103, 247,
+ 101, 82, 246, 125, 87, 125, 78, 21, 186, 102, 205, 20, 40, 32, 201, 174,
+ 15, 52, 240, 217, 180, 162, 108, 6, 211, 41, 18, 135, 232, 184, 18, 188,
+ 169, 157, 190, 76, 166, 75, 176, 127, 39, 251, 22, 203, 153, 80, 49, 241,
+ 124, 137, 151, 123, 204, 43, 159, 190, 177, 196, 18, 117, 169, 46, 152,
+ 251, 45, 25, 164, 27, 145, 214, 228, 55, 15, 2, 131, 216, 80, 255, 204,
+ 175, 100, 59, 145, 15, 103, 40, 33, 45, 255, 200, 254, 172, 138, 20, 58,
+ 87, 182, 192, 148, 219, 41, 88, 230, 229, 70, 249,
+ ]),
+ };
+
+ return {
+ plaintext,
+ keyBytes,
+ iv,
+ additionalData,
+ tag,
+ tag_with_empty_ad,
+ ciphertext,
+ };
+}
diff --git a/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_gcm_96_iv_fixtures.js b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_gcm_96_iv_fixtures.js
new file mode 100644
index 0000000000..bb00e2d7dd
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_gcm_96_iv_fixtures.js
@@ -0,0 +1,209 @@
+function getFixtures() {
+ // Before we can really start, we need to fill a bunch of buffers with data
+ var plaintext = new Uint8Array([
+ 84, 104, 105, 115, 32, 115, 112, 101, 99, 105, 102, 105, 99, 97, 116, 105,
+ 111, 110, 32, 100, 101, 115, 99, 114, 105, 98, 101, 115, 32, 97, 32, 74, 97,
+ 118, 97, 83, 99, 114, 105, 112, 116, 32, 65, 80, 73, 32, 102, 111, 114, 32,
+ 112, 101, 114, 102, 111, 114, 109, 105, 110, 103, 32, 98, 97, 115, 105, 99,
+ 32, 99, 114, 121, 112, 116, 111, 103, 114, 97, 112, 104, 105, 99, 32, 111,
+ 112, 101, 114, 97, 116, 105, 111, 110, 115, 32, 105, 110, 32, 119, 101, 98,
+ 32, 97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 115, 44, 32, 115,
+ 117, 99, 104, 32, 97, 115, 32, 104, 97, 115, 104, 105, 110, 103, 44, 32,
+ 115, 105, 103, 110, 97, 116, 117, 114, 101, 32, 103, 101, 110, 101, 114, 97,
+ 116, 105, 111, 110, 32, 97, 110, 100, 32, 118, 101, 114, 105, 102, 105, 99,
+ 97, 116, 105, 111, 110, 44, 32, 97, 110, 100, 32, 101, 110, 99, 114, 121,
+ 112, 116, 105, 111, 110, 32, 97, 110, 100, 32, 100, 101, 99, 114, 121, 112,
+ 116, 105, 111, 110, 46, 32, 65, 100, 100, 105, 116, 105, 111, 110, 97, 108,
+ 108, 121, 44, 32, 105, 116, 32, 100, 101, 115, 99, 114, 105, 98, 101, 115,
+ 32, 97, 110, 32, 65, 80, 73, 32, 102, 111, 114, 32, 97, 112, 112, 108, 105,
+ 99, 97, 116, 105, 111, 110, 115, 32, 116, 111, 32, 103, 101, 110, 101, 114,
+ 97, 116, 101, 32, 97, 110, 100, 47, 111, 114, 32, 109, 97, 110, 97, 103,
+ 101, 32, 116, 104, 101, 32, 107, 101, 121, 105, 110, 103, 32, 109, 97, 116,
+ 101, 114, 105, 97, 108, 32, 110, 101, 99, 101, 115, 115, 97, 114, 121, 32,
+ 116, 111, 32, 112, 101, 114, 102, 111, 114, 109, 32, 116, 104, 101, 115,
+ 101, 32, 111, 112, 101, 114, 97, 116, 105, 111, 110, 115, 46, 32, 85, 115,
+ 101, 115, 32, 102, 111, 114, 32, 116, 104, 105, 115, 32, 65, 80, 73, 32,
+ 114, 97, 110, 103, 101, 32, 102, 114, 111, 109, 32, 117, 115, 101, 114, 32,
+ 111, 114, 32, 115, 101, 114, 118, 105, 99, 101, 32, 97, 117, 116, 104, 101,
+ 110, 116, 105, 99, 97, 116, 105, 111, 110, 44, 32, 100, 111, 99, 117, 109,
+ 101, 110, 116, 32, 111, 114, 32, 99, 111, 100, 101, 32, 115, 105, 103, 110,
+ 105, 110, 103, 44, 32, 97, 110, 100, 32, 116, 104, 101, 32, 99, 111, 110,
+ 102, 105, 100, 101, 110, 116, 105, 97, 108, 105, 116, 121, 32, 97, 110, 100,
+ 32, 105, 110, 116, 101, 103, 114, 105, 116, 121, 32, 111, 102, 32, 99, 111,
+ 109, 109, 117, 110, 105, 99, 97, 116, 105, 111, 110, 115, 46,
+ ]);
+
+ // We want some random key bytes of various sizes.
+ // These were randomly generated from a script.
+ var keyBytes = {
+ 128: new Uint8Array([
+ 222, 192, 212, 252, 191, 60, 71, 65, 200, 146, 218, 189, 28, 212, 192, 78,
+ ]),
+ 192: new Uint8Array([
+ 208, 238, 131, 65, 63, 68, 196, 63, 186, 208, 61, 207, 166, 18, 99, 152,
+ 29, 109, 221, 95, 240, 30, 28, 246,
+ ]),
+ 256: new Uint8Array([
+ 103, 105, 56, 35, 251, 29, 88, 7, 63, 145, 236, 233, 204, 58, 249, 16,
+ 229, 83, 38, 22, 164, 210, 123, 19, 235, 123, 116, 216, 0, 11, 191, 48,
+ ]),
+ };
+
+ // AES-GCM specification recommends that the IV should be 96 bits long.
+ var iv = new Uint8Array([
+ 58, 146, 115, 42, 166, 234, 57, 191, 57, 134, 224, 199,
+ ]);
+
+ // Authenticated encryption via AES-GCM requires additional data that
+ // will be checked. We use the ASCII encoded Editorial Note
+ // following the Abstract of the Web Cryptography API recommendation.
+ var additionalData = new Uint8Array([
+ 84, 104, 101, 114, 101, 32, 97, 114, 101, 32, 55, 32, 102, 117, 114, 116,
+ 104, 101, 114, 32, 101, 100, 105, 116, 111, 114, 105, 97, 108, 32, 110, 111,
+ 116, 101, 115, 32, 105, 110, 32, 116, 104, 101, 32, 100, 111, 99, 117, 109,
+ 101, 110, 116, 46,
+ ]);
+
+ // The length of the tag defaults to 16 bytes (128 bit).
+ var tag = {
+ 128: new Uint8Array([
+ 180, 165, 14, 180, 121, 113, 220, 168, 254, 117, 18, 66, 110, 98, 146,
+ 240,
+ ]),
+ 192: new Uint8Array([
+ 43, 102, 63, 121, 1, 120, 252, 2, 95, 149, 99, 207, 161, 10, 139, 159,
+ ]),
+ 256: new Uint8Array([
+ 53, 0, 70, 11, 217, 64, 250, 241, 175, 160, 37, 78, 92, 160, 107, 38,
+ ]),
+ };
+
+ var tag_with_empty_ad = {
+ 128: new Uint8Array([
+ 168, 116, 195, 94, 178, 179, 227, 160, 158, 207, 188, 132, 23, 137, 246,
+ 129,
+ ]),
+ 192: new Uint8Array([
+ 111, 84, 157, 153, 12, 219, 247, 161, 220, 24, 0, 74, 203, 228, 83, 201,
+ ]),
+ 256: new Uint8Array([
+ 125, 85, 225, 240, 220, 112, 144, 9, 168, 179, 251, 128, 126, 147, 131,
+ 244,
+ ]),
+ };
+
+ // Results. These were created using OpenSSL.
+
+ // AES-GCM produces ciphertext and a tag.
+ var ciphertext = {
+ 128: new Uint8Array([
+ 46, 244, 139, 198, 120, 180, 9, 39, 83, 58, 203, 107, 69, 71, 8, 165, 132,
+ 200, 94, 31, 228, 120, 170, 81, 241, 29, 38, 175, 99, 215, 241, 157, 144,
+ 97, 35, 42, 36, 231, 2, 94, 214, 140, 67, 48, 189, 242, 21, 208, 110, 179,
+ 30, 90, 181, 105, 242, 17, 244, 42, 42, 36, 125, 228, 82, 250, 87, 199,
+ 95, 168, 210, 57, 174, 20, 220, 188, 107, 65, 242, 43, 217, 122, 145, 160,
+ 100, 139, 54, 135, 175, 139, 115, 89, 15, 236, 234, 83, 2, 135, 51, 125,
+ 63, 168, 184, 235, 148, 68, 132, 124, 166, 171, 53, 68, 94, 187, 31, 68,
+ 119, 47, 252, 73, 63, 138, 154, 84, 167, 0, 54, 33, 11, 200, 22, 91, 245,
+ 62, 64, 192, 7, 180, 210, 52, 233, 23, 24, 181, 50, 230, 63, 118, 228, 24,
+ 1, 242, 75, 62, 196, 222, 122, 154, 227, 125, 89, 73, 112, 100, 154, 249,
+ 61, 141, 126, 145, 46, 247, 102, 242, 62, 148, 94, 172, 128, 181, 110, 6,
+ 7, 209, 58, 222, 51, 169, 83, 189, 200, 47, 22, 80, 49, 169, 227, 245,
+ 165, 24, 96, 152, 228, 14, 252, 199, 193, 148, 46, 84, 49, 248, 198, 7, 0,
+ 134, 255, 174, 151, 103, 48, 154, 178, 198, 103, 45, 226, 118, 19, 41, 85,
+ 2, 55, 71, 7, 6, 0, 24, 150, 145, 227, 162, 126, 102, 248, 134, 116, 174,
+ 215, 217, 166, 160, 140, 129, 21, 220, 131, 110, 242, 94, 249, 103, 151,
+ 154, 81, 225, 35, 111, 131, 129, 111, 172, 214, 168, 30, 169, 71, 210, 64,
+ 68, 56, 228, 223, 248, 233, 234, 140, 86, 145, 121, 29, 232, 55, 165, 61,
+ 175, 147, 66, 33, 92, 6, 209, 241, 149, 73, 77, 9, 104, 2, 154, 247, 92,
+ 87, 159, 191, 113, 82, 122, 148, 89, 28, 122, 111, 93, 110, 60, 42, 34,
+ 70, 161, 14, 50, 153, 238, 189, 173, 99, 10, 118, 252, 1, 28, 67, 151,
+ 114, 46, 78, 181, 78, 233, 183, 6, 254, 57, 29, 53, 118, 175, 80, 97, 156,
+ 237, 219, 196, 71, 80, 161, 248, 139, 96, 124, 181, 154, 124, 149, 219,
+ 47, 90, 11, 98, 63, 21, 64, 144, 77, 161, 204, 127, 209, 209, 7, 86, 65,
+ 39, 142, 251, 183, 43, 227, 120, 155, 72, 70, 204, 89, 227, 199, 203, 28,
+ 128, 23, 104, 188, 215, 32, 190, 18, 156, 57, 105, 7, 179, 155, 136, 236,
+ 82, 173, 156, 170, 124, 210, 22, 11, 27, 182, 236, 109, 200, 172, 227, 72,
+ 37, 1, 175, 9, 214, 227, 23, 141, 169, 215, 77, 134, 76, 229, 169, 241,
+ 116, 222, 157, 77, 158, 213, 118, 223, 17, 31, 212, 97, 21, 237, 83, 2,
+ 218, 239, 59, 147, 30, 169, 97, 12,
+ ]),
+
+ 192: new Uint8Array([
+ 129, 16, 61, 38, 99, 56, 226, 139, 71, 251, 211, 15, 91, 152, 159, 219,
+ 112, 147, 210, 73, 97, 204, 203, 240, 183, 243, 104, 241, 37, 67, 169,
+ 198, 56, 76, 96, 202, 250, 212, 177, 157, 93, 115, 247, 176, 19, 3, 229,
+ 102, 75, 200, 252, 222, 197, 58, 31, 44, 123, 151, 9, 191, 88, 123, 35,
+ 48, 47, 25, 149, 35, 191, 219, 223, 94, 251, 152, 109, 171, 225, 31, 236,
+ 252, 223, 174, 128, 238, 173, 32, 32, 79, 22, 100, 112, 215, 153, 128, 63,
+ 158, 247, 18, 215, 81, 247, 208, 91, 28, 223, 222, 170, 9, 135, 210, 143,
+ 47, 247, 132, 183, 252, 84, 19, 78, 85, 17, 215, 20, 51, 32, 124, 149,
+ 172, 129, 202, 161, 217, 207, 24, 45, 177, 11, 106, 17, 108, 17, 12, 6,
+ 62, 90, 132, 2, 54, 96, 90, 30, 239, 216, 173, 76, 67, 7, 221, 62, 124,
+ 228, 156, 243, 31, 111, 160, 192, 188, 87, 107, 182, 138, 95, 122, 152,
+ 202, 51, 118, 100, 124, 67, 220, 116, 52, 99, 15, 39, 2, 14, 209, 173,
+ 119, 88, 6, 174, 106, 236, 150, 28, 189, 112, 161, 224, 186, 58, 110, 91,
+ 54, 211, 132, 149, 7, 188, 77, 232, 118, 197, 43, 107, 101, 179, 44, 195,
+ 159, 4, 124, 5, 30, 48, 227, 251, 199, 72, 98, 177, 206, 234, 228, 58,
+ 191, 150, 28, 211, 29, 182, 138, 141, 249, 152, 142, 244, 203, 210, 128,
+ 143, 244, 44, 187, 251, 221, 101, 152, 31, 119, 194, 51, 27, 167, 215,
+ 122, 244, 193, 224, 191, 198, 210, 2, 143, 185, 207, 145, 228, 193, 153,
+ 207, 119, 167, 75, 145, 43, 17, 1, 42, 146, 164, 21, 15, 164, 221, 216,
+ 140, 122, 248, 49, 19, 246, 84, 214, 176, 226, 118, 140, 130, 123, 163,
+ 217, 61, 198, 243, 182, 217, 52, 127, 190, 127, 135, 18, 239, 163, 195,
+ 102, 136, 227, 128, 38, 244, 49, 208, 229, 249, 126, 157, 100, 72, 246,
+ 10, 102, 163, 241, 155, 112, 165, 95, 32, 61, 66, 24, 233, 123, 236, 190,
+ 124, 214, 65, 135, 114, 118, 122, 222, 196, 47, 120, 120, 64, 117, 253,
+ 165, 28, 17, 152, 104, 119, 10, 53, 140, 109, 79, 246, 246, 28, 104, 228,
+ 175, 102, 71, 246, 183, 79, 30, 31, 186, 32, 64, 146, 72, 228, 1, 175,
+ 252, 115, 254, 95, 66, 87, 196, 134, 41, 115, 165, 206, 253, 245, 147,
+ 137, 163, 230, 235, 238, 77, 218, 74, 157, 65, 97, 43, 198, 130, 190, 195,
+ 142, 22, 166, 4, 179, 184, 167, 254, 156, 243, 38, 46, 66, 68, 252, 252,
+ 161, 209, 83, 177, 128, 115, 92, 158, 182, 177, 185, 23, 39, 138, 245, 29,
+ 216, 17, 178, 142, 225, 135, 8, 115,
+ ]),
+
+ 256: new Uint8Array([
+ 191, 72, 167, 1, 122, 218, 148, 218, 15, 239, 202, 129, 96, 108, 229, 157,
+ 138, 161, 232, 71, 80, 188, 118, 61, 75, 105, 120, 201, 14, 102, 102, 240,
+ 111, 131, 180, 83, 95, 73, 2, 138, 205, 56, 9, 137, 227, 235, 73, 71, 200,
+ 62, 246, 0, 223, 209, 3, 255, 113, 112, 63, 103, 41, 154, 77, 13, 149, 89,
+ 94, 79, 132, 193, 114, 40, 158, 33, 55, 242, 130, 109, 136, 69, 124, 130,
+ 150, 40, 69, 211, 224, 154, 209, 243, 65, 58, 230, 253, 31, 21, 72, 102,
+ 18, 250, 139, 230, 235, 11, 108, 184, 133, 108, 181, 138, 188, 189, 91,
+ 91, 115, 216, 68, 9, 229, 30, 154, 132, 118, 219, 183, 235, 177, 197, 221,
+ 58, 13, 90, 126, 198, 74, 87, 162, 226, 7, 51, 184, 15, 209, 81, 86, 138,
+ 169, 154, 12, 206, 58, 187, 228, 177, 68, 65, 62, 68, 141, 93, 241, 105,
+ 29, 239, 20, 102, 222, 49, 209, 18, 162, 247, 200, 240, 122, 244, 204,
+ 148, 67, 58, 118, 164, 95, 230, 68, 242, 203, 138, 145, 132, 6, 224, 206,
+ 234, 131, 183, 137, 249, 2, 11, 254, 123, 235, 70, 14, 136, 207, 76, 57,
+ 22, 38, 49, 197, 219, 123, 43, 241, 191, 64, 211, 152, 178, 140, 165, 1,
+ 189, 52, 79, 184, 213, 56, 215, 182, 27, 27, 70, 243, 101, 255, 50, 108,
+ 210, 105, 13, 22, 218, 176, 238, 36, 113, 251, 18, 218, 138, 214, 193, 21,
+ 122, 224, 125, 118, 134, 161, 174, 130, 86, 233, 149, 151, 33, 31, 88, 63,
+ 91, 63, 209, 145, 158, 109, 42, 176, 43, 23, 151, 49, 101, 199, 35, 101,
+ 158, 139, 198, 219, 209, 125, 221, 205, 99, 69, 142, 165, 139, 110, 220,
+ 184, 226, 238, 149, 161, 175, 171, 167, 170, 65, 19, 156, 166, 219, 231,
+ 87, 20, 226, 58, 210, 134, 110, 160, 176, 118, 250, 73, 86, 213, 116, 53,
+ 114, 24, 101, 34, 185, 59, 237, 47, 39, 206, 67, 12, 74, 236, 130, 7, 249,
+ 217, 203, 245, 122, 14, 230, 53, 203, 126, 93, 131, 51, 2, 0, 231, 161,
+ 111, 42, 126, 173, 121, 80, 179, 59, 186, 133, 236, 252, 188, 149, 99,
+ 221, 182, 55, 5, 38, 83, 132, 43, 123, 233, 174, 208, 140, 165, 77, 1,
+ 202, 46, 6, 183, 207, 246, 125, 37, 110, 226, 61, 155, 194, 198, 153, 107,
+ 1, 8, 0, 23, 124, 18, 4, 144, 235, 146, 77, 220, 123, 152, 114, 219, 127,
+ 59, 126, 10, 79, 106, 198, 11, 27, 111, 11, 155, 1, 137, 38, 74, 3, 248,
+ 225, 221, 203, 86, 4, 148, 25, 88, 144, 185, 38, 114, 139, 48, 74, 82,
+ 172, 36, 115, 193, 223, 220, 144, 69, 91, 5, 83, 56, 138, 63,
+ ]),
+ };
+
+ return {
+ plaintext,
+ keyBytes,
+ iv,
+ additionalData,
+ tag,
+ tag_with_empty_ad,
+ ciphertext,
+ };
+}
diff --git a/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_gcm_vectors.js b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_gcm_vectors.js
new file mode 100644
index 0000000000..965fe9564d
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/aes_gcm_vectors.js
@@ -0,0 +1,76 @@
+// aes_gcm_vectors.js
+
+// The following function returns an array of test vectors
+// for the subtleCrypto encrypt method.
+//
+// Each test vector has the following fields:
+// name - a unique name for this vector
+// keyBuffer - an arrayBuffer with the key data in raw form
+// key - a CryptoKey object for the keyBuffer. INITIALLY null! You must fill this in first to use it!
+// algorithm - the value of the AlgorithmIdentifier parameter to provide to encrypt
+// plaintext - the text to encrypt
+// result - the expected result (usually just ciphertext, sometimes with added authentication)
+function getTestVectors() {
+ const {
+ plaintext,
+ keyBytes,
+ iv,
+ additionalData,
+ tag,
+ tag_with_empty_ad,
+ ciphertext,
+ } = getFixtures();
+
+ var keyLengths = [128, 192, 256];
+ var tagLengths = [32, 64, 96, 104, 112, 120, 128];
+
+ // All the scenarios that should succeed, if the key has "encrypt" usage
+ var passing = [];
+ keyLengths.forEach(function(keyLength) {
+ tagLengths.forEach(function(tagLength) {
+ var byteCount = tagLength / 8;
+
+ var result = new Uint8Array(ciphertext[keyLength].byteLength + byteCount);
+ result.set(ciphertext[keyLength], 0);
+ result.set(tag[keyLength].slice(0, byteCount), ciphertext[keyLength].byteLength);
+ passing.push({
+ name: "AES-GCM " + keyLength.toString() + "-bit key, " + tagLength.toString() + "-bit tag, " + (iv.byteLength << 3).toString() + "-bit iv",
+ keyBuffer: keyBytes[keyLength],
+ key: null,
+ algorithm: {name: "AES-GCM", iv: iv, additionalData: additionalData, tagLength: tagLength},
+ plaintext: plaintext,
+ result: result
+ });
+
+ var noadresult = new Uint8Array(ciphertext[keyLength].byteLength + byteCount);
+ noadresult.set(ciphertext[keyLength], 0);
+ noadresult.set(tag_with_empty_ad[keyLength].slice(0, byteCount), ciphertext[keyLength].byteLength);
+ passing.push({
+ name: "AES-GCM " + keyLength.toString() + "-bit key, no additional data, " + tagLength.toString() + "-bit tag, " + (iv.byteLength << 3).toString() + "-bit iv",
+ keyBuffer: keyBytes[keyLength],
+ key: null,
+ algorithm: {name: "AES-GCM", iv: iv, tagLength: tagLength},
+ plaintext: plaintext,
+ result: noadresult
+ });
+ });
+ });
+
+ // Scenarios that should fail because of a bad tag length, causing an OperationError
+ var failing = [];
+ keyLengths.forEach(function(keyLength) {
+ // First, make some tests for bad tag lengths
+ [24, 48, 72, 95, 129].forEach(function(badTagLength) {
+ failing.push({
+ name: "AES-GCM " + keyLength.toString() + "-bit key, " + (iv.byteLength << 3).toString() + "-bit iv, " + "illegal tag length " + badTagLength.toString() + "-bits",
+ keyBuffer: keyBytes[keyLength],
+ key: null,
+ algorithm: {name: "AES-GCM", iv: iv, additionalData: additionalData, tagLength: badTagLength},
+ plaintext: plaintext,
+ result: ciphertext[keyLength]
+ });
+ });
+ });
+
+ return {passing: passing, failing: failing, decryptionFailing: []};
+}
diff --git a/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/rsa.js b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/rsa.js
new file mode 100644
index 0000000000..5eae06e474
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/rsa.js
@@ -0,0 +1,378 @@
+
+function run_test() {
+ var subtle = self.crypto.subtle; // Change to test prefixed implementations
+
+ // When are all these tests really done? When all the promises they use have resolved.
+ var all_promises = [];
+
+ // Source file rsa_vectors.js provides the getTestVectors method
+ // for the RSA-OAEP algorithm that drives these tests.
+ var vectors = getTestVectors();
+ var passingVectors = vectors.passing;
+ var failingVectors = vectors.failing;
+
+ // Test decryption, first, because encryption tests rely on that working
+ passingVectors.forEach(function(vector) {
+ var promise = importVectorKeys(vector, ["encrypt"], ["decrypt"])
+ .then(function(vectors) {
+ // Get a one byte longer plaintext to encrypt
+ if (!("ciphertext" in vector)) {
+ return;
+ }
+
+ promise_test(function(test) {
+ return subtle.decrypt(vector.algorithm, vector.privateKey, vector.ciphertext)
+ .then(function(plaintext) {
+ assert_true(equalBuffers(plaintext, vector.plaintext, "Decryption works"));
+ }, function(err) {
+ assert_unreached("Decryption should not throw error " + vector.name + ": " + err.message + "'");
+ });
+ }, vector.name + " decryption");
+
+ }, function(err) {
+ // We need a failed test if the importVectorKey operation fails, so
+ // we know we never tested encryption
+ promise_test(function(test) {
+ assert_unreached("importVectorKeys failed for " + vector.name + ". Message: ''" + err.message + "''");
+ }, "importVectorKeys step: " + vector.name + " decryption");
+ });
+
+ all_promises.push(promise);
+ });
+
+ // Test decryption with an altered buffer
+ passingVectors.forEach(function(vector) {
+ var promise = importVectorKeys(vector, ["encrypt"], ["decrypt"])
+ .then(function(vectors) {
+ // Get a one byte longer plaintext to encrypt
+ if (!("ciphertext" in vector)) {
+ return;
+ }
+
+ promise_test(function(test) {
+ var ciphertext = copyBuffer(vector.ciphertext);
+ var operation = subtle.decrypt(vector.algorithm, vector.privateKey, ciphertext)
+ .then(function(plaintext) {
+ assert_true(equalBuffers(plaintext, vector.plaintext, "Decryption works"));
+ }, function(err) {
+ assert_unreached("Decryption should not throw error " + vector.name + ": " + err.message + "'");
+ });
+ ciphertext[0] = 255 - ciphertext[0];
+ return operation;
+ }, vector.name + " decryption with altered ciphertext");
+
+ }, function(err) {
+ // We need a failed test if the importVectorKey operation fails, so
+ // we know we never tested encryption
+ promise_test(function(test) {
+ assert_unreached("importVectorKeys failed for " + vector.name + ". Message: ''" + err.message + "''");
+ }, "importVectorKeys step: " + vector.name + " decryption with altered ciphertext");
+ });
+
+ all_promises.push(promise);
+ });
+
+ // Check for failures due to using publicKey to decrypt.
+ passingVectors.forEach(function(vector) {
+ var promise = importVectorKeys(vector, ["encrypt"], ["decrypt"])
+ .then(function(vectors) {
+ promise_test(function(test) {
+ return subtle.decrypt(vector.algorithm, vector.publicKey, vector.ciphertext)
+ .then(function(plaintext) {
+ assert_unreached("Should have thrown error for using publicKey to decrypt in " + vector.name + ": " + err.message + "'");
+ }, function(err) {
+ assert_equals(err.name, "InvalidAccessError", "Should throw InvalidAccessError instead of " + err.message);
+ });
+ }, vector.name + " using publicKey to decrypt");
+
+ }, function(err) {
+ // We need a failed test if the importVectorKey operation fails, so
+ // we know we never tested encryption
+ promise_test(function(test) {
+ assert_unreached("importVectorKeys failed for " + vector.name + ". Message: ''" + err.message + "''");
+ }, "importVectorKeys step: " + vector.name + " using publicKey to decrypt");
+ });
+
+ all_promises.push(promise);
+ });
+
+
+ // Check for failures due to no "decrypt" usage.
+ passingVectors.forEach(function(originalVector) {
+ var vector = Object.assign({}, originalVector);
+
+ var promise = importVectorKeys(vector, ["encrypt"], ["unwrapKey"])
+ .then(function(vectors) {
+ // Get a one byte longer plaintext to encrypt
+ promise_test(function(test) {
+ return subtle.decrypt(vector.algorithm, vector.publicKey, vector.ciphertext)
+ .then(function(plaintext) {
+ assert_unreached("Should have thrown error for no decrypt usage in " + vector.name + ": " + err.message + "'");
+ }, function(err) {
+ assert_equals(err.name, "InvalidAccessError", "Should throw InvalidAccessError instead of " + err.message);
+ });
+ }, vector.name + " no decrypt usage");
+
+ }, function(err) {
+ // We need a failed test if the importVectorKey operation fails, so
+ // we know we never tested encryption
+ promise_test(function(test) {
+ assert_unreached("importVectorKeys failed for " + vector.name + ". Message: ''" + err.message + "''");
+ }, "importVectorKeys step: " + vector.name + " no decrypt usage");
+ });
+
+ all_promises.push(promise);
+ });
+
+
+ // Check for successful encryption even if plaintext is altered after call.
+ passingVectors.forEach(function(vector) {
+ var promise = importVectorKeys(vector, ["encrypt"], ["decrypt"])
+ .then(function(vectors) {
+ promise_test(function(test) {
+ var plaintext = copyBuffer(vector.plaintext);
+ var operation = subtle.encrypt(vector.algorithm, vector.publicKey, plaintext)
+ .then(function(ciphertext) {
+ assert_equals(ciphertext.byteLength * 8, vector.privateKey.algorithm.modulusLength, "Ciphertext length matches modulus length");
+ // Can we get the original plaintext back via decrypt?
+ return subtle.decrypt(vector.algorithm, vector.privateKey, ciphertext)
+ .then(function(result) {
+ assert_true(equalBuffers(result, vector.plaintext), "Round trip returns original plaintext");
+ return ciphertext;
+ }, function(err) {
+ assert_unreached("decrypt error for test " + vector.name + ": " + err.message + "'");
+ });
+ })
+ .then(function(priorCiphertext) {
+ // Will a second encrypt give us different ciphertext, as it should?
+ return subtle.encrypt(vector.algorithm, vector.publicKey, vector.plaintext)
+ .then(function(ciphertext) {
+ assert_false(equalBuffers(priorCiphertext, ciphertext), "Two encrypts give different results")
+ }, function(err) {
+ assert_unreached("second time encrypt error for test " + vector.name + ": '" + err.message + "'");
+ });
+ }, function(err) {
+ assert_unreached("decrypt error for test " + vector.name + ": '" + err.message + "'");
+ });
+
+ plaintext[0] = 255 - plaintext[0];
+ return operation;
+ }, vector.name + " with altered plaintext");
+
+ }, function(err) {
+ // We need a failed test if the importVectorKey operation fails, so
+ // we know we never tested encryption
+ promise_test(function(test) {
+ assert_unreached("importVectorKeys failed for " + vector.name + ". Message: ''" + err.message + "''");
+ }, "importVectorKeys step: " + vector.name + " with altered plaintext");
+ });
+
+ all_promises.push(promise);
+ });
+
+ // Check for successful encryption.
+ passingVectors.forEach(function(vector) {
+ var promise = importVectorKeys(vector, ["encrypt"], ["decrypt"])
+ .then(function(vectors) {
+ promise_test(function(test) {
+ return subtle.encrypt(vector.algorithm, vector.publicKey, vector.plaintext)
+ .then(function(ciphertext) {
+ assert_equals(ciphertext.byteLength * 8, vector.privateKey.algorithm.modulusLength, "Ciphertext length matches modulus length");
+
+ // Can we get the original plaintext back via decrypt?
+ return subtle.decrypt(vector.algorithm, vector.privateKey, ciphertext)
+ .then(function(result) {
+ assert_true(equalBuffers(result, vector.plaintext), "Round trip returns original plaintext");
+ return ciphertext;
+ }, function(err) {
+ assert_unreached("decrypt error for test " + vector.name + ": " + err.message + "'");
+ });
+ })
+ .then(function(priorCiphertext) {
+ // Will a second encrypt give us different ciphertext, as it should?
+ return subtle.encrypt(vector.algorithm, vector.publicKey, vector.plaintext)
+ .then(function(ciphertext) {
+ assert_false(equalBuffers(priorCiphertext, ciphertext), "Two encrypts give different results")
+ }, function(err) {
+ assert_unreached("second time encrypt error for test " + vector.name + ": '" + err.message + "'");
+ });
+ }, function(err) {
+ assert_unreached("decrypt error for test " + vector.name + ": '" + err.message + "'");
+ });
+ }, vector.name);
+
+ }, function(err) {
+ // We need a failed test if the importVectorKey operation fails, so
+ // we know we never tested encryption
+ promise_test(function(test) {
+ assert_unreached("importVectorKeys failed for " + vector.name + ". Message: ''" + err.message + "''");
+ }, "importVectorKeys step: " + vector.name);
+ });
+
+ all_promises.push(promise);
+ });
+
+ // Check for failures due to too long plaintext.
+ passingVectors.forEach(function(vector) {
+ var promise = importVectorKeys(vector, ["encrypt"], ["decrypt"])
+ .then(function(vectors) {
+ // Get a one byte longer plaintext to encrypt
+ var plaintext = new Uint8Array(vector.plaintext.byteLength + 1);
+ plaintext.set(plaintext, 0);
+ plaintext.set(new Uint8Array([32]), vector.plaintext.byteLength);
+ promise_test(function(test) {
+ return subtle.encrypt(vector.algorithm, vector.publicKey, plaintext)
+ .then(function(ciphertext) {
+ assert_unreached("Should have thrown error for too long plaintext in " + vector.name + ": " + err.message + "'");
+ }, function(err) {
+ assert_equals(err.name, "OperationError", "Should throw OperationError instead of " + err.message);
+ });
+ }, vector.name + " too long plaintext");
+
+ }, function(err) {
+ // We need a failed test if the importVectorKey operation fails, so
+ // we know we never tested encryption
+ promise_test(function(test) {
+ assert_unreached("importVectorKeys failed for " + vector.name + ". Message: ''" + err.message + "''");
+ }, "importVectorKeys step: " + vector.name + " too long plaintext");
+ });
+
+ all_promises.push(promise);
+ });
+
+
+ // Check for failures due to using privateKey to encrypt.
+ passingVectors.forEach(function(vector) {
+ var promise = importVectorKeys(vector, ["encrypt"], ["decrypt"])
+ .then(function(vectors) {
+ promise_test(function(test) {
+ return subtle.encrypt(vector.algorithm, vector.privateKey, vector.plaintext)
+ .then(function(ciphertext) {
+ assert_unreached("Should have thrown error for using privateKey to encrypt in " + vector.name + ": " + err.message + "'");
+ }, function(err) {
+ assert_equals(err.name, "InvalidAccessError", "Should throw InvalidAccessError instead of " + err.message);
+ });
+ }, vector.name + " using privateKey to encrypt");
+
+ }, function(err) {
+ // We need a failed test if the importVectorKey operation fails, so
+ // we know we never tested encryption
+ promise_test(function(test) {
+ assert_unreached("importVectorKeys failed for " + vector.name + ". Message: ''" + err.message + "''");
+ }, "importVectorKeys step: " + vector.name + " using privateKey to encrypt");
+ });
+
+ all_promises.push(promise);
+ });
+
+
+ // Check for failures due to no "encrypt usage".
+ passingVectors.forEach(function(originalVector) {
+ var vector = Object.assign({}, originalVector);
+
+ var promise = importVectorKeys(vector, [], ["decrypt"])
+ .then(function(vectors) {
+ // Get a one byte longer plaintext to encrypt
+ promise_test(function(test) {
+ return subtle.encrypt(vector.algorithm, vector.publicKey, vector.plaintext)
+ .then(function(ciphertext) {
+ assert_unreached("Should have thrown error for no encrypt usage in " + vector.name + ": " + err.message + "'");
+ }, function(err) {
+ assert_equals(err.name, "InvalidAccessError", "Should throw InvalidAccessError instead of " + err.message);
+ });
+ }, vector.name + " no encrypt usage");
+
+ }, function(err) {
+ // We need a failed test if the importVectorKey operation fails, so
+ // we know we never tested encryption
+ promise_test(function(test) {
+ assert_unreached("importVectorKeys failed for " + vector.name + ". Message: ''" + err.message + "''");
+ }, "importVectorKeys step: " + vector.name + " no encrypt usage");
+ });
+
+ all_promises.push(promise);
+ });
+
+ promise_test(function() {
+ return Promise.all(all_promises)
+ .then(function() {done();})
+ .catch(function() {done();})
+ }, "setup");
+
+ // A test vector has all needed fields for encryption, EXCEPT that the
+ // key field may be null. This function replaces that null with the Correct
+ // CryptoKey object.
+ //
+ // Returns a Promise that yields an updated vector on success.
+ function importVectorKeys(vector, publicKeyUsages, privateKeyUsages) {
+ var publicPromise, privatePromise;
+
+ if (vector.publicKey !== null) {
+ publicPromise = new Promise(function(resolve, reject) {
+ resolve(vector);
+ });
+ } else {
+ publicPromise = subtle.importKey(vector.publicKeyFormat, vector.publicKeyBuffer, {name: vector.algorithm.name, hash: vector.hash}, false, publicKeyUsages)
+ .then(function(key) {
+ vector.publicKey = key;
+ return vector;
+ }); // Returns a copy of the sourceBuffer it is sent.
+ function copyBuffer(sourceBuffer) {
+ var source = new Uint8Array(sourceBuffer);
+ var copy = new Uint8Array(sourceBuffer.byteLength)
+
+ for (var i=0; i<source.byteLength; i++) {
+ copy[i] = source[i];
+ }
+
+ return copy;
+ }
+
+ }
+
+ if (vector.privateKey !== null) {
+ privatePromise = new Promise(function(resolve, reject) {
+ resolve(vector);
+ });
+ } else {
+ privatePromise = subtle.importKey(vector.privateKeyFormat, vector.privateKeyBuffer, {name: vector.algorithm.name, hash: vector.hash}, false, privateKeyUsages)
+ .then(function(key) {
+ vector.privateKey = key;
+ return vector;
+ });
+ }
+
+ return Promise.all([publicPromise, privatePromise]);
+ }
+
+ // Returns a copy of the sourceBuffer it is sent.
+ function copyBuffer(sourceBuffer) {
+ var source = new Uint8Array(sourceBuffer);
+ var copy = new Uint8Array(sourceBuffer.byteLength)
+
+ for (var i=0; i<source.byteLength; i++) {
+ copy[i] = source[i];
+ }
+
+ return copy;
+ }
+
+ function equalBuffers(a, b) {
+ if (a.byteLength !== b.byteLength) {
+ return false;
+ }
+
+ var aBytes = new Uint8Array(a);
+ var bBytes = new Uint8Array(b);
+
+ for (var i=0; i<a.byteLength; i++) {
+ if (aBytes[i] !== bBytes[i]) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ return;
+}
diff --git a/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/rsa_oaep.https.any.js b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/rsa_oaep.https.any.js
new file mode 100644
index 0000000000..20fd17c571
--- /dev/null
+++ b/testing/web-platform/tests/WebCryptoAPI/encrypt_decrypt/rsa_oaep.https.any.js
@@ -0,0 +1,6 @@
+// META: title=WebCryptoAPI: encrypt() Using RSA-OAEP
+// META: script=rsa_vectors.js
+// META: script=rsa.js
+// META: timeout=long
+
+run_test();