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

PBKDF2 & HKDF derive bits should throw OperationError when length is zero #275

Merged
merged 1 commit into from
Sep 2, 2021

Conversation

littledivy
Copy link
Contributor

Closes #274

@twiss twiss merged commit 6438d87 into w3c:main Sep 2, 2021
github-actions bot added a commit that referenced this pull request Sep 2, 2021
… if length is zero (#275)

SHA: 6438d87
Reason: push, by @twiss

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@twiss
Copy link
Member

twiss commented Sep 2, 2021

@littledivy Thanks for the PR!

javifernandez added a commit to javifernandez/WebKit that referenced this pull request Jul 10, 2024
https://bugs.webkit.org/show_bug.cgi?id=276394

Reviewed by NOBODY (OOPS!).

The PR#345 [1] to the WebCryptoAPI spec defines now the 'length'
parameter as optional, defaulting to 'null'. This change tries to
solve a long-standing interoperability issue in the deriveBits
operation.

This patch implements the required changes in the IDL so that the
'length' parameter is declared as optional, with 'null' as default
value when omitted. The affected algorithms (ECDH, HKDF, PBKDF2
and X25519) are adapted to the parameter's new type.

The PR#43400 [2] defined tests for the new behavior of the afected
algorithms, which Chrome passes except for the case of HKDF with
length=0 (see the PR#275 [3] for details)

[1] w3c/webcrypto#345
[2] web-platform-tests/wpt#43400
[3] w3c/webcrypto#275

* LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/derived_bits_length.https.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/derived_bits_length.https.any.worker-expected.txt:
* Source/WebCore/crypto/CryptoAlgorithm.cpp:
(WebCore::CryptoAlgorithm::deriveBits):
* Source/WebCore/crypto/CryptoAlgorithm.h:
* Source/WebCore/crypto/SubtleCrypto.cpp:
(WebCore::SubtleCrypto::deriveKey):
(WebCore::SubtleCrypto::deriveBits):
* Source/WebCore/crypto/SubtleCrypto.h:
* Source/WebCore/crypto/SubtleCrypto.idl:
* Source/WebCore/crypto/algorithms/CryptoAlgorithmECDH.cpp:
(WebCore::CryptoAlgorithmECDH::deriveBits):
* Source/WebCore/crypto/algorithms/CryptoAlgorithmECDH.h:
* Source/WebCore/crypto/algorithms/CryptoAlgorithmHKDF.cpp:
(WebCore::CryptoAlgorithmHKDF::deriveBits):
* Source/WebCore/crypto/algorithms/CryptoAlgorithmHKDF.h:
* Source/WebCore/crypto/algorithms/CryptoAlgorithmPBKDF2.cpp:
(WebCore::CryptoAlgorithmPBKDF2::deriveBits):
* Source/WebCore/crypto/algorithms/CryptoAlgorithmPBKDF2.h:
* Source/WebCore/crypto/algorithms/CryptoAlgorithmX25519.cpp:
(WebCore::CryptoAlgorithmX25519::deriveBits):
* Source/WebCore/crypto/algorithms/CryptoAlgorithmX25519.h:
twiss added a commit that referenced this pull request Oct 25, 2024
…erations if length is zero (#275)"

This reverts commit 6438d87.
twiss added a commit that referenced this pull request Nov 6, 2024
* Revert "Throw an OperationError in the PBKDF2 and HKDF derive bits operations if length is zero (#275)"

This reverts commit 6438d87.

* Properly handle length=0 in the PBKDF2 derive bits operation

RFC 8018 does not allow passing dkLen=0. Therefore, we explicitly
return an empty ArrayBuffer in that case.

* Explicitly return `ArrayBuffer`s in HKDF and PBKDF2

The algorithm registrations state that they return `ArrayBuffer`s,
but the operations did not.
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
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.

PBKDF2 derive bits should throw OperationError when length is zero
2 participants