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("Tests deriveBits() using HKDF"); | |
13 | |
14 jsTestIsAsync = true; | |
15 | |
16 // These test vectors are from Appendix A of RFC 5869 | |
17 kHkdfTestVectors = [ | |
18 { | |
19 algorithm: "SHA-256", | |
20 input: "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", | |
21 salt: "000102030405060708090a0b0c", | |
22 info: "f0f1f2f3f4f5f6f7f8f9", | |
23 length: 42, | |
24 output: "3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5b
f34007208d5b887185865" | |
25 }, | |
26 { | |
27 algorithm: "SHA-256", | |
28 input: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f4041424344454647
48494a4b4c4d4e4f", | |
29 salt: "606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f8
08182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a
8a9aaabacadaeaf", | |
30 info: "b0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd
0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f
8f9fafbfcfdfeff", | |
31 length: 82, | |
32 output: "b11e398dc80327a1c8e7f78c596a49344f012eda2d4efad8a050cc4c19afa97
c59045a99cac7827271cb41c65e590e09da3275600c2f09b8367793a9aca3db71cc30c58179ec3e8
7c14c01d5c1f3434f1d87" | |
33 }, | |
34 { | |
35 algorithm: "SHA-256", | |
36 input: "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", | |
37 salt: "", | |
38 info: "", | |
39 length: 42, | |
40 output: "8da4e775a563c18f715f802a063c5a31b8a11f5c5ee1879ec3454e5f3c738d2
d9d201395faa4b61a96c8" | |
41 }, | |
42 { | |
43 algorithm: "SHA-1", | |
44 input: "0b0b0b0b0b0b0b0b0b0b0b", | |
45 salt: "000102030405060708090a0b0c", | |
46 info: "f0f1f2f3f4f5f6f7f8f9", | |
47 length: 42, | |
48 output: "085a01ea1b10f36933068b56efa5ad81a4f14b822f5b091568a9cdd4f155fda
2c22e422478d305f3f896" | |
49 }, | |
50 { | |
51 algorithm: "SHA-1", | |
52 input: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f4041424344454647
48494a4b4c4d4e4f", | |
53 salt: "606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f8
08182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a
8a9aaabacadaeaf", | |
54 info: "b0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd
0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f
8f9fafbfcfdfeff", | |
55 length: 82, | |
56 output: "0bd770a74d1160f7c9f12cd5912a06ebff6adcae899d92191fe4305673ba2ff
e8fa3f1a4e5ad79f3f334b3b202b2173c486ea37ce3d397ed034c7f9dfeb15c5e927336d0441f4c4
300e2cff0d0900b52d3b4" | |
57 }, | |
58 { | |
59 algorithm: "SHA-1", | |
60 input: "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", | |
61 salt: "", | |
62 info: "", | |
63 length: 42, | |
64 output: "0ac1af7002b3d761d1e55298da9d0506b9ae52057220a306e07b6b87e8df21d
0ea00033de03984d34918" | |
65 }, | |
66 { | |
67 algorithm: "SHA-1", | |
68 input: "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c", | |
69 salt: "", | |
70 info: "", | |
71 length: 42, | |
72 output: "2c91117204d745f3500d636a62f64f0ab3bae548aa53d423b0d1f27ebba6f5e
5673a081d70cce7acfc48" | |
73 }, | |
74 ]; | |
75 | |
76 var extractable = true; | |
77 function runTest(testCase) | |
78 { | |
79 return Promise.resolve(null).then(function() { | |
80 return crypto.subtle.importKey("raw", hexStringToUint8Array(testCase.inp
ut), "HKDF", extractable, ['deriveKey','deriveBits']); | |
81 }).then(function(result) { | |
82 key = result; | |
83 | |
84 shouldEvaluateAs("key.type", "secret"); | |
85 shouldEvaluateAs("key.extractable", extractable); | |
86 shouldEvaluateAs("key.algorithm.name", "HKDF"); | |
87 shouldEvaluateAs("key.usages.join(',')", "deriveKey,deriveBits"); | |
88 | |
89 return crypto.subtle.deriveBits({name: "HKDF", hash: testCase.algorithm,
salt: hexStringToUint8Array(testCase.salt), info: hexStringToUint8Array(testCas
e.info)}, key, testCase.length * 8); | |
90 }).then(function(result) { | |
91 var testDescription = "HKDF of [" + testCase.input + "]"; | |
92 bytesShouldMatchHexString(testDescription, testCase.output, result); | |
93 }); | |
94 } | |
95 | |
96 var lastPromise = Promise.resolve(null); | |
97 | |
98 kHkdfTestVectors.forEach(function(testCase) { | |
99 lastPromise = lastPromise.then(runTest.bind(null, testCase)); | |
100 }); | |
101 | |
102 lastPromise.then(finishJSTest, failAndFinishJSTest); | |
103 | |
104 </script> | |
105 | |
106 </body> | |
107 </html> | |
OLD | NEW |