Repository navigation
JCE: validate RSA keygen size and public exponent at KeyPairGenerator.initialize() - #295
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Native maximum and platform-specific constraints can still cause late failures or exponent truncation.
2 open findings
What changed in this PR
Adds early RSA key-generation validation to avoid deferred native errors.
Changes:
- Adds native minimum-exponent detection.
- Validates minimum key size and exponent parity/range.
- Adds invalid-parameter tests.
| File | Description |
|---|---|
jni/jni_rsa.c |
Exposes the native minimum exponent. |
jni/include/com_wolfssl_wolfcrypt_Rsa.h |
Declares the new JNI method. |
src/main/java/com/wolfssl/wolfcrypt/Rsa.java |
Publishes RSA_MIN_EXPONENT. |
src/main/java/com/wolfssl/provider/jce/WolfCryptKeyPairGenerator.java |
Adds early RSA parameter validation. |
src/test/java/com/wolfssl/provider/jce/test/WolfCryptKeyPairGeneratorTest.java |
Tests rejected sizes and exponents. |
Files not reviewed (1)
- jni/include/com_wolfssl_wolfcrypt_Rsa.h: Generated file
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #295
Scan targets checked: wolfcrypt-jni-src, wolfcrypt-jni-bugs
Coverage: 2 of 5 in-scope changed file(s) opened by the reviewer; not opened: jni/include/com_wolfssl_wolfcrypt_Rsa.h, src/main/java/com/wolfssl/wolfcrypt/Rsa.java, src/test/java/com/wolfssl/provider/jce/test/WolfCryptKeyPairGeneratorTest.java
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Lite
…ative minimum at initialize(), add Rsa.RSA_MIN_EXPONENT
e3761d9 to
8d1f6fa
Compare

This PR adjusts
KeyPairGenerator.initialize(RSAKeyGenParameterSpec)to throwInvalidAlgorithmParameterExceptionfor RSA key sizes or public exponents that native key generation would reject. Before, these failed later ingenerateKeyPair()with an uncheckedWolfCryptException(BAD_FUNC_ARG).Rsa.RSA_MIN_SIZE, matching the existinginitialize(int)check.Rsa.RSA_MIN_EXPONENT:WC_RSA_EXPONENT(65537) on FIPS builds, since FIPS 186-4/186-5 key generation requires e > 2^16, and 3 otherwise. This matches thewc_MakeRsaKey()check. Exponents below it, or even exponents, are rejected.RSA_MIN_EXPONENT, and makes the existing bad key size test fail when no exception is thrown.