feat: PQC PKCS#8 seed validation for ML-DSA and ML-KEM#1017
Merged
Conversation
Reject ML-DSA / ML-KEM PKCS#8 imports that contain only the expanded private key (seedless), and validate exported PKCS#8 length against 22 + seed_size to catch the toCryptoKey-on-seedless-KeyObject edge case. Also configures OpenSSL providers to prefer seed-only PKCS#8 output for ML-DSA / ML-KEM (seed-only,priv-only), mirroring Node's src/crypto/crypto_util.cc. Without this, OpenSSL defaults to seed-priv, which silently produces a longer encoding and breaks cross-implementation interop.
- Export PQC_SEEDLESS_PKCS8_LENGTHS and consume it from tests instead of redeclaring the table in the test file. - Replace startsWith fallback with explicit PQC_FAMILY lookup so the import-rejection error message can't mislabel an unknown algorithm whose seedless length happens to collide. - Move configurePqcOutputFormats() call into HybridKeyObjectHandle ctor (still guarded by std::call_once) so providers are configured on first handle construction rather than per-export. - Add ML-DSA-65 PKCS#8 round-trip + sign/verify test mirroring the existing ML-KEM-768 round-trip. - Replace absolute-path comment with repo-relative reference.
|
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
Closes #997.
Aligns ML-DSA / ML-KEM PKCS#8 import and export with Node's WebCrypto:
NotSupportedError— identified by exact byte length (matches Node'slib/internal/crypto/ml_dsa.jsandml_kem.js).seed-only,priv-onlyPKCS#8 output (mirrorsnode/src/crypto/crypto_util.cc) so RNQC emits the compact 54-byte (ML-DSA) / 86-byte (ML-KEM) encoding by default. Adds a defensive length check that throwsOperationErrorif a seedlessKeyObjectwas wrapped viatoCryptoKeyand slipped past the import guard.Changes
packages/react-native-quick-crypto/src/subtle.tsPQC_SEEDLESS_PKCS8_LENGTHSand addPQC_FAMILYlookup; reject seedless PKCS#8 imports with the same error message Node emits.exportKeyPkcs8.packages/react-native-quick-crypto/cpp/keys/HybridKeyObjectHandle.{cpp,hpp}ml-{kem,dsa}.output_formatstoseed-only,priv-onlyonce, on firstHybridKeyObjectHandleconstruction, viastd::call_once. Gated to OpenSSL ≥ 3.6 (OSSL_PROVIDER_add_conf_parameter).example/src/tests/subtle/import_export.tsTest plan
subtle: ML-DSA-{44,65,87} pkcs8 import rejects seedless key—NotSupportedErrorthrown with Node-matching messagesubtle: ML-KEM-{512,768,1024} pkcs8 import rejects seedless key—NotSupportedErrorthrownsubtle: ML-DSA-{44,65,87} pkcs8 export produces 54-byte seed-only encodingsubtle: ML-KEM-{512,768,1024} pkcs8 export produces 86-byte seed-only encodingsubtle: ML-DSA-65 pkcs8 round-trip + sign/verifysubtle: ML-KEM-768 pkcs8 round-trip + decapsulate