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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/crypto/subtle/pbkdf2-deriveBits.html
diff --git a/LayoutTests/crypto/subtle/pbkdf2-deriveBits.html b/LayoutTests/crypto/subtle/pbkdf2-deriveBits.html
new file mode 100644
index 0000000000000000000000000000000000000000..3dd9e36c7fc8205fadf4f3d525af586e258d66f4
--- /dev/null
+++ b/LayoutTests/crypto/subtle/pbkdf2-deriveBits.html
@@ -0,0 +1,128 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test.js"></script>
+<script src="resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Tests importKey/deriveBits for PBKDF2");
+
+jsTestIsAsync = true;
+
+// -------------------------------------------------
+// Successful password import and bits derivation
+// -------------------------------------------------
+
+// Test vectors were copied from:
+// https://tools.ietf.org/html/rfc6070
+//
+
+var kPbkdf2SuccessVectors = [
+ {
+ password: "password",
+ salt: "salt",
+ c: 1,
+ dkLen: 20,
+ hash: "SHA-1",
+ derived_key_full_length: "0c60c80f961f0e71f3a9b524af6012062fe037a6"
+ },
+
+ {
+ password: "password",
+ salt: "salt",
+ c: 2,
+ dkLen: 20,
+ hash: "SHA-1",
+ derived_key_full_length: "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957"
+ },
+
+ {
+ password: "password",
+ salt: "salt",
+ c: 4096,
+ dkLen: 20,
+ hash: "SHA-1",
+ derived_key_full_length: "4b007901b765489abead49d926f721d065a429c1"
+ },
+
+// 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.
+// {
+// password: "password",
+// salt: "salt",
+// c: 16777216,
+// dkLen: 20,
+// hash: "SHA-1",
+// derived_key_full_length: "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984"
+// },
+
+ {
+ password: "passwordPASSWORDpassword",
+ salt: "saltSALTsaltSALTsaltSALTsaltSALTsalt",
+ c: 4096,
+ dkLen: 25,
+ hash: "SHA-1",
+ 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.
+ },
+
+ {
+ password: "pass\0word",
+ salt: "sa\0lt",
+ c: 4096,
+ dkLen: 16,
+ hash: "SHA-1",
+ derived_key_full_length: "56fa6aa75548099dcc37d7f03425e0c3"
+ },
+];
+
+function runPbkdf2SuccessTestCase(testCase)
+{
+ var algorithm = {name: 'PBKDF2'};
+
+ var key = null;
+ var password = asciiToUint8Array(testCase.password);
+ var usages = ['deriveBits', 'deriveKey'];
+ var extractable = false;
+
+ var params = {
+ name: 'PBKDF2',
+ salt: asciiToUint8Array(testCase.salt),
+ iterations: testCase.c,
+ hash: {name: testCase.hash}
+ };
+ // (1) Import the password
+ return crypto.subtle.importKey('raw', password, algorithm, extractable, usages).then(function(result) {
+ key = result;
+ // shouldBe() can only resolve variables in global context.
+ tmpKey = key;
+ shouldEvaluateAs("tmpKey.type", "secret");
+ shouldEvaluateAs("tmpKey.extractable", false);
+ shouldEvaluateAs("tmpKey.algorithm.name", "PBKDF2");
+ shouldEvaluateAs("tmpKey.usages.join(',')", "deriveKey,deriveBits");
+
+ // (2) Derive bits
+ return crypto.subtle.deriveBits(params, key, testCase.dkLen*8);
+ }).then(function(result) {
+ bytesShouldMatchHexString("deriveBits", testCase.derived_key_full_length, result);
+ return crypto.subtle.deriveBits(params, key, 0);
+ }).then(function(result) {
+ derivedBits = result;
+ shouldBe("derivedBits.byteLength", "0");
+ });
+}
+
+var lastPromise = Promise.resolve(null);
+
+kPbkdf2SuccessVectors.forEach(function(test) {
+ lastPromise = lastPromise.then(runPbkdf2SuccessTestCase.bind(null, test));
+});
+
+lastPromise.then(finishJSTest, failAndFinishJSTest);
+
+</script>
+
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698