1 /* pkcs11.h
2    Copyright 2006, 2007 g10 Code GmbH
3    Copyright 2006 Andreas Jellinghaus
4    Copyright 2017 Red Hat, Inc.
5 
6    This file is free software; as a special exception the author gives
7    unlimited permission to copy and/or distribute it, with or without
8    modifications, as long as this notice is preserved.
9 
10    This file is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY, to the extent permitted by law; without even
12    the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13    PURPOSE.  */
14 
15 /* Please submit any changes back to the p11-kit project at
16    https://github.com/p11-glue/p11-kit/, so that
17    they can be picked up by other projects from there as well.  */
18 
19 /* This file is a modified implementation of the PKCS #11 standard by
20    OASIS group.  It is mostly a drop-in replacement, with the
21    following change:
22 
23    This header file does not require any macro definitions by the user
24    (like CK_DEFINE_FUNCTION etc).  In fact, it defines those macros
25    for you (if useful, some are missing, let me know if you need
26    more).
27 
28    There is an additional API available that does comply better to the
29    GNU coding standard.  It can be switched on by defining
30    CRYPTOKI_GNU before including this header file.  For this, the
31    following changes are made to the specification:
32 
33    All structure types are changed to a "struct ck_foo" where CK_FOO
34    is the type name in PKCS #11.
35 
36    All non-structure types are changed to ck_foo_t where CK_FOO is the
37    lowercase version of the type name in PKCS #11.  The basic types
38    (CK_ULONG et al.) are removed without substitute.
39 
40    All members of structures are modified in the following way: Type
41    indication prefixes are removed, and underscore characters are
42    inserted before words.  Then the result is lowercased.
43 
44    Note that function names are still in the original case, as they
45    need for ABI compatibility.
46 
47    CK_FALSE, CK_TRUE and NULL_PTR are removed without substitute.  Use
48    <stdbool.h>.
49 
50    If CRYPTOKI_COMPAT is defined before including this header file,
51    then none of the API changes above take place, and the API is the
52    one defined by the PKCS #11 standard.  */
53 
54 #ifndef PKCS11_H
55 #define PKCS11_H 1
56 
57 #if defined(__cplusplus)
58 extern "C" {
59 #endif
60 
61 
62 /* The version of cryptoki we implement.  The revision is changed with
63    each modification of this file.  */
64 #define CRYPTOKI_VERSION_MAJOR		2
65 #define CRYPTOKI_VERSION_MINOR		40
66 #define P11_KIT_CRYPTOKI_VERSION_REVISION	0
67 
68 
69 /* Compatibility interface is default, unless CRYPTOKI_GNU is
70    given.  */
71 #ifndef CRYPTOKI_GNU
72 #ifndef CRYPTOKI_COMPAT
73 #define CRYPTOKI_COMPAT 1
74 #endif
75 #endif
76 
77 /* System dependencies.  */
78 
79 #if defined(_WIN32) || defined(CRYPTOKI_FORCE_WIN32)
80 
81 /* There is a matching pop below.  */
82 #pragma pack(push, cryptoki, 1)
83 
84 #ifdef CRYPTOKI_EXPORTS
85 #define CK_SPEC __declspec(dllexport)
86 #else
87 #define CK_SPEC __declspec(dllimport)
88 #endif
89 
90 #else
91 
92 #define CK_SPEC
93 
94 #endif
95 
96 
97 #ifdef CRYPTOKI_COMPAT
98   /* If we are in compatibility mode, switch all exposed names to the
99      PKCS #11 variant.  There are corresponding #undefs below.  */
100 
101 #define ck_flags_t CK_FLAGS
102 #define ck_version _CK_VERSION
103 
104 #define ck_info _CK_INFO
105 #define cryptoki_version cryptokiVersion
106 #define manufacturer_id manufacturerID
107 #define library_description libraryDescription
108 #define library_version libraryVersion
109 
110 #define ck_notification_t CK_NOTIFICATION
111 #define ck_slot_id_t CK_SLOT_ID
112 
113 #define ck_slot_info _CK_SLOT_INFO
114 #define slot_description slotDescription
115 #define hardware_version hardwareVersion
116 #define firmware_version firmwareVersion
117 
118 #define ck_token_info _CK_TOKEN_INFO
119 #define serial_number serialNumber
120 #define max_session_count ulMaxSessionCount
121 #define session_count ulSessionCount
122 #define max_rw_session_count ulMaxRwSessionCount
123 #define rw_session_count ulRwSessionCount
124 #define max_pin_len ulMaxPinLen
125 #define min_pin_len ulMinPinLen
126 #define total_public_memory ulTotalPublicMemory
127 #define free_public_memory ulFreePublicMemory
128 #define total_private_memory ulTotalPrivateMemory
129 #define free_private_memory ulFreePrivateMemory
130 #define utc_time utcTime
131 
132 #define ck_session_handle_t CK_SESSION_HANDLE
133 #define ck_user_type_t CK_USER_TYPE
134 #define ck_state_t CK_STATE
135 
136 #define ck_session_info _CK_SESSION_INFO
137 #define slot_id slotID
138 #define device_error ulDeviceError
139 
140 #define ck_object_handle_t CK_OBJECT_HANDLE
141 #define ck_object_class_t CK_OBJECT_CLASS
142 #define ck_hw_feature_type_t CK_HW_FEATURE_TYPE
143 #define ck_key_type_t CK_KEY_TYPE
144 #define ck_certificate_type_t CK_CERTIFICATE_TYPE
145 #define ck_attribute_type_t CK_ATTRIBUTE_TYPE
146 
147 #define ck_attribute _CK_ATTRIBUTE
148 #define value pValue
149 #define value_len ulValueLen
150 
151 #define count ulCount
152 
153 #define ck_date _CK_DATE
154 
155 #define ck_mechanism_type_t CK_MECHANISM_TYPE
156 
157 #define ck_mechanism _CK_MECHANISM
158 #define parameter pParameter
159 #define parameter_len ulParameterLen
160 
161 #define params pParams
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_param_type CK_PARAM_TYPE
168 #define ck_otp_param CK_OTP_PARAM
169 #define ck_otp_params CK_OTP_PARAMS
170 #define ck_otp_signature_info CK_OTP_SIGNATURE_INFO
171 
172 #define ck_rv_t CK_RV
173 #define ck_notify_t CK_NOTIFY
174 
175 #define ck_function_list _CK_FUNCTION_LIST
176 
177 #define ck_createmutex_t CK_CREATEMUTEX
178 #define ck_destroymutex_t CK_DESTROYMUTEX
179 #define ck_lockmutex_t CK_LOCKMUTEX
180 #define ck_unlockmutex_t CK_UNLOCKMUTEX
181 
182 #define ck_c_initialize_args _CK_C_INITIALIZE_ARGS
183 #define create_mutex CreateMutex
184 #define destroy_mutex DestroyMutex
185 #define lock_mutex LockMutex
186 #define unlock_mutex UnlockMutex
187 #define reserved pReserved
188 
189 #define ck_rsa_pkcs_mgf_type_t CK_RSA_PKCS_MGF_TYPE
190 #define ck_rsa_pkcs_oaep_source_type_t CK_RSA_PKCS_OAEP_SOURCE_TYPE
191 #define hash_alg hashAlg
192 #define s_len sLen
193 #define source_data pSourceData
194 #define source_data_len ulSourceDataLen
195 
196 #define counter_bits ulCounterBits
197 #define iv_ptr pIv
198 #define iv_len ulIvLen
199 #define iv_bits ulIvBits
200 #define aad_ptr pAAD
201 #define aad_len ulAADLen
202 #define tag_bits ulTagBits
203 #define shared_data_len ulSharedDataLen
204 #define shared_data pSharedData
205 #define public_data_len ulPublicDataLen
206 #define public_data pPublicData
207 #define string_data pData
208 #define string_data_len ulLen
209 #define data_params pData
210 #endif	/* CRYPTOKI_COMPAT */
211 
212 
213 
214 typedef unsigned long ck_flags_t;
215 
216 struct ck_version
217 {
218   unsigned char major;
219   unsigned char minor;
220 };
221 
222 
223 struct ck_info
224 {
225   struct ck_version cryptoki_version;
226   unsigned char manufacturer_id[32];
227   ck_flags_t flags;
228   unsigned char library_description[32];
229   struct ck_version library_version;
230 };
231 
232 
233 typedef unsigned long ck_notification_t;
234 
235 #define CKN_SURRENDER	(0UL)
236 
237 
238 typedef unsigned long ck_slot_id_t;
239 
240 
241 struct ck_slot_info
242 {
243   unsigned char slot_description[64];
244   unsigned char manufacturer_id[32];
245   ck_flags_t flags;
246   struct ck_version hardware_version;
247   struct ck_version firmware_version;
248 };
249 
250 
251 #define CKF_TOKEN_PRESENT	(1UL << 0)
252 #define CKF_REMOVABLE_DEVICE	(1UL << 1)
253 #define CKF_HW_SLOT		(1UL << 2)
254 #define CKF_ARRAY_ATTRIBUTE	(1UL << 30)
255 
256 
257 struct ck_token_info
258 {
259   unsigned char label[32];
260   unsigned char manufacturer_id[32];
261   unsigned char model[16];
262   unsigned char serial_number[16];
263   ck_flags_t flags;
264   unsigned long max_session_count;
265   unsigned long session_count;
266   unsigned long max_rw_session_count;
267   unsigned long rw_session_count;
268   unsigned long max_pin_len;
269   unsigned long min_pin_len;
270   unsigned long total_public_memory;
271   unsigned long free_public_memory;
272   unsigned long total_private_memory;
273   unsigned long free_private_memory;
274   struct ck_version hardware_version;
275   struct ck_version firmware_version;
276   unsigned char utc_time[16];
277 };
278 
279 
280 #define CKF_RNG					(1UL << 0)
281 #define CKF_WRITE_PROTECTED			(1UL << 1)
282 #define CKF_LOGIN_REQUIRED			(1UL << 2)
283 #define CKF_USER_PIN_INITIALIZED		(1UL << 3)
284 #define CKF_RESTORE_KEY_NOT_NEEDED		(1UL << 5)
285 #define CKF_CLOCK_ON_TOKEN			(1UL << 6)
286 #define CKF_PROTECTED_AUTHENTICATION_PATH	(1UL << 8)
287 #define CKF_DUAL_CRYPTO_OPERATIONS		(1UL << 9)
288 #define CKF_TOKEN_INITIALIZED			(1UL << 10)
289 #define CKF_SECONDARY_AUTHENTICATION		(1UL << 11)
290 #define CKF_USER_PIN_COUNT_LOW			(1UL << 16)
291 #define CKF_USER_PIN_FINAL_TRY			(1UL << 17)
292 #define CKF_USER_PIN_LOCKED			(1UL << 18)
293 #define CKF_USER_PIN_TO_BE_CHANGED		(1UL << 19)
294 #define CKF_SO_PIN_COUNT_LOW			(1UL << 20)
295 #define CKF_SO_PIN_FINAL_TRY			(1UL << 21)
296 #define CKF_SO_PIN_LOCKED			(1UL << 22)
297 #define CKF_SO_PIN_TO_BE_CHANGED		(1UL << 23)
298 
299 #define CK_UNAVAILABLE_INFORMATION	((unsigned long)-1L)
300 #define CK_EFFECTIVELY_INFINITE		(0UL)
301 
302 
303 typedef unsigned long ck_session_handle_t;
304 
305 #define CK_INVALID_HANDLE	(0UL)
306 
307 
308 typedef unsigned long ck_user_type_t;
309 
310 #define CKU_SO			(0UL)
311 #define CKU_USER		(1UL)
312 #define CKU_CONTEXT_SPECIFIC	(2UL)
313 
314 
315 typedef unsigned long ck_state_t;
316 
317 #define CKS_RO_PUBLIC_SESSION	(0UL)
318 #define CKS_RO_USER_FUNCTIONS	(1UL)
319 #define CKS_RW_PUBLIC_SESSION	(2UL)
320 #define CKS_RW_USER_FUNCTIONS	(3UL)
321 #define CKS_RW_SO_FUNCTIONS	(4UL)
322 
323 
324 struct ck_session_info
325 {
326   ck_slot_id_t slot_id;
327   ck_state_t state;
328   ck_flags_t flags;
329   unsigned long device_error;
330 };
331 
332 #define CKF_RW_SESSION		(1UL << 1)
333 #define CKF_SERIAL_SESSION	(1UL << 2)
334 
335 
336 typedef unsigned long ck_object_handle_t;
337 
338 
339 typedef unsigned long ck_object_class_t;
340 
341 #define CKO_DATA		(0UL)
342 #define CKO_CERTIFICATE		(1UL)
343 #define CKO_PUBLIC_KEY		(2UL)
344 #define CKO_PRIVATE_KEY		(3UL)
345 #define CKO_SECRET_KEY		(4UL)
346 #define CKO_HW_FEATURE		(5UL)
347 #define CKO_DOMAIN_PARAMETERS	(6UL)
348 #define CKO_MECHANISM		(7UL)
349 #define CKO_OTP_KEY		(8UL)
350 #define CKO_VENDOR_DEFINED	((unsigned long) (1UL << 31))
351 
352 
353 typedef unsigned long ck_hw_feature_type_t;
354 
355 #define CKH_MONOTONIC_COUNTER	(1UL)
356 #define CKH_CLOCK		(2UL)
357 #define CKH_USER_INTERFACE	(3UL)
358 #define CKH_VENDOR_DEFINED	((unsigned long) (1UL << 31))
359 
360 
361 typedef unsigned long ck_key_type_t;
362 
363 #define CKK_RSA			(0UL)
364 #define CKK_DSA			(1UL)
365 #define CKK_DH			(2UL)
366 #define CKK_ECDSA		(3UL)
367 #define CKK_EC			(3UL)
368 #define CKK_X9_42_DH		(4UL)
369 #define CKK_KEA			(5UL)
370 #define CKK_GENERIC_SECRET	(0x10UL)
371 #define CKK_RC2			(0x11UL)
372 #define CKK_RC4			(0x12UL)
373 #define CKK_DES			(0x13UL)
374 #define CKK_DES2		(0x14UL)
375 #define CKK_DES3		(0x15UL)
376 #define CKK_CAST		(0x16UL)
377 #define CKK_CAST3		(0x17UL)
378 #define CKK_CAST128		(0x18UL)
379 #define CKK_RC5			(0x19UL)
380 #define CKK_IDEA		(0x1aUL)
381 #define CKK_SKIPJACK		(0x1bUL)
382 #define CKK_BATON		(0x1cUL)
383 #define CKK_JUNIPER		(0x1dUL)
384 #define CKK_CDMF		(0x1eUL)
385 #define CKK_AES			(0x1fUL)
386 #define CKK_BLOWFISH		(0x20UL)
387 #define CKK_TWOFISH		(0x21UL)
388 #define CKK_SECURID		(0x22UL)
389 #define CKK_HOTP		(0x23UL)
390 #define CKK_ACTI		(0x24UL)
391 #define CKK_CAMELLIA		(0x25UL)
392 #define CKK_ARIA		(0x26UL)
393 #define CKK_MD5_HMAC		(0x27UL)
394 #define CKK_SHA_1_HMAC		(0x28UL)
395 #define CKK_RIPEMD128_HMAC	(0x29UL)
396 #define CKK_RIPEMD160_HMAC	(0x2aUL)
397 #define CKK_SHA256_HMAC		(0x2bUL)
398 #define CKK_SHA384_HMAC		(0x2cUL)
399 #define CKK_SHA512_HMAC		(0x2dUL)
400 #define CKK_SHA224_HMAC		(0x2eUL)
401 #define CKK_SEED		(0x2fUL)
402 #define CKK_GOSTR3410		(0x30UL)
403 #define CKK_GOSTR3411		(0x31UL)
404 #define CKK_GOST28147		(0x32UL)
405 #define CKK_EC_EDWARDS		(0x40UL)
406 #define CKK_VENDOR_DEFINED	((unsigned long) (1UL << 31))
407 
408 
409 typedef unsigned long ck_certificate_type_t;
410 
411 #define CKC_X_509		(0UL)
412 #define CKC_X_509_ATTR_CERT	(1UL)
413 #define CKC_WTLS		(2UL)
414 #define CKC_VENDOR_DEFINED	((unsigned long) (1UL << 31))
415 
416 #define CKC_OPENPGP		(CKC_VENDOR_DEFINED|0x504750UL)
417 
418 typedef unsigned long ck_attribute_type_t;
419 
420 #define CKA_CLASS			(0UL)
421 #define CKA_TOKEN			(1UL)
422 #define CKA_PRIVATE			(2UL)
423 #define CKA_LABEL			(3UL)
424 #define CKA_APPLICATION			(0x10UL)
425 #define CKA_VALUE			(0x11UL)
426 #define CKA_OBJECT_ID			(0x12UL)
427 #define CKA_CERTIFICATE_TYPE		(0x80UL)
428 #define CKA_ISSUER			(0x81UL)
429 #define CKA_SERIAL_NUMBER		(0x82UL)
430 #define CKA_AC_ISSUER			(0x83UL)
431 #define CKA_OWNER			(0x84UL)
432 #define CKA_ATTR_TYPES			(0x85UL)
433 #define CKA_TRUSTED			(0x86UL)
434 #define CKA_CERTIFICATE_CATEGORY	(0x87UL)
435 #define CKA_JAVA_MIDP_SECURITY_DOMAIN	(0x88UL)
436 #define CKA_URL				(0x89UL)
437 #define CKA_HASH_OF_SUBJECT_PUBLIC_KEY	(0x8aUL)
438 #define CKA_HASH_OF_ISSUER_PUBLIC_KEY	(0x8bUL)
439 #define CKA_NAME_HASH_ALGORITHM         (0x8cUL)
440 #define CKA_CHECK_VALUE			(0x90UL)
441 #define CKA_KEY_TYPE			(0x100UL)
442 #define CKA_SUBJECT			(0x101UL)
443 #define CKA_ID				(0x102UL)
444 #define CKA_SENSITIVE			(0x103UL)
445 #define CKA_ENCRYPT			(0x104UL)
446 #define CKA_DECRYPT			(0x105UL)
447 #define CKA_WRAP			(0x106UL)
448 #define CKA_UNWRAP			(0x107UL)
449 #define CKA_SIGN			(0x108UL)
450 #define CKA_SIGN_RECOVER		(0x109UL)
451 #define CKA_VERIFY			(0x10aUL)
452 #define CKA_VERIFY_RECOVER		(0x10bUL)
453 #define CKA_DERIVE			(0x10cUL)
454 #define CKA_START_DATE			(0x110UL)
455 #define CKA_END_DATE			(0x111UL)
456 #define CKA_MODULUS			(0x120UL)
457 #define CKA_MODULUS_BITS		(0x121UL)
458 #define CKA_PUBLIC_EXPONENT		(0x122UL)
459 #define CKA_PRIVATE_EXPONENT		(0x123UL)
460 #define CKA_PRIME_1			(0x124UL)
461 #define CKA_PRIME_2			(0x125UL)
462 #define CKA_EXPONENT_1			(0x126UL)
463 #define CKA_EXPONENT_2			(0x127UL)
464 #define CKA_COEFFICIENT			(0x128UL)
465 #define CKA_PUBLIC_KEY_INFO		(0x129UL)
466 #define CKA_PRIME			(0x130UL)
467 #define CKA_SUBPRIME			(0x131UL)
468 #define CKA_BASE			(0x132UL)
469 #define CKA_PRIME_BITS			(0x133UL)
470 #define CKA_SUB_PRIME_BITS		(0x134UL)
471 #define CKA_VALUE_BITS			(0x160UL)
472 #define CKA_VALUE_LEN			(0x161UL)
473 #define CKA_EXTRACTABLE			(0x162UL)
474 #define CKA_LOCAL			(0x163UL)
475 #define CKA_NEVER_EXTRACTABLE		(0x164UL)
476 #define CKA_ALWAYS_SENSITIVE		(0x165UL)
477 #define CKA_KEY_GEN_MECHANISM		(0x166UL)
478 #define CKA_MODIFIABLE			(0x170UL)
479 #define CKA_COPYABLE			(0x171UL)
480 #define CKA_DESTROYABLE			(0x172UL)
481 #define CKA_ECDSA_PARAMS		(0x180UL)
482 #define CKA_EC_PARAMS			(0x180UL)
483 #define CKA_EC_POINT			(0x181UL)
484 #define CKA_SECONDARY_AUTH		(0x200UL)
485 #define CKA_AUTH_PIN_FLAGS		(0x201UL)
486 #define CKA_ALWAYS_AUTHENTICATE		(0x202UL)
487 #define CKA_WRAP_WITH_TRUSTED		(0x210UL)
488 #define CKA_OTP_FORMAT			(0x220UL)
489 #define CKA_OTP_LENGTH			(0x221UL)
490 #define CKA_OTP_TIME_INTERVAL		(0x222UL)
491 #define CKA_OTP_USER_FRIENDLY_MODE	(0x223UL)
492 #define CKA_OTP_CHALLENGE_REQUIREMENT	(0x224UL)
493 #define CKA_OTP_TIME_REQUIREMENT	(0x225UL)
494 #define CKA_OTP_COUNTER_REQUIREMENT	(0x226UL)
495 #define CKA_OTP_PIN_REQUIREMENT		(0x227UL)
496 #define CKA_OTP_USER_IDENTIFIER		(0x22AUL)
497 #define CKA_OTP_SERVICE_IDENTIFIER	(0x22BUL)
498 #define CKA_OTP_SERVICE_LOGO		(0x22CUL)
499 #define CKA_OTP_SERVICE_LOGO_TYPE	(0x22DUL)
500 #define CKA_OTP_COUNTER			(0x22EUL)
501 #define CKA_OTP_TIME                    (0x22FUL)
502 #define CKA_GOSTR3410_PARAMS		(0x250UL)
503 #define CKA_GOSTR3411_PARAMS		(0x251UL)
504 #define CKA_GOST28147_PARAMS		(0x252UL)
505 #define CKA_HW_FEATURE_TYPE		(0x300UL)
506 #define CKA_RESET_ON_INIT		(0x301UL)
507 #define CKA_HAS_RESET			(0x302UL)
508 #define CKA_PIXEL_X			(0x400UL)
509 #define CKA_PIXEL_Y			(0x401UL)
510 #define CKA_RESOLUTION			(0x402UL)
511 #define CKA_CHAR_ROWS			(0x403UL)
512 #define CKA_CHAR_COLUMNS		(0x404UL)
513 #define CKA_COLOR			(0x405UL)
514 #define CKA_BITS_PER_PIXEL		(0x406UL)
515 #define CKA_CHAR_SETS			(0x480UL)
516 #define CKA_ENCODING_METHODS		(0x481UL)
517 #define CKA_MIME_TYPES			(0x482UL)
518 #define CKA_MECHANISM_TYPE		(0x500UL)
519 #define CKA_REQUIRED_CMS_ATTRIBUTES	(0x501UL)
520 #define CKA_DEFAULT_CMS_ATTRIBUTES	(0x502UL)
521 #define CKA_SUPPORTED_CMS_ATTRIBUTES	(0x503UL)
522 #define CKA_WRAP_TEMPLATE		(CKF_ARRAY_ATTRIBUTE | 0x211UL)
523 #define CKA_UNWRAP_TEMPLATE		(CKF_ARRAY_ATTRIBUTE | 0x212UL)
524 #define CKA_DERIVE_TEMPLATE		(CKF_ARRAY_ATTRIBUTE | 0x213UL)
525 #define CKA_ALLOWED_MECHANISMS		(CKF_ARRAY_ATTRIBUTE | 0x600UL)
526 #define CKA_VENDOR_DEFINED		((unsigned long) (1UL << 31))
527 
528 
529 struct ck_attribute
530 {
531   ck_attribute_type_t type;
532   void *value;
533   unsigned long value_len;
534 };
535 
536 
537 struct ck_date
538 {
539   unsigned char year[4];
540   unsigned char month[2];
541   unsigned char day[2];
542 };
543 
544 
545 typedef unsigned long ck_mechanism_type_t;
546 
547 #define CKM_RSA_PKCS_KEY_PAIR_GEN	(0UL)
548 #define CKM_RSA_PKCS			(1UL)
549 #define CKM_RSA_9796			(2UL)
550 #define CKM_RSA_X_509			(3UL)
551 #define CKM_MD2_RSA_PKCS		(4UL)
552 #define CKM_MD5_RSA_PKCS		(5UL)
553 #define CKM_SHA1_RSA_PKCS		(6UL)
554 #define CKM_RIPEMD128_RSA_PKCS		(7UL)
555 #define CKM_RIPEMD160_RSA_PKCS		(8UL)
556 #define CKM_RSA_PKCS_OAEP		(9UL)
557 #define CKM_RSA_X9_31_KEY_PAIR_GEN	(0xaUL)
558 #define CKM_RSA_X9_31			(0xbUL)
559 #define CKM_SHA1_RSA_X9_31		(0xcUL)
560 #define CKM_RSA_PKCS_PSS		(0xdUL)
561 #define CKM_SHA1_RSA_PKCS_PSS		(0xeUL)
562 #define CKM_DSA_KEY_PAIR_GEN		(0x10UL)
563 #define	CKM_DSA				(0x11UL)
564 #define CKM_DSA_SHA1			(0x12UL)
565 #define CKM_DSA_SHA224			(0x13UL)
566 #define CKM_DSA_SHA256			(0x14UL)
567 #define CKM_DSA_SHA384			(0x15UL)
568 #define CKM_DSA_SHA512			(0x16UL)
569 #define CKM_DH_PKCS_KEY_PAIR_GEN	(0x20UL)
570 #define CKM_DH_PKCS_DERIVE		(0x21UL)
571 #define	CKM_X9_42_DH_KEY_PAIR_GEN	(0x30UL)
572 #define CKM_X9_42_DH_DERIVE		(0x31UL)
573 #define CKM_X9_42_DH_HYBRID_DERIVE	(0x32UL)
574 #define CKM_X9_42_MQV_DERIVE		(0x33UL)
575 #define CKM_SHA256_RSA_PKCS		(0x40UL)
576 #define CKM_SHA384_RSA_PKCS		(0x41UL)
577 #define CKM_SHA512_RSA_PKCS		(0x42UL)
578 #define CKM_SHA256_RSA_PKCS_PSS		(0x43UL)
579 #define CKM_SHA384_RSA_PKCS_PSS		(0x44UL)
580 #define CKM_SHA512_RSA_PKCS_PSS		(0x45UL)
581 #define CKM_SHA512_224			(0x48UL)
582 #define CKM_SHA512_224_HMAC		(0x49UL)
583 #define CKM_SHA512_224_HMAC_GENERAL	(0x4aUL)
584 #define CKM_SHA512_224_KEY_DERIVATION	(0x4bUL)
585 #define CKM_SHA512_256			(0x4cUL)
586 #define CKM_SHA512_256_HMAC		(0x4dUL)
587 #define CKM_SHA512_256_HMAC_GENERAL	(0x4eUL)
588 #define CKM_SHA512_256_KEY_DERIVATION	(0x4fUL)
589 #define CKM_SHA512_T			(0x50UL)
590 #define CKM_SHA512_T_HMAC		(0x51UL)
591 #define CKM_SHA512_T_HMAC_GENERAL	(0x52UL)
592 #define CKM_SHA512_T_KEY_DERIVATION	(0x53UL)
593 #define CKM_RC2_KEY_GEN			(0x100UL)
594 #define CKM_RC2_ECB			(0x101UL)
595 #define	CKM_RC2_CBC			(0x102UL)
596 #define	CKM_RC2_MAC			(0x103UL)
597 #define CKM_RC2_MAC_GENERAL		(0x104UL)
598 #define CKM_RC2_CBC_PAD			(0x105UL)
599 #define CKM_RC4_KEY_GEN			(0x110UL)
600 #define CKM_RC4				(0x111UL)
601 #define CKM_DES_KEY_GEN			(0x120UL)
602 #define CKM_DES_ECB			(0x121UL)
603 #define CKM_DES_CBC			(0x122UL)
604 #define CKM_DES_MAC			(0x123UL)
605 #define CKM_DES_MAC_GENERAL		(0x124UL)
606 #define CKM_DES_CBC_PAD			(0x125UL)
607 #define CKM_DES2_KEY_GEN		(0x130UL)
608 #define CKM_DES3_KEY_GEN		(0x131UL)
609 #define CKM_DES3_ECB			(0x132UL)
610 #define CKM_DES3_CBC			(0x133UL)
611 #define CKM_DES3_MAC			(0x134UL)
612 #define CKM_DES3_MAC_GENERAL		(0x135UL)
613 #define CKM_DES3_CBC_PAD		(0x136UL)
614 #define CKM_DES3_CMAC_GENERAL		(0x137UL)
615 #define CKM_DES3_CMAC			(0x138UL)
616 #define CKM_CDMF_KEY_GEN		(0x140UL)
617 #define CKM_CDMF_ECB			(0x141UL)
618 #define CKM_CDMF_CBC			(0x142UL)
619 #define CKM_CDMF_MAC			(0x143UL)
620 #define CKM_CDMF_MAC_GENERAL		(0x144UL)
621 #define CKM_CDMF_CBC_PAD		(0x145UL)
622 #define CKM_DES_OFB64			(0x150UL)
623 #define CKM_DES_OFB8			(0x151UL)
624 #define CKM_DES_CFB64			(0x152UL)
625 #define CKM_DES_CFB8			(0x153UL)
626 #define CKM_MD2				(0x200UL)
627 #define CKM_MD2_HMAC			(0x201UL)
628 #define CKM_MD2_HMAC_GENERAL		(0x202UL)
629 #define CKM_MD5				(0x210UL)
630 #define CKM_MD5_HMAC			(0x211UL)
631 #define CKM_MD5_HMAC_GENERAL		(0x212UL)
632 #define CKM_SHA_1			(0x220UL)
633 #define CKM_SHA_1_HMAC			(0x221UL)
634 #define CKM_SHA_1_HMAC_GENERAL		(0x222UL)
635 #define CKM_RIPEMD128			(0x230UL)
636 #define CKM_RIPEMD128_HMAC		(0x231UL)
637 #define CKM_RIPEMD128_HMAC_GENERAL	(0x232UL)
638 #define CKM_RIPEMD160			(0x240UL)
639 #define CKM_RIPEMD160_HMAC		(0x241UL)
640 #define CKM_RIPEMD160_HMAC_GENERAL	(0x242UL)
641 #define CKM_SHA256			(0x250UL)
642 #define CKM_SHA256_HMAC			(0x251UL)
643 #define CKM_SHA256_HMAC_GENERAL		(0x252UL)
644 #define CKM_SHA384			(0x260UL)
645 #define CKM_SHA384_HMAC			(0x261UL)
646 #define CKM_SHA384_HMAC_GENERAL		(0x262UL)
647 #define CKM_SHA512			(0x270UL)
648 #define CKM_SHA512_HMAC			(0x271UL)
649 #define CKM_SHA512_HMAC_GENERAL		(0x272UL)
650 #define CKM_SECURID_KEY_GEN             (0x280UL)
651 #define CKM_SECURID                     (0x282UL)
652 #define CKM_HOTP_KEY_GEN                (0x290UL)
653 #define CKM_HOTP                        (0x291UL)
654 #define CKM_ACTI                        (0x2a0UL)
655 #define CKM_ACTI_KEY_GEN                (0x2a1UL)
656 #define CKM_CAST_KEY_GEN		(0x300UL)
657 #define CKM_CAST_ECB			(0x301UL)
658 #define CKM_CAST_CBC			(0x302UL)
659 #define CKM_CAST_MAC			(0x303UL)
660 #define CKM_CAST_MAC_GENERAL		(0x304UL)
661 #define CKM_CAST_CBC_PAD		(0x305UL)
662 #define CKM_CAST3_KEY_GEN		(0x310UL)
663 #define CKM_CAST3_ECB			(0x311UL)
664 #define CKM_CAST3_CBC			(0x312UL)
665 #define CKM_CAST3_MAC			(0x313UL)
666 #define CKM_CAST3_MAC_GENERAL		(0x314UL)
667 #define CKM_CAST3_CBC_PAD		(0x315UL)
668 #define CKM_CAST5_KEY_GEN		(0x320UL)
669 #define CKM_CAST128_KEY_GEN		(0x320UL)
670 #define CKM_CAST5_ECB			(0x321UL)
671 #define CKM_CAST128_ECB			(0x321UL)
672 #define CKM_CAST5_CBC			(0x322UL)
673 #define CKM_CAST128_CBC			(0x322UL)
674 #define CKM_CAST5_MAC			(0x323UL)
675 #define	CKM_CAST128_MAC			(0x323UL)
676 #define CKM_CAST5_MAC_GENERAL		(0x324UL)
677 #define CKM_CAST128_MAC_GENERAL		(0x324UL)
678 #define CKM_CAST5_CBC_PAD		(0x325UL)
679 #define CKM_CAST128_CBC_PAD		(0x325UL)
680 #define CKM_RC5_KEY_GEN			(0x330UL)
681 #define CKM_RC5_ECB			(0x331UL)
682 #define CKM_RC5_CBC			(0x332UL)
683 #define CKM_RC5_MAC			(0x333UL)
684 #define CKM_RC5_MAC_GENERAL		(0x334UL)
685 #define CKM_RC5_CBC_PAD			(0x335UL)
686 #define CKM_IDEA_KEY_GEN		(0x340UL)
687 #define CKM_IDEA_ECB			(0x341UL)
688 #define	CKM_IDEA_CBC			(0x342UL)
689 #define CKM_IDEA_MAC			(0x343UL)
690 #define CKM_IDEA_MAC_GENERAL		(0x344UL)
691 #define CKM_IDEA_CBC_PAD		(0x345UL)
692 #define CKM_GENERIC_SECRET_KEY_GEN	(0x350UL)
693 #define CKM_CONCATENATE_BASE_AND_KEY	(0x360UL)
694 #define CKM_CONCATENATE_BASE_AND_DATA	(0x362UL)
695 #define CKM_CONCATENATE_DATA_AND_BASE	(0x363UL)
696 #define CKM_XOR_BASE_AND_DATA		(0x364UL)
697 #define CKM_EXTRACT_KEY_FROM_KEY	(0x365UL)
698 #define CKM_SSL3_PRE_MASTER_KEY_GEN	(0x370UL)
699 #define CKM_SSL3_MASTER_KEY_DERIVE	(0x371UL)
700 #define CKM_SSL3_KEY_AND_MAC_DERIVE	(0x372UL)
701 #define CKM_SSL3_MASTER_KEY_DERIVE_DH	(0x373UL)
702 #define CKM_TLS_PRE_MASTER_KEY_GEN	(0x374UL)
703 #define CKM_TLS_MASTER_KEY_DERIVE	(0x375UL)
704 #define CKM_TLS_KEY_AND_MAC_DERIVE	(0x376UL)
705 #define CKM_TLS_MASTER_KEY_DERIVE_DH	(0x377UL)
706 #define CKM_TLS_PRF			(0x378UL)
707 #define CKM_SSL3_MD5_MAC		(0x380UL)
708 #define CKM_SSL3_SHA1_MAC		(0x381UL)
709 #define CKM_MD5_KEY_DERIVATION		(0x390UL)
710 #define CKM_MD2_KEY_DERIVATION		(0x391UL)
711 #define CKM_SHA1_KEY_DERIVATION		(0x392UL)
712 #define CKM_SHA256_KEY_DERIVATION	(0x393UL)
713 #define CKM_SHA384_KEY_DERIVATION	(0x394UL)
714 #define CKM_SHA512_KEY_DERIVATION	(0x395UL)
715 #define CKM_PBE_MD2_DES_CBC		(0x3a0UL)
716 #define CKM_PBE_MD5_DES_CBC		(0x3a1UL)
717 #define CKM_PBE_MD5_CAST_CBC		(0x3a2UL)
718 #define CKM_PBE_MD5_CAST3_CBC		(0x3a3UL)
719 #define CKM_PBE_MD5_CAST5_CBC		(0x3a4UL)
720 #define CKM_PBE_MD5_CAST128_CBC		(0x3a4UL)
721 #define CKM_PBE_SHA1_CAST5_CBC		(0x3a5UL)
722 #define CKM_PBE_SHA1_CAST128_CBC	(0x3a5UL)
723 #define CKM_PBE_SHA1_RC4_128		(0x3a6UL)
724 #define CKM_PBE_SHA1_RC4_40		(0x3a7UL)
725 #define CKM_PBE_SHA1_DES3_EDE_CBC	(0x3a8UL)
726 #define CKM_PBE_SHA1_DES2_EDE_CBC	(0x3a9UL)
727 #define CKM_PBE_SHA1_RC2_128_CBC	(0x3aaUL)
728 #define CKM_PBE_SHA1_RC2_40_CBC		(0x3abUL)
729 #define CKM_PKCS5_PBKD2			(0x3b0UL)
730 #define CKM_PBA_SHA1_WITH_SHA1_HMAC	(0x3c0UL)
731 #define CKM_WTLS_PRE_MASTER_KEY_GEN	(0x3d0UL)
732 #define CKM_WTLS_MASTER_KEY_DERIVE	(0x3d1UL)
733 #define CKM_WTLS_MASTER_KEY_DERIVE_DH_ECC (0x3d2UL)
734 #define CKM_WTLS_PRF			(0x3d3UL)
735 #define CKM_WTLS_SERVER_KEY_AND_MAC_DERIVE (0x3d4UL)
736 #define CKM_WTLS_CLIENT_KEY_AND_MAC_DERIVE (0x3d5UL)
737 #define CKM_TLS10_MAC_SERVER		(0x3d6UL)
738 #define CKM_TLS10_MAC_CLIENT		(0x3d7UL)
739 #define CKM_TLS12_MAC			(0x3d8UL)
740 #define CKM_TLS12_KDF			(0x3d9UL)
741 #define CKM_TLS12_MASTER_KEY_DERIVE	(0x3e0UL)
742 #define CKM_TLS12_KEY_AND_MAC_DERIVE	(0x3e1UL)
743 #define CKM_TLS12_MASTER_KEY_DERIVE_DH	(0x3e2UL)
744 #define CKM_TLS12_KEY_SAFE_DERIVE	(0x3e3UL)
745 #define CKM_TLS_MAC			(0x3e4UL)
746 #define CKM_TLS_KDF			(0x3e5UL)
747 #define CKM_KEY_WRAP_LYNKS		(0x400UL)
748 #define CKM_KEY_WRAP_SET_OAEP		(0x401UL)
749 #define CKM_CMS_SIG			(0x500UL)
750 #define CKM_KIP_DERIVE			(0x510UL)
751 #define CKM_KIP_WRAP			(0x511UL)
752 #define CKM_KIP_MAC			(0x512UL)
753 #define CKM_ARIA_KEY_GEN		(0x560UL)
754 #define CKM_ARIA_ECB			(0x561UL)
755 #define CKM_ARIA_CBC			(0x562UL)
756 #define CKM_ARIA_MAC			(0x563UL)
757 #define CKM_ARIA_MAC_GENERAL		(0x564UL)
758 #define CKM_ARIA_CBC_PAD		(0x565UL)
759 #define CKM_ARIA_ECB_ENCRYPT_DATA	(0x566UL)
760 #define CKM_ARIA_CBC_ENCRYPT_DATA	(0x567UL)
761 #define CKM_SEED_KEY_GEN		(0x650UL)
762 #define CKM_SEED_ECB			(0x651UL)
763 #define CKM_SEED_CBC			(0x652UL)
764 #define CKM_SEED_MAC			(0x653UL)
765 #define CKM_SEED_MAC_GENERAL		(0x654UL)
766 #define CKM_SEED_CBC_PAD		(0x655UL)
767 #define CKM_SEED_ECB_ENCRYPT_DATA	(0x656UL)
768 #define CKM_SEED_CBC_ENCRYPT_DATA	(0x657UL)
769 #define CKM_SKIPJACK_KEY_GEN		(0x1000UL)
770 #define CKM_SKIPJACK_ECB64		(0x1001UL)
771 #define CKM_SKIPJACK_CBC64		(0x1002UL)
772 #define CKM_SKIPJACK_OFB64		(0x1003UL)
773 #define CKM_SKIPJACK_CFB64		(0x1004UL)
774 #define CKM_SKIPJACK_CFB32		(0x1005UL)
775 #define CKM_SKIPJACK_CFB16		(0x1006UL)
776 #define CKM_SKIPJACK_CFB8		(0x1007UL)
777 #define CKM_SKIPJACK_WRAP		(0x1008UL)
778 #define CKM_SKIPJACK_PRIVATE_WRAP	(0x1009UL)
779 #define CKM_SKIPJACK_RELAYX		(0x100aUL)
780 #define CKM_KEA_KEY_PAIR_GEN		(0x1010UL)
781 #define CKM_KEA_KEY_DERIVE		(0x1011UL)
782 #define CKM_FORTEZZA_TIMESTAMP		(0x1020UL)
783 #define CKM_BATON_KEY_GEN		(0x1030UL)
784 #define CKM_BATON_ECB128		(0x1031UL)
785 #define CKM_BATON_ECB96			(0x1032UL)
786 #define CKM_BATON_CBC128		(0x1033UL)
787 #define CKM_BATON_COUNTER		(0x1034UL)
788 #define CKM_BATON_SHUFFLE		(0x1035UL)
789 #define CKM_BATON_WRAP			(0x1036UL)
790 #define CKM_ECDSA_KEY_PAIR_GEN		(0x1040UL)
791 #define CKM_EC_KEY_PAIR_GEN		(0x1040UL)
792 #define CKM_ECDSA			(0x1041UL)
793 #define CKM_ECDSA_SHA1			(0x1042UL)
794 #define CKM_ECDSA_SHA224		(0x1043UL)
795 #define CKM_ECDSA_SHA256		(0x1044UL)
796 #define CKM_ECDSA_SHA384		(0x1045UL)
797 #define CKM_ECDSA_SHA512		(0x1046UL)
798 #define CKM_ECDH1_DERIVE		(0x1050UL)
799 #define CKM_ECDH1_COFACTOR_DERIVE	(0x1051UL)
800 #define CKM_ECMQV_DERIVE		(0x1052UL)
801 #define CKM_ECDH_AES_KEY_WRAP		(0x1053UL)
802 #define CKM_RSA_AES_KEY_WRAP		(0x1054UL)
803 #define CKM_JUNIPER_KEY_GEN		(0x1060UL)
804 #define CKM_JUNIPER_ECB128		(0x1061UL)
805 #define CKM_JUNIPER_CBC128		(0x1062UL)
806 #define CKM_JUNIPER_COUNTER		(0x1063UL)
807 #define CKM_JUNIPER_SHUFFLE		(0x1064UL)
808 #define CKM_JUNIPER_WRAP		(0x1065UL)
809 #define CKM_FASTHASH			(0x1070UL)
810 #define CKM_AES_KEY_GEN			(0x1080UL)
811 #define CKM_AES_ECB			(0x1081UL)
812 #define CKM_AES_CBC			(0x1082UL)
813 #define CKM_AES_MAC			(0x1083UL)
814 #define CKM_AES_MAC_GENERAL		(0x1084UL)
815 #define CKM_AES_CBC_PAD			(0x1085UL)
816 #define CKM_AES_CTR			(0x1086UL)
817 #define CKM_AES_GCM			(0x1087UL)
818 #define CKM_AES_CCM			(0x1088UL)
819 #define CKM_AES_CTS			(0x1089UL)
820 #define CKM_AES_CMAC			(0x108aUL)
821 #define CKM_AES_CMAC_GENERAL		(0x108bUL)
822 #define CKM_AES_XCBC_MAC		(0x108cUL)
823 #define CKM_AES_XCBC_MAC_96		(0x108dUL)
824 #define CKM_AES_GMAC			(0x108eUL)
825 #define CKM_BLOWFISH_KEY_GEN		(0x1090UL)
826 #define CKM_BLOWFISH_CBC		(0x1091UL)
827 #define CKM_TWOFISH_KEY_GEN		(0x1092UL)
828 #define CKM_TWOFISH_CBC			(0x1093UL)
829 #define CKM_BLOWFISH_CBC_PAD		(0x1094UL)
830 #define CKM_TWOFISH_CBC_PAD		(0x1095UL)
831 #define CKM_DES_ECB_ENCRYPT_DATA	(0x1100UL)
832 #define CKM_DES_CBC_ENCRYPT_DATA	(0x1101UL)
833 #define CKM_DES3_ECB_ENCRYPT_DATA	(0x1102UL)
834 #define CKM_DES3_CBC_ENCRYPT_DATA	(0x1103UL)
835 #define CKM_AES_ECB_ENCRYPT_DATA	(0x1104UL)
836 #define CKM_AES_CBC_ENCRYPT_DATA	(0x1105UL)
837 #define CKM_GOSTR3410_KEY_PAIR_GEN	(0x1200UL)
838 #define CKM_GOSTR3410			(0x1201UL)
839 #define CKM_GOSTR3410_WITH_GOSTR3411	(0x1202UL)
840 #define CKM_GOSTR3410_KEY_WRAP		(0x1203UL)
841 #define CKM_GOSTR3410_DERIVE		(0x1204UL)
842 #define CKM_GOSTR3411			(0x1210UL)
843 #define CKM_GOSTR3411_HMAC		(0x1211UL)
844 #define CKM_GOST28147_KEY_GEN		(0x1220UL)
845 #define CKM_GOST28147_ECB		(0x1221UL)
846 #define CKM_GOST28147			(0x1222UL)
847 #define CKM_GOST28147_MAC		(0x1223UL)
848 #define CKM_GOST28147_KEY_WRAP		(0x1224UL)
849 #define CKM_DSA_PARAMETER_GEN		(0x2000UL)
850 #define CKM_DH_PKCS_PARAMETER_GEN	(0x2001UL)
851 #define CKM_X9_42_DH_PARAMETER_GEN	(0x2002UL)
852 #define CKM_DSA_PROBABLISTIC_PARAMETER_GEN	(0x2003UL)
853 #define CKM_DSA_SHAWE_TAYLOR_PARAMETER_GEN	(0x2004UL)
854 #define CKM_AES_OFB			(0x2104UL)
855 #define CKM_AES_CFB64			(0x2105UL)
856 #define CKM_AES_CFB8			(0x2106UL)
857 #define CKM_AES_CFB128			(0x2107UL)
858 #define CKM_AES_CFB1			(0x2108UL)
859 
860 #define CKM_VENDOR_DEFINED		((unsigned long) (1UL << 31))
861 
862 /* Amendments */
863 #define CKM_SHA224			(0x255UL)
864 #define CKM_SHA224_HMAC			(0x256UL)
865 #define CKM_SHA224_HMAC_GENERAL		(0x257UL)
866 #define CKM_SHA224_RSA_PKCS		(0x46UL)
867 #define CKM_SHA224_RSA_PKCS_PSS		(0x47UL)
868 #define CKM_SHA224_KEY_DERIVATION	(0x396UL)
869 
870 #define CKM_CAMELLIA_KEY_GEN		(0x550UL)
871 #define CKM_CAMELLIA_ECB		(0x551UL)
872 #define CKM_CAMELLIA_CBC		(0x552UL)
873 #define CKM_CAMELLIA_MAC		(0x553UL)
874 #define CKM_CAMELLIA_MAC_GENERAL	(0x554UL)
875 #define CKM_CAMELLIA_CBC_PAD		(0x555UL)
876 #define CKM_CAMELLIA_ECB_ENCRYPT_DATA	(0x556UL)
877 #define CKM_CAMELLIA_CBC_ENCRYPT_DATA	(0x557UL)
878 #define CKM_CAMELLIA_CTR		(0x558UL)
879 
880 #define CKM_AES_KEY_WRAP		(0x2109UL)
881 #define CKM_AES_KEY_WRAP_PAD		(0x210aUL)
882 
883 #define CKM_RSA_PKCS_TPM_1_1		(0x4001UL)
884 #define CKM_RSA_PKCS_OAEP_TPM_1_1	(0x4002UL)
885 
886 /* From version 3.0 */
887 #define CKM_EC_EDWARDS_KEY_PAIR_GEN	(0x1055UL)
888 #define CKM_EDDSA			(0x1057UL)
889 
890 /* Attribute and other constants related to OTP */
891 #define CK_OTP_FORMAT_DECIMAL		(0UL)
892 #define CK_OTP_FORMAT_HEXADECIMAL	(1UL)
893 #define CK_OTP_FORMAT_ALPHANUMERIC	(2UL)
894 #define CK_OTP_FORMAT_BINARY		(3UL)
895 #define CK_OTP_PARAM_IGNORED		(0UL)
896 #define CK_OTP_PARAM_OPTIONAL		(1UL)
897 #define CK_OTP_PARAM_MANDATORY		(2UL)
898 
899 #define CK_OTP_VALUE			(0UL)
900 #define CK_OTP_PIN			(1UL)
901 #define CK_OTP_CHALLENGE		(2UL)
902 #define CK_OTP_TIME			(3UL)
903 #define CK_OTP_COUNTER			(4UL)
904 #define CK_OTP_FLAGS			(5UL)
905 #define CK_OTP_OUTPUT_LENGTH		(6UL)
906 #define CK_OTP_FORMAT			(7UL)
907 
908 /* OTP mechanism flags */
909 #define CKF_NEXT_OTP			(0x01UL)
910 #define CKF_EXCLUDE_TIME		(0x02UL)
911 #define CKF_EXCLUDE_COUNTER		(0x04UL)
912 #define CKF_EXCLUDE_CHALLENGE		(0x08UL)
913 #define CKF_EXCLUDE_PIN			(0x10UL)
914 #define CKF_USER_FRIENDLY_OTP		(0x20UL)
915 
916 #define CKN_OTP_CHANGED			(0x01UL)
917 
918 struct ck_mechanism
919 {
920   ck_mechanism_type_t mechanism;
921   void *parameter;
922   unsigned long parameter_len;
923 };
924 
925 
926 struct ck_mechanism_info
927 {
928   unsigned long min_key_size;
929   unsigned long max_key_size;
930   ck_flags_t flags;
931 };
932 
933 typedef unsigned long ck_param_type;
934 
935 typedef struct ck_otp_param {
936    ck_param_type type;
937    void *value;
938    unsigned long value_len;
939 } ck_otp_param;
940 
941 typedef struct ck_otp_params {
942    struct ck_otp_param *params;
943    unsigned long count;
944 } ck_otp_params;
945 
946 typedef struct ck_otp_signature_info
947 {
948   struct ck_otp_param *params;
949   unsigned long count;
950 } ck_otp_signature_info;
951 
952 #define CKG_MGF1_SHA1 0x00000001UL
953 #define CKG_MGF1_SHA224 0x00000005UL
954 #define CKG_MGF1_SHA256 0x00000002UL
955 #define CKG_MGF1_SHA384 0x00000003UL
956 #define CKG_MGF1_SHA512 0x00000004UL
957 
958 typedef unsigned long ck_rsa_pkcs_mgf_type_t;
959 typedef ck_rsa_pkcs_mgf_type_t * CK_RSA_PKCS_MGF_TYPE_PTR;
960 
961 struct ck_rsa_pkcs_pss_params {
962   ck_mechanism_type_t hash_alg;
963   ck_rsa_pkcs_mgf_type_t mgf;
964   unsigned long s_len;
965 };
966 
967 typedef unsigned long ck_rsa_pkcs_oaep_source_type_t;
968 
969 struct ck_rsa_pkcs_oaep_params {
970   ck_mechanism_type_t hash_alg;
971   ck_rsa_pkcs_mgf_type_t mgf;
972   ck_rsa_pkcs_oaep_source_type_t source;
973   void *source_data;
974   unsigned long source_data_len;
975 };
976 
977 struct ck_aes_ctr_params {
978   unsigned long counter_bits;
979   unsigned char cb[16];
980 };
981 
982 struct ck_gcm_params {
983   unsigned char *iv_ptr;
984   unsigned long iv_len;
985   unsigned long iv_bits;
986   unsigned char *aad_ptr;
987   unsigned long aad_len;
988   unsigned long tag_bits;
989 };
990 
991 
992 /* The following EC Key Derivation Functions are defined */
993 #define CKD_NULL			(0x01UL)
994 #define CKD_SHA1_KDF			(0x02UL)
995 
996 /* The following X9.42 DH key derivation functions are defined */
997 #define CKD_SHA1_KDF_ASN1		(0x03UL)
998 #define CKD_SHA1_KDF_CONCATENATE	(0x04UL)
999 #define CKD_SHA224_KDF			(0x05UL)
1000 #define CKD_SHA256_KDF			(0x06UL)
1001 #define CKD_SHA384_KDF			(0x07UL)
1002 #define CKD_SHA512_KDF			(0x08UL)
1003 #define CKD_CPDIVERSIFY_KDF		(0x09UL)
1004 
1005 typedef unsigned long ck_ec_kdf_t;
1006 
1007 struct ck_ecdh1_derive_params {
1008   ck_ec_kdf_t kdf;
1009   unsigned long shared_data_len;
1010   unsigned char *shared_data;
1011   unsigned long public_data_len;
1012   unsigned char *public_data;
1013 };
1014 
1015 struct ck_key_derivation_string_data {
1016   unsigned char *string_data;
1017   unsigned long string_data_len;
1018 };
1019 
1020 struct ck_des_cbc_encrypt_data_params {
1021   unsigned char iv[8];
1022   unsigned char *data_params;
1023   unsigned long length;
1024 };
1025 
1026 struct ck_aes_cbc_encrypt_data_params {
1027   unsigned char iv[16];
1028   unsigned char *data_params;
1029   unsigned long length;
1030 };
1031 
1032 #define CKF_HW			(1UL << 0)
1033 #define CKF_ENCRYPT		(1UL << 8)
1034 #define CKF_DECRYPT		(1UL << 9)
1035 #define CKF_DIGEST		(1UL << 10)
1036 #define CKF_SIGN		(1UL << 11)
1037 #define CKF_SIGN_RECOVER	(1UL << 12)
1038 #define CKF_VERIFY		(1UL << 13)
1039 #define CKF_VERIFY_RECOVER	(1UL << 14)
1040 #define CKF_GENERATE		(1UL << 15)
1041 #define CKF_GENERATE_KEY_PAIR	(1UL << 16)
1042 #define CKF_WRAP		(1UL << 17)
1043 #define CKF_UNWRAP		(1UL << 18)
1044 #define CKF_DERIVE		(1UL << 19)
1045 #define CKF_EXTENSION		((unsigned long) (1UL << 31))
1046 
1047 #define CKF_EC_F_P		(1UL << 20)
1048 #define CKF_EC_NAMEDCURVE	(1UL << 23)
1049 #define CKF_EC_UNCOMPRESS	(1UL << 24)
1050 #define CKF_EC_COMPRESS		(1UL << 25)
1051 
1052 
1053 /* Flags for C_WaitForSlotEvent.  */
1054 #define CKF_DONT_BLOCK				(1UL)
1055 
1056 
1057 typedef unsigned long ck_rv_t;
1058 
1059 
1060 typedef ck_rv_t (*ck_notify_t) (ck_session_handle_t session,
1061 				ck_notification_t event, void *application);
1062 
1063 /* Forward reference.  */
1064 struct ck_function_list;
1065 
1066 #define _CK_DECLARE_FUNCTION(name, args)	\
1067 typedef ck_rv_t (*CK_ ## name) args;		\
1068 ck_rv_t CK_SPEC name args
1069 
1070 _CK_DECLARE_FUNCTION (C_Initialize, (void *init_args));
1071 _CK_DECLARE_FUNCTION (C_Finalize, (void *reserved));
1072 _CK_DECLARE_FUNCTION (C_GetInfo, (struct ck_info *info));
1073 _CK_DECLARE_FUNCTION (C_GetFunctionList,
1074 		      (struct ck_function_list **function_list));
1075 
1076 _CK_DECLARE_FUNCTION (C_GetSlotList,
1077 		      (unsigned char token_present, ck_slot_id_t *slot_list,
1078 		       unsigned long *count));
1079 _CK_DECLARE_FUNCTION (C_GetSlotInfo,
1080 		      (ck_slot_id_t slot_id, struct ck_slot_info *info));
1081 _CK_DECLARE_FUNCTION (C_GetTokenInfo,
1082 		      (ck_slot_id_t slot_id, struct ck_token_info *info));
1083 _CK_DECLARE_FUNCTION (C_WaitForSlotEvent,
1084 		      (ck_flags_t flags, ck_slot_id_t *slot, void *reserved));
1085 _CK_DECLARE_FUNCTION (C_GetMechanismList,
1086 		      (ck_slot_id_t slot_id,
1087 		       ck_mechanism_type_t *mechanism_list,
1088 		       unsigned long *count));
1089 _CK_DECLARE_FUNCTION (C_GetMechanismInfo,
1090 		      (ck_slot_id_t slot_id, ck_mechanism_type_t type,
1091 		       struct ck_mechanism_info *info));
1092 _CK_DECLARE_FUNCTION (C_InitToken,
1093 		      (ck_slot_id_t slot_id, unsigned char *pin,
1094 		       unsigned long pin_len, unsigned char *label));
1095 _CK_DECLARE_FUNCTION (C_InitPIN,
1096 		      (ck_session_handle_t session, unsigned char *pin,
1097 		       unsigned long pin_len));
1098 _CK_DECLARE_FUNCTION (C_SetPIN,
1099 		      (ck_session_handle_t session, unsigned char *old_pin,
1100 		       unsigned long old_len, unsigned char *new_pin,
1101 		       unsigned long new_len));
1102 
1103 _CK_DECLARE_FUNCTION (C_OpenSession,
1104 		      (ck_slot_id_t slot_id, ck_flags_t flags,
1105 		       void *application, ck_notify_t notify,
1106 		       ck_session_handle_t *session));
1107 _CK_DECLARE_FUNCTION (C_CloseSession, (ck_session_handle_t session));
1108 _CK_DECLARE_FUNCTION (C_CloseAllSessions, (ck_slot_id_t slot_id));
1109 _CK_DECLARE_FUNCTION (C_GetSessionInfo,
1110 		      (ck_session_handle_t session,
1111 		       struct ck_session_info *info));
1112 _CK_DECLARE_FUNCTION (C_GetOperationState,
1113 		      (ck_session_handle_t session,
1114 		       unsigned char *operation_state,
1115 		       unsigned long *operation_state_len));
1116 _CK_DECLARE_FUNCTION (C_SetOperationState,
1117 		      (ck_session_handle_t session,
1118 		       unsigned char *operation_state,
1119 		       unsigned long operation_state_len,
1120 		       ck_object_handle_t encryption_key,
1121 		       ck_object_handle_t authentiation_key));
1122 _CK_DECLARE_FUNCTION (C_Login,
1123 		      (ck_session_handle_t session, ck_user_type_t user_type,
1124 		       unsigned char *pin, unsigned long pin_len));
1125 _CK_DECLARE_FUNCTION (C_Logout, (ck_session_handle_t session));
1126 
1127 _CK_DECLARE_FUNCTION (C_CreateObject,
1128 		      (ck_session_handle_t session,
1129 		       struct ck_attribute *templ,
1130 		       unsigned long count, ck_object_handle_t *object));
1131 _CK_DECLARE_FUNCTION (C_CopyObject,
1132 		      (ck_session_handle_t session, ck_object_handle_t object,
1133 		       struct ck_attribute *templ, unsigned long count,
1134 		       ck_object_handle_t *new_object));
1135 _CK_DECLARE_FUNCTION (C_DestroyObject,
1136 		      (ck_session_handle_t session,
1137 		       ck_object_handle_t object));
1138 _CK_DECLARE_FUNCTION (C_GetObjectSize,
1139 		      (ck_session_handle_t session,
1140 		       ck_object_handle_t object,
1141 		       unsigned long *size));
1142 _CK_DECLARE_FUNCTION (C_GetAttributeValue,
1143 		      (ck_session_handle_t session,
1144 		       ck_object_handle_t object,
1145 		       struct ck_attribute *templ,
1146 		       unsigned long count));
1147 _CK_DECLARE_FUNCTION (C_SetAttributeValue,
1148 		      (ck_session_handle_t session,
1149 		       ck_object_handle_t object,
1150 		       struct ck_attribute *templ,
1151 		       unsigned long count));
1152 _CK_DECLARE_FUNCTION (C_FindObjectsInit,
1153 		      (ck_session_handle_t session,
1154 		       struct ck_attribute *templ,
1155 		       unsigned long count));
1156 _CK_DECLARE_FUNCTION (C_FindObjects,
1157 		      (ck_session_handle_t session,
1158 		       ck_object_handle_t *object,
1159 		       unsigned long max_object_count,
1160 		       unsigned long *object_count));
1161 _CK_DECLARE_FUNCTION (C_FindObjectsFinal,
1162 		      (ck_session_handle_t session));
1163 
1164 _CK_DECLARE_FUNCTION (C_EncryptInit,
1165 		      (ck_session_handle_t session,
1166 		       struct ck_mechanism *mechanism,
1167 		       ck_object_handle_t key));
1168 _CK_DECLARE_FUNCTION (C_Encrypt,
1169 		      (ck_session_handle_t session,
1170 		       unsigned char *data, unsigned long data_len,
1171 		       unsigned char *encrypted_data,
1172 		       unsigned long *encrypted_data_len));
1173 _CK_DECLARE_FUNCTION (C_EncryptUpdate,
1174 		      (ck_session_handle_t session,
1175 		       unsigned char *part, unsigned long part_len,
1176 		       unsigned char *encrypted_part,
1177 		       unsigned long *encrypted_part_len));
1178 _CK_DECLARE_FUNCTION (C_EncryptFinal,
1179 		      (ck_session_handle_t session,
1180 		       unsigned char *last_encrypted_part,
1181 		       unsigned long *last_encrypted_part_len));
1182 
1183 _CK_DECLARE_FUNCTION (C_DecryptInit,
1184 		      (ck_session_handle_t session,
1185 		       struct ck_mechanism *mechanism,
1186 		       ck_object_handle_t key));
1187 _CK_DECLARE_FUNCTION (C_Decrypt,
1188 		      (ck_session_handle_t session,
1189 		       unsigned char *encrypted_data,
1190 		       unsigned long encrypted_data_len,
1191 		       unsigned char *data, unsigned long *data_len));
1192 _CK_DECLARE_FUNCTION (C_DecryptUpdate,
1193 		      (ck_session_handle_t session,
1194 		       unsigned char *encrypted_part,
1195 		       unsigned long encrypted_part_len,
1196 		       unsigned char *part, unsigned long *part_len));
1197 _CK_DECLARE_FUNCTION (C_DecryptFinal,
1198 		      (ck_session_handle_t session,
1199 		       unsigned char *last_part,
1200 		       unsigned long *last_part_len));
1201 
1202 _CK_DECLARE_FUNCTION (C_DigestInit,
1203 		      (ck_session_handle_t session,
1204 		       struct ck_mechanism *mechanism));
1205 _CK_DECLARE_FUNCTION (C_Digest,
1206 		      (ck_session_handle_t session,
1207 		       unsigned char *data, unsigned long data_len,
1208 		       unsigned char *digest,
1209 		       unsigned long *digest_len));
1210 _CK_DECLARE_FUNCTION (C_DigestUpdate,
1211 		      (ck_session_handle_t session,
1212 		       unsigned char *part, unsigned long part_len));
1213 _CK_DECLARE_FUNCTION (C_DigestKey,
1214 		      (ck_session_handle_t session, ck_object_handle_t key));
1215 _CK_DECLARE_FUNCTION (C_DigestFinal,
1216 		      (ck_session_handle_t session,
1217 		       unsigned char *digest,
1218 		       unsigned long *digest_len));
1219 
1220 _CK_DECLARE_FUNCTION (C_SignInit,
1221 		      (ck_session_handle_t session,
1222 		       struct ck_mechanism *mechanism,
1223 		       ck_object_handle_t key));
1224 _CK_DECLARE_FUNCTION (C_Sign,
1225 		      (ck_session_handle_t session,
1226 		       unsigned char *data, unsigned long data_len,
1227 		       unsigned char *signature,
1228 		       unsigned long *signature_len));
1229 _CK_DECLARE_FUNCTION (C_SignUpdate,
1230 		      (ck_session_handle_t session,
1231 		       unsigned char *part, unsigned long part_len));
1232 _CK_DECLARE_FUNCTION (C_SignFinal,
1233 		      (ck_session_handle_t session,
1234 		       unsigned char *signature,
1235 		       unsigned long *signature_len));
1236 _CK_DECLARE_FUNCTION (C_SignRecoverInit,
1237 		      (ck_session_handle_t session,
1238 		       struct ck_mechanism *mechanism,
1239 		       ck_object_handle_t key));
1240 _CK_DECLARE_FUNCTION (C_SignRecover,
1241 		      (ck_session_handle_t session,
1242 		       unsigned char *data, unsigned long data_len,
1243 		       unsigned char *signature,
1244 		       unsigned long *signature_len));
1245 
1246 _CK_DECLARE_FUNCTION (C_VerifyInit,
1247 		      (ck_session_handle_t session,
1248 		       struct ck_mechanism *mechanism,
1249 		       ck_object_handle_t key));
1250 _CK_DECLARE_FUNCTION (C_Verify,
1251 		      (ck_session_handle_t session,
1252 		       unsigned char *data, unsigned long data_len,
1253 		       unsigned char *signature,
1254 		       unsigned long signature_len));
1255 _CK_DECLARE_FUNCTION (C_VerifyUpdate,
1256 		      (ck_session_handle_t session,
1257 		       unsigned char *part, unsigned long part_len));
1258 _CK_DECLARE_FUNCTION (C_VerifyFinal,
1259 		      (ck_session_handle_t session,
1260 		       unsigned char *signature,
1261 		       unsigned long signature_len));
1262 _CK_DECLARE_FUNCTION (C_VerifyRecoverInit,
1263 		      (ck_session_handle_t session,
1264 		       struct ck_mechanism *mechanism,
1265 		       ck_object_handle_t key));
1266 _CK_DECLARE_FUNCTION (C_VerifyRecover,
1267 		      (ck_session_handle_t session,
1268 		       unsigned char *signature,
1269 		       unsigned long signature_len,
1270 		       unsigned char *data,
1271 		       unsigned long *data_len));
1272 
1273 _CK_DECLARE_FUNCTION (C_DigestEncryptUpdate,
1274 		      (ck_session_handle_t session,
1275 		       unsigned char *part, unsigned long part_len,
1276 		       unsigned char *encrypted_part,
1277 		       unsigned long *encrypted_part_len));
1278 _CK_DECLARE_FUNCTION (C_DecryptDigestUpdate,
1279 		      (ck_session_handle_t session,
1280 		       unsigned char *encrypted_part,
1281 		       unsigned long encrypted_part_len,
1282 		       unsigned char *part,
1283 		       unsigned long *part_len));
1284 _CK_DECLARE_FUNCTION (C_SignEncryptUpdate,
1285 		      (ck_session_handle_t session,
1286 		       unsigned char *part, unsigned long part_len,
1287 		       unsigned char *encrypted_part,
1288 		       unsigned long *encrypted_part_len));
1289 _CK_DECLARE_FUNCTION (C_DecryptVerifyUpdate,
1290 		      (ck_session_handle_t session,
1291 		       unsigned char *encrypted_part,
1292 		       unsigned long encrypted_part_len,
1293 		       unsigned char *part,
1294 		       unsigned long *part_len));
1295 
1296 _CK_DECLARE_FUNCTION (C_GenerateKey,
1297 		      (ck_session_handle_t session,
1298 		       struct ck_mechanism *mechanism,
1299 		       struct ck_attribute *templ,
1300 		       unsigned long count,
1301 		       ck_object_handle_t *key));
1302 _CK_DECLARE_FUNCTION (C_GenerateKeyPair,
1303 		      (ck_session_handle_t session,
1304 		       struct ck_mechanism *mechanism,
1305 		       struct ck_attribute *public_key_template,
1306 		       unsigned long public_key_attribute_count,
1307 		       struct ck_attribute *private_key_template,
1308 		       unsigned long private_key_attribute_count,
1309 		       ck_object_handle_t *public_key,
1310 		       ck_object_handle_t *private_key));
1311 _CK_DECLARE_FUNCTION (C_WrapKey,
1312 		      (ck_session_handle_t session,
1313 		       struct ck_mechanism *mechanism,
1314 		       ck_object_handle_t wrapping_key,
1315 		       ck_object_handle_t key,
1316 		       unsigned char *wrapped_key,
1317 		       unsigned long *wrapped_key_len));
1318 _CK_DECLARE_FUNCTION (C_UnwrapKey,
1319 		      (ck_session_handle_t session,
1320 		       struct ck_mechanism *mechanism,
1321 		       ck_object_handle_t unwrapping_key,
1322 		       unsigned char *wrapped_key,
1323 		       unsigned long wrapped_key_len,
1324 		       struct ck_attribute *templ,
1325 		       unsigned long attribute_count,
1326 		       ck_object_handle_t *key));
1327 _CK_DECLARE_FUNCTION (C_DeriveKey,
1328 		      (ck_session_handle_t session,
1329 		       struct ck_mechanism *mechanism,
1330 		       ck_object_handle_t base_key,
1331 		       struct ck_attribute *templ,
1332 		       unsigned long attribute_count,
1333 		       ck_object_handle_t *key));
1334 
1335 _CK_DECLARE_FUNCTION (C_SeedRandom,
1336 		      (ck_session_handle_t session, unsigned char *seed,
1337 		       unsigned long seed_len));
1338 _CK_DECLARE_FUNCTION (C_GenerateRandom,
1339 		      (ck_session_handle_t session,
1340 		       unsigned char *random_data,
1341 		       unsigned long random_len));
1342 
1343 _CK_DECLARE_FUNCTION (C_GetFunctionStatus, (ck_session_handle_t session));
1344 _CK_DECLARE_FUNCTION (C_CancelFunction, (ck_session_handle_t session));
1345 
1346 
1347 struct ck_function_list
1348 {
1349   struct ck_version version;
1350   CK_C_Initialize C_Initialize;
1351   CK_C_Finalize C_Finalize;
1352   CK_C_GetInfo C_GetInfo;
1353   CK_C_GetFunctionList C_GetFunctionList;
1354   CK_C_GetSlotList C_GetSlotList;
1355   CK_C_GetSlotInfo C_GetSlotInfo;
1356   CK_C_GetTokenInfo C_GetTokenInfo;
1357   CK_C_GetMechanismList C_GetMechanismList;
1358   CK_C_GetMechanismInfo C_GetMechanismInfo;
1359   CK_C_InitToken C_InitToken;
1360   CK_C_InitPIN C_InitPIN;
1361   CK_C_SetPIN C_SetPIN;
1362   CK_C_OpenSession C_OpenSession;
1363   CK_C_CloseSession C_CloseSession;
1364   CK_C_CloseAllSessions C_CloseAllSessions;
1365   CK_C_GetSessionInfo C_GetSessionInfo;
1366   CK_C_GetOperationState C_GetOperationState;
1367   CK_C_SetOperationState C_SetOperationState;
1368   CK_C_Login C_Login;
1369   CK_C_Logout C_Logout;
1370   CK_C_CreateObject C_CreateObject;
1371   CK_C_CopyObject C_CopyObject;
1372   CK_C_DestroyObject C_DestroyObject;
1373   CK_C_GetObjectSize C_GetObjectSize;
1374   CK_C_GetAttributeValue C_GetAttributeValue;
1375   CK_C_SetAttributeValue C_SetAttributeValue;
1376   CK_C_FindObjectsInit C_FindObjectsInit;
1377   CK_C_FindObjects C_FindObjects;
1378   CK_C_FindObjectsFinal C_FindObjectsFinal;
1379   CK_C_EncryptInit C_EncryptInit;
1380   CK_C_Encrypt C_Encrypt;
1381   CK_C_EncryptUpdate C_EncryptUpdate;
1382   CK_C_EncryptFinal C_EncryptFinal;
1383   CK_C_DecryptInit C_DecryptInit;
1384   CK_C_Decrypt C_Decrypt;
1385   CK_C_DecryptUpdate C_DecryptUpdate;
1386   CK_C_DecryptFinal C_DecryptFinal;
1387   CK_C_DigestInit C_DigestInit;
1388   CK_C_Digest C_Digest;
1389   CK_C_DigestUpdate C_DigestUpdate;
1390   CK_C_DigestKey C_DigestKey;
1391   CK_C_DigestFinal C_DigestFinal;
1392   CK_C_SignInit C_SignInit;
1393   CK_C_Sign C_Sign;
1394   CK_C_SignUpdate C_SignUpdate;
1395   CK_C_SignFinal C_SignFinal;
1396   CK_C_SignRecoverInit C_SignRecoverInit;
1397   CK_C_SignRecover C_SignRecover;
1398   CK_C_VerifyInit C_VerifyInit;
1399   CK_C_Verify C_Verify;
1400   CK_C_VerifyUpdate C_VerifyUpdate;
1401   CK_C_VerifyFinal C_VerifyFinal;
1402   CK_C_VerifyRecoverInit C_VerifyRecoverInit;
1403   CK_C_VerifyRecover C_VerifyRecover;
1404   CK_C_DigestEncryptUpdate C_DigestEncryptUpdate;
1405   CK_C_DecryptDigestUpdate C_DecryptDigestUpdate;
1406   CK_C_SignEncryptUpdate C_SignEncryptUpdate;
1407   CK_C_DecryptVerifyUpdate C_DecryptVerifyUpdate;
1408   CK_C_GenerateKey C_GenerateKey;
1409   CK_C_GenerateKeyPair C_GenerateKeyPair;
1410   CK_C_WrapKey C_WrapKey;
1411   CK_C_UnwrapKey C_UnwrapKey;
1412   CK_C_DeriveKey C_DeriveKey;
1413   CK_C_SeedRandom C_SeedRandom;
1414   CK_C_GenerateRandom C_GenerateRandom;
1415   CK_C_GetFunctionStatus C_GetFunctionStatus;
1416   CK_C_CancelFunction C_CancelFunction;
1417   CK_C_WaitForSlotEvent C_WaitForSlotEvent;
1418 };
1419 
1420 
1421 typedef ck_rv_t (*ck_createmutex_t) (void **mutex);
1422 typedef ck_rv_t (*ck_destroymutex_t) (void *mutex);
1423 typedef ck_rv_t (*ck_lockmutex_t) (void *mutex);
1424 typedef ck_rv_t (*ck_unlockmutex_t) (void *mutex);
1425 
1426 
1427 struct ck_c_initialize_args
1428 {
1429   ck_createmutex_t create_mutex;
1430   ck_destroymutex_t destroy_mutex;
1431   ck_lockmutex_t lock_mutex;
1432   ck_unlockmutex_t unlock_mutex;
1433   ck_flags_t flags;
1434   void *reserved;
1435 };
1436 
1437 
1438 #define CKF_LIBRARY_CANT_CREATE_OS_THREADS	(1UL << 0)
1439 #define CKF_OS_LOCKING_OK			(1UL << 1)
1440 
1441 #define CKR_OK					(0UL)
1442 #define CKR_CANCEL				(1UL)
1443 #define CKR_HOST_MEMORY				(2UL)
1444 #define CKR_SLOT_ID_INVALID			(3UL)
1445 #define CKR_GENERAL_ERROR			(5UL)
1446 #define CKR_FUNCTION_FAILED			(6UL)
1447 #define CKR_ARGUMENTS_BAD			(7UL)
1448 #define CKR_NO_EVENT				(8UL)
1449 #define CKR_NEED_TO_CREATE_THREADS		(9UL)
1450 #define CKR_CANT_LOCK				(0xaUL)
1451 #define CKR_ATTRIBUTE_READ_ONLY			(0x10UL)
1452 #define CKR_ATTRIBUTE_SENSITIVE			(0x11UL)
1453 #define CKR_ATTRIBUTE_TYPE_INVALID		(0x12UL)
1454 #define CKR_ATTRIBUTE_VALUE_INVALID		(0x13UL)
1455 #define CKR_ACTION_PROHIBITED			(0x1BUL)
1456 #define CKR_DATA_INVALID			(0x20UL)
1457 #define CKR_DATA_LEN_RANGE			(0x21UL)
1458 #define CKR_DEVICE_ERROR			(0x30UL)
1459 #define CKR_DEVICE_MEMORY			(0x31UL)
1460 #define CKR_DEVICE_REMOVED			(0x32UL)
1461 #define CKR_ENCRYPTED_DATA_INVALID		(0x40UL)
1462 #define CKR_ENCRYPTED_DATA_LEN_RANGE		(0x41UL)
1463 #define CKR_FUNCTION_CANCELED			(0x50UL)
1464 #define CKR_FUNCTION_NOT_PARALLEL		(0x51UL)
1465 #define CKR_FUNCTION_NOT_SUPPORTED		(0x54UL)
1466 #define CKR_KEY_HANDLE_INVALID			(0x60UL)
1467 #define CKR_KEY_SIZE_RANGE			(0x62UL)
1468 #define CKR_KEY_TYPE_INCONSISTENT		(0x63UL)
1469 #define CKR_KEY_NOT_NEEDED			(0x64UL)
1470 #define CKR_KEY_CHANGED				(0x65UL)
1471 #define CKR_KEY_NEEDED				(0x66UL)
1472 #define CKR_KEY_INDIGESTIBLE			(0x67UL)
1473 #define CKR_KEY_FUNCTION_NOT_PERMITTED		(0x68UL)
1474 #define CKR_KEY_NOT_WRAPPABLE			(0x69UL)
1475 #define CKR_KEY_UNEXTRACTABLE			(0x6aUL)
1476 #define CKR_MECHANISM_INVALID			(0x70UL)
1477 #define CKR_MECHANISM_PARAM_INVALID		(0x71UL)
1478 #define CKR_OBJECT_HANDLE_INVALID		(0x82UL)
1479 #define CKR_OPERATION_ACTIVE			(0x90UL)
1480 #define CKR_OPERATION_NOT_INITIALIZED		(0x91UL)
1481 #define CKR_PIN_INCORRECT			(0xa0UL)
1482 #define CKR_PIN_INVALID				(0xa1UL)
1483 #define CKR_PIN_LEN_RANGE			(0xa2UL)
1484 #define CKR_PIN_EXPIRED				(0xa3UL)
1485 #define CKR_PIN_LOCKED				(0xa4UL)
1486 #define CKR_SESSION_CLOSED			(0xb0UL)
1487 #define CKR_SESSION_COUNT			(0xb1UL)
1488 #define CKR_SESSION_HANDLE_INVALID		(0xb3UL)
1489 #define CKR_SESSION_PARALLEL_NOT_SUPPORTED	(0xb4UL)
1490 #define CKR_SESSION_READ_ONLY			(0xb5UL)
1491 #define CKR_SESSION_EXISTS			(0xb6UL)
1492 #define CKR_SESSION_READ_ONLY_EXISTS		(0xb7UL)
1493 #define CKR_SESSION_READ_WRITE_SO_EXISTS	(0xb8UL)
1494 #define CKR_SIGNATURE_INVALID			(0xc0UL)
1495 #define CKR_SIGNATURE_LEN_RANGE			(0xc1UL)
1496 #define CKR_TEMPLATE_INCOMPLETE			(0xd0UL)
1497 #define CKR_TEMPLATE_INCONSISTENT		(0xd1UL)
1498 #define CKR_TOKEN_NOT_PRESENT			(0xe0UL)
1499 #define CKR_TOKEN_NOT_RECOGNIZED		(0xe1UL)
1500 #define CKR_TOKEN_WRITE_PROTECTED		(0xe2UL)
1501 #define	CKR_UNWRAPPING_KEY_HANDLE_INVALID	(0xf0UL)
1502 #define CKR_UNWRAPPING_KEY_SIZE_RANGE		(0xf1UL)
1503 #define CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT	(0xf2UL)
1504 #define CKR_USER_ALREADY_LOGGED_IN		(0x100UL)
1505 #define CKR_USER_NOT_LOGGED_IN			(0x101UL)
1506 #define CKR_USER_PIN_NOT_INITIALIZED		(0x102UL)
1507 #define CKR_USER_TYPE_INVALID			(0x103UL)
1508 #define CKR_USER_ANOTHER_ALREADY_LOGGED_IN	(0x104UL)
1509 #define CKR_USER_TOO_MANY_TYPES			(0x105UL)
1510 #define CKR_WRAPPED_KEY_INVALID			(0x110UL)
1511 #define CKR_WRAPPED_KEY_LEN_RANGE		(0x112UL)
1512 #define CKR_WRAPPING_KEY_HANDLE_INVALID		(0x113UL)
1513 #define CKR_WRAPPING_KEY_SIZE_RANGE		(0x114UL)
1514 #define CKR_WRAPPING_KEY_TYPE_INCONSISTENT	(0x115UL)
1515 #define CKR_RANDOM_SEED_NOT_SUPPORTED		(0x120UL)
1516 #define CKR_RANDOM_NO_RNG			(0x121UL)
1517 #define CKR_DOMAIN_PARAMS_INVALID		(0x130UL)
1518 #define CKR_CURVE_NOT_SUPPORTED			(0x140UL)
1519 #define CKR_BUFFER_TOO_SMALL			(0x150UL)
1520 #define CKR_SAVED_STATE_INVALID			(0x160UL)
1521 #define CKR_INFORMATION_SENSITIVE		(0x170UL)
1522 #define CKR_STATE_UNSAVEABLE			(0x180UL)
1523 #define CKR_CRYPTOKI_NOT_INITIALIZED		(0x190UL)
1524 #define CKR_CRYPTOKI_ALREADY_INITIALIZED	(0x191UL)
1525 #define CKR_MUTEX_BAD				(0x1a0UL)
1526 #define CKR_MUTEX_NOT_LOCKED			(0x1a1UL)
1527 #define CKR_NEW_PIN_MODE			(0x1b0UL)
1528 #define CKR_NEXT_OTP				(0x1b1UL)
1529 #define CKR_EXCEEDED_MAX_ITERATIONS		(0x1c0UL)
1530 #define CKR_FIPS_SELF_TEST_FAILED		(0x1c1UL)
1531 #define CKR_LIBRARY_LOAD_FAILED			(0x1c2UL)
1532 #define CKR_PIN_TOO_WEAK			(0x1c3UL)
1533 #define CKR_PUBLIC_KEY_INVALID			(0x1c4UL)
1534 #define CKR_FUNCTION_REJECTED			(0x200UL)
1535 #define CKR_VENDOR_DEFINED			((unsigned long) (1UL << 31))
1536 
1537 
1538 #define CKZ_DATA_SPECIFIED			(0x01UL)
1539 
1540 
1541 
1542 /* Compatibility layer.  */
1543 
1544 #ifdef CRYPTOKI_COMPAT
1545 
1546 #undef CK_DEFINE_FUNCTION
1547 #define CK_DEFINE_FUNCTION(retval, name) retval CK_SPEC name
1548 
1549 /* For NULL.  */
1550 #include <stddef.h>
1551 
1552 typedef unsigned char CK_BYTE;
1553 typedef unsigned char CK_CHAR;
1554 typedef unsigned char CK_UTF8CHAR;
1555 typedef unsigned char CK_BBOOL;
1556 typedef unsigned long int CK_ULONG;
1557 typedef long int CK_LONG;
1558 typedef CK_BYTE *CK_BYTE_PTR;
1559 typedef CK_CHAR *CK_CHAR_PTR;
1560 typedef CK_UTF8CHAR *CK_UTF8CHAR_PTR;
1561 typedef CK_ULONG *CK_ULONG_PTR;
1562 typedef void *CK_VOID_PTR;
1563 typedef void **CK_VOID_PTR_PTR;
1564 #define CK_FALSE 0
1565 #define CK_TRUE 1
1566 #ifndef CK_DISABLE_TRUE_FALSE
1567 #ifndef FALSE
1568 #define FALSE 0
1569 #endif
1570 #ifndef TRUE
1571 #define TRUE 1
1572 #endif
1573 #endif
1574 
1575 typedef struct ck_version CK_VERSION;
1576 typedef struct ck_version *CK_VERSION_PTR;
1577 
1578 typedef struct ck_info CK_INFO;
1579 typedef struct ck_info *CK_INFO_PTR;
1580 
1581 typedef ck_slot_id_t *CK_SLOT_ID_PTR;
1582 
1583 typedef struct ck_slot_info CK_SLOT_INFO;
1584 typedef struct ck_slot_info *CK_SLOT_INFO_PTR;
1585 
1586 typedef struct ck_token_info CK_TOKEN_INFO;
1587 typedef struct ck_token_info *CK_TOKEN_INFO_PTR;
1588 
1589 typedef ck_session_handle_t *CK_SESSION_HANDLE_PTR;
1590 
1591 typedef struct ck_session_info CK_SESSION_INFO;
1592 typedef struct ck_session_info *CK_SESSION_INFO_PTR;
1593 
1594 typedef ck_object_handle_t *CK_OBJECT_HANDLE_PTR;
1595 
1596 typedef ck_object_class_t *CK_OBJECT_CLASS_PTR;
1597 
1598 typedef struct ck_attribute CK_ATTRIBUTE;
1599 typedef struct ck_attribute *CK_ATTRIBUTE_PTR;
1600 
1601 typedef struct ck_date CK_DATE;
1602 typedef struct ck_date *CK_DATE_PTR;
1603 
1604 typedef ck_mechanism_type_t *CK_MECHANISM_TYPE_PTR;
1605 
1606 typedef struct ck_mechanism CK_MECHANISM;
1607 typedef struct ck_mechanism *CK_MECHANISM_PTR;
1608 
1609 typedef struct ck_mechanism_info CK_MECHANISM_INFO;
1610 typedef struct ck_mechanism_info *CK_MECHANISM_INFO_PTR;
1611 
1612 typedef struct ck_otp_mechanism_info CK_OTP_MECHANISM_INFO;
1613 typedef struct ck_otp_mechanism_info *CK_OTP_MECHANISM_INFO_PTR;
1614 
1615 typedef struct ck_function_list CK_FUNCTION_LIST;
1616 typedef struct ck_function_list *CK_FUNCTION_LIST_PTR;
1617 typedef struct ck_function_list **CK_FUNCTION_LIST_PTR_PTR;
1618 
1619 typedef struct ck_c_initialize_args CK_C_INITIALIZE_ARGS;
1620 typedef struct ck_c_initialize_args *CK_C_INITIALIZE_ARGS_PTR;
1621 
1622 typedef struct ck_rsa_pkcs_pss_params CK_RSA_PKCS_PSS_PARAMS;
1623 typedef struct ck_rsa_pkcs_pss_params *CK_RSA_PKCS_PSS_PARAMS_PTR;
1624 
1625 typedef struct ck_rsa_pkcs_oaep_params CK_RSA_PKCS_OAEP_PARAMS;
1626 typedef struct ck_rsa_pkcs_oaep_params *CK_RSA_PKCS_OAEP_PARAMS_PTR;
1627 
1628 typedef struct ck_aes_ctr_params CK_AES_CTR_PARAMS;
1629 typedef struct ck_aes_ctr_params *CK_AES_CTR_PARAMS_PTR;
1630 
1631 typedef struct ck_gcm_params CK_GCM_PARAMS;
1632 typedef struct ck_gcm_params *CK_GCM_PARAMS_PTR;
1633 
1634 typedef struct ck_ecdh1_derive_params CK_ECDH1_DERIVE_PARAMS;
1635 typedef struct ck_ecdh1_derive_params *CK_ECDH1_DERIVE_PARAMS_PTR;
1636 
1637 typedef struct ck_key_derivation_string_data CK_KEY_DERIVATION_STRING_DATA;
1638 typedef struct ck_key_derivation_string_data *CK_KEY_DERIVATION_STRING_DATA_PTR;
1639 
1640 typedef struct ck_des_cbc_encrypt_data_params CK_DES_CBC_ENCRYPT_DATA_PARAMS;
1641 typedef struct ck_des_cbc_encrypt_data_params *CK_DES_CBC_ENCRYPT_DATA_PARAMS_PTR;
1642 
1643 typedef struct ck_aes_cbc_encrypt_data_params CK_AES_CBC_ENCRYPT_DATA_PARAMS;
1644 typedef struct ck_aes_cbc_encrypt_data_params *CK_AES_CBC_ENCRYPT_DATA_PARAMS_PTR;
1645 
1646 #ifndef NULL_PTR
1647 #define NULL_PTR NULL
1648 #endif
1649 
1650 /* Delete the helper macros defined at the top of the file.  */
1651 #undef ck_flags_t
1652 #undef ck_version
1653 
1654 #undef ck_info
1655 #undef cryptoki_version
1656 #undef manufacturer_id
1657 #undef library_description
1658 #undef library_version
1659 
1660 #undef ck_notification_t
1661 #undef ck_slot_id_t
1662 
1663 #undef ck_slot_info
1664 #undef slot_description
1665 #undef hardware_version
1666 #undef firmware_version
1667 
1668 #undef ck_token_info
1669 #undef serial_number
1670 #undef max_session_count
1671 #undef session_count
1672 #undef max_rw_session_count
1673 #undef rw_session_count
1674 #undef max_pin_len
1675 #undef min_pin_len
1676 #undef total_public_memory
1677 #undef free_public_memory
1678 #undef total_private_memory
1679 #undef free_private_memory
1680 #undef utc_time
1681 
1682 #undef ck_session_handle_t
1683 #undef ck_user_type_t
1684 #undef ck_state_t
1685 
1686 #undef ck_session_info
1687 #undef slot_id
1688 #undef device_error
1689 
1690 #undef ck_object_handle_t
1691 #undef ck_object_class_t
1692 #undef ck_hw_feature_type_t
1693 #undef ck_key_type_t
1694 #undef ck_certificate_type_t
1695 #undef ck_attribute_type_t
1696 
1697 #undef ck_attribute
1698 #undef value
1699 #undef value_len
1700 
1701 #undef params
1702 #undef count
1703 
1704 #undef ck_date
1705 
1706 #undef ck_mechanism_type_t
1707 
1708 #undef ck_mechanism
1709 #undef parameter
1710 #undef parameter_len
1711 
1712 #undef ck_mechanism_info
1713 
1714 #undef ck_param_type
1715 #undef ck_otp_param
1716 #undef ck_otp_params
1717 #undef ck_otp_signature_info
1718 
1719 #undef min_key_size
1720 #undef max_key_size
1721 
1722 #undef ck_rv_t
1723 #undef ck_notify_t
1724 
1725 #undef ck_function_list
1726 
1727 #undef ck_createmutex_t
1728 #undef ck_destroymutex_t
1729 #undef ck_lockmutex_t
1730 #undef ck_unlockmutex_t
1731 
1732 #undef ck_c_initialize_args
1733 #undef create_mutex
1734 #undef destroy_mutex
1735 #undef lock_mutex
1736 #undef unlock_mutex
1737 #undef reserved
1738 
1739 #endif	/* CRYPTOKI_COMPAT */
1740 
1741 
1742 /* System dependencies.  */
1743 #if defined(_WIN32) || defined(CRYPTOKI_FORCE_WIN32)
1744 #pragma pack(pop, cryptoki)
1745 #endif
1746 
1747 #if defined(__cplusplus)
1748 }
1749 #endif
1750 
1751 #endif	/* PKCS11_H */
1752