| 1 |
/* Copyright (c) OASIS Open 2016,2019. All Rights Reserved./ |
| 2 |
* /Distributed under the terms of the OASIS IPR Policy, |
| 3 |
* [http://www.oasis-open.org/policies-guidelines/ipr], AS-IS, WITHOUT ANY |
| 4 |
* IMPLIED OR EXPRESS WARRANTY; there is no warranty of MERCHANTABILITY, FITNESS FOR A |
| 5 |
* PARTICULAR PURPOSE or NONINFRINGEMENT of the rights of others. |
| 6 |
*/ |
| 7 |
|
| 8 |
/* Latest version of the specification: |
| 9 |
* http://docs.oasis-open.org/pkcs11/pkcs11-base/v3.0/pkcs11-base-v3.0.html |
| 10 |
*/ |
| 11 |
|
| 12 |
#ifndef _PKCS11_H_ |
| 13 |
#define _PKCS11_H_ 1 |
| 14 |
|
| 15 |
#ifdef __cplusplus |
| 16 |
extern "C" { |
| 17 |
#endif |
| 18 |
|
| 19 |
/* Before including this file (pkcs11.h) (or pkcs11t.h by |
| 20 |
* itself), 5 platform-specific macros must be defined. These |
| 21 |
* macros are described below, and typical definitions for them |
| 22 |
* are also given. Be advised that these definitions can depend |
| 23 |
* on both the platform and the compiler used (and possibly also |
| 24 |
* on whether a Cryptoki library is linked statically or |
| 25 |
* dynamically). |
| 26 |
* |
| 27 |
* In addition to defining these 5 macros, the packing convention |
| 28 |
* for Cryptoki structures should be set. The Cryptoki |
| 29 |
* convention on packing is that structures should be 1-byte |
| 30 |
* aligned. |
| 31 |
* |
| 32 |
* If you're using Windows this might be done by using the following |
| 33 |
* preprocessor directive before including pkcs11.h or pkcs11t.h: |
| 34 |
* |
| 35 |
* #pragma pack(push, cryptoki, 1) |
| 36 |
* |
| 37 |
* and using the following preprocessor directive after including |
| 38 |
* pkcs11.h or pkcs11t.h: |
| 39 |
* |
| 40 |
* #pragma pack(pop, cryptoki) |
| 41 |
* |
| 42 |
* In a UNIX environment, you're on your own for this. You might |
| 43 |
* not need to do (or be able to do!) anything. |
| 44 |
* |
| 45 |
* |
| 46 |
* Now for the macros: |
| 47 |
* |
| 48 |
* |
| 49 |
* 1. CK_PTR: The indirection string for making a pointer to an |
| 50 |
* object. It can be used like this: |
| 51 |
* |
| 52 |
* typedef CK_BYTE CK_PTR CK_BYTE_PTR; |
| 53 |
* |
| 54 |
* If you're using Windows, it might be defined by: |
| 55 |
* |
| 56 |
* #define CK_PTR * |
| 57 |
* |
| 58 |
* In a typical UNIX environment, it might be defined by: |
| 59 |
* |
| 60 |
* #define CK_PTR * |
| 61 |
* |
| 62 |
* |
| 63 |
* 2. CK_DECLARE_FUNCTION(returnType, name): A macro which makes |
| 64 |
* an importable Cryptoki library function declaration out of a |
| 65 |
* return type and a function name. It should be used in the |
| 66 |
* following fashion: |
| 67 |
* |
| 68 |
* extern CK_DECLARE_FUNCTION(CK_RV, C_Initialize)( |
| 69 |
* CK_VOID_PTR pReserved |
| 70 |
* ); |
| 71 |
* |
| 72 |
* If you're using Windows to declare a function in a Win32 Cryptoki .dll, |
| 73 |
* it might be defined by: |
| 74 |
* |
| 75 |
* #define CK_DECLARE_FUNCTION(returnType, name) \ |
| 76 |
* returnType __declspec(dllimport) name |
| 77 |
* |
| 78 |
* In a UNIX environment, it might be defined by: |
| 79 |
* |
| 80 |
* #define CK_DECLARE_FUNCTION(returnType, name) \ |
| 81 |
* returnType name |
| 82 |
* |
| 83 |
* |
| 84 |
* 3. CK_DECLARE_FUNCTION_POINTER(returnType, name): A macro |
| 85 |
* which makes a Cryptoki API function pointer declaration or |
| 86 |
* function pointer type declaration out of a return type and a |
| 87 |
* function name. It should be used in the following fashion: |
| 88 |
* |
| 89 |
* // Define funcPtr to be a pointer to a Cryptoki API function |
| 90 |
* // taking arguments args and returning CK_RV. |
| 91 |
* CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtr)(args); |
| 92 |
* |
| 93 |
* or |
| 94 |
* |
| 95 |
* // Define funcPtrType to be the type of a pointer to a |
| 96 |
* // Cryptoki API function taking arguments args and returning |
| 97 |
* // CK_RV, and then define funcPtr to be a variable of type |
| 98 |
* // funcPtrType. |
| 99 |
* typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtrType)(args); |
| 100 |
* funcPtrType funcPtr; |
| 101 |
* |
| 102 |
* If you're using Windows to access |
| 103 |
* functions in a Win32 Cryptoki .dll, in might be defined by: |
| 104 |
* |
| 105 |
* #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \ |
| 106 |
* returnType __declspec(dllimport) (* name) |
| 107 |
* |
| 108 |
* In a UNIX environment, it might be defined by: |
| 109 |
* |
| 110 |
* #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \ |
| 111 |
* returnType (* name) |
| 112 |
* |
| 113 |
* |
| 114 |
* 4. CK_CALLBACK_FUNCTION(returnType, name): A macro which makes |
| 115 |
* a function pointer type for an application callback out of |
| 116 |
* a return type for the callback and a name for the callback. |
| 117 |
* It should be used in the following fashion: |
| 118 |
* |
| 119 |
* CK_CALLBACK_FUNCTION(CK_RV, myCallback)(args); |
| 120 |
* |
| 121 |
* to declare a function pointer, myCallback, to a callback |
| 122 |
* which takes arguments args and returns a CK_RV. It can also |
| 123 |
* be used like this: |
| 124 |
* |
| 125 |
* typedef CK_CALLBACK_FUNCTION(CK_RV, myCallbackType)(args); |
| 126 |
* myCallbackType myCallback; |
| 127 |
* |
| 128 |
* If you're using Windows, it might be defined by: |
| 129 |
* |
| 130 |
* #define CK_CALLBACK_FUNCTION(returnType, name) \ |
| 131 |
* returnType (* name) |
| 132 |
* |
| 133 |
* In a UNIX environment, it might be defined by: |
| 134 |
* |
| 135 |
* #define CK_CALLBACK_FUNCTION(returnType, name) \ |
| 136 |
* returnType (* name) |
| 137 |
* |
| 138 |
* |
| 139 |
* 5. NULL_PTR: This macro is the value of a NULL pointer. |
| 140 |
* |
| 141 |
* In any ANSI/ISO C environment (and in many others as well), |
| 142 |
* this should best be defined by |
| 143 |
* |
| 144 |
* #ifndef NULL_PTR |
| 145 |
* #define NULL_PTR 0 |
| 146 |
* #endif |
| 147 |
*/ |
| 148 |
|
| 149 |
|
| 150 |
/* All the various Cryptoki types and #define'd values are in the |
| 151 |
* file pkcs11t.h. |
| 152 |
*/ |
| 153 |
#include "pkcs11t.h" |
| 154 |
|
| 155 |
#define __PASTE(x,y) x##y |
| 156 |
|
| 157 |
|
| 158 |
/* ============================================================== |
| 159 |
* Define the "extern" form of all the entry points. |
| 160 |
* ============================================================== |
| 161 |
*/ |
| 162 |
|
| 163 |
#define CK_NEED_ARG_LIST 1 |
| 164 |
#define CK_PKCS11_FUNCTION_INFO(name) \ |
| 165 |
extern CK_DECLARE_FUNCTION(CK_RV, name) |
| 166 |
|
| 167 |
/* pkcs11f.h has all the information about the Cryptoki |
| 168 |
* function prototypes. |
| 169 |
*/ |
| 170 |
#include "pkcs11f.h" |
| 171 |
|
| 172 |
#undef CK_NEED_ARG_LIST |
| 173 |
#undef CK_PKCS11_FUNCTION_INFO |
| 174 |
|
| 175 |
|
| 176 |
/* ============================================================== |
| 177 |
* Define the typedef form of all the entry points. That is, for |
| 178 |
* each Cryptoki function C_XXX, define a type CK_C_XXX which is |
| 179 |
* a pointer to that kind of function. |
| 180 |
* ============================================================== |
| 181 |
*/ |
| 182 |
|
| 183 |
#define CK_NEED_ARG_LIST 1 |
| 184 |
#define CK_PKCS11_FUNCTION_INFO(name) \ |
| 185 |
typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, __PASTE(CK_,name)) |
| 186 |
|
| 187 |
/* pkcs11f.h has all the information about the Cryptoki |
| 188 |
* function prototypes. |
| 189 |
*/ |
| 190 |
#include "pkcs11f.h" |
| 191 |
|
| 192 |
#undef CK_NEED_ARG_LIST |
| 193 |
#undef CK_PKCS11_FUNCTION_INFO |
| 194 |
|
| 195 |
|
| 196 |
/* ============================================================== |
| 197 |
* Define structed vector of entry points. A CK_FUNCTION_LIST |
| 198 |
* contains a CK_VERSION indicating a library's Cryptoki version |
| 199 |
* and then a whole slew of function pointers to the routines in |
| 200 |
* the library. This type was declared, but not defined, in |
| 201 |
* pkcs11t.h. |
| 202 |
* ============================================================== |
| 203 |
*/ |
| 204 |
|
| 205 |
#define CK_PKCS11_FUNCTION_INFO(name) \ |
| 206 |
__PASTE(CK_,name) name; |
| 207 |
|
| 208 |
/* Create the 3.0 Function list */ |
| 209 |
struct CK_FUNCTION_LIST_3_0 { |
| 210 |
|
| 211 |
CK_VERSION version; /* Cryptoki version */ |
| 212 |
|
| 213 |
/* Pile all the function pointers into the CK_FUNCTION_LIST. */ |
| 214 |
/* pkcs11f.h has all the information about the Cryptoki |
| 215 |
* function prototypes. |
| 216 |
*/ |
| 217 |
#include "pkcs11f.h" |
| 218 |
|
| 219 |
}; |
| 220 |
|
| 221 |
#define CK_PKCS11_2_0_ONLY 1 |
| 222 |
|
| 223 |
/* Continue to define the old CK_FUNCTION_LIST */ |
| 224 |
struct CK_FUNCTION_LIST { |
| 225 |
|
| 226 |
CK_VERSION version; /* Cryptoki version */ |
| 227 |
|
| 228 |
/* Pile all the function pointers into the CK_FUNCTION_LIST. */ |
| 229 |
/* pkcs11f.h has all the information about the Cryptoki |
| 230 |
* function prototypes. |
| 231 |
*/ |
| 232 |
#include "pkcs11f.h" |
| 233 |
|
| 234 |
}; |
| 235 |
|
| 236 |
#undef CK_PKCS11_FUNCTION_INFO |
| 237 |
#undef CK_PKCS11_2_0_ONLY |
| 238 |
|
| 239 |
|
| 240 |
#undef __PASTE |
| 241 |
|
| 242 |
#ifdef __cplusplus |
| 243 |
} |
| 244 |
#endif |
| 245 |
|
| 246 |
#endif /* _PKCS11_H_ */ |
| 247 |
|