wolfCrypt JNI/JCE hardening fixes - #264
Open
cconlon wants to merge 10 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Hardening-focused changes across the wolfCrypt JNI layer and the wolfJCE provider to enforce strict parameter validation, improve secret handling (zeroization), and align AEAD failure behavior with JCE expectations.
Changes:
- Added native input validation for cipher key/IV/nonce lengths (ChaCha, AES variants, 3DES) to prevent out-of-bounds reads in underlying wolfCrypt calls.
- Added/expanded zeroization of sensitive key material and buffers in both Java (HMAC re-key) and JNI (ChaCha key, ML-DSA seed/private inputs, RSA decrypt output buffer).
- Enforced a minimum DH prime size (Dh.DH_MIN_SIZE) on DH KeyFactory/key import paths and added regression tests; mapped AES-CCM auth failures to AEADBadTagException and added coverage.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/test/java/com/wolfssl/wolfcrypt/test/Des3Test.java | Adds negative/positive coverage for 3DES setKey key/IV length enforcement. |
| src/test/java/com/wolfssl/wolfcrypt/test/ChachaTest.java | Adds tests asserting ChaCha nonce (IV) must be exactly 12 bytes. |
| src/test/java/com/wolfssl/wolfcrypt/test/AesTest.java | Adds tests asserting non-null AES IV must be exactly one block. |
| src/test/java/com/wolfssl/wolfcrypt/test/AesOfbTest.java | Adds IV length validation tests for AES-OFB key setup. |
| src/test/java/com/wolfssl/wolfcrypt/test/AesCtrTest.java | Adds IV length validation tests for AES-CTR key setup. |
| src/test/java/com/wolfssl/provider/jce/test/WolfCryptDHKeyFactoryTest.java | Adds regression test ensuring weak DH primes are rejected across import/translate paths. |
| src/test/java/com/wolfssl/provider/jce/test/WolfCryptCipherTest.java | Adds regression test expecting AEADBadTagException on AES-CCM tag mismatch. |
| src/main/java/com/wolfssl/wolfcrypt/Hmac.java | Zeroizes the previous saved HMAC key on re-key before overwriting. |
| src/main/java/com/wolfssl/provider/jce/WolfCryptDHPublicKey.java | Rejects DH primes below Dh.DH_MIN_SIZE during X.509 parse. |
| src/main/java/com/wolfssl/provider/jce/WolfCryptDHPrivateKey.java | Rejects DH primes below Dh.DH_MIN_SIZE during PKCS#8 parse. |
| src/main/java/com/wolfssl/provider/jce/WolfCryptDHKeyFactory.java | Enforces minimum DH prime size for DHPrivateKeySpec/DHPublicKeySpec generation. |
| src/main/java/com/wolfssl/provider/jce/WolfCryptCipher.java | Converts wolfCrypt AES-CCM auth failures into AEADBadTagException (mirrors GCM path). |
| jni/jni_rsa.c | Zeroizes full RSA private-decrypt output allocation size (not just plaintext length) before free. |
| jni/jni_mldsa.c | Zeroizes native copies of ML-DSA seed/private inputs when JNI returns a copy buffer. |
| jni/jni_des3.c | Validates 3DES key size and (optional) IV size before calling wc_Des3_SetKey. |
| jni/jni_chacha.c | Validates ChaCha IV length and zeroizes JNI key copy prior to releasing it. |
| jni/jni_aesofb.c | Validates AES-OFB IV length before calling wc_AesSetKey. |
| jni/jni_aesctr.c | Validates AES-CTR IV length before calling wc_AesSetKey. |
| jni/jni_aes.c | Validates AES (CBC/other) optional IV length before calling wc_AesSetKey. |
| examples/provider/CryptoBenchmark.sh | Fails closed when SHA-256 tooling is unavailable; avoids unverified downloads/use. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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 includes 10 Fenrir fixes: