Import from 1.9a8 tarball
[mozilla-nss.git] / security / nss / lib / softoken / pkcs11.h
blob9352fc1c6c73571a7824ea532a4a11b1528c4e47
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * RSA Labs
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 * Copyright (C) 1994-1999 RSA Security Inc. Licence to copy this document
39 * is granted provided that it is identified as "RSA Security In.c Public-Key
40 * Cryptography Standards (PKCS)" in all material mentioning or referencing
41 * this document.
43 * The latest version of this header can be found at:
44 * http://www.rsalabs.com/pkcs/pkcs-11/index.html
46 #ifndef _PKCS11_H_
47 #define _PKCS11_H_ 1
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
53 /* Before including this file (pkcs11.h) (or pkcs11t.h by
54 * itself), 6 platform-specific macros must be defined. These
55 * macros are described below, and typical definitions for them
56 * are also given. Be advised that these definitions can depend
57 * on both the platform and the compiler used (and possibly also
58 * on whether a PKCS #11 library is linked statically or
59 * dynamically).
61 * In addition to defining these 6 macros, the packing convention
62 * for PKCS #11 structures should be set. The PKCS #11
63 * convention on packing is that structures should be 1-byte
64 * aligned.
66 * In a Win32 environment, this might be done by using the
67 * following preprocessor directive before including pkcs11.h
68 * or pkcs11t.h:
70 * #pragma pack(push, cryptoki, 1)
72 * and using the following preprocessor directive after including
73 * pkcs11.h or pkcs11t.h:
75 * #pragma pack(pop, cryptoki)
77 * In a Win16 environment, this might be done by using the
78 * following preprocessor directive before including pkcs11.h
79 * or pkcs11t.h:
81 * #pragma pack(1)
83 * In a UNIX environment, you're on your own here. You might
84 * not need to do anything.
87 * Now for the macros:
90 * 1. CK_PTR: The indirection string for making a pointer to an
91 * object. It can be used like this:
93 * typedef CK_BYTE CK_PTR CK_BYTE_PTR;
95 * In a Win32 environment, it might be defined by
97 * #define CK_PTR *
99 * In a Win16 environment, it might be defined by
101 * #define CK_PTR far *
103 * In a UNIX environment, it might be defined by
105 * #define CK_PTR *
108 * 2. CK_DEFINE_FUNCTION(returnType, name): A macro which makes
109 * an exportable PKCS #11 library function definition out of a
110 * return type and a function name. It should be used in the
111 * following fashion to define the exposed PKCS #11 functions in
112 * a PKCS #11 library:
114 * CK_DEFINE_FUNCTION(CK_RV, C_Initialize)(
115 * CK_VOID_PTR pReserved
118 * ...
121 * For defining a function in a Win32 PKCS #11 .dll, it might be
122 * defined by
124 * #define CK_DEFINE_FUNCTION(returnType, name) \
125 * returnType __declspec(dllexport) name
127 * For defining a function in a Win16 PKCS #11 .dll, it might be
128 * defined by
130 * #define CK_DEFINE_FUNCTION(returnType, name) \
131 * returnType __export _far _pascal name
133 * In a UNIX environment, it might be defined by
135 * #define CK_DEFINE_FUNCTION(returnType, name) \
136 * returnType name
139 * 3. CK_DECLARE_FUNCTION(returnType, name): A macro which makes
140 * an importable PKCS #11 library function declaration out of a
141 * return type and a function name. It should be used in the
142 * following fashion:
144 * extern CK_DECLARE_FUNCTION(CK_RV, C_Initialize)(
145 * CK_VOID_PTR pReserved
146 * );
148 * For declaring a function in a Win32 PKCS #11 .dll, it might
149 * be defined by
151 * #define CK_DECLARE_FUNCTION(returnType, name) \
152 * returnType __declspec(dllimport) name
154 * For declaring a function in a Win16 PKCS #11 .dll, it might
155 * be defined by
157 * #define CK_DECLARE_FUNCTION(returnType, name) \
158 * returnType __export _far _pascal name
160 * In a UNIX environment, it might be defined by
162 * #define CK_DECLARE_FUNCTION(returnType, name) \
163 * returnType name
166 * 4. CK_DECLARE_FUNCTION_POINTER(returnType, name): A macro
167 * which makes a PKCS #11 API function pointer declaration or
168 * function pointer type declaration out of a return type and a
169 * function name. It should be used in the following fashion:
171 * // Define funcPtr to be a pointer to a PKCS #11 API function
172 * // taking arguments args and returning CK_RV.
173 * CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtr)(args);
175 * or
177 * // Define funcPtrType to be the type of a pointer to a
178 * // PKCS #11 API function taking arguments args and returning
179 * // CK_RV, and then define funcPtr to be a variable of type
180 * // funcPtrType.
181 * typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtrType)(args);
182 * funcPtrType funcPtr;
184 * For accessing functions in a Win32 PKCS #11 .dll, in might be
185 * defined by
187 * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
188 * returnType __declspec(dllimport) (* name)
190 * For accessing functions in a Win16 PKCS #11 .dll, it might be
191 * defined by
193 * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
194 * returnType __export _far _pascal (* name)
196 * In a UNIX environment, it might be defined by
198 * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
199 * returnType (* name)
202 * 5. CK_CALLBACK_FUNCTION(returnType, name): A macro which makes
203 * a function pointer type for an application callback out of
204 * a return type for the callback and a name for the callback.
205 * It should be used in the following fashion:
207 * CK_CALLBACK_FUNCTION(CK_RV, myCallback)(args);
209 * to declare a function pointer, myCallback, to a callback
210 * which takes arguments args and returns a CK_RV. It can also
211 * be used like this:
213 * typedef CK_CALLBACK_FUNCTION(CK_RV, myCallbackType)(args);
214 * myCallbackType myCallback;
216 * In a Win32 environment, it might be defined by
218 * #define CK_CALLBACK_FUNCTION(returnType, name) \
219 * returnType (* name)
221 * In a Win16 environment, it might be defined by
223 * #define CK_CALLBACK_FUNCTION(returnType, name) \
224 * returnType _far _pascal (* name)
226 * In a UNIX environment, it might be defined by
228 * #define CK_CALLBACK_FUNCTION(returnType, name) \
229 * returnType (* name)
232 * 6. NULL_PTR: This macro is the value of a NULL pointer.
234 * In any ANSI/ISO C environment (and in many others as well),
235 * this should be defined by
237 * #ifndef NULL_PTR
238 * #define NULL_PTR 0
239 * #endif
243 /* All the various PKCS #11 types and #define'd values are in the
244 * file pkcs11t.h. */
245 #include "pkcs11t.h"
247 #define __PASTE(x,y) x##y
250 /* packing defines */
251 #include "pkcs11p.h"
252 /* ==============================================================
253 * Define the "extern" form of all the entry points.
254 * ==============================================================
257 #define CK_NEED_ARG_LIST 1
258 #define CK_PKCS11_FUNCTION_INFO(name) \
259 CK_DECLARE_FUNCTION(CK_RV, name)
261 /* pkcs11f.h has all the information about the PKCS #11
262 * function prototypes. */
263 #include "pkcs11f.h"
265 #undef CK_NEED_ARG_LIST
266 #undef CK_PKCS11_FUNCTION_INFO
269 /* ==============================================================
270 * Define the typedef form of all the entry points. That is, for
271 * each PKCS #11 function C_XXX, define a type CK_C_XXX which is
272 * a pointer to that kind of function.
273 * ==============================================================
276 #define CK_NEED_ARG_LIST 1
277 #define CK_PKCS11_FUNCTION_INFO(name) \
278 typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, __PASTE(CK_,name))
280 /* pkcs11f.h has all the information about the PKCS #11
281 * function prototypes. */
282 #include "pkcs11f.h"
284 #undef CK_NEED_ARG_LIST
285 #undef CK_PKCS11_FUNCTION_INFO
288 /* ==============================================================
289 * Define structed vector of entry points. A CK_FUNCTION_LIST
290 * contains a CK_VERSION indicating a library's PKCS #11 version
291 * and then a whole slew of function pointers to the routines in
292 * the library. This type was declared, but not defined, in
293 * pkcs11t.h.
294 * ==============================================================
297 #define CK_PKCS11_FUNCTION_INFO(name) \
298 __PASTE(CK_,name) name;
300 struct CK_FUNCTION_LIST {
302 CK_VERSION version; /* PKCS #11 version */
304 /* Pile all the function pointers into the CK_FUNCTION_LIST. */
305 /* pkcs11f.h has all the information about the PKCS #11
306 * function prototypes. */
307 #include "pkcs11f.h"
311 #undef CK_PKCS11_FUNCTION_INFO
314 #undef __PASTE
316 /* unpack */
317 #include "pkcs11u.h"
319 #ifdef __cplusplus
321 #endif
323 #endif