Skip to content

Commit e06ba5a

Browse files
authored
Merge pull request #162 from cconlon/rsaKeyPairGenFix
JCE: check RSA KeyPairGenerator key size against Rsa.RSA_MIN_SIZE
2 parents 28787ca + 29d2b85 commit e06ba5a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/main/java/com/wolfssl/provider/jce/WolfCryptKeyPairGenerator.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,14 @@ else if (keysize == 8192) {
232232
}
233233

234234
if (type == KeyType.WC_RSA || type == KeyType.WC_RSA_PSS) {
235+
236+
/* Sanity check on key size */
237+
if (keysize < Rsa.RSA_MIN_SIZE) {
238+
throw new InvalidParameterException(
239+
"RSA key size too small, min is " +
240+
Rsa.RSA_MIN_SIZE);
241+
}
242+
235243
/* Set default RSA exponent for wolfSSL */
236244
this.publicExponent = Rsa.getDefaultRsaExponent();
237245
}

src/test/java/com/wolfssl/provider/jce/test/WolfCryptKeyPairGeneratorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public void testKeyPairGeneratorRsaInitializeWithKeySize()
259259
/* bad key size should fail */
260260
try {
261261
kpg.initialize(10);
262-
} catch (WolfCryptException e) {}
262+
} catch (InvalidParameterException e) {}
263263
}
264264
}
265265

0 commit comments

Comments
 (0)