Chromium Code Reviews| OLD | NEW |
|---|---|
| (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", | |
|
eroman
2015/01/13 00:45:34
indent by 4.
nharper
2015/01/13 01:43:26
Done.
| |
| 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 | |
| 79 debug("\nTry to derive an HKDF key from an HKDF key"); | |
| 80 var hkdfAlgorithm = { | |
| 81 name: "HKDF", | |
| 82 hash: "SHA-256", | |
| 83 salt: new Uint8Array(), | |
| 84 info: new Uint8Array() | |
| 85 }; | |
| 86 return crypto.subtle.deriveKey(hkdfAlgorithm, hkdfKey, "HKDF", true, ['deriv eBits']); | |
| 87 }).then(failAndFinishJSTest, function(result) { | |
| 88 logError(result); | |
| 89 }).then(finishJSTest, failAndFinishJSTest); | |
| 90 | |
| 91 </script> | |
| 92 | |
| 93 </body> | |
| 94 </html> | |
| OLD | NEW |