Unleashed v1.4
[unleashed.git] / usr / src / lib / pkcs11 / include / pkcs11.h
blob53bbbd6120ca6dc80d4597d01e6d30c6300b0eb9
1 /* Copyright (c) OASIS Open 2016. 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 */
8 /* Latest version of the specification:
9 * http://docs.oasis-open.org/pkcs11/pkcs11-base/v2.40/pkcs11-base-v2.40.html
12 #ifndef _PKCS11_H_
13 #define _PKCS11_H_ 1
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
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).
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.
32 * If you're using Microsoft Developer Studio 5.0 to produce
33 * Win32 stuff, this might be done by using the following
34 * preprocessor directive before including pkcs11.h or pkcs11t.h:
36 * #pragma pack(push, cryptoki, 1)
38 * and using the following preprocessor directive after including
39 * pkcs11.h or pkcs11t.h:
41 * #pragma pack(pop, cryptoki)
43 * If you're using an earlier version of Microsoft Developer
44 * Studio to produce Win16 stuff, this might be done by using
45 * the following preprocessor directive before including
46 * pkcs11.h or pkcs11t.h:
48 * #pragma pack(1)
50 * In a UNIX environment, you're on your own for this. You might
51 * not need to do (or be able to do!) anything.
54 * Now for the macros:
57 * 1. CK_PTR: The indirection string for making a pointer to an
58 * object. It can be used like this:
60 * typedef CK_BYTE CK_PTR CK_BYTE_PTR;
62 * If you're using Microsoft Developer Studio 5.0 to produce
63 * Win32 stuff, it might be defined by:
65 * #define CK_PTR *
67 * If you're using an earlier version of Microsoft Developer
68 * Studio to produce Win16 stuff, it might be defined by:
70 * #define CK_PTR far *
72 * In a typical UNIX environment, it might be defined by:
74 * #define CK_PTR *
77 * 2. CK_DECLARE_FUNCTION(returnType, name): A macro which makes
78 * an importable Cryptoki library function declaration out of a
79 * return type and a function name. It should be used in the
80 * following fashion:
82 * extern CK_DECLARE_FUNCTION(CK_RV, C_Initialize)(
83 * CK_VOID_PTR pReserved
84 * );
86 * If you're using Microsoft Developer Studio 5.0 to declare a
87 * function in a Win32 Cryptoki .dll, it might be defined by:
89 * #define CK_DECLARE_FUNCTION(returnType, name) \
90 * returnType __declspec(dllimport) name
92 * If you're using an earlier version of Microsoft Developer
93 * Studio to declare a function in a Win16 Cryptoki .dll, it
94 * might be defined by:
96 * #define CK_DECLARE_FUNCTION(returnType, name) \
97 * returnType __export _far _pascal name
99 * In a UNIX environment, it might be defined by:
101 * #define CK_DECLARE_FUNCTION(returnType, name) \
102 * returnType name
105 * 3. CK_DECLARE_FUNCTION_POINTER(returnType, name): A macro
106 * which makes a Cryptoki API function pointer declaration or
107 * function pointer type declaration out of a return type and a
108 * function name. It should be used in the following fashion:
110 * // Define funcPtr to be a pointer to a Cryptoki API function
111 * // taking arguments args and returning CK_RV.
112 * CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtr)(args);
114 * or
116 * // Define funcPtrType to be the type of a pointer to a
117 * // Cryptoki API function taking arguments args and returning
118 * // CK_RV, and then define funcPtr to be a variable of type
119 * // funcPtrType.
120 * typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtrType)(args);
121 * funcPtrType funcPtr;
123 * If you're using Microsoft Developer Studio 5.0 to access
124 * functions in a Win32 Cryptoki .dll, in might be defined by:
126 * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
127 * returnType __declspec(dllimport) (* name)
129 * If you're using an earlier version of Microsoft Developer
130 * Studio to access functions in a Win16 Cryptoki .dll, it might
131 * be defined by:
133 * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
134 * returnType __export _far _pascal (* name)
136 * In a UNIX environment, it might be defined by:
138 * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
139 * returnType (* name)
142 * 4. CK_CALLBACK_FUNCTION(returnType, name): A macro which makes
143 * a function pointer type for an application callback out of
144 * a return type for the callback and a name for the callback.
145 * It should be used in the following fashion:
147 * CK_CALLBACK_FUNCTION(CK_RV, myCallback)(args);
149 * to declare a function pointer, myCallback, to a callback
150 * which takes arguments args and returns a CK_RV. It can also
151 * be used like this:
153 * typedef CK_CALLBACK_FUNCTION(CK_RV, myCallbackType)(args);
154 * myCallbackType myCallback;
156 * If you're using Microsoft Developer Studio 5.0 to do Win32
157 * Cryptoki development, it might be defined by:
159 * #define CK_CALLBACK_FUNCTION(returnType, name) \
160 * returnType (* name)
162 * If you're using an earlier version of Microsoft Developer
163 * Studio to do Win16 development, it might be defined by:
165 * #define CK_CALLBACK_FUNCTION(returnType, name) \
166 * returnType _far _pascal (* name)
168 * In a UNIX environment, it might be defined by:
170 * #define CK_CALLBACK_FUNCTION(returnType, name) \
171 * returnType (* name)
174 * 5. NULL_PTR: This macro is the value of a NULL pointer.
176 * In any ANSI/ISO C environment (and in many others as well),
177 * this should best be defined by
179 * #ifndef NULL_PTR
180 * #define NULL_PTR 0
181 * #endif
185 /* All the various Cryptoki types and #define'd values are in the
186 * file pkcs11t.h.
188 #include "pkcs11t.h"
190 #define __PASTE(x,y) x##y
193 /* ==============================================================
194 * Define the "extern" form of all the entry points.
195 * ==============================================================
198 #define CK_NEED_ARG_LIST 1
199 #define CK_PKCS11_FUNCTION_INFO(name) \
200 extern CK_DECLARE_FUNCTION(CK_RV, name)
202 /* pkcs11f.h has all the information about the Cryptoki
203 * function prototypes.
205 #include "pkcs11f.h"
207 #undef CK_NEED_ARG_LIST
208 #undef CK_PKCS11_FUNCTION_INFO
211 /* ==============================================================
212 * Define the typedef form of all the entry points. That is, for
213 * each Cryptoki function C_XXX, define a type CK_C_XXX which is
214 * a pointer to that kind of function.
215 * ==============================================================
218 #define CK_NEED_ARG_LIST 1
219 #define CK_PKCS11_FUNCTION_INFO(name) \
220 typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, __PASTE(CK_,name))
222 /* pkcs11f.h has all the information about the Cryptoki
223 * function prototypes.
225 #include "pkcs11f.h"
227 #undef CK_NEED_ARG_LIST
228 #undef CK_PKCS11_FUNCTION_INFO
231 /* ==============================================================
232 * Define structed vector of entry points. A CK_FUNCTION_LIST
233 * contains a CK_VERSION indicating a library's Cryptoki version
234 * and then a whole slew of function pointers to the routines in
235 * the library. This type was declared, but not defined, in
236 * pkcs11t.h.
237 * ==============================================================
240 #define CK_PKCS11_FUNCTION_INFO(name) \
241 __PASTE(CK_,name) name;
243 struct CK_FUNCTION_LIST {
245 CK_VERSION version; /* Cryptoki version */
247 /* Pile all the function pointers into the CK_FUNCTION_LIST. */
248 /* pkcs11f.h has all the information about the Cryptoki
249 * function prototypes.
251 #include "pkcs11f.h"
255 #undef CK_PKCS11_FUNCTION_INFO
258 #undef __PASTE
260 #ifdef __cplusplus
262 #endif
264 #endif /* _PKCS11_H_ */