src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_convert.c
changeset 58489 2faeaa5933a6
parent 58281 49836127542b
child 58679 9c3209ff7550
equal deleted inserted replaced
58488:165b193b30dd 58489:2faeaa5933a6
   719         throwOutOfMemoryError(env, 0);
   719         throwOutOfMemoryError(env, 0);
   720         return NULL;
   720         return NULL;
   721     }
   721     }
   722 
   722 
   723     // populate using java values
   723     // populate using java values
   724     ckParamPtr->prfMechanism = jLongToCKULong(jPrfMechanism);
   724     ckParamPtr->prfHashMechanism = jLongToCKULong(jPrfMechanism);
   725     ckParamPtr->ulMacLength = jLongToCKULong(jUlMacLength);
   725     ckParamPtr->ulMacLength = jLongToCKULong(jUlMacLength);
   726     ckParamPtr->ulServerOrClient = jLongToCKULong(jUlServerOrClient);
   726     ckParamPtr->ulServerOrClient = jLongToCKULong(jUlServerOrClient);
   727 
   727 
   728     if (pLength != NULL) {
   728     if (pLength != NULL) {
   729         *pLength = sizeof(CK_TLS_MAC_PARAMS);
   729         *pLength = sizeof(CK_TLS_MAC_PARAMS);
  1012     free(ckParamPtr);
  1012     free(ckParamPtr);
  1013     return NULL;
  1013     return NULL;
  1014 }
  1014 }
  1015 
  1015 
  1016 /*
  1016 /*
  1017  * converts the Java CK_GCM_PARAMS object to a CK_GCM_PARAMS pointer
  1017  * converts the Java CK_GCM_PARAMS object to a CK_GCM_PARAMS_NO_IVBITS pointer
       
  1018  * Note: Need to try NSS definition first to avoid SIGSEGV.
  1018  *
  1019  *
  1019  * @param env - used to call JNI funktions to get the Java classes and objects
  1020  * @param env - used to call JNI funktions to get the Java classes and objects
  1020  * @param jParam - the Java CK_GCM_PARAMS object to convert
  1021  * @param jParam - the Java CK_GCM_PARAMS object to convert
  1021  * @param pLength - length of the allocated memory of the returned pointer
  1022  * @param pLength - length of the allocated memory of the returned pointer
  1022  * @return pointer to the new CK_GCM_PARAMS structure
  1023  * @return pointer to the new CK_GCM_PARAMS_NO_IVBITS structure
  1023  */
  1024  */
  1024 CK_GCM_PARAMS_PTR
  1025 CK_GCM_PARAMS_NO_IVBITS_PTR
  1025 jGCMParamsToCKGCMParamPtr(JNIEnv *env, jobject jParam, CK_ULONG *pLength)
  1026 jGCMParamsToCKGCMParamPtr(JNIEnv *env, jobject jParam, CK_ULONG *pLength)
  1026 {
  1027 {
  1027     CK_GCM_PARAMS_PTR ckParamPtr;
  1028     CK_GCM_PARAMS_NO_IVBITS_PTR ckParamPtr;
  1028     jclass jGcmParamsClass;
  1029     jclass jGcmParamsClass;
  1029     jfieldID fieldID;
  1030     jfieldID fieldID;
  1030     jobject jIv, jAad;
  1031     jobject jIv, jAad;
  1031     jlong jTagLen;
  1032     jlong jTagLen;
  1032 
  1033 
  1050     jAad = (*env)->GetObjectField(env, jParam, fieldID);
  1051     jAad = (*env)->GetObjectField(env, jParam, fieldID);
  1051     fieldID = (*env)->GetFieldID(env, jGcmParamsClass, "tagBits", "J");
  1052     fieldID = (*env)->GetFieldID(env, jGcmParamsClass, "tagBits", "J");
  1052     if (fieldID == NULL) { return NULL; }
  1053     if (fieldID == NULL) { return NULL; }
  1053     jTagLen = (*env)->GetLongField(env, jParam, fieldID);
  1054     jTagLen = (*env)->GetLongField(env, jParam, fieldID);
  1054 
  1055 
  1055     // allocate memory for CK_GCM_PARAMS pointer
  1056     // allocate memory for CK_GCM_PARAMS_NO_IVBITS pointer
  1056     ckParamPtr = calloc(1, sizeof(CK_GCM_PARAMS));
  1057     ckParamPtr = calloc(1, sizeof(CK_GCM_PARAMS_NO_IVBITS));
  1057     if (ckParamPtr == NULL) {
  1058     if (ckParamPtr == NULL) {
  1058         throwOutOfMemoryError(env, 0);
  1059         throwOutOfMemoryError(env, 0);
  1059         return NULL;
  1060         return NULL;
  1060     }
  1061     }
  1061 
  1062 
  1071     }
  1072     }
  1072 
  1073 
  1073     ckParamPtr->ulTagBits = jLongToCKULong(jTagLen);
  1074     ckParamPtr->ulTagBits = jLongToCKULong(jTagLen);
  1074 
  1075 
  1075     if (pLength != NULL) {
  1076     if (pLength != NULL) {
  1076         *pLength = sizeof(CK_GCM_PARAMS);
  1077         *pLength = sizeof(CK_GCM_PARAMS_NO_IVBITS);
  1077     }
  1078     }
  1078     TRACE1("Created inner GCM_PARAMS PTR %lX\n", ptr_to_jlong(ckParamPtr));
  1079     TRACE1("Created inner GCM_PARAMS PTR w/o ulIvBits %p\n", ckParamPtr);
  1079     return ckParamPtr;
  1080     return ckParamPtr;
  1080 cleanup:
  1081 cleanup:
  1081     free(ckParamPtr->pIv);
  1082     free(ckParamPtr->pIv);
  1082     free(ckParamPtr->pAAD);
  1083     free(ckParamPtr->pAAD);
  1083     free(ckParamPtr);
  1084     free(ckParamPtr);
  1084     return NULL;
  1085     return NULL;
  1085 
       
  1086 }
  1086 }
  1087 
  1087 
  1088 /*
  1088 /*
  1089  * converts the Java CK_CCM_PARAMS object to a CK_CCM_PARAMS pointer
  1089  * converts the Java CK_CCM_PARAMS object to a CK_CCM_PARAMS pointer
  1090  *
  1090  *
  1177     ckpMech =  (CK_MECHANISM_PTR) calloc(1, sizeof(CK_MECHANISM));
  1177     ckpMech =  (CK_MECHANISM_PTR) calloc(1, sizeof(CK_MECHANISM));
  1178     if (ckpMech == NULL) {
  1178     if (ckpMech == NULL) {
  1179         throwOutOfMemoryError(env, 0);
  1179         throwOutOfMemoryError(env, 0);
  1180         return NULL;
  1180         return NULL;
  1181     }
  1181     }
  1182     TRACE1("DEBUG jMechanismToCKMechanismPtr: allocated mech %p \n", ckpMech);
  1182     TRACE1("DEBUG jMechanismToCKMechanismPtr: allocated mech %p\n", ckpMech);
  1183 
  1183 
  1184     ckpMech->mechanism = jLongToCKULong(jMechType);
  1184     ckpMech->mechanism = jLongToCKULong(jMechType);
  1185 
  1185 
  1186     /* convert the specific Java mechanism parameter object to a pointer to a
  1186     /* convert the specific Java mechanism parameter object to a pointer to a
  1187      *  CK-type mechanism structure
  1187      *  CK-type mechanism structure