Path: blob/master/src/jdk.crypto.cryptoki/share/native/libj2pkcs11/pkcs11.h
41152 views
/* Copyright (c) OASIS Open 2016-2019. All Rights Reserved.1* Distributed under the terms of the OASIS IPR Policy,2* [http://www.oasis-open.org/policies-guidelines/ipr], AS-IS, WITHOUT ANY3* IMPLIED OR EXPRESS WARRANTY; there is no warranty of MERCHANTABILITY, FITNESS FOR A4* PARTICULAR PURPOSE or NONINFRINGEMENT of the rights of others.5*/67#ifndef _PKCS11_H_8#define _PKCS11_H_ 1910#ifdef __cplusplus11extern "C" {12#endif1314/* Before including this file (pkcs11.h) (or pkcs11t.h by15* itself), 5 platform-specific macros must be defined. These16* macros are described below, and typical definitions for them17* are also given. Be advised that these definitions can depend18* on both the platform and the compiler used (and possibly also19* on whether a Cryptoki library is linked statically or20* dynamically).21*22* In addition to defining these 5 macros, the packing convention23* for Cryptoki structures should be set. The Cryptoki24* convention on packing is that structures should be 1-byte25* aligned.26*27* If you're using Windows this might be done by using the following28* preprocessor directive before including pkcs11.h or pkcs11t.h:29*30* #pragma pack(push, cryptoki, 1)31*32* and using the following preprocessor directive after including33* pkcs11.h or pkcs11t.h:34*35* #pragma pack(pop, cryptoki)36*37* In a UNIX environment, you're on your own for this. You might38* not need to do (or be able to do!) anything.39*40*41* Now for the macros:42*43*44* 1. CK_PTR: The indirection string for making a pointer to an45* object. It can be used like this:46*47* typedef CK_BYTE CK_PTR CK_BYTE_PTR;48*49* If you're using windows, it might be defined by:50*51* #define CK_PTR *52*53* In a typical UNIX environment, it might be defined by:54*55* #define CK_PTR *56*57*58* 2. CK_DECLARE_FUNCTION(returnType, name): A macro which makes59* an importable Cryptoki library function declaration out of a60* return type and a function name. It should be used in the61* following fashion:62*63* extern CK_DECLARE_FUNCTION(CK_RV, C_Initialize)(64* CK_VOID_PTR pReserved65* );66*67* If you're using Windows to declare a function in a Win32 cryptoki .dll,68* it might be defined by:69*70* #define CK_DECLARE_FUNCTION(returnType, name) \71* returnType __declspec(dllimport) name72*73* In a UNIX environment, it might be defined by:74*75* #define CK_DECLARE_FUNCTION(returnType, name) \76* returnType name77*78*79* 3. CK_DECLARE_FUNCTION_POINTER(returnType, name): A macro80* which makes a Cryptoki API function pointer declaration or81* function pointer type declaration out of a return type and a82* function name. It should be used in the following fashion:83*84* // Define funcPtr to be a pointer to a Cryptoki API function85* // taking arguments args and returning CK_RV.86* CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtr)(args);87*88* or89*90* // Define funcPtrType to be the type of a pointer to a91* // Cryptoki API function taking arguments args and returning92* // CK_RV, and then define funcPtr to be a variable of type93* // funcPtrType.94* typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtrType)(args);95* funcPtrType funcPtr;96*97* If you're using Windows to access98* functions in a Win32 Cryptoki .dll, in might be defined by:99*100* #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \101* returnType __declspec(dllimport) (* name)102*103* In a UNIX environment, it might be defined by:104*105* #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \106* returnType (* name)107*108*109* 4. CK_CALLBACK_FUNCTION(returnType, name): A macro which makes110* a function pointer type for an application callback out of111* a return type for the callback and a name for the callback.112* It should be used in the following fashion:113*114* CK_CALLBACK_FUNCTION(CK_RV, myCallback)(args);115*116* to declare a function pointer, myCallback, to a callback117* which takes arguments args and returns a CK_RV. It can also118* be used like this:119*120* typedef CK_CALLBACK_FUNCTION(CK_RV, myCallbackType)(args);121* myCallbackType myCallback;122*123* If you're using Windows, it might be defined by:124*125* #define CK_CALLBACK_FUNCTION(returnType, name) \126* returnType (* name)127*128* In a UNIX environment, it might be defined by:129*130* #define CK_CALLBACK_FUNCTION(returnType, name) \131* returnType (* name)132*133*134* 5. NULL_PTR: This macro is the value of a NULL pointer.135*136* In any ANSI/ISO C environment (and in many others as well),137* this should best be defined by138*139* #ifndef NULL_PTR140* #define NULL_PTR 0141* #endif142*/143144145/* All the various Cryptoki types and #define'd values are in the146* file pkcs11t.h.147*/148#include "pkcs11t.h"149150#define __PASTE(x,y) x##y151152153/* ==============================================================154* Define the "extern" form of all the entry points.155* ==============================================================156*/157158#define CK_NEED_ARG_LIST 1159#define CK_PKCS11_FUNCTION_INFO(name) \160extern CK_DECLARE_FUNCTION(CK_RV, name)161162/* pkcs11f.h has all the information about the Cryptoki163* function prototypes.164*/165#include "pkcs11f.h"166167#undef CK_NEED_ARG_LIST168#undef CK_PKCS11_FUNCTION_INFO169170171/* ==============================================================172* Define the typedef form of all the entry points. That is, for173* each Cryptoki function C_XXX, define a type CK_C_XXX which is174* a pointer to that kind of function.175* ==============================================================176*/177178#define CK_NEED_ARG_LIST 1179#define CK_PKCS11_FUNCTION_INFO(name) \180typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, __PASTE(CK_,name))181182/* pkcs11f.h has all the information about the Cryptoki183* function prototypes.184*/185#include "pkcs11f.h"186187#undef CK_NEED_ARG_LIST188#undef CK_PKCS11_FUNCTION_INFO189190191/* ==============================================================192* Define structed vector of entry points. A CK_FUNCTION_LIST193* contains a CK_VERSION indicating a library's Cryptoki version194* and then a whole slew of function pointers to the routines in195* the library. This type was declared, but not defined, in196* pkcs11t.h.197* ==============================================================198*/199200#define CK_PKCS11_FUNCTION_INFO(name) \201__PASTE(CK_,name) name;202203/* Create the 3.0 Function list */204struct CK_FUNCTION_LIST_3_0 {205206CK_VERSION version; /* Cryptoki version */207208/* Pile all the function pointers into the CK_FUNCTION_LIST. */209/* pkcs11f.h has all the information about the Cryptoki210* function prototypes.211*/212#include "pkcs11f.h"213214};215216#define CK_PKCS11_2_0_ONLY 1217218/* Continue to define the old CK_FUNCTION_LIST */219struct CK_FUNCTION_LIST {220221CK_VERSION version; /* Cryptoki version */222223/* Pile all the function pointers into the CK_FUNCTION_LIST. */224/* pkcs11f.h has all the information about the Cryptoki225* function prototypes.226*/227#include "pkcs11f.h"228229};230231#undef CK_PKCS11_FUNCTION_INFO232#undef CK_PKCS11_2_0_ONLY233234235#undef __PASTE236237#ifdef __cplusplus238}239#endif240241#endif /* _PKCS11_H_ */242243244245246