Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h
38918 views
/*1* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.2*/34/* Copyright (c) 2002 Graz University of Technology. All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions are met:8*9* 1. Redistributions of source code must retain the above copyright notice,10* this list of conditions and the following disclaimer.11*12* 2. Redistributions in binary form must reproduce the above copyright notice,13* this list of conditions and the following disclaimer in the documentation14* and/or other materials provided with the distribution.15*16* 3. The end-user documentation included with the redistribution, if any, must17* include the following acknowledgment:18*19* "This product includes software developed by IAIK of Graz University of20* Technology."21*22* Alternately, this acknowledgment may appear in the software itself, if23* and wherever such third-party acknowledgments normally appear.24*25* 4. The names "Graz University of Technology" and "IAIK of Graz University of26* Technology" must not be used to endorse or promote products derived from27* this software without prior written permission.28*29* 5. Products derived from this software may not be called30* "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior31* written permission of Graz University of Technology.32*33* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED34* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED35* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR36* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE37* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,38* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,39* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,40* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON41* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,42* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY43* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE44* POSSIBILITY OF SUCH DAMAGE.45*/4647/*48* pkcs11wrapper.h49* 18.05.200150*51* declaration of all functions used by pkcs11wrapper.c52*53* @author Karl Scheibelhofer <[email protected]>54* @author Martin Schlaeffer <[email protected]>55*/5657/* disable asserts in product mode */58#ifndef DEBUG59#ifndef NDEBUG60#define NDEBUG61#endif62#endif6364/* extra PKCS#11 constants not in the standard include files */6566#define CKA_NETSCAPE_BASE (0x80000000 + 0x4E534350)67#define CKA_NETSCAPE_TRUST_BASE (CKA_NETSCAPE_BASE + 0x2000)68#define CKA_NETSCAPE_TRUST_SERVER_AUTH (CKA_NETSCAPE_TRUST_BASE + 8)69#define CKA_NETSCAPE_TRUST_CLIENT_AUTH (CKA_NETSCAPE_TRUST_BASE + 9)70#define CKA_NETSCAPE_TRUST_CODE_SIGNING (CKA_NETSCAPE_TRUST_BASE + 10)71#define CKA_NETSCAPE_TRUST_EMAIL_PROTECTION (CKA_NETSCAPE_TRUST_BASE + 11)72#define CKA_NETSCAPE_DB 0xD5A0DB0073#define CKM_NSS_TLS_PRF_GENERAL 0x800003737475/*7677Define the PKCS#11 functions to include and exclude. Reduces the size78of the binary somewhat.7980This list needs to be kept in sync with the mapfile and PKCS11.java8182*/8384#define P11_ENABLE_C_INITIALIZE85#define P11_ENABLE_C_FINALIZE86#define P11_ENABLE_C_GETINFO87#define P11_ENABLE_C_GETSLOTLIST88#define P11_ENABLE_C_GETSLOTINFO89#define P11_ENABLE_C_GETTOKENINFO90#define P11_ENABLE_C_GETMECHANISMLIST91#define P11_ENABLE_C_GETMECHANISMINFO92#undef P11_ENABLE_C_INITTOKEN93#undef P11_ENABLE_C_INITPIN94#undef P11_ENABLE_C_SETPIN95#define P11_ENABLE_C_OPENSESSION96#define P11_ENABLE_C_CLOSESESSION97#undef P11_ENABLE_C_CLOSEALLSESSIONS98#define P11_ENABLE_C_GETSESSIONINFO99#define P11_ENABLE_C_GETOPERATIONSTATE100#define P11_ENABLE_C_SETOPERATIONSTATE101#define P11_ENABLE_C_LOGIN102#define P11_ENABLE_C_LOGOUT103#define P11_ENABLE_C_CREATEOBJECT104#define P11_ENABLE_C_COPYOBJECT105#define P11_ENABLE_C_DESTROYOBJECT106#undef P11_ENABLE_C_GETOBJECTSIZE107#define P11_ENABLE_C_GETATTRIBUTEVALUE108#define P11_ENABLE_C_SETATTRIBUTEVALUE109#define P11_ENABLE_C_FINDOBJECTSINIT110#define P11_ENABLE_C_FINDOBJECTS111#define P11_ENABLE_C_FINDOBJECTSFINAL112#define P11_ENABLE_C_ENCRYPTINIT113#define P11_ENABLE_C_ENCRYPT114#define P11_ENABLE_C_ENCRYPTUPDATE115#define P11_ENABLE_C_ENCRYPTFINAL116#define P11_ENABLE_C_DECRYPTINIT117#define P11_ENABLE_C_DECRYPT118#define P11_ENABLE_C_DECRYPTUPDATE119#define P11_ENABLE_C_DECRYPTFINAL120#define P11_ENABLE_C_DIGESTINIT121#define P11_ENABLE_C_DIGEST122#define P11_ENABLE_C_DIGESTUPDATE123#define P11_ENABLE_C_DIGESTKEY124#define P11_ENABLE_C_DIGESTFINAL125#define P11_ENABLE_C_SIGNINIT126#define P11_ENABLE_C_SIGN127#define P11_ENABLE_C_SIGNUPDATE128#define P11_ENABLE_C_SIGNFINAL129#define P11_ENABLE_C_SIGNRECOVERINIT130#define P11_ENABLE_C_SIGNRECOVER131#define P11_ENABLE_C_VERIFYINIT132#define P11_ENABLE_C_VERIFY133#define P11_ENABLE_C_VERIFYUPDATE134#define P11_ENABLE_C_VERIFYFINAL135#define P11_ENABLE_C_VERIFYRECOVERINIT136#define P11_ENABLE_C_VERIFYRECOVER137#undef P11_ENABLE_C_DIGESTENCRYPTUPDATE138#undef P11_ENABLE_C_DECRYPTDIGESTUPDATE139#undef P11_ENABLE_C_SIGNENCRYPTUPDATE140#undef P11_ENABLE_C_DECRYPTVERIFYUPDATE141#define P11_ENABLE_C_GENERATEKEY142#define P11_ENABLE_C_GENERATEKEYPAIR143#define P11_ENABLE_C_WRAPKEY144#define P11_ENABLE_C_UNWRAPKEY145#define P11_ENABLE_C_DERIVEKEY146#define P11_ENABLE_C_SEEDRANDOM147#define P11_ENABLE_C_GENERATERANDOM148#undef P11_ENABLE_C_GETFUNCTIONSTATUS149#undef P11_ENABLE_C_CANCELFUNCTION150#undef P11_ENABLE_C_WAITFORSLOTEVENT151#define P11_ENABLE_GETNATIVEKEYINFO152#define P11_ENABLE_CREATENATIVEKEY153154155/* include the platform dependent part of the header */156#include "p11_md.h"157158#include "pkcs11.h"159#include <jni.h>160#include <jni_util.h>161162#define MAX_STACK_BUFFER_LEN (4 * 1024)163#define MAX_HEAP_BUFFER_LEN (64 * 1024)164165#define MAX_DIGEST_LEN (64)166167#ifndef min168#define min(a, b) (((a) < (b)) ? (a) : (b))169#endif170171#define ckBBoolToJBoolean(x) ((x == TRUE) ? JNI_TRUE : JNI_FALSE);172#define jBooleanToCKBBool(x) ((x == JNI_TRUE) ? TRUE : FALSE);173174#define ckByteToJByte(x) ((jbyte) x)175#define jByteToCKByte(x) ((CK_BYTE) x)176177#define ckLongToJLong(x) ((jlong) x)178#define jLongToCKLong(x) ((CK_LONG) x)179180#define ckULongToJLong(x) ((jlong) x)181#define jLongToCKULong(x) ((CK_ULONG) x)182183// For CK_UNAVAILABLE_INFORMATION, always return -1 to avoid 32/64 bit problems.184#define ckULongSpecialToJLong(x) (((x) == CK_UNAVAILABLE_INFORMATION) \185? (jlong)-1 : ((jlong) x))186187#define ckCharToJChar(x) ((jchar) x)188#define jCharToCKChar(x) ((CK_CHAR) x)189190#define ckUTF8CharToJChar(x) ((jchar) x)191#define jCharToCKUTF8Char(x) ((CK_UTF8CHAR) x)192193#define ckFlageToJLong(x) ((jlong) x)194195#define ckVoidPtrToJObject(x) ((jobject) x)196#define jObjectToCKVoidPtr(x) ((CK_VOID_PTR) x)197198#define jIntToCKLong(x) ((CK_LONG) x)199#define jIntToCKULong(x) ((CK_ULONG) x)200#define ckLongToJInt(x) ((jint) x)201#define ckULongToJInt(x) ((jint) x)202#define ckULongToJSize(x) ((jsize) x)203#define unsignedIntToCKULong(x) ((CK_ULONG) x)204205//#define TRACE0d(s) { printf(s); fflush(stdout); }206//#define TRACE1d(s, p1) { printf(s, p1); fflush(stdout); }207//#define TRACE2d(s, p1, p2) { printf(s, p1, p2); fflush(stdout); }208209#ifdef P11_DEBUG210#define TRACE0(s) { printf(s); fflush(stdout); }211#define TRACE1(s, p1) { printf(s, p1); fflush(stdout); }212#define TRACE2(s, p1, p2) { printf(s, p1, p2); fflush(stdout); }213#define TRACE3(s, p1, p2, p3) { printf(s, p1, p2, p3); fflush(stdout); }214#else215#define TRACE0(s)216#define TRACE1(s, p1)217#define TRACE2(s, p1, p2)218#define TRACE3(s, p1, p2, p3)219#define TRACE_INTEND220#define TRACE_UNINTEND221#endif222223#define CK_ASSERT_OK 0L224225#define CLASS_P11PSSSIGNATURE "sun/security/pkcs11/P11PSSSignature"226227#define CLASS_INFO "sun/security/pkcs11/wrapper/CK_INFO"228#define CLASS_VERSION "sun/security/pkcs11/wrapper/CK_VERSION"229#define CLASS_SLOT_INFO "sun/security/pkcs11/wrapper/CK_SLOT_INFO"230#define CLASS_TOKEN_INFO "sun/security/pkcs11/wrapper/CK_TOKEN_INFO"231#define CLASS_MECHANISM "sun/security/pkcs11/wrapper/CK_MECHANISM"232#define CLASS_MECHANISM_INFO "sun/security/pkcs11/wrapper/CK_MECHANISM_INFO"233#define CLASS_SESSION_INFO "sun/security/pkcs11/wrapper/CK_SESSION_INFO"234#define CLASS_ATTRIBUTE "sun/security/pkcs11/wrapper/CK_ATTRIBUTE"235#define CLASS_DATE "sun/security/pkcs11/wrapper/CK_DATE"236#define CLASS_PKCS11EXCEPTION "sun/security/pkcs11/wrapper/PKCS11Exception"237#define CLASS_PKCS11RUNTIMEEXCEPTION "sun/security/pkcs11/wrapper/PKCS11RuntimeException"238#define CLASS_FILE_NOT_FOUND_EXCEPTION "java/io/FileNotFoundException"239#define CLASS_C_INITIALIZE_ARGS "sun/security/pkcs11/wrapper/CK_C_INITIALIZE_ARGS"240#define CLASS_CREATEMUTEX "sun/security/pkcs11/wrapper/CK_CREATEMUTEX"241#define CLASS_DESTROYMUTEX "sun/security/pkcs11/wrapper/CK_DESTROYMUTEX"242#define CLASS_LOCKMUTEX "sun/security/pkcs11/wrapper/CK_LOCKMUTEX"243#define CLASS_UNLOCKMUTEX "sun/security/pkcs11/wrapper/CK_UNLOCKMUTEX"244#define CLASS_NOTIFY "sun/security/pkcs11/wrapper/CK_NOTIFY"245246247/* mechanism parameter classes */248#define CLASS_AES_CTR_PARAMS "sun/security/pkcs11/wrapper/CK_AES_CTR_PARAMS"249#define CLASS_GCM_PARAMS "sun/security/pkcs11/wrapper/CK_GCM_PARAMS"250#define CLASS_CCM_PARAMS "sun/security/pkcs11/wrapper/CK_CCM_PARAMS"251#define CLASS_RSA_PKCS_PSS_PARAMS "sun/security/pkcs11/wrapper/CK_RSA_PKCS_PSS_PARAMS"252#define CLASS_RSA_PKCS_OAEP_PARAMS "sun/security/pkcs11/wrapper/CK_RSA_PKCS_OAEP_PARAMS"253254#define CLASS_MAC_GENERAL_PARAMS "sun/security/pkcs11/wrapper/CK_MAC_GENERAL_PARAMS"255#define CLASS_PBE_PARAMS "sun/security/pkcs11/wrapper/CK_PBE_PARAMS"256#define PBE_INIT_VECTOR_SIZE 8257#define CLASS_PKCS5_PBKD2_PARAMS "sun/security/pkcs11/wrapper/CK_PKCS5_PBKD2_PARAMS"258#define CLASS_EXTRACT_PARAMS "sun/security/pkcs11/wrapper/CK_EXTRACT_PARAMS"259260#define CLASS_ECDH1_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_ECDH1_DERIVE_PARAMS"261#define CLASS_ECDH2_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_ECDH2_DERIVE_PARAMS"262#define CLASS_X9_42_DH1_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_X9_42_DH1_DERIVE_PARAMS"263#define CLASS_X9_42_DH2_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_X9_42_DH2_DERIVE_PARAMS"264265/*266#define CLASS_KEA_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_KEA_DERIVE_PARAMS"267#define CLASS_RC2_PARAMS "sun/security/pkcs11/wrapper/CK_RC2_PARAMS"268#define CLASS_RC2_CBC_PARAMS "sun/security/pkcs11/wrapper/CK_RC2_CBC_PARAMS"269#define CLASS_RC2_MAC_GENERAL_PARAMS "sun/security/pkcs11/wrapper/CK_RC2_MAC_GENERAL_PARAMS"270#define CLASS_RC5_PARAMS "sun/security/pkcs11/wrapper/CK_RC5_PARAMS"271#define CLASS_RC5_CBC_PARAMS "sun/security/pkcs11/wrapper/CK_RC5_CBC_PARAMS"272#define CLASS_RC5_MAC_GENERAL_PARAMS "sun/security/pkcs11/wrapper/CK_RC5_MAC_GENERAL_PARAMS"273#define CLASS_SKIPJACK_PRIVATE_WRAP_PARAMS "sun/security/pkcs11/wrapper/CK_SKIPJACK_PRIVATE_WRAP_PARAMS"274#define CLASS_SKIPJACK_RELAYX_PARAMS "sun/security/pkcs11/wrapper/CK_SKIPJACK_RELAYX_PARAMS"275#define CLASS_KEY_WRAP_SET_OAEP_PARAMS "sun/security/pkcs11/wrapper/CK_KEY_WRAP_SET_OAEP_PARAMS"276#define CLASS_KEY_DERIVATION_STRING_DATA "sun/security/pkcs11/wrapper/CK_KEY_DERIVATION_STRING_DATA"277*/278279#define CLASS_SSL3_RANDOM_DATA "sun/security/pkcs11/wrapper/CK_SSL3_RANDOM_DATA"280// CLASS_SSL3_RANDOM_DATA is used by CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS281#define CLASS_SSL3_KEY_MAT_OUT "sun/security/pkcs11/wrapper/CK_SSL3_KEY_MAT_OUT"282// CLASS_SSL3_KEY_MAT_OUT is used by CLASS_SSL3_KEY_MAT_PARAMS and CK_TLS12_KEY_MAT_PARAMS283#define CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_SSL3_MASTER_KEY_DERIVE_PARAMS"284#define CLASS_TLS12_MASTER_KEY_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_TLS12_MASTER_KEY_DERIVE_PARAMS"285#define CLASS_SSL3_KEY_MAT_PARAMS "sun/security/pkcs11/wrapper/CK_SSL3_KEY_MAT_PARAMS"286#define CLASS_TLS12_KEY_MAT_PARAMS "sun/security/pkcs11/wrapper/CK_TLS12_KEY_MAT_PARAMS"287#define CLASS_TLS_PRF_PARAMS "sun/security/pkcs11/wrapper/CK_TLS_PRF_PARAMS"288#define CLASS_TLS_MAC_PARAMS "sun/security/pkcs11/wrapper/CK_TLS_MAC_PARAMS"289290291/* function to convert a PKCS#11 return value other than CK_OK into a Java Exception292* or to throw a PKCS11RuntimeException293*/294295jlong ckAssertReturnValueOK(JNIEnv *env, CK_RV returnValue);296void throwOutOfMemoryError(JNIEnv *env, const char *message);297void throwNullPointerException(JNIEnv *env, const char *message);298void throwIOException(JNIEnv *env, const char *message);299void throwPKCS11RuntimeException(JNIEnv *env, const char *message);300void throwDisconnectedRuntimeException(JNIEnv *env);301302/* functions to free CK structures and pointers303*/304void freeCKAttributeArray(CK_ATTRIBUTE_PTR attrPtr, int len);305void freeCKMechanismPtr(CK_MECHANISM_PTR mechPtr);306307/* functions to convert Java arrays to a CK-type array and the array length */308309void jBooleanArrayToCKBBoolArray(JNIEnv *env, const jbooleanArray jArray, CK_BBOOL **ckpArray, CK_ULONG_PTR ckLength);310void jByteArrayToCKByteArray(JNIEnv *env, const jbyteArray jArray, CK_BYTE_PTR *ckpArray, CK_ULONG_PTR ckLength);311void jLongArrayToCKULongArray(JNIEnv *env, const jlongArray jArray, CK_ULONG_PTR *ckpArray, CK_ULONG_PTR ckLength);312void jCharArrayToCKCharArray(JNIEnv *env, const jcharArray jArray, CK_CHAR_PTR *ckpArray, CK_ULONG_PTR ckLength);313void jCharArrayToCKUTF8CharArray(JNIEnv *env, const jcharArray jArray, CK_UTF8CHAR_PTR *ckpArray, CK_ULONG_PTR ckLength);314void jStringToCKUTF8CharArray(JNIEnv *env, const jstring jArray, CK_UTF8CHAR_PTR *ckpArray, CK_ULONG_PTR ckpLength);315void jAttributeArrayToCKAttributeArray(JNIEnv *env, jobjectArray jAArray, CK_ATTRIBUTE_PTR *ckpArray, CK_ULONG_PTR ckpLength);316/*void jObjectArrayToCKVoidPtrArray(JNIEnv *env, const jobjectArray jArray, CK_VOID_PTR_PTR ckpArray, CK_ULONG_PTR ckpLength); */317318319/* functions to convert a CK-type array and the array length to a Java array */320321jbyteArray ckByteArrayToJByteArray(JNIEnv *env, const CK_BYTE_PTR ckpArray, CK_ULONG ckLength);322jlongArray ckULongArrayToJLongArray(JNIEnv *env, const CK_ULONG_PTR ckpArray, CK_ULONG ckLength);323jcharArray ckCharArrayToJCharArray(JNIEnv *env, const CK_CHAR_PTR ckpArray, CK_ULONG length);324jcharArray ckUTF8CharArrayToJCharArray(JNIEnv *env, const CK_UTF8CHAR_PTR ckpArray, CK_ULONG ckLength);325326327/* functions to convert a CK-type structure or a pointer to a CK-value to a Java object */328329jobject ckBBoolPtrToJBooleanObject(JNIEnv *env, const CK_BBOOL* ckpValue);330jobject ckULongPtrToJLongObject(JNIEnv *env, const CK_ULONG_PTR ckpValue);331jobject ckDatePtrToJDateObject(JNIEnv *env, const CK_DATE *ckpValue);332jobject ckVersionPtrToJVersion(JNIEnv *env, const CK_VERSION_PTR ckpVersion);333jobject ckSessionInfoPtrToJSessionInfo(JNIEnv *env, const CK_SESSION_INFO_PTR ckpSessionInfo);334jobject ckAttributePtrToJAttribute(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttribute);335336337/* function to convert the CK-value used by the CK_ATTRIBUTE structure to a Java object */338339jobject ckAttributeValueToJObject(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttribute);340341342/* functions to convert a Java object to a CK-type structure or a pointer to a CK-value */343344CK_BBOOL* jBooleanObjectToCKBBoolPtr(JNIEnv *env, jobject jObject);345CK_BYTE_PTR jByteObjectToCKBytePtr(JNIEnv *env, jobject jObject);346CK_ULONG* jIntegerObjectToCKULongPtr(JNIEnv *env, jobject jObject);347CK_ULONG* jLongObjectToCKULongPtr(JNIEnv *env, jobject jObject);348CK_CHAR_PTR jCharObjectToCKCharPtr(JNIEnv *env, jobject jObject);349CK_VERSION_PTR jVersionToCKVersionPtr(JNIEnv *env, jobject jVersion);350CK_DATE * jDateObjectToCKDatePtr(JNIEnv *env, jobject jDate);351CK_ATTRIBUTE jAttributeToCKAttribute(JNIEnv *env, jobject jAttribute);352CK_MECHANISM_PTR jMechanismToCKMechanismPtr(JNIEnv *env, jobject jMechanism);353354355/* functions to convert Java objects used by the Mechanism and Attribute class to a CK-type structure */356CK_VOID_PTR jObjectToPrimitiveCKObjectPtr(JNIEnv *env, jobject jObject, CK_ULONG *ckpLength);357CK_VOID_PTR jMechParamToCKMechParamPtr(JNIEnv *env, jobject jParam, CK_MECHANISM_TYPE, CK_ULONG358*ckpLength);359360361/* functions to convert a specific Java mechanism parameter object to a CK-mechanism parameter pointer */362363CK_RSA_PKCS_OAEP_PARAMS_PTR jRsaPkcsOaepParamToCKRsaPkcsOaepParamPtr(JNIEnv *env,364jobject jParam, CK_ULONG* pLength);365CK_PBE_PARAMS_PTR jPbeParamToCKPbeParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);366CK_PKCS5_PBKD2_PARAMS_PTR jPkcs5Pbkd2ParamToCKPkcs5Pbkd2ParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);367CK_SSL3_MASTER_KEY_DERIVE_PARAMS_PTR jSsl3MasterKeyDeriveParamToCKSsl3MasterKeyDeriveParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);368CK_SSL3_KEY_MAT_PARAMS_PTR jSsl3KeyMatParamToCKSsl3KeyMatParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);369CK_KEY_DERIVATION_STRING_DATA jKeyDerivationStringDataToCKKeyDerivationStringData(JNIEnv *env, jobject jParam);370CK_RSA_PKCS_PSS_PARAMS_PTR jRsaPkcsPssParamToCKRsaPkcsPssParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);371CK_ECDH1_DERIVE_PARAMS_PTR jEcdh1DeriveParamToCKEcdh1DeriveParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);372CK_ECDH2_DERIVE_PARAMS_PTR jEcdh2DeriveParamToCKEcdh2DeriveParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);373CK_X9_42_DH1_DERIVE_PARAMS_PTR jX942Dh1DeriveParamToCKX942Dh1DeriveParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);374CK_X9_42_DH2_DERIVE_PARAMS_PTR jX942Dh2DeriveParamToCKX942Dh2DeriveParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);375376/* functions to copy the returned values inside CK-mechanism back to Java object */377378void copyBackPBEInitializationVector(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);379void copyBackSetUnwrappedKey(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);380void ssl3CopyBackClientVersion(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);381void tls12CopyBackClientVersion(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);382void ssl3CopyBackKeyMatParams(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);383void tls12CopyBackKeyMatParams(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);384385386/* functions to convert the InitArgs object for calling the right Java mutex functions */387388CK_C_INITIALIZE_ARGS_PTR makeCKInitArgsAdapter(JNIEnv *env, jobject pInitArgs);389390#ifndef NO_CALLBACKS /* if the library should not make callbacks; e.g. no javai.lib or jvm.lib available */391CK_RV callJCreateMutex(CK_VOID_PTR_PTR ppMutex);392CK_RV callJDestroyMutex(CK_VOID_PTR pMutex);393CK_RV callJLockMutex(CK_VOID_PTR pMutex);394CK_RV callJUnlockMutex(CK_VOID_PTR pMutex);395#endif /* NO_CALLBACKS */396397void putModuleEntry(JNIEnv *env, jobject pkcs11Implementation, ModuleData *moduleData);398ModuleData * removeModuleEntry(JNIEnv *env, jobject pkcs11Implementation);399CK_FUNCTION_LIST_PTR getFunctionList(JNIEnv *env, jobject pkcs11Implementation);400401/* A structure to encapsulate the required data for a Notify callback */402struct NotifyEncapsulation {403404/* The object that implements the CK_NOTIFY interface and which should be405* notified.406*/407jobject jNotifyObject;408409/* The data object to pass back to the Notify object upon callback. */410jobject jApplicationData;411};412typedef struct NotifyEncapsulation NotifyEncapsulation;413414/* The function for handling notify callbacks. */415CK_RV notifyCallback(416CK_SESSION_HANDLE hSession, /* the session's handle */417CK_NOTIFICATION event,418CK_VOID_PTR pApplication /* passed to C_OpenSession */419);420421422/* A node of the list of notify callbacks. To be able to free the resources after use. */423struct NotifyListNode {424425/* The handle of the session this notify object is attached to*/426CK_SESSION_HANDLE hSession;427428/* Reference to the Notify encapsulation object that was passed to C_OpenSession. */429NotifyEncapsulation *notifyEncapsulation;430431/* Pointer to the next node in the list. */432struct NotifyListNode *next;433434};435typedef struct NotifyListNode NotifyListNode;436437void putNotifyEntry(JNIEnv *env, CK_SESSION_HANDLE hSession, NotifyEncapsulation *notifyEncapsulation);438NotifyEncapsulation * removeNotifyEntry(JNIEnv *env, CK_SESSION_HANDLE hSession);439NotifyEncapsulation * removeFirstNotifyEntry(JNIEnv *env);440441jobject createLockObject(JNIEnv *env);442void destroyLockObject(JNIEnv *env, jobject jLockObject);443444extern jfieldID pNativeDataID;445extern jfieldID mech_mechanismID;446extern jfieldID mech_pParameterID;447extern jfieldID mech_pHandleID;448449extern jclass jByteArrayClass;450extern jclass jLongClass;451452#ifndef NO_CALLBACKS453extern NotifyListNode *notifyListHead;454extern jobject notifyListLock;455456extern jobject jInitArgsObject;457extern CK_C_INITIALIZE_ARGS_PTR ckpGlobalInitArgs;458#endif /* NO_CALLBACKS */459460#ifdef P11_MEMORYDEBUG461#include <stdlib.h>462463/* Simple malloc/calloc/free dumper */464void *p11malloc(size_t c, char *file, int line);465void *p11calloc(size_t c, size_t s, char *file, int line);466void p11free(void *p, char *file, int line);467468/* Use THIS_FILE when it is available. */469#ifndef THIS_FILE470#define THIS_FILE __FILE__471#endif472473#define malloc(c) (p11malloc((c), THIS_FILE, __LINE__))474#define calloc(c, s) (p11calloc((c), (s), THIS_FILE, __LINE__))475#define free(c) (p11free((c), THIS_FILE, __LINE__))476477#endif478479480