2
* The contents of this file are subject to the Mozilla Public
3
* License Version 1.1 (the "License"); you may not use this file
4
* except in compliance with the License. You may obtain a copy of
5
* the License at http://www.mozilla.org/MPL/
7
* Software distributed under the License is distributed on an "AS
8
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9
* implied. See the License for the specific language governing
10
* rights and limitations under the License.
12
* The Original Code is the Netscape security libraries.
14
* The Initial Developer of the Original Code is Netscape
15
* Communications Corporation. Portions created by Netscape are
16
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
19
* Contributor(s): RSA Labs
21
* Alternatively, the contents of this file may be used under the
22
* terms of the GNU General Public License Version 2 or later (the
23
* "GPL"), in which case the provisions of the GPL are applicable
24
* instead of those above. If you wish to allow use of your
25
* version of this file only under the terms of the GPL and not to
26
* allow others to use your version of this file under the MPL,
27
* indicate your decision by deleting the provisions above and
28
* replace them with the notice and other provisions required by
29
* the GPL. If you do not delete the provisions above, a recipient
30
* may use your version of this file under either the MPL or the
34
* Copyright (C) 1994-1999 RSA Security Inc. Licence to copy this document
35
* is granted provided that it is identified as "RSA Security In.c Public-Key
36
* Cryptography Standards (PKCS)" in all material mentioning or referencing
39
* The latest version of this header can be found at:
40
* http://www.rsalabs.com/pkcs/pkcs-11/index.html
49
/* Before including this file (pkcs11.h) (or pkcs11t.h by
50
* itself), 6 platform-specific macros must be defined. These
51
* macros are described below, and typical definitions for them
52
* are also given. Be advised that these definitions can depend
53
* on both the platform and the compiler used (and possibly also
54
* on whether a PKCS #11 library is linked statically or
57
* In addition to defining these 6 macros, the packing convention
58
* for PKCS #11 structures should be set. The PKCS #11
59
* convention on packing is that structures should be 1-byte
62
* In a Win32 environment, this might be done by using the
63
* following preprocessor directive before including pkcs11.h
66
* #pragma pack(push, cryptoki, 1)
68
* and using the following preprocessor directive after including
69
* pkcs11.h or pkcs11t.h:
71
* #pragma pack(pop, cryptoki)
73
* In a Win16 environment, this might be done by using the
74
* following preprocessor directive before including pkcs11.h
79
* In a UNIX environment, you're on your own here. You might
80
* not need to do anything.
86
* 1. CK_PTR: The indirection string for making a pointer to an
87
* object. It can be used like this:
89
* typedef CK_BYTE CK_PTR CK_BYTE_PTR;
91
* In a Win32 environment, it might be defined by
95
* In a Win16 environment, it might be defined by
97
* #define CK_PTR far *
99
* In a UNIX environment, it might be defined by
104
* 2. CK_DEFINE_FUNCTION(returnType, name): A macro which makes
105
* an exportable PKCS #11 library function definition out of a
106
* return type and a function name. It should be used in the
107
* following fashion to define the exposed PKCS #11 functions in
108
* a PKCS #11 library:
110
* CK_DEFINE_FUNCTION(CK_RV, C_Initialize)(
111
* CK_VOID_PTR pReserved
117
* For defining a function in a Win32 PKCS #11 .dll, it might be
120
* #define CK_DEFINE_FUNCTION(returnType, name) \
121
* returnType __declspec(dllexport) name
123
* For defining a function in a Win16 PKCS #11 .dll, it might be
126
* #define CK_DEFINE_FUNCTION(returnType, name) \
127
* returnType __export _far _pascal name
129
* In a UNIX environment, it might be defined by
131
* #define CK_DEFINE_FUNCTION(returnType, name) \
135
* 3. CK_DECLARE_FUNCTION(returnType, name): A macro which makes
136
* an importable PKCS #11 library function declaration out of a
137
* return type and a function name. It should be used in the
140
* extern CK_DECLARE_FUNCTION(CK_RV, C_Initialize)(
141
* CK_VOID_PTR pReserved
144
* For declaring a function in a Win32 PKCS #11 .dll, it might
147
* #define CK_DECLARE_FUNCTION(returnType, name) \
148
* returnType __declspec(dllimport) name
150
* For declaring a function in a Win16 PKCS #11 .dll, it might
153
* #define CK_DECLARE_FUNCTION(returnType, name) \
154
* returnType __export _far _pascal name
156
* In a UNIX environment, it might be defined by
158
* #define CK_DECLARE_FUNCTION(returnType, name) \
162
* 4. CK_DECLARE_FUNCTION_POINTER(returnType, name): A macro
163
* which makes a PKCS #11 API function pointer declaration or
164
* function pointer type declaration out of a return type and a
165
* function name. It should be used in the following fashion:
167
* // Define funcPtr to be a pointer to a PKCS #11 API function
168
* // taking arguments args and returning CK_RV.
169
* CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtr)(args);
173
* // Define funcPtrType to be the type of a pointer to a
174
* // PKCS #11 API function taking arguments args and returning
175
* // CK_RV, and then define funcPtr to be a variable of type
177
* typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtrType)(args);
178
* funcPtrType funcPtr;
180
* For accessing functions in a Win32 PKCS #11 .dll, in might be
183
* #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
184
* returnType __declspec(dllimport) (* name)
186
* For accessing functions in a Win16 PKCS #11 .dll, it might be
189
* #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
190
* returnType __export _far _pascal (* name)
192
* In a UNIX environment, it might be defined by
194
* #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
195
* returnType (* name)
198
* 5. CK_CALLBACK_FUNCTION(returnType, name): A macro which makes
199
* a function pointer type for an application callback out of
200
* a return type for the callback and a name for the callback.
201
* It should be used in the following fashion:
203
* CK_CALLBACK_FUNCTION(CK_RV, myCallback)(args);
205
* to declare a function pointer, myCallback, to a callback
206
* which takes arguments args and returns a CK_RV. It can also
209
* typedef CK_CALLBACK_FUNCTION(CK_RV, myCallbackType)(args);
210
* myCallbackType myCallback;
212
* In a Win32 environment, it might be defined by
214
* #define CK_CALLBACK_FUNCTION(returnType, name) \
215
* returnType (* name)
217
* In a Win16 environment, it might be defined by
219
* #define CK_CALLBACK_FUNCTION(returnType, name) \
220
* returnType _far _pascal (* name)
222
* In a UNIX environment, it might be defined by
224
* #define CK_CALLBACK_FUNCTION(returnType, name) \
225
* returnType (* name)
228
* 6. NULL_PTR: This macro is the value of a NULL pointer.
230
* In any ANSI/ISO C environment (and in many others as well),
231
* this should be defined by
239
/* All the various PKCS #11 types and #define'd values are in the
243
#define __PASTE(x,y) x##y
246
/* packing defines */
248
/* ==============================================================
249
* Define the "extern" form of all the entry points.
250
* ==============================================================
253
#define CK_NEED_ARG_LIST 1
254
#define CK_PKCS11_FUNCTION_INFO(name) \
255
CK_DECLARE_FUNCTION(CK_RV, name)
257
/* pkcs11f.h has all the information about the PKCS #11
258
* function prototypes. */
261
#undef CK_NEED_ARG_LIST
262
#undef CK_PKCS11_FUNCTION_INFO
265
/* ==============================================================
266
* Define the typedef form of all the entry points. That is, for
267
* each PKCS #11 function C_XXX, define a type CK_C_XXX which is
268
* a pointer to that kind of function.
269
* ==============================================================
272
#define CK_NEED_ARG_LIST 1
273
#define CK_PKCS11_FUNCTION_INFO(name) \
274
typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, __PASTE(CK_,name))
276
/* pkcs11f.h has all the information about the PKCS #11
277
* function prototypes. */
280
#undef CK_NEED_ARG_LIST
281
#undef CK_PKCS11_FUNCTION_INFO
284
/* ==============================================================
285
* Define structed vector of entry points. A CK_FUNCTION_LIST
286
* contains a CK_VERSION indicating a library's PKCS #11 version
287
* and then a whole slew of function pointers to the routines in
288
* the library. This type was declared, but not defined, in
290
* ==============================================================
293
#define CK_PKCS11_FUNCTION_INFO(name) \
294
__PASTE(CK_,name) name;
296
struct CK_FUNCTION_LIST {
298
CK_VERSION version; /* PKCS #11 version */
300
/* Pile all the function pointers into the CK_FUNCTION_LIST. */
301
/* pkcs11f.h has all the information about the PKCS #11
302
* function prototypes. */
307
#undef CK_PKCS11_FUNCTION_INFO