Buffer sizing, native resource cleanup, and lifecycle fixes - #259
Open
cconlon wants to merge 8 commits into
Open
Buffer sizing, native resource cleanup, and lifecycle fixes#259cconlon wants to merge 8 commits into
cconlon wants to merge 8 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR tightens argument/buffer validation, improves native resource lifecycle handling, and corrects JNI wrapper behavior/comments across several crypto primitives in the wolfCrypt JNI/JCE codebase.
Changes:
- Fix
BlockCipher.update()to size returned output based on the requested operation length and add new invalid-length tests for AES/3DES/ECB variants. - Add defensive buffer-capacity validation for RSA CRT key export and extend tests to cover oversized/negative capacities.
- Improve native cleanup and lifecycle behavior (FIPS callback local ref cleanup + thread detach; JNI_OnLoad partial-init cleanup; CMAC context freeing on reuse), plus correct misleading import comments in Curve25519/Ed25519 JNI wrappers.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/com/wolfssl/wolfcrypt/BlockCipher.java | Adjusts update() output sizing and adds argument validation for offset/length. |
| jni/jni_rsa.c | Validates caller-provided RSA export buffer sizes against actual Java array lengths. |
| src/test/java/com/wolfssl/wolfcrypt/test/RsaTest.java | Adds regression tests for invalid RSA export buffer capacities. |
| src/test/java/com/wolfssl/wolfcrypt/test/AesTest.java | Adds tests ensuring update() sizes output to requested length and rejects invalid ranges. |
| src/test/java/com/wolfssl/wolfcrypt/test/Des3Test.java | Adds test coverage for rejecting invalid update() ranges. |
| src/test/java/com/wolfssl/wolfcrypt/test/AesEcbTest.java | Adds test coverage for rejecting invalid update() ranges. |
| jni/jni_native_struct.c | Ensures partial JNI_OnLoad failures clean up cert manager init and reset stored JavaVM pointer. |
| jni/jni_fips.c | Ensures FIPS callback releases local refs and detaches threads when it attached them. |
| jni/jni_aescmac.c | Adds version-gated CMAC context freeing for reset/rekey and native free paths. |
| src/test/java/com/wolfssl/wolfcrypt/test/AesCmacTest.java | Adds regression test for CMAC reset/rekey behavior mid-stream. |
| jni/jni_curve25519.c | Corrects copied/misleading import comments in Curve25519 JNI wrappers. |
| jni/jni_ed25519.c | Corrects copied/misleading import comments in Ed25519 JNI wrappers. |
💡 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 11 Fenrir fixes:
BlockCipher.update()output from requested length instead of the full input arraywc_CmacFree()on release and before reinitializing in setKey/reset