Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pkcs11.h
Go to the documentation of this file.
1 /* 02-Sep-2008 from ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-11/v2-20/ */
2 
3 /* pkcs11.h include file for PKCS #11. */
4 /* $Revision: 1.4 $ */
5 
6 /* License to copy and use this software is granted provided that it is
7  * identified as "RSA Security Inc. PKCS #11 Cryptographic Token Interface
8  * (Cryptoki)" in all material mentioning or referencing this software.
9 
10  * License is also granted to make and use derivative works provided that
11  * such works are identified as "derived from the RSA Security Inc. PKCS #11
12  * Cryptographic Token Interface (Cryptoki)" in all material mentioning or
13  * referencing the derived work.
14 
15  * RSA Security Inc. makes no representations concerning either the
16  * merchantability of this software or the suitability of this software for
17  * any particular purpose. It is provided "as is" without express or implied
18  * warranty of any kind.
19  */
20 #ifndef _PKCS11_H_
21 #define _PKCS11_H_ 1
22 
23 #ifndef P6API_DEFINE
24 #define P6API_DEFINE
25 #endif
26 
27 #ifndef P6API_DECLARE
28 #define P6API_DECLARE
29 #endif
30 
31 #ifndef P6API_FPOINTER
32 #define P6API_FPOINTER
33 #endif
34 
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 /* Before including this file (pkcs11.h) (or pkcs11t.h by
41  * itself), 6 platform-specific macros must be defined. These
42  * macros are described below, and typical definitions for them
43  * are also given. Be advised that these definitions can depend
44  * on both the platform and the compiler used (and possibly also
45  * on whether a Cryptoki library is linked statically or
46  * dynamically).
47  *
48  * In addition to defining these 6 macros, the packing convention
49  * for Cryptoki structures should be set. The Cryptoki
50  * convention on packing is that structures should be 1-byte
51  * aligned.
52  *
53  * If you're using Microsoft Developer Studio 5.0 to produce
54  * Win32 stuff, this might be done by using the following
55  * preprocessor directive before including pkcs11.h or pkcs11t.h:
56  *
57  * #pragma pack(push, cryptoki, 1)
58  *
59  * and using the following preprocessor directive after including
60  * pkcs11.h or pkcs11t.h:
61  *
62  * #pragma pack(pop, cryptoki)
63  *
64  * If you're using an earlier version of Microsoft Developer
65  * Studio to produce Win16 stuff, this might be done by using
66  * the following preprocessor directive before including
67  * pkcs11.h or pkcs11t.h:
68  *
69  * #pragma pack(1)
70  *
71  * In a UNIX environment, you're on your own for this. You might
72  * not need to do (or be able to do!) anything.
73  *
74  *
75  * Now for the macros:
76  *
77  *
78  * 1. CK_PTR: The indirection string for making a pointer to an
79  * object. It can be used like this:
80  *
81  * typedef CK_BYTE CK_PTR CK_BYTE_PTR;
82  *
83  * If you're using Microsoft Developer Studio 5.0 to produce
84  * Win32 stuff, it might be defined by:
85  *
86  * #define CK_PTR *
87  *
88  * If you're using an earlier version of Microsoft Developer
89  * Studio to produce Win16 stuff, it might be defined by:
90  *
91  * #define CK_PTR far *
92  *
93  * In a typical UNIX environment, it might be defined by:
94  *
95  * #define CK_PTR *
96  */
97 #define CK_PTR *
98 
99 
100 /*
101  * 2. CK_DEFINE_FUNCTION(returnType, name): A macro which makes
102  * an exportable Cryptoki library function definition out of a
103  * return type and a function name. It should be used in the
104  * following fashion to define the exposed Cryptoki functions in
105  * a Cryptoki library:
106  *
107  * CK_DEFINE_FUNCTION(CK_RV, C_Initialize)(
108  * CK_VOID_PTR pReserved
109  * )
110  * {
111  * ...
112  * }
113  *
114  * If you're using Microsoft Developer Studio 5.0 to define a
115  * function in a Win32 Cryptoki .dll, it might be defined by:
116  *
117  * #define CK_DEFINE_FUNCTION(returnType, name) \
118  * returnType __declspec(dllexport) name
119  *
120  * If you're using an earlier version of Microsoft Developer
121  * Studio to define a function in a Win16 Cryptoki .dll, it
122  * might be defined by:
123  *
124  * #define CK_DEFINE_FUNCTION(returnType, name) \
125  * returnType __export _far _pascal name
126  *
127  * In a UNIX environment, it might be defined by:
128  *
129  * #define CK_DEFINE_FUNCTION(returnType, name) \
130  * returnType name
131  */
132 #define CK_DEFINE_FUNCTION(returnType, name) \
133  P6API_DEFINE returnType name
134 
135 
136 /*
137  * 3. CK_DECLARE_FUNCTION(returnType, name): A macro which makes
138  * an importable Cryptoki library function declaration out of a
139  * return type and a function name. It should be used in the
140  * following fashion:
141  *
142  * extern CK_DECLARE_FUNCTION(CK_RV, C_Initialize)(
143  * CK_VOID_PTR pReserved
144  * );
145  *
146  * If you're using Microsoft Developer Studio 5.0 to declare a
147  * function in a Win32 Cryptoki .dll, it might be defined by:
148  *
149  * #define CK_DECLARE_FUNCTION(returnType, name) \
150  * returnType __declspec(dllimport) name
151  *
152  * If you're using an earlier version of Microsoft Developer
153  * Studio to declare a function in a Win16 Cryptoki .dll, it
154  * might be defined by:
155  *
156  * #define CK_DECLARE_FUNCTION(returnType, name) \
157  * returnType __export _far _pascal name
158  *
159  * In a UNIX environment, it might be defined by:
160  *
161  * #define CK_DECLARE_FUNCTION(returnType, name) \
162  * returnType name
163  */
164 #define CK_DECLARE_FUNCTION(returnType, name) \
165  P6API_DECLARE returnType name
166 
167 
168 /*
169  * 4. CK_DECLARE_FUNCTION_POINTER(returnType, name): A macro
170  * which makes a Cryptoki API function pointer declaration or
171  * function pointer type declaration out of a return type and a
172  * function name. It should be used in the following fashion:
173  *
174  * // Define funcPtr to be a pointer to a Cryptoki API function
175  * // taking arguments args and returning CK_RV.
176  * CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtr)(args);
177  *
178  * or
179  *
180  * // Define funcPtrType to be the type of a pointer to a
181  * // Cryptoki API function taking arguments args and returning
182  * // CK_RV, and then define funcPtr to be a variable of type
183  * // funcPtrType.
184  * typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtrType)(args);
185  * funcPtrType funcPtr;
186  *
187  * If you're using Microsoft Developer Studio 5.0 to access
188  * functions in a Win32 Cryptoki .dll, in might be defined by:
189  *
190  * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
191  * returnType __declspec(dllimport) (* name)
192  *
193  * If you're using an earlier version of Microsoft Developer
194  * Studio to access functions in a Win16 Cryptoki .dll, it might
195  * be defined by:
196  *
197  * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
198  * returnType __export _far _pascal (* name)
199  *
200  * In a UNIX environment, it might be defined by:
201  *
202  * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
203  * returnType (* name)
204  *
205  */
206 #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
207  P6API_FPOINTER returnType (* name)
208 
209 
210  /* 5. CK_CALLBACK_FUNCTION(returnType, name): A macro which makes
211  * a function pointer type for an application callback out of
212  * a return type for the callback and a name for the callback.
213  * It should be used in the following fashion:
214  *
215  * CK_CALLBACK_FUNCTION(CK_RV, myCallback)(args);
216  *
217  * to declare a function pointer, myCallback, to a callback
218  * which takes arguments args and returns a CK_RV. It can also
219  * be used like this:
220  *
221  * typedef CK_CALLBACK_FUNCTION(CK_RV, myCallbackType)(args);
222  * myCallbackType myCallback;
223  *
224  * If you're using Microsoft Developer Studio 5.0 to do Win32
225  * Cryptoki development, it might be defined by:
226  *
227  * #define CK_CALLBACK_FUNCTION(returnType, name) \
228  * returnType (* name)
229  *
230  * If you're using an earlier version of Microsoft Developer
231  * Studio to do Win16 development, it might be defined by:
232  *
233  * #define CK_CALLBACK_FUNCTION(returnType, name) \
234  * returnType _far _pascal (* name)
235  *
236  * In a UNIX environment, it might be defined by:
237  *
238  * #define CK_CALLBACK_FUNCTION(returnType, name) \
239  * returnType (* name)
240  */
241 #define CK_CALLBACK_FUNCTION(returnType, name) \
242  returnType (* name)
243 
244 /*
245  * 6. NULL_PTR: This macro is the value of a NULL pointer.
246  *
247  * In any ANSI/ISO C environment (and in many others as well),
248  * this should best be defined by
249  */
250 #ifndef NULL_PTR
251 #define NULL_PTR 0
252 #endif
253 
254 
255 
256 /* All the various Cryptoki types and #define'd values are in the
257  * file pkcs11t.h. */
258 #include "pkcs11t.h"
259 
260 #define __PASTE(x,y) x##y
261 
262 
263 /* ==============================================================
264  * Define the "extern" form of all the entry points.
265  * ==============================================================
266  */
267 
268 #define CK_NEED_ARG_LIST 1
269 #define CK_PKCS11_FUNCTION_INFO(name) \
270  extern CK_DECLARE_FUNCTION(CK_RV, name)
271 
272 /* pkcs11f.h has all the information about the Cryptoki
273  * function prototypes. */
274 #include "pkcs11f.h"
275 
276 #undef CK_NEED_ARG_LIST
277 #undef CK_PKCS11_FUNCTION_INFO
278 
279 
280 /* ==============================================================
281  * Define the typedef form of all the entry points. That is, for
282  * each Cryptoki function C_XXX, define a type CK_C_XXX which is
283  * a pointer to that kind of function.
284  * ==============================================================
285  */
286 
287 #define CK_NEED_ARG_LIST 1
288 #define CK_PKCS11_FUNCTION_INFO(name) \
289  typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, __PASTE(CK_,name))
290 
291 /* pkcs11f.h has all the information about the Cryptoki
292  * function prototypes. */
293 #include "pkcs11f.h"
294 
295 #undef CK_NEED_ARG_LIST
296 #undef CK_PKCS11_FUNCTION_INFO
297 
298 
299 /* ==============================================================
300  * Define structed vector of entry points. A CK_FUNCTION_LIST
301  * contains a CK_VERSION indicating a library's Cryptoki version
302  * and then a whole slew of function pointers to the routines in
303  * the library. This type was declared, but not defined, in
304  * pkcs11t.h.
305  * ==============================================================
306  */
307 
308 #define CK_PKCS11_FUNCTION_INFO(name) \
309  __PASTE(CK_,name) name;
310 
312 
313  CK_VERSION version; /* Cryptoki version */
314 
315 /* Pile all the function pointers into the CK_FUNCTION_LIST. */
316 /* pkcs11f.h has all the information about the Cryptoki
317  * function prototypes. */
318 #include "pkcs11f.h"
319 
320 };
321 
322 #undef CK_PKCS11_FUNCTION_INFO
323 
324 
325 #undef __PASTE
326 
327 #ifdef __cplusplus
328 }
329 #endif
330 
331 #endif
CK_VERSION version
Definition: pkcs11.h:313