4 <script src=
"../../../resources/js-test.js"></script>
5 <script src=
"../resources/common.js"></script>
8 <p id=
"description"></p>
9 <div id=
"console"></div>
12 description("Test that keys can be derived from an HKDF key");
16 kHkdfKey
= "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b";
18 var extractable
= true;
19 var derivingKeyAlgorithm
= {
22 salt
: new Uint8Array(),
23 info
: new Uint8Array()
26 Promise
.resolve(null).then(function(result
) {
27 return crypto
.subtle
.importKey("raw", hexStringToUint8Array(kHkdfKey
), "HKDF", extractable
, ['deriveKey']);
28 }).then(function(result
) {
31 return crypto
.subtle
.deriveKey(derivingKeyAlgorithm
, baseKey
, {name
: "AES-GCM", length
: 256}, extractable
, ['encrypt']);
32 }).then(function(result
) {
35 shouldEvaluateAs("derivedKey.type", "secret");
36 shouldEvaluateAs("derivedKey.extractable", extractable
);
37 shouldEvaluateAs("derivedKey.algorithm.name", "AES-GCM");
38 shouldEvaluateAs("derivedKey.usages.join(',')", "encrypt");
40 debug("\nTry to derive an HKDF key...");
41 return crypto
.subtle
.deriveKey(derivingKeyAlgorithm
, baseKey
, "HKDF", extractable
, ['deriveKey']);
42 }).then(failAndFinishJSTest
, function(result
) {
45 // Create an empty key and test deriving a key with it.
46 return crypto
.subtle
.importKey("raw", new Uint8Array(), "HKDF", extractable
, ['deriveKey']);
47 }).then(function(result
) {
50 shouldEvaluateAs("emptyKey.type", "secret");
51 shouldEvaluateAs("emptyKey.extractable", extractable
);
52 shouldEvaluateAs("emptyKey.algorithm.name", "HKDF");
53 shouldEvaluateAs("emptyKey.usages.join(',')", "deriveKey");
55 return crypto
.subtle
.deriveKey(derivingKeyAlgorithm
, emptyKey
, {name
: "AES-GCM", length
: 256}, extractable
, ['encrypt']);
56 }).then(function(result
) {
59 shouldEvaluateAs("derivedKey.type", "secret");
60 shouldEvaluateAs("derivedKey.extractable", extractable
);
61 shouldEvaluateAs("derivedKey.algorithm.name", "AES-GCM");
62 shouldEvaluateAs("derivedKey.usages.join(',')", "encrypt");
63 }).then(finishJSTest
, failAndFinishJSTest
);