Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow length=0 in HKDF and PBKDF2 derive bits operations #380

Merged
merged 3 commits into from
Nov 6, 2024

Conversation

twiss
Copy link
Member

@twiss twiss commented Oct 25, 2024

Fixes #370.

This PR reverts #275, and addresses #274 in an alternative way, namely by explicitly returning an empty ArrayBuffer for PBKDF2 when length=0 (as RFC 8018 does not allow dkLen=0).

Additionally, explicitly return an ArrayBuffer in all cases (the algorithm registrations already stated this, but the operations did not).


Preview | Diff

…erations if length is zero (#275)"

This reverts commit 6438d87.
RFC 8018 does not allow passing dkLen=0. Therefore, we explicitly
return an empty ArrayBuffer in that case.
The algorithm registrations state that they return `ArrayBuffer`s,
but the operations did not.
Copy link
Collaborator

@davidben davidben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Collaborator

@Frosne Frosne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@javifernandez
Copy link
Collaborator

@nmahendru it´d be great if you could review this PR, to get also support from WebKit.
Thanks.

Copy link
Collaborator

@nmahendru nmahendru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
cc: @annevk

@twiss twiss merged commit d4ffcad into main Nov 6, 2024
2 checks passed
@twiss twiss deleted the hkdf-pbkdf2-allow-0-length branch November 6, 2024 11:32
@javifernandez javifernandez mentioned this pull request Nov 7, 2024
8 tasks
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Nov 7, 2024
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
javifernandez added a commit to javifernandez/web-platform-tests that referenced this pull request Nov 8, 2024
The PR#380 [1] changed the PBKDF2 deriveBits operation to allow
zero length and introduced an additional step to return an empty
string in that case. It also reversted the PR#275 [2] so that
HKDF also handles the zero length in the same way.

This PR updates the tests cases affecting this 2 algorithms on
the cases where zero was passed in the length parameter.

[1] w3c/webcrypto#380
[2] w3c/webcrypto#275
javifernandez added a commit to javifernandez/web-platform-tests that referenced this pull request Nov 8, 2024
The PR#380 [1] changed the PBKDF2 deriveBits operation to allow
zero length and introduced an additional step to return an empty
string in that case. It also reversted the PR#275 [2] so that
HKDF also handles the zero length in the same way.

This PR updates the tests cases affecting this 2 algorithms on
the cases where zero was passed in the length parameter.

[1] w3c/webcrypto#380
[2] w3c/webcrypto#275
javifernandez added a commit to javifernandez/web-platform-tests that referenced this pull request Nov 8, 2024
The PR#380 [1] changed the PBKDF2 deriveBits operation to allow
zero length and introduced an additional step to return an empty
string in that case. It also reversted the PR#275 [2] so that
HKDF also handles the zero length in the same way.

This PR updates the tests cases affecting this 2 algorithms on
the cases where zero was passed in the length parameter.

[1] w3c/webcrypto#380
[2] w3c/webcrypto#275
github-actions bot added a commit that referenced this pull request Nov 8, 2024
SHA: d4ffcad
Reason: push, by twiss

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Interop issue with HKDF deriveBits operation when length is zero
5 participants