security/nss/lib/util/pkcs11.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/nss/lib/util/pkcs11.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,257 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +/*
     1.8 + * Copyright (C) 1994-1999 RSA Security Inc. Licence to copy this document
     1.9 + * is granted provided that it is identified as "RSA Security In.c Public-Key
    1.10 + * Cryptography Standards (PKCS)" in all material mentioning or referencing
    1.11 + * this document.
    1.12 + *
    1.13 + * The latest version of this header can be found at:
    1.14 + *    http://www.rsalabs.com/pkcs/pkcs-11/index.html
    1.15 + */
    1.16 +#ifndef _PKCS11_H_
    1.17 +#define _PKCS11_H_ 1
    1.18 +
    1.19 +#ifdef __cplusplus
    1.20 +extern "C" {
    1.21 +#endif
    1.22 +
    1.23 +/* Before including this file (pkcs11.h) (or pkcs11t.h by
    1.24 + * itself), 6 platform-specific macros must be defined.  These
    1.25 + * macros are described below, and typical definitions for them
    1.26 + * are also given.  Be advised that these definitions can depend
    1.27 + * on both the platform and the compiler used (and possibly also
    1.28 + * on whether a PKCS #11 library is linked statically or
    1.29 + * dynamically).
    1.30 + *
    1.31 + * In addition to defining these 6 macros, the packing convention
    1.32 + * for PKCS #11 structures should be set.  The PKCS #11
    1.33 + * convention on packing is that structures should be 1-byte
    1.34 + * aligned.
    1.35 + *
    1.36 + * In a Win32 environment, this might be done by using the
    1.37 + * following preprocessor directive before including pkcs11.h
    1.38 + * or pkcs11t.h:
    1.39 + *
    1.40 + * #pragma pack(push, cryptoki, 1)
    1.41 + *
    1.42 + * and using the following preprocessor directive after including
    1.43 + * pkcs11.h or pkcs11t.h:
    1.44 + *
    1.45 + * #pragma pack(pop, cryptoki)
    1.46 + *
    1.47 + * In a UNIX environment, you're on your own here.  You might
    1.48 + * not need to do anything.
    1.49 + *
    1.50 + *
    1.51 + * Now for the macros:
    1.52 + *
    1.53 + *
    1.54 + * 1. CK_PTR: The indirection string for making a pointer to an
    1.55 + * object.  It can be used like this:
    1.56 + *
    1.57 + * typedef CK_BYTE CK_PTR CK_BYTE_PTR;
    1.58 + *
    1.59 + * In a Win32 environment, it might be defined by
    1.60 + *
    1.61 + * #define CK_PTR *
    1.62 + *
    1.63 + * In a UNIX environment, it might be defined by
    1.64 + *
    1.65 + * #define CK_PTR *
    1.66 + *
    1.67 + *
    1.68 + * 2. CK_DEFINE_FUNCTION(returnType, name): A macro which makes
    1.69 + * an exportable PKCS #11 library function definition out of a
    1.70 + * return type and a function name.  It should be used in the
    1.71 + * following fashion to define the exposed PKCS #11 functions in
    1.72 + * a PKCS #11 library:
    1.73 + *
    1.74 + * CK_DEFINE_FUNCTION(CK_RV, C_Initialize)(
    1.75 + *   CK_VOID_PTR pReserved
    1.76 + * )
    1.77 + * {
    1.78 + *   ...
    1.79 + * }
    1.80 + *
    1.81 + * For defining a function in a Win32 PKCS #11 .dll, it might be
    1.82 + * defined by
    1.83 + *
    1.84 + * #define CK_DEFINE_FUNCTION(returnType, name) \
    1.85 + *   returnType __declspec(dllexport) name
    1.86 + *
    1.87 + * In a UNIX environment, it might be defined by
    1.88 + *
    1.89 + * #define CK_DEFINE_FUNCTION(returnType, name) \
    1.90 + *   returnType name
    1.91 + *
    1.92 + *
    1.93 + * 3. CK_DECLARE_FUNCTION(returnType, name): A macro which makes
    1.94 + * an importable PKCS #11 library function declaration out of a
    1.95 + * return type and a function name.  It should be used in the
    1.96 + * following fashion:
    1.97 + *
    1.98 + * extern CK_DECLARE_FUNCTION(CK_RV, C_Initialize)(
    1.99 + *   CK_VOID_PTR pReserved
   1.100 + * );
   1.101 + *
   1.102 + * For declaring a function in a Win32 PKCS #11 .dll, it might
   1.103 + * be defined by
   1.104 + *
   1.105 + * #define CK_DECLARE_FUNCTION(returnType, name) \
   1.106 + *   returnType __declspec(dllimport) name
   1.107 + *
   1.108 + * In a UNIX environment, it might be defined by
   1.109 + *
   1.110 + * #define CK_DECLARE_FUNCTION(returnType, name) \
   1.111 + *   returnType name
   1.112 + *
   1.113 + *
   1.114 + * 4. CK_DECLARE_FUNCTION_POINTER(returnType, name): A macro
   1.115 + * which makes a PKCS #11 API function pointer declaration or
   1.116 + * function pointer type declaration out of a return type and a
   1.117 + * function name.  It should be used in the following fashion:
   1.118 + *
   1.119 + * // Define funcPtr to be a pointer to a PKCS #11 API function
   1.120 + * // taking arguments args and returning CK_RV.
   1.121 + * CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtr)(args);
   1.122 + *
   1.123 + * or
   1.124 + *
   1.125 + * // Define funcPtrType to be the type of a pointer to a
   1.126 + * // PKCS #11 API function taking arguments args and returning
   1.127 + * // CK_RV, and then define funcPtr to be a variable of type
   1.128 + * // funcPtrType.
   1.129 + * typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtrType)(args);
   1.130 + * funcPtrType funcPtr;
   1.131 + *
   1.132 + * For accessing functions in a Win32 PKCS #11 .dll, in might be
   1.133 + * defined by
   1.134 + *
   1.135 + * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
   1.136 + *   returnType __declspec(dllimport) (* name)
   1.137 + *
   1.138 + * In a UNIX environment, it might be defined by
   1.139 + *
   1.140 + * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
   1.141 + *   returnType (* name)
   1.142 + *
   1.143 + *
   1.144 + * 5. CK_CALLBACK_FUNCTION(returnType, name): A macro which makes
   1.145 + * a function pointer type for an application callback out of
   1.146 + * a return type for the callback and a name for the callback.
   1.147 + * It should be used in the following fashion:
   1.148 + *
   1.149 + * CK_CALLBACK_FUNCTION(CK_RV, myCallback)(args);
   1.150 + *
   1.151 + * to declare a function pointer, myCallback, to a callback
   1.152 + * which takes arguments args and returns a CK_RV.  It can also
   1.153 + * be used like this:
   1.154 + *
   1.155 + * typedef CK_CALLBACK_FUNCTION(CK_RV, myCallbackType)(args);
   1.156 + * myCallbackType myCallback;
   1.157 + *
   1.158 + * In a Win32 environment, it might be defined by
   1.159 + *
   1.160 + * #define CK_CALLBACK_FUNCTION(returnType, name) \
   1.161 + *   returnType (* name)
   1.162 + *
   1.163 + * In a UNIX environment, it might be defined by
   1.164 + *
   1.165 + * #define CK_CALLBACK_FUNCTION(returnType, name) \
   1.166 + *   returnType (* name)
   1.167 + *
   1.168 + *
   1.169 + * 6. NULL_PTR: This macro is the value of a NULL pointer.
   1.170 + *
   1.171 + * In any ANSI/ISO C environment (and in many others as well),
   1.172 + * this should be defined by
   1.173 + *
   1.174 + * #ifndef NULL_PTR
   1.175 + * #define NULL_PTR 0
   1.176 + * #endif
   1.177 + */
   1.178 +
   1.179 +
   1.180 +/* All the various PKCS #11 types and #define'd values are in the
   1.181 + * file pkcs11t.h. */
   1.182 +#include "pkcs11t.h"
   1.183 +
   1.184 +#define __PASTE(x,y)      x##y
   1.185 +
   1.186 +
   1.187 +/* packing defines */
   1.188 +#include "pkcs11p.h"
   1.189 +/* ==============================================================
   1.190 + * Define the "extern" form of all the entry points.
   1.191 + * ==============================================================
   1.192 + */
   1.193 +
   1.194 +#define CK_NEED_ARG_LIST  1
   1.195 +#define CK_PKCS11_FUNCTION_INFO(name) \
   1.196 +  CK_DECLARE_FUNCTION(CK_RV, name)
   1.197 +
   1.198 +/* pkcs11f.h has all the information about the PKCS #11
   1.199 + * function prototypes. */
   1.200 +#include "pkcs11f.h"
   1.201 +
   1.202 +#undef CK_NEED_ARG_LIST
   1.203 +#undef CK_PKCS11_FUNCTION_INFO
   1.204 +
   1.205 +
   1.206 +/* ==============================================================
   1.207 + * Define the typedef form of all the entry points.  That is, for
   1.208 + * each PKCS #11 function C_XXX, define a type CK_C_XXX which is
   1.209 + * a pointer to that kind of function.
   1.210 + * ==============================================================
   1.211 + */
   1.212 +
   1.213 +#define CK_NEED_ARG_LIST  1
   1.214 +#define CK_PKCS11_FUNCTION_INFO(name) \
   1.215 +  typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, __PASTE(CK_,name))
   1.216 +
   1.217 +/* pkcs11f.h has all the information about the PKCS #11
   1.218 + * function prototypes. */
   1.219 +#include "pkcs11f.h"
   1.220 +
   1.221 +#undef CK_NEED_ARG_LIST
   1.222 +#undef CK_PKCS11_FUNCTION_INFO
   1.223 +
   1.224 +
   1.225 +/* ==============================================================
   1.226 + * Define structed vector of entry points.  A CK_FUNCTION_LIST
   1.227 + * contains a CK_VERSION indicating a library's PKCS #11 version
   1.228 + * and then a whole slew of function pointers to the routines in
   1.229 + * the library.  This type was declared, but not defined, in
   1.230 + * pkcs11t.h.
   1.231 + * ==============================================================
   1.232 + */
   1.233 +
   1.234 +#define CK_PKCS11_FUNCTION_INFO(name) \
   1.235 +  __PASTE(CK_,name) name;
   1.236 +  
   1.237 +struct CK_FUNCTION_LIST {
   1.238 +
   1.239 +  CK_VERSION    version;  /* PKCS #11 version */
   1.240 +
   1.241 +/* Pile all the function pointers into the CK_FUNCTION_LIST. */
   1.242 +/* pkcs11f.h has all the information about the PKCS #11
   1.243 + * function prototypes. */
   1.244 +#include "pkcs11f.h" 
   1.245 +
   1.246 +};
   1.247 +
   1.248 +#undef CK_PKCS11_FUNCTION_INFO
   1.249 +
   1.250 +
   1.251 +#undef __PASTE
   1.252 +
   1.253 +/* unpack */
   1.254 +#include "pkcs11u.h"
   1.255 +
   1.256 +#ifdef __cplusplus
   1.257 +}
   1.258 +#endif
   1.259 +
   1.260 +#endif

mercurial