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

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

Issue 957713004: [WebCrypto] Split LayoutTests/crypto/subtle into per-algorithm directories (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Updated to latest master Created 5 years, 10 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 encrypt/decrypt for AES-CBC");
13
14 jsTestIsAsync = true;
15
16 // -------------------------------------------------
17 // Successful password import and key 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 {
53 password: "passwordPASSWORDpassword",
54 salt: "saltSALTsaltSALTsaltSALTsaltSALTsalt",
55 c: 4096,
56 dkLen: 25,
57 hash: "SHA-1",
58 derived_key_full_length: "3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038 "
59 },
60
61 {
62 password: "pass\0word",
63 salt: "sa\0lt",
64 c: 4096,
65 dkLen: 16,
66 hash: "SHA-1",
67 derived_key_full_length: "56fa6aa75548099dcc37d7f03425e0c3"
68 },
69 ];
70
71 var key = null;
72 var dkey = null;
73
74 function runPbkdf2SuccessTestCase(testCase)
75 {
76 var algorithm = {name: 'PBKDF2'};
77
78 var password = asciiToUint8Array(testCase.password);
79 var usages = ['deriveBits', 'deriveKey'];
80 var extractable = false;
81
82 var params = {
83 name: 'PBKDF2',
84 salt: asciiToUint8Array(testCase.salt),
85 iterations: testCase.c,
86 hash: {name: testCase.hash}
87 };
88 // (1) Import the password
89 return crypto.subtle.importKey('raw', password, algorithm, extractable, usag es).then(function(result) {
90 key = result;
91 // shouldBe() can only resolve variables in global context.
92 tmpKey = key;
93 shouldEvaluateAs("tmpKey.type", "secret");
94 shouldEvaluateAs("tmpKey.extractable", false);
95 shouldEvaluateAs("tmpKey.algorithm.name", "PBKDF2");
96 shouldEvaluateAs("tmpKey.usages.join(',')", "deriveKey,deriveBits");
97
98 var derivedAlgorithm = {name: 'aes-cbc', length: 128};
99 // (2) Derive key for aes-cbc
100 return crypto.subtle.deriveKey(params, key, derivedAlgorithm, true, ['en crypt']);
101 }).then(function(result) {
102 dkey = result;
103
104 // Verify the key's properties.
105 shouldEvaluateAs("dkey.type", "secret");
106 shouldEvaluateAs("dkey.extractable", true);
107 shouldEvaluateAs("dkey.algorithm.name", "AES-CBC");
108 shouldEvaluateAs("dkey.algorithm.length", 128);
109 shouldEvaluateAs("dkey.usages.join(',')", "encrypt");
110
111 // Export the key and check its bytes.
112 return crypto.subtle.exportKey("raw",dkey);
113 }).then(function(result) {
114 bytesShouldMatchHexString("Derivedkey", testCase.derived_key_full_length .substring(0, 32), result);
115 });
116 }
117
118 var lastPromise = Promise.resolve(null);
119
120 kPbkdf2SuccessVectors.forEach(function(test) {
121 lastPromise = lastPromise.then(runPbkdf2SuccessTestCase.bind(null, test));
122 });
123
124 lastPromise.then(finishJSTest, failAndFinishJSTest);
125
126 </script>
127
128 </body>
129 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698