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

Side by Side Diff: LayoutTests/crypto/subtle/pbkdf2-deriveBits.html

Issue 820523003: [webcrypto] Implement PBKDF2 (blink-side) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase and structured cloning test 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("Tests importKey/deriveBits for PBKDF2");
13
14 jsTestIsAsync = true;
15
16 // -------------------------------------------------
17 // Successful password import and bits derivation
18 // -------------------------------------------------
19
20 // Test vectors were copied from:
21 // https://tools.ietf.org/html/rfc6070
22 //
23
24 var kPbkdf2SuccessVectors = [
25 {
26 password: "password",
27 salt: "salt",
28 c: 1,
29 dkLen: 20,
30 hash: "SHA-1",
31 derived_key_full_length: "0c60c80f961f0e71f3a9b524af6012062fe037a6"
32 },
33
34 {
35 password: "password",
36 salt: "salt",
37 c: 2,
38 dkLen: 20,
39 hash: "SHA-1",
40 derived_key_full_length: "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957"
41 },
42
43 {
44 password: "password",
45 salt: "salt",
46 c: 4096,
47 dkLen: 20,
48 hash: "SHA-1",
49 derived_key_full_length: "4b007901b765489abead49d926f721d065a429c1"
50 },
51
52 // 16777216 iterations would timeout
eroman 2015/01/14 21:12:22 Delete this commented out code (since we do not pl
xun.sun 2015/01/15 17:13:29 Done.
53 // {
54 // password: "password",
55 // salt: "salt",
56 // c: 16777216,
57 // dkLen: 20,
58 // hash: "SHA-1",
59 // derived_key_full_length: "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984"
60 // },
61
62 {
63 password: "passwordPASSWORDpassword",
64 salt: "saltSALTsaltSALTsaltSALTsaltSALTsalt",
65 c: 4096,
66 dkLen: 25,
67 hash: "SHA-1",
68 derived_key_full_length: "3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038 "
eroman 2015/01/14 21:12:22 naming: I suggest either "derived_key" or "dk". Th
xun.sun 2015/01/15 17:13:29 Done.
69 },
70
71 {
72 password: "pass\0word",
73 salt: "sa\0lt",
74 c: 4096,
75 dkLen: 16,
76 hash: "SHA-1",
77 derived_key_full_length: "56fa6aa75548099dcc37d7f03425e0c3"
78 },
79 ];
80
81 function runPbkdf2SuccessTestCase(testCase)
82 {
83 var algorithm = {name: 'PBKDF2'};
84
85 var key = null;
86 var password = asciiToUint8Array(testCase.password);
87 var usages = ['deriveBits', 'deriveKey'];
88 var extractable = false;
89
90 var params = {
91 name: 'PBKDF2',
92 salt: asciiToUint8Array(testCase.salt),
93 iterations: testCase.c,
94 hash: {name: testCase.hash}
95 };
96 // (1) Import the password
97 return crypto.subtle.importKey('raw', password, algorithm, extractable, usag es).then(function(result) {
98 key = result;
99 // shouldBe() can only resolve variables in global context.
100 tmpKey = key;
101 shouldEvaluateAs("tmpKey.type", "secret");
102 shouldEvaluateAs("tmpKey.extractable", false);
103 shouldEvaluateAs("tmpKey.algorithm.name", "PBKDF2");
104 shouldEvaluateAs("tmpKey.usages.join(',')", "deriveKey,deriveBits");
105
106 // (2) Derive bits
107 return crypto.subtle.deriveBits(params, key, testCase.dkLen*8);
108 }).then(function(result) {
109 bytesShouldMatchHexString("deriveBits", testCase.derived_key_full_length , result);
110 return crypto.subtle.deriveBits(params, key, 0);
111 }).then(function(result) {
112 derivedBits = result;
113 shouldBe("derivedBits.byteLength", "0");
114 });
115 }
116
117 var lastPromise = Promise.resolve(null);
118
119 kPbkdf2SuccessVectors.forEach(function(test) {
120 lastPromise = lastPromise.then(runPbkdf2SuccessTestCase.bind(null, test));
121 });
122
123 lastPromise.then(finishJSTest, failAndFinishJSTest);
124
125 </script>
126
127 </body>
128 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698