Add DH AlgorithmParameters, AlgorithmParameterGenerator, KeyFactory, and related fixes#161
Merged
rlm2002 merged 8 commits intowolfSSL:masterfrom Oct 20, 2025
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive DH (Diffie-Hellman) support to wolfJCE by implementing AlgorithmParameters, AlgorithmParameterGenerator, and KeyFactory, along with fixing KeyAgreement implementation issues to match SunJCE behavior.
Key changes:
- Implemented DH AlgorithmParameters for encoding/decoding DH parameters using ASN.1
- Added DH AlgorithmParameterGenerator supporting both FFDHE standard groups and dynamic parameter generation
- Created DH KeyFactory with support for key conversion between various KeySpec formats
- Fixed KeyAgreement secret key generation and DH padding behavior to match SunJCE post-Java 8
Reviewed Changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| WolfCryptProvider.java | Registered new DH services (AlgorithmParameters, AlgorithmParameterGenerator, KeyFactory) |
| Dh.java | Added native methods and constants for FFDHE groups, parameter generation, and key operations |
| WolfCryptKeyPairGenerator.java | Added default FFDHE parameter initialization and FFDHE key size support for DH |
| WolfCryptKeyAgreement.java | Fixed DH padding and secret key generation to match SunJCE behavior |
| WolfCryptDhParameters.java | New class implementing DH AlgorithmParameters with ASN.1 encoding/decoding |
| WolfCryptDhParameterGenerator.java | New class for generating DH parameters using FFDHE groups or dynamic generation |
| WolfCryptDHKeyFactory.java | New class for DH key conversion between KeySpec formats |
| WolfCryptDHPublicKey.java | New class implementing DHPublicKey with X.509 encoding |
| WolfCryptDHPrivateKey.java | New class implementing DHPrivateKey with PKCS#8 encoding |
| WolfCryptASN1Util.java | New utility class for ASN.1/DER encoding operations |
| jni_dh.c | Added JNI implementations for new DH operations |
| jni_aesgcm.c | Fixed constant name from WC_AES_BLOCK_SIZE to AES_BLOCK_SIZE |
| jni_aesccm.c | Fixed constant name from WC_AES_BLOCK_SIZE to AES_BLOCK_SIZE |
| Test files | Added comprehensive test coverage for new DH functionality |
| Documentation | Updated README_JCE.md and CLAUDE.md with new features and guidelines |
Comments suppressed due to low confidence (1)
jni/jni_dh.c:1
- The changes to jni_aesgcm.c and jni_aesccm.c replace
WC_AES_BLOCK_SIZEwithAES_BLOCK_SIZE. Verify thatAES_BLOCK_SIZEis defined in the wolfSSL version being used, asWC_AES_BLOCK_SIZEis the standard wolfSSL constant name. IfAES_BLOCK_SIZEis not available in older wolfSSL versions, this could cause compilation failures.
/* jni_dh.c
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
4b288b9 to
4de44cf
Compare
…eGenerateSecret()
4de44cf to
5ee60dc
Compare
rlm2002
approved these changes
Oct 20, 2025
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 DH AlgorithmParameters, AlgorithmParameterGenerator, and KeyFactory implementations as well as fixes some KeyAgreement implementation issues to match SunJCE behavior.
New DH Components
WolfCryptDhParameters- Encode/decode DH parameters using ASN.1WolfCryptDhParameterGenerator- Generate DH domain parameters (p, g)WolfCryptDHKeyFactory- Convert between DH key specs (DHPublicKeySpec, DHPrivateKeySpec, X509EncodedKeySpec, PKCS8EncodedKeySpec)WolfCryptDHPublicKeyandWolfCryptDHPrivateKeyJNI Layer
jni_dh.cKeyAgreement Fixes
engineGenerateSecret(String)): Now returns SecretKeySpec instead of incorrectly casting DESKeySpec/DESedeKeySpec to SecretKey interface. Added proper AES key size handling (128/192/256-bit).engineGenerateSecret(byte[], int)): Pad DH shared secrets to prime length with leading zeros per JDK-7146728, matching SunJCE post-Java 8 behavior and RFC 2631 (2.1.2).Test Coverage
Other Changes