feat(hkdf): add hkdfExtract and hkdfExpand (RFC 5869)#1064
Merged
Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
🤖 End-to-End Test Results - AndroidStatus: ✅ Passed 📸 Final Test ScreenshotScreenshot automatically captured from End-to-End tests and will expire in 30 days This comment is automatically updated on each test run. |
Contributor
🤖 End-to-End Test Results - iOSStatus: ✅ Passed 📸 Final Test ScreenshotScreenshot automatically captured from End-to-End tests and will expire in 30 days This comment is automatically updated on each test run. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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 existinghkdf/hkdfSyncconvention.These are RNQC extensions — Node.js does not expose split HKDF.
Changes
hkdfExtractSync(digest, ikm, salt?)— RFC 5869 §2.2 Extract; returns the PRK (HashLenbytes).saltdefaults toHashLenzero 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 (mirrorhkdf).HkdfModeunion ('full' | 'extract' | 'expand') through the Nitro spec → C++, mapping to OpenSSLEVP_KDF_HKDF_MODE_*. The C++switchthrows on an unknown mode.prkshorter thanHashLen(§2.3) andkeylen > 255 * HashLen.api/hkdf.mdx) and coverage tables updated.Testing
example/src/tests/hkdf/hkdf_tests.ts:keylenceiling, and PRK-too-short guard cases.Validated in the example app (iOS/Android).
Closes #1060