Skip to content

feat(hkdf): add hkdfExtract and hkdfExpand (RFC 5869)#1064

Merged
boorad merged 3 commits into
mainfrom
feat/hkdf-extract-expand
Jul 8, 2026
Merged

feat(hkdf): add hkdfExtract and hkdfExpand (RFC 5869)#1064
boorad merged 3 commits into
mainfrom
feat/hkdf-extract-expand

Conversation

@boorad

@boorad boorad commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Exposes the two stages of HKDF (RFC 5869) independently, so protocols that run Extract and Expand at different points (TLS 1.3, Noise, Signal, MLS) can use them directly instead of only the combined hkdf/hkdfSync. Both sync and async (callback) forms are provided, mirroring the existing hkdf/hkdfSync convention.

These are RNQC extensions — Node.js does not expose split HKDF.

Changes

  • New API:
    • hkdfExtractSync(digest, ikm, salt?) — RFC 5869 §2.2 Extract; returns the PRK (HashLen bytes). salt defaults to HashLen zero bytes when omitted.
    • hkdfExpandSync(digest, prk, info, keylen) — RFC 5869 §2.3 Expand.
    • hkdfExtract(digest, ikm, salt, callback) / hkdfExpand(digest, prk, info, keylen, callback) — async siblings (mirror hkdf).
  • Native: thread an HkdfMode union ('full' | 'extract' | 'expand') through the Nitro spec → C++, mapping to OpenSSL EVP_KDF_HKDF_MODE_*. The C++ switch throws on an unknown mode.
  • Validation: Expand rejects prk shorter than HashLen (§2.3) and keylen > 255 * HashLen.
  • Docs (api/hkdf.mdx) and coverage tables updated.

Testing

example/src/tests/hkdf/hkdf_tests.ts:

  • All 7 RFC 5869 vectors validated for Extract (against published PRK), Expand, and Extract→Expand recomposition — sync and async.
  • Omitted-salt-defaults-to-zeros, keylen ceiling, and PRK-too-short guard cases.

Validated in the example app (iOS/Android).

Closes #1060

boorad added 3 commits July 7, 2026 20:13
…ment)

react-native-quick-base64 3.0.0+ is a pure C++ TurboModule that only
registers under the New Architecture. As a required dependency of
react-native-quick-crypto, it crashes the app on launch when the
consuming app runs on the Old Architecture. Document the cause and the
fixes (enable New Arch + clean rebuild, or pin quick-base64 2.2.2).

Closes #1052
Expose the HKDF Extract and Expand steps independently for protocols that
run them at different stages (TLS 1.3, Noise, Signal, MLS). The native
HKDF path gains a `mode` param mapping to OpenSSL's
EVP_KDF_HKDF_MODE_{EXTRACT_ONLY,EXPAND_ONLY,EXTRACT_AND_EXPAND}; existing
full-HKDF callers pass 'full'.

- hkdfExtract(digest, ikm[, salt]) -> PRK (HashLen bytes)
- hkdfExpand(digest, prk, info, keylen) -> OKM
- Tests: RFC 5869 A.1-A.7 PRK/OKM vectors, extract->expand recompose,
  default-salt, keylen ceiling
- Docs: api/hkdf.mdx + both coverage tables (not-in-node / RNQC extension)
Review follow-ups on the RFC 5869 Extract/Expand split (#1060):

- Add callback-based hkdfExtract/hkdfExpand mirroring hkdf; move the
  synchronous forms to hkdfExtractSync/hkdfExpandSync.
- Replace the stringly-typed native mode param with an HkdfMode union
  ('full' | 'extract' | 'expand'); native switch throws on unknown mode.
- Reject PRK shorter than HashLen in Expand (RFC 5869 §2.3).
- Docs + coverage updated; add async and PRK-guard tests.
@boorad boorad self-assigned this Jul 8, 2026
@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

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 Jul 8, 2026 5:36pm

Request Review

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

🤖 End-to-End Test Results - Android

Status: ✅ Passed
Platform: Android
Run: 28962483947

📸 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.

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

🤖 End-to-End Test Results - iOS

Status: ✅ Passed
Platform: iOS
Run: 28962483916

📸 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 merged commit a596975 into main Jul 8, 2026
10 checks passed
@boorad boorad deleted the feat/hkdf-extract-expand branch July 8, 2026 18:08
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.

✨ Support HKDF-Expand (RFC 5869) without HKDF-Extract

1 participant