| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../../resources/js-test.js"></script> | 4 <script src="../../resources/js-test.js"></script> |
| 5 <script src="resources/common.js"></script> | 5 <script src="resources/common.js"></script> |
| 6 </head> | 6 </head> |
| 7 <body> | 7 <body> |
| 8 <p id="description"></p> | 8 <p id="description"></p> |
| 9 <div id="console"></div> | 9 <div id="console"></div> |
| 10 | 10 |
| 11 <script> | 11 <script> |
| 12 description("Test deriving HKDF keys with deriveKey()"); | 12 description("Test deriving HKDF keys with deriveKey()"); |
| 13 | 13 |
| 14 jsTestIsAsync = true; | 14 jsTestIsAsync = true; |
| 15 | 15 |
| 16 var extractable = true; | |
| 17 var derivingKeyAlgorithm = { | 16 var derivingKeyAlgorithm = { |
| 18 name: "HKDF", | 17 name: "HKDF", |
| 19 hash: "SHA-256", | 18 hash: "SHA-256", |
| 20 salt: new Uint8Array(), | 19 salt: new Uint8Array(), |
| 21 info: new Uint8Array() | 20 info: new Uint8Array() |
| 22 }; | 21 }; |
| 23 | 22 |
| 24 var privateKeyJSON = { | 23 var privateKeyJSON = { |
| 25 "kty": "EC", | 24 "kty": "EC", |
| 26 "crv": "P-256", | 25 "crv": "P-256", |
| (...skipping 21 matching lines...) Expand all Loading... |
| 48 Promise.resolve(null).then(function(result) { | 47 Promise.resolve(null).then(function(result) { |
| 49 return crypto.subtle.importKey("jwk", privateKeyJSON, {name: "ECDH", namedCu
rve: "P-256"}, true, ["deriveKey"]); | 48 return crypto.subtle.importKey("jwk", privateKeyJSON, {name: "ECDH", namedCu
rve: "P-256"}, true, ["deriveKey"]); |
| 50 }).then(function(result) { | 49 }).then(function(result) { |
| 51 privateKey = result; | 50 privateKey = result; |
| 52 | 51 |
| 53 return crypto.subtle.importKey("jwk", publicKeyJSON, {name: "ECDH", namedCur
ve: "P-256"}, true, []); | 52 return crypto.subtle.importKey("jwk", publicKeyJSON, {name: "ECDH", namedCur
ve: "P-256"}, true, []); |
| 54 }).then(function(result) { | 53 }).then(function(result) { |
| 55 publicKey = result; | 54 publicKey = result; |
| 56 | 55 |
| 57 debug("Derive an HKDF key from ECDH keys"); | 56 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']); | 57 return crypto.subtle.deriveKey({name: "ECDH", namedCurve: "P-256", public: p
ublicKey}, privateKey, "HKDF", false, ['deriveKey', 'deriveBits']); |
| 59 }).then(function(result) { | 58 }).then(function(result) { |
| 60 hkdfKey = result; | 59 hkdfKey = result; |
| 61 | 60 |
| 62 shouldEvaluateAs("hkdfKey.algorithm.name", "HKDF"); | 61 shouldEvaluateAs("hkdfKey.algorithm.name", "HKDF"); |
| 63 shouldEvaluateAs("hkdfKey.extractable", true); | 62 shouldEvaluateAs("hkdfKey.extractable", false); |
| 64 shouldEvaluateAs("hkdfKey.usages.join(',')", "deriveKey,deriveBits"); | 63 shouldEvaluateAs("hkdfKey.usages.join(',')", "deriveKey,deriveBits"); |
| 65 | 64 |
| 66 debug("\nDerive 128 bits from the HKDF key"); | 65 debug("\nDerive 128 bits from the HKDF key"); |
| 67 return crypto.subtle.deriveBits(hkdfAlgorithm, hkdfKey, 128); | 66 return crypto.subtle.deriveBits(hkdfAlgorithm, hkdfKey, 128); |
| 68 }).then(function(result) { | 67 }).then(function(result) { |
| 69 derivedBits = result; | 68 derivedBits = result; |
| 70 | 69 |
| 71 return crypto.subtle.importKey("raw", secret, hkdfAlgorithm, true, ['deriveB
its']); | 70 return crypto.subtle.importKey("raw", secret, hkdfAlgorithm, false, ['derive
Bits']); |
| 72 }).then(function(hkdfKey) { | 71 }).then(function(hkdfKey) { |
| 73 return crypto.subtle.deriveBits(hkdfAlgorithm, hkdfKey, 128); | 72 return crypto.subtle.deriveBits(hkdfAlgorithm, hkdfKey, 128); |
| 74 }).then(function(result) { | 73 }).then(function(result) { |
| 75 expectedDerivedBits = result; | 74 expectedDerivedBits = result; |
| 76 | 75 |
| 77 shouldEvaluateAs("bytesToHexString(derivedBits)", bytesToHexString(expectedD
erivedBits)); | 76 shouldEvaluateAs("bytesToHexString(derivedBits)", bytesToHexString(expectedD
erivedBits)); |
| 78 }).then(finishJSTest, failAndFinishJSTest); | 77 }).then(finishJSTest, failAndFinishJSTest); |
| 79 | 78 |
| 80 </script> | 79 </script> |
| 81 | 80 |
| 82 </body> | 81 </body> |
| 83 </html> | 82 </html> |
| OLD | NEW |