Throw correct IllegalArgumentException from WolfCryptRandom.engineGenerateSeed()#152
Merged
rlm2002 merged 1 commit intowolfSSL:masterfrom Sep 8, 2025
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the WolfCryptRandom implementation by adding proper input validation to engineGenerateSeed() and introducing algorithm aliases for better interoperability. The changes ensure that negative values and values exceeding wolfCrypt's maximum block length properly throw IllegalArgumentException, which fixes compatibility with OpenJDK SunJCE tests.
- Added input validation to throw
IllegalArgumentExceptionfor invalid seed generation parameters - Introduced algorithm aliases (
Hash_DRBG,DRBG) to match existingHashDRBGimplementation - Added comprehensive JUnit tests to prevent regression
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/com/wolfssl/provider/jce/WolfCryptRandom.java | Added input validation and logging to engineGenerateSeed() method |
| src/main/java/com/wolfssl/provider/jce/WolfCryptProvider.java | Registered new algorithm aliases for SecureRandom |
| src/main/java/com/wolfssl/wolfcrypt/Rng.java | Added static constant for maximum block length |
| jni/jni_rng.c | Refactored error handling and added native method for max block length |
| jni/include/com_wolfssl_wolfcrypt_Rng.h | Added JNI header for new native method |
| src/test/java/com/wolfssl/provider/jce/test/WolfCryptRandomTest.java | Added comprehensive tests for new validation and aliases |
| README_JCE.md | Updated documentation to reflect new algorithm aliases |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
fe8f07a to
8c69699
Compare
…neGenerateSeed(), add HashDRBG aliases Hash_DRBG and DRBG
8c69699 to
fde6651
Compare
rlm2002
approved these changes
Sep 8, 2025
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 correctly throws
IllegalArgumentExceptionfromWolfCryptRandom.engineGenerateSeed()for input values that are negative or larger than wolfCrypt's supported size.This also adds algorithm aliases (
Hash_DRBG,DRBG) to match the existingHashDRBGimplementation. This allows for better interop for applications using those other algorithm names.JUnit tests are included to prevent regression on these changes.
This fixes OpenJDK SunJCE test:
security/SecureRandom/EnoughSeedTest.java