Skip to content

crypto: simplify hash, MAC, and signature options - #67565

Open
panva wants to merge 5 commits into
nodejs:mainfrom
panva:crypto-settable-params
Open

panva wants to merge 5 commits into
nodejs:mainfrom
panva:crypto-settable-params

Conversation

@panva

@panva panva commented Nov 17, 2026

Copy link
Copy Markdown
Member

Use OpenSSL's settable parameter descriptors to select the supported types for digest and MAC options exposed by Node.js. Digests that accept customization as an octet string now receive the original bytes, including embedded NULs.

Share hash initialization and sign/verify setup, and check RSA implicit rejection support without setting the parameter.

Clarify which options apply in the crypto and Web Crypto docs.

Resolve the exposed digest options against provider descriptors and
construct UTF-8 or octet strings according to their advertised types.
Keep binary values intact for octet strings and reject NUL bytes for
UTF-8 strings.

Share hash initialization and one-shot input/output handling while
retaining the plain digest fast paths and XOF length checks. Probe RSA
implicit rejection without changing its context.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
Build exposed MAC parameters from one option table and their advertised
types. Keep binary octet values and terminated UTF-8 strings.

Share sign/verify initialization and replace padding and salt length
presence flags with optional values. Pass context parameters during
initialization and retain backend-specific handling.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
Cover binary and empty digest customization, incompatible parameter
types, and MAC descriptor selection with a shared test provider.
Check UTF-8 termination for byte inputs.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
@panva
panva requested review from anonrig and jasnell November 17, 2026 23:30
@panva panva added the commit-queue-rebase PRs the Commit Queue should land as multiple self-contained commits. label Nov 17, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto
  • @nodejs/gyp
  • @nodejs/security-wg

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Nov 17, 2026
Use the same error as createHash() when outputLength differs from a
fixed-size digest's length. Preserve acceptance of the exact length.

Assisted-by: Codex
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Document which digest and MAC options apply and how output lengths
work. Clarify signature contexts and distinguish required parameters
from optional defaults in Web Crypto.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
@panva
panva force-pushed the crypto-settable-params branch from 342c5fe to b61e0b5 Compare November 17, 2026 23:45
@codecov

codecov Bot commented Nov 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.66667% with 39 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.70%. Comparing base (3ea9547) to head (b61e0b5).

Files with missing lines Patch % Lines
src/crypto/crypto_util.cc 70.58% 8 Missing and 7 partials ⚠️
src/crypto/crypto_mac.cc 86.30% 2 Missing and 8 partials ⚠️
src/crypto/crypto_hash.cc 89.33% 4 Missing and 4 partials ⚠️
src/crypto/crypto_util.h 55.55% 3 Missing and 1 partial ⚠️
src/crypto/crypto_cipher.cc 0.00% 0 Missing and 1 partial ⚠️
src/crypto/crypto_sig.cc 91.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67565      +/-   ##
==========================================
- Coverage   90.71%   90.70%   -0.01%     
==========================================
  Files         801      801              
  Lines      280705   280650      -55     
  Branches    54168    54152      -16     
==========================================
- Hits       254640   254573      -67     
- Misses      16247    16253       +6     
- Partials     9818     9824       +6     
Files with missing lines Coverage Δ
lib/internal/crypto/hash.js 99.74% <100.00%> (+0.24%) ⬆️
src/crypto/crypto_hash.h 20.00% <ø> (ø)
src/crypto/crypto_sig.h 50.00% <ø> (-13.64%) ⬇️
src/crypto/crypto_cipher.cc 79.40% <0.00%> (ø)
src/crypto/crypto_sig.cc 68.93% <91.66%> (-0.44%) ⬇️
src/crypto/crypto_util.h 68.24% <55.55%> (-0.30%) ⬇️
src/crypto/crypto_hash.cc 81.46% <89.33%> (+0.38%) ⬆️
src/crypto/crypto_mac.cc 79.27% <86.30%> (-0.63%) ⬇️
src/crypto/crypto_util.cc 57.60% <70.58%> (+0.32%) ⬆️

... and 24 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit-queue-rebase PRs the Commit Queue should land as multiple self-contained commits. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants