pkcs11.h 7.8 KB

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