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