security/nss/lib/util/pkcs11.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4 /*
michael@0 5 * Copyright (C) 1994-1999 RSA Security Inc. Licence to copy this document
michael@0 6 * is granted provided that it is identified as "RSA Security In.c Public-Key
michael@0 7 * Cryptography Standards (PKCS)" in all material mentioning or referencing
michael@0 8 * this document.
michael@0 9 *
michael@0 10 * The latest version of this header can be found at:
michael@0 11 * http://www.rsalabs.com/pkcs/pkcs-11/index.html
michael@0 12 */
michael@0 13 #ifndef _PKCS11_H_
michael@0 14 #define _PKCS11_H_ 1
michael@0 15
michael@0 16 #ifdef __cplusplus
michael@0 17 extern "C" {
michael@0 18 #endif
michael@0 19
michael@0 20 /* Before including this file (pkcs11.h) (or pkcs11t.h by
michael@0 21 * itself), 6 platform-specific macros must be defined. These
michael@0 22 * macros are described below, and typical definitions for them
michael@0 23 * are also given. Be advised that these definitions can depend
michael@0 24 * on both the platform and the compiler used (and possibly also
michael@0 25 * on whether a PKCS #11 library is linked statically or
michael@0 26 * dynamically).
michael@0 27 *
michael@0 28 * In addition to defining these 6 macros, the packing convention
michael@0 29 * for PKCS #11 structures should be set. The PKCS #11
michael@0 30 * convention on packing is that structures should be 1-byte
michael@0 31 * aligned.
michael@0 32 *
michael@0 33 * In a Win32 environment, this might be done by using the
michael@0 34 * following preprocessor directive before including pkcs11.h
michael@0 35 * or pkcs11t.h:
michael@0 36 *
michael@0 37 * #pragma pack(push, cryptoki, 1)
michael@0 38 *
michael@0 39 * and using the following preprocessor directive after including
michael@0 40 * pkcs11.h or pkcs11t.h:
michael@0 41 *
michael@0 42 * #pragma pack(pop, cryptoki)
michael@0 43 *
michael@0 44 * In a UNIX environment, you're on your own here. You might
michael@0 45 * not need to do anything.
michael@0 46 *
michael@0 47 *
michael@0 48 * Now for the macros:
michael@0 49 *
michael@0 50 *
michael@0 51 * 1. CK_PTR: The indirection string for making a pointer to an
michael@0 52 * object. It can be used like this:
michael@0 53 *
michael@0 54 * typedef CK_BYTE CK_PTR CK_BYTE_PTR;
michael@0 55 *
michael@0 56 * In a Win32 environment, it might be defined by
michael@0 57 *
michael@0 58 * #define CK_PTR *
michael@0 59 *
michael@0 60 * In a UNIX environment, it might be defined by
michael@0 61 *
michael@0 62 * #define CK_PTR *
michael@0 63 *
michael@0 64 *
michael@0 65 * 2. CK_DEFINE_FUNCTION(returnType, name): A macro which makes
michael@0 66 * an exportable PKCS #11 library function definition out of a
michael@0 67 * return type and a function name. It should be used in the
michael@0 68 * following fashion to define the exposed PKCS #11 functions in
michael@0 69 * a PKCS #11 library:
michael@0 70 *
michael@0 71 * CK_DEFINE_FUNCTION(CK_RV, C_Initialize)(
michael@0 72 * CK_VOID_PTR pReserved
michael@0 73 * )
michael@0 74 * {
michael@0 75 * ...
michael@0 76 * }
michael@0 77 *
michael@0 78 * For defining a function in a Win32 PKCS #11 .dll, it might be
michael@0 79 * defined by
michael@0 80 *
michael@0 81 * #define CK_DEFINE_FUNCTION(returnType, name) \
michael@0 82 * returnType __declspec(dllexport) name
michael@0 83 *
michael@0 84 * In a UNIX environment, it might be defined by
michael@0 85 *
michael@0 86 * #define CK_DEFINE_FUNCTION(returnType, name) \
michael@0 87 * returnType name
michael@0 88 *
michael@0 89 *
michael@0 90 * 3. CK_DECLARE_FUNCTION(returnType, name): A macro which makes
michael@0 91 * an importable PKCS #11 library function declaration out of a
michael@0 92 * return type and a function name. It should be used in the
michael@0 93 * following fashion:
michael@0 94 *
michael@0 95 * extern CK_DECLARE_FUNCTION(CK_RV, C_Initialize)(
michael@0 96 * CK_VOID_PTR pReserved
michael@0 97 * );
michael@0 98 *
michael@0 99 * For declaring a function in a Win32 PKCS #11 .dll, it might
michael@0 100 * be defined by
michael@0 101 *
michael@0 102 * #define CK_DECLARE_FUNCTION(returnType, name) \
michael@0 103 * returnType __declspec(dllimport) name
michael@0 104 *
michael@0 105 * In a UNIX environment, it might be defined by
michael@0 106 *
michael@0 107 * #define CK_DECLARE_FUNCTION(returnType, name) \
michael@0 108 * returnType name
michael@0 109 *
michael@0 110 *
michael@0 111 * 4. CK_DECLARE_FUNCTION_POINTER(returnType, name): A macro
michael@0 112 * which makes a PKCS #11 API function pointer declaration or
michael@0 113 * function pointer type declaration out of a return type and a
michael@0 114 * function name. It should be used in the following fashion:
michael@0 115 *
michael@0 116 * // Define funcPtr to be a pointer to a PKCS #11 API function
michael@0 117 * // taking arguments args and returning CK_RV.
michael@0 118 * CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtr)(args);
michael@0 119 *
michael@0 120 * or
michael@0 121 *
michael@0 122 * // Define funcPtrType to be the type of a pointer to a
michael@0 123 * // PKCS #11 API function taking arguments args and returning
michael@0 124 * // CK_RV, and then define funcPtr to be a variable of type
michael@0 125 * // funcPtrType.
michael@0 126 * typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtrType)(args);
michael@0 127 * funcPtrType funcPtr;
michael@0 128 *
michael@0 129 * For accessing functions in a Win32 PKCS #11 .dll, in might be
michael@0 130 * defined by
michael@0 131 *
michael@0 132 * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
michael@0 133 * returnType __declspec(dllimport) (* name)
michael@0 134 *
michael@0 135 * In a UNIX environment, it might be defined by
michael@0 136 *
michael@0 137 * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
michael@0 138 * returnType (* name)
michael@0 139 *
michael@0 140 *
michael@0 141 * 5. CK_CALLBACK_FUNCTION(returnType, name): A macro which makes
michael@0 142 * a function pointer type for an application callback out of
michael@0 143 * a return type for the callback and a name for the callback.
michael@0 144 * It should be used in the following fashion:
michael@0 145 *
michael@0 146 * CK_CALLBACK_FUNCTION(CK_RV, myCallback)(args);
michael@0 147 *
michael@0 148 * to declare a function pointer, myCallback, to a callback
michael@0 149 * which takes arguments args and returns a CK_RV. It can also
michael@0 150 * be used like this:
michael@0 151 *
michael@0 152 * typedef CK_CALLBACK_FUNCTION(CK_RV, myCallbackType)(args);
michael@0 153 * myCallbackType myCallback;
michael@0 154 *
michael@0 155 * In a Win32 environment, it might be defined by
michael@0 156 *
michael@0 157 * #define CK_CALLBACK_FUNCTION(returnType, name) \
michael@0 158 * returnType (* name)
michael@0 159 *
michael@0 160 * In a UNIX environment, it might be defined by
michael@0 161 *
michael@0 162 * #define CK_CALLBACK_FUNCTION(returnType, name) \
michael@0 163 * returnType (* name)
michael@0 164 *
michael@0 165 *
michael@0 166 * 6. NULL_PTR: This macro is the value of a NULL pointer.
michael@0 167 *
michael@0 168 * In any ANSI/ISO C environment (and in many others as well),
michael@0 169 * this should be defined by
michael@0 170 *
michael@0 171 * #ifndef NULL_PTR
michael@0 172 * #define NULL_PTR 0
michael@0 173 * #endif
michael@0 174 */
michael@0 175
michael@0 176
michael@0 177 /* All the various PKCS #11 types and #define'd values are in the
michael@0 178 * file pkcs11t.h. */
michael@0 179 #include "pkcs11t.h"
michael@0 180
michael@0 181 #define __PASTE(x,y) x##y
michael@0 182
michael@0 183
michael@0 184 /* packing defines */
michael@0 185 #include "pkcs11p.h"
michael@0 186 /* ==============================================================
michael@0 187 * Define the "extern" form of all the entry points.
michael@0 188 * ==============================================================
michael@0 189 */
michael@0 190
michael@0 191 #define CK_NEED_ARG_LIST 1
michael@0 192 #define CK_PKCS11_FUNCTION_INFO(name) \
michael@0 193 CK_DECLARE_FUNCTION(CK_RV, name)
michael@0 194
michael@0 195 /* pkcs11f.h has all the information about the PKCS #11
michael@0 196 * function prototypes. */
michael@0 197 #include "pkcs11f.h"
michael@0 198
michael@0 199 #undef CK_NEED_ARG_LIST
michael@0 200 #undef CK_PKCS11_FUNCTION_INFO
michael@0 201
michael@0 202
michael@0 203 /* ==============================================================
michael@0 204 * Define the typedef form of all the entry points. That is, for
michael@0 205 * each PKCS #11 function C_XXX, define a type CK_C_XXX which is
michael@0 206 * a pointer to that kind of function.
michael@0 207 * ==============================================================
michael@0 208 */
michael@0 209
michael@0 210 #define CK_NEED_ARG_LIST 1
michael@0 211 #define CK_PKCS11_FUNCTION_INFO(name) \
michael@0 212 typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, __PASTE(CK_,name))
michael@0 213
michael@0 214 /* pkcs11f.h has all the information about the PKCS #11
michael@0 215 * function prototypes. */
michael@0 216 #include "pkcs11f.h"
michael@0 217
michael@0 218 #undef CK_NEED_ARG_LIST
michael@0 219 #undef CK_PKCS11_FUNCTION_INFO
michael@0 220
michael@0 221
michael@0 222 /* ==============================================================
michael@0 223 * Define structed vector of entry points. A CK_FUNCTION_LIST
michael@0 224 * contains a CK_VERSION indicating a library's PKCS #11 version
michael@0 225 * and then a whole slew of function pointers to the routines in
michael@0 226 * the library. This type was declared, but not defined, in
michael@0 227 * pkcs11t.h.
michael@0 228 * ==============================================================
michael@0 229 */
michael@0 230
michael@0 231 #define CK_PKCS11_FUNCTION_INFO(name) \
michael@0 232 __PASTE(CK_,name) name;
michael@0 233
michael@0 234 struct CK_FUNCTION_LIST {
michael@0 235
michael@0 236 CK_VERSION version; /* PKCS #11 version */
michael@0 237
michael@0 238 /* Pile all the function pointers into the CK_FUNCTION_LIST. */
michael@0 239 /* pkcs11f.h has all the information about the PKCS #11
michael@0 240 * function prototypes. */
michael@0 241 #include "pkcs11f.h"
michael@0 242
michael@0 243 };
michael@0 244
michael@0 245 #undef CK_PKCS11_FUNCTION_INFO
michael@0 246
michael@0 247
michael@0 248 #undef __PASTE
michael@0 249
michael@0 250 /* unpack */
michael@0 251 #include "pkcs11u.h"
michael@0 252
michael@0 253 #ifdef __cplusplus
michael@0 254 }
michael@0 255 #endif
michael@0 256
michael@0 257 #endif

mercurial