andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: /* andre@0: * Copyright (C) 1994-1999 RSA Security Inc. Licence to copy this document andre@0: * is granted provided that it is identified as "RSA Security In.c Public-Key andre@0: * Cryptography Standards (PKCS)" in all material mentioning or referencing andre@0: * this document. andre@0: * andre@0: * The latest version of this header can be found at: andre@0: * http://www.rsalabs.com/pkcs/pkcs-11/index.html andre@0: */ andre@0: #ifndef _PKCS11_H_ andre@0: #define _PKCS11_H_ 1 andre@0: andre@0: #ifdef __cplusplus andre@0: extern "C" { andre@0: #endif andre@0: andre@0: /* Before including this file (pkcs11.h) (or pkcs11t.h by andre@0: * itself), 6 platform-specific macros must be defined. These andre@0: * macros are described below, and typical definitions for them andre@0: * are also given. Be advised that these definitions can depend andre@0: * on both the platform and the compiler used (and possibly also andre@0: * on whether a PKCS #11 library is linked statically or andre@0: * dynamically). andre@0: * andre@0: * In addition to defining these 6 macros, the packing convention andre@0: * for PKCS #11 structures should be set. The PKCS #11 andre@0: * convention on packing is that structures should be 1-byte andre@0: * aligned. andre@0: * andre@0: * In a Win32 environment, this might be done by using the andre@0: * following preprocessor directive before including pkcs11.h andre@0: * or pkcs11t.h: andre@0: * andre@0: * #pragma pack(push, cryptoki, 1) andre@0: * andre@0: * and using the following preprocessor directive after including andre@0: * pkcs11.h or pkcs11t.h: andre@0: * andre@0: * #pragma pack(pop, cryptoki) andre@0: * andre@0: * In a UNIX environment, you're on your own here. You might andre@0: * not need to do anything. andre@0: * andre@0: * andre@0: * Now for the macros: andre@0: * andre@0: * andre@0: * 1. CK_PTR: The indirection string for making a pointer to an andre@0: * object. It can be used like this: andre@0: * andre@0: * typedef CK_BYTE CK_PTR CK_BYTE_PTR; andre@0: * andre@0: * In a Win32 environment, it might be defined by andre@0: * andre@0: * #define CK_PTR * andre@0: * andre@0: * In a UNIX environment, it might be defined by andre@0: * andre@0: * #define CK_PTR * andre@0: * andre@0: * andre@0: * 2. CK_DEFINE_FUNCTION(returnType, name): A macro which makes andre@0: * an exportable PKCS #11 library function definition out of a andre@0: * return type and a function name. It should be used in the andre@0: * following fashion to define the exposed PKCS #11 functions in andre@0: * a PKCS #11 library: andre@0: * andre@0: * CK_DEFINE_FUNCTION(CK_RV, C_Initialize)( andre@0: * CK_VOID_PTR pReserved andre@0: * ) andre@0: * { andre@0: * ... andre@0: * } andre@0: * andre@0: * For defining a function in a Win32 PKCS #11 .dll, it might be andre@0: * defined by andre@0: * andre@0: * #define CK_DEFINE_FUNCTION(returnType, name) \ andre@0: * returnType __declspec(dllexport) name andre@0: * andre@0: * In a UNIX environment, it might be defined by andre@0: * andre@0: * #define CK_DEFINE_FUNCTION(returnType, name) \ andre@0: * returnType name andre@0: * andre@0: * andre@0: * 3. CK_DECLARE_FUNCTION(returnType, name): A macro which makes andre@0: * an importable PKCS #11 library function declaration out of a andre@0: * return type and a function name. It should be used in the andre@0: * following fashion: andre@0: * andre@0: * extern CK_DECLARE_FUNCTION(CK_RV, C_Initialize)( andre@0: * CK_VOID_PTR pReserved andre@0: * ); andre@0: * andre@0: * For declaring a function in a Win32 PKCS #11 .dll, it might andre@0: * be defined by andre@0: * andre@0: * #define CK_DECLARE_FUNCTION(returnType, name) \ andre@0: * returnType __declspec(dllimport) name andre@0: * andre@0: * In a UNIX environment, it might be defined by andre@0: * andre@0: * #define CK_DECLARE_FUNCTION(returnType, name) \ andre@0: * returnType name andre@0: * andre@0: * andre@0: * 4. CK_DECLARE_FUNCTION_POINTER(returnType, name): A macro andre@0: * which makes a PKCS #11 API function pointer declaration or andre@0: * function pointer type declaration out of a return type and a andre@0: * function name. It should be used in the following fashion: andre@0: * andre@0: * // Define funcPtr to be a pointer to a PKCS #11 API function andre@0: * // taking arguments args and returning CK_RV. andre@0: * CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtr)(args); andre@0: * andre@0: * or andre@0: * andre@0: * // Define funcPtrType to be the type of a pointer to a andre@0: * // PKCS #11 API function taking arguments args and returning andre@0: * // CK_RV, and then define funcPtr to be a variable of type andre@0: * // funcPtrType. andre@0: * typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtrType)(args); andre@0: * funcPtrType funcPtr; andre@0: * andre@0: * For accessing functions in a Win32 PKCS #11 .dll, in might be andre@0: * defined by andre@0: * andre@0: * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \ andre@0: * returnType __declspec(dllimport) (* name) andre@0: * andre@0: * In a UNIX environment, it might be defined by andre@0: * andre@0: * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \ andre@0: * returnType (* name) andre@0: * andre@0: * andre@0: * 5. CK_CALLBACK_FUNCTION(returnType, name): A macro which makes andre@0: * a function pointer type for an application callback out of andre@0: * a return type for the callback and a name for the callback. andre@0: * It should be used in the following fashion: andre@0: * andre@0: * CK_CALLBACK_FUNCTION(CK_RV, myCallback)(args); andre@0: * andre@0: * to declare a function pointer, myCallback, to a callback andre@0: * which takes arguments args and returns a CK_RV. It can also andre@0: * be used like this: andre@0: * andre@0: * typedef CK_CALLBACK_FUNCTION(CK_RV, myCallbackType)(args); andre@0: * myCallbackType myCallback; andre@0: * andre@0: * In a Win32 environment, it might be defined by andre@0: * andre@0: * #define CK_CALLBACK_FUNCTION(returnType, name) \ andre@0: * returnType (* name) andre@0: * andre@0: * In a UNIX environment, it might be defined by andre@0: * andre@0: * #define CK_CALLBACK_FUNCTION(returnType, name) \ andre@0: * returnType (* name) andre@0: * andre@0: * andre@0: * 6. NULL_PTR: This macro is the value of a NULL pointer. andre@0: * andre@0: * In any ANSI/ISO C environment (and in many others as well), andre@0: * this should be defined by andre@0: * andre@0: * #ifndef NULL_PTR andre@0: * #define NULL_PTR 0 andre@0: * #endif andre@0: */ andre@0: andre@0: andre@0: /* All the various PKCS #11 types and #define'd values are in the andre@0: * file pkcs11t.h. */ andre@0: #include "pkcs11t.h" andre@0: andre@0: #define __PASTE(x,y) x##y andre@0: andre@0: andre@0: /* packing defines */ andre@0: #include "pkcs11p.h" andre@0: /* ============================================================== andre@0: * Define the "extern" form of all the entry points. andre@0: * ============================================================== andre@0: */ andre@0: andre@0: #define CK_NEED_ARG_LIST 1 andre@0: #define CK_PKCS11_FUNCTION_INFO(name) \ andre@0: CK_DECLARE_FUNCTION(CK_RV, name) andre@0: andre@0: /* pkcs11f.h has all the information about the PKCS #11 andre@0: * function prototypes. */ andre@0: #include "pkcs11f.h" andre@0: andre@0: #undef CK_NEED_ARG_LIST andre@0: #undef CK_PKCS11_FUNCTION_INFO andre@0: andre@0: andre@0: /* ============================================================== andre@0: * Define the typedef form of all the entry points. That is, for andre@0: * each PKCS #11 function C_XXX, define a type CK_C_XXX which is andre@0: * a pointer to that kind of function. andre@0: * ============================================================== andre@0: */ andre@0: andre@0: #define CK_NEED_ARG_LIST 1 andre@0: #define CK_PKCS11_FUNCTION_INFO(name) \ andre@0: typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, __PASTE(CK_,name)) andre@0: andre@0: /* pkcs11f.h has all the information about the PKCS #11 andre@0: * function prototypes. */ andre@0: #include "pkcs11f.h" andre@0: andre@0: #undef CK_NEED_ARG_LIST andre@0: #undef CK_PKCS11_FUNCTION_INFO andre@0: andre@0: andre@0: /* ============================================================== andre@0: * Define structed vector of entry points. A CK_FUNCTION_LIST andre@0: * contains a CK_VERSION indicating a library's PKCS #11 version andre@0: * and then a whole slew of function pointers to the routines in andre@0: * the library. This type was declared, but not defined, in andre@0: * pkcs11t.h. andre@0: * ============================================================== andre@0: */ andre@0: andre@0: #define CK_PKCS11_FUNCTION_INFO(name) \ andre@0: __PASTE(CK_,name) name; andre@0: andre@0: struct CK_FUNCTION_LIST { andre@0: andre@0: CK_VERSION version; /* PKCS #11 version */ andre@0: andre@0: /* Pile all the function pointers into the CK_FUNCTION_LIST. */ andre@0: /* pkcs11f.h has all the information about the PKCS #11 andre@0: * function prototypes. */ andre@0: #include "pkcs11f.h" andre@0: andre@0: }; andre@0: andre@0: #undef CK_PKCS11_FUNCTION_INFO andre@0: andre@0: andre@0: #undef __PASTE andre@0: andre@0: /* unpack */ andre@0: #include "pkcs11u.h" andre@0: andre@0: #ifdef __cplusplus andre@0: } andre@0: #endif andre@0: andre@0: #endif