Path: blob/master/src/jdk.crypto.cryptoki/share/native/libj2pkcs11/pkcs11wrapper.h
41149 views
/*1* Copyright (c) 2003, 2021, 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#ifndef _PKCS11WRAPPER_H58#define _PKCS11WRAPPER_H 15960/* disable asserts in product mode */61#ifndef DEBUG62#ifndef NDEBUG63#define NDEBUG64#endif65#endif6667/* extra PKCS#11 constants not in the standard include files */6869#define CKA_NETSCAPE_BASE (0x80000000 + 0x4E534350)70#define CKA_NETSCAPE_TRUST_BASE (CKA_NETSCAPE_BASE + 0x2000)71#define CKA_NETSCAPE_TRUST_SERVER_AUTH (CKA_NETSCAPE_TRUST_BASE + 8)72#define CKA_NETSCAPE_TRUST_CLIENT_AUTH (CKA_NETSCAPE_TRUST_BASE + 9)73#define CKA_NETSCAPE_TRUST_CODE_SIGNING (CKA_NETSCAPE_TRUST_BASE + 10)74#define CKA_NETSCAPE_TRUST_EMAIL_PROTECTION (CKA_NETSCAPE_TRUST_BASE + 11)75#define CKA_NETSCAPE_DB 0xD5A0DB0076#define CKM_NSS_TLS_PRF_GENERAL 0x800003737778/*7980Define the PKCS#11 functions to include and exclude. Reduces the size81of the binary somewhat.8283This list needs to be kept in sync with the mapfile and PKCS11.java8485*/8687#define P11_ENABLE_C_INITIALIZE88#define P11_ENABLE_C_FINALIZE89#define P11_ENABLE_C_GETINFO90#define P11_ENABLE_C_GETSLOTLIST91#define P11_ENABLE_C_GETSLOTINFO92#define P11_ENABLE_C_GETTOKENINFO93#define P11_ENABLE_C_GETMECHANISMLIST94#define P11_ENABLE_C_GETMECHANISMINFO95#undef P11_ENABLE_C_INITTOKEN96#undef P11_ENABLE_C_INITPIN97#undef P11_ENABLE_C_SETPIN98#define P11_ENABLE_C_OPENSESSION99#define P11_ENABLE_C_CLOSESESSION100#undef P11_ENABLE_C_CLOSEALLSESSIONS101#define P11_ENABLE_C_GETSESSIONINFO102#define P11_ENABLE_C_GETOPERATIONSTATE103#define P11_ENABLE_C_SETOPERATIONSTATE104#define P11_ENABLE_C_LOGIN105#define P11_ENABLE_C_LOGOUT106#define P11_ENABLE_C_CREATEOBJECT107#define P11_ENABLE_C_COPYOBJECT108#define P11_ENABLE_C_DESTROYOBJECT109#undef P11_ENABLE_C_GETOBJECTSIZE110#define P11_ENABLE_C_GETATTRIBUTEVALUE111#define P11_ENABLE_C_SETATTRIBUTEVALUE112#define P11_ENABLE_C_FINDOBJECTSINIT113#define P11_ENABLE_C_FINDOBJECTS114#define P11_ENABLE_C_FINDOBJECTSFINAL115#define P11_ENABLE_C_ENCRYPTINIT116#define P11_ENABLE_C_ENCRYPT117#define P11_ENABLE_C_ENCRYPTUPDATE118#define P11_ENABLE_C_ENCRYPTFINAL119#define P11_ENABLE_C_DECRYPTINIT120#define P11_ENABLE_C_DECRYPT121#define P11_ENABLE_C_DECRYPTUPDATE122#define P11_ENABLE_C_DECRYPTFINAL123#define P11_ENABLE_C_DIGESTINIT124#define P11_ENABLE_C_DIGEST125#define P11_ENABLE_C_DIGESTUPDATE126#define P11_ENABLE_C_DIGESTKEY127#define P11_ENABLE_C_DIGESTFINAL128#define P11_ENABLE_C_SIGNINIT129#define P11_ENABLE_C_SIGN130#define P11_ENABLE_C_SIGNUPDATE131#define P11_ENABLE_C_SIGNFINAL132#define P11_ENABLE_C_SIGNRECOVERINIT133#define P11_ENABLE_C_SIGNRECOVER134#define P11_ENABLE_C_VERIFYINIT135#define P11_ENABLE_C_VERIFY136#define P11_ENABLE_C_VERIFYUPDATE137#define P11_ENABLE_C_VERIFYFINAL138#define P11_ENABLE_C_VERIFYRECOVERINIT139#define P11_ENABLE_C_VERIFYRECOVER140#undef P11_ENABLE_C_DIGESTENCRYPTUPDATE141#undef P11_ENABLE_C_DECRYPTDIGESTUPDATE142#undef P11_ENABLE_C_SIGNENCRYPTUPDATE143#undef P11_ENABLE_C_DECRYPTVERIFYUPDATE144#define P11_ENABLE_C_GENERATEKEY145#define P11_ENABLE_C_GENERATEKEYPAIR146#define P11_ENABLE_C_WRAPKEY147#define P11_ENABLE_C_UNWRAPKEY148#define P11_ENABLE_C_DERIVEKEY149#define P11_ENABLE_C_SEEDRANDOM150#define P11_ENABLE_C_GENERATERANDOM151#undef P11_ENABLE_C_GETFUNCTIONSTATUS152#undef P11_ENABLE_C_CANCELFUNCTION153#undef P11_ENABLE_C_WAITFORSLOTEVENT154#define P11_ENABLE_GETNATIVEKEYINFO155#define P11_ENABLE_CREATENATIVEKEY156157158/* include the platform dependent part of the header */159#include "p11_md.h"160161#include <jni.h>162#include <jni_util.h>163#include <stdarg.h>164165#define MAX_STACK_BUFFER_LEN (4 * 1024)166#define MAX_HEAP_BUFFER_LEN (64 * 1024)167168#define MAX_DIGEST_LEN (64)169170#ifndef min171#define min(a, b) (((a) < (b)) ? (a) : (b))172#endif173174#define ckBBoolToJBoolean(x) ((x == TRUE) ? JNI_TRUE : JNI_FALSE);175#define jBooleanToCKBBool(x) ((x == JNI_TRUE) ? TRUE : FALSE);176177#define ckByteToJByte(x) ((jbyte) x)178#define jByteToCKByte(x) ((CK_BYTE) x)179180#define ckLongToJLong(x) ((jlong) x)181#define jLongToCKLong(x) ((CK_LONG) x)182183#define ckULongToJLong(x) ((jlong) x)184#define jLongToCKULong(x) ((CK_ULONG) x)185186// For CK_UNAVAILABLE_INFORMATION, always return -1 to avoid 32/64 bit problems.187#define ckULongSpecialToJLong(x) (((x) == CK_UNAVAILABLE_INFORMATION) \188? (jlong)-1 : ((jlong) x))189190#define ckCharToJChar(x) ((jchar) x)191#define jCharToCKChar(x) ((CK_CHAR) x)192193#define ckUTF8CharToJChar(x) ((jchar) x)194#define jCharToCKUTF8Char(x) ((CK_UTF8CHAR) x)195196#define ckFlageToJLong(x) ((jlong) x)197198#define ckVoidPtrToJObject(x) ((jobject) x)199#define jObjectToCKVoidPtr(x) ((CK_VOID_PTR) x)200201#define jIntToCKLong(x) ((CK_LONG) x)202#define jIntToCKULong(x) ((CK_ULONG) x)203#define ckLongToJInt(x) ((jint) x)204#define ckULongToJInt(x) ((jint) x)205#define ckULongToJSize(x) ((jsize) x)206#define unsignedIntToCKULong(x) ((CK_ULONG) x)207208//#define TRACE0d(s) { printf(s); fflush(stdout); }209//#define TRACE1d(s, p1) { printf(s, p1); fflush(stdout); }210//#define TRACE2d(s, p1, p2) { printf(s, p1, p2); fflush(stdout); }211212#ifdef P11_DEBUG213#define TRACE0(s) { printf(s); fflush(stdout); }214#define TRACE1(s, p1) { printf(s, p1); fflush(stdout); }215#define TRACE2(s, p1, p2) { printf(s, p1, p2); fflush(stdout); }216#define TRACE3(s, p1, p2, p3) { printf(s, p1, p2, p3); fflush(stdout); }217#else218#define TRACE0(s)219#define TRACE1(s, p1)220#define TRACE2(s, p1, p2)221#define TRACE3(s, p1, p2, p3)222#define TRACE_INTEND223#define TRACE_UNINTEND224#endif225226/* debug output */227extern jboolean debug;228void printDebug(const char *format, ...);229230#define CK_ASSERT_OK 0L231232#define CLASS_P11PSSSIGNATURE "sun/security/pkcs11/P11PSSSignature"233234#define CLASS_INFO "sun/security/pkcs11/wrapper/CK_INFO"235#define CLASS_VERSION "sun/security/pkcs11/wrapper/CK_VERSION"236#define CLASS_SLOT_INFO "sun/security/pkcs11/wrapper/CK_SLOT_INFO"237#define CLASS_TOKEN_INFO "sun/security/pkcs11/wrapper/CK_TOKEN_INFO"238#define CLASS_MECHANISM "sun/security/pkcs11/wrapper/CK_MECHANISM"239#define CLASS_MECHANISM_INFO "sun/security/pkcs11/wrapper/CK_MECHANISM_INFO"240#define CLASS_SESSION_INFO "sun/security/pkcs11/wrapper/CK_SESSION_INFO"241#define CLASS_ATTRIBUTE "sun/security/pkcs11/wrapper/CK_ATTRIBUTE"242#define CLASS_DATE "sun/security/pkcs11/wrapper/CK_DATE"243#define CLASS_PKCS11EXCEPTION "sun/security/pkcs11/wrapper/PKCS11Exception"244#define CLASS_PKCS11RUNTIMEEXCEPTION "sun/security/pkcs11/wrapper/PKCS11RuntimeException"245#define CLASS_FILE_NOT_FOUND_EXCEPTION "java/io/FileNotFoundException"246#define CLASS_C_INITIALIZE_ARGS "sun/security/pkcs11/wrapper/CK_C_INITIALIZE_ARGS"247#define CLASS_CREATEMUTEX "sun/security/pkcs11/wrapper/CK_CREATEMUTEX"248#define CLASS_DESTROYMUTEX "sun/security/pkcs11/wrapper/CK_DESTROYMUTEX"249#define CLASS_LOCKMUTEX "sun/security/pkcs11/wrapper/CK_LOCKMUTEX"250#define CLASS_UNLOCKMUTEX "sun/security/pkcs11/wrapper/CK_UNLOCKMUTEX"251#define CLASS_NOTIFY "sun/security/pkcs11/wrapper/CK_NOTIFY"252253254/* mechanism parameter classes */255#define CLASS_AES_CTR_PARAMS "sun/security/pkcs11/wrapper/CK_AES_CTR_PARAMS"256#define CLASS_GCM_PARAMS "sun/security/pkcs11/wrapper/CK_GCM_PARAMS"257#define CLASS_CCM_PARAMS "sun/security/pkcs11/wrapper/CK_CCM_PARAMS"258#define CLASS_SALSA20_CHACHA20_POLY1305_PARAMS \259"sun/security/pkcs11/wrapper/CK_SALSA20_CHACHA20_POLY1305_PARAMS"260#define CLASS_RSA_PKCS_PSS_PARAMS "sun/security/pkcs11/wrapper/CK_RSA_PKCS_PSS_PARAMS"261#define CLASS_RSA_PKCS_OAEP_PARAMS "sun/security/pkcs11/wrapper/CK_RSA_PKCS_OAEP_PARAMS"262263#define CLASS_MAC_GENERAL_PARAMS "sun/security/pkcs11/wrapper/CK_MAC_GENERAL_PARAMS"264#define CLASS_PBE_PARAMS "sun/security/pkcs11/wrapper/CK_PBE_PARAMS"265#define PBE_INIT_VECTOR_SIZE 8266#define CLASS_PKCS5_PBKD2_PARAMS "sun/security/pkcs11/wrapper/CK_PKCS5_PBKD2_PARAMS"267#define CLASS_EXTRACT_PARAMS "sun/security/pkcs11/wrapper/CK_EXTRACT_PARAMS"268269#define CLASS_ECDH1_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_ECDH1_DERIVE_PARAMS"270#define CLASS_ECDH2_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_ECDH2_DERIVE_PARAMS"271#define CLASS_X9_42_DH1_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_X9_42_DH1_DERIVE_PARAMS"272#define CLASS_X9_42_DH2_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_X9_42_DH2_DERIVE_PARAMS"273274/*275#define CLASS_KEA_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_KEA_DERIVE_PARAMS"276#define CLASS_RC2_PARAMS "sun/security/pkcs11/wrapper/CK_RC2_PARAMS"277#define CLASS_RC2_CBC_PARAMS "sun/security/pkcs11/wrapper/CK_RC2_CBC_PARAMS"278#define CLASS_RC2_MAC_GENERAL_PARAMS "sun/security/pkcs11/wrapper/CK_RC2_MAC_GENERAL_PARAMS"279#define CLASS_RC5_PARAMS "sun/security/pkcs11/wrapper/CK_RC5_PARAMS"280#define CLASS_RC5_CBC_PARAMS "sun/security/pkcs11/wrapper/CK_RC5_CBC_PARAMS"281#define CLASS_RC5_MAC_GENERAL_PARAMS "sun/security/pkcs11/wrapper/CK_RC5_MAC_GENERAL_PARAMS"282#define CLASS_SKIPJACK_PRIVATE_WRAP_PARAMS "sun/security/pkcs11/wrapper/CK_SKIPJACK_PRIVATE_WRAP_PARAMS"283#define CLASS_SKIPJACK_RELAYX_PARAMS "sun/security/pkcs11/wrapper/CK_SKIPJACK_RELAYX_PARAMS"284#define CLASS_KEY_WRAP_SET_OAEP_PARAMS "sun/security/pkcs11/wrapper/CK_KEY_WRAP_SET_OAEP_PARAMS"285#define CLASS_KEY_DERIVATION_STRING_DATA "sun/security/pkcs11/wrapper/CK_KEY_DERIVATION_STRING_DATA"286*/287288#define CLASS_SSL3_RANDOM_DATA "sun/security/pkcs11/wrapper/CK_SSL3_RANDOM_DATA"289// CLASS_SSL3_RANDOM_DATA is used by CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS290#define CLASS_SSL3_KEY_MAT_OUT "sun/security/pkcs11/wrapper/CK_SSL3_KEY_MAT_OUT"291// CLASS_SSL3_KEY_MAT_OUT is used by CLASS_SSL3_KEY_MAT_PARAMS and CK_TLS12_KEY_MAT_PARAMS292#define CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_SSL3_MASTER_KEY_DERIVE_PARAMS"293#define CLASS_TLS12_MASTER_KEY_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_TLS12_MASTER_KEY_DERIVE_PARAMS"294#define CLASS_SSL3_KEY_MAT_PARAMS "sun/security/pkcs11/wrapper/CK_SSL3_KEY_MAT_PARAMS"295#define CLASS_TLS12_KEY_MAT_PARAMS "sun/security/pkcs11/wrapper/CK_TLS12_KEY_MAT_PARAMS"296#define CLASS_TLS_PRF_PARAMS "sun/security/pkcs11/wrapper/CK_TLS_PRF_PARAMS"297#define CLASS_TLS_MAC_PARAMS "sun/security/pkcs11/wrapper/CK_TLS_MAC_PARAMS"298299/* function to update the CK_NSS_GCM_PARAMS in mechanism pointer with300* CK_GCM_PARAMS301*/302CK_MECHANISM_PTR updateGCMParams(JNIEnv *env, CK_MECHANISM_PTR mechPtr);303304/* function to convert a PKCS#11 return value other than CK_OK into a Java Exception305* or to throw a PKCS11RuntimeException306*/307308jlong ckAssertReturnValueOK(JNIEnv *env, CK_RV returnValue);309jlong ckAssertReturnValueOK2(JNIEnv *env, CK_RV returnValue, const char *msg);310void throwOutOfMemoryError(JNIEnv *env, const char *message);311void throwNullPointerException(JNIEnv *env, const char *message);312void throwIOException(JNIEnv *env, const char *message);313void throwPKCS11RuntimeException(JNIEnv *env, const char *message);314void throwDisconnectedRuntimeException(JNIEnv *env);315316/* functions to free CK structures and pointers317*/318void freeCKAttributeArray(CK_ATTRIBUTE_PTR attrPtr, int len);319void freeCKMechanismPtr(CK_MECHANISM_PTR mechPtr);320321/* functions to convert Java arrays to a CK-type array and the array length */322323void jBooleanArrayToCKBBoolArray(JNIEnv *env, const jbooleanArray jArray, CK_BBOOL **ckpArray, CK_ULONG_PTR ckLength);324void jByteArrayToCKByteArray(JNIEnv *env, const jbyteArray jArray, CK_BYTE_PTR *ckpArray, CK_ULONG_PTR ckLength);325void jLongArrayToCKULongArray(JNIEnv *env, const jlongArray jArray, CK_ULONG_PTR *ckpArray, CK_ULONG_PTR ckLength);326void jCharArrayToCKCharArray(JNIEnv *env, const jcharArray jArray, CK_CHAR_PTR *ckpArray, CK_ULONG_PTR ckLength);327void jCharArrayToCKUTF8CharArray(JNIEnv *env, const jcharArray jArray, CK_UTF8CHAR_PTR *ckpArray, CK_ULONG_PTR ckLength);328void jStringToCKUTF8CharArray(JNIEnv *env, const jstring jArray, CK_UTF8CHAR_PTR *ckpArray, CK_ULONG_PTR ckpLength);329void jAttributeArrayToCKAttributeArray(JNIEnv *env, jobjectArray jAArray, CK_ATTRIBUTE_PTR *ckpArray, CK_ULONG_PTR ckpLength);330/*void jObjectArrayToCKVoidPtrArray(JNIEnv *env, const jobjectArray jArray, CK_VOID_PTR_PTR ckpArray, CK_ULONG_PTR ckpLength); */331332333/* functions to convert a CK-type array and the array length to a Java array */334335jbyteArray ckByteArrayToJByteArray(JNIEnv *env, const CK_BYTE_PTR ckpArray, CK_ULONG ckLength);336jlongArray ckULongArrayToJLongArray(JNIEnv *env, const CK_ULONG_PTR ckpArray, CK_ULONG ckLength);337jcharArray ckCharArrayToJCharArray(JNIEnv *env, const CK_CHAR_PTR ckpArray, CK_ULONG length);338jcharArray ckUTF8CharArrayToJCharArray(JNIEnv *env, const CK_UTF8CHAR_PTR ckpArray, CK_ULONG ckLength);339340341/* functions to convert a CK-type structure or a pointer to a CK-value to a Java object */342343jobject ckBBoolPtrToJBooleanObject(JNIEnv *env, const CK_BBOOL* ckpValue);344jobject ckULongPtrToJLongObject(JNIEnv *env, const CK_ULONG_PTR ckpValue);345jobject ckDatePtrToJDateObject(JNIEnv *env, const CK_DATE *ckpValue);346jobject ckVersionPtrToJVersion(JNIEnv *env, const CK_VERSION_PTR ckpVersion);347jobject ckSessionInfoPtrToJSessionInfo(JNIEnv *env, const CK_SESSION_INFO_PTR ckpSessionInfo);348jobject ckAttributePtrToJAttribute(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttribute);349350351/* function to convert the CK-value used by the CK_ATTRIBUTE structure to a Java object */352353jobject ckAttributeValueToJObject(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttribute);354355356/* functions to convert a Java object to a CK-type structure or a pointer to a CK-value */357358CK_BBOOL* jBooleanObjectToCKBBoolPtr(JNIEnv *env, jobject jObject);359CK_BYTE_PTR jByteObjectToCKBytePtr(JNIEnv *env, jobject jObject);360CK_ULONG* jIntegerObjectToCKULongPtr(JNIEnv *env, jobject jObject);361CK_ULONG* jLongObjectToCKULongPtr(JNIEnv *env, jobject jObject);362CK_CHAR_PTR jCharObjectToCKCharPtr(JNIEnv *env, jobject jObject);363CK_VERSION_PTR jVersionToCKVersionPtr(JNIEnv *env, jobject jVersion);364CK_DATE * jDateObjectToCKDatePtr(JNIEnv *env, jobject jDate);365CK_ATTRIBUTE jAttributeToCKAttribute(JNIEnv *env, jobject jAttribute);366CK_MECHANISM_PTR jMechanismToCKMechanismPtr(JNIEnv *env, jobject jMechanism);367368369/* functions to convert Java objects used by the Mechanism and Attribute class to a CK-type structure */370CK_VOID_PTR jObjectToPrimitiveCKObjectPtr(JNIEnv *env, jobject jObject, CK_ULONG *ckpLength);371CK_VOID_PTR jMechParamToCKMechParamPtr(JNIEnv *env, jobject jParam, CK_MECHANISM_TYPE, CK_ULONG372*ckpLength);373374375/* functions to convert a specific Java mechanism parameter object to a CK-mechanism parameter pointer */376377CK_RSA_PKCS_OAEP_PARAMS_PTR jRsaPkcsOaepParamToCKRsaPkcsOaepParamPtr(JNIEnv *env,378jobject jParam, CK_ULONG* pLength);379CK_PBE_PARAMS_PTR jPbeParamToCKPbeParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);380CK_PKCS5_PBKD2_PARAMS_PTR jPkcs5Pbkd2ParamToCKPkcs5Pbkd2ParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);381CK_SSL3_MASTER_KEY_DERIVE_PARAMS_PTR jSsl3MasterKeyDeriveParamToCKSsl3MasterKeyDeriveParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);382CK_SSL3_KEY_MAT_PARAMS_PTR jSsl3KeyMatParamToCKSsl3KeyMatParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);383CK_KEY_DERIVATION_STRING_DATA jKeyDerivationStringDataToCKKeyDerivationStringData(JNIEnv *env, jobject jParam);384CK_RSA_PKCS_PSS_PARAMS_PTR jRsaPkcsPssParamToCKRsaPkcsPssParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);385CK_ECDH1_DERIVE_PARAMS_PTR jEcdh1DeriveParamToCKEcdh1DeriveParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);386CK_ECDH2_DERIVE_PARAMS_PTR jEcdh2DeriveParamToCKEcdh2DeriveParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);387CK_X9_42_DH1_DERIVE_PARAMS_PTR jX942Dh1DeriveParamToCKX942Dh1DeriveParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);388CK_X9_42_DH2_DERIVE_PARAMS_PTR jX942Dh2DeriveParamToCKX942Dh2DeriveParamPtr(JNIEnv *env, jobject jParam, CK_ULONG* pLength);389390/* functions to copy the returned values inside CK-mechanism back to Java object */391392void copyBackPBEInitializationVector(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);393void copyBackSetUnwrappedKey(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);394void ssl3CopyBackClientVersion(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);395void tls12CopyBackClientVersion(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);396void ssl3CopyBackKeyMatParams(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);397void tls12CopyBackKeyMatParams(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism);398399400/* functions to convert the InitArgs object for calling the right Java mutex functions */401402CK_C_INITIALIZE_ARGS_PTR makeCKInitArgsAdapter(JNIEnv *env, jobject pInitArgs);403404#ifndef NO_CALLBACKS /* if the library should not make callbacks; e.g. no javai.lib or jvm.lib available */405CK_RV callJCreateMutex(CK_VOID_PTR_PTR ppMutex);406CK_RV callJDestroyMutex(CK_VOID_PTR pMutex);407CK_RV callJLockMutex(CK_VOID_PTR pMutex);408CK_RV callJUnlockMutex(CK_VOID_PTR pMutex);409#endif /* NO_CALLBACKS */410411void putModuleEntry(JNIEnv *env, jobject pkcs11Implementation, ModuleData *moduleData);412ModuleData * removeModuleEntry(JNIEnv *env, jobject pkcs11Implementation);413CK_FUNCTION_LIST_PTR getFunctionList(JNIEnv *env, jobject pkcs11Implementation);414415/* A structure to encapsulate the required data for a Notify callback */416struct NotifyEncapsulation {417418/* The object that implements the CK_NOTIFY interface and which should be419* notified.420*/421jobject jNotifyObject;422423/* The data object to pass back to the Notify object upon callback. */424jobject jApplicationData;425};426typedef struct NotifyEncapsulation NotifyEncapsulation;427428/* The function for handling notify callbacks. */429CK_RV notifyCallback(430CK_SESSION_HANDLE hSession, /* the session's handle */431CK_NOTIFICATION event,432CK_VOID_PTR pApplication /* passed to C_OpenSession */433);434435436/* A node of the list of notify callbacks. To be able to free the resources after use. */437struct NotifyListNode {438439/* The handle of the session this notify object is attached to*/440CK_SESSION_HANDLE hSession;441442/* Reference to the Notify encapsulation object that was passed to C_OpenSession. */443NotifyEncapsulation *notifyEncapsulation;444445/* Pointer to the next node in the list. */446struct NotifyListNode *next;447448};449typedef struct NotifyListNode NotifyListNode;450451void putNotifyEntry(JNIEnv *env, CK_SESSION_HANDLE hSession, NotifyEncapsulation *notifyEncapsulation);452NotifyEncapsulation * removeNotifyEntry(JNIEnv *env, CK_SESSION_HANDLE hSession);453NotifyEncapsulation * removeFirstNotifyEntry(JNIEnv *env);454455jobject createLockObject(JNIEnv *env);456void destroyLockObject(JNIEnv *env, jobject jLockObject);457458extern jfieldID pNativeDataID;459extern jfieldID mech_mechanismID;460extern jfieldID mech_pParameterID;461extern jfieldID mech_pHandleID;462463extern jclass jByteArrayClass;464extern jclass jLongClass;465466#ifndef NO_CALLBACKS467extern NotifyListNode *notifyListHead;468extern jobject notifyListLock;469470extern jobject jInitArgsObject;471extern CK_C_INITIALIZE_ARGS_PTR ckpGlobalInitArgs;472#endif /* NO_CALLBACKS */473474#ifdef P11_MEMORYDEBUG475#include <stdlib.h>476477/* Simple malloc/calloc/free dumper */478void *p11malloc(size_t c, char *file, int line);479void *p11calloc(size_t c, size_t s, char *file, int line);480void p11free(void *p, char *file, int line);481482#define malloc(c) (p11malloc((c), __FILE__, __LINE__))483#define calloc(c, s) (p11calloc((c), (s), __FILE__, __LINE__))484#define free(c) (p11free((c), __FILE__, __LINE__))485486#endif487488#endif /* _PKCS11WRAPPER_H */489490491