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("Tests importKey/deriveBits for PBKDF2");
16 // -------------------------------------------------
17 // Successful password import and bits derivation
18 // -------------------------------------------------
20 var kPbkdf2SuccessVectors
= [
23 password
: [200, 201, 202, 203, 204, 205, 206, 207],
28 derived_key
: "a7950c143ec64e2b8d4bb1db8677188b"
33 password
: "pass\0word",
38 derived_key
: "7deaf8b4a801011c1cd27f36e3bfc962"
48 derived_key
: "83eb100b6a3a975f0fe3ffcdc2419852"
58 derived_key
: "e4dfce3830983830c50c351a0b0f79e1"
68 derived_key
: "750261780a187897a9978371599db5d1"
82 function runPbkdf2SuccessTestCase(testCase
)
84 var algorithm
= {name
: 'PBKDF2'};
88 if (typeof testCase
.password
=== 'string')
89 password
= asciiToUint8Array(testCase
.password
);
90 else if (Array
.isArray(testCase
.password
))
91 password
= new Uint8Array(testCase
.password
);
93 var usages
= ['deriveBits', 'deriveKey'];
94 var extractable
= false;
98 salt
: asciiToUint8Array(testCase
.salt
),
99 iterations
: testCase
.c
,
100 hash
: {name
: testCase
.hash
}
102 // (1) Import the password
103 return crypto
.subtle
.importKey('raw', password
, algorithm
, extractable
, usages
).then(function(result
) {
105 // shouldBe() can only resolve variables in global context.
107 shouldEvaluateAs("tmpKey.type", "secret");
108 shouldEvaluateAs("tmpKey.extractable", false);
109 shouldEvaluateAs("tmpKey.algorithm.name", "PBKDF2");
110 shouldEvaluateAs("tmpKey.usages.join(',')", "deriveKey,deriveBits");
113 return crypto
.subtle
.deriveBits(params
, key
, testCase
.dkLen
*8);
114 }).then(function(result
) {
115 bytesShouldMatchHexString("deriveBits", testCase
.derived_key
, result
);
116 return crypto
.subtle
.deriveBits(params
, key
, 0);
117 }).then(function(result
) {
118 derivedBits
= result
;
119 shouldBe("derivedBits.byteLength", "0");
123 var lastPromise
= Promise
.resolve(null);
125 kPbkdf2SuccessVectors
.forEach(function(test
) {
126 lastPromise
= lastPromise
.then(runPbkdf2SuccessTestCase
.bind(null, test
));
129 lastPromise
.then(finishJSTest
, failAndFinishJSTest
);