|
1 | 1 | /* |
2 | | - * Copyright IBM Corp. 2025 |
| 2 | + * Copyright IBM Corp. 2025, 2026 |
3 | 3 | * |
4 | 4 | * This code is free software; you can redistribute it and/or modify it |
5 | 5 | * under the terms provided by IBM in the LICENSE file that accompanied |
@@ -373,49 +373,45 @@ Java_com_ibm_crypto_plus_provider_ock_NativeInterface_MLKEY_1createPrivateKey( |
373 | 373 | return mlkeyId; |
374 | 374 | } |
375 | 375 |
|
376 | | - keyBytesNative = (unsigned char *)((*env)->GetPrimitiveArrayCritical( |
377 | | - env, privateKeyBytes, &isCopy)); |
378 | | - if (NULL == keyBytesNative) { |
379 | | - throwOCKException(env, 0, "NULL from GetPrimitiveArrayCritical!"); |
380 | | - } else { |
381 | | - pBytes = keyBytesNative; |
382 | | - size = (*env)->GetArrayLength(env, privateKeyBytes); |
383 | | - if (cipherName == NULL) { |
| 376 | + if (!(algoChars = (*env)->GetStringUTFChars(env, cipherName, NULL))) { |
384 | 377 | #ifdef DEBUG_PQC_KEY_DETAIL |
385 | | - if (debug) { |
386 | | - gslogMessage("cipherName = NULL"); |
387 | | - } |
388 | | -#endif |
389 | | - (*env)->ReleasePrimitiveArrayCritical(env, privateKeyBytes, |
390 | | - keyBytesNative, JNI_ABORT); |
391 | | - return 0; |
| 378 | + if (debug) { |
| 379 | + gslogMessage("GetStringUTFChars failed %s", cipherName); |
392 | 380 | } |
393 | | - |
394 | | - if (!(algoChars = (*env)->GetStringUTFChars(env, cipherName, NULL))) { |
395 | | -#ifdef DEBUG_PQC_KEY_DETAIL |
396 | | - if (debug) { |
397 | | - gslogMessage("GetStringUTFChars failed %s", cipherName); |
398 | | - } |
399 | 381 | #endif |
400 | | - (*env)->ReleasePrimitiveArrayCritical(env, privateKeyBytes, |
401 | | - keyBytesNative, JNI_ABORT); |
402 | | - return 0; |
403 | | - } |
404 | | - nid = ICC_OBJ_txt2nid(ockCtx, algoChars); |
| 382 | + return 0; |
| 383 | + } |
405 | 384 |
|
406 | | - if (!nid) { |
407 | | - throwOCKException( |
408 | | - env, 0, "Algorithm not found."); /* Unsupported algorithm */ |
409 | | - } else { |
410 | | - ockPKey = |
411 | | - ICC_d2i_PrivateKey(ockCtx, nid, &ockPKey, &pBytes, (long)size); |
| 385 | + nid = ICC_OBJ_txt2nid(ockCtx, algoChars); |
412 | 386 |
|
413 | | - if (ockPKey == NULL) { |
414 | | - ockCheckStatus(ockCtx); |
415 | | - throwOCKException(env, 0, "ICC_d2i_PrivateKey failed"); |
| 387 | + if (!nid) { |
| 388 | + throwOCKException( |
| 389 | + env, 0, "Algorithm not found."); /* Unsupported algorithm */ |
| 390 | + } else { |
| 391 | + keyBytesNative = (unsigned char *)((*env)->GetPrimitiveArrayCritical( |
| 392 | + env, privateKeyBytes, &isCopy)); |
| 393 | + |
| 394 | + if (NULL != keyBytesNative) { |
| 395 | + pBytes = keyBytesNative; |
| 396 | + size = (*env)->GetArrayLength(env, privateKeyBytes); |
| 397 | + |
| 398 | + if (cipherName != NULL) { |
| 399 | + ockPKey = |
| 400 | + ICC_d2i_PrivateKey(ockCtx, nid, &ockPKey, &pBytes, (long)size); |
| 401 | + |
| 402 | + if (ockPKey == NULL) { |
| 403 | + ockCheckStatus(ockCtx); |
| 404 | + throwOCKException(env, 0, "ICC_d2i_PrivateKey failed"); |
| 405 | + } else { |
| 406 | + mlkeyId = (jlong)((intptr_t)ockPKey); |
| 407 | + } |
416 | 408 | } else { |
417 | | - mlkeyId = (jlong)((intptr_t)ockPKey); |
418 | | - } |
| 409 | +#ifdef DEBUG_PQC_KEY_DETAIL |
| 410 | + if (debug) { |
| 411 | + gslogMessage("cipherName = NULL"); |
| 412 | + } |
| 413 | +#endif |
| 414 | + } |
419 | 415 | } |
420 | 416 | } |
421 | 417 |
|
@@ -653,7 +649,7 @@ Java_com_ibm_crypto_plus_provider_ock_NativeInterface_MLKEY_1getPublicKeyBytes( |
653 | 649 | (*env)->DeleteLocalRef(env, keyBytes); |
654 | 650 | } |
655 | 651 |
|
656 | | - return keyBytes; |
| 652 | + return retKeyBytes; |
657 | 653 | } |
658 | 654 |
|
659 | 655 | //============================================================================ |
|
0 commit comments