Skip to content

feat: implement ML-KEM encapsulate/decapsulate#941

Merged
boorad merged 2 commits intomainfrom
feat/ml-kem-encapsulate-decapsulate
Feb 17, 2026
Merged

feat: implement ML-KEM encapsulate/decapsulate#941
boorad merged 2 commits intomainfrom
feat/ml-kem-encapsulate-decapsulate

Conversation

@boorad
Copy link
Collaborator

@boorad boorad commented Feb 17, 2026

Summary

Adds full ML-KEM (Module-Lattice Key Encapsulation Mechanism) support — a post-quantum cryptographic primitive for key encapsulation. Supports all three FIPS 203 parameter sets: ML-KEM-512, ML-KEM-768, and ML-KEM-1024.

Changes

API Surface

  • WebCrypto: subtle.encapsulateBits(), subtle.encapsulateKey(), subtle.decapsulateBits(), subtle.decapsulateKey()
  • Top-level: crypto.encapsulate(), crypto.decapsulate()
  • Key management: subtle.generateKey(), subtle.importKey(), subtle.exportKey() for ML-KEM key pairs (spki/pkcs8)

Implementation

  • C++ native HybridMlKemKeyPair using OpenSSL 3.5+ EVP encapsulation/decapsulation APIs
  • TypeScript MlKem class with Nitro Module bindings
  • Fallback key type detection in getAsymmetricKeyType() using EVP_PKEY_get0_type_name() for provider-only key types
  • RAII EVP_PKEY_ptr (unique_ptr with custom deleter) in both ML-KEM and ML-DSA classes

Tests

  • All 3 variants: encapsulateBits/decapsulateBits roundtrips, encapsulateKey/decapsulateKey with AES-GCM, import-then-encapsulate roundtrips, top-level API, keygen, import/export, error cases

Code Quality

  • Shared ML-KEM test constants extracted to mlkem_constants.ts
  • Removed redundant ML-DSA string checks in key type fallback
  • Simplified double buffer conversion in decapsulate()

Testing

Tests run in the React Native example app. Test suite: subtle.encapsulate/decapsulate.

Closes #934
Closes #937

Add ML-KEM-512/768/1024 support with key generation, encapsulation, and
decapsulation via both Node.js-style and WebCrypto APIs.

New APIs:
- crypto.encapsulate() / crypto.decapsulate()
- subtle.encapsulateBits() / subtle.decapsulateBits()
- subtle.encapsulateKey() / subtle.decapsulateKey()
- subtle.generateKey() for ML-KEM variants
- subtle.importKey() / subtle.exportKey() (spki, pkcs8)

Implementation:
- Nitro HybridMlKemKeyPair module with OpenSSL 3.5+ EVP KEM APIs
- C++ encapsulate/decapsulate using EVP_PKEY_encapsulate/decapsulate
- Packed ArrayBuffer format for bridge efficiency
- String-based EVP_PKEY type detection fallback for provider-only keys

Also adds 'Both' platform option to feature request issue template and
documents metro log location in CLAUDE.md.
…issues

- Replace raw EVP_PKEY* with unique_ptr<EVP_PKEY> RAII wrapper in both
  HybridMlKemKeyPair and HybridMlDsaKeyPair, matching existing pattern
  from HybridDsaKeyPair/HybridDhKeyPair
- Remove redundant ML-DSA string checks in getAsymmetricKeyType()
  fallback (already handled by EVP_PKEY_ML_DSA_* switch cases)
- Simplify double buffer conversion in mlkem.ts decapsulate()
- Extract shared ML-KEM test constants into mlkem_constants.ts
@boorad boorad self-assigned this Feb 17, 2026
@github-actions
Copy link
Contributor

🤖 End-to-End Test Results - Android

Status: ✅ Passed
Platform: Android
Run: 22082019083

📸 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
Copy link
Contributor

🤖 End-to-End Test Results - iOS

Status: ✅ Passed
Platform: iOS
Run: 22082019089

📸 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 e040d63 into main Feb 17, 2026
7 checks passed
@boorad boorad deleted the feat/ml-kem-encapsulate-decapsulate branch February 17, 2026 01:00
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.

✨ add ML-KEM implementations ✨ add Encapsulate and Decapsulate functionality

1 participant