Repository navigation
fix(cryptography): derive HKDF from HMAC for an empty IKM - #11024
Closed
tylerc-consensys wants to merge 2 commits into
Closed
tylerc-consensys wants to merge 2 commits into
tylerc-consensys wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tylerc-consensys
marked this pull request as ready for review
October 23, 2026 02:10
tylerc-consensys
temporarily deployed
to
default-branch
October 23, 2026 02:10 — with
GitHub Actions
Inactive
tylerc-consensys
marked this pull request as draft
October 23, 2026 04:53
tylerc-consensys
marked this pull request as ready for review
October 23, 2026 09:15
tylerc-consensys
temporarily deployed
to
default-branch
October 23, 2026 09:15 — with
GitHub Actions
Inactive
Contributor
|
If this is fixed upstream, we can use react-native-quick-crypto with zero IKM. |
Comment on lines
+111
to
+112
| // Some WebCrypto implementations, such as react-native-quick-crypto, reject | ||
| // an empty HKDF key, so derive it from HMAC as RFC 5869 defines it. |
Member
There was a problem hiding this comment.
Since this seems like a bug in react-native-quick-crypto, where it doesn't conform to the spec and I have verified that our existing implementation works in both Node.js and the browser I think we should prefer upstreaming a fix. @matthiasgeihs has already opened a PR for this.
Contributor
There was a problem hiding this comment.
Related PR that bumps react-native-quick-crypto on mobile.
MetaMask/metamask-mobile#38279
Once that's in, we might be able to drop this one here.
Draft
8 of 10 tasks
ccharly
added a commit
to MetaMask/metamask-mobile
that referenced
this pull request
Nov 6, 2026
Extracts the real MPC money keyring from feat/money-mfa-mpc-account without the Money MFA UI or 2FA approval path: - `buildRealMpcMoneyKeyringBuilder`: DKLS23/CL24 via `@metamask/mpc-react-native`, dev MPC service endpoints, pinned MFA whitelist config, placeholder backup key. Registered in `getKeyringBuilders` under `MM_MONEY_MPC_REAL_KEYRING` (needs `MM_MONEY_MPC_KEYRING_ENABLED`). - `empty-ikm-hkdf-workaround`: lets `crypto.subtle` run the HKDF with an empty IKM that the Noise `Split` in `@metamask/mfa-wallet-network` needs and `react-native-quick-crypto` rejects. Temporary until MetaMask/core#11024 and MetaMask/mfa-wallet-sdk#68. - Developer-options section that creates the MPC money account via `MoneyAccountController.createMoneyAccount({ type: 'mpc' })` and signs and recovers a test message. - Adds `@metamask/mpc-react-native` and pins `uniffi-bindgen-react-native`; transpiles the ESM-only TSS packages in jest; maps `@metamask/eth-money-mpc-keyring/v2` types in tsconfig.
This branch was previously deployed
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.
Explanation
The bug
hkdfSha256/hkdfSha384/hkdfSha512import the IKM as a WebCrypto HKDF key. On React Native,react-native-quick-cryptorejects an empty HKDF key (HKDF derivation failed), even withunsafeInputKeyingMaterial: true. Browsers and Node accept it.When it happens
Any HKDF call with an empty IKM on React Native. The Noise
Splitstep always does this (the Noise spec definesSplitasHKDF(ck, zerolen)), so every Noise handshake in@metamask/mfa-wallet-networkfails on mobile. That blocks MPC key creation for the Money account (@metamask/eth-money-mpc-keyring+@metamask/mpc-react-native), which surfaces asCl24Error: Rust panic.The fix
When the IKM is empty, compute HKDF from WebCrypto HMAC using the Extract and Expand steps of RFC 5869 (an empty salt becomes
HashLenzero bytes). Non-empty IKM still uses WebCrypto HKDF. The output is the same as WebCrypto HKDF for the same inputs. No new dependencies.References
Splitpasses a chaining key that is zeroed while HKDF is running. This path reads it before it is zeroed, so keys would not match peers that read it after.Testing
crypto.hkdfSyncfor SHA-256/384/512, an empty salt, info, and multi-block lengths; the 255-block limit throws.Checklist