a294c5e94e5ce7934a1354d539d2d09262356795
[samba.git] / source4 / heimdal / lib / hx509 / ref / pkcs11.h
1 /* pkcs11.h
2    Copyright 2006, 2007 g10 Code GmbH
3    Copyright 2006 Andreas Jellinghaus
4
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
9    This file is distributed in the hope that it will be useful, but
10    WITHOUT ANY WARRANTY, to the extent permitted by law; without even
11    the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12    PURPOSE.  */
13
14 /* Please submit changes back to the Scute project at
15    http://www.scute.org/ (or send them to marcus@g10code.com), so that
16    they can be picked up by other projects from there as well.  */
17
18 /* This file is a modified implementation of the PKCS #11 standard by
19    RSA Security Inc.  It is mostly a drop-in replacement, with the
20    following change:
21
22    This header file does not require any macro definitions by the user
23    (like CK_DEFINE_FUNCTION etc).  In fact, it defines those macros
24    for you (if useful, some are missing, let me know if you need
25    more).
26
27    There is an additional API available that does comply better to the
28    GNU coding standard.  It can be switched on by defining
29    CRYPTOKI_GNU before including this header file.  For this, the
30    following changes are made to the specification:
31
32    All structure types are changed to a "struct ck_foo" where CK_FOO
33    is the type name in PKCS #11.
34
35    All non-structure types are changed to ck_foo_t where CK_FOO is the
36    lowercase version of the type name in PKCS #11.  The basic types
37    (CK_ULONG et al.) are removed without substitute.
38
39    All members of structures are modified in the following way: Type
40    indication prefixes are removed, and underscore characters are
41    inserted before words.  Then the result is lowercased.
42
43    Note that function names are still in the original case, as they
44    need for ABI compatibility.
45
46    CK_FALSE, CK_TRUE and NULL_PTR are removed without substitute.  Use
47    <stdbool.h>.
48
49    If CRYPTOKI_COMPAT is defined before including this header file,
50    then none of the API changes above take place, and the API is the
51    one defined by the PKCS #11 standard.  */
52
53 #ifndef PKCS11_H
54 #define PKCS11_H 1
55
56 #if defined(__cplusplus)
57 extern "C" {
58 #endif
59
60
61 /* The version of cryptoki we implement.  The revision is changed with
62    each modification of this file.  If you do not use the "official"
63    version of this file, please consider deleting the revision macro
64    (you may use a macro with a different name to keep track of your
65    versions).  */
66 #define CRYPTOKI_VERSION_MAJOR          2
67 #define CRYPTOKI_VERSION_MINOR          30
68 #define CRYPTOKI_VERSION_REVISION       0
69 #define CRYPTOKI_VERSION_AMENDMENT      0
70
71
72 /* Compatibility interface is default, unless CRYPTOKI_GNU is
73    given.  */
74 #ifndef CRYPTOKI_GNU
75 #ifndef CRYPTOKI_COMPAT
76 #define CRYPTOKI_COMPAT 1
77 #endif
78 #endif
79
80 /* System dependencies.  */
81
82 #if defined(_WIN32) || defined(CRYPTOKI_FORCE_WIN32)
83
84 /* There is a matching pop below.  */
85 #pragma pack(push, cryptoki, 1)
86
87 #ifdef CRYPTOKI_EXPORTS
88 #define CK_SPEC __declspec(dllexport)
89 #else
90 #define CK_SPEC __declspec(dllimport)
91 #endif
92
93 #else
94
95 #if defined(CRYPTOKI_VISIBILITY) && defined(CRYPTOKI_EXPORTS)
96 #define CK_SPEC __attribute__((visibility("default")))
97 #else
98 #define CK_SPEC
99 #endif
100
101 #endif
102
103 \f
104 #ifdef CRYPTOKI_COMPAT
105   /* If we are in compatibility mode, switch all exposed names to the
106      PKCS #11 variant.  There are corresponding #undefs below.  */
107
108 #define ck_flags_t CK_FLAGS
109 #define ck_version _CK_VERSION
110
111 #define ck_info _CK_INFO
112 #define cryptoki_version cryptokiVersion
113 #define manufacturer_id manufacturerID
114 #define library_description libraryDescription
115 #define library_version libraryVersion
116
117 #define ck_notification_t CK_NOTIFICATION
118 #define ck_slot_id_t CK_SLOT_ID
119
120 #define ck_slot_info _CK_SLOT_INFO
121 #define slot_description slotDescription
122 #define hardware_version hardwareVersion
123 #define firmware_version firmwareVersion
124
125 #define ck_token_info _CK_TOKEN_INFO
126 #define serial_number serialNumber
127 #define max_session_count ulMaxSessionCount
128 #define session_count ulSessionCount
129 #define max_rw_session_count ulMaxRwSessionCount
130 #define rw_session_count ulRwSessionCount
131 #define max_pin_len ulMaxPinLen
132 #define min_pin_len ulMinPinLen
133 #define total_public_memory ulTotalPublicMemory
134 #define free_public_memory ulFreePublicMemory
135 #define total_private_memory ulTotalPrivateMemory
136 #define free_private_memory ulFreePrivateMemory
137 #define utc_time utcTime
138
139 #define ck_session_handle_t CK_SESSION_HANDLE
140 #define ck_user_type_t CK_USER_TYPE
141 #define ck_state_t CK_STATE
142
143 #define ck_session_info _CK_SESSION_INFO
144 #define slot_id slotID
145 #define device_error ulDeviceError
146
147 #define ck_object_handle_t CK_OBJECT_HANDLE
148 #define ck_object_class_t CK_OBJECT_CLASS
149 #define ck_hw_feature_type_t CK_HW_FEATURE_TYPE
150 #define ck_key_type_t CK_KEY_TYPE
151 #define ck_certificate_type_t CK_CERTIFICATE_TYPE
152 #define ck_attribute_type_t CK_ATTRIBUTE_TYPE
153
154 #define ck_attribute _CK_ATTRIBUTE
155 #define value pValue
156 #define value_len ulValueLen
157
158 #define ck_date _CK_DATE
159
160 #define ck_mechanism_type_t CK_MECHANISM_TYPE
161
162 #define ck_mechanism _CK_MECHANISM
163 #define parameter pParameter
164 #define parameter_len ulParameterLen
165
166 #define ck_mechanism_info _CK_MECHANISM_INFO
167 #define min_key_size ulMinKeySize
168 #define max_key_size ulMaxKeySize
169
170 #define hash_alg hashAlg
171 #define source_data pSourceData
172 #define source_data_len ulSourceDataLen
173
174 #define slen sLen
175
176 #define ck_ec_kdf_type_t CK_EC_KDF_TYPE
177
178 #define shared_data_len ulSharedDataLen
179 #define shared_data pSharedData
180 #define public_data_len ulPublicDataLen
181 #define public_data pPublicData
182
183 #define private_data_len ulPrivateDataLen
184 #define private_data hPrivateData
185 #define public_data_len2 ulPublicDataLen2
186 #define public_data2 pPublicData2
187
188 #define public_key publicKey
189
190 #define ck_x9_42_dh_kdf_type_t CK_X9_42_DH_KDF_TYPE
191
192 #define other_info_len ulOtherInfoLen
193 #define other_info pOtherInfo
194
195 #define data pData
196 #define len ulLen
197
198 #define ck_rv_t CK_RV
199 #define ck_notify_t CK_NOTIFY
200
201 #define ck_function_list _CK_FUNCTION_LIST
202
203 #define ck_createmutex_t CK_CREATEMUTEX
204 #define ck_destroymutex_t CK_DESTROYMUTEX
205 #define ck_lockmutex_t CK_LOCKMUTEX
206 #define ck_unlockmutex_t CK_UNLOCKMUTEX
207
208 #define ck_c_initialize_args _CK_C_INITIALIZE_ARGS
209 #define create_mutex CreateMutex
210 #define destroy_mutex DestroyMutex
211 #define lock_mutex LockMutex
212 #define unlock_mutex UnlockMutex
213 #define reserved pReserved
214
215 #endif  /* CRYPTOKI_COMPAT */
216
217 \f
218
219 typedef unsigned long ck_flags_t;
220
221 struct ck_version
222 {
223   unsigned char major;
224   unsigned char minor;
225 };
226
227
228 struct ck_info
229 {
230   struct ck_version cryptoki_version;
231   unsigned char manufacturer_id[32];
232   ck_flags_t flags;
233   unsigned char library_description[32];
234   struct ck_version library_version;
235 };
236
237
238 typedef unsigned long ck_notification_t;
239
240 #define CKN_SURRENDER   (0)
241 #define CKN_OTP_CHANGED (1)
242
243 typedef unsigned long ck_slot_id_t;
244
245
246 struct ck_slot_info
247 {
248   unsigned char slot_description[64];
249   unsigned char manufacturer_id[32];
250   ck_flags_t flags;
251   struct ck_version hardware_version;
252   struct ck_version firmware_version;
253 };
254
255
256 #define CKF_TOKEN_PRESENT       (1 << 0)
257 #define CKF_REMOVABLE_DEVICE    (1 << 1)
258 #define CKF_HW_SLOT             (1 << 2)
259 #define CKF_ARRAY_ATTRIBUTE     (1 << 30)
260
261
262 struct ck_token_info
263 {
264   unsigned char label[32];
265   unsigned char manufacturer_id[32];
266   unsigned char model[16];
267   unsigned char serial_number[16];
268   ck_flags_t flags;
269   unsigned long max_session_count;
270   unsigned long session_count;
271   unsigned long max_rw_session_count;
272   unsigned long rw_session_count;
273   unsigned long max_pin_len;
274   unsigned long min_pin_len;
275   unsigned long total_public_memory;
276   unsigned long free_public_memory;
277   unsigned long total_private_memory;
278   unsigned long free_private_memory;
279   struct ck_version hardware_version;
280   struct ck_version firmware_version;
281   unsigned char utc_time[16];
282 };
283
284
285 #define CKF_RNG                                 (1 << 0)
286 #define CKF_WRITE_PROTECTED                     (1 << 1)
287 #define CKF_LOGIN_REQUIRED                      (1 << 2)
288 #define CKF_USER_PIN_INITIALIZED                (1 << 3)
289 #define CKF_RESTORE_KEY_NOT_NEEDED              (1 << 5)
290 #define CKF_CLOCK_ON_TOKEN                      (1 << 6)
291 #define CKF_PROTECTED_AUTHENTICATION_PATH       (1 << 8)
292 #define CKF_DUAL_CRYPTO_OPERATIONS              (1 << 9)
293 #define CKF_TOKEN_INITIALIZED                   (1 << 10)
294 #define CKF_SECONDARY_AUTHENTICATION            (1 << 11)
295 #define CKF_USER_PIN_COUNT_LOW                  (1 << 16)
296 #define CKF_USER_PIN_FINAL_TRY                  (1 << 17)
297 #define CKF_USER_PIN_LOCKED                     (1 << 18)
298 #define CKF_USER_PIN_TO_BE_CHANGED              (1 << 19)
299 #define CKF_SO_PIN_COUNT_LOW                    (1 << 20)
300 #define CKF_SO_PIN_FINAL_TRY                    (1 << 21)
301 #define CKF_SO_PIN_LOCKED                       (1 << 22)
302 #define CKF_SO_PIN_TO_BE_CHANGED                (1 << 23)
303 #define CKF_ERROR_STATE                         (1 << 24)
304
305 #define CK_UNAVAILABLE_INFORMATION      ((unsigned long) -1)
306 #define CK_EFFECTIVELY_INFINITE         (0)
307
308
309 typedef unsigned long ck_session_handle_t;
310
311 #define CK_INVALID_HANDLE       (0)
312
313
314 typedef unsigned long ck_user_type_t;
315
316 #define CKU_SO                  (0)
317 #define CKU_USER                (1)
318 #define CKU_CONTEXT_SPECIFIC    (2)
319
320
321 typedef unsigned long ck_state_t;
322
323 #define CKS_RO_PUBLIC_SESSION   (0)
324 #define CKS_RO_USER_FUNCTIONS   (1)
325 #define CKS_RW_PUBLIC_SESSION   (2)
326 #define CKS_RW_USER_FUNCTIONS   (3)
327 #define CKS_RW_SO_FUNCTIONS     (4)
328
329
330 struct ck_session_info
331 {
332   ck_slot_id_t slot_id;
333   ck_state_t state;
334   ck_flags_t flags;
335   unsigned long device_error;
336 };
337
338 #define CKF_RW_SESSION          (1 << 1)
339 #define CKF_SERIAL_SESSION      (1 << 2)
340
341
342 typedef unsigned long ck_object_handle_t;
343
344
345 typedef unsigned long ck_object_class_t;
346
347 #define CKO_DATA                (0)
348 #define CKO_CERTIFICATE         (1)
349 #define CKO_PUBLIC_KEY          (2)
350 #define CKO_PRIVATE_KEY         (3)
351 #define CKO_SECRET_KEY          (4)
352 #define CKO_HW_FEATURE          (5)
353 #define CKO_DOMAIN_PARAMETERS   (6)
354 #define CKO_MECHANISM           (7)
355 #define CKO_OTP_KEY             (8)
356 #define CKO_VENDOR_DEFINED      ((unsigned long) (1ul << 31))
357
358
359 typedef unsigned long ck_hw_feature_type_t;
360
361 #define CKH_MONOTONIC_COUNTER   (1)
362 #define CKH_CLOCK               (2)
363 #define CKH_USER_INTERFACE      (3)
364 #define CKH_VENDOR_DEFINED      ((unsigned long) (1ul << 31))
365
366
367 typedef unsigned long ck_key_type_t;
368
369 #define CKK_RSA                 (0)
370 #define CKK_DSA                 (1)
371 #define CKK_DH                  (2)
372 #define CKK_ECDSA               (3)
373 #define CKK_EC                  (3)
374 #define CKK_X9_42_DH            (4)
375 #define CKK_KEA                 (5)
376 #define CKK_GENERIC_SECRET      (0x10)
377 #define CKK_RC2                 (0x11)
378 #define CKK_RC4                 (0x12)
379 #define CKK_DES                 (0x13)
380 #define CKK_DES2                (0x14)
381 #define CKK_DES3                (0x15)
382 #define CKK_CAST                (0x16)
383 #define CKK_CAST3               (0x17)
384 #define CKK_CAST5               (0x18)
385 #define CKK_CAST128             (0x18)
386 #define CKK_RC5                 (0x19)
387 #define CKK_IDEA                (0x1a)
388 #define CKK_SKIPJACK            (0x1b)
389 #define CKK_BATON               (0x1c)
390 #define CKK_JUNIPER             (0x1d)
391 #define CKK_CDMF                (0x1e)
392 #define CKK_AES                 (0x1f)
393 #define CKK_BLOWFISH            (0x20)
394 #define CKK_TWOFISH             (0x21)
395 #define CKK_SECURID             (0x22)
396 #define CKK_HOTP                (0x23)
397 #define CKK_ACTI                (0x24)
398 #define CKK_CAMELLIA            (0x25)
399 #define CKK_ARIA                (0x26)
400 #define CKK_MD5_HMAC            (0x27)
401 #define CKK_SHA_1_HMAC          (0x28)
402 #define CKK_RIPEMD128_HMAC      (0x29)
403 #define CKK_RIPEMD160_HMAC      (0x2A)
404 #define CKK_SHA256_HMAC         (0x2B)
405 #define CKK_SHA384_HMAC         (0x2C)
406 #define CKK_SHA512_HMAC         (0x2D)
407 #define CKK_SHA224_HMAC         (0x2E)
408 #define CKK_SEED                (0x2F)
409 #define CKK_GOSTR3410           (0x30)
410 #define CKK_GOSTR3411           (0x31)
411 #define CKK_GOST28147           (0x32)
412 #define CKK_VENDOR_DEFINED      ((unsigned long) (1ul << 31))
413
414
415 typedef unsigned long ck_certificate_type_t;
416
417 #define CKC_X_509               (0)
418 #define CKC_X_509_ATTR_CERT     (1)
419 #define CKC_WTLS                (2)
420 #define CKC_VENDOR_DEFINED      ((unsigned long) (1ul << 31))
421 #define CKC_OPENPGP             (CKC_VENDOR_DEFINED|0x00504750)
422
423 #define CK_OTP_FORMAT_DECIMAL           (0)
424 #define CK_OTP_FORMAT_HEXADECIMAL       (1)
425 #define CK_OTP_FORMAT_ALPHANUMERIC      (2)
426 #define CK_OTP_FORMAT_BINARY            (3)
427
428 #define CK_OTP_PARAM_IGNORED            (0)
429 #define CK_OTP_PARAM_OPTIONAL           (1)
430 #define CK_OTP_PARAM_MANDATORY          (2)
431
432 typedef unsigned long ck_attribute_type_t;
433
434 #define CKA_CLASS                       (0)
435 #define CKA_TOKEN                       (1)
436 #define CKA_PRIVATE                     (2)
437 #define CKA_LABEL                       (3)
438 #define CKA_APPLICATION                 (0x10)
439 #define CKA_VALUE                       (0x11)
440 #define CKA_OBJECT_ID                   (0x12)
441 #define CKA_CERTIFICATE_TYPE            (0x80)
442 #define CKA_ISSUER                      (0x81)
443 #define CKA_SERIAL_NUMBER               (0x82)
444 #define CKA_AC_ISSUER                   (0x83)
445 #define CKA_OWNER                       (0x84)
446 #define CKA_ATTR_TYPES                  (0x85)
447 #define CKA_TRUSTED                     (0x86)
448 #define CKA_CERTIFICATE_CATEGORY        (0x87)
449 #define CKA_JAVA_MIDP_SECURITY_DOMAIN   (0x88)
450 #define CKA_URL                         (0x89)
451 #define CKA_HASH_OF_SUBJECT_PUBLIC_KEY  (0x8a)
452 #define CKA_HASH_OF_ISSUER_PUBLIC_KEY   (0x8b)
453 #define CKA_NAME_HASH_ALGORITHM         (0x8c)
454 #define CKA_CHECK_VALUE                 (0x90)
455 #define CKA_KEY_TYPE                    (0x100)
456 #define CKA_SUBJECT                     (0x101)
457 #define CKA_ID                          (0x102)
458 #define CKA_SENSITIVE                   (0x103)
459 #define CKA_ENCRYPT                     (0x104)
460 #define CKA_DECRYPT                     (0x105)
461 #define CKA_WRAP                        (0x106)
462 #define CKA_UNWRAP                      (0x107)
463 #define CKA_SIGN                        (0x108)
464 #define CKA_SIGN_RECOVER                (0x109)
465 #define CKA_VERIFY                      (0x10a)
466 #define CKA_VERIFY_RECOVER              (0x10b)
467 #define CKA_DERIVE                      (0x10c)
468 #define CKA_START_DATE                  (0x110)
469 #define CKA_END_DATE                    (0x111)
470 #define CKA_MODULUS                     (0x120)
471 #define CKA_MODULUS_BITS                (0x121)
472 #define CKA_PUBLIC_EXPONENT             (0x122)
473 #define CKA_PRIVATE_EXPONENT            (0x123)
474 #define CKA_PRIME_1                     (0x124)
475 #define CKA_PRIME_2                     (0x125)
476 #define CKA_EXPONENT_1                  (0x126)
477 #define CKA_EXPONENT_2                  (0x127)
478 #define CKA_COEFFICIENT                 (0x128)
479 #define CKA_PRIME                       (0x130)
480 #define CKA_SUBPRIME                    (0x131)
481 #define CKA_BASE                        (0x132)
482 #define CKA_PRIME_BITS                  (0x133)
483 #define CKA_SUB_PRIME_BITS              (0x134)
484 #define CKA_SUBPRIME_BITS               (0x134)
485 #define CKA_VALUE_BITS                  (0x160)
486 #define CKA_VALUE_LEN                   (0x161)
487 #define CKA_EXTRACTABLE                 (0x162)
488 #define CKA_LOCAL                       (0x163)
489 #define CKA_NEVER_EXTRACTABLE           (0x164)
490 #define CKA_ALWAYS_SENSITIVE            (0x165)
491 #define CKA_KEY_GEN_MECHANISM           (0x166)
492 #define CKA_MODIFIABLE                  (0x170)
493 #define CKA_COPYABLE                    (0x171)
494 #define CKA_ECDSA_PARAMS                (0x180)
495 #define CKA_EC_PARAMS                   (0x180)
496 #define CKA_EC_POINT                    (0x181)
497 #define CKA_SECONDARY_AUTH              (0x200)
498 #define CKA_AUTH_PIN_FLAGS              (0x201)
499 #define CKA_ALWAYS_AUTHENTICATE         (0x202)
500 #define CKA_WRAP_WITH_TRUSTED           (0x210)
501 #define CKA_OTP_FORMAT                  (0x220)
502 #define CKA_OTP_LENGTH                  (0x221)
503 #define CKA_OTP_TIME_INTERVAL           (0x222)
504 #define CKA_OTP_USER_FRIENDLY_MODE      (0x223)
505 #define CKA_OTP_CHALLENGE_REQUIREMENT   (0x224)
506 #define CKA_OTP_TIME_REQUIREMENT        (0x225)
507 #define CKA_OTP_COUNTER_REQUIREMENT     (0x226)
508 #define CKA_OTP_PIN_REQUIREMENT         (0x227)
509 #define CKA_OTP_COUNTER                 (0x22E)
510 #define CKA_OTP_TIME                    (0x22F)
511 #define CKA_OTP_USER_IDENTIFIER         (0x22A)
512 #define CKA_OTP_SERVICE_IDENTIFIER      (0x22B)
513 #define CKA_OTP_SERVICE_LOGO            (0x22C)
514 #define CKA_OTP_SERVICE_LOGO_TYPE       (0x22D)
515 #define CKA_GOSTR3410_PARAMS            (0x250)
516 #define CKA_GOSTR3411_PARAMS            (0x251)
517 #define CKA_GOST28147_PARAMS            (0x252)
518 #define CKA_HW_FEATURE_TYPE             (0x300)
519 #define CKA_RESET_ON_INIT               (0x301)
520 #define CKA_HAS_RESET                   (0x302)
521 #define CKA_PIXEL_X                     (0x400)
522 #define CKA_PIXEL_Y                     (0x401)
523 #define CKA_RESOLUTION                  (0x402)
524 #define CKA_CHAR_ROWS                   (0x403)
525 #define CKA_CHAR_COLUMNS                (0x404)
526 #define CKA_COLOR                       (0x405)
527 #define CKA_BITS_PER_PIXEL              (0x406)
528 #define CKA_CHAR_SETS                   (0x480)
529 #define CKA_ENCODING_METHODS            (0x481)
530 #define CKA_MIME_TYPES                  (0x482)
531 #define CKA_MECHANISM_TYPE              (0x500)
532 #define CKA_REQUIRED_CMS_ATTRIBUTES     (0x501)
533 #define CKA_DEFAULT_CMS_ATTRIBUTES      (0x502)
534 #define CKA_SUPPORTED_CMS_ATTRIBUTES    (0x503)
535 #define CKA_WRAP_TEMPLATE               (CKF_ARRAY_ATTRIBUTE | 0x211)
536 #define CKA_UNWRAP_TEMPLATE             (CKF_ARRAY_ATTRIBUTE | 0x212)
537 #define CKA_DERIVE_TEMPLATE             (CKF_ARRAY_ATTRIBUTE | 0x213)
538 #define CKA_ALLOWED_MECHANISMS          (CKF_ARRAY_ATTRIBUTE | 0x600)
539 #define CKA_VENDOR_DEFINED              ((unsigned long) (1ul << 31))
540
541
542 struct ck_attribute
543 {
544   ck_attribute_type_t type;
545   void *value;
546   unsigned long value_len;
547 };
548
549
550 struct ck_date
551 {
552   unsigned char year[4];
553   unsigned char month[2];
554   unsigned char day[2];
555 };
556
557
558 typedef unsigned long ck_mechanism_type_t;
559
560 #define CKM_RSA_PKCS_KEY_PAIR_GEN       (0)
561 #define CKM_RSA_PKCS                    (1)
562 #define CKM_RSA_9796                    (2)
563 #define CKM_RSA_X_509                   (3)
564 #define CKM_MD2_RSA_PKCS                (4)
565 #define CKM_MD5_RSA_PKCS                (5)
566 #define CKM_SHA1_RSA_PKCS               (6)
567 #define CKM_RIPEMD128_RSA_PKCS          (7)
568 #define CKM_RIPEMD160_RSA_PKCS          (8)
569 #define CKM_RSA_PKCS_OAEP               (9)
570 #define CKM_RSA_X9_31_KEY_PAIR_GEN      (0xa)
571 #define CKM_RSA_X9_31                   (0xb)
572 #define CKM_SHA1_RSA_X9_31              (0xc)
573 #define CKM_RSA_PKCS_PSS                (0xd)
574 #define CKM_SHA1_RSA_PKCS_PSS           (0xe)
575 #define CKM_DSA_KEY_PAIR_GEN            (0x10)
576 #define CKM_DSA                         (0x11)
577 #define CKM_DSA_SHA1                    (0x12)
578 #define CKM_DSA_SHA224                  (0x13)
579 #define CKM_DSA_SHA256                  (0x14)
580 #define CKM_DSA_SHA384                  (0x15)
581 #define CKM_DSA_SHA512                  (0x16)
582 #define CKM_DH_PKCS_KEY_PAIR_GEN        (0x20)
583 #define CKM_DH_PKCS_DERIVE              (0x21)
584 #define CKM_X9_42_DH_KEY_PAIR_GEN       (0x30)
585 #define CKM_X9_42_DH_DERIVE             (0x31)
586 #define CKM_X9_42_DH_HYBRID_DERIVE      (0x32)
587 #define CKM_X9_42_MQV_DERIVE            (0x33)
588 #define CKM_SHA256_RSA_PKCS             (0x40)
589 #define CKM_SHA384_RSA_PKCS             (0x41)
590 #define CKM_SHA512_RSA_PKCS             (0x42)
591 #define CKM_SHA256_RSA_PKCS_PSS         (0x43)
592 #define CKM_SHA384_RSA_PKCS_PSS         (0x44)
593 #define CKM_SHA512_RSA_PKCS_PSS         (0x45)
594 #define CKM_SHA224_RSA_PKCS             (0x46)
595 #define CKM_SHA224_RSA_PKCS_PSS         (0x47)
596 #define CKM_RC2_KEY_GEN                 (0x100)
597 #define CKM_RC2_ECB                     (0x101)
598 #define CKM_RC2_CBC                     (0x102)
599 #define CKM_RC2_MAC                     (0x103)
600 #define CKM_RC2_MAC_GENERAL             (0x104)
601 #define CKM_RC2_CBC_PAD                 (0x105)
602 #define CKM_RC4_KEY_GEN                 (0x110)
603 #define CKM_RC4                         (0x111)
604 #define CKM_DES_KEY_GEN                 (0x120)
605 #define CKM_DES_ECB                     (0x121)
606 #define CKM_DES_CBC                     (0x122)
607 #define CKM_DES_MAC                     (0x123)
608 #define CKM_DES_MAC_GENERAL             (0x124)
609 #define CKM_DES_CBC_PAD                 (0x125)
610 #define CKM_DES2_KEY_GEN                (0x130)
611 #define CKM_DES3_KEY_GEN                (0x131)
612 #define CKM_DES3_ECB                    (0x132)
613 #define CKM_DES3_CBC                    (0x133)
614 #define CKM_DES3_MAC                    (0x134)
615 #define CKM_DES3_MAC_GENERAL            (0x135)
616 #define CKM_DES3_CBC_PAD                (0x136)
617 #define CKM_DES3_CMAC_GENERAL           (0x137)
618 #define CKM_DES3_CMAC                   (0x138)
619 #define CKM_CDMF_KEY_GEN                (0x140)
620 #define CKM_CDMF_ECB                    (0x141)
621 #define CKM_CDMF_CBC                    (0x142)
622 #define CKM_CDMF_MAC                    (0x143)
623 #define CKM_CDMF_MAC_GENERAL            (0x144)
624 #define CKM_CDMF_CBC_PAD                (0x145)
625 #define CKM_DES_OFB64                   (0x150)
626 #define CKM_DES_OFB8                    (0x151)
627 #define CKM_DES_CFB64                   (0x152)
628 #define CKM_DES_CFB8                    (0x153)
629 #define CKM_MD2                         (0x200)
630 #define CKM_MD2_HMAC                    (0x201)
631 #define CKM_MD2_HMAC_GENERAL            (0x202)
632 #define CKM_MD5                         (0x210)
633 #define CKM_MD5_HMAC                    (0x211)
634 #define CKM_MD5_HMAC_GENERAL            (0x212)
635 #define CKM_SHA_1                       (0x220)
636 #define CKM_SHA_1_HMAC                  (0x221)
637 #define CKM_SHA_1_HMAC_GENERAL          (0x222)
638 #define CKM_RIPEMD128                   (0x230)
639 #define CKM_RIPEMD128_HMAC              (0x231)
640 #define CKM_RIPEMD128_HMAC_GENERAL      (0x232)
641 #define CKM_RIPEMD160                   (0x240)
642 #define CKM_RIPEMD160_HMAC              (0x241)
643 #define CKM_RIPEMD160_HMAC_GENERAL      (0x242)
644 #define CKM_SHA256                      (0x250)
645 #define CKM_SHA256_HMAC                 (0x251)
646 #define CKM_SHA256_HMAC_GENERAL         (0x252)
647 #define CKM_SHA224                      (0x255)
648 #define CKM_SHA224_HMAC                 (0x256)
649 #define CKM_SHA224_HMAC_GENERAL         (0x257)
650 #define CKM_SHA384                      (0x260)
651 #define CKM_SHA384_HMAC                 (0x261)
652 #define CKM_SHA384_HMAC_GENERAL         (0x262)
653 #define CKM_SHA512                      (0x270)
654 #define CKM_SHA512_HMAC                 (0x271)
655 #define CKM_SHA512_HMAC_GENERAL         (0x272)
656 #define CKM_SECURID_KEY_GEN             (0x280)
657 #define CKM_SECURID                     (0x282)
658 #define CKM_HOTP_KEY_GEN                (0x290)
659 #define CKM_HOTP                        (0x291)
660 #define CKM_ACTI                        (0x2A0)
661 #define CKM_ACTI_KEY_GEN                (0x2A1)
662 #define CKM_CAST_KEY_GEN                (0x300)
663 #define CKM_CAST_ECB                    (0x301)
664 #define CKM_CAST_CBC                    (0x302)
665 #define CKM_CAST_MAC                    (0x303)
666 #define CKM_CAST_MAC_GENERAL            (0x304)
667 #define CKM_CAST_CBC_PAD                (0x305)
668 #define CKM_CAST3_KEY_GEN               (0x310)
669 #define CKM_CAST3_ECB                   (0x311)
670 #define CKM_CAST3_CBC                   (0x312)
671 #define CKM_CAST3_MAC                   (0x313)
672 #define CKM_CAST3_MAC_GENERAL           (0x314)
673 #define CKM_CAST3_CBC_PAD               (0x315)
674 #define CKM_CAST5_KEY_GEN               (0x320)
675 #define CKM_CAST128_KEY_GEN             (0x320)
676 #define CKM_CAST5_ECB                   (0x321)
677 #define CKM_CAST128_ECB                 (0x321)
678 #define CKM_CAST5_CBC                   (0x322)
679 #define CKM_CAST128_CBC                 (0x322)
680 #define CKM_CAST5_MAC                   (0x323)
681 #define CKM_CAST128_MAC                 (0x323)
682 #define CKM_CAST5_MAC_GENERAL           (0x324)
683 #define CKM_CAST128_MAC_GENERAL         (0x324)
684 #define CKM_CAST5_CBC_PAD               (0x325)
685 #define CKM_CAST128_CBC_PAD             (0x325)
686 #define CKM_RC5_KEY_GEN                 (0x330)
687 #define CKM_RC5_ECB                     (0x331)
688 #define CKM_RC5_CBC                     (0x332)
689 #define CKM_RC5_MAC                     (0x333)
690 #define CKM_RC5_MAC_GENERAL             (0x334)
691 #define CKM_RC5_CBC_PAD                 (0x335)
692 #define CKM_IDEA_KEY_GEN                (0x340)
693 #define CKM_IDEA_ECB                    (0x341)
694 #define CKM_IDEA_CBC                    (0x342)
695 #define CKM_IDEA_MAC                    (0x343)
696 #define CKM_IDEA_MAC_GENERAL            (0x344)
697 #define CKM_IDEA_CBC_PAD                (0x345)
698 #define CKM_GENERIC_SECRET_KEY_GEN      (0x350)
699 #define CKM_CONCATENATE_BASE_AND_KEY    (0x360)
700 #define CKM_CONCATENATE_BASE_AND_DATA   (0x362)
701 #define CKM_CONCATENATE_DATA_AND_BASE   (0x363)
702 #define CKM_XOR_BASE_AND_DATA           (0x364)
703 #define CKM_EXTRACT_KEY_FROM_KEY        (0x365)
704 #define CKM_SSL3_PRE_MASTER_KEY_GEN     (0x370)
705 #define CKM_SSL3_MASTER_KEY_DERIVE      (0x371)
706 #define CKM_SSL3_KEY_AND_MAC_DERIVE     (0x372)
707 #define CKM_SSL3_MASTER_KEY_DERIVE_DH   (0x373)
708 #define CKM_TLS_PRE_MASTER_KEY_GEN      (0x374)
709 #define CKM_TLS_MASTER_KEY_DERIVE       (0x375)
710 #define CKM_TLS_KEY_AND_MAC_DERIVE      (0x376)
711 #define CKM_TLS_MASTER_KEY_DERIVE_DH    (0x377)
712 #define CKM_TLS_PRF                     (0x378)
713 #define CKM_SSL3_MD5_MAC                (0x380)
714 #define CKM_SSL3_SHA1_MAC               (0x381)
715 #define CKM_MD5_KEY_DERIVATION          (0x390)
716 #define CKM_MD2_KEY_DERIVATION          (0x391)
717 #define CKM_SHA1_KEY_DERIVATION         (0x392)
718 #define CKM_SHA256_KEY_DERIVATION       (0x393)
719 #define CKM_SHA384_KEY_DERIVATION       (0x394)
720 #define CKM_SHA512_KEY_DERIVATION       (0x395)
721 #define CKM_SHA224_KEY_DERIVATION       (0x396)
722 #define CKM_PBE_MD2_DES_CBC             (0x3a0)
723 #define CKM_PBE_MD5_DES_CBC             (0x3a1)
724 #define CKM_PBE_MD5_CAST_CBC            (0x3a2)
725 #define CKM_PBE_MD5_CAST3_CBC           (0x3a3)
726 #define CKM_PBE_MD5_CAST5_CBC           (0x3a4)
727 #define CKM_PBE_MD5_CAST128_CBC         (0x3a4)
728 #define CKM_PBE_SHA1_CAST5_CBC          (0x3a5)
729 #define CKM_PBE_SHA1_CAST128_CBC        (0x3a5)
730 #define CKM_PBE_SHA1_RC4_128            (0x3a6)
731 #define CKM_PBE_SHA1_RC4_40             (0x3a7)
732 #define CKM_PBE_SHA1_DES3_EDE_CBC       (0x3a8)
733 #define CKM_PBE_SHA1_DES2_EDE_CBC       (0x3a9)
734 #define CKM_PBE_SHA1_RC2_128_CBC        (0x3aa)
735 #define CKM_PBE_SHA1_RC2_40_CBC         (0x3ab)
736 #define CKM_PKCS5_PBKD2                 (0x3b0)
737 #define CKM_PBA_SHA1_WITH_SHA1_HMAC     (0x3c0)
738 #define CKM_WTLS_PRE_MASTER_KEY_GEN     (0x3d0)
739 #define CKM_WTLS_MASTER_KEY_DERIVE      (0x3d1)
740 #define CKM_WTLS_MASTER_KEY_DERIVE_DH_ECC (0x3d2)
741 #define CKM_WTLS_PRF                    (0x3d3)
742 #define CKM_WTLS_SERVER_KEY_AND_MAC_DERIVE (0x3d4)
743 #define CKM_WTLS_CLIENT_KEY_AND_MAC_DERIVE (0x3d5)
744 #define CKM_KEY_WRAP_LYNKS              (0x400)
745 #define CKM_KEY_WRAP_SET_OAEP           (0x401)
746 #define CKM_CMS_SIG                     (0x500)
747 #define CKM_KIP_DERIVE                  (0x510)
748 #define CKM_KIP_WRAP                    (0x511)
749 #define CKM_KIP_MAC                     (0x512)
750 #define CKM_CAMELLIA_KEY_GEN            (0x550)
751 #define CKM_CAMELLIA_ECB                (0x551)
752 #define CKM_CAMELLIA_CBC                (0x552)
753 #define CKM_CAMELLIA_MAC                (0x553)
754 #define CKM_CAMELLIA_MAC_GENERAL        (0x554)
755 #define CKM_CAMELLIA_CBC_PAD            (0x555)
756 #define CKM_CAMELLIA_ECB_ENCRYPT_DATA   (0x556)
757 #define CKM_CAMELLIA_CBC_ENCRYPT_DATA   (0x557)
758 #define CKM_CAMELLIA_CTR                (0x558)
759 #define CKM_ARIA_KEY_GEN                (0x560)
760 #define CKM_ARIA_ECB                    (0x561)
761 #define CKM_ARIA_CBC                    (0x562)
762 #define CKM_ARIA_MAC                    (0x563)
763 #define CKM_ARIA_MAC_GENERAL            (0x564)
764 #define CKM_ARIA_CBC_PAD                (0x565)
765 #define CKM_ARIA_ECB_ENCRYPT_DATA       (0x566)
766 #define CKM_ARIA_CBC_ENCRYPT_DATA       (0x567)
767 #define CKM_SEED_KEY_GEN                (0x650)
768 #define CKM_SEED_ECB                    (0x651)
769 #define CKM_SEED_CBC                    (0x652)
770 #define CKM_SEED_MAC                    (0x653)
771 #define CKM_SEED_MAC_GENERAL            (0x654)
772 #define CKM_SEED_CBC_PAD                (0x655)
773 #define CKM_SEED_ECB_ENCRYPT_DATA       (0x656)
774 #define CKM_SEED_CBC_ENCRYPT_DATA       (0x657)
775 #define CKM_SKIPJACK_KEY_GEN            (0x1000)
776 #define CKM_SKIPJACK_ECB64              (0x1001)
777 #define CKM_SKIPJACK_CBC64              (0x1002)
778 #define CKM_SKIPJACK_OFB64              (0x1003)
779 #define CKM_SKIPJACK_CFB64              (0x1004)
780 #define CKM_SKIPJACK_CFB32              (0x1005)
781 #define CKM_SKIPJACK_CFB16              (0x1006)
782 #define CKM_SKIPJACK_CFB8               (0x1007)
783 #define CKM_SKIPJACK_WRAP               (0x1008)
784 #define CKM_SKIPJACK_PRIVATE_WRAP       (0x1009)
785 #define CKM_SKIPJACK_RELAYX             (0x100a)
786 #define CKM_KEA_KEY_PAIR_GEN            (0x1010)
787 #define CKM_KEA_KEY_DERIVE              (0x1011)
788 #define CKM_FORTEZZA_TIMESTAMP          (0x1020)
789 #define CKM_BATON_KEY_GEN               (0x1030)
790 #define CKM_BATON_ECB128                (0x1031)
791 #define CKM_BATON_ECB96                 (0x1032)
792 #define CKM_BATON_CBC128                (0x1033)
793 #define CKM_BATON_COUNTER               (0x1034)
794 #define CKM_BATON_SHUFFLE               (0x1035)
795 #define CKM_BATON_WRAP                  (0x1036)
796 #define CKM_ECDSA_KEY_PAIR_GEN          (0x1040)
797 #define CKM_EC_KEY_PAIR_GEN             (0x1040)
798 #define CKM_ECDSA                       (0x1041)
799 #define CKM_ECDSA_SHA1                  (0x1042)
800 #define CKM_ECDSA_SHA224                (0x1043)
801 #define CKM_ECDSA_SHA256                (0x1044)
802 #define CKM_ECDSA_SHA384                (0x1045)
803 #define CKM_ECDSA_SHA512                (0x1046)
804 #define CKM_ECDH1_DERIVE                (0x1050)
805 #define CKM_ECDH1_COFACTOR_DERIVE       (0x1051)
806 #define CKM_ECMQV_DERIVE                (0x1052)
807 #define CKM_JUNIPER_KEY_GEN             (0x1060)
808 #define CKM_JUNIPER_ECB128              (0x1061)
809 #define CKM_JUNIPER_CBC128              (0x1062)
810 #define CKM_JUNIPER_COUNTER             (0x1063)
811 #define CKM_JUNIPER_SHUFFLE             (0x1064)
812 #define CKM_JUNIPER_WRAP                (0x1065)
813 #define CKM_FASTHASH                    (0x1070)
814 #define CKM_AES_KEY_GEN                 (0x1080)
815 #define CKM_AES_ECB                     (0x1081)
816 #define CKM_AES_CBC                     (0x1082)
817 #define CKM_AES_MAC                     (0x1083)
818 #define CKM_AES_MAC_GENERAL             (0x1084)
819 #define CKM_AES_CBC_PAD                 (0x1085)
820 #define CKM_AES_CTR                     (0x1086)
821 #define CKM_AES_GCM                     (0x1087)
822 #define CKM_AES_CCM                     (0x1088)
823 #define CKM_AES_CTS                     (0x1089)
824 #define CKM_AES_CMAC                    (0x108a)
825 #define CKM_AES_CMAC_GENERAL            (0x108b)
826 #define CKM_BLOWFISH_KEY_GEN            (0x1090)
827 #define CKM_BLOWFISH_CBC                (0x1091)
828 #define CKM_TWOFISH_KEY_GEN             (0x1092)
829 #define CKM_TWOFISH_CBC                 (0x1093)
830 #define CKM_BLOWFISH_CBC_PAD            (0x1094)
831 #define CKM_TWOFISH_CBC_PAD             (0x1095)
832 #define CKM_DES_ECB_ENCRYPT_DATA        (0x1100)
833 #define CKM_DES_CBC_ENCRYPT_DATA        (0x1101)
834 #define CKM_DES3_ECB_ENCRYPT_DATA       (0x1102)
835 #define CKM_DES3_CBC_ENCRYPT_DATA       (0x1103)
836 #define CKM_AES_ECB_ENCRYPT_DATA        (0x1104)
837 #define CKM_AES_CBC_ENCRYPT_DATA        (0x1105)
838 #define CKM_GOSTR3410_KEY_PAIR_GEN      (0x1200)
839 #define CKM_GOSTR3410                   (0x1201)
840 #define CKM_GOSTR3410_WITH_GOSTR3411    (0x1202)
841 #define CKM_GOSTR3410_KEY_WRAP          (0x1203)
842 #define CKM_GOSTR3410_DERIVE            (0x1204)
843 #define CKM_GOSTR3411                   (0x1210)
844 #define CKM_GOSTR3411_HMAC              (0x1211)
845 #define CKM_GOST28147_KEY_GEN           (0x1220)
846 #define CKM_GOST28147_ECB               (0x1221)
847 #define CKM_GOST28147                   (0x1222)
848 #define CKM_GOST28147_MAC               (0x1223)
849 #define CKM_GOST28147_KEY_WRAP          (0x1224)
850 #define CKM_DSA_PARAMETER_GEN           (0x2000)
851 #define CKM_DH_PKCS_PARAMETER_GEN       (0x2001)
852 #define CKM_X9_42_DH_PARAMETER_GEN      (0x2002)
853 #define CKM_AES_OFB                     (0x2104)
854 #define CKM_AES_CFB64                   (0x2105)
855 #define CKM_AES_CFB8                    (0x2106)
856 #define CKM_AES_CFB128                  (0x2107)
857 #define CKM_AES_KEY_WRAP                (0x2109)
858 #define CKM_AES_KEY_WRAP_PAD            (0x210a)
859 #define CKM_RSA_PKCS_TPM_1_1            (0x4001)
860 #define CKM_RSA_PKCS_OAEPTPM_1_1        (0x4002)
861 #define CKM_VENDOR_DEFINED              ((unsigned long) (1ul << 31))
862
863
864 struct ck_mechanism
865 {
866   ck_mechanism_type_t mechanism;
867   void *parameter;
868   unsigned long parameter_len;
869 };
870
871
872 struct ck_mechanism_info
873 {
874   unsigned long min_key_size;
875   unsigned long max_key_size;
876   ck_flags_t flags;
877 };
878
879 #define CKF_HW                  (1 << 0)
880 #define CKF_ENCRYPT             (1 << 8)
881 #define CKF_DECRYPT             (1 << 9)
882 #define CKF_DIGEST              (1 << 10)
883 #define CKF_SIGN                (1 << 11)
884 #define CKF_SIGN_RECOVER        (1 << 12)
885 #define CKF_VERIFY              (1 << 13)
886 #define CKF_VERIFY_RECOVER      (1 << 14)
887 #define CKF_GENERATE            (1 << 15)
888 #define CKF_GENERATE_KEY_PAIR   (1 << 16)
889 #define CKF_WRAP                (1 << 17)
890 #define CKF_UNWRAP              (1 << 18)
891 #define CKF_DERIVE              (1 << 19)
892 #define CKF_EC_F_P              (1 << 20)
893 #define CKF_EC_F_2M             (1 << 21)
894 #define CKF_EC_ECPARAMETERS     (1 << 22)
895 #define CKF_EC_NAMEDCURVE       (1 << 23)
896 #define CKF_EC_UNCOMPRESS       (1 << 24)
897 #define CKF_EC_COMPRESS         (1 << 25)
898 #define CKF_EXTENSION           ((unsigned long) (1ul << 31))
899
900
901 /* The following MGFs are defined */
902 #define CKG_MGF1_SHA1         (0x00000001)
903 #define CKG_MGF1_SHA256       (0x00000002)
904 #define CKG_MGF1_SHA384       (0x00000003)
905 #define CKG_MGF1_SHA512       (0x00000004)
906 #define CKG_MGF1_SHA224       (0x00000005)
907
908 #define CKZ_DATA_SPECIFIED    (0x00000001)
909
910 struct ck_rsa_pkcs_oaep_params {
911   ck_mechanism_type_t hash_alg;
912   unsigned long mgf;
913   unsigned long source;
914   void *source_data;
915   unsigned long source_data_len;
916 };
917
918 struct ck_rsa_pkcs_pss_params {
919   ck_mechanism_type_t hash_alg;
920   unsigned long mgf;
921   unsigned long slen;
922 };
923
924 typedef unsigned long ck_ec_kdf_type_t;
925
926 /* The following EC Key Derivation Functions are defined */
927 #define CKD_NULL                       (0x00000001)
928 #define CKD_SHA1_KDF                   (0x00000002)
929
930 struct ck_ecdh1_derive_params {
931   ck_ec_kdf_type_t kdf;
932   unsigned long shared_data_len;
933   unsigned char *shared_data;
934   unsigned long public_data_len;
935   unsigned char *public_data;
936 };
937
938 struct ck_ecdh2_derive_params {
939   ck_ec_kdf_type_t kdf;
940   unsigned long shared_data_len;
941   unsigned char *shared_data;
942   unsigned long public_data_len;
943   unsigned char *public_data;
944   unsigned long private_data_len;
945   ck_object_handle_t private_data;
946   unsigned long public_data_len2;
947   unsigned char *public_data2;
948 };
949
950 struct ck_ecmqv_derive_params {
951   ck_ec_kdf_type_t kdf;
952   unsigned long shared_data_len;
953   unsigned char *shared_data;
954   unsigned long public_data_len;
955   unsigned char *public_data;
956   unsigned long private_data_len;
957   ck_object_handle_t private_data;
958   unsigned long public_data_len2;
959   unsigned char *public_data2;
960   ck_object_handle_t public_key;
961 };
962
963 typedef unsigned long ck_x9_42_dh_kdf_type_t;
964
965 /* The following X9.42 DH key derivation functions are defined */
966 #define CKD_SHA1_KDF_ASN1              (0x00000003)
967 #define CKD_SHA1_KDF_CONCATENATE       (0x00000004)
968 #define CKD_SHA224_KDF                 (0x00000005)
969 #define CKD_SHA256_KDF                 (0x00000006)
970 #define CKD_SHA384_KDF                 (0x00000007)
971 #define CKD_SHA512_KDF                 (0x00000008)
972 #define CKD_CPDIVERSIFY_KDF            (0x00000009)
973
974 struct ck_x9_42_dh1_derive_params {
975   ck_x9_42_dh_kdf_type_t kdf;
976   unsigned long other_info_len;
977   unsigned char *other_info;
978   unsigned long public_data_len;
979   unsigned char *public_data;
980 };
981
982 struct ck_x9_42_dh2_derive_params {
983   ck_x9_42_dh_kdf_type_t kdf;
984   unsigned long other_info_len;
985   unsigned char *other_info;
986   unsigned long public_data_len;
987   unsigned char *public_data;
988   unsigned long private_data_len;
989   ck_object_handle_t private_data;
990   unsigned long public_data_len2;
991   unsigned char *public_data2;
992 };
993
994 struct ck_x9_42_mqv_derive_params {
995   ck_x9_42_dh_kdf_type_t kdf;
996   unsigned long other_info_len;
997   unsigned char *other_info;
998   unsigned long public_data_len;
999   unsigned char *public_data;
1000   unsigned long private_data_len;
1001   ck_object_handle_t private_data;
1002   unsigned long public_data_len2;
1003   unsigned char *public_data2;
1004   ck_object_handle_t public_key;
1005 };
1006
1007 struct ck_des_cbc_encrypt_data_params {
1008   unsigned char iv[8];
1009   unsigned char *data;
1010   unsigned long length;
1011 };
1012
1013 struct ck_aes_cbc_encrypt_data_params {
1014   unsigned char iv[16];
1015   unsigned char *data;
1016   unsigned long length;
1017 };
1018
1019 struct ck_key_derivation_string_data {
1020   unsigned char *data;
1021   unsigned long len;
1022 };
1023
1024 /* Flags for C_WaitForSlotEvent.  */
1025 #define CKF_DONT_BLOCK                          (1)
1026
1027
1028 typedef unsigned long ck_rv_t;
1029
1030
1031 typedef ck_rv_t (*ck_notify_t) (ck_session_handle_t session,
1032                                 ck_notification_t event, void *application);
1033
1034 /* Forward reference.  */
1035 struct ck_function_list;
1036
1037 #define _CK_DECLARE_FUNCTION(name, args)        \
1038 typedef ck_rv_t (*CK_ ## name) args;            \
1039 ck_rv_t CK_SPEC name args
1040
1041 _CK_DECLARE_FUNCTION (C_Initialize, (void *init_args));
1042 _CK_DECLARE_FUNCTION (C_Finalize, (void *reserved));
1043 _CK_DECLARE_FUNCTION (C_GetInfo, (struct ck_info *info));
1044 _CK_DECLARE_FUNCTION (C_GetFunctionList,
1045                       (struct ck_function_list **function_list));
1046
1047 _CK_DECLARE_FUNCTION (C_GetSlotList,
1048                       (unsigned char token_present, ck_slot_id_t *slot_list,
1049                        unsigned long *count));
1050 _CK_DECLARE_FUNCTION (C_GetSlotInfo,
1051                       (ck_slot_id_t slot_id, struct ck_slot_info *info));
1052 _CK_DECLARE_FUNCTION (C_GetTokenInfo,
1053                       (ck_slot_id_t slot_id, struct ck_token_info *info));
1054 _CK_DECLARE_FUNCTION (C_WaitForSlotEvent,
1055                       (ck_flags_t flags, ck_slot_id_t *slot, void *reserved));
1056 _CK_DECLARE_FUNCTION (C_GetMechanismList,
1057                       (ck_slot_id_t slot_id,
1058                        ck_mechanism_type_t *mechanism_list,
1059                        unsigned long *count));
1060 _CK_DECLARE_FUNCTION (C_GetMechanismInfo,
1061                       (ck_slot_id_t slot_id, ck_mechanism_type_t type,
1062                        struct ck_mechanism_info *info));
1063 _CK_DECLARE_FUNCTION (C_InitToken,
1064                       (ck_slot_id_t slot_id, unsigned char *pin,
1065                        unsigned long pin_len, unsigned char *label));
1066 _CK_DECLARE_FUNCTION (C_InitPIN,
1067                       (ck_session_handle_t session, unsigned char *pin,
1068                        unsigned long pin_len));
1069 _CK_DECLARE_FUNCTION (C_SetPIN,
1070                       (ck_session_handle_t session, unsigned char *old_pin,
1071                        unsigned long old_len, unsigned char *new_pin,
1072                        unsigned long new_len));
1073
1074 _CK_DECLARE_FUNCTION (C_OpenSession,
1075                       (ck_slot_id_t slot_id, ck_flags_t flags,
1076                        void *application, ck_notify_t notify,
1077                        ck_session_handle_t *session));
1078 _CK_DECLARE_FUNCTION (C_CloseSession, (ck_session_handle_t session));
1079 _CK_DECLARE_FUNCTION (C_CloseAllSessions, (ck_slot_id_t slot_id));
1080 _CK_DECLARE_FUNCTION (C_GetSessionInfo,
1081                       (ck_session_handle_t session,
1082                        struct ck_session_info *info));
1083 _CK_DECLARE_FUNCTION (C_GetOperationState,
1084                       (ck_session_handle_t session,
1085                        unsigned char *operation_state,
1086                        unsigned long *operation_state_len));
1087 _CK_DECLARE_FUNCTION (C_SetOperationState,
1088                       (ck_session_handle_t session,
1089                        unsigned char *operation_state,
1090                        unsigned long operation_state_len,
1091                        ck_object_handle_t encryption_key,
1092                        ck_object_handle_t authentiation_key));
1093 _CK_DECLARE_FUNCTION (C_Login,
1094                       (ck_session_handle_t session, ck_user_type_t user_type,
1095                        unsigned char *pin, unsigned long pin_len));
1096 _CK_DECLARE_FUNCTION (C_Logout, (ck_session_handle_t session));
1097
1098 _CK_DECLARE_FUNCTION (C_CreateObject,
1099                       (ck_session_handle_t session,
1100                        struct ck_attribute *templ,
1101                        unsigned long count, ck_object_handle_t *object));
1102 _CK_DECLARE_FUNCTION (C_CopyObject,
1103                       (ck_session_handle_t session, ck_object_handle_t object,
1104                        struct ck_attribute *templ, unsigned long count,
1105                        ck_object_handle_t *new_object));
1106 _CK_DECLARE_FUNCTION (C_DestroyObject,
1107                       (ck_session_handle_t session,
1108                        ck_object_handle_t object));
1109 _CK_DECLARE_FUNCTION (C_GetObjectSize,
1110                       (ck_session_handle_t session,
1111                        ck_object_handle_t object,
1112                        unsigned long *size));
1113 _CK_DECLARE_FUNCTION (C_GetAttributeValue,
1114                       (ck_session_handle_t session,
1115                        ck_object_handle_t object,
1116                        struct ck_attribute *templ,
1117                        unsigned long count));
1118 _CK_DECLARE_FUNCTION (C_SetAttributeValue,
1119                       (ck_session_handle_t session,
1120                        ck_object_handle_t object,
1121                        struct ck_attribute *templ,
1122                        unsigned long count));
1123 _CK_DECLARE_FUNCTION (C_FindObjectsInit,
1124                       (ck_session_handle_t session,
1125                        struct ck_attribute *templ,
1126                        unsigned long count));
1127 _CK_DECLARE_FUNCTION (C_FindObjects,
1128                       (ck_session_handle_t session,
1129                        ck_object_handle_t *object,
1130                        unsigned long max_object_count,
1131                        unsigned long *object_count));
1132 _CK_DECLARE_FUNCTION (C_FindObjectsFinal,
1133                       (ck_session_handle_t session));
1134
1135 _CK_DECLARE_FUNCTION (C_EncryptInit,
1136                       (ck_session_handle_t session,
1137                        struct ck_mechanism *mechanism,
1138                        ck_object_handle_t key));
1139 _CK_DECLARE_FUNCTION (C_Encrypt,
1140                       (ck_session_handle_t session,
1141                        unsigned char *data, unsigned long data_len,
1142                        unsigned char *encrypted_data,
1143                        unsigned long *encrypted_data_len));
1144 _CK_DECLARE_FUNCTION (C_EncryptUpdate,
1145                       (ck_session_handle_t session,
1146                        unsigned char *part, unsigned long part_len,
1147                        unsigned char *encrypted_part,
1148                        unsigned long *encrypted_part_len));
1149 _CK_DECLARE_FUNCTION (C_EncryptFinal,
1150                       (ck_session_handle_t session,
1151                        unsigned char *last_encrypted_part,
1152                        unsigned long *last_encrypted_part_len));
1153
1154 _CK_DECLARE_FUNCTION (C_DecryptInit,
1155                       (ck_session_handle_t session,
1156                        struct ck_mechanism *mechanism,
1157                        ck_object_handle_t key));
1158 _CK_DECLARE_FUNCTION (C_Decrypt,
1159                       (ck_session_handle_t session,
1160                        unsigned char *encrypted_data,
1161                        unsigned long encrypted_data_len,
1162                        unsigned char *data, unsigned long *data_len));
1163 _CK_DECLARE_FUNCTION (C_DecryptUpdate,
1164                       (ck_session_handle_t session,
1165                        unsigned char *encrypted_part,
1166                        unsigned long encrypted_part_len,
1167                        unsigned char *part, unsigned long *part_len));
1168 _CK_DECLARE_FUNCTION (C_DecryptFinal,
1169                       (ck_session_handle_t session,
1170                        unsigned char *last_part,
1171                        unsigned long *last_part_len));
1172
1173 _CK_DECLARE_FUNCTION (C_DigestInit,
1174                       (ck_session_handle_t session,
1175                        struct ck_mechanism *mechanism));
1176 _CK_DECLARE_FUNCTION (C_Digest,
1177                       (ck_session_handle_t session,
1178                        unsigned char *data, unsigned long data_len,
1179                        unsigned char *digest,
1180                        unsigned long *digest_len));
1181 _CK_DECLARE_FUNCTION (C_DigestUpdate,
1182                       (ck_session_handle_t session,
1183                        unsigned char *part, unsigned long part_len));
1184 _CK_DECLARE_FUNCTION (C_DigestKey,
1185                       (ck_session_handle_t session, ck_object_handle_t key));
1186 _CK_DECLARE_FUNCTION (C_DigestFinal,
1187                       (ck_session_handle_t session,
1188                        unsigned char *digest,
1189                        unsigned long *digest_len));
1190
1191 _CK_DECLARE_FUNCTION (C_SignInit,
1192                       (ck_session_handle_t session,
1193                        struct ck_mechanism *mechanism,
1194                        ck_object_handle_t key));
1195 _CK_DECLARE_FUNCTION (C_Sign,
1196                       (ck_session_handle_t session,
1197                        unsigned char *data, unsigned long data_len,
1198                        unsigned char *signature,
1199                        unsigned long *signature_len));
1200 _CK_DECLARE_FUNCTION (C_SignUpdate,
1201                       (ck_session_handle_t session,
1202                        unsigned char *part, unsigned long part_len));
1203 _CK_DECLARE_FUNCTION (C_SignFinal,
1204                       (ck_session_handle_t session,
1205                        unsigned char *signature,
1206                        unsigned long *signature_len));
1207 _CK_DECLARE_FUNCTION (C_SignRecoverInit,
1208                       (ck_session_handle_t session,
1209                        struct ck_mechanism *mechanism,
1210                        ck_object_handle_t key));
1211 _CK_DECLARE_FUNCTION (C_SignRecover,
1212                       (ck_session_handle_t session,
1213                        unsigned char *data, unsigned long data_len,
1214                        unsigned char *signature,
1215                        unsigned long *signature_len));
1216
1217 _CK_DECLARE_FUNCTION (C_VerifyInit,
1218                       (ck_session_handle_t session,
1219                        struct ck_mechanism *mechanism,
1220                        ck_object_handle_t key));
1221 _CK_DECLARE_FUNCTION (C_Verify,
1222                       (ck_session_handle_t session,
1223                        unsigned char *data, unsigned long data_len,
1224                        unsigned char *signature,
1225                        unsigned long signature_len));
1226 _CK_DECLARE_FUNCTION (C_VerifyUpdate,
1227                       (ck_session_handle_t session,
1228                        unsigned char *part, unsigned long part_len));
1229 _CK_DECLARE_FUNCTION (C_VerifyFinal,
1230                       (ck_session_handle_t session,
1231                        unsigned char *signature,
1232                        unsigned long signature_len));
1233 _CK_DECLARE_FUNCTION (C_VerifyRecoverInit,
1234                       (ck_session_handle_t session,
1235                        struct ck_mechanism *mechanism,
1236                        ck_object_handle_t key));
1237 _CK_DECLARE_FUNCTION (C_VerifyRecover,
1238                       (ck_session_handle_t session,
1239                        unsigned char *signature,
1240                        unsigned long signature_len,
1241                        unsigned char *data,
1242                        unsigned long *data_len));
1243
1244 _CK_DECLARE_FUNCTION (C_DigestEncryptUpdate,
1245                       (ck_session_handle_t session,
1246                        unsigned char *part, unsigned long part_len,
1247                        unsigned char *encrypted_part,
1248                        unsigned long *encrypted_part_len));
1249 _CK_DECLARE_FUNCTION (C_DecryptDigestUpdate,
1250                       (ck_session_handle_t session,
1251                        unsigned char *encrypted_part,
1252                        unsigned long encrypted_part_len,
1253                        unsigned char *part,
1254                        unsigned long *part_len));
1255 _CK_DECLARE_FUNCTION (C_SignEncryptUpdate,
1256                       (ck_session_handle_t session,
1257                        unsigned char *part, unsigned long part_len,
1258                        unsigned char *encrypted_part,
1259                        unsigned long *encrypted_part_len));
1260 _CK_DECLARE_FUNCTION (C_DecryptVerifyUpdate,
1261                       (ck_session_handle_t session,
1262                        unsigned char *encrypted_part,
1263                        unsigned long encrypted_part_len,
1264                        unsigned char *part,
1265                        unsigned long *part_len));
1266
1267 _CK_DECLARE_FUNCTION (C_GenerateKey,
1268                       (ck_session_handle_t session,
1269                        struct ck_mechanism *mechanism,
1270                        struct ck_attribute *templ,
1271                        unsigned long count,
1272                        ck_object_handle_t *key));
1273 _CK_DECLARE_FUNCTION (C_GenerateKeyPair,
1274                       (ck_session_handle_t session,
1275                        struct ck_mechanism *mechanism,
1276                        struct ck_attribute *public_key_template,
1277                        unsigned long public_key_attribute_count,
1278                        struct ck_attribute *private_key_template,
1279                        unsigned long private_key_attribute_count,
1280                        ck_object_handle_t *public_key,
1281                        ck_object_handle_t *private_key));
1282 _CK_DECLARE_FUNCTION (C_WrapKey,
1283                       (ck_session_handle_t session,
1284                        struct ck_mechanism *mechanism,
1285                        ck_object_handle_t wrapping_key,
1286                        ck_object_handle_t key,
1287                        unsigned char *wrapped_key,
1288                        unsigned long *wrapped_key_len));
1289 _CK_DECLARE_FUNCTION (C_UnwrapKey,
1290                       (ck_session_handle_t session,
1291                        struct ck_mechanism *mechanism,
1292                        ck_object_handle_t unwrapping_key,
1293                        unsigned char *wrapped_key,
1294                        unsigned long wrapped_key_len,
1295                        struct ck_attribute *templ,
1296                        unsigned long attribute_count,
1297                        ck_object_handle_t *key));
1298 _CK_DECLARE_FUNCTION (C_DeriveKey,
1299                       (ck_session_handle_t session,
1300                        struct ck_mechanism *mechanism,
1301                        ck_object_handle_t base_key,
1302                        struct ck_attribute *templ,
1303                        unsigned long attribute_count,
1304                        ck_object_handle_t *key));
1305
1306 _CK_DECLARE_FUNCTION (C_SeedRandom,
1307                       (ck_session_handle_t session, unsigned char *seed,
1308                        unsigned long seed_len));
1309 _CK_DECLARE_FUNCTION (C_GenerateRandom,
1310                       (ck_session_handle_t session,
1311                        unsigned char *random_data,
1312                        unsigned long random_len));
1313
1314 _CK_DECLARE_FUNCTION (C_GetFunctionStatus, (ck_session_handle_t session));
1315 _CK_DECLARE_FUNCTION (C_CancelFunction, (ck_session_handle_t session));
1316
1317
1318 struct ck_function_list
1319 {
1320   struct ck_version version;
1321   CK_C_Initialize C_Initialize;
1322   CK_C_Finalize C_Finalize;
1323   CK_C_GetInfo C_GetInfo;
1324   CK_C_GetFunctionList C_GetFunctionList;
1325   CK_C_GetSlotList C_GetSlotList;
1326   CK_C_GetSlotInfo C_GetSlotInfo;
1327   CK_C_GetTokenInfo C_GetTokenInfo;
1328   CK_C_GetMechanismList C_GetMechanismList;
1329   CK_C_GetMechanismInfo C_GetMechanismInfo;
1330   CK_C_InitToken C_InitToken;
1331   CK_C_InitPIN C_InitPIN;
1332   CK_C_SetPIN C_SetPIN;
1333   CK_C_OpenSession C_OpenSession;
1334   CK_C_CloseSession C_CloseSession;
1335   CK_C_CloseAllSessions C_CloseAllSessions;
1336   CK_C_GetSessionInfo C_GetSessionInfo;
1337   CK_C_GetOperationState C_GetOperationState;
1338   CK_C_SetOperationState C_SetOperationState;
1339   CK_C_Login C_Login;
1340   CK_C_Logout C_Logout;
1341   CK_C_CreateObject C_CreateObject;
1342   CK_C_CopyObject C_CopyObject;
1343   CK_C_DestroyObject C_DestroyObject;
1344   CK_C_GetObjectSize C_GetObjectSize;
1345   CK_C_GetAttributeValue C_GetAttributeValue;
1346   CK_C_SetAttributeValue C_SetAttributeValue;
1347   CK_C_FindObjectsInit C_FindObjectsInit;
1348   CK_C_FindObjects C_FindObjects;
1349   CK_C_FindObjectsFinal C_FindObjectsFinal;
1350   CK_C_EncryptInit C_EncryptInit;
1351   CK_C_Encrypt C_Encrypt;
1352   CK_C_EncryptUpdate C_EncryptUpdate;
1353   CK_C_EncryptFinal C_EncryptFinal;
1354   CK_C_DecryptInit C_DecryptInit;
1355   CK_C_Decrypt C_Decrypt;
1356   CK_C_DecryptUpdate C_DecryptUpdate;
1357   CK_C_DecryptFinal C_DecryptFinal;
1358   CK_C_DigestInit C_DigestInit;
1359   CK_C_Digest C_Digest;
1360   CK_C_DigestUpdate C_DigestUpdate;
1361   CK_C_DigestKey C_DigestKey;
1362   CK_C_DigestFinal C_DigestFinal;
1363   CK_C_SignInit C_SignInit;
1364   CK_C_Sign C_Sign;
1365   CK_C_SignUpdate C_SignUpdate;
1366   CK_C_SignFinal C_SignFinal;
1367   CK_C_SignRecoverInit C_SignRecoverInit;
1368   CK_C_SignRecover C_SignRecover;
1369   CK_C_VerifyInit C_VerifyInit;
1370   CK_C_Verify C_Verify;
1371   CK_C_VerifyUpdate C_VerifyUpdate;
1372   CK_C_VerifyFinal C_VerifyFinal;
1373   CK_C_VerifyRecoverInit C_VerifyRecoverInit;
1374   CK_C_VerifyRecover C_VerifyRecover;
1375   CK_C_DigestEncryptUpdate C_DigestEncryptUpdate;
1376   CK_C_DecryptDigestUpdate C_DecryptDigestUpdate;
1377   CK_C_SignEncryptUpdate C_SignEncryptUpdate;
1378   CK_C_DecryptVerifyUpdate C_DecryptVerifyUpdate;
1379   CK_C_GenerateKey C_GenerateKey;
1380   CK_C_GenerateKeyPair C_GenerateKeyPair;
1381   CK_C_WrapKey C_WrapKey;
1382   CK_C_UnwrapKey C_UnwrapKey;
1383   CK_C_DeriveKey C_DeriveKey;
1384   CK_C_SeedRandom C_SeedRandom;
1385   CK_C_GenerateRandom C_GenerateRandom;
1386   CK_C_GetFunctionStatus C_GetFunctionStatus;
1387   CK_C_CancelFunction C_CancelFunction;
1388   CK_C_WaitForSlotEvent C_WaitForSlotEvent;
1389 };
1390
1391
1392 typedef ck_rv_t (*ck_createmutex_t) (void **mutex);
1393 typedef ck_rv_t (*ck_destroymutex_t) (void *mutex);
1394 typedef ck_rv_t (*ck_lockmutex_t) (void *mutex);
1395 typedef ck_rv_t (*ck_unlockmutex_t) (void *mutex);
1396
1397
1398 struct ck_c_initialize_args
1399 {
1400   ck_createmutex_t create_mutex;
1401   ck_destroymutex_t destroy_mutex;
1402   ck_lockmutex_t lock_mutex;
1403   ck_unlockmutex_t unlock_mutex;
1404   ck_flags_t flags;
1405   void *reserved;
1406 };
1407
1408
1409 #define CKF_LIBRARY_CANT_CREATE_OS_THREADS      (1 << 0)
1410 #define CKF_OS_LOCKING_OK                       (1 << 1)
1411
1412 #define CKR_OK                                  (0)
1413 #define CKR_CANCEL                              (1)
1414 #define CKR_HOST_MEMORY                         (2)
1415 #define CKR_SLOT_ID_INVALID                     (3)
1416 #define CKR_GENERAL_ERROR                       (5)
1417 #define CKR_FUNCTION_FAILED                     (6)
1418 #define CKR_ARGUMENTS_BAD                       (7)
1419 #define CKR_NO_EVENT                            (8)
1420 #define CKR_NEED_TO_CREATE_THREADS              (9)
1421 #define CKR_CANT_LOCK                           (0xa)
1422 #define CKR_ATTRIBUTE_READ_ONLY                 (0x10)
1423 #define CKR_ATTRIBUTE_SENSITIVE                 (0x11)
1424 #define CKR_ATTRIBUTE_TYPE_INVALID              (0x12)
1425 #define CKR_ATTRIBUTE_VALUE_INVALID             (0x13)
1426 #define CKR_COPY_PROHIBITED                     (0x1A)
1427 #define CKR_DATA_INVALID                        (0x20)
1428 #define CKR_DATA_LEN_RANGE                      (0x21)
1429 #define CKR_DEVICE_ERROR                        (0x30)
1430 #define CKR_DEVICE_MEMORY                       (0x31)
1431 #define CKR_DEVICE_REMOVED                      (0x32)
1432 #define CKR_ENCRYPTED_DATA_INVALID              (0x40)
1433 #define CKR_ENCRYPTED_DATA_LEN_RANGE            (0x41)
1434 #define CKR_FUNCTION_CANCELED                   (0x50)
1435 #define CKR_FUNCTION_NOT_PARALLEL               (0x51)
1436 #define CKR_FUNCTION_NOT_SUPPORTED              (0x54)
1437 #define CKR_KEY_HANDLE_INVALID                  (0x60)
1438 #define CKR_KEY_SIZE_RANGE                      (0x62)
1439 #define CKR_KEY_TYPE_INCONSISTENT               (0x63)
1440 #define CKR_KEY_NOT_NEEDED                      (0x64)
1441 #define CKR_KEY_CHANGED                         (0x65)
1442 #define CKR_KEY_NEEDED                          (0x66)
1443 #define CKR_KEY_INDIGESTIBLE                    (0x67)
1444 #define CKR_KEY_FUNCTION_NOT_PERMITTED          (0x68)
1445 #define CKR_KEY_NOT_WRAPPABLE                   (0x69)
1446 #define CKR_KEY_UNEXTRACTABLE                   (0x6a)
1447 #define CKR_MECHANISM_INVALID                   (0x70)
1448 #define CKR_MECHANISM_PARAM_INVALID             (0x71)
1449 #define CKR_OBJECT_HANDLE_INVALID               (0x82)
1450 #define CKR_OPERATION_ACTIVE                    (0x90)
1451 #define CKR_OPERATION_NOT_INITIALIZED           (0x91)
1452 #define CKR_PIN_INCORRECT                       (0xa0)
1453 #define CKR_PIN_INVALID                         (0xa1)
1454 #define CKR_PIN_LEN_RANGE                       (0xa2)
1455 #define CKR_PIN_EXPIRED                         (0xa3)
1456 #define CKR_PIN_LOCKED                          (0xa4)
1457 #define CKR_SESSION_CLOSED                      (0xb0)
1458 #define CKR_SESSION_COUNT                       (0xb1)
1459 #define CKR_SESSION_HANDLE_INVALID              (0xb3)
1460 #define CKR_SESSION_PARALLEL_NOT_SUPPORTED      (0xb4)
1461 #define CKR_SESSION_READ_ONLY                   (0xb5)
1462 #define CKR_SESSION_EXISTS                      (0xb6)
1463 #define CKR_SESSION_READ_ONLY_EXISTS            (0xb7)
1464 #define CKR_SESSION_READ_WRITE_SO_EXISTS        (0xb8)
1465 #define CKR_SIGNATURE_INVALID                   (0xc0)
1466 #define CKR_SIGNATURE_LEN_RANGE                 (0xc1)
1467 #define CKR_TEMPLATE_INCOMPLETE                 (0xd0)
1468 #define CKR_TEMPLATE_INCONSISTENT               (0xd1)
1469 #define CKR_TOKEN_NOT_PRESENT                   (0xe0)
1470 #define CKR_TOKEN_NOT_RECOGNIZED                (0xe1)
1471 #define CKR_TOKEN_WRITE_PROTECTED               (0xe2)
1472 #define CKR_UNWRAPPING_KEY_HANDLE_INVALID       (0xf0)
1473 #define CKR_UNWRAPPING_KEY_SIZE_RANGE           (0xf1)
1474 #define CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT    (0xf2)
1475 #define CKR_USER_ALREADY_LOGGED_IN              (0x100)
1476 #define CKR_USER_NOT_LOGGED_IN                  (0x101)
1477 #define CKR_USER_PIN_NOT_INITIALIZED            (0x102)
1478 #define CKR_USER_TYPE_INVALID                   (0x103)
1479 #define CKR_USER_ANOTHER_ALREADY_LOGGED_IN      (0x104)
1480 #define CKR_USER_TOO_MANY_TYPES                 (0x105)
1481 #define CKR_WRAPPED_KEY_INVALID                 (0x110)
1482 #define CKR_WRAPPED_KEY_LEN_RANGE               (0x112)
1483 #define CKR_WRAPPING_KEY_HANDLE_INVALID         (0x113)
1484 #define CKR_WRAPPING_KEY_SIZE_RANGE             (0x114)
1485 #define CKR_WRAPPING_KEY_TYPE_INCONSISTENT      (0x115)
1486 #define CKR_RANDOM_SEED_NOT_SUPPORTED           (0x120)
1487 #define CKR_RANDOM_NO_RNG                       (0x121)
1488 #define CKR_DOMAIN_PARAMS_INVALID               (0x130)
1489 #define CKR_BUFFER_TOO_SMALL                    (0x150)
1490 #define CKR_SAVED_STATE_INVALID                 (0x160)
1491 #define CKR_INFORMATION_SENSITIVE               (0x170)
1492 #define CKR_STATE_UNSAVEABLE                    (0x180)
1493 #define CKR_CRYPTOKI_NOT_INITIALIZED            (0x190)
1494 #define CKR_CRYPTOKI_ALREADY_INITIALIZED        (0x191)
1495 #define CKR_MUTEX_BAD                           (0x1a0)
1496 #define CKR_MUTEX_NOT_LOCKED                    (0x1a1)
1497 #define CKR_NEW_PIN_MODE                        (0x1b0)
1498 #define CKR_NEXT_OTP                            (0x1b1)
1499 #define CKR_EXCEEDED_MAX_ITERATIONS             (0x1b5)
1500 #define CKR_FIPS_SELF_TEST_FAILED               (0x1b6)
1501 #define CKR_LIBRARY_LOAD_FAILED                 (0x1b7)
1502 #define CKR_PIN_TOO_WEAK                        (0x1b8)
1503 #define CKR_PUBLIC_KEY_INVALID                  (0x1b9)
1504 #define CKR_FUNCTION_REJECTED                   (0x200)
1505 #define CKR_VENDOR_DEFINED                      ((unsigned long) (1ul << 31))
1506
1507
1508 \f
1509 /* Compatibility layer.  */
1510
1511 #ifdef CRYPTOKI_COMPAT
1512
1513 #undef CK_DEFINE_FUNCTION
1514 #define CK_DEFINE_FUNCTION(retval, name) retval CK_SPEC name
1515
1516 /* For NULL.  */
1517 #include <stddef.h>
1518
1519 typedef unsigned char CK_BYTE;
1520 typedef unsigned char CK_CHAR;
1521 typedef unsigned char CK_UTF8CHAR;
1522 typedef unsigned char CK_BBOOL;
1523 typedef unsigned long int CK_ULONG;
1524 typedef long int CK_LONG;
1525 typedef CK_BYTE *CK_BYTE_PTR;
1526 typedef CK_CHAR *CK_CHAR_PTR;
1527 typedef CK_UTF8CHAR *CK_UTF8CHAR_PTR;
1528 typedef CK_ULONG *CK_ULONG_PTR;
1529 typedef void *CK_VOID_PTR;
1530 typedef void **CK_VOID_PTR_PTR;
1531 #define CK_FALSE 0
1532 #define CK_TRUE 1
1533 #ifndef CK_DISABLE_TRUE_FALSE
1534 #ifndef FALSE
1535 #define FALSE 0
1536 #endif
1537 #ifndef TRUE
1538 #define TRUE 1
1539 #endif
1540 #endif
1541
1542 typedef struct ck_version CK_VERSION;
1543 typedef struct ck_version *CK_VERSION_PTR;
1544
1545 typedef struct ck_info CK_INFO;
1546 typedef struct ck_info *CK_INFO_PTR;
1547
1548 typedef ck_slot_id_t *CK_SLOT_ID_PTR;
1549
1550 typedef struct ck_slot_info CK_SLOT_INFO;
1551 typedef struct ck_slot_info *CK_SLOT_INFO_PTR;
1552
1553 typedef struct ck_token_info CK_TOKEN_INFO;
1554 typedef struct ck_token_info *CK_TOKEN_INFO_PTR;
1555
1556 typedef ck_session_handle_t *CK_SESSION_HANDLE_PTR;
1557
1558 typedef struct ck_session_info CK_SESSION_INFO;
1559 typedef struct ck_session_info *CK_SESSION_INFO_PTR;
1560
1561 typedef ck_object_handle_t *CK_OBJECT_HANDLE_PTR;
1562
1563 typedef ck_object_class_t *CK_OBJECT_CLASS_PTR;
1564
1565 typedef struct ck_attribute CK_ATTRIBUTE;
1566 typedef struct ck_attribute *CK_ATTRIBUTE_PTR;
1567
1568 typedef struct ck_date CK_DATE;
1569 typedef struct ck_date *CK_DATE_PTR;
1570
1571 typedef ck_mechanism_type_t *CK_MECHANISM_TYPE_PTR;
1572
1573 typedef struct ck_mechanism CK_MECHANISM;
1574 typedef struct ck_mechanism *CK_MECHANISM_PTR;
1575
1576 typedef struct ck_mechanism_info CK_MECHANISM_INFO;
1577 typedef struct ck_mechanism_info *CK_MECHANISM_INFO_PTR;
1578
1579 typedef struct ck_rsa_pkcs_oaep_params CK_RSA_PKCS_OAEP_PARAMS;
1580 typedef struct ck_rsa_pkcs_oaep_params *CK_RSA_PKCS_OAEP_PARAMS_PTR;
1581
1582 typedef struct ck_rsa_pkcs_pss_params CK_RSA_PKCS_PSS_PARAMS;
1583 typedef struct ck_rsa_pkcs_pss_params *CK_RSA_PKCS_PSS_PARAMS_PTR;
1584
1585 typedef struct ck_ecdh1_derive_params CK_ECDH1_DERIVE_PARAMS;
1586 typedef struct ck_ecdh1_derive_params *CK_ECDH1_DERIVE_PARAMS_PTR;
1587
1588 typedef struct ck_des_cbc_encrypt_data_params CK_DES_CBC_ENCRYPT_DATA_PARAMS;
1589 typedef struct ck_des_cbc_encrypt_data_params *CK_DES_CBC_ENCRYPT_DATA_PARAMS_PTR;
1590
1591 typedef struct ck_aes_cbc_encrypt_data_params CK_AES_CBC_ENCRYPT_DATA_PARAMS;
1592 typedef struct ck_aes_cbc_encrypt_data_params *CK_AES_CBC_ENCRYPT_DATA_PARAMS_PTR;
1593
1594 typedef struct ck_key_derivation_string_data CK_KEY_DERIVATION_STRING_DATA;
1595 typedef struct ck_key_derivation_string_data *CK_KEY_DERIVATION_STRING_DATA_PTR;
1596
1597 typedef struct ck_function_list CK_FUNCTION_LIST;
1598 typedef struct ck_function_list *CK_FUNCTION_LIST_PTR;
1599 typedef struct ck_function_list **CK_FUNCTION_LIST_PTR_PTR;
1600
1601 typedef struct ck_c_initialize_args CK_C_INITIALIZE_ARGS;
1602 typedef struct ck_c_initialize_args *CK_C_INITIALIZE_ARGS_PTR;
1603
1604 #define NULL_PTR NULL
1605
1606 /* Delete the helper macros defined at the top of the file.  */
1607 #undef ck_flags_t
1608 #undef ck_version
1609
1610 #undef ck_info
1611 #undef cryptoki_version
1612 #undef manufacturer_id
1613 #undef library_description
1614 #undef library_version
1615
1616 #undef ck_notification_t
1617 #undef ck_slot_id_t
1618
1619 #undef ck_slot_info
1620 #undef slot_description
1621 #undef hardware_version
1622 #undef firmware_version
1623
1624 #undef ck_token_info
1625 #undef serial_number
1626 #undef max_session_count
1627 #undef session_count
1628 #undef max_rw_session_count
1629 #undef rw_session_count
1630 #undef max_pin_len
1631 #undef min_pin_len
1632 #undef total_public_memory
1633 #undef free_public_memory
1634 #undef total_private_memory
1635 #undef free_private_memory
1636 #undef utc_time
1637
1638 #undef ck_session_handle_t
1639 #undef ck_user_type_t
1640 #undef ck_state_t
1641
1642 #undef ck_session_info
1643 #undef slot_id
1644 #undef device_error
1645
1646 #undef ck_object_handle_t
1647 #undef ck_object_class_t
1648 #undef ck_hw_feature_type_t
1649 #undef ck_key_type_t
1650 #undef ck_certificate_type_t
1651 #undef ck_attribute_type_t
1652
1653 #undef ck_attribute
1654 #undef value
1655 #undef value_len
1656
1657 #undef ck_date
1658
1659 #undef ck_mechanism_type_t
1660
1661 #undef ck_mechanism
1662 #undef parameter
1663 #undef parameter_len
1664
1665 #undef ck_mechanism_info
1666 #undef min_key_size
1667 #undef max_key_size
1668
1669 #undef ck_rsa_pkcs_oaep_params
1670 #undef hash_alg
1671 #undef source_data
1672 #undef source_data_len
1673 #undef slen
1674
1675 #undef ck_ec_kdf_type_t
1676 #undef shared_data_len
1677 #undef shared_data
1678 #undef public_data_len
1679 #undef public_data
1680 #undef private_data_len
1681 #undef private_data
1682 #undef public_data_len2
1683 #undef public_data2
1684 #undef public_key
1685
1686 #undef ck_x9_42_dh_kdf_type_t
1687 #undef other_info_len
1688 #undef other_info
1689
1690 #undef data
1691 #undef len
1692
1693 #undef ck_rv_t
1694 #undef ck_notify_t
1695
1696 #undef ck_function_list
1697
1698 #undef ck_createmutex_t
1699 #undef ck_destroymutex_t
1700 #undef ck_lockmutex_t
1701 #undef ck_unlockmutex_t
1702
1703 #undef ck_c_initialize_args
1704 #undef create_mutex
1705 #undef destroy_mutex
1706 #undef lock_mutex
1707 #undef unlock_mutex
1708 #undef reserved
1709
1710 #endif  /* CRYPTOKI_COMPAT */
1711
1712 \f
1713 /* System dependencies.  */
1714 #if defined(_WIN32) || defined(CRYPTOKI_FORCE_WIN32)
1715 #pragma pack(pop, cryptoki)
1716 #endif
1717
1718 #if defined(__cplusplus)
1719 }
1720 #endif
1721
1722 #endif  /* PKCS11_H */