Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(995)

Side by Side Diff: LayoutTests/crypto/subtle/derive-hkdf-keys.html

Issue 822083003: Webcrypto: add layout tests for HKDF algorithm (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: remove duplicate test case Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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>
10
11 <script>
12 description("Test deriving HKDF keys with deriveKey()");
13
14 jsTestIsAsync = true;
15
16 var extractable = true;
17 var derivingKeyAlgorithm = {
18 name: "HKDF",
19 hash: "SHA-256",
20 salt: new Uint8Array(),
21 info: new Uint8Array()
22 };
23
24 var privateKeyJSON = {
25 "kty": "EC",
26 "crv": "P-256",
27 "d": "1mGcHOo_eTxXMTgSjWLLa5DCZIf0o8NNySooVNefCIw",
28 "x": "QcD58SaUjtYiUaUnTaOMWC7YKyfQ5yD0-8F9RStayBU",
29 "y": "CjHmp9BL54FleRbhJVQb1MgVu5YsFn7tJt0VWof_jj0"
30 };
31
32 var publicKeyJSON = {
33 "kty": "EC",
34 "crv": "P-256",
35 "x": "AGzVMZDcNVrG7e8m9bLFTy7Si7o1IcU-SNyI8_Up62E",
36 "y": "bSVna0fR_BTIgH5--cEXXgOB3J2IlxKTmb8YeOZ7UKE"
37 };
38
39 var secret = hexStringToUint8Array("82b17497eefdeee07fb108496b1e88b1975e42a98046 b5521d18edc96a639fea");
40
41 var hkdfAlgorithm = {
42 name: "HKDF",
43 hash: "SHA-256",
44 salt: new Uint8Array(),
45 info: new Uint8Array()
46 }
47
48 Promise.resolve(null).then(function(result) {
49 return crypto.subtle.importKey("jwk", privateKeyJSON, {name: "ECDH", namedCu rve: "P-256"}, true, ["deriveKey"]);
50 }).then(function(result) {
51 privateKey = result;
52
53 return crypto.subtle.importKey("jwk", publicKeyJSON, {name: "ECDH", namedCur ve: "P-256"}, true, []);
54 }).then(function(result) {
55 publicKey = result;
56
57 debug("Derive an HKDF key from ECDH keys");
58 return crypto.subtle.deriveKey({name: "ECDH", namedCurve: "P-256", public: p ublicKey}, privateKey, "HKDF", true, ['deriveKey', 'deriveBits']);
59 }).then(function(result) {
60 hkdfKey = result;
61
62 shouldEvaluateAs("hkdfKey.algorithm.name", "HKDF");
63 shouldEvaluateAs("hkdfKey.extractable", true);
64 shouldEvaluateAs("hkdfKey.usages.join(',')", "deriveKey,deriveBits");
65
66 debug("\nDerive 128 bits from the HKDF key");
67 return crypto.subtle.deriveBits(hkdfAlgorithm, hkdfKey, 128);
68 }).then(function(result) {
69 derivedBits = result;
70
71 return crypto.subtle.importKey("raw", secret, hkdfAlgorithm, true, ['deriveB its']);
72 }).then(function(hkdfKey) {
73 return crypto.subtle.deriveBits(hkdfAlgorithm, hkdfKey, 128);
74 }).then(function(result) {
75 expectedDerivedBits = result;
76
77 shouldEvaluateAs("bytesToHexString(derivedBits)", bytesToHexString(expectedD erivedBits));
78 }).then(finishJSTest, failAndFinishJSTest);
79
80 </script>
81
82 </body>
83 </html>
OLDNEW
« no previous file with comments | « LayoutTests/crypto/subtle/clone-hmacKey.html ('k') | LayoutTests/crypto/subtle/derive-hkdf-keys-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698