JNI/JCE: add ML-KEM (FIPS 203) support to wolfCrypt JNI and wolfJCE#232
Open
cconlon wants to merge 1 commit into
Open
JNI/JCE: add ML-KEM (FIPS 203) support to wolfCrypt JNI and wolfJCE#232cconlon wants to merge 1 commit into
cconlon wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds ML-KEM (FIPS 203) support across the wolfCrypt JNI layer and the wolfJCE provider, including key generation, key encoding (RFC 9935 SPKI/PKCS#8), and JDK 21+ javax.crypto.KEM integration, plus tests and build wiring.
Changes:
- Introduces a new
com.wolfssl.wolfcrypt.MlKemJNI wrapper and nativejni_mlkem.cbindings for keygen/encap/decap/import/export/size queries. - Adds wolfJCE ML-KEM provider services:
KeyPairGenerator,KeyFactory, ML-KEM public/private key classes, RFC 9935 encoding utilities, and optional JDK 21+KEMSPI registration. - Adds ML-KEM unit tests (including interop with SunJCE) and updates build scripts/docs/project files to include ML-KEM.
Reviewed changes
Copilot reviewed 28 out of 29 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| src/test/java/com/wolfssl/wolfcrypt/test/WolfCryptTestSuite.java | Adds ML-KEM tests to the wolfCrypt JNI test suite. |
| src/test/java/com/wolfssl/provider/jce/test/WolfJCETestSuite.java | Adds ML-KEM JCE tests to the provider test suite. |
| src/test/java/com/wolfssl/provider/jce/test/WolfCryptMlKemKeyPairGeneratorTest.java | Verifies ML-KEM KeyPairGenerator behavior and defaults. |
| src/test/java/com/wolfssl/provider/jce/test/WolfCryptMlKemKeyFactoryTest.java | Validates ML-KEM KeyFactory parsing/encoding (including PKCS#8 CHOICE forms). |
| src/test/java/com/wolfssl/provider/jce/test/WolfCryptMlKemKemTest.java | Tests JDK 21+ KEM SPI behavior and SunJCE interop via reflection for Java 8 compatibility. |
| src/main/java/com/wolfssl/wolfcrypt/MlKem.java | New JNI wrapper API for native ML-KEM operations. |
| src/main/java/com/wolfssl/provider/jce/WolfPQCJdkCompat.java | Adds ML-KEM name→level mapping helper for parameter specs. |
| src/main/java/com/wolfssl/provider/jce/WolfCryptProvider.java | Registers ML-KEM services (KeyPairGenerator/KeyFactory/KEM + OID aliases) with feature/JDK guards. |
| src/main/java/com/wolfssl/provider/jce/WolfCryptMlKemUtil.java | Implements RFC 9935 DER encode/decode helpers for ML-KEM SPKI/PKCS#8. |
| src/main/java/com/wolfssl/provider/jce/WolfCryptMlKemPublicKey.java | New ML-KEM PublicKey type backed by raw key bytes + SPKI encoding. |
| src/main/java/com/wolfssl/provider/jce/WolfCryptMlKemPrivateKey.java | New ML-KEM PrivateKey type supporting seed/expanded/both PKCS#8 CHOICE inputs. |
| src/main/java/com/wolfssl/provider/jce/WolfCryptMlKemKeyFactory.java | New KeyFactorySpi implementation for ML-KEM (generic + per-level variants). |
| src/main/java/com/wolfssl/provider/jce/WolfCryptMlKemKem.java | New JDK 21+ KEMSpi implementation for ML-KEM encapsulation/decapsulation. |
| src/main/java/com/wolfssl/provider/jce/WolfCryptKeyPairGenerator.java | Extends KeyPairGenerator support to ML-KEM (levels, defaults, seed retention). |
| src/main/java/com/wolfssl/provider/jce/WolfCryptASN1Util.java | Adds ASN.1 context-specific primitive tag constant used by ML-KEM PKCS#8 seed form. |
| scripts/infer.sh | Adds ML-KEM sources to Infer’s javac invocation. |
| README.md | Documents native build requirement for ML-KEM and JDK 21+ KEM note. |
| README_JCE.md | Documents ML-KEM services, parameter selection, encoding property, and OIDs. |
| pom.xml | Adds a JDK<21 profile to exclude KEM SPI compilation. |
| makefile.macosx | Adds jni_mlkem.o to macOS JNI build. |
| makefile.linux | Adds jni_mlkem.o to Linux JNI build. |
| jni/jni_mlkem.c | Implements native JNI bindings to wolfSSL wc_MlKemKey_* APIs. |
| jni/include/com_wolfssl_wolfcrypt_MlKem.h | Adds generated JNI header for MlKem. |
| IDE/WIN/wolfcryptjni.vcxproj | Includes ML-KEM JNI sources/headers in the Windows project. |
| IDE/Android/app/src/main/cpp/CMakeLists.txt | Includes ML-KEM JNI source in Android build. |
| examples/provider/MlKemExample.sh | Adds a helper script to run the ML-KEM example. |
| examples/provider/MlKemExample.java | Adds a JDK 21+ ML-KEM KEM + encoding round-trip example. |
| build.xml | Adds JDK 21+ detection and excludes KEM SPI + example from Java 8 builds/javadoc. |
Files not reviewed (1)
- jni/include/com_wolfssl_wolfcrypt_MlKem.h: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
This PR adds ML-KEM (FIPS 203) for parameter sets ML-KEM-512/768/1024, at both the JNI and JCE layers, backed by native wolfSSL's
wc_MlKemKey_*API.JNI (
com.wolfssl.wolfcrypt)MlKemclass +jni/jni_mlkem.c: key generation (RNG and deterministic 64-byte seed), encapsulation (RNG and deterministicencapsulateWithRandom), decapsulation, raw key import/export, and size getters.JCE (
wolfJCE)KeyPairGenerator,KeyFactory, andKEM(KEMSpi, JDK 21+) services plusML-KEMpublic/private key classes, registered with family + per-level + OID aliases.SubjectPublicKeyInfoand PKCS#8PrivateKeyInfo(RFC 9935) encoding/decoding accepts all three PKCS#8 CHOICE forms (seed/expandedKey/both).expandedKeyby default, honors thejdk.mlkem.pkcs8.encodingproperty.Compatibility
KEMSPI is conditionally compiled (JDK 21+) and registered behind a runtime guard, so Java 8 builds load with the KEM service absent.Tests
Build
--enable-mlkem(definesWOLFSSL_HAVE_MLKEM).build.xml,pom.xml, Android/VS projects, andinfer.sh. IncludesMlKemExampleand README updates.