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

fix(crypto): improve handling of length option #5505

Merged
merged 3 commits into from
Jul 26, 2024
Merged

Conversation

iuioiua
Copy link
Contributor

@iuioiua iuioiua commented Jul 23, 2024

Closes #1429

@iuioiua iuioiua requested a review from kt3k as a code owner July 23, 2024 01:51
@iuioiua iuioiua enabled auto-merge (squash) July 23, 2024 01:51
Copy link

codecov bot commented Jul 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.48%. Comparing base (42693da) to head (6ee03a3).
Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5505      +/-   ##
==========================================
- Coverage   96.51%   96.48%   -0.03%     
==========================================
  Files         465      465              
  Lines       37714    37770      +56     
  Branches     5576     5580       +4     
==========================================
+ Hits        36400    36443      +43     
- Misses       1272     1285      +13     
  Partials       42       42              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@iuioiua
Copy link
Contributor Author

iuioiua commented Jul 25, 2024

PTAL, @kt3k

@iuioiua iuioiua requested a review from littledivy July 25, 2024 05:49
@@ -33,7 +36,7 @@
* - `BLAKE2B-256`
* - `BLAKE2B-384`
* - `BLAKE2S`
* - `BLAKE3`
* - `BLAKE3` (length-adjustable)
Copy link
Member

@kt3k kt3k Jul 25, 2024

Choose a reason for hiding this comment

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

What's the difference of (length-adjustable) and (length-extendable)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"length-extendable" refers to a specific vulnerability in some hash functions, while "length-adjustable" is not a standard term in cryptography but could refer to the general capability of hash functions to process inputs of different lengths.

-- ChatGPT

crypto/crypto.ts Outdated
@@ -215,6 +218,11 @@ const stdCrypto: StdCrypto = ((x) => x)({
// and the data is a single buffer,
isBufferSource(data)
) {
if (length !== undefined) {
throw new TypeError(
Copy link
Member

Choose a reason for hiding this comment

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

The native crypto.subtle.digest seems ignoring length for the case where length is irrelevant. Throwing here feels inconsistent with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I've reverted and instead added a note saying that length will be ignored in some cases.

@iuioiua iuioiua requested a review from kt3k July 26, 2024 02:22
Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

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

LGTM

@iuioiua iuioiua merged commit f7561ca into main Jul 26, 2024
16 checks passed
@iuioiua iuioiua deleted the crypto-length-adjustable branch July 26, 2024 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docs: document about which algorithms support length option for stdCrypto.digest
3 participants