PageRenderTime 10ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/gecko_api/include/pkcs11.h

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