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