pkcs11.h 9.1 KB

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