pkcs11.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358
  1. /* $OpenBSD: pkcs11.h,v 1.3 2013/11/26 19:15:09 deraadt Exp $ */
  2. /* pkcs11.h
  3. Copyright 2006, 2007 g10 Code GmbH
  4. Copyright 2006 Andreas Jellinghaus
  5. This file is free software; as a special exception the author gives
  6. unlimited permission to copy and/or distribute it, with or without
  7. modifications, as long as this notice is preserved.
  8. This file is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY, to the extent permitted by law; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. */
  12. /* Please submit changes back to the Scute project at
  13. http://www.scute.org/ (or send them to marcus@g10code.com), so that
  14. they can be picked up by other projects from there as well. */
  15. /* This file is a modified implementation of the PKCS #11 standard by
  16. RSA Security Inc. It is mostly a drop-in replacement, with the
  17. following change:
  18. This header file does not require any macro definitions by the user
  19. (like CK_DEFINE_FUNCTION etc). In fact, it defines those macros
  20. for you (if useful, some are missing, let me know if you need
  21. more).
  22. There is an additional API available that does comply better to the
  23. GNU coding standard. It can be switched on by defining
  24. CRYPTOKI_GNU before including this header file. For this, the
  25. following changes are made to the specification:
  26. All structure types are changed to a "struct ck_foo" where CK_FOO
  27. is the type name in PKCS #11.
  28. All non-structure types are changed to ck_foo_t where CK_FOO is the
  29. lowercase version of the type name in PKCS #11. The basic types
  30. (CK_ULONG et al.) are removed without substitute.
  31. All members of structures are modified in the following way: Type
  32. indication prefixes are removed, and underscore characters are
  33. inserted before words. Then the result is lowercased.
  34. Note that function names are still in the original case, as they
  35. need for ABI compatibility.
  36. CK_FALSE, CK_TRUE and NULL_PTR are removed without substitute. Use
  37. <stdbool.h>.
  38. If CRYPTOKI_COMPAT is defined before including this header file,
  39. then none of the API changes above take place, and the API is the
  40. one defined by the PKCS #11 standard. */
  41. #ifndef PKCS11_H
  42. #define PKCS11_H 1
  43. #if defined(__cplusplus)
  44. extern "C" {
  45. #endif
  46. /* The version of cryptoki we implement. The revision is changed with
  47. each modification of this file. If you do not use the "official"
  48. version of this file, please consider deleting the revision macro
  49. (you may use a macro with a different name to keep track of your
  50. versions). */
  51. #define CRYPTOKI_VERSION_MAJOR 2
  52. #define CRYPTOKI_VERSION_MINOR 20
  53. #define CRYPTOKI_VERSION_REVISION 6
  54. /* Compatibility interface is default, unless CRYPTOKI_GNU is
  55. given. */
  56. #ifndef CRYPTOKI_GNU
  57. #ifndef CRYPTOKI_COMPAT
  58. #define CRYPTOKI_COMPAT 1
  59. #endif
  60. #endif
  61. /* System dependencies. */
  62. #if defined(_WIN32) || defined(CRYPTOKI_FORCE_WIN32)
  63. /* There is a matching pop below. */
  64. #pragma pack(push, cryptoki, 1)
  65. #ifdef CRYPTOKI_EXPORTS
  66. #define CK_SPEC __declspec(dllexport)
  67. #else
  68. #define CK_SPEC __declspec(dllimport)
  69. #endif
  70. #else
  71. #define CK_SPEC
  72. #endif
  73. #ifdef CRYPTOKI_COMPAT
  74. /* If we are in compatibility mode, switch all exposed names to the
  75. PKCS #11 variant. There are corresponding #undefs below. */
  76. #define ck_flags_t CK_FLAGS
  77. #define ck_version _CK_VERSION
  78. #define ck_info _CK_INFO
  79. #define cryptoki_version cryptokiVersion
  80. #define manufacturer_id manufacturerID
  81. #define library_description libraryDescription
  82. #define library_version libraryVersion
  83. #define ck_notification_t CK_NOTIFICATION
  84. #define ck_slot_id_t CK_SLOT_ID
  85. #define ck_slot_info _CK_SLOT_INFO
  86. #define slot_description slotDescription
  87. #define hardware_version hardwareVersion
  88. #define firmware_version firmwareVersion
  89. #define ck_token_info _CK_TOKEN_INFO
  90. #define serial_number serialNumber
  91. #define max_session_count ulMaxSessionCount
  92. #define session_count ulSessionCount
  93. #define max_rw_session_count ulMaxRwSessionCount
  94. #define rw_session_count ulRwSessionCount
  95. #define max_pin_len ulMaxPinLen
  96. #define min_pin_len ulMinPinLen
  97. #define total_public_memory ulTotalPublicMemory
  98. #define free_public_memory ulFreePublicMemory
  99. #define total_private_memory ulTotalPrivateMemory
  100. #define free_private_memory ulFreePrivateMemory
  101. #define utc_time utcTime
  102. #define ck_session_handle_t CK_SESSION_HANDLE
  103. #define ck_user_type_t CK_USER_TYPE
  104. #define ck_state_t CK_STATE
  105. #define ck_session_info _CK_SESSION_INFO
  106. #define slot_id slotID
  107. #define device_error ulDeviceError
  108. #define ck_object_handle_t CK_OBJECT_HANDLE
  109. #define ck_object_class_t CK_OBJECT_CLASS
  110. #define ck_hw_feature_type_t CK_HW_FEATURE_TYPE
  111. #define ck_key_type_t CK_KEY_TYPE
  112. #define ck_certificate_type_t CK_CERTIFICATE_TYPE
  113. #define ck_attribute_type_t CK_ATTRIBUTE_TYPE
  114. #define ck_attribute _CK_ATTRIBUTE
  115. #define value pValue
  116. #define value_len ulValueLen
  117. #define ck_date _CK_DATE
  118. #define ck_mechanism_type_t CK_MECHANISM_TYPE
  119. #define ck_mechanism _CK_MECHANISM
  120. #define parameter pParameter
  121. #define parameter_len ulParameterLen
  122. #define ck_mechanism_info _CK_MECHANISM_INFO
  123. #define min_key_size ulMinKeySize
  124. #define max_key_size ulMaxKeySize
  125. #define ck_rv_t CK_RV
  126. #define ck_notify_t CK_NOTIFY
  127. #define ck_function_list _CK_FUNCTION_LIST
  128. #define ck_createmutex_t CK_CREATEMUTEX
  129. #define ck_destroymutex_t CK_DESTROYMUTEX
  130. #define ck_lockmutex_t CK_LOCKMUTEX
  131. #define ck_unlockmutex_t CK_UNLOCKMUTEX
  132. #define ck_c_initialize_args _CK_C_INITIALIZE_ARGS
  133. #define create_mutex CreateMutex
  134. #define destroy_mutex DestroyMutex
  135. #define lock_mutex LockMutex
  136. #define unlock_mutex UnlockMutex
  137. #define reserved pReserved
  138. #endif /* CRYPTOKI_COMPAT */
  139. typedef unsigned long ck_flags_t;
  140. struct ck_version
  141. {
  142. unsigned char major;
  143. unsigned char minor;
  144. };
  145. struct ck_info
  146. {
  147. struct ck_version cryptoki_version;
  148. unsigned char manufacturer_id[32];
  149. ck_flags_t flags;
  150. unsigned char library_description[32];
  151. struct ck_version library_version;
  152. };
  153. typedef unsigned long ck_notification_t;
  154. #define CKN_SURRENDER (0)
  155. typedef unsigned long ck_slot_id_t;
  156. struct ck_slot_info
  157. {
  158. unsigned char slot_description[64];
  159. unsigned char manufacturer_id[32];
  160. ck_flags_t flags;
  161. struct ck_version hardware_version;
  162. struct ck_version firmware_version;
  163. };
  164. #define CKF_TOKEN_PRESENT (1 << 0)
  165. #define CKF_REMOVABLE_DEVICE (1 << 1)
  166. #define CKF_HW_SLOT (1 << 2)
  167. #define CKF_ARRAY_ATTRIBUTE (1 << 30)
  168. struct ck_token_info
  169. {
  170. unsigned char label[32];
  171. unsigned char manufacturer_id[32];
  172. unsigned char model[16];
  173. unsigned char serial_number[16];
  174. ck_flags_t flags;
  175. unsigned long max_session_count;
  176. unsigned long session_count;
  177. unsigned long max_rw_session_count;
  178. unsigned long rw_session_count;
  179. unsigned long max_pin_len;
  180. unsigned long min_pin_len;
  181. unsigned long total_public_memory;
  182. unsigned long free_public_memory;
  183. unsigned long total_private_memory;
  184. unsigned long free_private_memory;
  185. struct ck_version hardware_version;
  186. struct ck_version firmware_version;
  187. unsigned char utc_time[16];
  188. };
  189. #define CKF_RNG (1 << 0)
  190. #define CKF_WRITE_PROTECTED (1 << 1)
  191. #define CKF_LOGIN_REQUIRED (1 << 2)
  192. #define CKF_USER_PIN_INITIALIZED (1 << 3)
  193. #define CKF_RESTORE_KEY_NOT_NEEDED (1 << 5)
  194. #define CKF_CLOCK_ON_TOKEN (1 << 6)
  195. #define CKF_PROTECTED_AUTHENTICATION_PATH (1 << 8)
  196. #define CKF_DUAL_CRYPTO_OPERATIONS (1 << 9)
  197. #define CKF_TOKEN_INITIALIZED (1 << 10)
  198. #define CKF_SECONDARY_AUTHENTICATION (1 << 11)
  199. #define CKF_USER_PIN_COUNT_LOW (1 << 16)
  200. #define CKF_USER_PIN_FINAL_TRY (1 << 17)
  201. #define CKF_USER_PIN_LOCKED (1 << 18)
  202. #define CKF_USER_PIN_TO_BE_CHANGED (1 << 19)
  203. #define CKF_SO_PIN_COUNT_LOW (1 << 20)
  204. #define CKF_SO_PIN_FINAL_TRY (1 << 21)
  205. #define CKF_SO_PIN_LOCKED (1 << 22)
  206. #define CKF_SO_PIN_TO_BE_CHANGED (1 << 23)
  207. #define CK_UNAVAILABLE_INFORMATION ((unsigned long) -1)
  208. #define CK_EFFECTIVELY_INFINITE (0)
  209. typedef unsigned long ck_session_handle_t;
  210. #define CK_INVALID_HANDLE (0)
  211. typedef unsigned long ck_user_type_t;
  212. #define CKU_SO (0)
  213. #define CKU_USER (1)
  214. #define CKU_CONTEXT_SPECIFIC (2)
  215. typedef unsigned long ck_state_t;
  216. #define CKS_RO_PUBLIC_SESSION (0)
  217. #define CKS_RO_USER_FUNCTIONS (1)
  218. #define CKS_RW_PUBLIC_SESSION (2)
  219. #define CKS_RW_USER_FUNCTIONS (3)
  220. #define CKS_RW_SO_FUNCTIONS (4)
  221. struct ck_session_info
  222. {
  223. ck_slot_id_t slot_id;
  224. ck_state_t state;
  225. ck_flags_t flags;
  226. unsigned long device_error;
  227. };
  228. #define CKF_RW_SESSION (1 << 1)
  229. #define CKF_SERIAL_SESSION (1 << 2)
  230. typedef unsigned long ck_object_handle_t;
  231. typedef unsigned long ck_object_class_t;
  232. #define CKO_DATA (0)
  233. #define CKO_CERTIFICATE (1)
  234. #define CKO_PUBLIC_KEY (2)
  235. #define CKO_PRIVATE_KEY (3)
  236. #define CKO_SECRET_KEY (4)
  237. #define CKO_HW_FEATURE (5)
  238. #define CKO_DOMAIN_PARAMETERS (6)
  239. #define CKO_MECHANISM (7)
  240. #define CKO_VENDOR_DEFINED (1U << 31)
  241. typedef unsigned long ck_hw_feature_type_t;
  242. #define CKH_MONOTONIC_COUNTER (1)
  243. #define CKH_CLOCK (2)
  244. #define CKH_USER_INTERFACE (3)
  245. #define CKH_VENDOR_DEFINED (1U << 31)
  246. typedef unsigned long ck_key_type_t;
  247. #define CKK_RSA (0)
  248. #define CKK_DSA (1)
  249. #define CKK_DH (2)
  250. #define CKK_ECDSA (3)
  251. #define CKK_EC (3)
  252. #define CKK_X9_42_DH (4)
  253. #define CKK_KEA (5)
  254. #define CKK_GENERIC_SECRET (0x10)
  255. #define CKK_RC2 (0x11)
  256. #define CKK_RC4 (0x12)
  257. #define CKK_DES (0x13)
  258. #define CKK_DES2 (0x14)
  259. #define CKK_DES3 (0x15)
  260. #define CKK_CAST (0x16)
  261. #define CKK_CAST3 (0x17)
  262. #define CKK_CAST128 (0x18)
  263. #define CKK_RC5 (0x19)
  264. #define CKK_IDEA (0x1a)
  265. #define CKK_SKIPJACK (0x1b)
  266. #define CKK_BATON (0x1c)
  267. #define CKK_JUNIPER (0x1d)
  268. #define CKK_CDMF (0x1e)
  269. #define CKK_AES (0x1f)
  270. #define CKK_BLOWFISH (0x20)
  271. #define CKK_TWOFISH (0x21)
  272. #define CKK_VENDOR_DEFINED (1U << 31)
  273. typedef unsigned long ck_certificate_type_t;
  274. #define CKC_X_509 (0)
  275. #define CKC_X_509_ATTR_CERT (1)
  276. #define CKC_WTLS (2)
  277. #define CKC_VENDOR_DEFINED (1U << 31)
  278. typedef unsigned long ck_attribute_type_t;
  279. #define CKA_CLASS (0)
  280. #define CKA_TOKEN (1)
  281. #define CKA_PRIVATE (2)
  282. #define CKA_LABEL (3)
  283. #define CKA_APPLICATION (0x10)
  284. #define CKA_VALUE (0x11)
  285. #define CKA_OBJECT_ID (0x12)
  286. #define CKA_CERTIFICATE_TYPE (0x80)
  287. #define CKA_ISSUER (0x81)
  288. #define CKA_SERIAL_NUMBER (0x82)
  289. #define CKA_AC_ISSUER (0x83)
  290. #define CKA_OWNER (0x84)
  291. #define CKA_ATTR_TYPES (0x85)
  292. #define CKA_TRUSTED (0x86)
  293. #define CKA_CERTIFICATE_CATEGORY (0x87)
  294. #define CKA_JAVA_MIDP_SECURITY_DOMAIN (0x88)
  295. #define CKA_URL (0x89)
  296. #define CKA_HASH_OF_SUBJECT_PUBLIC_KEY (0x8a)
  297. #define CKA_HASH_OF_ISSUER_PUBLIC_KEY (0x8b)
  298. #define CKA_CHECK_VALUE (0x90)
  299. #define CKA_KEY_TYPE (0x100)
  300. #define CKA_SUBJECT (0x101)
  301. #define CKA_ID (0x102)
  302. #define CKA_SENSITIVE (0x103)
  303. #define CKA_ENCRYPT (0x104)
  304. #define CKA_DECRYPT (0x105)
  305. #define CKA_WRAP (0x106)
  306. #define CKA_UNWRAP (0x107)
  307. #define CKA_SIGN (0x108)
  308. #define CKA_SIGN_RECOVER (0x109)
  309. #define CKA_VERIFY (0x10a)
  310. #define CKA_VERIFY_RECOVER (0x10b)
  311. #define CKA_DERIVE (0x10c)
  312. #define CKA_START_DATE (0x110)
  313. #define CKA_END_DATE (0x111)
  314. #define CKA_MODULUS (0x120)
  315. #define CKA_MODULUS_BITS (0x121)
  316. #define CKA_PUBLIC_EXPONENT (0x122)
  317. #define CKA_PRIVATE_EXPONENT (0x123)
  318. #define CKA_PRIME_1 (0x124)
  319. #define CKA_PRIME_2 (0x125)
  320. #define CKA_EXPONENT_1 (0x126)
  321. #define CKA_EXPONENT_2 (0x127)
  322. #define CKA_COEFFICIENT (0x128)
  323. #define CKA_PRIME (0x130)
  324. #define CKA_SUBPRIME (0x131)
  325. #define CKA_BASE (0x132)
  326. #define CKA_PRIME_BITS (0x133)
  327. #define CKA_SUB_PRIME_BITS (0x134)
  328. #define CKA_VALUE_BITS (0x160)
  329. #define CKA_VALUE_LEN (0x161)
  330. #define CKA_EXTRACTABLE (0x162)
  331. #define CKA_LOCAL (0x163)
  332. #define CKA_NEVER_EXTRACTABLE (0x164)
  333. #define CKA_ALWAYS_SENSITIVE (0x165)
  334. #define CKA_KEY_GEN_MECHANISM (0x166)
  335. #define CKA_MODIFIABLE (0x170)
  336. #define CKA_ECDSA_PARAMS (0x180)
  337. #define CKA_EC_PARAMS (0x180)
  338. #define CKA_EC_POINT (0x181)
  339. #define CKA_SECONDARY_AUTH (0x200)
  340. #define CKA_AUTH_PIN_FLAGS (0x201)
  341. #define CKA_ALWAYS_AUTHENTICATE (0x202)
  342. #define CKA_WRAP_WITH_TRUSTED (0x210)
  343. #define CKA_HW_FEATURE_TYPE (0x300)
  344. #define CKA_RESET_ON_INIT (0x301)
  345. #define CKA_HAS_RESET (0x302)
  346. #define CKA_PIXEL_X (0x400)
  347. #define CKA_PIXEL_Y (0x401)
  348. #define CKA_RESOLUTION (0x402)
  349. #define CKA_CHAR_ROWS (0x403)
  350. #define CKA_CHAR_COLUMNS (0x404)
  351. #define CKA_COLOR (0x405)
  352. #define CKA_BITS_PER_PIXEL (0x406)
  353. #define CKA_CHAR_SETS (0x480)
  354. #define CKA_ENCODING_METHODS (0x481)
  355. #define CKA_MIME_TYPES (0x482)
  356. #define CKA_MECHANISM_TYPE (0x500)
  357. #define CKA_REQUIRED_CMS_ATTRIBUTES (0x501)
  358. #define CKA_DEFAULT_CMS_ATTRIBUTES (0x502)
  359. #define CKA_SUPPORTED_CMS_ATTRIBUTES (0x503)
  360. #define CKA_WRAP_TEMPLATE (CKF_ARRAY_ATTRIBUTE | 0x211)
  361. #define CKA_UNWRAP_TEMPLATE (CKF_ARRAY_ATTRIBUTE | 0x212)
  362. #define CKA_ALLOWED_MECHANISMS (CKF_ARRAY_ATTRIBUTE | 0x600)
  363. #define CKA_VENDOR_DEFINED (1U << 31)
  364. struct ck_attribute
  365. {
  366. ck_attribute_type_t type;
  367. void *value;
  368. unsigned long value_len;
  369. };
  370. struct ck_date
  371. {
  372. unsigned char year[4];
  373. unsigned char month[2];
  374. unsigned char day[2];
  375. };
  376. typedef unsigned long ck_mechanism_type_t;
  377. #define CKM_RSA_PKCS_KEY_PAIR_GEN (0)
  378. #define CKM_RSA_PKCS (1)
  379. #define CKM_RSA_9796 (2)
  380. #define CKM_RSA_X_509 (3)
  381. #define CKM_MD2_RSA_PKCS (4)
  382. #define CKM_MD5_RSA_PKCS (5)
  383. #define CKM_SHA1_RSA_PKCS (6)
  384. #define CKM_RIPEMD128_RSA_PKCS (7)
  385. #define CKM_RIPEMD160_RSA_PKCS (8)
  386. #define CKM_RSA_PKCS_OAEP (9)
  387. #define CKM_RSA_X9_31_KEY_PAIR_GEN (0xa)
  388. #define CKM_RSA_X9_31 (0xb)
  389. #define CKM_SHA1_RSA_X9_31 (0xc)
  390. #define CKM_RSA_PKCS_PSS (0xd)
  391. #define CKM_SHA1_RSA_PKCS_PSS (0xe)
  392. #define CKM_DSA_KEY_PAIR_GEN (0x10)
  393. #define CKM_DSA (0x11)
  394. #define CKM_DSA_SHA1 (0x12)
  395. #define CKM_DH_PKCS_KEY_PAIR_GEN (0x20)
  396. #define CKM_DH_PKCS_DERIVE (0x21)
  397. #define CKM_X9_42_DH_KEY_PAIR_GEN (0x30)
  398. #define CKM_X9_42_DH_DERIVE (0x31)
  399. #define CKM_X9_42_DH_HYBRID_DERIVE (0x32)
  400. #define CKM_X9_42_MQV_DERIVE (0x33)
  401. #define CKM_SHA256_RSA_PKCS (0x40)
  402. #define CKM_SHA384_RSA_PKCS (0x41)
  403. #define CKM_SHA512_RSA_PKCS (0x42)
  404. #define CKM_SHA256_RSA_PKCS_PSS (0x43)
  405. #define CKM_SHA384_RSA_PKCS_PSS (0x44)
  406. #define CKM_SHA512_RSA_PKCS_PSS (0x45)
  407. #define CKM_RC2_KEY_GEN (0x100)
  408. #define CKM_RC2_ECB (0x101)
  409. #define CKM_RC2_CBC (0x102)
  410. #define CKM_RC2_MAC (0x103)
  411. #define CKM_RC2_MAC_GENERAL (0x104)
  412. #define CKM_RC2_CBC_PAD (0x105)
  413. #define CKM_RC4_KEY_GEN (0x110)
  414. #define CKM_RC4 (0x111)
  415. #define CKM_DES_KEY_GEN (0x120)
  416. #define CKM_DES_ECB (0x121)
  417. #define CKM_DES_CBC (0x122)
  418. #define CKM_DES_MAC (0x123)
  419. #define CKM_DES_MAC_GENERAL (0x124)
  420. #define CKM_DES_CBC_PAD (0x125)
  421. #define CKM_DES2_KEY_GEN (0x130)
  422. #define CKM_DES3_KEY_GEN (0x131)
  423. #define CKM_DES3_ECB (0x132)
  424. #define CKM_DES3_CBC (0x133)
  425. #define CKM_DES3_MAC (0x134)
  426. #define CKM_DES3_MAC_GENERAL (0x135)
  427. #define CKM_DES3_CBC_PAD (0x136)
  428. #define CKM_CDMF_KEY_GEN (0x140)
  429. #define CKM_CDMF_ECB (0x141)
  430. #define CKM_CDMF_CBC (0x142)
  431. #define CKM_CDMF_MAC (0x143)
  432. #define CKM_CDMF_MAC_GENERAL (0x144)
  433. #define CKM_CDMF_CBC_PAD (0x145)
  434. #define CKM_MD2 (0x200)
  435. #define CKM_MD2_HMAC (0x201)
  436. #define CKM_MD2_HMAC_GENERAL (0x202)
  437. #define CKM_MD5 (0x210)
  438. #define CKM_MD5_HMAC (0x211)
  439. #define CKM_MD5_HMAC_GENERAL (0x212)
  440. #define CKM_SHA_1 (0x220)
  441. #define CKM_SHA_1_HMAC (0x221)
  442. #define CKM_SHA_1_HMAC_GENERAL (0x222)
  443. #define CKM_RIPEMD128 (0x230)
  444. #define CKM_RIPEMD128_HMAC (0x231)
  445. #define CKM_RIPEMD128_HMAC_GENERAL (0x232)
  446. #define CKM_RIPEMD160 (0x240)
  447. #define CKM_RIPEMD160_HMAC (0x241)
  448. #define CKM_RIPEMD160_HMAC_GENERAL (0x242)
  449. #define CKM_SHA256 (0x250)
  450. #define CKM_SHA256_HMAC (0x251)
  451. #define CKM_SHA256_HMAC_GENERAL (0x252)
  452. #define CKM_SHA384 (0x260)
  453. #define CKM_SHA384_HMAC (0x261)
  454. #define CKM_SHA384_HMAC_GENERAL (0x262)
  455. #define CKM_SHA512 (0x270)
  456. #define CKM_SHA512_HMAC (0x271)
  457. #define CKM_SHA512_HMAC_GENERAL (0x272)
  458. #define CKM_CAST_KEY_GEN (0x300)
  459. #define CKM_CAST_ECB (0x301)
  460. #define CKM_CAST_CBC (0x302)
  461. #define CKM_CAST_MAC (0x303)
  462. #define CKM_CAST_MAC_GENERAL (0x304)
  463. #define CKM_CAST_CBC_PAD (0x305)
  464. #define CKM_CAST3_KEY_GEN (0x310)
  465. #define CKM_CAST3_ECB (0x311)
  466. #define CKM_CAST3_CBC (0x312)
  467. #define CKM_CAST3_MAC (0x313)
  468. #define CKM_CAST3_MAC_GENERAL (0x314)
  469. #define CKM_CAST3_CBC_PAD (0x315)
  470. #define CKM_CAST5_KEY_GEN (0x320)
  471. #define CKM_CAST128_KEY_GEN (0x320)
  472. #define CKM_CAST5_ECB (0x321)
  473. #define CKM_CAST128_ECB (0x321)
  474. #define CKM_CAST5_CBC (0x322)
  475. #define CKM_CAST128_CBC (0x322)
  476. #define CKM_CAST5_MAC (0x323)
  477. #define CKM_CAST128_MAC (0x323)
  478. #define CKM_CAST5_MAC_GENERAL (0x324)
  479. #define CKM_CAST128_MAC_GENERAL (0x324)
  480. #define CKM_CAST5_CBC_PAD (0x325)
  481. #define CKM_CAST128_CBC_PAD (0x325)
  482. #define CKM_RC5_KEY_GEN (0x330)
  483. #define CKM_RC5_ECB (0x331)
  484. #define CKM_RC5_CBC (0x332)
  485. #define CKM_RC5_MAC (0x333)
  486. #define CKM_RC5_MAC_GENERAL (0x334)
  487. #define CKM_RC5_CBC_PAD (0x335)
  488. #define CKM_IDEA_KEY_GEN (0x340)
  489. #define CKM_IDEA_ECB (0x341)
  490. #define CKM_IDEA_CBC (0x342)
  491. #define CKM_IDEA_MAC (0x343)
  492. #define CKM_IDEA_MAC_GENERAL (0x344)
  493. #define CKM_IDEA_CBC_PAD (0x345)
  494. #define CKM_GENERIC_SECRET_KEY_GEN (0x350)
  495. #define CKM_CONCATENATE_BASE_AND_KEY (0x360)
  496. #define CKM_CONCATENATE_BASE_AND_DATA (0x362)
  497. #define CKM_CONCATENATE_DATA_AND_BASE (0x363)
  498. #define CKM_XOR_BASE_AND_DATA (0x364)
  499. #define CKM_EXTRACT_KEY_FROM_KEY (0x365)
  500. #define CKM_SSL3_PRE_MASTER_KEY_GEN (0x370)
  501. #define CKM_SSL3_MASTER_KEY_DERIVE (0x371)
  502. #define CKM_SSL3_KEY_AND_MAC_DERIVE (0x372)
  503. #define CKM_SSL3_MASTER_KEY_DERIVE_DH (0x373)
  504. #define CKM_TLS_PRE_MASTER_KEY_GEN (0x374)
  505. #define CKM_TLS_MASTER_KEY_DERIVE (0x375)
  506. #define CKM_TLS_KEY_AND_MAC_DERIVE (0x376)
  507. #define CKM_TLS_MASTER_KEY_DERIVE_DH (0x377)
  508. #define CKM_SSL3_MD5_MAC (0x380)
  509. #define CKM_SSL3_SHA1_MAC (0x381)
  510. #define CKM_MD5_KEY_DERIVATION (0x390)
  511. #define CKM_MD2_KEY_DERIVATION (0x391)
  512. #define CKM_SHA1_KEY_DERIVATION (0x392)
  513. #define CKM_PBE_MD2_DES_CBC (0x3a0)
  514. #define CKM_PBE_MD5_DES_CBC (0x3a1)
  515. #define CKM_PBE_MD5_CAST_CBC (0x3a2)
  516. #define CKM_PBE_MD5_CAST3_CBC (0x3a3)
  517. #define CKM_PBE_MD5_CAST5_CBC (0x3a4)
  518. #define CKM_PBE_MD5_CAST128_CBC (0x3a4)
  519. #define CKM_PBE_SHA1_CAST5_CBC (0x3a5)
  520. #define CKM_PBE_SHA1_CAST128_CBC (0x3a5)
  521. #define CKM_PBE_SHA1_RC4_128 (0x3a6)
  522. #define CKM_PBE_SHA1_RC4_40 (0x3a7)
  523. #define CKM_PBE_SHA1_DES3_EDE_CBC (0x3a8)
  524. #define CKM_PBE_SHA1_DES2_EDE_CBC (0x3a9)
  525. #define CKM_PBE_SHA1_RC2_128_CBC (0x3aa)
  526. #define CKM_PBE_SHA1_RC2_40_CBC (0x3ab)
  527. #define CKM_PKCS5_PBKD2 (0x3b0)
  528. #define CKM_PBA_SHA1_WITH_SHA1_HMAC (0x3c0)
  529. #define CKM_KEY_WRAP_LYNKS (0x400)
  530. #define CKM_KEY_WRAP_SET_OAEP (0x401)
  531. #define CKM_SKIPJACK_KEY_GEN (0x1000)
  532. #define CKM_SKIPJACK_ECB64 (0x1001)
  533. #define CKM_SKIPJACK_CBC64 (0x1002)
  534. #define CKM_SKIPJACK_OFB64 (0x1003)
  535. #define CKM_SKIPJACK_CFB64 (0x1004)
  536. #define CKM_SKIPJACK_CFB32 (0x1005)
  537. #define CKM_SKIPJACK_CFB16 (0x1006)
  538. #define CKM_SKIPJACK_CFB8 (0x1007)
  539. #define CKM_SKIPJACK_WRAP (0x1008)
  540. #define CKM_SKIPJACK_PRIVATE_WRAP (0x1009)
  541. #define CKM_SKIPJACK_RELAYX (0x100a)
  542. #define CKM_KEA_KEY_PAIR_GEN (0x1010)
  543. #define CKM_KEA_KEY_DERIVE (0x1011)
  544. #define CKM_FORTEZZA_TIMESTAMP (0x1020)
  545. #define CKM_BATON_KEY_GEN (0x1030)
  546. #define CKM_BATON_ECB128 (0x1031)
  547. #define CKM_BATON_ECB96 (0x1032)
  548. #define CKM_BATON_CBC128 (0x1033)
  549. #define CKM_BATON_COUNTER (0x1034)
  550. #define CKM_BATON_SHUFFLE (0x1035)
  551. #define CKM_BATON_WRAP (0x1036)
  552. #define CKM_ECDSA_KEY_PAIR_GEN (0x1040)
  553. #define CKM_EC_KEY_PAIR_GEN (0x1040)
  554. #define CKM_ECDSA (0x1041)
  555. #define CKM_ECDSA_SHA1 (0x1042)
  556. #define CKM_ECDH1_DERIVE (0x1050)
  557. #define CKM_ECDH1_COFACTOR_DERIVE (0x1051)
  558. #define CKM_ECMQV_DERIVE (0x1052)
  559. #define CKM_JUNIPER_KEY_GEN (0x1060)
  560. #define CKM_JUNIPER_ECB128 (0x1061)
  561. #define CKM_JUNIPER_CBC128 (0x1062)
  562. #define CKM_JUNIPER_COUNTER (0x1063)
  563. #define CKM_JUNIPER_SHUFFLE (0x1064)
  564. #define CKM_JUNIPER_WRAP (0x1065)
  565. #define CKM_FASTHASH (0x1070)
  566. #define CKM_AES_KEY_GEN (0x1080)
  567. #define CKM_AES_ECB (0x1081)
  568. #define CKM_AES_CBC (0x1082)
  569. #define CKM_AES_MAC (0x1083)
  570. #define CKM_AES_MAC_GENERAL (0x1084)
  571. #define CKM_AES_CBC_PAD (0x1085)
  572. #define CKM_DSA_PARAMETER_GEN (0x2000)
  573. #define CKM_DH_PKCS_PARAMETER_GEN (0x2001)
  574. #define CKM_X9_42_DH_PARAMETER_GEN (0x2002)
  575. #define CKM_VENDOR_DEFINED (1U << 31)
  576. struct ck_mechanism
  577. {
  578. ck_mechanism_type_t mechanism;
  579. void *parameter;
  580. unsigned long parameter_len;
  581. };
  582. struct ck_mechanism_info
  583. {
  584. unsigned long min_key_size;
  585. unsigned long max_key_size;
  586. ck_flags_t flags;
  587. };
  588. #define CKF_HW (1 << 0)
  589. #define CKF_ENCRYPT (1 << 8)
  590. #define CKF_DECRYPT (1 << 9)
  591. #define CKF_DIGEST (1 << 10)
  592. #define CKF_SIGN (1 << 11)
  593. #define CKF_SIGN_RECOVER (1 << 12)
  594. #define CKF_VERIFY (1 << 13)
  595. #define CKF_VERIFY_RECOVER (1 << 14)
  596. #define CKF_GENERATE (1 << 15)
  597. #define CKF_GENERATE_KEY_PAIR (1 << 16)
  598. #define CKF_WRAP (1 << 17)
  599. #define CKF_UNWRAP (1 << 18)
  600. #define CKF_DERIVE (1 << 19)
  601. #define CKF_EXTENSION (1U << 31)
  602. /* Flags for C_WaitForSlotEvent. */
  603. #define CKF_DONT_BLOCK (1)
  604. typedef unsigned long ck_rv_t;
  605. typedef ck_rv_t (*ck_notify_t) (ck_session_handle_t session,
  606. ck_notification_t event, void *application);
  607. /* Forward reference. */
  608. struct ck_function_list;
  609. #define _CK_DECLARE_FUNCTION(name, args) \
  610. typedef ck_rv_t (*CK_ ## name) args; \
  611. ck_rv_t CK_SPEC name args
  612. _CK_DECLARE_FUNCTION (C_Initialize, (void *init_args));
  613. _CK_DECLARE_FUNCTION (C_Finalize, (void *reserved));
  614. _CK_DECLARE_FUNCTION (C_GetInfo, (struct ck_info *info));
  615. _CK_DECLARE_FUNCTION (C_GetFunctionList,
  616. (struct ck_function_list **function_list));
  617. _CK_DECLARE_FUNCTION (C_GetSlotList,
  618. (unsigned char token_present, ck_slot_id_t *slot_list,
  619. unsigned long *count));
  620. _CK_DECLARE_FUNCTION (C_GetSlotInfo,
  621. (ck_slot_id_t slot_id, struct ck_slot_info *info));
  622. _CK_DECLARE_FUNCTION (C_GetTokenInfo,
  623. (ck_slot_id_t slot_id, struct ck_token_info *info));
  624. _CK_DECLARE_FUNCTION (C_WaitForSlotEvent,
  625. (ck_flags_t flags, ck_slot_id_t *slot, void *reserved));
  626. _CK_DECLARE_FUNCTION (C_GetMechanismList,
  627. (ck_slot_id_t slot_id,
  628. ck_mechanism_type_t *mechanism_list,
  629. unsigned long *count));
  630. _CK_DECLARE_FUNCTION (C_GetMechanismInfo,
  631. (ck_slot_id_t slot_id, ck_mechanism_type_t type,
  632. struct ck_mechanism_info *info));
  633. _CK_DECLARE_FUNCTION (C_InitToken,
  634. (ck_slot_id_t slot_id, unsigned char *pin,
  635. unsigned long pin_len, unsigned char *label));
  636. _CK_DECLARE_FUNCTION (C_InitPIN,
  637. (ck_session_handle_t session, unsigned char *pin,
  638. unsigned long pin_len));
  639. _CK_DECLARE_FUNCTION (C_SetPIN,
  640. (ck_session_handle_t session, unsigned char *old_pin,
  641. unsigned long old_len, unsigned char *new_pin,
  642. unsigned long new_len));
  643. _CK_DECLARE_FUNCTION (C_OpenSession,
  644. (ck_slot_id_t slot_id, ck_flags_t flags,
  645. void *application, ck_notify_t notify,
  646. ck_session_handle_t *session));
  647. _CK_DECLARE_FUNCTION (C_CloseSession, (ck_session_handle_t session));
  648. _CK_DECLARE_FUNCTION (C_CloseAllSessions, (ck_slot_id_t slot_id));
  649. _CK_DECLARE_FUNCTION (C_GetSessionInfo,
  650. (ck_session_handle_t session,
  651. struct ck_session_info *info));
  652. _CK_DECLARE_FUNCTION (C_GetOperationState,
  653. (ck_session_handle_t session,
  654. unsigned char *operation_state,
  655. unsigned long *operation_state_len));
  656. _CK_DECLARE_FUNCTION (C_SetOperationState,
  657. (ck_session_handle_t session,
  658. unsigned char *operation_state,
  659. unsigned long operation_state_len,
  660. ck_object_handle_t encryption_key,
  661. ck_object_handle_t authentiation_key));
  662. _CK_DECLARE_FUNCTION (C_Login,
  663. (ck_session_handle_t session, ck_user_type_t user_type,
  664. unsigned char *pin, unsigned long pin_len));
  665. _CK_DECLARE_FUNCTION (C_Logout, (ck_session_handle_t session));
  666. _CK_DECLARE_FUNCTION (C_CreateObject,
  667. (ck_session_handle_t session,
  668. struct ck_attribute *templ,
  669. unsigned long count, ck_object_handle_t *object));
  670. _CK_DECLARE_FUNCTION (C_CopyObject,
  671. (ck_session_handle_t session, ck_object_handle_t object,
  672. struct ck_attribute *templ, unsigned long count,
  673. ck_object_handle_t *new_object));
  674. _CK_DECLARE_FUNCTION (C_DestroyObject,
  675. (ck_session_handle_t session,
  676. ck_object_handle_t object));
  677. _CK_DECLARE_FUNCTION (C_GetObjectSize,
  678. (ck_session_handle_t session,
  679. ck_object_handle_t object,
  680. unsigned long *size));
  681. _CK_DECLARE_FUNCTION (C_GetAttributeValue,
  682. (ck_session_handle_t session,
  683. ck_object_handle_t object,
  684. struct ck_attribute *templ,
  685. unsigned long count));
  686. _CK_DECLARE_FUNCTION (C_SetAttributeValue,
  687. (ck_session_handle_t session,
  688. ck_object_handle_t object,
  689. struct ck_attribute *templ,
  690. unsigned long count));
  691. _CK_DECLARE_FUNCTION (C_FindObjectsInit,
  692. (ck_session_handle_t session,
  693. struct ck_attribute *templ,
  694. unsigned long count));
  695. _CK_DECLARE_FUNCTION (C_FindObjects,
  696. (ck_session_handle_t session,
  697. ck_object_handle_t *object,
  698. unsigned long max_object_count,
  699. unsigned long *object_count));
  700. _CK_DECLARE_FUNCTION (C_FindObjectsFinal,
  701. (ck_session_handle_t session));
  702. _CK_DECLARE_FUNCTION (C_EncryptInit,
  703. (ck_session_handle_t session,
  704. struct ck_mechanism *mechanism,
  705. ck_object_handle_t key));
  706. _CK_DECLARE_FUNCTION (C_Encrypt,
  707. (ck_session_handle_t session,
  708. unsigned char *data, unsigned long data_len,
  709. unsigned char *encrypted_data,
  710. unsigned long *encrypted_data_len));
  711. _CK_DECLARE_FUNCTION (C_EncryptUpdate,
  712. (ck_session_handle_t session,
  713. unsigned char *part, unsigned long part_len,
  714. unsigned char *encrypted_part,
  715. unsigned long *encrypted_part_len));
  716. _CK_DECLARE_FUNCTION (C_EncryptFinal,
  717. (ck_session_handle_t session,
  718. unsigned char *last_encrypted_part,
  719. unsigned long *last_encrypted_part_len));
  720. _CK_DECLARE_FUNCTION (C_DecryptInit,
  721. (ck_session_handle_t session,
  722. struct ck_mechanism *mechanism,
  723. ck_object_handle_t key));
  724. _CK_DECLARE_FUNCTION (C_Decrypt,
  725. (ck_session_handle_t session,
  726. unsigned char *encrypted_data,
  727. unsigned long encrypted_data_len,
  728. unsigned char *data, unsigned long *data_len));
  729. _CK_DECLARE_FUNCTION (C_DecryptUpdate,
  730. (ck_session_handle_t session,
  731. unsigned char *encrypted_part,
  732. unsigned long encrypted_part_len,
  733. unsigned char *part, unsigned long *part_len));
  734. _CK_DECLARE_FUNCTION (C_DecryptFinal,
  735. (ck_session_handle_t session,
  736. unsigned char *last_part,
  737. unsigned long *last_part_len));
  738. _CK_DECLARE_FUNCTION (C_DigestInit,
  739. (ck_session_handle_t session,
  740. struct ck_mechanism *mechanism));
  741. _CK_DECLARE_FUNCTION (C_Digest,
  742. (ck_session_handle_t session,
  743. unsigned char *data, unsigned long data_len,
  744. unsigned char *digest,
  745. unsigned long *digest_len));
  746. _CK_DECLARE_FUNCTION (C_DigestUpdate,
  747. (ck_session_handle_t session,
  748. unsigned char *part, unsigned long part_len));
  749. _CK_DECLARE_FUNCTION (C_DigestKey,
  750. (ck_session_handle_t session, ck_object_handle_t key));
  751. _CK_DECLARE_FUNCTION (C_DigestFinal,
  752. (ck_session_handle_t session,
  753. unsigned char *digest,
  754. unsigned long *digest_len));
  755. _CK_DECLARE_FUNCTION (C_SignInit,
  756. (ck_session_handle_t session,
  757. struct ck_mechanism *mechanism,
  758. ck_object_handle_t key));
  759. _CK_DECLARE_FUNCTION (C_Sign,
  760. (ck_session_handle_t session,
  761. unsigned char *data, unsigned long data_len,
  762. unsigned char *signature,
  763. unsigned long *signature_len));
  764. _CK_DECLARE_FUNCTION (C_SignUpdate,
  765. (ck_session_handle_t session,
  766. unsigned char *part, unsigned long part_len));
  767. _CK_DECLARE_FUNCTION (C_SignFinal,
  768. (ck_session_handle_t session,
  769. unsigned char *signature,
  770. unsigned long *signature_len));
  771. _CK_DECLARE_FUNCTION (C_SignRecoverInit,
  772. (ck_session_handle_t session,
  773. struct ck_mechanism *mechanism,
  774. ck_object_handle_t key));
  775. _CK_DECLARE_FUNCTION (C_SignRecover,
  776. (ck_session_handle_t session,
  777. unsigned char *data, unsigned long data_len,
  778. unsigned char *signature,
  779. unsigned long *signature_len));
  780. _CK_DECLARE_FUNCTION (C_VerifyInit,
  781. (ck_session_handle_t session,
  782. struct ck_mechanism *mechanism,
  783. ck_object_handle_t key));
  784. _CK_DECLARE_FUNCTION (C_Verify,
  785. (ck_session_handle_t session,
  786. unsigned char *data, unsigned long data_len,
  787. unsigned char *signature,
  788. unsigned long signature_len));
  789. _CK_DECLARE_FUNCTION (C_VerifyUpdate,
  790. (ck_session_handle_t session,
  791. unsigned char *part, unsigned long part_len));
  792. _CK_DECLARE_FUNCTION (C_VerifyFinal,
  793. (ck_session_handle_t session,
  794. unsigned char *signature,
  795. unsigned long signature_len));
  796. _CK_DECLARE_FUNCTION (C_VerifyRecoverInit,
  797. (ck_session_handle_t session,
  798. struct ck_mechanism *mechanism,
  799. ck_object_handle_t key));
  800. _CK_DECLARE_FUNCTION (C_VerifyRecover,
  801. (ck_session_handle_t session,
  802. unsigned char *signature,
  803. unsigned long signature_len,
  804. unsigned char *data,
  805. unsigned long *data_len));
  806. _CK_DECLARE_FUNCTION (C_DigestEncryptUpdate,
  807. (ck_session_handle_t session,
  808. unsigned char *part, unsigned long part_len,
  809. unsigned char *encrypted_part,
  810. unsigned long *encrypted_part_len));
  811. _CK_DECLARE_FUNCTION (C_DecryptDigestUpdate,
  812. (ck_session_handle_t session,
  813. unsigned char *encrypted_part,
  814. unsigned long encrypted_part_len,
  815. unsigned char *part,
  816. unsigned long *part_len));
  817. _CK_DECLARE_FUNCTION (C_SignEncryptUpdate,
  818. (ck_session_handle_t session,
  819. unsigned char *part, unsigned long part_len,
  820. unsigned char *encrypted_part,
  821. unsigned long *encrypted_part_len));
  822. _CK_DECLARE_FUNCTION (C_DecryptVerifyUpdate,
  823. (ck_session_handle_t session,
  824. unsigned char *encrypted_part,
  825. unsigned long encrypted_part_len,
  826. unsigned char *part,
  827. unsigned long *part_len));
  828. _CK_DECLARE_FUNCTION (C_GenerateKey,
  829. (ck_session_handle_t session,
  830. struct ck_mechanism *mechanism,
  831. struct ck_attribute *templ,
  832. unsigned long count,
  833. ck_object_handle_t *key));
  834. _CK_DECLARE_FUNCTION (C_GenerateKeyPair,
  835. (ck_session_handle_t session,
  836. struct ck_mechanism *mechanism,
  837. struct ck_attribute *public_key_template,
  838. unsigned long public_key_attribute_count,
  839. struct ck_attribute *private_key_template,
  840. unsigned long private_key_attribute_count,
  841. ck_object_handle_t *public_key,
  842. ck_object_handle_t *private_key));
  843. _CK_DECLARE_FUNCTION (C_WrapKey,
  844. (ck_session_handle_t session,
  845. struct ck_mechanism *mechanism,
  846. ck_object_handle_t wrapping_key,
  847. ck_object_handle_t key,
  848. unsigned char *wrapped_key,
  849. unsigned long *wrapped_key_len));
  850. _CK_DECLARE_FUNCTION (C_UnwrapKey,
  851. (ck_session_handle_t session,
  852. struct ck_mechanism *mechanism,
  853. ck_object_handle_t unwrapping_key,
  854. unsigned char *wrapped_key,
  855. unsigned long wrapped_key_len,
  856. struct ck_attribute *templ,
  857. unsigned long attribute_count,
  858. ck_object_handle_t *key));
  859. _CK_DECLARE_FUNCTION (C_DeriveKey,
  860. (ck_session_handle_t session,
  861. struct ck_mechanism *mechanism,
  862. ck_object_handle_t base_key,
  863. struct ck_attribute *templ,
  864. unsigned long attribute_count,
  865. ck_object_handle_t *key));
  866. _CK_DECLARE_FUNCTION (C_SeedRandom,
  867. (ck_session_handle_t session, unsigned char *seed,
  868. unsigned long seed_len));
  869. _CK_DECLARE_FUNCTION (C_GenerateRandom,
  870. (ck_session_handle_t session,
  871. unsigned char *random_data,
  872. unsigned long random_len));
  873. _CK_DECLARE_FUNCTION (C_GetFunctionStatus, (ck_session_handle_t session));
  874. _CK_DECLARE_FUNCTION (C_CancelFunction, (ck_session_handle_t session));
  875. struct ck_function_list
  876. {
  877. struct ck_version version;
  878. CK_C_Initialize C_Initialize;
  879. CK_C_Finalize C_Finalize;
  880. CK_C_GetInfo C_GetInfo;
  881. CK_C_GetFunctionList C_GetFunctionList;
  882. CK_C_GetSlotList C_GetSlotList;
  883. CK_C_GetSlotInfo C_GetSlotInfo;
  884. CK_C_GetTokenInfo C_GetTokenInfo;
  885. CK_C_GetMechanismList C_GetMechanismList;
  886. CK_C_GetMechanismInfo C_GetMechanismInfo;
  887. CK_C_InitToken C_InitToken;
  888. CK_C_InitPIN C_InitPIN;
  889. CK_C_SetPIN C_SetPIN;
  890. CK_C_OpenSession C_OpenSession;
  891. CK_C_CloseSession C_CloseSession;
  892. CK_C_CloseAllSessions C_CloseAllSessions;
  893. CK_C_GetSessionInfo C_GetSessionInfo;
  894. CK_C_GetOperationState C_GetOperationState;
  895. CK_C_SetOperationState C_SetOperationState;
  896. CK_C_Login C_Login;
  897. CK_C_Logout C_Logout;
  898. CK_C_CreateObject C_CreateObject;
  899. CK_C_CopyObject C_CopyObject;
  900. CK_C_DestroyObject C_DestroyObject;
  901. CK_C_GetObjectSize C_GetObjectSize;
  902. CK_C_GetAttributeValue C_GetAttributeValue;
  903. CK_C_SetAttributeValue C_SetAttributeValue;
  904. CK_C_FindObjectsInit C_FindObjectsInit;
  905. CK_C_FindObjects C_FindObjects;
  906. CK_C_FindObjectsFinal C_FindObjectsFinal;
  907. CK_C_EncryptInit C_EncryptInit;
  908. CK_C_Encrypt C_Encrypt;
  909. CK_C_EncryptUpdate C_EncryptUpdate;
  910. CK_C_EncryptFinal C_EncryptFinal;
  911. CK_C_DecryptInit C_DecryptInit;
  912. CK_C_Decrypt C_Decrypt;
  913. CK_C_DecryptUpdate C_DecryptUpdate;
  914. CK_C_DecryptFinal C_DecryptFinal;
  915. CK_C_DigestInit C_DigestInit;
  916. CK_C_Digest C_Digest;
  917. CK_C_DigestUpdate C_DigestUpdate;
  918. CK_C_DigestKey C_DigestKey;
  919. CK_C_DigestFinal C_DigestFinal;
  920. CK_C_SignInit C_SignInit;
  921. CK_C_Sign C_Sign;
  922. CK_C_SignUpdate C_SignUpdate;
  923. CK_C_SignFinal C_SignFinal;
  924. CK_C_SignRecoverInit C_SignRecoverInit;
  925. CK_C_SignRecover C_SignRecover;
  926. CK_C_VerifyInit C_VerifyInit;
  927. CK_C_Verify C_Verify;
  928. CK_C_VerifyUpdate C_VerifyUpdate;
  929. CK_C_VerifyFinal C_VerifyFinal;
  930. CK_C_VerifyRecoverInit C_VerifyRecoverInit;
  931. CK_C_VerifyRecover C_VerifyRecover;
  932. CK_C_DigestEncryptUpdate C_DigestEncryptUpdate;
  933. CK_C_DecryptDigestUpdate C_DecryptDigestUpdate;
  934. CK_C_SignEncryptUpdate C_SignEncryptUpdate;
  935. CK_C_DecryptVerifyUpdate C_DecryptVerifyUpdate;
  936. CK_C_GenerateKey C_GenerateKey;
  937. CK_C_GenerateKeyPair C_GenerateKeyPair;
  938. CK_C_WrapKey C_WrapKey;
  939. CK_C_UnwrapKey C_UnwrapKey;
  940. CK_C_DeriveKey C_DeriveKey;
  941. CK_C_SeedRandom C_SeedRandom;
  942. CK_C_GenerateRandom C_GenerateRandom;
  943. CK_C_GetFunctionStatus C_GetFunctionStatus;
  944. CK_C_CancelFunction C_CancelFunction;
  945. CK_C_WaitForSlotEvent C_WaitForSlotEvent;
  946. };
  947. typedef ck_rv_t (*ck_createmutex_t) (void **mutex);
  948. typedef ck_rv_t (*ck_destroymutex_t) (void *mutex);
  949. typedef ck_rv_t (*ck_lockmutex_t) (void *mutex);
  950. typedef ck_rv_t (*ck_unlockmutex_t) (void *mutex);
  951. struct ck_c_initialize_args
  952. {
  953. ck_createmutex_t create_mutex;
  954. ck_destroymutex_t destroy_mutex;
  955. ck_lockmutex_t lock_mutex;
  956. ck_unlockmutex_t unlock_mutex;
  957. ck_flags_t flags;
  958. void *reserved;
  959. };
  960. #define CKF_LIBRARY_CANT_CREATE_OS_THREADS (1 << 0)
  961. #define CKF_OS_LOCKING_OK (1 << 1)
  962. #define CKR_OK (0)
  963. #define CKR_CANCEL (1)
  964. #define CKR_HOST_MEMORY (2)
  965. #define CKR_SLOT_ID_INVALID (3)
  966. #define CKR_GENERAL_ERROR (5)
  967. #define CKR_FUNCTION_FAILED (6)
  968. #define CKR_ARGUMENTS_BAD (7)
  969. #define CKR_NO_EVENT (8)
  970. #define CKR_NEED_TO_CREATE_THREADS (9)
  971. #define CKR_CANT_LOCK (0xa)
  972. #define CKR_ATTRIBUTE_READ_ONLY (0x10)
  973. #define CKR_ATTRIBUTE_SENSITIVE (0x11)
  974. #define CKR_ATTRIBUTE_TYPE_INVALID (0x12)
  975. #define CKR_ATTRIBUTE_VALUE_INVALID (0x13)
  976. #define CKR_DATA_INVALID (0x20)
  977. #define CKR_DATA_LEN_RANGE (0x21)
  978. #define CKR_DEVICE_ERROR (0x30)
  979. #define CKR_DEVICE_MEMORY (0x31)
  980. #define CKR_DEVICE_REMOVED (0x32)
  981. #define CKR_ENCRYPTED_DATA_INVALID (0x40)
  982. #define CKR_ENCRYPTED_DATA_LEN_RANGE (0x41)
  983. #define CKR_FUNCTION_CANCELED (0x50)
  984. #define CKR_FUNCTION_NOT_PARALLEL (0x51)
  985. #define CKR_FUNCTION_NOT_SUPPORTED (0x54)
  986. #define CKR_KEY_HANDLE_INVALID (0x60)
  987. #define CKR_KEY_SIZE_RANGE (0x62)
  988. #define CKR_KEY_TYPE_INCONSISTENT (0x63)
  989. #define CKR_KEY_NOT_NEEDED (0x64)
  990. #define CKR_KEY_CHANGED (0x65)
  991. #define CKR_KEY_NEEDED (0x66)
  992. #define CKR_KEY_INDIGESTIBLE (0x67)
  993. #define CKR_KEY_FUNCTION_NOT_PERMITTED (0x68)
  994. #define CKR_KEY_NOT_WRAPPABLE (0x69)
  995. #define CKR_KEY_UNEXTRACTABLE (0x6a)
  996. #define CKR_MECHANISM_INVALID (0x70)
  997. #define CKR_MECHANISM_PARAM_INVALID (0x71)
  998. #define CKR_OBJECT_HANDLE_INVALID (0x82)
  999. #define CKR_OPERATION_ACTIVE (0x90)
  1000. #define CKR_OPERATION_NOT_INITIALIZED (0x91)
  1001. #define CKR_PIN_INCORRECT (0xa0)
  1002. #define CKR_PIN_INVALID (0xa1)
  1003. #define CKR_PIN_LEN_RANGE (0xa2)
  1004. #define CKR_PIN_EXPIRED (0xa3)
  1005. #define CKR_PIN_LOCKED (0xa4)
  1006. #define CKR_SESSION_CLOSED (0xb0)
  1007. #define CKR_SESSION_COUNT (0xb1)
  1008. #define CKR_SESSION_HANDLE_INVALID (0xb3)
  1009. #define CKR_SESSION_PARALLEL_NOT_SUPPORTED (0xb4)
  1010. #define CKR_SESSION_READ_ONLY (0xb5)
  1011. #define CKR_SESSION_EXISTS (0xb6)
  1012. #define CKR_SESSION_READ_ONLY_EXISTS (0xb7)
  1013. #define CKR_SESSION_READ_WRITE_SO_EXISTS (0xb8)
  1014. #define CKR_SIGNATURE_INVALID (0xc0)
  1015. #define CKR_SIGNATURE_LEN_RANGE (0xc1)
  1016. #define CKR_TEMPLATE_INCOMPLETE (0xd0)
  1017. #define CKR_TEMPLATE_INCONSISTENT (0xd1)
  1018. #define CKR_TOKEN_NOT_PRESENT (0xe0)
  1019. #define CKR_TOKEN_NOT_RECOGNIZED (0xe1)
  1020. #define CKR_TOKEN_WRITE_PROTECTED (0xe2)
  1021. #define CKR_UNWRAPPING_KEY_HANDLE_INVALID (0xf0)
  1022. #define CKR_UNWRAPPING_KEY_SIZE_RANGE (0xf1)
  1023. #define CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT (0xf2)
  1024. #define CKR_USER_ALREADY_LOGGED_IN (0x100)
  1025. #define CKR_USER_NOT_LOGGED_IN (0x101)
  1026. #define CKR_USER_PIN_NOT_INITIALIZED (0x102)
  1027. #define CKR_USER_TYPE_INVALID (0x103)
  1028. #define CKR_USER_ANOTHER_ALREADY_LOGGED_IN (0x104)
  1029. #define CKR_USER_TOO_MANY_TYPES (0x105)
  1030. #define CKR_WRAPPED_KEY_INVALID (0x110)
  1031. #define CKR_WRAPPED_KEY_LEN_RANGE (0x112)
  1032. #define CKR_WRAPPING_KEY_HANDLE_INVALID (0x113)
  1033. #define CKR_WRAPPING_KEY_SIZE_RANGE (0x114)
  1034. #define CKR_WRAPPING_KEY_TYPE_INCONSISTENT (0x115)
  1035. #define CKR_RANDOM_SEED_NOT_SUPPORTED (0x120)
  1036. #define CKR_RANDOM_NO_RNG (0x121)
  1037. #define CKR_DOMAIN_PARAMS_INVALID (0x130)
  1038. #define CKR_BUFFER_TOO_SMALL (0x150)
  1039. #define CKR_SAVED_STATE_INVALID (0x160)
  1040. #define CKR_INFORMATION_SENSITIVE (0x170)
  1041. #define CKR_STATE_UNSAVEABLE (0x180)
  1042. #define CKR_CRYPTOKI_NOT_INITIALIZED (0x190)
  1043. #define CKR_CRYPTOKI_ALREADY_INITIALIZED (0x191)
  1044. #define CKR_MUTEX_BAD (0x1a0)
  1045. #define CKR_MUTEX_NOT_LOCKED (0x1a1)
  1046. #define CKR_FUNCTION_REJECTED (0x200)
  1047. #define CKR_VENDOR_DEFINED (1U << 31)
  1048. /* Compatibility layer. */
  1049. #ifdef CRYPTOKI_COMPAT
  1050. #undef CK_DEFINE_FUNCTION
  1051. #define CK_DEFINE_FUNCTION(retval, name) retval CK_SPEC name
  1052. /* For NULL. */
  1053. #include <stddef.h>
  1054. typedef unsigned char CK_BYTE;
  1055. typedef unsigned char CK_CHAR;
  1056. typedef unsigned char CK_UTF8CHAR;
  1057. typedef unsigned char CK_BBOOL;
  1058. typedef unsigned long int CK_ULONG;
  1059. typedef long int CK_LONG;
  1060. typedef CK_BYTE *CK_BYTE_PTR;
  1061. typedef CK_CHAR *CK_CHAR_PTR;
  1062. typedef CK_UTF8CHAR *CK_UTF8CHAR_PTR;
  1063. typedef CK_ULONG *CK_ULONG_PTR;
  1064. typedef void *CK_VOID_PTR;
  1065. typedef void **CK_VOID_PTR_PTR;
  1066. #define CK_FALSE 0
  1067. #define CK_TRUE 1
  1068. #ifndef CK_DISABLE_TRUE_FALSE
  1069. #ifndef FALSE
  1070. #define FALSE 0
  1071. #endif
  1072. #ifndef TRUE
  1073. #define TRUE 1
  1074. #endif
  1075. #endif
  1076. typedef struct ck_version CK_VERSION;
  1077. typedef struct ck_version *CK_VERSION_PTR;
  1078. typedef struct ck_info CK_INFO;
  1079. typedef struct ck_info *CK_INFO_PTR;
  1080. typedef ck_slot_id_t *CK_SLOT_ID_PTR;
  1081. typedef struct ck_slot_info CK_SLOT_INFO;
  1082. typedef struct ck_slot_info *CK_SLOT_INFO_PTR;
  1083. typedef struct ck_token_info CK_TOKEN_INFO;
  1084. typedef struct ck_token_info *CK_TOKEN_INFO_PTR;
  1085. typedef ck_session_handle_t *CK_SESSION_HANDLE_PTR;
  1086. typedef struct ck_session_info CK_SESSION_INFO;
  1087. typedef struct ck_session_info *CK_SESSION_INFO_PTR;
  1088. typedef ck_object_handle_t *CK_OBJECT_HANDLE_PTR;
  1089. typedef ck_object_class_t *CK_OBJECT_CLASS_PTR;
  1090. typedef struct ck_attribute CK_ATTRIBUTE;
  1091. typedef struct ck_attribute *CK_ATTRIBUTE_PTR;
  1092. typedef struct ck_date CK_DATE;
  1093. typedef struct ck_date *CK_DATE_PTR;
  1094. typedef ck_mechanism_type_t *CK_MECHANISM_TYPE_PTR;
  1095. typedef struct ck_mechanism CK_MECHANISM;
  1096. typedef struct ck_mechanism *CK_MECHANISM_PTR;
  1097. typedef struct ck_mechanism_info CK_MECHANISM_INFO;
  1098. typedef struct ck_mechanism_info *CK_MECHANISM_INFO_PTR;
  1099. typedef struct ck_function_list CK_FUNCTION_LIST;
  1100. typedef struct ck_function_list *CK_FUNCTION_LIST_PTR;
  1101. typedef struct ck_function_list **CK_FUNCTION_LIST_PTR_PTR;
  1102. typedef struct ck_c_initialize_args CK_C_INITIALIZE_ARGS;
  1103. typedef struct ck_c_initialize_args *CK_C_INITIALIZE_ARGS_PTR;
  1104. #define NULL_PTR NULL
  1105. /* Delete the helper macros defined at the top of the file. */
  1106. #undef ck_flags_t
  1107. #undef ck_version
  1108. #undef ck_info
  1109. #undef cryptoki_version
  1110. #undef manufacturer_id
  1111. #undef library_description
  1112. #undef library_version
  1113. #undef ck_notification_t
  1114. #undef ck_slot_id_t
  1115. #undef ck_slot_info
  1116. #undef slot_description
  1117. #undef hardware_version
  1118. #undef firmware_version
  1119. #undef ck_token_info
  1120. #undef serial_number
  1121. #undef max_session_count
  1122. #undef session_count
  1123. #undef max_rw_session_count
  1124. #undef rw_session_count
  1125. #undef max_pin_len
  1126. #undef min_pin_len
  1127. #undef total_public_memory
  1128. #undef free_public_memory
  1129. #undef total_private_memory
  1130. #undef free_private_memory
  1131. #undef utc_time
  1132. #undef ck_session_handle_t
  1133. #undef ck_user_type_t
  1134. #undef ck_state_t
  1135. #undef ck_session_info
  1136. #undef slot_id
  1137. #undef device_error
  1138. #undef ck_object_handle_t
  1139. #undef ck_object_class_t
  1140. #undef ck_hw_feature_type_t
  1141. #undef ck_key_type_t
  1142. #undef ck_certificate_type_t
  1143. #undef ck_attribute_type_t
  1144. #undef ck_attribute
  1145. #undef value
  1146. #undef value_len
  1147. #undef ck_date
  1148. #undef ck_mechanism_type_t
  1149. #undef ck_mechanism
  1150. #undef parameter
  1151. #undef parameter_len
  1152. #undef ck_mechanism_info
  1153. #undef min_key_size
  1154. #undef max_key_size
  1155. #undef ck_rv_t
  1156. #undef ck_notify_t
  1157. #undef ck_function_list
  1158. #undef ck_createmutex_t
  1159. #undef ck_destroymutex_t
  1160. #undef ck_lockmutex_t
  1161. #undef ck_unlockmutex_t
  1162. #undef ck_c_initialize_args
  1163. #undef create_mutex
  1164. #undef destroy_mutex
  1165. #undef lock_mutex
  1166. #undef unlock_mutex
  1167. #undef reserved
  1168. #endif /* CRYPTOKI_COMPAT */
  1169. /* System dependencies. */
  1170. #if defined(_WIN32) || defined(CRYPTOKI_FORCE_WIN32)
  1171. #pragma pack(pop, cryptoki)
  1172. #endif
  1173. #if defined(__cplusplus)
  1174. }
  1175. #endif
  1176. #endif /* PKCS11_H */