Skip to content

fix: route raw / raw-secret / raw-public per-algorithm in subtle#1023

Merged
boorad merged 2 commits into
mainfrom
fix/format-aliasing-1002
May 5, 2026
Merged

fix: route raw / raw-secret / raw-public per-algorithm in subtle#1023
boorad merged 2 commits into
mainfrom
fix/format-aliasing-1002

Conversation

@boorad
Copy link
Copy Markdown
Collaborator

@boorad boorad commented May 5, 2026

Summary

  • Stops unconditionally collapsing raw-secret/raw-public to raw in subtle.importKey/exportKey. Each algorithm now validates its own format per Node's aliasKeyFormat matrix (webcrypto.js:734-742).
  • Routes derived/encapsulated/decapsulated bits through raw-secret so AEADs (AES-OCB, ChaCha20-Poly1305) and KMAC keys produced from deriveKey / encapsulateKey / decapsulateKey are now valid downstream.
  • Replaces plain Error throws with spec-correct DOMException types (SyntaxError / NotSupportedError / DataError).

Format matrix (mirrors Node)

Algorithm raw raw-secret raw-public
AES-CTR/CBC/GCM/KW, HMAC
AES-OCB, KMAC128/256, ChaCha20-Poly1305
Argon2d/i/id
ECDSA, ECDH (public)
Ed25519, Ed448, X25519, X448 (public)
ML-DSA, ML-KEM (public)
RSA, HKDF, PBKDF2 aliased aliased aliased

Closes #1002.

Test plan

  • bun tsc --noEmit clean across both packages
  • New tests in example/src/tests/subtle/import_export.ts:
    • AES-OCB, ChaCha20-Poly1305, KMAC128/256, Argon2d/i/id reject plain raw
    • ML-DSA-44/65/87, ML-KEM-512/768/1024 reject plain raw for public-key import/export
    • AES-GCM accepts raw-secret round-trip
    • HMAC accepts raw-secret round-trip; rejects raw-public
    • Ed25519/Ed448/X25519/X448 accept raw-public round-trip (equivalent to raw)
    • ECDSA/ECDH accept raw-public round-trip (equivalent to raw)
  • Existing KMAC NIST sign/verify, AES-OCB and ChaCha20-Poly1305 import/export tests updated to use raw-secret
  • Existing PBKDF2 "Bad inputs" test still passes (extractable → usage → format ordering preserved)

boorad added 2 commits May 5, 2026 17:50
Stop unconditionally collapsing raw-secret/raw-public to raw. Each algorithm
now validates its own format per Node's matrix:

- AES-OCB and ChaCha20-Poly1305 require raw-secret (reject raw)
- KMAC128/KMAC256 require raw-secret
- Argon2d/i/id require raw-secret
- ML-DSA and ML-KEM require raw-public (reject raw)
- AES-CTR/CBC/GCM/KW + HMAC + HKDF + PBKDF2 + RSA + EC + Ed/X alias both forms
- exportKey enforces the same matrix (raw / raw-secret / raw-public)
- deriveKey, encapsulateKey, decapsulateKey now import derived/shared bits as
  raw-secret so AEAD/KMAC keys are valid downstream
- HMAC dispatcher no longer aliases format; hmacImportKey accepts 'raw'
  and 'raw-secret' directly and rejects 'raw-public' (matches Node mac.js)
- Split importGenericSecretKey into pbkdf2ImportKey + argon2ImportKey;
  PBKDF2 keeps Node's extractable -> usage -> format ordering, Argon2
  gates format first (matches Node webcrypto.js dispatcher)
- Replace plain Error throws with lazyDOMException (SyntaxError /
  NotSupportedError / DataError) per WebCrypto spec
- Add tests: HMAC raw-secret round-trip, HMAC raw-public reject,
  Ed25519/Ed448/X25519/X448 raw-public accept, ECDSA/ECDH raw-public
  accept

Also adds fix-plan tables to /review and a new /address-pr-feedback
command, mirroring the spicy/ea workflow.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
react-native-quick-crypto Ready Ready Preview, Comment May 5, 2026 10:10pm

Request Review

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

🤖 End-to-End Test Results - iOS

Status: ✅ Passed
Platform: iOS
Run: 25405088942

📸 Final Test Screenshot

Maestro Test Results - ios

Screenshot automatically captured from End-to-End tests and will expire in 30 days


This comment is automatically updated on each test run.

@boorad boorad self-assigned this May 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

🤖 End-to-End Test Results - Android

Status: ✅ Passed
Platform: Android
Run: 25405088953

📸 Final Test Screenshot

Maestro Test Results - android

Screenshot automatically captured from End-to-End tests and will expire in 30 days


This comment is automatically updated on each test run.

@boorad boorad merged commit d2c46b1 into main May 5, 2026
9 checks passed
@boorad boorad deleted the fix/format-aliasing-1002 branch May 5, 2026 23:23
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.

subtle: format aliasing — distinguish raw / raw-secret / raw-public per algorithm

1 participant