Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / crypto / subtle / derive-hkdf-keys.html
blob8c846275900d18eea779cb8635010f8c3e456b0e
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 <script src="resources/common.js"></script>
6 </head>
7 <body>
8 <p id="description"></p>
9 <div id="console"></div>
11 <script>
12 description("Test deriving HKDF keys with deriveKey()");
14 jsTestIsAsync = true;
16 var extractable = true;
17 var derivingKeyAlgorithm = {
18 name: "HKDF",
19 hash: "SHA-256",
20 salt: new Uint8Array(),
21 info: new Uint8Array()
24 var privateKeyJSON = {
25 "kty": "EC",
26 "crv": "P-256",
27 "d": "1mGcHOo_eTxXMTgSjWLLa5DCZIf0o8NNySooVNefCIw",
28 "x": "QcD58SaUjtYiUaUnTaOMWC7YKyfQ5yD0-8F9RStayBU",
29 "y": "CjHmp9BL54FleRbhJVQb1MgVu5YsFn7tJt0VWof_jj0"
32 var publicKeyJSON = {
33 "kty": "EC",
34 "crv": "P-256",
35 "x": "AGzVMZDcNVrG7e8m9bLFTy7Si7o1IcU-SNyI8_Up62E",
36 "y": "bSVna0fR_BTIgH5--cEXXgOB3J2IlxKTmb8YeOZ7UKE"
39 var secret = hexStringToUint8Array("82b17497eefdeee07fb108496b1e88b1975e42a98046b5521d18edc96a639fea");
41 var hkdfAlgorithm = {
42 name: "HKDF",
43 hash: "SHA-256",
44 salt: new Uint8Array(),
45 info: new Uint8Array()
48 Promise.resolve(null).then(function(result) {
49 return crypto.subtle.importKey("jwk", privateKeyJSON, {name: "ECDH", namedCurve: "P-256"}, true, ["deriveKey"]);
50 }).then(function(result) {
51 privateKey = result;
53 return crypto.subtle.importKey("jwk", publicKeyJSON, {name: "ECDH", namedCurve: "P-256"}, true, []);
54 }).then(function(result) {
55 publicKey = result;
57 debug("Derive an HKDF key from ECDH keys");
58 return crypto.subtle.deriveKey({name: "ECDH", namedCurve: "P-256", public: publicKey}, privateKey, "HKDF", true, ['deriveKey', 'deriveBits']);
59 }).then(function(result) {
60 hkdfKey = result;
62 shouldEvaluateAs("hkdfKey.algorithm.name", "HKDF");
63 shouldEvaluateAs("hkdfKey.extractable", true);
64 shouldEvaluateAs("hkdfKey.usages.join(',')", "deriveKey,deriveBits");
66 debug("\nDerive 128 bits from the HKDF key");
67 return crypto.subtle.deriveBits(hkdfAlgorithm, hkdfKey, 128);
68 }).then(function(result) {
69 derivedBits = result;
71 return crypto.subtle.importKey("raw", secret, hkdfAlgorithm, true, ['deriveBits']);
72 }).then(function(hkdfKey) {
73 return crypto.subtle.deriveBits(hkdfAlgorithm, hkdfKey, 128);
74 }).then(function(result) {
75 expectedDerivedBits = result;
77 shouldEvaluateAs("bytesToHexString(derivedBits)", bytesToHexString(expectedDerivedBits));
78 }).then(finishJSTest, failAndFinishJSTest);
80 </script>
82 </body>
83 </html>