Skip to content

Commit 869abb0

Browse files
committed
Check for return code on call to ICC_EVP_PKEY_derive
1 parent 9c0b8ea commit 869abb0

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

src/main/native/ECKey.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2119,6 +2119,7 @@ JNIEXPORT jbyteArray JNICALL Java_com_ibm_crypto_plus_provider_ock_NativeInterfa
21192119
unsigned char * secretBytesNative = NULL;
21202120
jboolean isCopy = 0;
21212121
size_t secret_key_len = 0;
2122+
int rc = 0;
21222123

21232124
if (debug) {
21242125
gslogFunctionEntry(functionName);
@@ -2143,7 +2144,10 @@ JNIEXPORT jbyteArray JNICALL Java_com_ibm_crypto_plus_provider_ock_NativeInterfa
21432144
if (NULL == secretBytesNative) {
21442145
throwOCKException(env, 0, "NULL from GetPrimitiveArrayCritical");
21452146
} else {
2146-
ICC_EVP_PKEY_derive(ockCtx, gen_ctx, secretBytesNative, &secret_key_len);
2147+
rc = ICC_EVP_PKEY_derive(ockCtx, gen_ctx, secretBytesNative, &secret_key_len);
2148+
if (rc != ICC_OSSL_SUCCESS) {
2149+
throwOCKException(env, 0, "ICC_EVP_PKEY_derive failed to derive a key");
2150+
}
21472151
ICC_EVP_PKEY_CTX_free(ockCtx, gen_ctx);
21482152
(*env)->ReleasePrimitiveArrayCritical(env, secretBytes, secretBytesNative, 0);
21492153
if (debug) {

src/test/java/ibm/jceplus/junit/base/BaseTestXDH.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.security.spec.XECPublicKeySpec;
3131
import java.util.Arrays;
3232
import javax.crypto.KeyAgreement;
33+
import org.junit.jupiter.api.Assertions;
3334
import org.junit.jupiter.api.Test;
3435
import static org.junit.Assert.assertTrue;
3536

@@ -336,20 +337,10 @@ private void runSmallOrderTest() throws Exception {
336337
private void testSmallOrder(String name, String a_pri, String b_pub, String result)
337338
throws Exception {
338339

339-
try {
340-
//System.out.println("Pub - "+b_pub);
340+
Exception thrown = Assertions.assertThrows(IllegalStateException.class, () -> {
341341
runDiffieHellmanTest(name, a_pri, b_pub, result);
342-
} catch (InvalidKeyException ex) {
343-
assertTrue(true);
344-
return;
345-
} catch (InvalidKeySpecException ex) {
346-
assertTrue(true);
347-
return;
348-
} catch (Exception e1) {
349-
System.out.println(e1.getMessage());
350-
}
351-
352-
throw new RuntimeException("No exception on small-order point");
342+
});
343+
Assertions.assertEquals("ICC_EVP_PKEY_derive failed to derive a key", thrown.getMessage());
353344
}
354345

355346
private void runNonCanonicalTest() throws Exception {

0 commit comments

Comments
 (0)