Hardening for FIPS RNG, AES-CMAC key wipe, SHA finals - #270
Open
cconlon wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens wolfcrypt-jni’s FIPS/JNI boundary checks and key-handling hygiene to address three reported issues: validating RNG output sizing, ensuring AES-CMAC key material is wiped on re-key, and rejecting undersized output buffers in SHA/SHA3 native final functions (with safer debug logging).
Changes:
- Add FIPS RNG
GenerateBlockguardrails to reject negative sizes and sizes exceeding the backingByteBuffer/byte[]capacity, plus new JUnit coverage for these cases. - Ensure
AesCmac.setKey()zeroizes the previous stored key clone before replacing it, and add a regression test that verifies the prior clone is wiped on re-key. - Add output-array size validation to SHA/SHA224/SHA256/SHA384/SHA512 and SHA3 byte-array finals, and only emit debug hex logs when the final succeeds.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/test/java/com/wolfssl/wolfcrypt/test/fips/RngFipsTest.java | Adds tests covering rejected bufSz values for FIPS RNG GenerateBlock wrappers. |
| src/test/java/com/wolfssl/wolfcrypt/test/AesCmacTest.java | Adds a regression test validating prior key-clone zeroization on AES-CMAC re-key. |
| src/main/java/com/wolfssl/wolfcrypt/AesCmac.java | Zeroizes the previously stored key clone during setKey() before storing the new clone. |
| jni/jni_sha.c | Rejects undersized output arrays in SHA/SHA3 finals and guards debug hex logging on success. |
| jni/jni_fips.c | Validates bufSz against backing buffer capacity/length in FIPS RNG GenerateBlock 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 fixes 3 Fenrir issues:
bufSzagainst buffer capacity in the FIPS RNGGenerateBlockwrappersAesCmackey clone on re-key