pkcs11.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /* Copyright (c) OASIS Open 2016. All Rights Reserved./
  2. * /Distributed under the terms of the OASIS IPR Policy,
  3. * [http://www.oasis-open.org/policies-guidelines/ipr], AS-IS, WITHOUT ANY
  4. * IMPLIED OR EXPRESS WARRANTY; there is no warranty of MERCHANTABILITY, FITNESS FOR A
  5. * PARTICULAR PURPOSE or NONINFRINGEMENT of the rights of others.
  6. */
  7. /* Latest version of the specification:
  8. * http://docs.oasis-open.org/pkcs11/pkcs11-base/v2.40/pkcs11-base-v2.40.html
  9. */
  10. #ifndef _PKCS11_H_
  11. #define _PKCS11_H_ 1
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. /* Before including this file (pkcs11.h) (or pkcs11t.h by
  16. * itself), 5 platform-specific macros must be defined. These
  17. * macros are described below, and typical definitions for them
  18. * are also given. Be advised that these definitions can depend
  19. * on both the platform and the compiler used (and possibly also
  20. * on whether a Cryptoki library is linked statically or
  21. * dynamically).
  22. *
  23. * In addition to defining these 5 macros, the packing convention
  24. * for Cryptoki structures should be set. The Cryptoki
  25. * convention on packing is that structures should be 1-byte
  26. * aligned.
  27. *
  28. * If you're using Microsoft Developer Studio 5.0 to produce
  29. * Win32 stuff, this might be done by using the following
  30. * preprocessor directive before including pkcs11.h or pkcs11t.h:
  31. *
  32. * #pragma pack(push, cryptoki, 1)
  33. *
  34. * and using the following preprocessor directive after including
  35. * pkcs11.h or pkcs11t.h:
  36. *
  37. * #pragma pack(pop, cryptoki)
  38. *
  39. * If you're using an earlier version of Microsoft Developer
  40. * Studio to produce Win16 stuff, this might be done by using
  41. * the following preprocessor directive before including
  42. * pkcs11.h or pkcs11t.h:
  43. *
  44. * #pragma pack(1)
  45. *
  46. * In a UNIX environment, you're on your own for this. You might
  47. * not need to do (or be able to do!) anything.
  48. *
  49. *
  50. * Now for the macros:
  51. *
  52. *
  53. * 1. CK_PTR: The indirection string for making a pointer to an
  54. * object. It can be used like this:
  55. *
  56. * typedef CK_BYTE CK_PTR CK_BYTE_PTR;
  57. *
  58. * If you're using Microsoft Developer Studio 5.0 to produce
  59. * Win32 stuff, it might be defined by:
  60. *
  61. * #define CK_PTR *
  62. *
  63. * If you're using an earlier version of Microsoft Developer
  64. * Studio to produce Win16 stuff, it might be defined by:
  65. *
  66. * #define CK_PTR far *
  67. *
  68. * In a typical UNIX environment, it might be defined by:
  69. *
  70. * #define CK_PTR *
  71. *
  72. *
  73. * 2. CK_DECLARE_FUNCTION(returnType, name): A macro which makes
  74. * an importable Cryptoki library function declaration out of a
  75. * return type and a function name. It should be used in the
  76. * following fashion:
  77. *
  78. * extern CK_DECLARE_FUNCTION(CK_RV, C_Initialize)(
  79. * CK_VOID_PTR pReserved
  80. * );
  81. *
  82. * If you're using Microsoft Developer Studio 5.0 to declare a
  83. * function in a Win32 Cryptoki .dll, it might be defined by:
  84. *
  85. * #define CK_DECLARE_FUNCTION(returnType, name) \
  86. * returnType __declspec(dllimport) name
  87. *
  88. * If you're using an earlier version of Microsoft Developer
  89. * Studio to declare a function in a Win16 Cryptoki .dll, it
  90. * might be defined by:
  91. *
  92. * #define CK_DECLARE_FUNCTION(returnType, name) \
  93. * returnType __export _far _pascal name
  94. *
  95. * In a UNIX environment, it might be defined by:
  96. *
  97. * #define CK_DECLARE_FUNCTION(returnType, name) \
  98. * returnType name
  99. *
  100. *
  101. * 3. CK_DECLARE_FUNCTION_POINTER(returnType, name): A macro
  102. * which makes a Cryptoki API function pointer declaration or
  103. * function pointer type declaration out of a return type and a
  104. * function name. It should be used in the following fashion:
  105. *
  106. * // Define funcPtr to be a pointer to a Cryptoki API function
  107. * // taking arguments args and returning CK_RV.
  108. * CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtr)(args);
  109. *
  110. * or
  111. *
  112. * // Define funcPtrType to be the type of a pointer to a
  113. * // Cryptoki API function taking arguments args and returning
  114. * // CK_RV, and then define funcPtr to be a variable of type
  115. * // funcPtrType.
  116. * typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtrType)(args);
  117. * funcPtrType funcPtr;
  118. *
  119. * If you're using Microsoft Developer Studio 5.0 to access
  120. * functions in a Win32 Cryptoki .dll, in might be defined by:
  121. *
  122. * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
  123. * returnType __declspec(dllimport) (* name)
  124. *
  125. * If you're using an earlier version of Microsoft Developer
  126. * Studio to access functions in a Win16 Cryptoki .dll, it might
  127. * be defined by:
  128. *
  129. * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
  130. * returnType __export _far _pascal (* name)
  131. *
  132. * In a UNIX environment, it might be defined by:
  133. *
  134. * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
  135. * returnType (* name)
  136. *
  137. *
  138. * 4. CK_CALLBACK_FUNCTION(returnType, name): A macro which makes
  139. * a function pointer type for an application callback out of
  140. * a return type for the callback and a name for the callback.
  141. * It should be used in the following fashion:
  142. *
  143. * CK_CALLBACK_FUNCTION(CK_RV, myCallback)(args);
  144. *
  145. * to declare a function pointer, myCallback, to a callback
  146. * which takes arguments args and returns a CK_RV. It can also
  147. * be used like this:
  148. *
  149. * typedef CK_CALLBACK_FUNCTION(CK_RV, myCallbackType)(args);
  150. * myCallbackType myCallback;
  151. *
  152. * If you're using Microsoft Developer Studio 5.0 to do Win32
  153. * Cryptoki development, it might be defined by:
  154. *
  155. * #define CK_CALLBACK_FUNCTION(returnType, name) \
  156. * returnType (* name)
  157. *
  158. * If you're using an earlier version of Microsoft Developer
  159. * Studio to do Win16 development, it might be defined by:
  160. *
  161. * #define CK_CALLBACK_FUNCTION(returnType, name) \
  162. * returnType _far _pascal (* name)
  163. *
  164. * In a UNIX environment, it might be defined by:
  165. *
  166. * #define CK_CALLBACK_FUNCTION(returnType, name) \
  167. * returnType (* name)
  168. *
  169. *
  170. * 5. NULL_PTR: This macro is the value of a NULL pointer.
  171. *
  172. * In any ANSI/ISO C environment (and in many others as well),
  173. * this should best be defined by
  174. *
  175. * #ifndef NULL_PTR
  176. * #define NULL_PTR 0
  177. * #endif
  178. */
  179. /* All the various Cryptoki types and #define'd values are in the
  180. * file pkcs11t.h.
  181. */
  182. #include "pkcs11t.h"
  183. #define __PASTE(x,y) x##y
  184. /* ==============================================================
  185. * Define the "extern" form of all the entry points.
  186. * ==============================================================
  187. */
  188. #define CK_NEED_ARG_LIST 1
  189. #define CK_PKCS11_FUNCTION_INFO(name) \
  190. extern CK_DECLARE_FUNCTION(CK_RV, name)
  191. /* pkcs11f.h has all the information about the Cryptoki
  192. * function prototypes.
  193. */
  194. #include "pkcs11f.h"
  195. #undef CK_NEED_ARG_LIST
  196. #undef CK_PKCS11_FUNCTION_INFO
  197. /* ==============================================================
  198. * Define the typedef form of all the entry points. That is, for
  199. * each Cryptoki function C_XXX, define a type CK_C_XXX which is
  200. * a pointer to that kind of function.
  201. * ==============================================================
  202. */
  203. #define CK_NEED_ARG_LIST 1
  204. #define CK_PKCS11_FUNCTION_INFO(name) \
  205. typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, __PASTE(CK_,name))
  206. /* pkcs11f.h has all the information about the Cryptoki
  207. * function prototypes.
  208. */
  209. #include "pkcs11f.h"
  210. #undef CK_NEED_ARG_LIST
  211. #undef CK_PKCS11_FUNCTION_INFO
  212. /* ==============================================================
  213. * Define structed vector of entry points. A CK_FUNCTION_LIST
  214. * contains a CK_VERSION indicating a library's Cryptoki version
  215. * and then a whole slew of function pointers to the routines in
  216. * the library. This type was declared, but not defined, in
  217. * pkcs11t.h.
  218. * ==============================================================
  219. */
  220. #define CK_PKCS11_FUNCTION_INFO(name) \
  221. __PASTE(CK_,name) name;
  222. struct CK_FUNCTION_LIST {
  223. CK_VERSION version; /* Cryptoki version */
  224. /* Pile all the function pointers into the CK_FUNCTION_LIST. */
  225. /* pkcs11f.h has all the information about the Cryptoki
  226. * function prototypes.
  227. */
  228. #include "pkcs11f.h"
  229. };
  230. #undef CK_PKCS11_FUNCTION_INFO
  231. #undef __PASTE
  232. #ifdef __cplusplus
  233. }
  234. #endif
  235. #endif /* _PKCS11_H_ */