1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 #include "pk11table.h"
6 
7 const char *_valueString[] = {
8     "None",
9     "Variable",
10     "CK_ULONG",
11     "Data",
12     "UTF8",
13     "CK_INFO",
14     "CK_SLOT_INFO",
15     "CK_TOKEN_INFO",
16     "CK_SESSION_INFO",
17     "CK_ATTRIBUTE",
18     "CK_MECHANISM",
19     "CK_MECHANISM_INFO",
20     "CK_C_INITIALIZE_ARGS",
21     "CK_FUNCTION_LIST"
22 };
23 
24 const char **valueString = &_valueString[0];
25 const int valueCount = sizeof(_valueString) / sizeof(_valueString[0]);
26 
27 const char *_constTypeString[] = {
28     "None",
29     "Bool",
30     "InfoFlags",
31     "SlotFlags",
32     "TokenFlags",
33     "SessionFlags",
34     "MechanismFlags",
35     "InitializeFlags",
36     "Users",
37     "SessionState",
38     "Object",
39     "Hardware",
40     "KeyType",
41     "CertificateType",
42     "Attribute",
43     "Mechanism",
44     "Result",
45     "Trust",
46     "AvailableSizes",
47     "CurrentSize"
48 };
49 
50 const char **constTypeString = &_constTypeString[0];
51 const int constTypeCount = sizeof(_constTypeString) / sizeof(_constTypeString[0]);
52 
53 #define mkEntry(x, t)              \
54     {                              \
55         #x, x, Const##t, ConstNone \
56     }
57 #define mkEntry2(x, t, t2)         \
58     {                              \
59         #x, x, Const##t, Const##t2 \
60     }
61 
62 const Constant _consts[] = {
63     mkEntry(CK_FALSE, Bool),
64     mkEntry(CK_TRUE, Bool),
65 
66     mkEntry(CKF_TOKEN_PRESENT, SlotFlags),
67     mkEntry(CKF_REMOVABLE_DEVICE, SlotFlags),
68     mkEntry(CKF_HW_SLOT, SlotFlags),
69 
70     mkEntry(CKF_RNG, TokenFlags),
71     mkEntry(CKF_WRITE_PROTECTED, TokenFlags),
72     mkEntry(CKF_LOGIN_REQUIRED, TokenFlags),
73     mkEntry(CKF_USER_PIN_INITIALIZED, TokenFlags),
74     mkEntry(CKF_RESTORE_KEY_NOT_NEEDED, TokenFlags),
75     mkEntry(CKF_CLOCK_ON_TOKEN, TokenFlags),
76     mkEntry(CKF_PROTECTED_AUTHENTICATION_PATH, TokenFlags),
77     mkEntry(CKF_DUAL_CRYPTO_OPERATIONS, TokenFlags),
78     mkEntry(CKF_TOKEN_INITIALIZED, TokenFlags),
79     mkEntry(CKF_SECONDARY_AUTHENTICATION, TokenFlags),
80     mkEntry(CKF_USER_PIN_COUNT_LOW, TokenFlags),
81     mkEntry(CKF_USER_PIN_FINAL_TRY, TokenFlags),
82     mkEntry(CKF_USER_PIN_LOCKED, TokenFlags),
83     mkEntry(CKF_USER_PIN_TO_BE_CHANGED, TokenFlags),
84     mkEntry(CKF_SO_PIN_COUNT_LOW, TokenFlags),
85     mkEntry(CKF_SO_PIN_FINAL_TRY, TokenFlags),
86     mkEntry(CKF_SO_PIN_LOCKED, TokenFlags),
87     mkEntry(CKF_SO_PIN_TO_BE_CHANGED, TokenFlags),
88 
89     mkEntry(CKF_RW_SESSION, SessionFlags),
90     mkEntry(CKF_SERIAL_SESSION, SessionFlags),
91 
92     mkEntry(CKF_HW, MechanismFlags),
93     mkEntry(CKF_ENCRYPT, MechanismFlags),
94     mkEntry(CKF_DECRYPT, MechanismFlags),
95     mkEntry(CKF_DIGEST, MechanismFlags),
96     mkEntry(CKF_SIGN, MechanismFlags),
97     mkEntry(CKF_SIGN_RECOVER, MechanismFlags),
98     mkEntry(CKF_VERIFY, MechanismFlags),
99     mkEntry(CKF_VERIFY_RECOVER, MechanismFlags),
100     mkEntry(CKF_GENERATE, MechanismFlags),
101     mkEntry(CKF_GENERATE_KEY_PAIR, MechanismFlags),
102     mkEntry(CKF_WRAP, MechanismFlags),
103     mkEntry(CKF_UNWRAP, MechanismFlags),
104     mkEntry(CKF_DERIVE, MechanismFlags),
105     mkEntry(CKF_EC_F_P, MechanismFlags),
106     mkEntry(CKF_EC_F_2M, MechanismFlags),
107     mkEntry(CKF_EC_ECPARAMETERS, MechanismFlags),
108     mkEntry(CKF_EC_NAMEDCURVE, MechanismFlags),
109     mkEntry(CKF_EC_UNCOMPRESS, MechanismFlags),
110     mkEntry(CKF_EC_COMPRESS, MechanismFlags),
111 
112     mkEntry(CKF_LIBRARY_CANT_CREATE_OS_THREADS, InitializeFlags),
113     mkEntry(CKF_OS_LOCKING_OK, InitializeFlags),
114 
115     mkEntry(CKU_SO, Users),
116     mkEntry(CKU_USER, Users),
117 
118     mkEntry(CKS_RO_PUBLIC_SESSION, SessionState),
119     mkEntry(CKS_RO_USER_FUNCTIONS, SessionState),
120     mkEntry(CKS_RW_PUBLIC_SESSION, SessionState),
121     mkEntry(CKS_RW_USER_FUNCTIONS, SessionState),
122     mkEntry(CKS_RW_SO_FUNCTIONS, SessionState),
123 
124     mkEntry(CKO_DATA, Object),
125     mkEntry(CKO_CERTIFICATE, Object),
126     mkEntry(CKO_PUBLIC_KEY, Object),
127     mkEntry(CKO_PRIVATE_KEY, Object),
128     mkEntry(CKO_SECRET_KEY, Object),
129     mkEntry(CKO_HW_FEATURE, Object),
130     mkEntry(CKO_DOMAIN_PARAMETERS, Object),
131     mkEntry(CKO_NSS_CRL, Object),
132     mkEntry(CKO_NSS_SMIME, Object),
133     mkEntry(CKO_NSS_TRUST, Object),
134     mkEntry(CKO_NSS_BUILTIN_ROOT_LIST, Object),
135 
136     mkEntry(CKH_MONOTONIC_COUNTER, Hardware),
137     mkEntry(CKH_CLOCK, Hardware),
138 
139     mkEntry(CKK_RSA, KeyType),
140     mkEntry(CKK_DSA, KeyType),
141     mkEntry(CKK_DH, KeyType),
142     mkEntry(CKK_ECDSA, KeyType),
143     mkEntry(CKK_EC, KeyType),
144     mkEntry(CKK_X9_42_DH, KeyType),
145     mkEntry(CKK_KEA, KeyType),
146     mkEntry(CKK_GENERIC_SECRET, KeyType),
147     mkEntry(CKK_RC2, KeyType),
148     mkEntry(CKK_RC4, KeyType),
149     mkEntry(CKK_DES, KeyType),
150     mkEntry(CKK_DES2, KeyType),
151     mkEntry(CKK_DES3, KeyType),
152     mkEntry(CKK_CAST, KeyType),
153     mkEntry(CKK_CAST3, KeyType),
154     mkEntry(CKK_CAST5, KeyType),
155     mkEntry(CKK_CAST128, KeyType),
156     mkEntry(CKK_RC5, KeyType),
157     mkEntry(CKK_IDEA, KeyType),
158     mkEntry(CKK_SKIPJACK, KeyType),
159     mkEntry(CKK_BATON, KeyType),
160     mkEntry(CKK_JUNIPER, KeyType),
161     mkEntry(CKK_CDMF, KeyType),
162     mkEntry(CKK_AES, KeyType),
163     mkEntry(CKK_CAMELLIA, KeyType),
164     mkEntry(CKK_NSS_PKCS8, KeyType),
165 
166     mkEntry(CKC_X_509, CertType),
167     mkEntry(CKC_X_509_ATTR_CERT, CertType),
168 
169     mkEntry2(CKA_CLASS, Attribute, Object),
170     mkEntry2(CKA_TOKEN, Attribute, Bool),
171     mkEntry2(CKA_PRIVATE, Attribute, Bool),
172     mkEntry2(CKA_LABEL, Attribute, None),
173     mkEntry2(CKA_APPLICATION, Attribute, None),
174     mkEntry2(CKA_VALUE, Attribute, None),
175     mkEntry2(CKA_OBJECT_ID, Attribute, None),
176     mkEntry2(CKA_CERTIFICATE_TYPE, Attribute, CertType),
177     mkEntry2(CKA_ISSUER, Attribute, None),
178     mkEntry2(CKA_SERIAL_NUMBER, Attribute, None),
179     mkEntry2(CKA_AC_ISSUER, Attribute, None),
180     mkEntry2(CKA_OWNER, Attribute, None),
181     mkEntry2(CKA_ATTR_TYPES, Attribute, None),
182     mkEntry2(CKA_TRUSTED, Attribute, Bool),
183     mkEntry2(CKA_KEY_TYPE, Attribute, KeyType),
184     mkEntry2(CKA_SUBJECT, Attribute, None),
185     mkEntry2(CKA_ID, Attribute, None),
186     mkEntry2(CKA_SENSITIVE, Attribute, Bool),
187     mkEntry2(CKA_ENCRYPT, Attribute, Bool),
188     mkEntry2(CKA_DECRYPT, Attribute, Bool),
189     mkEntry2(CKA_WRAP, Attribute, Bool),
190     mkEntry2(CKA_UNWRAP, Attribute, Bool),
191     mkEntry2(CKA_SIGN, Attribute, Bool),
192     mkEntry2(CKA_SIGN_RECOVER, Attribute, Bool),
193     mkEntry2(CKA_VERIFY, Attribute, Bool),
194     mkEntry2(CKA_VERIFY_RECOVER, Attribute, Bool),
195     mkEntry2(CKA_DERIVE, Attribute, Bool),
196     mkEntry2(CKA_START_DATE, Attribute, None),
197     mkEntry2(CKA_END_DATE, Attribute, None),
198     mkEntry2(CKA_MODULUS, Attribute, None),
199     mkEntry2(CKA_MODULUS_BITS, Attribute, None),
200     mkEntry2(CKA_PUBLIC_EXPONENT, Attribute, None),
201     mkEntry2(CKA_PRIVATE_EXPONENT, Attribute, None),
202     mkEntry2(CKA_PRIME_1, Attribute, None),
203     mkEntry2(CKA_PRIME_2, Attribute, None),
204     mkEntry2(CKA_EXPONENT_1, Attribute, None),
205     mkEntry2(CKA_EXPONENT_2, Attribute, None),
206     mkEntry2(CKA_COEFFICIENT, Attribute, None),
207     mkEntry2(CKA_PRIME, Attribute, None),
208     mkEntry2(CKA_SUBPRIME, Attribute, None),
209     mkEntry2(CKA_BASE, Attribute, None),
210     mkEntry2(CKA_PRIME_BITS, Attribute, None),
211     mkEntry2(CKA_SUB_PRIME_BITS, Attribute, None),
212     mkEntry2(CKA_VALUE_BITS, Attribute, None),
213     mkEntry2(CKA_VALUE_LEN, Attribute, None),
214     mkEntry2(CKA_EXTRACTABLE, Attribute, Bool),
215     mkEntry2(CKA_LOCAL, Attribute, Bool),
216     mkEntry2(CKA_NEVER_EXTRACTABLE, Attribute, Bool),
217     mkEntry2(CKA_ALWAYS_SENSITIVE, Attribute, Bool),
218     mkEntry2(CKA_KEY_GEN_MECHANISM, Attribute, Mechanism),
219     mkEntry2(CKA_MODIFIABLE, Attribute, Bool),
220     mkEntry2(CKA_ECDSA_PARAMS, Attribute, None),
221     mkEntry2(CKA_EC_PARAMS, Attribute, None),
222     mkEntry2(CKA_EC_POINT, Attribute, None),
223     mkEntry2(CKA_SECONDARY_AUTH, Attribute, None),
224     mkEntry2(CKA_AUTH_PIN_FLAGS, Attribute, None),
225     mkEntry2(CKA_HW_FEATURE_TYPE, Attribute, Hardware),
226     mkEntry2(CKA_RESET_ON_INIT, Attribute, Bool),
227     mkEntry2(CKA_HAS_RESET, Attribute, Bool),
228     mkEntry2(CKA_NSS_URL, Attribute, None),
229     mkEntry2(CKA_NSS_EMAIL, Attribute, None),
230     mkEntry2(CKA_NSS_SMIME_INFO, Attribute, None),
231     mkEntry2(CKA_NSS_SMIME_TIMESTAMP, Attribute, None),
232     mkEntry2(CKA_NSS_PKCS8_SALT, Attribute, None),
233     mkEntry2(CKA_NSS_PASSWORD_CHECK, Attribute, None),
234     mkEntry2(CKA_NSS_EXPIRES, Attribute, None),
235     mkEntry2(CKA_NSS_KRL, Attribute, None),
236     mkEntry2(CKA_NSS_PQG_COUNTER, Attribute, None),
237     mkEntry2(CKA_NSS_PQG_SEED, Attribute, None),
238     mkEntry2(CKA_NSS_PQG_H, Attribute, None),
239     mkEntry2(CKA_NSS_PQG_SEED_BITS, Attribute, None),
240     mkEntry2(CKA_TRUST_DIGITAL_SIGNATURE, Attribute, Trust),
241     mkEntry2(CKA_TRUST_NON_REPUDIATION, Attribute, Trust),
242     mkEntry2(CKA_TRUST_KEY_ENCIPHERMENT, Attribute, Trust),
243     mkEntry2(CKA_TRUST_DATA_ENCIPHERMENT, Attribute, Trust),
244     mkEntry2(CKA_TRUST_KEY_AGREEMENT, Attribute, Trust),
245     mkEntry2(CKA_TRUST_KEY_CERT_SIGN, Attribute, Trust),
246     mkEntry2(CKA_TRUST_CRL_SIGN, Attribute, Trust),
247     mkEntry2(CKA_TRUST_SERVER_AUTH, Attribute, Trust),
248     mkEntry2(CKA_TRUST_CLIENT_AUTH, Attribute, Trust),
249     mkEntry2(CKA_TRUST_CODE_SIGNING, Attribute, Trust),
250     mkEntry2(CKA_TRUST_EMAIL_PROTECTION, Attribute, Trust),
251     mkEntry2(CKA_TRUST_IPSEC_END_SYSTEM, Attribute, Trust),
252     mkEntry2(CKA_TRUST_IPSEC_TUNNEL, Attribute, Trust),
253     mkEntry2(CKA_TRUST_IPSEC_USER, Attribute, Trust),
254     mkEntry2(CKA_TRUST_TIME_STAMPING, Attribute, Trust),
255     mkEntry2(CKA_CERT_SHA1_HASH, Attribute, None),
256     mkEntry2(CKA_CERT_MD5_HASH, Attribute, None),
257     mkEntry2(CKA_NSS_DB, Attribute, None),
258     mkEntry2(CKA_NSS_TRUST, Attribute, Trust),
259 
260     mkEntry(CKM_RSA_PKCS, Mechanism),
261     mkEntry(CKM_RSA_9796, Mechanism),
262     mkEntry(CKM_RSA_X_509, Mechanism),
263     mkEntry(CKM_RSA_PKCS_KEY_PAIR_GEN, Mechanism),
264     mkEntry(CKM_MD2_RSA_PKCS, Mechanism),
265     mkEntry(CKM_MD5_RSA_PKCS, Mechanism),
266     mkEntry(CKM_SHA1_RSA_PKCS, Mechanism),
267     mkEntry(CKM_RIPEMD128_RSA_PKCS, Mechanism),
268     mkEntry(CKM_RIPEMD160_RSA_PKCS, Mechanism),
269     mkEntry(CKM_RSA_PKCS_OAEP, Mechanism),
270     mkEntry(CKM_RSA_X9_31_KEY_PAIR_GEN, Mechanism),
271     mkEntry(CKM_RSA_X9_31, Mechanism),
272     mkEntry(CKM_SHA1_RSA_X9_31, Mechanism),
273     mkEntry(CKM_DSA_KEY_PAIR_GEN, Mechanism),
274     mkEntry(CKM_DSA, Mechanism),
275     mkEntry(CKM_DSA_SHA1, Mechanism),
276     mkEntry(CKM_DH_PKCS_KEY_PAIR_GEN, Mechanism),
277     mkEntry(CKM_DH_PKCS_DERIVE, Mechanism),
278     mkEntry(CKM_X9_42_DH_DERIVE, Mechanism),
279     mkEntry(CKM_X9_42_DH_HYBRID_DERIVE, Mechanism),
280     mkEntry(CKM_X9_42_MQV_DERIVE, Mechanism),
281     mkEntry(CKM_SHA256_RSA_PKCS, Mechanism),
282     mkEntry(CKM_SHA384_RSA_PKCS, Mechanism),
283     mkEntry(CKM_SHA512_RSA_PKCS, Mechanism),
284     mkEntry(CKM_RC2_KEY_GEN, Mechanism),
285     mkEntry(CKM_RC2_ECB, Mechanism),
286     mkEntry(CKM_RC2_CBC, Mechanism),
287     mkEntry(CKM_RC2_MAC, Mechanism),
288     mkEntry(CKM_RC2_MAC_GENERAL, Mechanism),
289     mkEntry(CKM_RC2_CBC_PAD, Mechanism),
290     mkEntry(CKM_RC4_KEY_GEN, Mechanism),
291     mkEntry(CKM_RC4, Mechanism),
292     mkEntry(CKM_DES_KEY_GEN, Mechanism),
293     mkEntry(CKM_DES_ECB, Mechanism),
294     mkEntry(CKM_DES_CBC, Mechanism),
295     mkEntry(CKM_DES_MAC, Mechanism),
296     mkEntry(CKM_DES_MAC_GENERAL, Mechanism),
297     mkEntry(CKM_DES_CBC_PAD, Mechanism),
298     mkEntry(CKM_DES2_KEY_GEN, Mechanism),
299     mkEntry(CKM_DES3_KEY_GEN, Mechanism),
300     mkEntry(CKM_DES3_ECB, Mechanism),
301     mkEntry(CKM_DES3_CBC, Mechanism),
302     mkEntry(CKM_DES3_MAC, Mechanism),
303     mkEntry(CKM_DES3_MAC_GENERAL, Mechanism),
304     mkEntry(CKM_DES3_CBC_PAD, Mechanism),
305     mkEntry(CKM_CDMF_KEY_GEN, Mechanism),
306     mkEntry(CKM_CDMF_ECB, Mechanism),
307     mkEntry(CKM_CDMF_CBC, Mechanism),
308     mkEntry(CKM_CDMF_MAC, Mechanism),
309     mkEntry(CKM_CDMF_MAC_GENERAL, Mechanism),
310     mkEntry(CKM_CDMF_CBC_PAD, Mechanism),
311     mkEntry(CKM_MD2, Mechanism),
312     mkEntry(CKM_MD2_HMAC, Mechanism),
313     mkEntry(CKM_MD2_HMAC_GENERAL, Mechanism),
314     mkEntry(CKM_MD5, Mechanism),
315     mkEntry(CKM_MD5_HMAC, Mechanism),
316     mkEntry(CKM_MD5_HMAC_GENERAL, Mechanism),
317     mkEntry(CKM_SHA_1, Mechanism),
318     mkEntry(CKM_SHA_1_HMAC, Mechanism),
319     mkEntry(CKM_SHA_1_HMAC_GENERAL, Mechanism),
320     mkEntry(CKM_RIPEMD128, Mechanism),
321     mkEntry(CKM_RIPEMD128_HMAC, Mechanism),
322     mkEntry(CKM_RIPEMD128_HMAC_GENERAL, Mechanism),
323     mkEntry(CKM_RIPEMD160, Mechanism),
324     mkEntry(CKM_RIPEMD160_HMAC, Mechanism),
325     mkEntry(CKM_RIPEMD160_HMAC_GENERAL, Mechanism),
326     mkEntry(CKM_SHA256, Mechanism),
327     mkEntry(CKM_SHA256_HMAC_GENERAL, Mechanism),
328     mkEntry(CKM_SHA256_HMAC, Mechanism),
329     mkEntry(CKM_SHA384, Mechanism),
330     mkEntry(CKM_SHA384_HMAC_GENERAL, Mechanism),
331     mkEntry(CKM_SHA384_HMAC, Mechanism),
332     mkEntry(CKM_SHA512, Mechanism),
333     mkEntry(CKM_SHA512_HMAC_GENERAL, Mechanism),
334     mkEntry(CKM_SHA512_HMAC, Mechanism),
335     mkEntry(CKM_AES_CMAC, Mechanism),
336     mkEntry(CKM_AES_CMAC_GENERAL, Mechanism),
337     mkEntry(CKM_CAST_KEY_GEN, Mechanism),
338     mkEntry(CKM_CAST_ECB, Mechanism),
339     mkEntry(CKM_CAST_CBC, Mechanism),
340     mkEntry(CKM_CAST_MAC, Mechanism),
341     mkEntry(CKM_CAST_MAC_GENERAL, Mechanism),
342     mkEntry(CKM_CAST_CBC_PAD, Mechanism),
343     mkEntry(CKM_CAST3_KEY_GEN, Mechanism),
344     mkEntry(CKM_CAST3_ECB, Mechanism),
345     mkEntry(CKM_CAST3_CBC, Mechanism),
346     mkEntry(CKM_CAST3_MAC, Mechanism),
347     mkEntry(CKM_CAST3_MAC_GENERAL, Mechanism),
348     mkEntry(CKM_CAST3_CBC_PAD, Mechanism),
349     mkEntry(CKM_CAST5_KEY_GEN, Mechanism),
350     mkEntry(CKM_CAST128_KEY_GEN, Mechanism),
351     mkEntry(CKM_CAST5_ECB, Mechanism),
352     mkEntry(CKM_CAST128_ECB, Mechanism),
353     mkEntry(CKM_CAST5_CBC, Mechanism),
354     mkEntry(CKM_CAST128_CBC, Mechanism),
355     mkEntry(CKM_CAST5_MAC, Mechanism),
356     mkEntry(CKM_CAST128_MAC, Mechanism),
357     mkEntry(CKM_CAST5_MAC_GENERAL, Mechanism),
358     mkEntry(CKM_CAST128_MAC_GENERAL, Mechanism),
359     mkEntry(CKM_CAST5_CBC_PAD, Mechanism),
360     mkEntry(CKM_CAST128_CBC_PAD, Mechanism),
361     mkEntry(CKM_RC5_KEY_GEN, Mechanism),
362     mkEntry(CKM_RC5_ECB, Mechanism),
363     mkEntry(CKM_RC5_CBC, Mechanism),
364     mkEntry(CKM_RC5_MAC, Mechanism),
365     mkEntry(CKM_RC5_MAC_GENERAL, Mechanism),
366     mkEntry(CKM_RC5_CBC_PAD, Mechanism),
367     mkEntry(CKM_IDEA_KEY_GEN, Mechanism),
368     mkEntry(CKM_IDEA_ECB, Mechanism),
369     mkEntry(CKM_IDEA_CBC, Mechanism),
370     mkEntry(CKM_IDEA_MAC, Mechanism),
371     mkEntry(CKM_IDEA_MAC_GENERAL, Mechanism),
372     mkEntry(CKM_IDEA_CBC_PAD, Mechanism),
373     mkEntry(CKM_GENERIC_SECRET_KEY_GEN, Mechanism),
374     mkEntry(CKM_CONCATENATE_BASE_AND_KEY, Mechanism),
375     mkEntry(CKM_CONCATENATE_BASE_AND_DATA, Mechanism),
376     mkEntry(CKM_CONCATENATE_DATA_AND_BASE, Mechanism),
377     mkEntry(CKM_XOR_BASE_AND_DATA, Mechanism),
378     mkEntry(CKM_EXTRACT_KEY_FROM_KEY, Mechanism),
379     mkEntry(CKM_SSL3_PRE_MASTER_KEY_GEN, Mechanism),
380     mkEntry(CKM_SSL3_MASTER_KEY_DERIVE, Mechanism),
381     mkEntry(CKM_SSL3_KEY_AND_MAC_DERIVE, Mechanism),
382     mkEntry(CKM_SSL3_MASTER_KEY_DERIVE_DH, Mechanism),
383     mkEntry(CKM_TLS_PRE_MASTER_KEY_GEN, Mechanism),
384     mkEntry(CKM_TLS_MASTER_KEY_DERIVE, Mechanism),
385     mkEntry(CKM_NSS_TLS_MASTER_KEY_DERIVE_SHA256, Mechanism),
386     mkEntry(CKM_TLS_KEY_AND_MAC_DERIVE, Mechanism),
387     mkEntry(CKM_NSS_TLS_KEY_AND_MAC_DERIVE_SHA256, Mechanism),
388     mkEntry(CKM_TLS_MASTER_KEY_DERIVE_DH, Mechanism),
389     mkEntry(CKM_NSS_TLS_MASTER_KEY_DERIVE_DH_SHA256, Mechanism),
390     mkEntry(CKM_SSL3_MD5_MAC, Mechanism),
391     mkEntry(CKM_SSL3_SHA1_MAC, Mechanism),
392     mkEntry(CKM_MD5_KEY_DERIVATION, Mechanism),
393     mkEntry(CKM_MD2_KEY_DERIVATION, Mechanism),
394     mkEntry(CKM_SHA1_KEY_DERIVATION, Mechanism),
395     mkEntry(CKM_SHA256_KEY_DERIVATION, Mechanism),
396     mkEntry(CKM_SHA384_KEY_DERIVATION, Mechanism),
397     mkEntry(CKM_SHA512_KEY_DERIVATION, Mechanism),
398     mkEntry(CKM_PBE_MD2_DES_CBC, Mechanism),
399     mkEntry(CKM_PBE_MD5_DES_CBC, Mechanism),
400     mkEntry(CKM_PBE_MD5_CAST_CBC, Mechanism),
401     mkEntry(CKM_PBE_MD5_CAST3_CBC, Mechanism),
402     mkEntry(CKM_PBE_MD5_CAST5_CBC, Mechanism),
403     mkEntry(CKM_PBE_MD5_CAST128_CBC, Mechanism),
404     mkEntry(CKM_PBE_SHA1_CAST5_CBC, Mechanism),
405     mkEntry(CKM_PBE_SHA1_CAST128_CBC, Mechanism),
406     mkEntry(CKM_PBE_SHA1_RC4_128, Mechanism),
407     mkEntry(CKM_PBE_SHA1_RC4_40, Mechanism),
408     mkEntry(CKM_PBE_SHA1_DES3_EDE_CBC, Mechanism),
409     mkEntry(CKM_PBE_SHA1_DES2_EDE_CBC, Mechanism),
410     mkEntry(CKM_PBE_SHA1_RC2_128_CBC, Mechanism),
411     mkEntry(CKM_PBE_SHA1_RC2_40_CBC, Mechanism),
412     mkEntry(CKM_PKCS5_PBKD2, Mechanism),
413     mkEntry(CKM_PBA_SHA1_WITH_SHA1_HMAC, Mechanism),
414     mkEntry(CKM_KEY_WRAP_LYNKS, Mechanism),
415     mkEntry(CKM_KEY_WRAP_SET_OAEP, Mechanism),
416     mkEntry(CKM_SKIPJACK_KEY_GEN, Mechanism),
417     mkEntry(CKM_SKIPJACK_ECB64, Mechanism),
418     mkEntry(CKM_SKIPJACK_CBC64, Mechanism),
419     mkEntry(CKM_SKIPJACK_OFB64, Mechanism),
420     mkEntry(CKM_SKIPJACK_CFB64, Mechanism),
421     mkEntry(CKM_SKIPJACK_CFB32, Mechanism),
422     mkEntry(CKM_SKIPJACK_CFB16, Mechanism),
423     mkEntry(CKM_SKIPJACK_CFB8, Mechanism),
424     mkEntry(CKM_SKIPJACK_WRAP, Mechanism),
425     mkEntry(CKM_SKIPJACK_PRIVATE_WRAP, Mechanism),
426     mkEntry(CKM_SKIPJACK_RELAYX, Mechanism),
427     mkEntry(CKM_KEA_KEY_PAIR_GEN, Mechanism),
428     mkEntry(CKM_KEA_KEY_DERIVE, Mechanism),
429     mkEntry(CKM_FORTEZZA_TIMESTAMP, Mechanism),
430     mkEntry(CKM_BATON_KEY_GEN, Mechanism),
431     mkEntry(CKM_BATON_ECB128, Mechanism),
432     mkEntry(CKM_BATON_ECB96, Mechanism),
433     mkEntry(CKM_BATON_CBC128, Mechanism),
434     mkEntry(CKM_BATON_COUNTER, Mechanism),
435     mkEntry(CKM_BATON_SHUFFLE, Mechanism),
436     mkEntry(CKM_BATON_WRAP, Mechanism),
437     mkEntry(CKM_ECDSA_KEY_PAIR_GEN, Mechanism),
438     mkEntry(CKM_EC_KEY_PAIR_GEN, Mechanism),
439     mkEntry(CKM_ECDSA, Mechanism),
440     mkEntry(CKM_ECDSA_SHA1, Mechanism),
441     mkEntry(CKM_ECDH1_DERIVE, Mechanism),
442     mkEntry(CKM_ECDH1_COFACTOR_DERIVE, Mechanism),
443     mkEntry(CKM_ECMQV_DERIVE, Mechanism),
444     mkEntry(CKM_JUNIPER_KEY_GEN, Mechanism),
445     mkEntry(CKM_JUNIPER_ECB128, Mechanism),
446     mkEntry(CKM_JUNIPER_CBC128, Mechanism),
447     mkEntry(CKM_JUNIPER_COUNTER, Mechanism),
448     mkEntry(CKM_JUNIPER_SHUFFLE, Mechanism),
449     mkEntry(CKM_JUNIPER_WRAP, Mechanism),
450     mkEntry(CKM_FASTHASH, Mechanism),
451     mkEntry(CKM_AES_KEY_GEN, Mechanism),
452     mkEntry(CKM_AES_ECB, Mechanism),
453     mkEntry(CKM_AES_CBC, Mechanism),
454     mkEntry(CKM_AES_MAC, Mechanism),
455     mkEntry(CKM_AES_MAC_GENERAL, Mechanism),
456     mkEntry(CKM_AES_CBC_PAD, Mechanism),
457     mkEntry(CKM_CAMELLIA_KEY_GEN, Mechanism),
458     mkEntry(CKM_CAMELLIA_ECB, Mechanism),
459     mkEntry(CKM_CAMELLIA_CBC, Mechanism),
460     mkEntry(CKM_CAMELLIA_MAC, Mechanism),
461     mkEntry(CKM_CAMELLIA_MAC_GENERAL, Mechanism),
462     mkEntry(CKM_CAMELLIA_CBC_PAD, Mechanism),
463     mkEntry(CKM_SEED_KEY_GEN, Mechanism),
464     mkEntry(CKM_SEED_ECB, Mechanism),
465     mkEntry(CKM_SEED_CBC, Mechanism),
466     mkEntry(CKM_SEED_MAC, Mechanism),
467     mkEntry(CKM_SEED_MAC_GENERAL, Mechanism),
468     mkEntry(CKM_SEED_CBC_PAD, Mechanism),
469     mkEntry(CKM_SEED_ECB_ENCRYPT_DATA, Mechanism),
470     mkEntry(CKM_SEED_CBC_ENCRYPT_DATA, Mechanism),
471     mkEntry(CKM_DSA_PARAMETER_GEN, Mechanism),
472     mkEntry(CKM_DH_PKCS_PARAMETER_GEN, Mechanism),
473     mkEntry(CKM_NSS_AES_KEY_WRAP, Mechanism),
474     mkEntry(CKM_NSS_AES_KEY_WRAP_PAD, Mechanism),
475     mkEntry(CKM_NSS_PBE_SHA1_DES_CBC, Mechanism),
476     mkEntry(CKM_NSS_PBE_SHA1_TRIPLE_DES_CBC, Mechanism),
477     mkEntry(CKM_NSS_PBE_SHA1_40_BIT_RC2_CBC, Mechanism),
478     mkEntry(CKM_NSS_PBE_SHA1_128_BIT_RC2_CBC, Mechanism),
479     mkEntry(CKM_NSS_PBE_SHA1_40_BIT_RC4, Mechanism),
480     mkEntry(CKM_NSS_PBE_SHA1_128_BIT_RC4, Mechanism),
481     mkEntry(CKM_NSS_PBE_SHA1_FAULTY_3DES_CBC, Mechanism),
482     mkEntry(CKM_NSS_PBE_SHA1_HMAC_KEY_GEN, Mechanism),
483     mkEntry(CKM_NSS_PBE_MD5_HMAC_KEY_GEN, Mechanism),
484     mkEntry(CKM_NSS_PBE_MD2_HMAC_KEY_GEN, Mechanism),
485     mkEntry(CKM_TLS_PRF_GENERAL, Mechanism),
486     mkEntry(CKM_NSS_TLS_PRF_GENERAL_SHA256, Mechanism),
487 
488     mkEntry(CKR_OK, Result),
489     mkEntry(CKR_CANCEL, Result),
490     mkEntry(CKR_HOST_MEMORY, Result),
491     mkEntry(CKR_SLOT_ID_INVALID, Result),
492     mkEntry(CKR_GENERAL_ERROR, Result),
493     mkEntry(CKR_FUNCTION_FAILED, Result),
494     mkEntry(CKR_ARGUMENTS_BAD, Result),
495     mkEntry(CKR_NO_EVENT, Result),
496     mkEntry(CKR_NEED_TO_CREATE_THREADS, Result),
497     mkEntry(CKR_CANT_LOCK, Result),
498     mkEntry(CKR_ATTRIBUTE_READ_ONLY, Result),
499     mkEntry(CKR_ATTRIBUTE_SENSITIVE, Result),
500     mkEntry(CKR_ATTRIBUTE_TYPE_INVALID, Result),
501     mkEntry(CKR_ATTRIBUTE_VALUE_INVALID, Result),
502     mkEntry(CKR_DATA_INVALID, Result),
503     mkEntry(CKR_DATA_LEN_RANGE, Result),
504     mkEntry(CKR_DEVICE_ERROR, Result),
505     mkEntry(CKR_DEVICE_MEMORY, Result),
506     mkEntry(CKR_DEVICE_REMOVED, Result),
507     mkEntry(CKR_ENCRYPTED_DATA_INVALID, Result),
508     mkEntry(CKR_ENCRYPTED_DATA_LEN_RANGE, Result),
509     mkEntry(CKR_FUNCTION_CANCELED, Result),
510     mkEntry(CKR_FUNCTION_NOT_PARALLEL, Result),
511     mkEntry(CKR_FUNCTION_NOT_SUPPORTED, Result),
512     mkEntry(CKR_KEY_HANDLE_INVALID, Result),
513     mkEntry(CKR_KEY_SIZE_RANGE, Result),
514     mkEntry(CKR_KEY_TYPE_INCONSISTENT, Result),
515     mkEntry(CKR_KEY_NOT_NEEDED, Result),
516     mkEntry(CKR_KEY_CHANGED, Result),
517     mkEntry(CKR_KEY_NEEDED, Result),
518     mkEntry(CKR_KEY_INDIGESTIBLE, Result),
519     mkEntry(CKR_KEY_FUNCTION_NOT_PERMITTED, Result),
520     mkEntry(CKR_KEY_NOT_WRAPPABLE, Result),
521     mkEntry(CKR_KEY_UNEXTRACTABLE, Result),
522     mkEntry(CKR_MECHANISM_INVALID, Result),
523     mkEntry(CKR_MECHANISM_PARAM_INVALID, Result),
524     mkEntry(CKR_OBJECT_HANDLE_INVALID, Result),
525     mkEntry(CKR_OPERATION_ACTIVE, Result),
526     mkEntry(CKR_OPERATION_NOT_INITIALIZED, Result),
527     mkEntry(CKR_PIN_INCORRECT, Result),
528     mkEntry(CKR_PIN_INVALID, Result),
529     mkEntry(CKR_PIN_LEN_RANGE, Result),
530     mkEntry(CKR_PIN_EXPIRED, Result),
531     mkEntry(CKR_PIN_LOCKED, Result),
532     mkEntry(CKR_SESSION_CLOSED, Result),
533     mkEntry(CKR_SESSION_COUNT, Result),
534     mkEntry(CKR_SESSION_HANDLE_INVALID, Result),
535     mkEntry(CKR_SESSION_PARALLEL_NOT_SUPPORTED, Result),
536     mkEntry(CKR_SESSION_READ_ONLY, Result),
537     mkEntry(CKR_SESSION_EXISTS, Result),
538     mkEntry(CKR_SESSION_READ_ONLY_EXISTS, Result),
539     mkEntry(CKR_SESSION_READ_WRITE_SO_EXISTS, Result),
540     mkEntry(CKR_SIGNATURE_INVALID, Result),
541     mkEntry(CKR_SIGNATURE_LEN_RANGE, Result),
542     mkEntry(CKR_TEMPLATE_INCOMPLETE, Result),
543     mkEntry(CKR_TEMPLATE_INCONSISTENT, Result),
544     mkEntry(CKR_TOKEN_NOT_PRESENT, Result),
545     mkEntry(CKR_TOKEN_NOT_RECOGNIZED, Result),
546     mkEntry(CKR_TOKEN_WRITE_PROTECTED, Result),
547     mkEntry(CKR_UNWRAPPING_KEY_HANDLE_INVALID, Result),
548     mkEntry(CKR_UNWRAPPING_KEY_SIZE_RANGE, Result),
549     mkEntry(CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT, Result),
550     mkEntry(CKR_USER_ALREADY_LOGGED_IN, Result),
551     mkEntry(CKR_USER_NOT_LOGGED_IN, Result),
552     mkEntry(CKR_USER_PIN_NOT_INITIALIZED, Result),
553     mkEntry(CKR_USER_TYPE_INVALID, Result),
554     mkEntry(CKR_USER_ANOTHER_ALREADY_LOGGED_IN, Result),
555     mkEntry(CKR_USER_TOO_MANY_TYPES, Result),
556     mkEntry(CKR_WRAPPED_KEY_INVALID, Result),
557     mkEntry(CKR_WRAPPED_KEY_LEN_RANGE, Result),
558     mkEntry(CKR_WRAPPING_KEY_HANDLE_INVALID, Result),
559     mkEntry(CKR_WRAPPING_KEY_SIZE_RANGE, Result),
560     mkEntry(CKR_WRAPPING_KEY_TYPE_INCONSISTENT, Result),
561     mkEntry(CKR_RANDOM_SEED_NOT_SUPPORTED, Result),
562     mkEntry(CKR_RANDOM_NO_RNG, Result),
563     mkEntry(CKR_DOMAIN_PARAMS_INVALID, Result),
564     mkEntry(CKR_BUFFER_TOO_SMALL, Result),
565     mkEntry(CKR_SAVED_STATE_INVALID, Result),
566     mkEntry(CKR_INFORMATION_SENSITIVE, Result),
567     mkEntry(CKR_STATE_UNSAVEABLE, Result),
568     mkEntry(CKR_CRYPTOKI_NOT_INITIALIZED, Result),
569     mkEntry(CKR_CRYPTOKI_ALREADY_INITIALIZED, Result),
570     mkEntry(CKR_MUTEX_BAD, Result),
571     mkEntry(CKR_MUTEX_NOT_LOCKED, Result),
572     mkEntry(CKR_VENDOR_DEFINED, Result),
573 
574     mkEntry(CKT_NSS_TRUSTED, Trust),
575     mkEntry(CKT_NSS_TRUSTED_DELEGATOR, Trust),
576     mkEntry(CKT_NSS_NOT_TRUSTED, Trust),
577     mkEntry(CKT_NSS_MUST_VERIFY_TRUST, Trust),
578     mkEntry(CKT_NSS_TRUST_UNKNOWN, Trust),
579     mkEntry(CKT_NSS_VALID_DELEGATOR, Trust),
580 
581     mkEntry(CK_EFFECTIVELY_INFINITE, AvailableSizes),
582     mkEntry(CK_UNAVAILABLE_INFORMATION, CurrentSize),
583 };
584 
585 const Constant *consts = &_consts[0];
586 const unsigned int constCount = sizeof(_consts) / sizeof(_consts[0]);
587 
588 const Commands _commands[] = {
589     { "C_Initialize",
590       F_C_Initialize,
591       "C_Initialize pInitArgs\n\n"
592       "C_Initialize initializes the PKCS #11 library.\n"
593       "  pInitArgs  if this is not NULL_PTR it gets cast to and dereferenced\n",
594       { ArgInitializeArgs, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
595         ArgNone, ArgNone } },
596     { "C_Finalize",
597       F_C_Finalize,
598       "C_Finalize pReserved\n\n"
599       "C_Finalize indicates that an application is done with the PKCS #11 library.\n"
600       " pReserved  reserved. Should be NULL_PTR\n",
601       { ArgInitializeArgs, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
602         ArgNone, ArgNone } },
603     { "C_GetInfo",
604       F_C_GetInfo,
605       "C_GetInfo pInfo\n\n"
606       "C_GetInfo returns general information about PKCS #11.\n"
607       " pInfo   location that receives information\n",
608       { ArgInfo | ArgOut, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
609         ArgNone, ArgNone } },
610     { "C_GetFunctionList",
611       F_C_GetFunctionList,
612       "C_GetFunctionList ppFunctionList\n\n"
613       "C_GetFunctionList returns the function list.\n"
614       " ppFunctionList   receives pointer to function list\n",
615       { ArgFunctionList | ArgOut, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
616         ArgNone, ArgNone, ArgNone } },
617     { "C_GetSlotList",
618       F_C_GetSlotList,
619       "C_GetSlotList tokenPresent pSlotList pulCount\n\n"
620       "C_GetSlotList obtains a list of slots in the system.\n"
621       " tokenPresent    only slots with tokens?\n"
622       " pSlotList       receives array of slot IDs\n"
623       " pulCount        receives number of slots\n",
624       { ArgULong, ArgULong | ArgArray | ArgOut, ArgULong | ArgOut, ArgNone, ArgNone,
625         ArgNone, ArgNone, ArgNone, ArgNone, ArgNone } },
626     { "C_GetSlotInfo",
627       F_C_GetSlotInfo,
628       "C_GetSlotInfo slotID pInfo\n\n"
629       "C_GetSlotInfo obtains information about a particular slot in the system.\n"
630       " slotID    the ID of the slot\n"
631       " pInfo     receives the slot information\n",
632       { ArgULong, ArgSlotInfo | ArgOut, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
633         ArgNone, ArgNone, ArgNone } },
634     { "C_GetTokenInfo",
635       F_C_GetTokenInfo,
636       "C_GetTokenInfo slotID pInfo\n\n"
637       "C_GetTokenInfo obtains information about a particular token in the system.\n"
638       " slotID    ID of the token's slot\n"
639       " pInfo     receives the token information\n",
640       { ArgULong, ArgTokenInfo | ArgOut, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
641         ArgNone, ArgNone, ArgNone } },
642     { "C_GetMechanismList",
643       F_C_GetMechanismList,
644       "C_GetMechanismList slotID pMechanismList pulCount\n\n"
645       "C_GetMechanismList obtains a list of mechanism types supported by a token.\n"
646       " slotID            ID of token's slot\n"
647       " pMechanismList    gets mech. array\n"
648       " pulCount          gets # of mechs.\n",
649       { ArgULong, ArgULong | ArgArray | ArgOut, ArgULong | ArgOut, ArgNone, ArgNone,
650         ArgNone, ArgNone, ArgNone, ArgNone, ArgNone } },
651     { "C_GetMechanismInfo",
652       F_C_GetMechanismInfo,
653       "C_GetMechanismInfo slotID type pInfo\n\n"
654       "C_GetMechanismInfo obtains information about a particular mechanism possibly\n"
655       "supported by a token.\n"
656       " slotID    ID of the token's slot\n"
657       " type      type of mechanism\n"
658       " pInfo     receives mechanism info\n",
659       { ArgULong, ArgULong, ArgMechanismInfo | ArgOut, ArgNone, ArgNone, ArgNone, ArgNone,
660         ArgNone, ArgNone, ArgNone } },
661     { "C_InitToken",
662       F_C_InitToken,
663       "C_InitToken slotID pPin ulPinLen pLabel\n\n"
664       "C_InitToken initializes a token.\n"
665       " slotID      ID of the token's slot\n"
666       " pPin        the SO's initial PIN\n"
667       " ulPinLen    length in bytes of the PIN\n"
668       " pLabel      32-byte token label (blank padded)\n",
669       { ArgULong, ArgUTF8, ArgULong, ArgUTF8, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
670         ArgNone } },
671     { "C_InitPIN",
672       F_C_InitPIN,
673       "C_InitPIN hSession pPin ulPinLen\n\n"
674       "C_InitPIN initializes the normal user's PIN.\n"
675       " hSession    the session's handle\n"
676       " pPin        the normal user's PIN\n"
677       " ulPinLen    length in bytes of the PIN\n",
678       { ArgULong, ArgUTF8, ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
679         ArgNone } },
680     { "C_SetPIN",
681       F_C_SetPIN,
682       "C_SetPIN hSession pOldPin ulOldLen pNewPin ulNewLen\n\n"
683       "C_SetPIN modifies the PIN of the user who is logged in.\n"
684       " hSession    the session's handle\n"
685       " pOldPin     the old PIN\n"
686       " ulOldLen    length of the old PIN\n"
687       " pNewPin     the new PIN\n"
688       " ulNewLen    length of the new PIN\n",
689       { ArgULong, ArgUTF8, ArgULong, ArgUTF8, ArgULong, ArgNone, ArgNone, ArgNone,
690         ArgNone, ArgNone } },
691     { "C_OpenSession",
692       F_C_OpenSession,
693       "C_OpenSession slotID flags phSession\n\n"
694       "C_OpenSession opens a session between an application and a token.\n"
695       " slotID          the slot's ID\n"
696       " flags           from\n"
697       " phSession       gets session handle\n",
698       { ArgULong, ArgULong, ArgULong | ArgOut, ArgNone, ArgNone, ArgNone, ArgNone,
699         ArgNone, ArgNone, ArgNone } },
700     { "C_CloseSession",
701       F_C_CloseSession,
702       "C_CloseSession hSession\n\n"
703       "C_CloseSession closes a session between an application and a token.\n"
704       " hSession   the session's handle\n",
705       { ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
706         ArgNone } },
707     { "C_CloseAllSessions",
708       F_C_CloseAllSessions,
709       "C_CloseAllSessions slotID\n\n"
710       "C_CloseAllSessions closes all sessions with a token.\n"
711       " slotID   the token's slot\n",
712       { ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
713         ArgNone } },
714     { "C_GetSessionInfo",
715       F_C_GetSessionInfo,
716       "C_GetSessionInfo hSession pInfo\n\n"
717       "C_GetSessionInfo obtains information about the session.\n"
718       " hSession    the session's handle\n"
719       " pInfo       receives session info\n",
720       { ArgULong, ArgSessionInfo | ArgOut, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
721         ArgNone, ArgNone, ArgNone } },
722     { "C_GetOperationState",
723       F_C_GetOperationState,
724       "C_GetOperationState hSession pOpState pulOpStateLen\n\n"
725       "C_GetOperationState obtains the state of the cryptographic operation in a\n"
726       "session.\n"
727       " hSession        session's handle\n"
728       " pOpState        gets state\n"
729       " pulOpStateLen   gets state length\n",
730       { ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone, ArgNone, ArgNone, ArgNone,
731         ArgNone, ArgNone, ArgNone } },
732     { "C_SetOperationState",
733       F_C_SetOperationState,
734       "C_SetOperationState hSession pOpState ulOpStateLen hEncKey hAuthKey\n\n"
735       "C_SetOperationState restores the state of the cryptographic operation in a\n"
736       "session.\n"
737       " hSession        session's handle\n"
738       " pOpState        holds state\n"
739       " ulOpStateLen    holds state length\n"
740       " hEncKey         en/decryption key\n"
741       " hAuthnKey       sign/verify key\n",
742       { ArgULong, ArgChar | ArgOut, ArgULong, ArgULong, ArgULong, ArgNone, ArgNone,
743         ArgNone, ArgNone, ArgNone } },
744     { "C_Login",
745       F_C_Login,
746       "C_Login hSession userType pPin ulPinLen\n\n"
747       "C_Login logs a user into a token.\n"
748       " hSession    the session's handle\n"
749       " userType    the user type\n"
750       " pPin        the user's PIN\n"
751       " ulPinLen    the length of the PIN\n",
752       { ArgULong, ArgULong, ArgVar, ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
753         ArgNone } },
754     { "C_Logout",
755       F_C_Logout,
756       "C_Logout hSession\n\n"
757       "C_Logout logs a user out from a token.\n"
758       " hSession   the session's handle\n",
759       { ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
760         ArgNone } },
761     { "C_CreateObject",
762       F_C_CreateObject,
763       "C_CreateObject hSession pTemplate ulCount phObject\n\n"
764       "C_CreateObject creates a new object.\n"
765       " hSession      the session's handle\n"
766       " pTemplate     the object's template\n"
767       " ulCount       attributes in template\n"
768       " phObject   gets new object's handle.\n",
769       { ArgULong, ArgAttribute | ArgArray, ArgULong, ArgULong | ArgOut, ArgNone, ArgNone,
770         ArgNone, ArgNone, ArgNone, ArgNone } },
771     { "C_CopyObject",
772       F_C_CopyObject,
773       "C_CopyObject hSession hObject pTemplate ulCount phNewObject\n\n"
774       "C_CopyObject copies an object creating a new object for the copy.\n"
775       " hSession      the session's handle\n"
776       " hObject       the object's handle\n"
777       " pTemplate     template for new object\n"
778       " ulCount       attributes in template\n"
779       " phNewObject   receives handle of copy\n",
780       { ArgULong, ArgULong, ArgAttribute | ArgArray, ArgULong, ArgULong | ArgOut, ArgNone,
781         ArgNone, ArgNone, ArgNone, ArgNone } },
782     { "C_DestroyObject",
783       F_C_DestroyObject,
784       "C_DestroyObject hSession hObject\n\n"
785       "C_DestroyObject destroys an object.\n"
786       " hSession    the session's handle\n"
787       " hObject     the object's handle\n",
788       { ArgULong, ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
789         ArgNone } },
790     { "C_GetObjectSize",
791       F_C_GetObjectSize,
792       "C_GetObjectSize hSession hObject pulSize\n\n"
793       "C_GetObjectSize gets the size of an object in bytes.\n"
794       " hSession    the session's handle\n"
795       " hObject     the object's handle\n"
796       " pulSize     receives size of object\n",
797       { ArgULong, ArgULong, ArgULong | ArgOut, ArgNone, ArgNone, ArgNone, ArgNone,
798         ArgNone, ArgNone, ArgNone } },
799     { "C_GetAttributeValue",
800       F_C_GetAttributeValue,
801       "C_GetAttributeValue hSession hObject pTemplate ulCount\n\n"
802       "C_GetAttributeValue obtains the value of one or more object attributes.\n"
803       " hSession     the session's handle\n"
804       " hObject      the object's handle\n"
805       " pTemplate    specifies attrs; gets vals\n"
806       " ulCount      attributes in template\n",
807       { ArgULong, ArgULong, ArgAttribute | ArgArray, ArgULong, ArgNone, ArgNone, ArgNone,
808         ArgNone, ArgNone, ArgNone } },
809     { "C_SetAttributeValue",
810       F_C_SetAttributeValue,
811       "C_SetAttributeValue hSession hObject pTemplate ulCount\n\n"
812       "C_SetAttributeValue modifies the value of one or more object attributes\n"
813       " hSession     the session's handle\n"
814       " hObject      the object's handle\n"
815       " pTemplate    specifies attrs and values\n"
816       " ulCount      attributes in template\n",
817       { ArgULong, ArgULong, ArgAttribute | ArgArray, ArgULong, ArgNone, ArgNone, ArgNone,
818         ArgNone, ArgNone, ArgNone } },
819     { "C_FindObjectsInit",
820       F_C_FindObjectsInit,
821       "C_FindObjectsInit hSession pTemplate ulCount\n\n"
822       "C_FindObjectsInit initializes a search for token and session objects that\n"
823       "match a template.\n"
824       " hSession     the session's handle\n"
825       " pTemplate    attribute values to match\n"
826       " ulCount      attrs in search template\n",
827       { ArgULong, ArgAttribute | ArgArray, ArgULong, ArgNone, ArgNone, ArgNone, ArgNone,
828         ArgNone, ArgNone, ArgNone } },
829     { "C_FindObjectsFinal",
830       F_C_FindObjectsFinal,
831       "C_FindObjectsFinal hSession\n\n"
832       "C_FindObjectsFinal finishes a search for token and session objects.\n"
833       " hSession   the session's handle\n",
834       { ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
835         ArgNone } },
836     { "C_FindObjects",
837       F_C_FindObjects,
838       "C_FindObjects hSession phObject ulMaxObjectCount pulObjectCount\n\n"
839       "C_FindObjects continues a search for token and session objects that match\n"
840       "a template obtaining additional object handles.\n"
841       " hSession            session's handle\n"
842       " phObject            gets obj. handles\n"
843       " ulMaxObjectCount    max handles to get\n"
844       " pulObjectCount      actual # returned\n",
845       { ArgULong, ArgULong | ArgOut, ArgULong, ArgULong | ArgOut, ArgNone, ArgNone,
846         ArgNone, ArgNone, ArgNone, ArgNone } },
847     { "C_EncryptInit",
848       F_C_EncryptInit,
849       "C_EncryptInit hSession pMechanism hKey\n\n"
850       "C_EncryptInit initializes an encryption operation.\n"
851       " hSession      the session's handle\n"
852       " pMechanism    the encryption mechanism\n"
853       " hKey          handle of encryption key\n",
854       { ArgULong, ArgMechanism, ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
855         ArgNone, ArgNone } },
856     { "C_EncryptUpdate",
857       F_C_EncryptUpdate,
858       "C_EncryptUpdate hSession pPart ulPartLen pEncryptedPart pulEncryptedPartLen\n"
859       "\n"
860       "C_EncryptUpdate continues a multiple-part encryption operation.\n"
861       " hSession             session's handle\n"
862       " pPart                the plaintext data\n"
863       " ulPartLen            plaintext data len\n"
864       " pEncryptedPart       gets ciphertext\n"
865       " pulEncryptedPartLen  gets c-text size\n",
866       { ArgULong, ArgChar, ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone,
867         ArgNone, ArgNone, ArgNone, ArgNone } },
868     { "C_EncryptFinal",
869       F_C_EncryptFinal,
870       "C_EncryptFinal hSession pLastEncryptedPart pulLastEncryptedPartLen\n\n"
871       "C_EncryptFinal finishes a multiple-part encryption operation.\n"
872       " hSession                  session handle\n"
873       " pLastEncryptedPart        last c-text\n"
874       " pulLastEncryptedPartLen   gets last size\n",
875       { ArgULong, ArgChar, ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone,
876         ArgNone, ArgNone, ArgNone, ArgNone } },
877     { "C_Encrypt",
878       F_C_Encrypt,
879       "C_Encrypt hSession pData ulDataLen pEncryptedData pulEncryptedDataLen\n\n"
880       "C_Encrypt encrypts single-part data.\n"
881       " hSession              session's handle\n"
882       " pData                 the plaintext data\n"
883       " ulDataLen             bytes of plaintext\n"
884       " pEncryptedData        gets ciphertext\n"
885       " pulEncryptedDataLen   gets c-text size\n",
886       { ArgULong, ArgChar, ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone,
887         ArgNone, ArgNone, ArgNone, ArgNone } },
888     { "C_DecryptInit",
889       F_C_DecryptInit,
890       "C_DecryptInit hSession pMechanism hKey\n\n"
891       "C_DecryptInit initializes a decryption operation.\n"
892       " hSession      the session's handle\n"
893       " pMechanism    the decryption mechanism\n"
894       " hKey          handle of decryption key\n",
895       { ArgULong, ArgMechanism, ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
896         ArgNone, ArgNone } },
897     { "C_DecryptUpdate",
898       F_C_DecryptUpdate,
899       "C_DecryptUpdate hSession pEncryptedPart ulEncryptedPartLen pPart pulPartLen\n"
900       "\n"
901       "C_DecryptUpdate continues a multiple-part decryption operation.\n"
902       " hSession              session's handle\n"
903       " pEncryptedPart        encrypted data\n"
904       " ulEncryptedPartLen    input length\n"
905       " pPart                 gets plaintext\n"
906       " pulPartLen            p-text size\n",
907       { ArgULong, ArgChar, ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone,
908         ArgNone, ArgNone, ArgNone, ArgNone } },
909     { "C_DecryptFinal",
910       F_C_DecryptFinal,
911       "C_DecryptFinal hSession pLastPart pulLastPartLen\n\n"
912       "C_DecryptFinal finishes a multiple-part decryption operation.\n"
913       " hSession         the session's handle\n"
914       " pLastPart        gets plaintext\n"
915       " pulLastPartLen   p-text size\n",
916       { ArgULong, ArgChar, ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone,
917         ArgNone, ArgNone, ArgNone, ArgNone } },
918     { "C_Decrypt",
919       F_C_Decrypt,
920       "C_Decrypt hSession pEncryptedData ulEncryptedDataLen pData pulDataLen\n\n"
921       "C_Decrypt decrypts encrypted data in a single part.\n"
922       " hSession             session's handle\n"
923       " pEncryptedData       ciphertext\n"
924       " ulEncryptedDataLen   ciphertext length\n"
925       " pData                gets plaintext\n"
926       " pulDataLen           gets p-text size\n",
927       { ArgULong, ArgChar, ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone,
928         ArgNone, ArgNone, ArgNone, ArgNone } },
929     { "C_DigestInit",
930       F_C_DigestInit,
931       "C_DigestInit hSession pMechanism\n\n"
932       "C_DigestInit initializes a message-digesting operation.\n"
933       " hSession     the session's handle\n"
934       " pMechanism   the digesting mechanism\n",
935       { ArgULong, ArgMechanism, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
936         ArgNone, ArgNone } },
937     { "C_DigestUpdate",
938       F_C_DigestUpdate,
939       "C_DigestUpdate hSession pPart ulPartLen\n\n"
940       "C_DigestUpdate continues a multiple-part message-digesting operation.\n"
941       " hSession    the session's handle\n"
942       " pPart       data to be digested\n"
943       " ulPartLen   bytes of data to be digested\n",
944       { ArgULong, ArgChar, ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone,
945         ArgNone, ArgNone, ArgNone, ArgNone } },
946     { "C_DigestKey",
947       F_C_DigestKey,
948       "C_DigestKey hSession hKey\n\n"
949       "C_DigestKey continues a multi-part message-digesting operation by digesting\n"
950       "the value of a secret key as part of the data already digested.\n"
951       " hSession    the session's handle\n"
952       " hKey        secret key to digest\n",
953       { ArgULong, ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
954         ArgNone } },
955     { "C_DigestFinal",
956       F_C_DigestFinal,
957       "C_DigestFinal hSession pDigest pulDigestLen\n\n"
958       "C_DigestFinal finishes a multiple-part message-digesting operation.\n"
959       " hSession       the session's handle\n"
960       " pDigest        gets the message digest\n"
961       " pulDigestLen   gets byte count of digest\n",
962       { ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone, ArgNone, ArgNone, ArgNone,
963         ArgNone, ArgNone, ArgNone } },
964     { "C_Digest",
965       F_C_Digest,
966       "C_Digest hSession pData ulDataLen pDigest pulDigestLen\n\n"
967       "C_Digest digests data in a single part.\n"
968       " hSession       the session's handle\n"
969       " pData          data to be digested\n"
970       " ulDataLen      bytes of data to digest\n"
971       " pDigest        gets the message digest\n"
972       " pulDigestLen   gets digest length\n",
973       { ArgULong, ArgChar, ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone,
974         ArgNone, ArgNone, ArgNone, ArgNone } },
975     { "C_SignInit",
976       F_C_SignInit,
977       "C_SignInit hSession pMechanism hKey\n\n"
978       "C_SignInit initializes a signature (private key encryption operation where\n"
979       "the signature is (will be) an appendix to the data and plaintext cannot be\n"
980       "recovered from the signature.\n"
981       " hSession      the session's handle\n"
982       " pMechanism    the signature mechanism\n"
983       " hKey          handle of signature key\n",
984       { ArgULong, ArgMechanism, ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
985         ArgNone, ArgNone } },
986     { "C_SignUpdate",
987       F_C_SignUpdate,
988       "C_SignUpdate hSession pPart ulPartLen\n\n"
989       "C_SignUpdate continues a multiple-part signature operation where the\n"
990       "signature is (will be) an appendix to the data and plaintext cannot be\n"
991       "recovered from the signature.\n"
992       " hSession    the session's handle\n"
993       " pPart       the data to sign\n"
994       " ulPartLen   count of bytes to sign\n",
995       { ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone, ArgNone, ArgNone, ArgNone,
996         ArgNone, ArgNone, ArgNone } },
997     { "C_SignFinal",
998       F_C_SignFinal,
999       "C_SignFinal hSession pSignature pulSignatureLen\n\n"
1000       "C_SignFinal finishes a multiple-part signature operation returning the\n"
1001       "signature.\n"
1002       " hSession          the session's handle\n"
1003       " pSignature        gets the signature\n"
1004       " pulSignatureLen   gets signature length\n",
1005       { ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone, ArgNone, ArgNone, ArgNone,
1006         ArgNone, ArgNone, ArgNone } },
1007     { "C_SignRecoverInit",
1008       F_C_SignRecoverInit,
1009       "C_SignRecoverInit hSession pMechanism hKey\n\n"
1010       "C_SignRecoverInit initializes a signature operation where the data can be\n"
1011       "recovered from the signature.\n"
1012       " hSession     the session's handle\n"
1013       " pMechanism   the signature mechanism\n"
1014       " hKey         handle of the signature key\n",
1015       { ArgULong, ArgMechanism, ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1016         ArgNone, ArgNone } },
1017     { "C_SignRecover",
1018       F_C_SignRecover,
1019       "C_SignRecover hSession pData ulDataLen pSignature pulSignatureLen\n\n"
1020       "C_SignRecover signs data in a single operation where the data can be\n"
1021       "recovered from the signature.\n"
1022       " hSession          the session's handle\n"
1023       " pData             the data to sign\n"
1024       " ulDataLen         count of bytes to sign\n"
1025       " pSignature        gets the signature\n"
1026       " pulSignatureLen   gets signature length\n",
1027       { ArgULong, ArgChar, ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone,
1028         ArgNone, ArgNone, ArgNone, ArgNone } },
1029     { "C_Sign",
1030       F_C_Sign,
1031       "C_Sign hSession pData ulDataLen pSignature pulSignatureLen\n\n"
1032       "C_Sign signs (encrypts with private key) data in a single part where the\n"
1033       "signature is (will be) an appendix to the data and plaintext cannot be\n"
1034       "recovered from the signature.\n"
1035       " hSession          the session's handle\n"
1036       " pData             the data to sign\n"
1037       " ulDataLen         count of bytes to sign\n"
1038       " pSignature        gets the signature\n"
1039       " pulSignatureLen   gets signature length\n",
1040       { ArgULong, ArgChar, ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone,
1041         ArgNone, ArgNone, ArgNone, ArgNone } },
1042     { "C_VerifyInit",
1043       F_C_VerifyInit,
1044       "C_VerifyInit hSession pMechanism hKey\n\n"
1045       "C_VerifyInit initializes a verification operation where the signature is an\n"
1046       "appendix to the data and plaintext cannot cannot be recovered from the\n"
1047       "signature (e.g. DSA).\n"
1048       " hSession      the session's handle\n"
1049       " pMechanism    the verification mechanism\n"
1050       " hKey          verification key\n",
1051       { ArgULong, ArgMechanism, ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1052         ArgNone, ArgNone } },
1053     { "C_VerifyUpdate",
1054       F_C_VerifyUpdate,
1055       "C_VerifyUpdate hSession pPart ulPartLen\n\n"
1056       "C_VerifyUpdate continues a multiple-part verification operation where the\n"
1057       "signature is an appendix to the data and plaintext cannot be recovered from\n"
1058       "the signature.\n"
1059       " hSession    the session's handle\n"
1060       " pPart       signed data\n"
1061       " ulPartLen   length of signed data\n",
1062       { ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone, ArgNone, ArgNone, ArgNone,
1063         ArgNone, ArgNone, ArgNone } },
1064     { "C_VerifyFinal",
1065       F_C_VerifyFinal,
1066       "C_VerifyFinal hSession pSignature ulSignatureLen\n\n"
1067       "C_VerifyFinal finishes a multiple-part verification operation checking the\n"
1068       "signature.\n"
1069       " hSession         the session's handle\n"
1070       " pSignature       signature to verify\n"
1071       " ulSignatureLen   signature length\n",
1072       { ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone, ArgNone, ArgNone, ArgNone,
1073         ArgNone, ArgNone, ArgNone } },
1074     { "C_VerifyRecoverInit",
1075       F_C_VerifyRecoverInit,
1076       "C_VerifyRecoverInit hSession pMechanism hKey\n\n"
1077       "C_VerifyRecoverInit initializes a signature verification operation where the\n"
1078       "data is recovered from the signature.\n"
1079       " hSession      the session's handle\n"
1080       " pMechanism    the verification mechanism\n"
1081       " hKey          verification key\n",
1082       { ArgULong, ArgMechanism, ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1083         ArgNone, ArgNone } },
1084     { "C_VerifyRecover",
1085       F_C_VerifyRecover,
1086       "C_VerifyRecover hSession pSignature ulSignatureLen pData pulDataLen\n\n"
1087       "C_VerifyRecover verifies a signature in a single-part operation where the\n"
1088       "data is recovered from the signature.\n"
1089       " hSession          the session's handle\n"
1090       " pSignature        signature to verify\n"
1091       " ulSignatureLen    signature length\n"
1092       " pData             gets signed data\n"
1093       " pulDataLen        gets signed data len\n",
1094       { ArgULong, ArgChar, ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone,
1095         ArgNone, ArgNone, ArgNone, ArgNone } },
1096     { "C_Verify",
1097       F_C_Verify,
1098       "C_Verify hSession pData ulDataLen pSignature ulSignatureLen\n\n"
1099       "C_Verify verifies a signature in a single-part operation where the signature\n"
1100       "is an appendix to the data and plaintext cannot be recovered from the\n"
1101       "signature.\n"
1102       " hSession         the session's handle\n"
1103       " pData            signed data\n"
1104       " ulDataLen        length of signed data\n"
1105       " pSignature       signature\n"
1106       " ulSignatureLen   signature length*/\n",
1107       { ArgULong, ArgChar, ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone,
1108         ArgNone, ArgNone, ArgNone, ArgNone } },
1109     { "C_DigestEncryptUpdate",
1110       F_C_DigestEncryptUpdate,
1111       "C_DigestEncryptUpdate hSession pPart ulPartLen pEncryptedPart \\\n"
1112       "    pulEncryptedPartLen\n\n"
1113       "C_DigestEncryptUpdate continues a multiple-part digesting and encryption\n"
1114       "operation.\n"
1115       " hSession              session's handle\n"
1116       " pPart                 the plaintext data\n"
1117       " ulPartLen             plaintext length\n"
1118       " pEncryptedPart        gets ciphertext\n"
1119       " pulEncryptedPartLen   gets c-text length\n",
1120       { ArgULong, ArgChar, ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone,
1121         ArgNone, ArgNone, ArgNone, ArgNone } },
1122     { "C_DecryptDigestUpdate",
1123       F_C_DecryptDigestUpdate,
1124       "C_DecryptDigestUpdate hSession pEncryptedPart ulEncryptedPartLen pPart \\\n"
1125       "    pulPartLen\n\n"
1126       "C_DecryptDigestUpdate continues a multiple-part decryption and digesting\n"
1127       "operation.\n"
1128       " hSession              session's handle\n"
1129       " pEncryptedPart        ciphertext\n"
1130       " ulEncryptedPartLen    ciphertext length\n"
1131       " pPart                 gets plaintext\n"
1132       " pulPartLen            gets plaintext len\n",
1133       { ArgULong, ArgChar, ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone,
1134         ArgNone, ArgNone, ArgNone, ArgNone } },
1135     { "C_SignEncryptUpdate",
1136       F_C_SignEncryptUpdate,
1137       "C_SignEncryptUpdate hSession pPart ulPartLen pEncryptedPart \\\n"
1138       "    pulEncryptedPartLen\n\n"
1139       "C_SignEncryptUpdate continues a multiple-part signing and encryption\n"
1140       "operation.\n"
1141       " hSession              session's handle\n"
1142       " pPart                 the plaintext data\n"
1143       " ulPartLen             plaintext length\n"
1144       " pEncryptedPart        gets ciphertext\n"
1145       " pulEncryptedPartLen   gets c-text length\n",
1146       { ArgULong, ArgChar, ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone,
1147         ArgNone, ArgNone, ArgNone, ArgNone } },
1148     { "C_DecryptVerifyUpdate",
1149       F_C_DecryptVerifyUpdate,
1150       "C_DecryptVerifyUpdate hSession pEncryptedPart ulEncryptedPartLen pPart \\\n"
1151       "    pulPartLen\n\n"
1152       "C_DecryptVerifyUpdate continues a multiple-part decryption and verify\n"
1153       "operation.\n"
1154       " hSession              session's handle\n"
1155       " pEncryptedPart        ciphertext\n"
1156       " ulEncryptedPartLen    ciphertext length\n"
1157       " pPart                 gets plaintext\n"
1158       " pulPartLen            gets p-text length\n",
1159       { ArgULong, ArgChar, ArgULong, ArgChar | ArgOut, ArgULong | ArgOut, ArgNone,
1160         ArgNone, ArgNone, ArgNone, ArgNone } },
1161     { "C_GenerateKeyPair",
1162       F_C_GenerateKeyPair,
1163       "C_GenerateKeyPair hSession pMechanism pPublicKeyTemplate \\\n"
1164       "    ulPublicKeyAttributeCount pPrivateKeyTemplate ulPrivateKeyAttributeCount \\\n"
1165       "    phPublicKey phPrivateKey\n\n"
1166       "C_GenerateKeyPair generates a public-key/private-key pair creating new key\n"
1167       "objects.\n"
1168       " hSession                      sessionhandle\n"
1169       " pMechanism                    key-genmech.\n"
1170       " pPublicKeyTemplate            templatefor pub. key\n"
1171       " ulPublicKeyAttributeCount     # pub. attrs.\n"
1172       " pPrivateKeyTemplate           templatefor priv. key\n"
1173       " ulPrivateKeyAttributeCount    # priv. attrs.\n"
1174       " phPublicKey                   gets pub. keyhandle\n"
1175       " phPrivateKey                  getspriv. keyhandle\n",
1176       { ArgULong, ArgMechanism, ArgAttribute | ArgArray, ArgULong,
1177         ArgAttribute | ArgArray, ArgULong, ArgULong | ArgOut, ArgULong | ArgOut, ArgNone,
1178         ArgNone } },
1179     { "C_GenerateKey",
1180       F_C_GenerateKey,
1181       "C_GenerateKey hSession pMechanism pTemplate ulCount phKey\n\n"
1182       "C_GenerateKey generates a secret key creating a new key object.\n"
1183       " hSession      the session's handle\n"
1184       " pMechanism    key generation mech.\n"
1185       " pTemplate     template for new key\n"
1186       " ulCount       # of attrs in template\n"
1187       " phKey         gets handle of new key\n",
1188       { ArgULong, ArgMechanism, ArgAttribute | ArgArray, ArgULong, ArgULong | ArgOut,
1189         ArgNone, ArgNone, ArgNone, ArgNone, ArgNone } },
1190     { "C_WrapKey",
1191       F_C_WrapKey,
1192       "C_WrapKey hSession pMechanism hWrappingKey hKey pWrappedKey pulWrappedKeyLen\n\n"
1193       "C_WrapKey wraps (i.e. encrypts) a key.\n"
1194       " hSession          the session's handle\n"
1195       " pMechanism        the wrapping mechanism\n"
1196       " hWrappingKey      wrapping key\n"
1197       " hKey              key to be wrapped\n"
1198       " pWrappedKey       gets wrapped key\n"
1199       " pulWrappedKeyLen  gets wrapped key size\n",
1200       { ArgULong, ArgMechanism, ArgULong, ArgULong, ArgULong, ArgChar | ArgOut,
1201         ArgULong | ArgOut, ArgNone, ArgNone, ArgNone } },
1202     { "C_UnwrapKey",
1203       F_C_UnwrapKey,
1204       "C_UnwrapKey hSession pMechanism hUnwrappingKey pWrappedKey ulWrappedKeyLen \\\n"
1205       "    pTemplate ulAttributeCount phKey\n\n"
1206       "C_UnwrapKey unwraps (decrypts) a wrapped key creating a new key object.\n"
1207       " hSession            session's handle\n"
1208       " pMechanism          unwrapping mech.\n"
1209       " hUnwrappingKey      unwrapping key\n"
1210       " pWrappedKey         the wrapped key\n"
1211       " ulWrappedKeyLen     wrapped key len\n"
1212       " pTemplate           new key template\n"
1213       " ulAttributeCount    template length\n"
1214       " phKey               gets new handle\n",
1215       { ArgULong, ArgMechanism, ArgULong, ArgChar, ArgULong, ArgAttribute | ArgArray,
1216         ArgULong, ArgULong | ArgOut, ArgNone, ArgNone } },
1217     { "C_DeriveKey",
1218       F_C_DeriveKey,
1219       "C_DeriveKey hSession pMechanism hBaseKey pTemplate ulAttributeCount phKey\n\n"
1220       "C_DeriveKey derives a key from a base key creating a new key object.\n"
1221       " hSession            session's handle\n"
1222       " pMechanism          key deriv. mech.\n"
1223       " hBaseKey            base key\n"
1224       " pTemplate           new key template\n"
1225       " ulAttributeCount    template length\n"
1226       " phKey               gets new handle\n",
1227       { ArgULong, ArgMechanism, ArgULong, ArgAttribute | ArgArray, ArgULong,
1228         ArgULong | ArgOut, ArgNone, ArgNone, ArgNone, ArgNone } },
1229     { "C_SeedRandom",
1230       F_C_SeedRandom,
1231       "C_SeedRandom hSession pSeed ulSeedLen\n\n"
1232       "C_SeedRandom mixes additional seed material into the token's random number\n"
1233       "generator.\n"
1234       " hSession    the session's handle\n"
1235       " pSeed       the seed material\n"
1236       " ulSeedLen   length of seed material\n",
1237       { ArgULong, ArgChar, ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1238         ArgNone } },
1239     { "C_GenerateRandom",
1240       F_C_GenerateRandom,
1241       "C_GenerateRandom hSession RandomData ulRandomLen\n\n"
1242       "C_GenerateRandom generates random data.\n"
1243       " hSession      the session's handle\n"
1244       " RandomData    receives the random data\n"
1245       " ulRandomLen   # of bytes to generate\n",
1246       { ArgULong, ArgChar, ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1247         ArgNone } },
1248     { "C_GetFunctionStatus",
1249       F_C_GetFunctionStatus,
1250       "C_GetFunctionStatus hSession\n\n"
1251       "C_GetFunctionStatus is a legacy function; it obtains an updated status of\n"
1252       "a function running in parallel with an application.\n"
1253       " hSession   the session's handle\n",
1254       { ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1255         ArgNone } },
1256     { "C_CancelFunction",
1257       F_C_CancelFunction,
1258       "C_CancelFunction hSession\n\n"
1259       "C_CancelFunction is a legacy function; it cancels a function running in\n"
1260       "parallel.\n"
1261       " hSession   the session's handle\n",
1262       { ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1263         ArgNone } },
1264     { "C_WaitForSlotEvent",
1265       F_C_WaitForSlotEvent,
1266       "C_WaitForSlotEvent flags pSlot pRserved\n\n"
1267       "C_WaitForSlotEvent waits for a slot event (token insertion removal etc.)\n"
1268       "to occur.\n"
1269       " flags          blocking/nonblocking flag\n"
1270       " pSlot    location that receives the slot ID\n"
1271       " pRserved    reserved.  Should be NULL_PTR\n",
1272       { ArgULong, ArgULong | ArgArray, ArgVar, ArgNone, ArgNone, ArgNone, ArgNone,
1273         ArgNone, ArgNone, ArgNone } },
1274     { "NewArray",
1275       F_NewArray,
1276       "NewArray varName varType array size\n\n"
1277       "Creates a new array variable.\n"
1278       " varName     variable name of the new array\n"
1279       " varType     data type of the new array\n"
1280       " size        number of elements in the array\n",
1281       { ArgVar | ArgNew, ArgVar, ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1282         ArgNone, ArgNone } },
1283     { "NewInitArg",
1284       F_NewInitializeArgs,
1285       "NewInitArg varName flags string\n\n"
1286       "Creates a new init variable.\n"
1287       " varName     variable name of the new initArg\n"
1288       " flags       value to set the flags field\n"
1289       " string      string parameter for init arg\n",
1290       { ArgVar | ArgNew, ArgULong, ArgVar | ArgNew, ArgNone, ArgNone, ArgNone, ArgNone,
1291         ArgNone, ArgNone, ArgNone } },
1292     { "NewTemplate",
1293       F_NewTemplate,
1294       "NewTemplate varName attributeList\n\n"
1295       "Create a new empty template and populate the attribute list\n"
1296       " varName        variable name of the new template\n"
1297       " attributeList  comma separated list of CKA_ATTRIBUTE types\n",
1298       { ArgVar | ArgNew, ArgVar, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1299         ArgNone, ArgNone } },
1300     { "NewMechanism",
1301       F_NewMechanism,
1302       "NewMechanism varName mechanismType\n\n"
1303       "Create a new CK_MECHANISM object with type NULL parameters and specified type\n"
1304       " varName        variable name of the new mechansim\n"
1305       " mechanismType  CKM_ mechanism type value to set int the type field\n",
1306       { ArgVar | ArgNew, ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1307         ArgNone, ArgNone } },
1308     { "BuildTemplate",
1309       F_BuildTemplate,
1310       "BuildTemplate template\n\n"
1311       "Allocates space for the value in a template which has the sizes filled in,\n"
1312       "but no values allocated yet.\n"
1313       " template        variable name of the template\n",
1314       { ArgAttribute, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1315         ArgNone, ArgNone } },
1316     { "SetTemplate",
1317       F_SetTemplate,
1318       "SetTemplate template index value\n\n"
1319       "Sets a particular element of a template to a CK_ULONG\n"
1320       " template        variable name of the template\n"
1321       " index           index into the template to the element to change\n"
1322       " value           32 bit value to set in the template\n",
1323       { ArgAttribute, ArgULong, ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1324         ArgNone, ArgNone } },
1325     { "SetString",
1326       F_SetStringVar,
1327       "SetString varName string\n\n"
1328       "Sets a particular variable to a string value\n"
1329       " variable        variable name of new string\n"
1330       " string          String to set the variable to\n",
1331       { ArgVar | ArgNew, ArgVar, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1332         ArgNone, ArgNone } },
1333     { "Set",
1334       F_SetVar,
1335       "Set varName value\n\n"
1336       "Sets a particular variable to CK_ULONG\n"
1337       " variable        name of the new variable\n"
1338       " value           32 bit value to set variable to\n",
1339       { ArgVar | ArgNew, ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1340         ArgNone, ArgNone } },
1341     { "Print",
1342       F_Print,
1343       "Print varName\n\n"
1344       "prints a variable\n"
1345       " variable        name of the variable to print\n",
1346       { ArgVar, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1347         ArgNone } },
1348     { "Delete",
1349       F_Delete,
1350       "Delete varName\n\n"
1351       "delete a variable\n"
1352       " variable        name of the variable to delete\n",
1353       { ArgVar | ArgNew, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1354         ArgNone, ArgNone } },
1355     { "Load",
1356       F_Load,
1357       "load libraryName\n\n"
1358       "load a pkcs #11 module\n"
1359       " libraryName        Name of a shared library\n",
1360       { ArgVar, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1361         ArgNone } },
1362     { "Save",
1363       F_SaveVar,
1364       "Save filename variable\n\n"
1365       "Saves the binary value of 'variable' in file 'filename'\n"
1366       " fileName        target file to save the variable in\n"
1367       " variable        variable to save\n",
1368       { ArgVar | ArgNew, ArgVar, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1369         ArgNone, ArgNone } },
1370     { "Restore",
1371       F_RestoreVar,
1372       "Restore filename variable\n\n"
1373       "Restores a variable from a file\n"
1374       " fileName        target file to restore the variable from\n"
1375       " variable        variable to restore\n",
1376       { ArgVar | ArgNew, ArgVar, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1377         ArgNone, ArgNone } },
1378     { "Increment",
1379       F_Increment,
1380       "Increment variable value\n\n"
1381       "Increment a variable by value\n",
1382       { ArgVar, ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1383         ArgNone } },
1384     { "Decrement",
1385       F_Decrement,
1386       "Decrement variable value\n\n"
1387       "Decrement a variable by value\n",
1388       { ArgVar, ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1389         ArgNone } },
1390     { "List",
1391       F_List,
1392       "List all the variables\n",
1393       { ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1394         ArgNone } },
1395     { "Unload",
1396       F_Unload,
1397       "Unload the currrently loaded PKCS #11 library\n",
1398       { ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1399         ArgNone } },
1400     { "Run",
1401       F_Run,
1402       "Run filename\n\n"
1403       "reads filename as script of commands to execute\n",
1404       { ArgVar | ArgNew, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1405         ArgNone, ArgNone } },
1406     { "Time",
1407       F_Time,
1408       "Time pkcs11 command\n\n"
1409       "Execute a pkcs #11 command and time the results\n",
1410       { ArgVar | ArgFull, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1411         ArgNone, ArgNone } },
1412     { "System",
1413       F_System,
1414       "Set System Flag",
1415       { ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1416         ArgNone } },
1417     { "LoopRun",
1418       F_Loop,
1419       "LoopRun filename var start end step\n\n"
1420       "Run in a loop. Loop exit if scrip does and explicit quit (Quit QuitIf etc.)",
1421       { ArgVar | ArgNew, ArgVar | ArgNew, ArgULong, ArgULong, ArgULong, ArgNone, ArgNone,
1422         ArgNone, ArgNone, ArgNone } },
1423     { "Help",
1424       F_Help,
1425       "Help [command]\n\n"
1426       "print general help, or help for a specific command\n",
1427       { ArgVar | ArgOpt, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1428         ArgNone, ArgNone } },
1429     { "QuitIf",
1430       F_QuitIf,
1431       "QuitIf arg1 comparator arg2\n\n"
1432       "Exit from this program if Condition is valid, valid comparators:\n"
1433       "  < > <= >= = !=\n",
1434       { ArgULong, ArgVar | ArgNew, ArgULong, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1435         ArgNone, ArgNone } },
1436     { "QuitIfString",
1437       F_QuitIfString,
1438       "QuitIfString arg1 comparator arg2\n\n"
1439       "Exit from this program if Condition is valid, valid comparators:\n"
1440       "  = !=\n",
1441       { ArgVar | ArgNew, ArgVar | ArgNew, ArgVar | ArgNew, ArgNone, ArgNone, ArgNone,
1442         ArgNone, ArgNone, ArgNone, ArgNone } },
1443     { "Quit",
1444       F_Quit,
1445       "Exit from this program",
1446       { ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone, ArgNone,
1447         ArgNone } },
1448 };
1449 
1450 const Commands *commands = &_commands[0];
1451 const int commandCount = sizeof(_commands) / sizeof(_commands[0]);
1452 
1453 const Topics _topics[] = {
1454     { "variables",
1455       "Variables are random strings of characters. These should begin with alpha\n"
1456       " characters, and should not contain any spaces, nor should they match any\n"
1457       " built-in constants. There is some checking in the code for these things,\n"
1458       " but it's not 100% and using invalid variable names can cause problems.\n"
1459       " Variables are created by any 'OUT' parameter. If the variable does not\n"
1460       " exist, it will be created. For in parameters variables must already exist.\n" },
1461     { "constants",
1462       "pk11util recognizes *lots* of constants. All CKA_, CKF_, CKO_, CKU_, CKS_,\n"
1463       " CKC_, CKK_, CKH_, CKM_, CKT_ values from the PKCS #11 spec are recognized.\n"
1464       " Constants can be specified with their fully qualified CK?_ value, or the\n"
1465       " prefix can be dropped. Constants are matched case insensitve.\n" },
1466     { "arrays",
1467       "Arrays are special variables which represent 'C' arrays. Each array \n"
1468       " variable can be referenced as a group (using just the name), or as \n"
1469       " individual elements (with the [int] operator). Example:\n"
1470       "      print myArray    # prints the full array.\n"
1471       "      print myArray[3] # prints the 3rd elemement of the array \n" },
1472     { "sizes",
1473       "Size operaters returns the size in bytes of a variable, or the number of\n"
1474       " elements in an array.\n"
1475       "    size(var) and sizeof(var) return the size of var in bytes.\n"
1476       "    sizea(var) and sizeofarray(var) return the number of elements in var.\n"
1477       "       If var is not an array, sizea(var) returns 1.\n" },
1478 };
1479 
1480 const Topics *topics = &_topics[0];
1481 const int topicCount = sizeof(_topics) / sizeof(_topics[0]);
1482 
1483 const char *
getName(CK_ULONG value,ConstType type)1484 getName(CK_ULONG value, ConstType type)
1485 {
1486     unsigned int i;
1487 
1488     for (i = 0; i < constCount; i++) {
1489         if (consts[i].type == type && consts[i].value == value) {
1490             return consts[i].name;
1491         }
1492         if (type == ConstNone && consts[i].value == value) {
1493             return consts[i].name;
1494         }
1495     }
1496 
1497     return NULL;
1498 }
1499 
1500 const char *
getNameFromAttribute(CK_ATTRIBUTE_TYPE type)1501 getNameFromAttribute(CK_ATTRIBUTE_TYPE type)
1502 {
1503     return getName(type, ConstAttribute);
1504 }
1505 
1506 unsigned int
totalKnownType(ConstType type)1507 totalKnownType(ConstType type)
1508 {
1509     unsigned int count = 0;
1510     unsigned int i;
1511 
1512     for (i = 0; i < constCount; i++) {
1513         if (consts[i].type == type)
1514             count++;
1515     }
1516     return count;
1517 }
1518