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