Skip to content

Commit

Permalink
Check for return code on call to ICC_EVP_PKEY_derive
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkatonica committed Dec 13, 2024
1 parent 9c0b8ea commit 869abb0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
6 changes: 5 additions & 1 deletion src/main/native/ECKey.c
Original file line number Diff line number Diff line change
Expand Up @@ -2119,6 +2119,7 @@ JNIEXPORT jbyteArray JNICALL Java_com_ibm_crypto_plus_provider_ock_NativeInterfa
unsigned char * secretBytesNative = NULL;
jboolean isCopy = 0;
size_t secret_key_len = 0;
int rc = 0;

if (debug) {
gslogFunctionEntry(functionName);
Expand All @@ -2143,7 +2144,10 @@ JNIEXPORT jbyteArray JNICALL Java_com_ibm_crypto_plus_provider_ock_NativeInterfa
if (NULL == secretBytesNative) {
throwOCKException(env, 0, "NULL from GetPrimitiveArrayCritical");
} else {
ICC_EVP_PKEY_derive(ockCtx, gen_ctx, secretBytesNative, &secret_key_len);
rc = ICC_EVP_PKEY_derive(ockCtx, gen_ctx, secretBytesNative, &secret_key_len);
if (rc != ICC_OSSL_SUCCESS) {
throwOCKException(env, 0, "ICC_EVP_PKEY_derive failed to derive a key");
}
ICC_EVP_PKEY_CTX_free(ockCtx, gen_ctx);
(*env)->ReleasePrimitiveArrayCritical(env, secretBytes, secretBytesNative, 0);
if (debug) {
Expand Down
17 changes: 4 additions & 13 deletions src/test/java/ibm/jceplus/junit/base/BaseTestXDH.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.security.spec.XECPublicKeySpec;
import java.util.Arrays;
import javax.crypto.KeyAgreement;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -336,20 +337,10 @@ private void runSmallOrderTest() throws Exception {
private void testSmallOrder(String name, String a_pri, String b_pub, String result)
throws Exception {

try {
//System.out.println("Pub - "+b_pub);
Exception thrown = Assertions.assertThrows(IllegalStateException.class, () -> {
runDiffieHellmanTest(name, a_pri, b_pub, result);
} catch (InvalidKeyException ex) {
assertTrue(true);
return;
} catch (InvalidKeySpecException ex) {
assertTrue(true);
return;
} catch (Exception e1) {
System.out.println(e1.getMessage());
}

throw new RuntimeException("No exception on small-order point");
});
Assertions.assertEquals("ICC_EVP_PKEY_derive failed to derive a key", thrown.getMessage());
}

private void runNonCanonicalTest() throws Exception {
Expand Down

0 comments on commit 869abb0

Please sign in to comment.