Skip to content

wolfCrypt JNI/JCE hardening fixes - #264

Open
cconlon wants to merge 10 commits into
wolfSSL:masterfrom
cconlon:fenrirAug20_2
Open

wolfCrypt JNI/JCE hardening fixes#264
cconlon wants to merge 10 commits into
wolfSSL:masterfrom
cconlon:fenrirAug20_2

Conversation

@cconlon

@cconlon cconlon commented Aug 21, 2026

Copy link
Copy Markdown
Member

This PR includes 10 Fenrir fixes:

  • F-5225: Validate ChaCha IV length before native SetIV, which reads a fixed 12 bytes.
  • F-5226: Zeroize native ChaCha key copy before JNI release in setKey.
  • F-5395: Validate AES IV length in native CBC/CTR/OFB setKey wrappers.
  • F-5396: Validate 3DES key and IV length in native setKey wrapper.
  • F-5892: Enforce minimum DH prime size (Dh.DH_MIN_SIZE) on all KeyFactory import paths.
  • F-5893: Zeroize previous HMAC key on re-key in setKey.
  • F-5992: Throw AEADBadTagException on AES-CCM tag mismatch, mirroring AES-GCM.
  • F-6153: Zeroize full RSA private-decrypt output buffer before free, not just plaintext length.
  • F-6154: Zeroize native ML-DSA seed and private key copies before JNI release.
  • F-3763: Fail closed in CryptoBenchmark.sh when no SHA-256 tool is available.

@cconlon cconlon self-assigned this Aug 21, 2026
Copilot AI lite review requested due to automatic review settings August 21, 2026 22:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

2 participants