1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 * Copyright (C) 1994-1999 RSA Security Inc. Licence to copy this document
6 * is granted provided that it is identified as "RSA Security In.c Public-Key
7 * Cryptography Standards (PKCS)" in all material mentioning or referencing
10 * The latest version of this header can be found at:
11 * http://www.rsalabs.com/pkcs/pkcs-11/index.html
20 /* Before including this file (pkcs11.h) (or pkcs11t.h by
21 * itself), 6 platform-specific macros must be defined. These
22 * macros are described below, and typical definitions for them
23 * are also given. Be advised that these definitions can depend
24 * on both the platform and the compiler used (and possibly also
25 * on whether a PKCS #11 library is linked statically or
28 * In addition to defining these 6 macros, the packing convention
29 * for PKCS #11 structures should be set. The PKCS #11
30 * convention on packing is that structures should be 1-byte
33 * In a Win32 environment, this might be done by using the
34 * following preprocessor directive before including pkcs11.h
37 * #pragma pack(push, cryptoki, 1)
39 * and using the following preprocessor directive after including
40 * pkcs11.h or pkcs11t.h:
42 * #pragma pack(pop, cryptoki)
44 * In a UNIX environment, you're on your own here. You might
45 * not need to do anything.
51 * 1. CK_PTR: The indirection string for making a pointer to an
52 * object. It can be used like this:
54 * typedef CK_BYTE CK_PTR CK_BYTE_PTR;
56 * In a Win32 environment, it might be defined by
60 * In a UNIX environment, it might be defined by
65 * 2. CK_DEFINE_FUNCTION(returnType, name): A macro which makes
66 * an exportable PKCS #11 library function definition out of a
67 * return type and a function name. It should be used in the
68 * following fashion to define the exposed PKCS #11 functions in
71 * CK_DEFINE_FUNCTION(CK_RV, C_Initialize)(
72 * CK_VOID_PTR pReserved
78 * For defining a function in a Win32 PKCS #11 .dll, it might be
81 * #define CK_DEFINE_FUNCTION(returnType, name) \
82 * returnType __declspec(dllexport) name
84 * In a UNIX environment, it might be defined by
86 * #define CK_DEFINE_FUNCTION(returnType, name) \
90 * 3. CK_DECLARE_FUNCTION(returnType, name): A macro which makes
91 * an importable PKCS #11 library function declaration out of a
92 * return type and a function name. It should be used in the
95 * extern CK_DECLARE_FUNCTION(CK_RV, C_Initialize)(
96 * CK_VOID_PTR pReserved
99 * For declaring a function in a Win32 PKCS #11 .dll, it might
102 * #define CK_DECLARE_FUNCTION(returnType, name) \
103 * returnType __declspec(dllimport) name
105 * In a UNIX environment, it might be defined by
107 * #define CK_DECLARE_FUNCTION(returnType, name) \
111 * 4. CK_DECLARE_FUNCTION_POINTER(returnType, name): A macro
112 * which makes a PKCS #11 API function pointer declaration or
113 * function pointer type declaration out of a return type and a
114 * function name. It should be used in the following fashion:
116 * // Define funcPtr to be a pointer to a PKCS #11 API function
117 * // taking arguments args and returning CK_RV.
118 * CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtr)(args);
122 * // Define funcPtrType to be the type of a pointer to a
123 * // PKCS #11 API function taking arguments args and returning
124 * // CK_RV, and then define funcPtr to be a variable of type
126 * typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtrType)(args);
127 * funcPtrType funcPtr;
129 * For accessing functions in a Win32 PKCS #11 .dll, in might be
132 * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
133 * returnType __declspec(dllimport) (* name)
135 * In a UNIX environment, it might be defined by
137 * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
138 * returnType (* name)
141 * 5. CK_CALLBACK_FUNCTION(returnType, name): A macro which makes
142 * a function pointer type for an application callback out of
143 * a return type for the callback and a name for the callback.
144 * It should be used in the following fashion:
146 * CK_CALLBACK_FUNCTION(CK_RV, myCallback)(args);
148 * to declare a function pointer, myCallback, to a callback
149 * which takes arguments args and returns a CK_RV. It can also
152 * typedef CK_CALLBACK_FUNCTION(CK_RV, myCallbackType)(args);
153 * myCallbackType myCallback;
155 * In a Win32 environment, it might be defined by
157 * #define CK_CALLBACK_FUNCTION(returnType, name) \
158 * returnType (* name)
160 * In a UNIX environment, it might be defined by
162 * #define CK_CALLBACK_FUNCTION(returnType, name) \
163 * returnType (* name)
166 * 6. NULL_PTR: This macro is the value of a NULL pointer.
168 * In any ANSI/ISO C environment (and in many others as well),
169 * this should be defined by
176 /* All the various PKCS #11 types and #define'd values are in the
180 #define __PASTE(x, y) x##y
182 /* packing defines */
184 /* ==============================================================
185 * Define the "extern" form of all the entry points.
186 * ==============================================================
189 #define CK_NEED_ARG_LIST 1
190 #define CK_PKCS11_FUNCTION_INFO(name) \
191 CK_DECLARE_FUNCTION(CK_RV, name)
193 /* pkcs11f.h has all the information about the PKCS #11
194 * function prototypes. */
197 #undef CK_NEED_ARG_LIST
198 #undef CK_PKCS11_FUNCTION_INFO
200 /* ==============================================================
201 * Define the typedef form of all the entry points. That is, for
202 * each PKCS #11 function C_XXX, define a type CK_C_XXX which is
203 * a pointer to that kind of function.
204 * ==============================================================
207 #define CK_NEED_ARG_LIST 1
208 #define CK_PKCS11_FUNCTION_INFO(name) \
209 typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, __PASTE(CK_, name))
211 /* pkcs11f.h has all the information about the PKCS #11
212 * function prototypes. */
215 #undef CK_NEED_ARG_LIST
216 #undef CK_PKCS11_FUNCTION_INFO
218 /* ==============================================================
219 * Define structed vector of entry points. A CK_FUNCTION_LIST
220 * contains a CK_VERSION indicating a library's PKCS #11 version
221 * and then a whole slew of function pointers to the routines in
222 * the library. This type was declared, but not defined, in
224 * ==============================================================
227 #define CK_PKCS11_FUNCTION_INFO(name) \
231 struct CK_FUNCTION_LIST {
233 CK_VERSION version; /* PKCS #11 version */
235 /* Pile all the function pointers into the CK_FUNCTION_LIST. */
236 /* pkcs11f.h has all the information about the PKCS #11
237 * function prototypes. */
241 #undef CK_PKCS11_FUNCTION_INFO