[WebCrypto] Add layout tests covering EC P-521
authorzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Aug 2017 07:31:32 +0000 (07:31 +0000)
committerzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Aug 2017 07:31:32 +0000 (07:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=175659

Reviewed by Jiewen Tan.

Add layout tests that cover operations with 521-bit elliptic curves.
The newly-introduced tests are skipped on all platforms for now since
no implementation provides support just yet. The already-existing tests
are modified in a way that only tests the EC P-521 capability optionally,
if e.g. P-521 key imports are successful, without affecting the tests for
P-256 and P-384 operations.

The newly-introduced tests are mirros of existing P-256 and P-384 tests,
but they specifically test the P-521 capabilities and use appropriate
curve information (X and Y coordinates for the EC public key, D for the
EC private key) for that type of elliptic curve.

* crypto/subtle/ec-import-pkcs8-key-export-pkcs8-key-p521-expected.txt: Added.
* crypto/subtle/ec-import-pkcs8-key-export-pkcs8-key-p521.html: Added.
* crypto/subtle/ec-import-spki-key-export-spki-key-p521-expected.txt: Added.
* crypto/subtle/ec-import-spki-key-export-spki-key-p521.html: Added.
* crypto/subtle/ecdh-derive-bits-length-limits-expected.txt:
* crypto/subtle/ecdh-derive-bits-length-limits.html:
* crypto/subtle/ecdh-generate-export-jwk-key-p521-expected.txt: Added.
* crypto/subtle/ecdh-generate-export-jwk-key-p521.html: Added.
* crypto/subtle/ecdh-generate-export-key-pkcs8-p521-expected.txt: Added.
* crypto/subtle/ecdh-generate-export-key-pkcs8-p521.html: Added.
* crypto/subtle/ecdh-generate-export-key-raw-p521-expected.txt: Added.
* crypto/subtle/ecdh-generate-export-key-raw-p521.html: Added.
* crypto/subtle/ecdh-generate-export-key-spki-p521-expected.txt: Added.
* crypto/subtle/ecdh-generate-export-key-spki-p521.html: Added.
* crypto/subtle/ecdh-generate-key-p521-expected.txt: Added.
* crypto/subtle/ecdh-generate-key-p521.html: Added.
* crypto/subtle/ecdh-import-jwk-private-key-p521-expected.txt: Added.
* crypto/subtle/ecdh-import-jwk-private-key-p521.html: Added.
* crypto/subtle/ecdh-import-jwk-public-key-p521-expected.txt: Added.
* crypto/subtle/ecdh-import-jwk-public-key-p521.html: Added.
* crypto/subtle/ecdh-import-pkcs8-key-p521-expected.txt: Added.
* crypto/subtle/ecdh-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey-expected.txt: Added.
* crypto/subtle/ecdh-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey.html: Added.
* crypto/subtle/ecdh-import-pkcs8-key-p521.html: Added.
* crypto/subtle/ecdh-import-raw-key-p521-expected.txt: Added.
* crypto/subtle/ecdh-import-raw-key-p521.html: Added.
* crypto/subtle/ecdh-import-spki-key-ecdh-identifier-expected.txt:
* crypto/subtle/ecdh-import-spki-key-ecdh-identifier.html:
* crypto/subtle/ecdh-import-spki-key-p521-expected.txt: Added.
* crypto/subtle/ecdh-import-spki-key-p521.html: Added.
* crypto/subtle/ecdsa-generate-key-sign-verify-p521-expected.txt: Added.
* crypto/subtle/ecdsa-generate-key-sign-verify-p521.html: Added.
* crypto/subtle/ecdsa-import-jwk-public-key-alg-521-expected.txt: Added.
* crypto/subtle/ecdsa-import-jwk-public-key-alg-521.html: Added.
* crypto/subtle/ecdsa-import-key-sign-p521-expected.txt: Added.
* crypto/subtle/ecdsa-import-key-sign-p521.html: Added.
* crypto/subtle/ecdsa-import-key-verify-p521-expected.txt: Added.
* crypto/subtle/ecdsa-import-key-verify-p521.html: Added.
* crypto/subtle/ecdsa-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey-expected.txt: Added.
* crypto/subtle/ecdsa-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey.html: Added.
* platform/gtk/TestExpectations:
* platform/ios/TestExpectations:
* platform/mac/TestExpectations:
* platform/wpe/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221345 268f45cc-cd09-0410-ab3c-d52691b4dbfc

45 files changed:
LayoutTests/ChangeLog
LayoutTests/crypto/subtle/ec-import-pkcs8-key-export-pkcs8-key-p521-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ec-import-pkcs8-key-export-pkcs8-key-p521.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ec-import-spki-key-export-spki-key-p521-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ec-import-spki-key-export-spki-key-p521.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-derive-bits-length-limits-expected.txt
LayoutTests/crypto/subtle/ecdh-derive-bits-length-limits.html
LayoutTests/crypto/subtle/ecdh-generate-export-jwk-key-p521-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-generate-export-jwk-key-p521.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-generate-export-key-pkcs8-p521-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-generate-export-key-pkcs8-p521.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-generate-export-key-raw-p521-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-generate-export-key-raw-p521.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-generate-export-key-spki-p521-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-generate-export-key-spki-p521.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-generate-key-p521-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-generate-key-p521.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-import-jwk-private-key-p521-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-import-jwk-private-key-p521.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-import-jwk-public-key-p521-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-import-jwk-public-key-p521.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-import-pkcs8-key-p521-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-import-pkcs8-key-p521.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-import-raw-key-p521-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-import-raw-key-p521.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-import-spki-key-ecdh-identifier-expected.txt
LayoutTests/crypto/subtle/ecdh-import-spki-key-ecdh-identifier.html
LayoutTests/crypto/subtle/ecdh-import-spki-key-p521-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-import-spki-key-p521.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-generate-key-sign-verify-p521-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-generate-key-sign-verify-p521.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-jwk-public-key-alg-521-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-jwk-public-key-alg-521.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-key-sign-p521-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-key-sign-p521.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-key-verify-p521-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-key-verify-p521.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey.html [new file with mode: 0644]
LayoutTests/platform/gtk/TestExpectations
LayoutTests/platform/ios/TestExpectations
LayoutTests/platform/mac/TestExpectations
LayoutTests/platform/wpe/TestExpectations

index 6231952..07c7201 100644 (file)
@@ -1,3 +1,67 @@
+2017-08-30  Zan Dobersek  <zdobersek@igalia.com>
+
+        [WebCrypto] Add layout tests covering EC P-521
+        https://bugs.webkit.org/show_bug.cgi?id=175659
+
+        Reviewed by Jiewen Tan.
+
+        Add layout tests that cover operations with 521-bit elliptic curves.
+        The newly-introduced tests are skipped on all platforms for now since
+        no implementation provides support just yet. The already-existing tests
+        are modified in a way that only tests the EC P-521 capability optionally,
+        if e.g. P-521 key imports are successful, without affecting the tests for
+        P-256 and P-384 operations.
+
+        The newly-introduced tests are mirros of existing P-256 and P-384 tests,
+        but they specifically test the P-521 capabilities and use appropriate
+        curve information (X and Y coordinates for the EC public key, D for the
+        EC private key) for that type of elliptic curve.
+
+        * crypto/subtle/ec-import-pkcs8-key-export-pkcs8-key-p521-expected.txt: Added.
+        * crypto/subtle/ec-import-pkcs8-key-export-pkcs8-key-p521.html: Added.
+        * crypto/subtle/ec-import-spki-key-export-spki-key-p521-expected.txt: Added.
+        * crypto/subtle/ec-import-spki-key-export-spki-key-p521.html: Added.
+        * crypto/subtle/ecdh-derive-bits-length-limits-expected.txt:
+        * crypto/subtle/ecdh-derive-bits-length-limits.html:
+        * crypto/subtle/ecdh-generate-export-jwk-key-p521-expected.txt: Added.
+        * crypto/subtle/ecdh-generate-export-jwk-key-p521.html: Added.
+        * crypto/subtle/ecdh-generate-export-key-pkcs8-p521-expected.txt: Added.
+        * crypto/subtle/ecdh-generate-export-key-pkcs8-p521.html: Added.
+        * crypto/subtle/ecdh-generate-export-key-raw-p521-expected.txt: Added.
+        * crypto/subtle/ecdh-generate-export-key-raw-p521.html: Added.
+        * crypto/subtle/ecdh-generate-export-key-spki-p521-expected.txt: Added.
+        * crypto/subtle/ecdh-generate-export-key-spki-p521.html: Added.
+        * crypto/subtle/ecdh-generate-key-p521-expected.txt: Added.
+        * crypto/subtle/ecdh-generate-key-p521.html: Added.
+        * crypto/subtle/ecdh-import-jwk-private-key-p521-expected.txt: Added.
+        * crypto/subtle/ecdh-import-jwk-private-key-p521.html: Added.
+        * crypto/subtle/ecdh-import-jwk-public-key-p521-expected.txt: Added.
+        * crypto/subtle/ecdh-import-jwk-public-key-p521.html: Added.
+        * crypto/subtle/ecdh-import-pkcs8-key-p521-expected.txt: Added.
+        * crypto/subtle/ecdh-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey-expected.txt: Added.
+        * crypto/subtle/ecdh-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey.html: Added.
+        * crypto/subtle/ecdh-import-pkcs8-key-p521.html: Added.
+        * crypto/subtle/ecdh-import-raw-key-p521-expected.txt: Added.
+        * crypto/subtle/ecdh-import-raw-key-p521.html: Added.
+        * crypto/subtle/ecdh-import-spki-key-ecdh-identifier-expected.txt:
+        * crypto/subtle/ecdh-import-spki-key-ecdh-identifier.html:
+        * crypto/subtle/ecdh-import-spki-key-p521-expected.txt: Added.
+        * crypto/subtle/ecdh-import-spki-key-p521.html: Added.
+        * crypto/subtle/ecdsa-generate-key-sign-verify-p521-expected.txt: Added.
+        * crypto/subtle/ecdsa-generate-key-sign-verify-p521.html: Added.
+        * crypto/subtle/ecdsa-import-jwk-public-key-alg-521-expected.txt: Added.
+        * crypto/subtle/ecdsa-import-jwk-public-key-alg-521.html: Added.
+        * crypto/subtle/ecdsa-import-key-sign-p521-expected.txt: Added.
+        * crypto/subtle/ecdsa-import-key-sign-p521.html: Added.
+        * crypto/subtle/ecdsa-import-key-verify-p521-expected.txt: Added.
+        * crypto/subtle/ecdsa-import-key-verify-p521.html: Added.
+        * crypto/subtle/ecdsa-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey-expected.txt: Added.
+        * crypto/subtle/ecdsa-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey.html: Added.
+        * platform/gtk/TestExpectations:
+        * platform/ios/TestExpectations:
+        * platform/mac/TestExpectations:
+        * platform/wpe/TestExpectations:
+
 2017-08-29  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         REGRESSION(r210287) On drop, event.dataTransfer.getData("text") returns an empty string when dragging an image
diff --git a/LayoutTests/crypto/subtle/ec-import-pkcs8-key-export-pkcs8-key-p521-expected.txt b/LayoutTests/crypto/subtle/ec-import-pkcs8-key-export-pkcs8-key-p521-expected.txt
new file mode 100644 (file)
index 0000000..d305840
--- /dev/null
@@ -0,0 +1,11 @@
+Test importing a P-521 PKCS8 ECDH key and exporting it in PKCS8 format
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Importing a key...
+PASS bytesToHexString(privateKey) is pkcs8KeyHex
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/ec-import-pkcs8-key-export-pkcs8-key-p521.html b/LayoutTests/crypto/subtle/ec-import-pkcs8-key-export-pkcs8-key-p521.html
new file mode 100644 (file)
index 0000000..4cd7bdf
--- /dev/null
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a P-521 PKCS8 ECDH key and exporting it in PKCS8 format");
+
+jsTestIsAsync = true;
+
+var pkcs8KeyHex = "3081ee020100301006072a8648ce3d020106052b810400230481d63081d302010104420160ccf72d28b6df9768c30f67e77a000ecdb6e20381d8ee6f5474d6a612c39b7f3d361e1e9901f4cc573dcfc7da3eeadcb3e10532ca12d39df5ed39a5156c3e3ceba18189038186000400e9a76aed2acda29ba2a5dbdc1f04c6160bc16c6d16b737a557f9dcbc8efb79dd1b9eabfc0a911ea3fd574176e2cbf32caa9babb505b04f30ecf369e6bec91d1ac201a8aa718c0c293b085d7902a314cab6e8048e458cc28c7da4fff2fcbf3da6d42fee94de5e0a3fb34342780e3f9df7b424911d6efb8628079566b50efe6971271eea";
+var pkcs8Key = hexStringToUint8Array(pkcs8KeyHex);
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("pkcs8", pkcs8Key, {name: "ECDH", namedCurve: "P-521"}, extractable, ["deriveKey", "deriveBits"]).then(function(key) {
+    return crypto.subtle.exportKey("pkcs8", key);
+}).then(function(result) {
+    privateKey = result;
+
+    shouldBe("bytesToHexString(privateKey)", "pkcs8KeyHex");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/ec-import-spki-key-export-spki-key-p521-expected.txt b/LayoutTests/crypto/subtle/ec-import-spki-key-export-spki-key-p521-expected.txt
new file mode 100644 (file)
index 0000000..f4a5d33
--- /dev/null
@@ -0,0 +1,11 @@
+Test importing a P-521 SPKI ECDH key and exporting it in SPKI format
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Importing a key...
+PASS bytesToHexString(publicKey) is spkiKeyHex
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/ec-import-spki-key-export-spki-key-p521.html b/LayoutTests/crypto/subtle/ec-import-spki-key-export-spki-key-p521.html
new file mode 100644 (file)
index 0000000..cb708ff
--- /dev/null
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a P-521 SPKI ECDH key and exporting it in SPKI format");
+
+jsTestIsAsync = true;
+
+var spkiKeyHex = "30819b301006072a8648ce3d020106052b81040023038186000400e9a76aed2acda29ba2a5dbdc1f04c6160bc16c6d16b737a557f9dcbc8efb79dd1b9eabfc0a911ea3fd574176e2cbf32caa9babb505b04f30ecf369e6bec91d1ac201a8aa718c0c293b085d7902a314cab6e8048e458cc28c7da4fff2fcbf3da6d42fee94de5e0a3fb34342780e3f9df7b424911d6efb8628079566b50efe6971271eea";
+var spkiKey = hexStringToUint8Array(spkiKeyHex);
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("spki", spkiKey, {name: "ECDH", namedCurve: "P-521"}, extractable, [ ]).then(function(key) {
+    return crypto.subtle.exportKey("spki", key);
+}).then(function(result) {
+    publicKey = result;
+
+    shouldBe("bytesToHexString(publicKey)", "spkiKeyHex");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
index f62a5ba..0b51ecf 100644 (file)
@@ -13,6 +13,7 @@ PASS deriveBits(..., 8) successfully derived 8 bits for a P-384 curve
 PASS deriveBits(..., 384) successfully derived 384 bits for a P-384 curve
 PASS Bit derivations for EC P-384 with minimum and maximum lengths succeeded
 PASS deriveBits(P384, 384 + 8) rejected promise  with OperationError: The operation failed for an operation-specific reason.
+Bit derivations for EC P-521 skipped, likely due to missing P-521 supprot.
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 719945c..d2a4be2 100644 (file)
@@ -40,9 +40,23 @@ var jwkPublicKeyP384 = {
     x: "H9zo2G4WwHFSUqdN7jaChKg5fdmBxRLMP-_xWbcGDd4GzQBZBS72qKU_W-NLMoh_",
     y: "-VBlr88R42IGLDBvzFeUvH1cjPOlIxWgnfa6NzhKcYZQXFi9vFq4sdJX5cQfnc6H",
 };
+var jwkPrivateKeyP521 = {
+    kty: "EC",
+    crv: "P-521",
+    x: "AS3DmGl2O2u7YZbWpvIs7ab1tbAeQ_8PiYeB5Z7wgUulyVu4UHx15WU2SSKfqYvA8acaeiyK9zJ8gmXLZaKtwbFT",
+    y: "AEZSN9F_AQY_2Hk_DJhoVStuno4av3HkVaNcBAfPj-oodz9vcNSnxHfvO2C6NqszPnrJArY-xXmHfNDAYm7PARcR",
+    d: "AW4mYMpythEq-e7zcVH4c_kEV5q2Qnlg854I9rKTkudG_35NqHixOh8Y1GhMsXzHhlpa-QMPo34Zd5OcT9XkTB-s",
+};
+var jwkPublicKeyP521 = {
+    kty: "EC",
+    crv: "P-521",
+    x: "AS3DmGl2O2u7YZbWpvIs7ab1tbAeQ_8PiYeB5Z7wgUulyVu4UHx15WU2SSKfqYvA8acaeiyK9zJ8gmXLZaKtwbFT",
+    y: "AEZSN9F_AQY_2Hk_DJhoVStuno4av3HkVaNcBAfPj-oodz9vcNSnxHfvO2C6NqszPnrJArY-xXmHfNDAYm7PARcR",
+};
 
 var P256 = { curveName: "P-256" };
 var P384 = { curveName: "P-384" };
+var P521 = { curveName: "P-521" };
 
 crypto.subtle.importKey("jwk", jwkPrivateKeyP256, { name: "ECDH", namedCurve: "P-256" }, extractable, ["deriveBits"]).then(function(result) {
     P256.privateKey = result;
@@ -88,6 +102,25 @@ crypto.subtle.importKey("jwk", jwkPrivateKeyP256, { name: "ECDH", namedCurve: "P
             testPassed("Bit derivations for EC P-384 with minimum and maximum lengths succeeded");
             return shouldReject('deriveBits(P384, 384 + 8)');
         });
+    }).then(function(result) {
+        return crypto.subtle.importKey("jwk", jwkPrivateKeyP521, { name: "ECDH", namedCurve: "P-521" }, extractable, ["deriveBits"]).then(function(result) {
+            P521.privateKey = result;
+            return crypto.subtle.importKey("jwk", jwkPublicKeyP521, { name: "ECDH", namedCurve: "P-521" }, extractable, [ ]);
+        }).then(function(result) {
+            P521.publicKey = result;
+
+            // P-521
+            return Promise.all([
+                deriveBits(P521, 0, 528),
+                deriveBits(P521, 8, 8),
+                deriveBits(P521, 528, 528),
+            ]).then(function(result) {
+                testPassed("Bit derivations for EC P-521 with minimum and maximum lengths succeeded");
+                return shouldReject('deriveBits(P521, 528 + 8)');
+            });
+        }, function(result) {
+            debug("Bit derivations for EC P-521 skipped, likely due to missing P-521 supprot.");
+        });
     });
 }).then(finishJSTest, finishJSTest);
 
diff --git a/LayoutTests/crypto/subtle/ecdh-generate-export-jwk-key-p521-expected.txt b/LayoutTests/crypto/subtle/ecdh-generate-export-jwk-key-p521-expected.txt
new file mode 100644 (file)
index 0000000..021de41
--- /dev/null
@@ -0,0 +1,26 @@
+Test exporting a P-521 ECDH key pair with JWK format.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Generating a key pair...
+Exporting the public key...
+PASS publicKey.kty is 'EC'
+PASS publicKey.crv is 'P-521'
+PASS Base64URL.parse(publicKey.x).byteLength is 66
+PASS Base64URL.parse(publicKey.y).byteLength is 66
+PASS publicKey.d is undefined.
+PASS publicKey.key_ops is [ ]
+PASS publicKey.ext is true
+Exporting the private key...
+PASS privateKey.kty is 'EC'
+PASS privateKey.crv is 'P-521'
+PASS Base64URL.parse(privateKey.x).byteLength is 66
+PASS Base64URL.parse(privateKey.y).byteLength is 66
+PASS Base64URL.parse(privateKey.d).byteLength is 66
+PASS privateKey.key_ops is ['deriveBits', 'deriveKey']
+PASS privateKey.ext is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/ecdh-generate-export-jwk-key-p521.html b/LayoutTests/crypto/subtle/ecdh-generate-export-jwk-key-p521.html
new file mode 100644 (file)
index 0000000..b4bcfe4
--- /dev/null
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test exporting a P-521 ECDH key pair with JWK format.");
+
+jsTestIsAsync = true;
+
+var algorithmKeyGen = {
+    name: "ECDH",
+    namedCurve: "P-521"
+};
+var extractable = true;
+
+var keyPair;
+debug("Generating a key pair...");
+crypto.subtle.generateKey(algorithmKeyGen, extractable, ["deriveKey", "deriveBits"]).then(function(result) {
+    keyPair = result;
+    debug("Exporting the public key...");
+    return crypto.subtle.exportKey("jwk", keyPair.publicKey);
+}).then(function(result) {
+    publicKey = result;
+
+    shouldBe("publicKey.kty", "'EC'");
+    shouldBe("publicKey.crv", "'P-521'");
+    shouldBe("Base64URL.parse(publicKey.x).byteLength", "66");
+    shouldBe("Base64URL.parse(publicKey.y).byteLength", "66");
+    shouldBeUndefined("publicKey.d");
+    shouldBe("publicKey.key_ops", "[ ]");
+    shouldBe("publicKey.ext", "true");
+
+    debug("Exporting the private key...");
+    return crypto.subtle.exportKey("jwk", keyPair.privateKey);
+}).then(function(result) {
+    privateKey = result;
+
+    shouldBe("privateKey.kty", "'EC'");
+    shouldBe("privateKey.crv", "'P-521'");
+    shouldBe("Base64URL.parse(privateKey.x).byteLength", "66");
+    shouldBe("Base64URL.parse(privateKey.y).byteLength", "66");
+    shouldBe("Base64URL.parse(privateKey.d).byteLength", "66");
+    shouldBe("privateKey.key_ops", "['deriveBits', 'deriveKey']");
+    shouldBe("privateKey.ext", "true");
+
+    finishJSTest();
+});
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/ecdh-generate-export-key-pkcs8-p521-expected.txt b/LayoutTests/crypto/subtle/ecdh-generate-export-key-pkcs8-p521-expected.txt
new file mode 100644 (file)
index 0000000..8e890e0
--- /dev/null
@@ -0,0 +1,12 @@
+Test exporting a P-521 ECDH private key with PKCS8 format.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Generating a key pair...
+Exporting the public key...
+PASS privateKey.byteLength is 241
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/ecdh-generate-export-key-pkcs8-p521.html b/LayoutTests/crypto/subtle/ecdh-generate-export-key-pkcs8-p521.html
new file mode 100644 (file)
index 0000000..23ae0ed
--- /dev/null
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test exporting a P-521 ECDH private key with PKCS8 format.");
+
+jsTestIsAsync = true;
+
+var algorithmKeyGen = {
+    name: "ECDH",
+    namedCurve: "P-521"
+};
+var extractable = true;
+
+var keyPair;
+debug("Generating a key pair...");
+crypto.subtle.generateKey(algorithmKeyGen, extractable, ["deriveKey", "deriveBits"]).then(function(result) {
+    keyPair = result;
+    debug("Exporting the public key...");
+    return crypto.subtle.exportKey("pkcs8", keyPair.privateKey);
+}).then(function(result) {
+    privateKey = result;
+
+    shouldBe("privateKey.byteLength", "241");
+
+    finishJSTest();
+});
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/ecdh-generate-export-key-raw-p521-expected.txt b/LayoutTests/crypto/subtle/ecdh-generate-export-key-raw-p521-expected.txt
new file mode 100644 (file)
index 0000000..7a845e9
--- /dev/null
@@ -0,0 +1,12 @@
+Test exporting a P-521 ECDH public key with raw format.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Generating a key pair...
+Exporting the public key...
+PASS publicKey.byteLength is 133
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/ecdh-generate-export-key-raw-p521.html b/LayoutTests/crypto/subtle/ecdh-generate-export-key-raw-p521.html
new file mode 100644 (file)
index 0000000..e0a1eb3
--- /dev/null
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test exporting a P-521 ECDH public key with raw format.");
+
+jsTestIsAsync = true;
+
+var algorithmKeyGen = {
+    name: "ECDH",
+    namedCurve: "P-521"
+};
+var extractable = true;
+
+var keyPair;
+debug("Generating a key pair...");
+crypto.subtle.generateKey(algorithmKeyGen, extractable, ["deriveKey", "deriveBits"]).then(function(result) {
+    keyPair = result;
+    debug("Exporting the public key...");
+    return crypto.subtle.exportKey("raw", keyPair.publicKey);
+}).then(function(result) {
+    publicKey = result;
+
+    shouldBe("publicKey.byteLength", "133");
+
+    finishJSTest();
+});
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/ecdh-generate-export-key-spki-p521-expected.txt b/LayoutTests/crypto/subtle/ecdh-generate-export-key-spki-p521-expected.txt
new file mode 100644 (file)
index 0000000..4a211d4
--- /dev/null
@@ -0,0 +1,12 @@
+Test exporting a P-521 ECDH public key with SPKI format.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Generating a key pair...
+Exporting the public key...
+PASS publicKey.byteLength is 158
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/ecdh-generate-export-key-spki-p521.html b/LayoutTests/crypto/subtle/ecdh-generate-export-key-spki-p521.html
new file mode 100644 (file)
index 0000000..7fa13c5
--- /dev/null
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test exporting a P-521 ECDH public key with SPKI format.");
+
+jsTestIsAsync = true;
+
+var algorithmKeyGen = {
+    name: "ECDH",
+    namedCurve: "P-521"
+};
+var extractable = true;
+
+var keyPair;
+debug("Generating a key pair...");
+crypto.subtle.generateKey(algorithmKeyGen, extractable, ["deriveKey", "deriveBits"]).then(function(result) {
+    keyPair = result;
+    debug("Exporting the public key...");
+    return crypto.subtle.exportKey("spki", keyPair.publicKey);
+}).then(function(result) {
+    publicKey = result;
+
+    shouldBe("publicKey.byteLength", "158");
+
+    finishJSTest();
+});
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/ecdh-generate-key-p521-expected.txt b/LayoutTests/crypto/subtle/ecdh-generate-key-p521-expected.txt
new file mode 100644 (file)
index 0000000..1d6f707
--- /dev/null
@@ -0,0 +1,21 @@
+Test generating an EC key pair with P-521 using ECDH algorithm.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Generating a key pair...
+PASS keyPair.toString() is '[object Object]'
+PASS keyPair.publicKey.type is 'public'
+PASS keyPair.publicKey.extractable is true
+PASS keyPair.publicKey.algorithm.name is 'ECDH'
+PASS keyPair.publicKey.algorithm.namedCurve is 'P-521'
+PASS keyPair.publicKey.usages is [ ]
+PASS keyPair.privateKey.type is 'private'
+PASS keyPair.privateKey.extractable is false
+PASS keyPair.privateKey.algorithm.name is 'ECDH'
+PASS keyPair.privateKey.algorithm.namedCurve is 'P-521'
+PASS keyPair.privateKey.usages is ['deriveBits', 'deriveKey']
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/ecdh-generate-key-p521.html b/LayoutTests/crypto/subtle/ecdh-generate-key-p521.html
new file mode 100644 (file)
index 0000000..ec2bbc1
--- /dev/null
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test generating an EC key pair with P-521 using ECDH algorithm.");
+
+jsTestIsAsync = true;
+
+var nonExtractable = false;
+
+debug("Generating a key pair...");
+crypto.subtle.generateKey({ name: "ECDH", namedCurve: "P-521"}, nonExtractable, ["deriveKey", "deriveBits"]).then(function(result) {
+    keyPair = result;
+    shouldBe("keyPair.toString()", "'[object Object]'");
+    shouldBe("keyPair.publicKey.type", "'public'");
+    shouldBe("keyPair.publicKey.extractable", "true");
+    shouldBe("keyPair.publicKey.algorithm.name", "'ECDH'");
+    shouldBe("keyPair.publicKey.algorithm.namedCurve", "'P-521'");
+    shouldBe("keyPair.publicKey.usages", "[ ]");
+    shouldBe("keyPair.privateKey.type", "'private'");
+    shouldBe("keyPair.privateKey.extractable", "false");
+    shouldBe("keyPair.privateKey.algorithm.name", "'ECDH'");
+    shouldBe("keyPair.privateKey.algorithm.namedCurve", "'P-521'");
+    shouldBe("keyPair.privateKey.usages", "['deriveBits', 'deriveKey']");
+
+    finishJSTest();
+});
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/ecdh-import-jwk-private-key-p521-expected.txt b/LayoutTests/crypto/subtle/ecdh-import-jwk-private-key-p521-expected.txt
new file mode 100644 (file)
index 0000000..e4e512a
--- /dev/null
@@ -0,0 +1,16 @@
+Test importing a JWK ECDH private key with P-521
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Importing a key...
+PASS privateKey.toString() is '[object CryptoKey]'
+PASS privateKey.type is 'private'
+PASS privateKey.extractable is false
+PASS privateKey.algorithm.name is 'ECDH'
+PASS privateKey.algorithm.namedCurve is 'P-521'
+PASS privateKey.usages is ['deriveBits', 'deriveKey']
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/ecdh-import-jwk-private-key-p521.html b/LayoutTests/crypto/subtle/ecdh-import-jwk-private-key-p521.html
new file mode 100644 (file)
index 0000000..b18aa18
--- /dev/null
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a JWK ECDH private key with P-521");
+
+jsTestIsAsync = true;
+
+var jwkKey = {
+    kty: "EC",
+    use: "enc",
+    ext: false,
+    key_ops: ["deriveKey", "deriveBits"],
+    crv: "P-521",
+    x: "ATyYJNg6KbLelgL09FGKksW7qfIEPf4OPCHB7PuoUq4AyiJQaMqWD7TagGc4gwY5lJ7rDRLKGdxGmf19inAT_X1a",
+    y: "AAF1xys7jFj4QkHBC3uF_Kodak7rOkbmpAPKrqzR_akXaCwNfdsjX12_uVkDhyUqF-C5oUYsKLqET8RMm8kg8cX9",
+    d: "APLcP3zg0beau_cHUhnqmoeduWOKTh3Ki7shV0NxvrXTIp4pCUv3RX6do19RD7c4Goh3EGO3UJ9FdhzbeNLzYmmH",
+};
+var nonExtractable = false;
+
+debug("Importing a key...");
+crypto.subtle.importKey("jwk", jwkKey, { name: "ECDH", namedCurve: "P-521" }, nonExtractable, ["deriveKey", "deriveBits"]).then(function(result) {
+    privateKey = result;
+
+    shouldBe("privateKey.toString()", "'[object CryptoKey]'");
+    shouldBe("privateKey.type", "'private'");
+    shouldBe("privateKey.extractable", "false");
+    shouldBe("privateKey.algorithm.name", "'ECDH'");
+    shouldBe("privateKey.algorithm.namedCurve", "'P-521'");
+    shouldBe("privateKey.usages", "['deriveBits', 'deriveKey']");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/ecdh-import-jwk-public-key-p521-expected.txt b/LayoutTests/crypto/subtle/ecdh-import-jwk-public-key-p521-expected.txt
new file mode 100644 (file)
index 0000000..1a5986f
--- /dev/null
@@ -0,0 +1,16 @@
+Test importing a JWK ECDH public key with P-521
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Importing a key...
+PASS publicKey.toString() is '[object CryptoKey]'
+PASS publicKey.type is 'public'
+PASS publicKey.extractable is true
+PASS publicKey.algorithm.name is 'ECDH'
+PASS publicKey.algorithm.namedCurve is 'P-521'
+PASS publicKey.usages is [ ]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/ecdh-import-jwk-public-key-p521.html b/LayoutTests/crypto/subtle/ecdh-import-jwk-public-key-p521.html
new file mode 100644 (file)
index 0000000..75583f4
--- /dev/null
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a JWK ECDH public key with P-521");
+
+jsTestIsAsync = true;
+
+var jwkKey = {
+    kty: "EC",
+    use: "enc",
+    ext: true,
+    crv: "P-521",
+    x: "ATyYJNg6KbLelgL09FGKksW7qfIEPf4OPCHB7PuoUq4AyiJQaMqWD7TagGc4gwY5lJ7rDRLKGdxGmf19inAT_X1a",
+    y: "AAF1xys7jFj4QkHBC3uF_Kodak7rOkbmpAPKrqzR_akXaCwNfdsjX12_uVkDhyUqF-C5oUYsKLqET8RMm8kg8cX9",
+};
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("jwk", jwkKey, { name: "ECDH", namedCurve: "P-521" }, extractable, [ ]).then(function(result) {
+    publicKey = result;
+
+    shouldBe("publicKey.toString()", "'[object CryptoKey]'");
+    shouldBe("publicKey.type", "'public'");
+    shouldBe("publicKey.extractable", "true");
+    shouldBe("publicKey.algorithm.name", "'ECDH'");
+    shouldBe("publicKey.algorithm.namedCurve", "'P-521'");
+    shouldBe("publicKey.usages", "[ ]");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/ecdh-import-pkcs8-key-p521-expected.txt b/LayoutTests/crypto/subtle/ecdh-import-pkcs8-key-p521-expected.txt
new file mode 100644 (file)
index 0000000..2994aa7
--- /dev/null
@@ -0,0 +1,16 @@
+Test importing a P-521 PKCS8 ECDH key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Importing a key...
+PASS publicKey.toString() is '[object CryptoKey]'
+PASS publicKey.type is 'private'
+PASS publicKey.extractable is true
+PASS publicKey.algorithm.name is 'ECDH'
+PASS publicKey.algorithm.namedCurve is 'P-521'
+PASS publicKey.usages is [ 'deriveBits', 'deriveKey' ]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/ecdh-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey-expected.txt b/LayoutTests/crypto/subtle/ecdh-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey-expected.txt
new file mode 100644 (file)
index 0000000..ac5a93f
--- /dev/null
@@ -0,0 +1,19 @@
+Test that importing P-521 EC keys for the ECDH algorithm through PKCS#8 fails in case of incorrect curve identifier or public key used in the ECPrivateKey structure
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+ECDH: importing P-521 key that uses matching curve identifiers and valid public key in ECParameters structures in PKCS#8 ...
+PASS Successfully imported a P-521 key.
+ECDH: importing P-521 key whose curve identifiers in ECParameters structures in PKCS#8 don't match ...
+PASS importKey(pkcs8P521KeyMismatchedCurveIdentifiers) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+ECDH: importing P-521 key that has a public key in PKCS#8 of invalid length ...
+PASS importKey(pkcs8P521KeyInvalidPublicKeyLength) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+ECDH: importing P-521 key that has a public key in PKCS#8 of invalid EC point format ...
+PASS importKey(pkcs8P521KeyInvalidPublicKeyECPointFormat) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+ECDH: importing P-521 key that has an invalid public key in PKCS#8 ...
+PASS importKey(pkcs8P521KeyInvalidPublicKey) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/ecdh-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey.html b/LayoutTests/crypto/subtle/ecdh-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey.html
new file mode 100644 (file)
index 0000000..a67c02f
--- /dev/null
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test that importing P-521 EC keys for the ECDH algorithm through PKCS#8 fails in case of incorrect curve identifier or public key used in the ECPrivateKey structure");
+
+jsTestIsAsync = true;
+
+// Valid P-521 key that has matching named curve identifiers in ECParameters structures under
+// both AlgorithmIdentifier parameters and under ECPrivateKey parameters in the PKCS#8 structure,
+// as well as a valid public key under ECPrivateKey.
+var pkcs8P521ValidKey = hexStringToUint8Array("3081f7020100301006072a8648ce3d020106052b810400230481df3081dc02010104420160ccf72d28b6df9768c30f67e77a000ecdb6e20381d8ee6f5474d6a612c39b7f3d361e1e9901f4cc573dcfc7da3eeadcb3e10532ca12d39df5ed39a5156c3e3ceba00706052b81040023a18189038186000400e9a76aed2acda29ba2a5dbdc1f04c6160bc16c6d16b737a557f9dcbc8efb79dd1b9eabfc0a911ea3fd574176e2cbf32caa9babb505b04f30ecf369e6bec91d1ac201a8aa718c0c293b085d7902a314cab6e8048e458cc28c7da4fff2fcbf3da6d42fee94de5e0a3fb34342780e3f9df7b424911d6efb8628079566b50efe6971271eea");
+
+// Invalid P-521 key that has mismatched named curve identifiers in the mentioned ECParameters structures.
+var pkcs8P521KeyMismatchedCurveIdentifiers = hexStringToUint8Array("3081f7020100301006072a8648ce3d020106052b810400230481df3081dc02010104420160ccf72d28b6df9768c30f67e77a000ecdb6e20381d8ee6f5474d6a612c39b7f3d361e1e9901f4cc573dcfc7da3eeadcb3e10532ca12d39df5ed39a5156c3e3ceba00706052b81040022a18189038186000400e9a76aed2acda29ba2a5dbdc1f04c6160bc16c6d16b737a557f9dcbc8efb79dd1b9eabfc0a911ea3fd574176e2cbf32caa9babb505b04f30ecf369e6bec91d1ac201a8aa718c0c293b085d7902a314cab6e8048e458cc28c7da4fff2fcbf3da6d42fee94de5e0a3fb34342780e3f9df7b424911d6efb8628079566b50efe6971271eea");
+
+// Invalid P-521 key that has a public key of invalid length (its last byte is clipped).
+var pkcs8P521KeyInvalidPublicKeyLength = hexStringToUint8Array("3081f6020100301006072a8648ce3d020106052b810400230481de3081db02010104420160ccf72d28b6df9768c30f67e77a000ecdb6e20381d8ee6f5474d6a612c39b7f3d361e1e9901f4cc573dcfc7da3eeadcb3e10532ca12d39df5ed39a5156c3e3ceba00706052b81040023a18188038185000400e9a76aed2acda29ba2a5dbdc1f04c6160bc16c6d16b737a557f9dcbc8efb79dd1b9eabfc0a911ea3fd574176e2cbf32caa9babb505b04f30ecf369e6bec91d1ac201a8aa718c0c293b085d7902a314cab6e8048e458cc28c7da4fff2fcbf3da6d42fee94de5e0a3fb34342780e3f9df7b424911d6efb8628079566b50efe6971271eea");
+
+// Invalid P-521 key that has a public key of invalid EC point format (leading 0x05 byte instead of 0x04).
+var pkcs8P521KeyInvalidPublicKeyECPointFormat= hexStringToUint8Array("3081f7020100301006072a8648ce3d020106052b810400230481df3081dc02010104420160ccf72d28b6df9768c30f67e77a000ecdb6e20381d8ee6f5474d6a612c39b7f3d361e1e9901f4cc573dcfc7da3eeadcb3e10532ca12d39df5ed39a5156c3e3ceba00706052b81040023a18189038186000500e9a76aed2acda29ba2a5dbdc1f04c6160bc16c6d16b737a557f9dcbc8efb79dd1b9eabfc0a911ea3fd574176e2cbf32caa9babb505b04f30ecf369e6bec91d1ac201a8aa718c0c293b085d7902a314cab6e8048e458cc28c7da4fff2fcbf3da6d42fee94de5e0a3fb34342780e3f9df7b424911d6efb8628079566b50efe6971271eea");
+
+// Invalid P-521 key that has a public key of invalid value (0xabad1dea).
+var pkcs8P521KeyInvalidPublicKey = hexStringToUint8Array("3081f7020100301006072a8648ce3d020106052b810400230481df3081dc02010104420160ccf72d28b6df9768c30f67e77a000ecdb6e20381d8ee6f5474d6a612c39b7f3d361e1e9901f4cc573dcfc7da3eeadcb3e10532ca12d39df5ed39a5156c3e3ceba00706052b81040023a1818903818600040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000abad1dea");
+
+function importKey(keyData)
+{
+    return crypto.subtle.importKey("pkcs8", keyData, { name: "ECDH", namedCurve: "P-521" }, true, [ "deriveKey", "deriveBits" ]);
+}
+
+Promise.resolve().then(function(result) {
+    debug("ECDH: importing P-521 key that uses matching curve identifiers and valid public key in ECParameters structures in PKCS#8 ...");
+    return importKey(pkcs8P521ValidKey);
+}).then(function(result) {
+    testPassed("Successfully imported a P-521 key.");
+
+    debug("ECDH: importing P-521 key whose curve identifiers in ECParameters structures in PKCS#8 don't match ...");
+    return shouldReject('importKey(pkcs8P521KeyMismatchedCurveIdentifiers)');
+}).then(function(result) {
+    debug("ECDH: importing P-521 key that has a public key in PKCS#8 of invalid length ...");
+    return shouldReject('importKey(pkcs8P521KeyInvalidPublicKeyLength)');
+}).then(function(result) {
+    debug("ECDH: importing P-521 key that has a public key in PKCS#8 of invalid EC point format ...");
+    return shouldReject('importKey(pkcs8P521KeyInvalidPublicKeyECPointFormat)');
+}).then(function(result) {
+    debug("ECDH: importing P-521 key that has an invalid public key in PKCS#8 ...");
+    return shouldReject('importKey(pkcs8P521KeyInvalidPublicKey)');
+}).then(function(result) {
+    finishJSTest();
+});;
+
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/ecdh-import-pkcs8-key-p521.html b/LayoutTests/crypto/subtle/ecdh-import-pkcs8-key-p521.html
new file mode 100644 (file)
index 0000000..2776076
--- /dev/null
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a P-521 PKCS8 ECDH key");
+
+jsTestIsAsync = true;
+
+var pkcs8Key = hexStringToUint8Array("3081ee020100301006072a8648ce3d020106052b810400230481d63081d302010104420160ccf72d28b6df9768c30f67e77a000ecdb6e20381d8ee6f5474d6a612c39b7f3d361e1e9901f4cc573dcfc7da3eeadcb3e10532ca12d39df5ed39a5156c3e3ceba18189038186000400e9a76aed2acda29ba2a5dbdc1f04c6160bc16c6d16b737a557f9dcbc8efb79dd1b9eabfc0a911ea3fd574176e2cbf32caa9babb505b04f30ecf369e6bec91d1ac201a8aa718c0c293b085d7902a314cab6e8048e458cc28c7da4fff2fcbf3da6d42fee94de5e0a3fb34342780e3f9df7b424911d6efb8628079566b50efe6971271eea");
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("pkcs8", pkcs8Key, {name: "ECDH", namedCurve: "P-521"}, extractable, ["deriveKey", "deriveBits"]).then(function(result) {
+    publicKey = result;
+
+    shouldBe("publicKey.toString()", "'[object CryptoKey]'");
+    shouldBe("publicKey.type", "'private'");
+    shouldBe("publicKey.extractable", "true");
+    shouldBe("publicKey.algorithm.name", "'ECDH'");
+    shouldBe("publicKey.algorithm.namedCurve", "'P-521'");
+    shouldBe("publicKey.usages", "[ 'deriveBits', 'deriveKey' ]");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/ecdh-import-raw-key-p521-expected.txt b/LayoutTests/crypto/subtle/ecdh-import-raw-key-p521-expected.txt
new file mode 100644 (file)
index 0000000..e999c38
--- /dev/null
@@ -0,0 +1,16 @@
+Test importing an ECDH raw key with P-521
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Importing a key...
+PASS publicKey.toString() is '[object CryptoKey]'
+PASS publicKey.type is 'public'
+PASS publicKey.extractable is true
+PASS publicKey.algorithm.name is 'ECDH'
+PASS publicKey.algorithm.namedCurve is 'P-521'
+PASS publicKey.usages is [ ]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/ecdh-import-raw-key-p521.html b/LayoutTests/crypto/subtle/ecdh-import-raw-key-p521.html
new file mode 100644 (file)
index 0000000..0294a74
--- /dev/null
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing an ECDH raw key with P-521");
+
+jsTestIsAsync = true;
+
+var rawKey = hexStringToUint8Array("0400e9a76aed2acda29ba2a5dbdc1f04c6160bc16c6d16b737a557f9dcbc8efb79dd1b9eabfc0a911ea3fd574176e2cbf32caa9babb505b04f30ecf369e6bec91d1ac201a8aa718c0c293b085d7902a314cab6e8048e458cc28c7da4fff2fcbf3da6d42fee94de5e0a3fb34342780e3f9df7b424911d6efb8628079566b50efe6971271eea");
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("raw", rawKey, { name: "ECDH", namedCurve: "P-521" }, extractable, [ ]).then(function(result) {
+    publicKey = result;
+
+    shouldBe("publicKey.toString()", "'[object CryptoKey]'");
+    shouldBe("publicKey.type", "'public'");
+    shouldBe("publicKey.extractable", "true");
+    shouldBe("publicKey.algorithm.name", "'ECDH'");
+    shouldBe("publicKey.algorithm.namedCurve", "'P-521'");
+    shouldBe("publicKey.usages", "[ ]");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
index c1a4e6b..0c7a2b6 100644 (file)
@@ -1,4 +1,4 @@
-Test importing P-256 and P-384 SPKI ECDH keys that are using the ecDH algorithm identifier
+Test importing P-256, P-384 and P-521 SPKI ECDH keys that are using the ecDH algorithm identifier
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
@@ -17,6 +17,8 @@ PASS publicKey.extractable is true
 PASS publicKey.algorithm.name is 'ECDH'
 PASS publicKey.algorithm.namedCurve is 'P-384'
 PASS publicKey.usages is [ ]
+Importing a P-521 key that uses the ecDH algorithm identifier ...
+Importing EC P-521 key failed, likely due to missing P-521 support.
 PASS successfullyParsed is true
 
 TEST COMPLETE
index c7b6767..f7c0f3c 100644 (file)
@@ -9,12 +9,13 @@
 <div id="console"></div>
 
 <script>
-description("Test importing P-256 and P-384 SPKI ECDH keys that are using the ecDH algorithm identifier");
+description("Test importing P-256, P-384 and P-521 SPKI ECDH keys that are using the ecDH algorithm identifier");
 
 jsTestIsAsync = true;
 
 var spkiP256Key = hexStringToUint8Array("3057301106052b8104010c06082a8648ce3d03010703420004c3ee3a2c3380072b9b2a59fed2cada65121806e22c4f4f8a25e740fc3e54d75d86c200298e6dfc1611d185eedbdb3c2661b0eb0441f7fd57c90d08112e9ae71c");
 var spkiP384Key = hexStringToUint8Array("3074300e06052b8104010c06052b81040022036200044fe8f479a01b2d524d0f637add0391b733344a9eca4702359d42ad42acfd0632e77c855534e896828fec76318b3aa7f9745ed94a19a55152a4418cfdf277d3d706ddf3d443ee0710ac717ce85ba60e8fe29e7d8b3dfe0797c7eb47d2c19a86ca");
+var spkiP521Key = hexStringToUint8Array("30819b301006072a8648ce3d020106052b81040023038186000400e9a76aed2acda29ba2a5dbdc1f04c6160bc16c6d16b737a557f9dcbc8efb79dd1b9eabfc0a911ea3fd574176e2cbf32caa9babb505b04f30ecf369e6bec91d1ac201a8aa718c0c293b085d7902a314cab6e8048e458cc28c7da4fff2fcbf3da6d42fee94de5e0a3fb34342780e3f9df7b424911d6efb8628079566b50efe6971271eea");
 var extractable = true;
 
 Promise.resolve().then(function(result) {
@@ -42,6 +43,21 @@ Promise.resolve().then(function(result) {
     shouldBe("publicKey.algorithm.namedCurve", "'P-384'");
     shouldBe("publicKey.usages", "[ ]");
 
+    debug("Importing a P-521 key that uses the ecDH algorithm identifier ...");
+    return crypto.subtle.importKey("spki", spkiP521Key, {name: "ECDH", namedCurve: "P-521"}, extractable, [ ]);
+}).then(function(result) {
+    publicKey = result;
+
+    shouldBe("publicKey.toString()", "'[object CryptoKey]'");
+    shouldBe("publicKey.type", "'public'");
+    shouldBe("publicKey.extractable", "true");
+    shouldBe("publicKey.algorithm.name", "'ECDH'");
+    shouldBe("publicKey.algorithm.namedCurve", "'P-521'");
+    shouldBe("publicKey.usages", "[ ]");
+
+    finishJSTest();
+}, function(result) {
+    debug("Importing EC P-521 key failed, likely due to missing P-521 support.");
     finishJSTest();
 });
 
diff --git a/LayoutTests/crypto/subtle/ecdh-import-spki-key-p521-expected.txt b/LayoutTests/crypto/subtle/ecdh-import-spki-key-p521-expected.txt
new file mode 100644 (file)
index 0000000..309c418
--- /dev/null
@@ -0,0 +1,16 @@
+Test importing a P-521 SPKI ECDH key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Importing a key...
+PASS publicKey.toString() is '[object CryptoKey]'
+PASS publicKey.type is 'public'
+PASS publicKey.extractable is true
+PASS publicKey.algorithm.name is 'ECDH'
+PASS publicKey.algorithm.namedCurve is 'P-521'
+PASS publicKey.usages is [ ]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/ecdh-import-spki-key-p521.html b/LayoutTests/crypto/subtle/ecdh-import-spki-key-p521.html
new file mode 100644 (file)
index 0000000..521869a
--- /dev/null
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test importing a P-521 SPKI ECDH key");
+
+jsTestIsAsync = true;
+
+var spkiKey = hexStringToUint8Array("30819b301006072a8648ce3d020106052b81040023038186000400e9a76aed2acda29ba2a5dbdc1f04c6160bc16c6d16b737a557f9dcbc8efb79dd1b9eabfc0a911ea3fd574176e2cbf32caa9babb505b04f30ecf369e6bec91d1ac201a8aa718c0c293b085d7902a314cab6e8048e458cc28c7da4fff2fcbf3da6d42fee94de5e0a3fb34342780e3f9df7b424911d6efb8628079566b50efe6971271eea");
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("spki", spkiKey, {name: "ECDH", namedCurve: "P-521"}, extractable, [ ]).then(function(result) {
+    publicKey = result;
+
+    shouldBe("publicKey.toString()", "'[object CryptoKey]'");
+    shouldBe("publicKey.type", "'public'");
+    shouldBe("publicKey.extractable", "true");
+    shouldBe("publicKey.algorithm.name", "'ECDH'");
+    shouldBe("publicKey.algorithm.namedCurve", "'P-521'");
+    shouldBe("publicKey.usages", "[ ]");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/ecdsa-generate-key-sign-verify-p521-expected.txt b/LayoutTests/crypto/subtle/ecdsa-generate-key-sign-verify-p521-expected.txt
new file mode 100644 (file)
index 0000000..e422a30
--- /dev/null
@@ -0,0 +1,14 @@
+Test ECDSA signing/verifying operations with generated P-521 keys
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Generating keys
+Signing
+PASS signature.byteLength is 132
+Verifying
+PASS verified is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/ecdsa-generate-key-sign-verify-p521.html b/LayoutTests/crypto/subtle/ecdsa-generate-key-sign-verify-p521.html
new file mode 100644 (file)
index 0000000..2e07931
--- /dev/null
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script type="text/javascript">
+description("Test ECDSA signing/verifying operations with generated P-521 keys");
+
+jsTestIsAsync = true;
+
+var extractable = true;
+var ecdsaParams = {
+    name: "ECDSA",
+    hash: "SHA-256",
+}
+var data = asciiToUint8Array("Hello, World!");
+
+debug("Generating keys");
+crypto.subtle.generateKey({ name: "ECDSA", namedCurve: "P-521" }, extractable, ["sign", "verify"]).then(function(result) {
+    keyPair = result;
+
+    debug("Signing");
+    return crypto.subtle.sign(ecdsaParams, keyPair.privateKey, data);
+}).then(function(result) {
+    signature = result;
+
+    shouldBe("signature.byteLength", "132");
+
+    debug("Verifying");
+    return crypto.subtle.verify(ecdsaParams, keyPair.publicKey, signature, data);
+}).then(function(result) {
+    verified = result;
+
+    shouldBeTrue("verified");
+
+    finishJSTest();
+}, failAndFinishJSTest);
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/ecdsa-import-jwk-public-key-alg-521-expected.txt b/LayoutTests/crypto/subtle/ecdsa-import-jwk-public-key-alg-521-expected.txt
new file mode 100644 (file)
index 0000000..ab9efa3
--- /dev/null
@@ -0,0 +1,16 @@
+Test importing a JWK ECDSA public key with ES521
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Importing a key...
+PASS publicKey.toString() is '[object CryptoKey]'
+PASS publicKey.type is 'public'
+PASS publicKey.extractable is true
+PASS publicKey.algorithm.name is 'ECDSA'
+PASS publicKey.algorithm.namedCurve is 'P-521'
+PASS publicKey.usages is ['verify']
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/ecdsa-import-jwk-public-key-alg-521.html b/LayoutTests/crypto/subtle/ecdsa-import-jwk-public-key-alg-521.html
new file mode 100644 (file)
index 0000000..19097f8
--- /dev/null
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script type="text/javascript">
+description("Test importing a JWK ECDSA public key with ES521");
+
+jsTestIsAsync = true;
+
+var jwkKey = {
+    kty: "EC",
+    use: "sig",
+    ext: true,
+    crv: "P-521",
+    x: "ATyYJNg6KbLelgL09FGKksW7qfIEPf4OPCHB7PuoUq4AyiJQaMqWD7TagGc4gwY5lJ7rDRLKGdxGmf19inAT_X1a",
+    y: "AAF1xys7jFj4QkHBC3uF_Kodak7rOkbmpAPKrqzR_akXaCwNfdsjX12_uVkDhyUqF-C5oUYsKLqET8RMm8kg8cX9",
+    alg: "ES512"
+};
+var extractable = true;
+
+debug("Importing a key...");
+crypto.subtle.importKey("jwk", jwkKey, { name: "ECDSA", namedCurve: "P-521" }, extractable, ['verify']).then(function(result) {
+    publicKey = result;
+
+    shouldBe("publicKey.toString()", "'[object CryptoKey]'");
+    shouldBe("publicKey.type", "'public'");
+    shouldBe("publicKey.extractable", "true");
+    shouldBe("publicKey.algorithm.name", "'ECDSA'");
+    shouldBe("publicKey.algorithm.namedCurve", "'P-521'");
+    shouldBe("publicKey.usages", "['verify']");
+
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/ecdsa-import-key-sign-p521-expected.txt b/LayoutTests/crypto/subtle/ecdsa-import-key-sign-p521-expected.txt
new file mode 100644 (file)
index 0000000..f736557
--- /dev/null
@@ -0,0 +1,10 @@
+Test ECDSA signing operation with a P-521 private key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS signature.byteLength is 132
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/ecdsa-import-key-sign-p521.html b/LayoutTests/crypto/subtle/ecdsa-import-key-sign-p521.html
new file mode 100644 (file)
index 0000000..d3afd9d
--- /dev/null
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script type="text/javascript">
+description("Test ECDSA signing operation with a P-521 private key");
+
+jsTestIsAsync = true;
+
+var extractable = true;
+var jwkPrivateKey = {
+    kty: "EC",
+    crv: "P-521",
+    x: "ATyYJNg6KbLelgL09FGKksW7qfIEPf4OPCHB7PuoUq4AyiJQaMqWD7TagGc4gwY5lJ7rDRLKGdxGmf19inAT_X1a",
+    y: "AAF1xys7jFj4QkHBC3uF_Kodak7rOkbmpAPKrqzR_akXaCwNfdsjX12_uVkDhyUqF-C5oUYsKLqET8RMm8kg8cX9",
+    d: "APLcP3zg0beau_cHUhnqmoeduWOKTh3Ki7shV0NxvrXTIp4pCUv3RX6do19RD7c4Goh3EGO3UJ9FdhzbeNLzYmmH",
+};
+var ecdsaParams = {
+    name: "ECDSA",
+    hash: "SHA-256",
+}
+var data = asciiToUint8Array("Hello, World!");
+
+crypto.subtle.importKey("jwk", jwkPrivateKey, { name: "ECDSA", namedCurve: "P-521" }, extractable, ["sign"]).then(function(key) {
+    return crypto.subtle.sign(ecdsaParams, key, data);
+}).then(function(result) {
+    signature = result;
+
+    shouldBe("signature.byteLength", "132");
+
+    finishJSTest();
+}, failAndFinishJSTest);
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/ecdsa-import-key-verify-p521-expected.txt b/LayoutTests/crypto/subtle/ecdsa-import-key-verify-p521-expected.txt
new file mode 100644 (file)
index 0000000..1612b59
--- /dev/null
@@ -0,0 +1,10 @@
+Test ECDSA verifying operation with a P-521 public key
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS verified is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/ecdsa-import-key-verify-p521.html b/LayoutTests/crypto/subtle/ecdsa-import-key-verify-p521.html
new file mode 100644 (file)
index 0000000..e30abce
--- /dev/null
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script type="text/javascript">
+description("Test ECDSA verifying operation with a P-521 public key");
+
+jsTestIsAsync = true;
+
+var extractable = true;
+var jwkPublicKey = {
+    kty: "EC",
+    crv: "P-521",
+    x: "ATyYJNg6KbLelgL09FGKksW7qfIEPf4OPCHB7PuoUq4AyiJQaMqWD7TagGc4gwY5lJ7rDRLKGdxGmf19inAT_X1a",
+    y: "AAF1xys7jFj4QkHBC3uF_Kodak7rOkbmpAPKrqzR_akXaCwNfdsjX12_uVkDhyUqF-C5oUYsKLqET8RMm8kg8cX9",
+};
+var ecdsaParams = {
+    name: "ECDSA",
+    hash: "SHA-256",
+}
+var data = asciiToUint8Array("Hello, World!");
+var signature = hexStringToUint8Array("013f4994b96ea2d6ce58e70bde70717f00891194c91acb9ad6e6897b7769d837d3ed2695dd3de6f5e06413310a4e8b0aad83873ca7359584958a2d1ec1dad86a841c008961578f7cc2fb15703f614854921b7b5fff7ee38cacd37744419213582328903cb7c44d9c08378c5e1e70edabac439d3490680e9e1225f7c377bd44311717bdaa");
+
+crypto.subtle.importKey("jwk", jwkPublicKey, { name: "ECDSA", namedCurve: "P-521" }, extractable, ["verify"]).then(function(key) {
+    return crypto.subtle.verify(ecdsaParams, key, signature, data);
+}).then(function(result) {
+    verified = result;
+
+    shouldBeTrue("verified");
+
+    finishJSTest();
+}, failAndFinishJSTest);
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/ecdsa-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey-expected.txt b/LayoutTests/crypto/subtle/ecdsa-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey-expected.txt
new file mode 100644 (file)
index 0000000..8f8ffc3
--- /dev/null
@@ -0,0 +1,19 @@
+Test that importing P-521 EC keys for the ECDSA algorithm through PKCS#8 fails in case of incorrect curve identifier or public key used in the ECPrivateKey structure
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+ECDSA: importing P-521 key that uses matching curve identifiers and valid public key in ECParameters structures in PKCS#8 ...
+PASS Successfully imported a P-521 key.
+ECDSA: importing P-521 key whose curve identifiers in ECParameters structures in PKCS#8 don't match ...
+PASS importKey(pkcs8P521KeyMismatchedCurveIdentifiers) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+ECDSA: importing P-521 key that has a public key in PKCS#8 of invalid length ...
+PASS importKey(pkcs8P521KeyInvalidPublicKeyLength) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+ECDSA: importing P-521 key that has a public key in PKCS#8 of invalid EC point format ...
+PASS importKey(pkcs8P521KeyInvalidPublicKeyECPointFormat) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+ECDSA: importing P-521 key that has an invalid public key in PKCS#8 ...
+PASS importKey(pkcs8P521KeyInvalidPublicKey) rejected promise  with DataError: Data provided to an operation does not meet requirements.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/ecdsa-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey.html b/LayoutTests/crypto/subtle/ecdsa-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey.html
new file mode 100644 (file)
index 0000000..4d611c8
--- /dev/null
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test that importing P-521 EC keys for the ECDSA algorithm through PKCS#8 fails in case of incorrect curve identifier or public key used in the ECPrivateKey structure");
+
+jsTestIsAsync = true;
+
+// Valid P-521 key that has matching named curve identifiers in ECParameters structures under
+// both AlgorithmIdentifier parameters and under ECPrivateKey parameters in the PKCS#8 structure,
+// as well as a valid public key under ECPrivateKey.
+var pkcs8P521ValidKey = hexStringToUint8Array("3081f7020100301006072a8648ce3d020106052b810400230481df3081dc02010104420160ccf72d28b6df9768c30f67e77a000ecdb6e20381d8ee6f5474d6a612c39b7f3d361e1e9901f4cc573dcfc7da3eeadcb3e10532ca12d39df5ed39a5156c3e3ceba00706052b81040023a18189038186000400e9a76aed2acda29ba2a5dbdc1f04c6160bc16c6d16b737a557f9dcbc8efb79dd1b9eabfc0a911ea3fd574176e2cbf32caa9babb505b04f30ecf369e6bec91d1ac201a8aa718c0c293b085d7902a314cab6e8048e458cc28c7da4fff2fcbf3da6d42fee94de5e0a3fb34342780e3f9df7b424911d6efb8628079566b50efe6971271eea");
+
+// Invalid P-521 key that has mismatched named curve identifiers in the mentioned ECParameters structures.
+var pkcs8P521KeyMismatchedCurveIdentifiers = hexStringToUint8Array("3081f7020100301006072a8648ce3d020106052b810400230481df3081dc02010104420160ccf72d28b6df9768c30f67e77a000ecdb6e20381d8ee6f5474d6a612c39b7f3d361e1e9901f4cc573dcfc7da3eeadcb3e10532ca12d39df5ed39a5156c3e3ceba00706052b81040022a18189038186000400e9a76aed2acda29ba2a5dbdc1f04c6160bc16c6d16b737a557f9dcbc8efb79dd1b9eabfc0a911ea3fd574176e2cbf32caa9babb505b04f30ecf369e6bec91d1ac201a8aa718c0c293b085d7902a314cab6e8048e458cc28c7da4fff2fcbf3da6d42fee94de5e0a3fb34342780e3f9df7b424911d6efb8628079566b50efe6971271eea");
+
+// Invalid P-521 key that has a public key of invalid length (its last byte is clipped).
+var pkcs8P521KeyInvalidPublicKeyLength = hexStringToUint8Array("3081f6020100301006072a8648ce3d020106052b810400230481de3081db02010104420160ccf72d28b6df9768c30f67e77a000ecdb6e20381d8ee6f5474d6a612c39b7f3d361e1e9901f4cc573dcfc7da3eeadcb3e10532ca12d39df5ed39a5156c3e3ceba00706052b81040023a18188038185000400e9a76aed2acda29ba2a5dbdc1f04c6160bc16c6d16b737a557f9dcbc8efb79dd1b9eabfc0a911ea3fd574176e2cbf32caa9babb505b04f30ecf369e6bec91d1ac201a8aa718c0c293b085d7902a314cab6e8048e458cc28c7da4fff2fcbf3da6d42fee94de5e0a3fb34342780e3f9df7b424911d6efb8628079566b50efe6971271eea");
+
+// Invalid P-521 key that has a public key of invalid EC point format (leading 0x05 byte instead of 0x04).
+var pkcs8P521KeyInvalidPublicKeyECPointFormat= hexStringToUint8Array("3081f7020100301006072a8648ce3d020106052b810400230481df3081dc02010104420160ccf72d28b6df9768c30f67e77a000ecdb6e20381d8ee6f5474d6a612c39b7f3d361e1e9901f4cc573dcfc7da3eeadcb3e10532ca12d39df5ed39a5156c3e3ceba00706052b81040023a18189038186000500e9a76aed2acda29ba2a5dbdc1f04c6160bc16c6d16b737a557f9dcbc8efb79dd1b9eabfc0a911ea3fd574176e2cbf32caa9babb505b04f30ecf369e6bec91d1ac201a8aa718c0c293b085d7902a314cab6e8048e458cc28c7da4fff2fcbf3da6d42fee94de5e0a3fb34342780e3f9df7b424911d6efb8628079566b50efe6971271eea");
+
+// Invalid P-521 key that has a public key of invalid value (0xabad1dea).
+var pkcs8P521KeyInvalidPublicKey = hexStringToUint8Array("3081f7020100301006072a8648ce3d020106052b810400230481df3081dc02010104420160ccf72d28b6df9768c30f67e77a000ecdb6e20381d8ee6f5474d6a612c39b7f3d361e1e9901f4cc573dcfc7da3eeadcb3e10532ca12d39df5ed39a5156c3e3ceba00706052b81040023a1818903818600040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000abad1dea");
+
+function importKey(keyData)
+{
+    return crypto.subtle.importKey("pkcs8", keyData, { name: "ECDSA", namedCurve: "P-521" }, true, [ "sign" ]);
+}
+
+Promise.resolve().then(function(result) {
+    debug("ECDSA: importing P-521 key that uses matching curve identifiers and valid public key in ECParameters structures in PKCS#8 ...");
+    return importKey(pkcs8P521ValidKey);
+}).then(function(result) {
+    testPassed("Successfully imported a P-521 key.");
+
+    debug("ECDSA: importing P-521 key whose curve identifiers in ECParameters structures in PKCS#8 don't match ...");
+    return shouldReject('importKey(pkcs8P521KeyMismatchedCurveIdentifiers)');
+}).then(function(result) {
+    debug("ECDSA: importing P-521 key that has a public key in PKCS#8 of invalid length ...");
+    return shouldReject('importKey(pkcs8P521KeyInvalidPublicKeyLength)');
+}).then(function(result) {
+    debug("ECDSA: importing P-521 key that has a public key in PKCS#8 of invalid EC point format ...");
+    return shouldReject('importKey(pkcs8P521KeyInvalidPublicKeyECPointFormat)');
+}).then(function(result) {
+    debug("ECDSA: importing P-521 key that has an invalid public key in PKCS#8 ...");
+    return shouldReject('importKey(pkcs8P521KeyInvalidPublicKey)');
+}).then(function(result) {
+    finishJSTest();
+});;
+
+</script>
+
+</body>
+</html>
index dd9f6d0..fe3bae9 100644 (file)
@@ -783,6 +783,26 @@ crypto/subtle/rsa-pss-import-spki-key.html [ Pass ]
 crypto/workers/subtle/rsa-pss-import-key-sign.html [ Pass ]
 crypto/workers/subtle/rsa-pss-import-key-verify.html [ Pass ]
 
+# Missing support for 521-bit elliptic curves.
+webkit.org/b/175199 crypto/subtle/ec-import-pkcs8-key-export-pkcs8-key-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ec-import-spki-key-export-spki-key-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-generate-export-jwk-key-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-generate-export-key-pkcs8-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-generate-export-key-raw-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-generate-export-key-spki-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-generate-key-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-import-jwk-private-key-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-import-jwk-public-key-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-import-pkcs8-key-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-import-raw-key-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-import-spki-key-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdsa-generate-key-sign-verify-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdsa-import-jwk-public-key-alg-521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdsa-import-key-sign-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdsa-import-key-verify-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdsa-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey.html [ Skip ]
+
 # libgcrypt-based implementation supports ecDH algorithm identifier for ECDH SPKI imports.
 crypto/subtle/ecdh-import-spki-key-ecdh-identifier.html [ Pass ]
 
index c34910e..0aece1b 100644 (file)
@@ -2881,3 +2881,23 @@ fast/text/accessibility-bold-system-font-2.html [ Pass ]
 fast/text/font-lookup-dot-prefix-case-sensitive.html [ Pass ]
 
 webkit.org/b/172518 http/tests/preload/viewport/meta-viewport-link-headers.php [ Pass Failure ]
+
+# Missing support for 521-bit elliptic curves.
+crypto/subtle/ec-import-pkcs8-key-export-pkcs8-key-p521.html
+crypto/subtle/ec-import-spki-key-export-spki-key-p521.html
+crypto/subtle/ecdh-generate-export-jwk-key-p521.html
+crypto/subtle/ecdh-generate-export-key-pkcs8-p521.html
+crypto/subtle/ecdh-generate-export-key-raw-p521.html
+crypto/subtle/ecdh-generate-export-key-spki-p521.html
+crypto/subtle/ecdh-generate-key-p521.html
+crypto/subtle/ecdh-import-jwk-private-key-p521.html
+crypto/subtle/ecdh-import-jwk-public-key-p521.html
+crypto/subtle/ecdh-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey.html
+crypto/subtle/ecdh-import-pkcs8-key-p521.html
+crypto/subtle/ecdh-import-raw-key-p521.html
+crypto/subtle/ecdh-import-spki-key-p521.html
+crypto/subtle/ecdsa-generate-key-sign-verify-p521.html
+crypto/subtle/ecdsa-import-jwk-public-key-alg-521.html
+crypto/subtle/ecdsa-import-key-sign-p521.html
+crypto/subtle/ecdsa-import-key-verify-p521.html
+crypto/subtle/ecdsa-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey.html
index 786e538..e7a4118 100644 (file)
@@ -1614,3 +1614,22 @@ webkit.org/b/173560 inspector/css/add-rule.html [ Pass Timeout ]
 
 webkit.org/b/173780 [ Debug ] imported/w3c/web-platform-tests/html/webappapis/timers/type-long-settimeout.html [ Pass Failure ]
 
+# Missing support for 521-bit elliptic curves.
+crypto/subtle/ec-import-pkcs8-key-export-pkcs8-key-p521.html
+crypto/subtle/ec-import-spki-key-export-spki-key-p521.html
+crypto/subtle/ecdh-generate-export-jwk-key-p521.html
+crypto/subtle/ecdh-generate-export-key-pkcs8-p521.html
+crypto/subtle/ecdh-generate-export-key-raw-p521.html
+crypto/subtle/ecdh-generate-export-key-spki-p521.html
+crypto/subtle/ecdh-generate-key-p521.html
+crypto/subtle/ecdh-import-jwk-private-key-p521.html
+crypto/subtle/ecdh-import-jwk-public-key-p521.html
+crypto/subtle/ecdh-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey.html
+crypto/subtle/ecdh-import-pkcs8-key-p521.html
+crypto/subtle/ecdh-import-raw-key-p521.html
+crypto/subtle/ecdh-import-spki-key-p521.html
+crypto/subtle/ecdsa-generate-key-sign-verify-p521.html
+crypto/subtle/ecdsa-import-jwk-public-key-alg-521.html
+crypto/subtle/ecdsa-import-key-sign-p521.html
+crypto/subtle/ecdsa-import-key-verify-p521.html
+crypto/subtle/ecdsa-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey.html
index e060641..f4d0a3c 100644 (file)
@@ -735,6 +735,26 @@ crypto/subtle/rsa-pss-import-spki-key.html [ Pass ]
 crypto/workers/subtle/rsa-pss-import-key-sign.html [ Pass ]
 crypto/workers/subtle/rsa-pss-import-key-verify.html [ Pass ]
 
+# Missing support for 521-bit elliptic curves.
+webkit.org/b/175199 crypto/subtle/ec-import-pkcs8-key-export-pkcs8-key-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ec-import-spki-key-export-spki-key-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-generate-export-jwk-key-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-generate-export-key-pkcs8-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-generate-export-key-raw-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-generate-export-key-spki-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-generate-key-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-import-jwk-private-key-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-import-jwk-public-key-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-import-pkcs8-key-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-import-raw-key-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdh-import-spki-key-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdsa-generate-key-sign-verify-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdsa-import-jwk-public-key-alg-521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdsa-import-key-sign-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdsa-import-key-verify-p521.html [ Skip ]
+webkit.org/b/175199 crypto/subtle/ecdsa-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey.html [ Skip ]
+
 # ENABLE_CSS_COMPOSITING
 Bug(WPE) transitions/blendmode-transitions.html [ Failure ]