[WebCrypto] Crypto operations should copy their parameters before hoping to another...
[WebKit-https.git] / LayoutTests / crypto / subtle / aes-gcm-import-key-unwrap-ec-raw-key.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4     <script src="../../resources/js-test-pre.js"></script>
5     <script src="../resources/common.js"></script>
6 </head>
7 <body>
8 <p id="description"></p>
9 <div id="console"></div>
10
11 <script>
12     description("Test unwrapping an EC raw key with AES-GCM using an imported key");
13
14     jsTestIsAsync = true;
15
16     var extractable = true;
17     var expectedRawKey = "04d454955a2793be2905906d4d3b286450268c6dd421c701fa682bb8133fac46d0f6398d4cba8ce1c8c185d0271dc348f58415dcef0b166a3e11d65693c9ed01a2";
18     var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
19     var aesGcmParams = {
20         name: "aes-gcm",
21         iv: asciiToUint8Array("jnOw99oOZFLIEPMr"),
22     };
23     var wrappedKey = hexStringToUint8Array("b50b299894672c25341db938ad7dc3f87f05e29a36e062b08f7022f9bb7ee41a6d503bfa460e63333c2d1b6fe5b62169276f511ed928cdf0ad9af40807b8a5674af07016e5af5476f6aec5266321e300eb");
24
25
26     crypto.subtle.importKey("raw", rawKey, "aes-gcm", extractable, ["unwrapKey"]).then(function(unwrappingKey) {
27         return crypto.subtle.unwrapKey("raw", wrappedKey, unwrappingKey, aesGcmParams, { name: "ECDH", namedCurve: "P-256" }, extractable, []);
28     }).then(function(cryptoKey) {
29         return crypto.subtle.exportKey("raw", cryptoKey);
30     }).then(function(result) {
31         unwrappedKey = result;
32
33         shouldBe("bytesToHexString(unwrappedKey)", "expectedRawKey");
34
35         finishJSTest();
36     });
37
38 </script>
39
40 <script src="../../resources/js-test-post.js"></script>
41 </body>
42 </html>