Skip to content

First pass Fenrir fixes#205

Open
cconlon wants to merge 19 commits intowolfSSL:masterfrom
cconlon:fenrir
Open

First pass Fenrir fixes#205
cconlon wants to merge 19 commits intowolfSSL:masterfrom
cconlon:fenrir

Conversation

@cconlon
Copy link
Member

@cconlon cconlon commented Mar 19, 2026

Summary

This PR fixes 19 JNI/JCE issues identified by Fenrir, and adds some missing JUnit test coverage for Ed25519, Curve25519, RSA PKCS8 decode, RSA CRT export, and HMAC offset/length validation.

  • wc_ed25519_verify_msg() was passed message length instead of signature length
  • RsaFlattenPublicKey() and RsaExportCrtKey() cast 64-bit jlong* to 32-bit word32* for size parameters
  • wc_RsaEncryptSize() return assigned to unsigned word32 then checked < 0 (always false) in 8 RSA functions
  • HMAC throwWolfCryptExceptionFromError(env, ret) passed ret (still 0) instead of hmacSz
  • Add HMAC offset/length validation against array size in both byte array and ByteBuffer variants
  • NULL check improvements for HMAC, Ed25519, Curve25519, Pwdbased
  • More aggressive local reference cleanup
  • Return defensive copy of IV array for AES-GCM engineGetIV()

@cconlon cconlon self-assigned this Mar 19, 2026
Copilot AI review requested due to automatic review settings March 19, 2026 22:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Addresses Fenrir-reported JNI/JCE issues across RSA, HMAC, Ed25519, Curve25519, and related native bindings, and expands JUnit coverage for key crypto workflows and edge cases.

Changes:

  • Fixes JNI argument handling/size conversions for RSA and corrects Ed25519 verify parameter usage.
  • Adds stronger bounds validation and improved cleanup (local refs / pinned arrays) in several JNI modules.
  • Adds/extends JUnit tests for Ed25519, Curve25519, RSA PKCS8 + raw export sizing, and HMAC offset/length behavior.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
src/test/java/com/wolfssl/wolfcrypt/test/WolfCryptTestSuite.java Adds Ed25519/Curve25519 tests to the suite.
src/test/java/com/wolfssl/wolfcrypt/test/RsaTest.java Adds PKCS8 decode/verify and raw export sizing tests.
src/test/java/com/wolfssl/wolfcrypt/test/HmacTest.java Adds tests for offset/length validation and ByteBuffer updates.
src/test/java/com/wolfssl/wolfcrypt/test/Ed25519Test.java New JUnit coverage for Ed25519 sign/verify/export/import.
src/test/java/com/wolfssl/wolfcrypt/test/Curve25519Test.java New JUnit coverage for Curve25519 shared secret and export/import.
src/main/java/com/wolfssl/wolfcrypt/Ed25519.java Exposes Ed25519 key/signature sizes as Java constants.
src/main/java/com/wolfssl/wolfcrypt/Curve25519.java Exposes Curve25519 key size as a Java constant.
src/main/java/com/wolfssl/provider/jce/WolfCryptCipher.java Returns defensive copy of IV from engineGetIV().
jni/jni_rsa.c Fixes size type handling, cleanup, and encrypt-size checks in RSA JNI.
jni/jni_pwdbased.c Avoids dereferencing NULL Java arrays when pinning password/salt buffers.
jni/jni_hmac.c Adds offset/length bounds validation and fixes error propagation in final.
jni/jni_fips.c Ensures pinned IV array is released on BAD_FUNC_ARG path.
jni/jni_ed25519.c Improves NULL checks, removes stray printf, fixes sig length lookup.
jni/jni_ecc.c Adds missing releases for pinned parameter arrays.
jni/jni_curve25519.c Improves NULL checks and streamlines error handling for Curve25519 JNI.
jni/jni_chacha.c Ensures pinned input is released on error and on success.
jni/include/com_wolfssl_wolfcrypt_Ed25519.h Exposes Ed25519 size constants to JNI header.
jni/include/com_wolfssl_wolfcrypt_Curve25519.h Exposes Curve25519 key size constant to JNI header.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

cconlon added 19 commits March 19, 2026 17:05
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