Skip to content

Commit 45939a9

Browse files
committed
Tests: handle ECC curves unsupported by SP math in KeyPairGenerator tests
1 parent 595a071 commit 45939a9

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,23 @@ public static void testProviderInstallationAtRuntime() {
183183
int size = Ecc.getCurveSizeFromName(curves[i].toUpperCase());
184184

185185
if (size > 0) {
186+
187+
/* Verify curve supports key generation. */
188+
try {
189+
KeyPairGenerator testKpg =
190+
KeyPairGenerator.getInstance("EC", "wolfJCE");
191+
ECGenParameterSpec testSpec =
192+
new ECGenParameterSpec(curves[i]);
193+
testKpg.initialize(testSpec);
194+
KeyPair testKp = testKpg.generateKeyPair();
195+
if (testKp == null) {
196+
continue;
197+
}
198+
} catch (Exception e) {
199+
/* Curve not usable for keygen, skip */
200+
continue;
201+
}
202+
186203
enabledCurves.add(curves[i]);
187204

188205
if (!enabledEccKeySizes.contains(Integer.valueOf(size))) {
@@ -1174,7 +1191,9 @@ public void testECValidKeySizesMapToNISTCurves()
11741191

11751192
if (wce != null) {
11761193
String msg = wce.getMessage();
1177-
if (msg != null && msg.contains("Bad function argument")) {
1194+
if (msg != null &&
1195+
(msg.contains("Bad function argument") ||
1196+
msg.contains("Key size error"))) {
11781197
/* Expected for non-FIPS-approved curves */
11791198
continue;
11801199
}

0 commit comments

Comments
 (0)