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