Skip to content

Commit 7669912

Browse files
PBKDF2 allows zero length and returns and empty string
This CL adapts our implementation to the spec change described in the PR#380 [1]. Instead of trowing an OperationError exception, we allow now zero as value for the 'length' parameter. Given that the deriveBits operation must result in an empty string, this change early returns to avoid the unnecessary computation of the bits derivation. The specific WTP defined for this case are modified in this CL as well, so no additional test cases are needed. [1] w3c/webcrypto#380 Bug: 376493194 Change-Id: If685c349a0a9d134a8e8f7c902e8aac342945226
1 parent 1b37e8e commit 7669912

File tree

2 files changed

+2
-12
lines changed

2 files changed

+2
-12
lines changed

WebCryptoAPI/derive_bits_keys/derived_bits_length_testcases.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var testCases = {
33
{length: 256, expected: algorithms["HKDF"].derivation},
44
{length: 384, expected: algorithms["HKDF"].derivation384},
55
{length: 230, expected: undefined}, // should throw an exception, not multiple of 8
6-
{length: 0, expected: undefined}, // explicitly disallowed, so should throw
6+
{length: 0, expected: emptyArray},
77
{length: null, expected: undefined }, // should throw an exception
88
{length: undefined, expected: undefined }, // should throw an exception
99
{length: "omitted", expected: undefined }, // default value is null, so should throw
@@ -12,7 +12,7 @@ var testCases = {
1212
{length: 256, expected: algorithms["PBKDF2"].derivation},
1313
{length: 384, expected: algorithms["PBKDF2"].derivation384},
1414
{length: 230, expected: undefined}, // should throw an exception, not multiple of 8
15-
{length: 0, expected: undefined}, // explicitly disallowed, so should throw
15+
{length: 0, expected: emptyArray},
1616
{length: null, expected: undefined }, // should throw an exception
1717
{length: undefined, expected: undefined }, // should throw an exception
1818
{length: "omitted", expected: undefined }, // default value is null, so should throw

WebCryptoAPI/derive_bits_keys/pbkdf2.js

-10
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,6 @@ function define_tests() {
103103

104104
});
105105

106-
// 0 length (OperationError)
107-
subsetTest(promise_test, function(test) {
108-
return subtle.deriveBits({name: "PBKDF2", salt: salts[saltSize], hash: hashName, iterations: parseInt(iterations)}, baseKeys[passwordSize], 0)
109-
.then(function(derivation) {
110-
assert_unreached("0 length should have thrown an OperationError");
111-
}, function(err) {
112-
assert_equals(err.name, "OperationError", "deriveBits with 0 length correctly threw OperationError: " + err.message);
113-
});
114-
}, testName + " with 0 length");
115-
116106
// length not multiple of 8 (OperationError)
117107
subsetTest(promise_test, function(test) {
118108
return subtle.deriveBits({name: "PBKDF2", salt: salts[saltSize], hash: hashName, iterations: parseInt(iterations)}, baseKeys[passwordSize], 44)

0 commit comments

Comments
 (0)