subtle crypto deriveBits using pbkdf2 throws exception if dklen >2048 bits
Categories
(Core :: DOM: Web Crypto, defect, P5)
Tracking
()
People
(Reporter: alex, Unassigned)
Details
Comment 1•8 years ago
|
||
Updated•8 years ago
|
| Assignee | ||
Updated•7 years ago
|
Comment 2•6 years ago
|
||
Looks like the limitation is here:
Is there any reason this needs to have a maximum?
Comment 3•4 years ago
|
||
Any updates on this?
Updated•4 years ago
|
Updated•4 years ago
|
Comment 4•4 years ago
|
||
The maximum output length for PBKDF2 is implementation defined (https://datatracker.ietf.org/doc/html/rfc2898#appendix-A.2), and NSS happens to have a 2048 bit maximum. If you need a longer bit string you should use the output to seed a bit generator.
As an NSS bug this is a WONTFIX.
Comment 5•4 years ago
|
||
(New) Web Crypto spec editor here. I'm not sure your reading of the spec is correct - the Web Crypto spec refers to RFC8018 for PBKDF2, not RFC2898. Section 5.2 of RFC8018 says that:
The length of the derived key is
essentially unbounded. (However, the maximum effective search space
for the derived key may be limited by the structure of the underlying
pseudorandom function. See Appendix B.1 for further discussion.)
(...)
Steps:
1. If dkLen > (2^32 - 1) * hLen, output "derived key too long"
and stop.
RFC2898 defines an OID for PBKDF2, and can of course impose or allow additional restrictions on the output length, and the Web Crypto API could do so as well, but today it doesn't. If Mozilla's position is that it should, could you open a spec issue here to discuss this, please?
Comment 6•4 years ago
|
||
This is a wontfix for NSS. But the desired functionality can be implemented at a higher level. Re-opening for further discussion.
Comment 7•4 years ago
|
||
How the code from Alex can be implemented in firefox?
Comment 8•2 years ago
|
||
Two years after initially addressing this issue, it remains unresolved and reproducible. In the interim, I have explored alternatives such as nodeForge and CryptoJS; however, these libraries significantly underperform compared to the native deriveBits API in terms of speed. Is there a viable workaround to this problem, or is it still necessary to rely on non-native APIs within Firefox for this functionality?
Comment 9•2 years ago
•
|
||
What we can (at least, theoretically) do, is to use this code to compute pbkdf2 (quickly prototyped in JS, of course it should be c++)
var k1 = await window.crypto.subtle.importKey(
"raw",
new Uint8Array(32),
{ name: "HMAC", hash: {name: "SHA-256"}},
false,
["sign", "verify"])
salt = new Uint8Array([0x00, 0x00, 0x00, 0x09])
blockOutput = new Uint8Array(32)
forLoop = async _ => {
for (let index = 0; index < 10000; index++) {
await window.crypto.subtle.sign("HMAC", k1, salt).then(function(a) {
salt = new Uint8Array(a);
for (let i = 0; i < 32; i++)
{
blockOutput[i] = blockOutput[i] ^ salt[i];
}
})
}
}
Description
•