1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (c) 2017-2020, Linaro Limited
4  */
5 
6 #include <ck_debug.h>
7 #include <pkcs11.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdlib.h>
11 
12 #include "local_utils.h"
13 
14 #define CK2STR_ENTRY(id)	case id: return #id
15 
ckr2str(CK_RV id)16 const char *ckr2str(CK_RV id)
17 {
18 	switch (id) {
19 	CK2STR_ENTRY(CKR_OK);
20 	CK2STR_ENTRY(CKR_CANCEL);
21 	CK2STR_ENTRY(CKR_HOST_MEMORY);
22 	CK2STR_ENTRY(CKR_SLOT_ID_INVALID);
23 	CK2STR_ENTRY(CKR_GENERAL_ERROR);
24 	CK2STR_ENTRY(CKR_FUNCTION_FAILED);
25 	CK2STR_ENTRY(CKR_ARGUMENTS_BAD);
26 	CK2STR_ENTRY(CKR_NO_EVENT);
27 	CK2STR_ENTRY(CKR_NEED_TO_CREATE_THREADS);
28 	CK2STR_ENTRY(CKR_CANT_LOCK);
29 	CK2STR_ENTRY(CKR_ATTRIBUTE_READ_ONLY);
30 	CK2STR_ENTRY(CKR_ATTRIBUTE_SENSITIVE);
31 	CK2STR_ENTRY(CKR_ATTRIBUTE_TYPE_INVALID);
32 	CK2STR_ENTRY(CKR_ATTRIBUTE_VALUE_INVALID);
33 	CK2STR_ENTRY(CKR_ACTION_PROHIBITED);
34 	CK2STR_ENTRY(CKR_DATA_INVALID);
35 	CK2STR_ENTRY(CKR_DATA_LEN_RANGE);
36 	CK2STR_ENTRY(CKR_DEVICE_ERROR);
37 	CK2STR_ENTRY(CKR_DEVICE_MEMORY);
38 	CK2STR_ENTRY(CKR_DEVICE_REMOVED);
39 	CK2STR_ENTRY(CKR_ENCRYPTED_DATA_INVALID);
40 	CK2STR_ENTRY(CKR_ENCRYPTED_DATA_LEN_RANGE);
41 	CK2STR_ENTRY(CKR_FUNCTION_CANCELED);
42 	CK2STR_ENTRY(CKR_FUNCTION_NOT_PARALLEL);
43 	CK2STR_ENTRY(CKR_FUNCTION_NOT_SUPPORTED);
44 	CK2STR_ENTRY(CKR_KEY_HANDLE_INVALID);
45 	CK2STR_ENTRY(CKR_KEY_SIZE_RANGE);
46 	CK2STR_ENTRY(CKR_KEY_TYPE_INCONSISTENT);
47 	CK2STR_ENTRY(CKR_KEY_NOT_NEEDED);
48 	CK2STR_ENTRY(CKR_KEY_CHANGED);
49 	CK2STR_ENTRY(CKR_KEY_NEEDED);
50 	CK2STR_ENTRY(CKR_KEY_INDIGESTIBLE);
51 	CK2STR_ENTRY(CKR_KEY_FUNCTION_NOT_PERMITTED);
52 	CK2STR_ENTRY(CKR_KEY_NOT_WRAPPABLE);
53 	CK2STR_ENTRY(CKR_KEY_UNEXTRACTABLE);
54 	CK2STR_ENTRY(CKR_MECHANISM_INVALID);
55 	CK2STR_ENTRY(CKR_MECHANISM_PARAM_INVALID);
56 	CK2STR_ENTRY(CKR_OBJECT_HANDLE_INVALID);
57 	CK2STR_ENTRY(CKR_OPERATION_ACTIVE);
58 	CK2STR_ENTRY(CKR_OPERATION_NOT_INITIALIZED);
59 	CK2STR_ENTRY(CKR_PIN_INCORRECT);
60 	CK2STR_ENTRY(CKR_PIN_INVALID);
61 	CK2STR_ENTRY(CKR_PIN_LEN_RANGE);
62 	CK2STR_ENTRY(CKR_PIN_EXPIRED);
63 	CK2STR_ENTRY(CKR_PIN_LOCKED);
64 	CK2STR_ENTRY(CKR_SESSION_CLOSED);
65 	CK2STR_ENTRY(CKR_SESSION_COUNT);
66 	CK2STR_ENTRY(CKR_SESSION_HANDLE_INVALID);
67 	CK2STR_ENTRY(CKR_SESSION_PARALLEL_NOT_SUPPORTED);
68 	CK2STR_ENTRY(CKR_SESSION_READ_ONLY);
69 	CK2STR_ENTRY(CKR_SESSION_EXISTS);
70 	CK2STR_ENTRY(CKR_SESSION_READ_ONLY_EXISTS);
71 	CK2STR_ENTRY(CKR_SESSION_READ_WRITE_SO_EXISTS);
72 	CK2STR_ENTRY(CKR_SIGNATURE_INVALID);
73 	CK2STR_ENTRY(CKR_SIGNATURE_LEN_RANGE);
74 	CK2STR_ENTRY(CKR_TEMPLATE_INCOMPLETE);
75 	CK2STR_ENTRY(CKR_TEMPLATE_INCONSISTENT);
76 	CK2STR_ENTRY(CKR_TOKEN_NOT_PRESENT);
77 	CK2STR_ENTRY(CKR_TOKEN_NOT_RECOGNIZED);
78 	CK2STR_ENTRY(CKR_TOKEN_WRITE_PROTECTED);
79 	CK2STR_ENTRY(CKR_UNWRAPPING_KEY_HANDLE_INVALID);
80 	CK2STR_ENTRY(CKR_UNWRAPPING_KEY_SIZE_RANGE);
81 	CK2STR_ENTRY(CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT);
82 	CK2STR_ENTRY(CKR_USER_ALREADY_LOGGED_IN);
83 	CK2STR_ENTRY(CKR_USER_NOT_LOGGED_IN);
84 	CK2STR_ENTRY(CKR_USER_PIN_NOT_INITIALIZED);
85 	CK2STR_ENTRY(CKR_USER_TYPE_INVALID);
86 	CK2STR_ENTRY(CKR_USER_ANOTHER_ALREADY_LOGGED_IN);
87 	CK2STR_ENTRY(CKR_USER_TOO_MANY_TYPES);
88 	CK2STR_ENTRY(CKR_WRAPPED_KEY_INVALID);
89 	CK2STR_ENTRY(CKR_WRAPPED_KEY_LEN_RANGE);
90 	CK2STR_ENTRY(CKR_WRAPPING_KEY_HANDLE_INVALID);
91 	CK2STR_ENTRY(CKR_WRAPPING_KEY_SIZE_RANGE);
92 	CK2STR_ENTRY(CKR_WRAPPING_KEY_TYPE_INCONSISTENT);
93 	CK2STR_ENTRY(CKR_RANDOM_SEED_NOT_SUPPORTED);
94 	CK2STR_ENTRY(CKR_RANDOM_NO_RNG);
95 	CK2STR_ENTRY(CKR_DOMAIN_PARAMS_INVALID);
96 	CK2STR_ENTRY(CKR_CURVE_NOT_SUPPORTED);
97 	CK2STR_ENTRY(CKR_BUFFER_TOO_SMALL);
98 	CK2STR_ENTRY(CKR_SAVED_STATE_INVALID);
99 	CK2STR_ENTRY(CKR_INFORMATION_SENSITIVE);
100 	CK2STR_ENTRY(CKR_STATE_UNSAVEABLE);
101 	CK2STR_ENTRY(CKR_CRYPTOKI_NOT_INITIALIZED);
102 	CK2STR_ENTRY(CKR_CRYPTOKI_ALREADY_INITIALIZED);
103 	CK2STR_ENTRY(CKR_MUTEX_BAD);
104 	CK2STR_ENTRY(CKR_MUTEX_NOT_LOCKED);
105 	CK2STR_ENTRY(CKR_NEW_PIN_MODE);
106 	CK2STR_ENTRY(CKR_NEXT_OTP);
107 	CK2STR_ENTRY(CKR_EXCEEDED_MAX_ITERATIONS);
108 	CK2STR_ENTRY(CKR_FIPS_SELF_TEST_FAILED);
109 	CK2STR_ENTRY(CKR_LIBRARY_LOAD_FAILED);
110 	CK2STR_ENTRY(CKR_PIN_TOO_WEAK);
111 	CK2STR_ENTRY(CKR_PUBLIC_KEY_INVALID);
112 	CK2STR_ENTRY(CKR_FUNCTION_REJECTED);
113 	default:
114 		if (id & CKR_VENDOR_DEFINED)
115 			return "Vendor defined";
116 		else
117 			return "Unknown ID";
118 	}
119 }
120 
ckm2str(CK_MECHANISM_TYPE id)121 const char *ckm2str(CK_MECHANISM_TYPE id)
122 {
123 	switch (id) {
124 	CK2STR_ENTRY(CKM_RSA_PKCS_KEY_PAIR_GEN);
125 	CK2STR_ENTRY(CKM_RSA_PKCS);
126 	CK2STR_ENTRY(CKM_RSA_9796);
127 	CK2STR_ENTRY(CKM_RSA_X_509);
128 	CK2STR_ENTRY(CKM_MD5_RSA_PKCS);
129 	CK2STR_ENTRY(CKM_SHA1_RSA_PKCS);
130 	CK2STR_ENTRY(CKM_RSA_PKCS_OAEP);
131 	CK2STR_ENTRY(CKM_RSA_PKCS_PSS);
132 	CK2STR_ENTRY(CKM_SHA1_RSA_PKCS_PSS);
133 	CK2STR_ENTRY(CKM_SHA256_RSA_PKCS);
134 	CK2STR_ENTRY(CKM_SHA384_RSA_PKCS);
135 	CK2STR_ENTRY(CKM_SHA512_RSA_PKCS);
136 	CK2STR_ENTRY(CKM_SHA256_RSA_PKCS_PSS);
137 	CK2STR_ENTRY(CKM_SHA384_RSA_PKCS_PSS);
138 	CK2STR_ENTRY(CKM_SHA512_RSA_PKCS_PSS);
139 	CK2STR_ENTRY(CKM_SHA224_RSA_PKCS);
140 	CK2STR_ENTRY(CKM_SHA224_RSA_PKCS_PSS);
141 	CK2STR_ENTRY(CKM_SHA512_224);
142 	CK2STR_ENTRY(CKM_SHA512_224_HMAC);
143 	CK2STR_ENTRY(CKM_SHA512_224_HMAC_GENERAL);
144 	CK2STR_ENTRY(CKM_SHA512_224_KEY_DERIVATION);
145 	CK2STR_ENTRY(CKM_SHA512_256);
146 	CK2STR_ENTRY(CKM_SHA512_256_HMAC);
147 	CK2STR_ENTRY(CKM_SHA512_256_HMAC_GENERAL);
148 	CK2STR_ENTRY(CKM_SHA512_256_KEY_DERIVATION);
149 	CK2STR_ENTRY(CKM_MD5);
150 	CK2STR_ENTRY(CKM_MD5_HMAC);
151 	CK2STR_ENTRY(CKM_MD5_HMAC_GENERAL);
152 	CK2STR_ENTRY(CKM_SHA_1);
153 	CK2STR_ENTRY(CKM_SHA_1_HMAC);
154 	CK2STR_ENTRY(CKM_SHA_1_HMAC_GENERAL);
155 	CK2STR_ENTRY(CKM_SHA256);
156 	CK2STR_ENTRY(CKM_SHA256_HMAC);
157 	CK2STR_ENTRY(CKM_SHA256_HMAC_GENERAL);
158 	CK2STR_ENTRY(CKM_SHA224);
159 	CK2STR_ENTRY(CKM_SHA224_HMAC);
160 	CK2STR_ENTRY(CKM_SHA224_HMAC_GENERAL);
161 	CK2STR_ENTRY(CKM_SHA384);
162 	CK2STR_ENTRY(CKM_SHA384_HMAC);
163 	CK2STR_ENTRY(CKM_SHA384_HMAC_GENERAL);
164 	CK2STR_ENTRY(CKM_SHA512);
165 	CK2STR_ENTRY(CKM_SHA512_HMAC);
166 	CK2STR_ENTRY(CKM_SHA512_HMAC_GENERAL);
167 	CK2STR_ENTRY(CKM_HOTP_KEY_GEN);
168 	CK2STR_ENTRY(CKM_HOTP);
169 	CK2STR_ENTRY(CKM_GENERIC_SECRET_KEY_GEN);
170 	CK2STR_ENTRY(CKM_SHA1_KEY_DERIVATION);
171 	CK2STR_ENTRY(CKM_SHA256_KEY_DERIVATION);
172 	CK2STR_ENTRY(CKM_SHA384_KEY_DERIVATION);
173 	CK2STR_ENTRY(CKM_SHA512_KEY_DERIVATION);
174 	CK2STR_ENTRY(CKM_SHA224_KEY_DERIVATION);
175 	CK2STR_ENTRY(CKM_EC_KEY_PAIR_GEN);
176 	CK2STR_ENTRY(CKM_ECDSA);
177 	CK2STR_ENTRY(CKM_ECDSA_SHA1);
178 	CK2STR_ENTRY(CKM_ECDSA_SHA224);
179 	CK2STR_ENTRY(CKM_ECDSA_SHA256);
180 	CK2STR_ENTRY(CKM_ECDSA_SHA384);
181 	CK2STR_ENTRY(CKM_ECDSA_SHA512);
182 	CK2STR_ENTRY(CKM_ECDH1_DERIVE);
183 	CK2STR_ENTRY(CKM_ECDH1_COFACTOR_DERIVE);
184 	CK2STR_ENTRY(CKM_ECMQV_DERIVE);
185 	CK2STR_ENTRY(CKM_ECDH_AES_KEY_WRAP);
186 	CK2STR_ENTRY(CKM_RSA_AES_KEY_WRAP);
187 	CK2STR_ENTRY(CKM_AES_KEY_GEN);
188 	CK2STR_ENTRY(CKM_AES_ECB);
189 	CK2STR_ENTRY(CKM_AES_CBC);
190 	CK2STR_ENTRY(CKM_AES_MAC);
191 	CK2STR_ENTRY(CKM_AES_MAC_GENERAL);
192 	CK2STR_ENTRY(CKM_AES_CBC_PAD);
193 	CK2STR_ENTRY(CKM_AES_CTR);
194 	CK2STR_ENTRY(CKM_AES_GCM);
195 	CK2STR_ENTRY(CKM_AES_CCM);
196 	CK2STR_ENTRY(CKM_AES_CTS);
197 	CK2STR_ENTRY(CKM_AES_CMAC);
198 	CK2STR_ENTRY(CKM_AES_CMAC_GENERAL);
199 	CK2STR_ENTRY(CKM_AES_XCBC_MAC);
200 	CK2STR_ENTRY(CKM_AES_XCBC_MAC_96);
201 	CK2STR_ENTRY(CKM_AES_GMAC);
202 	CK2STR_ENTRY(CKM_DES3_ECB_ENCRYPT_DATA);
203 	CK2STR_ENTRY(CKM_DES3_CBC_ENCRYPT_DATA);
204 	CK2STR_ENTRY(CKM_AES_ECB_ENCRYPT_DATA);
205 	CK2STR_ENTRY(CKM_AES_CBC_ENCRYPT_DATA);
206 	CK2STR_ENTRY(CKM_AES_KEY_WRAP);
207 	CK2STR_ENTRY(CKM_AES_KEY_WRAP_PAD);
208 	default:
209 		if (id & CKM_VENDOR_DEFINED)
210 			return "Vendor defined";
211 		else
212 			return "Unknown ID";
213 	}
214 }
215 
slot_ckf2str(CK_ULONG flag)216 const char *slot_ckf2str(CK_ULONG flag)
217 {
218 	switch (flag) {
219 	CK2STR_ENTRY(CKF_TOKEN_PRESENT);
220 	CK2STR_ENTRY(CKF_REMOVABLE_DEVICE);
221 	CK2STR_ENTRY(CKF_HW_SLOT);
222 	default:
223 		return "Unknown flag";
224 	}
225 }
226 
token_ckf2str(CK_ULONG flag)227 const char *token_ckf2str(CK_ULONG flag)
228 {
229 	switch (flag) {
230 	CK2STR_ENTRY(CKF_RNG);
231 	CK2STR_ENTRY(CKF_WRITE_PROTECTED);
232 	CK2STR_ENTRY(CKF_LOGIN_REQUIRED);
233 	CK2STR_ENTRY(CKF_USER_PIN_INITIALIZED);
234 	CK2STR_ENTRY(CKF_RESTORE_KEY_NOT_NEEDED);
235 	CK2STR_ENTRY(CKF_CLOCK_ON_TOKEN);
236 	CK2STR_ENTRY(CKF_PROTECTED_AUTHENTICATION_PATH);
237 	CK2STR_ENTRY(CKF_DUAL_CRYPTO_OPERATIONS);
238 	CK2STR_ENTRY(CKF_TOKEN_INITIALIZED);
239 	CK2STR_ENTRY(CKF_SECONDARY_AUTHENTICATION);
240 	CK2STR_ENTRY(CKF_USER_PIN_COUNT_LOW);
241 	CK2STR_ENTRY(CKF_USER_PIN_FINAL_TRY);
242 	CK2STR_ENTRY(CKF_USER_PIN_LOCKED);
243 	CK2STR_ENTRY(CKF_USER_PIN_TO_BE_CHANGED);
244 	CK2STR_ENTRY(CKF_SO_PIN_COUNT_LOW);
245 	CK2STR_ENTRY(CKF_SO_PIN_FINAL_TRY);
246 	CK2STR_ENTRY(CKF_SO_PIN_LOCKED);
247 	CK2STR_ENTRY(CKF_SO_PIN_TO_BE_CHANGED);
248 	CK2STR_ENTRY(CKF_ERROR_STATE);
249 	default:
250 		return "Unknown flag";
251 	}
252 }
253 
mecha_ckf2str(CK_ULONG flag)254 const char *mecha_ckf2str(CK_ULONG flag)
255 {
256 	switch (flag) {
257 	CK2STR_ENTRY(CKF_HW);
258 	CK2STR_ENTRY(CKF_ENCRYPT);
259 	CK2STR_ENTRY(CKF_DECRYPT);
260 	CK2STR_ENTRY(CKF_DIGEST);
261 	CK2STR_ENTRY(CKF_SIGN);
262 	CK2STR_ENTRY(CKF_SIGN_RECOVER);
263 	CK2STR_ENTRY(CKF_VERIFY);
264 	CK2STR_ENTRY(CKF_VERIFY_RECOVER);
265 	CK2STR_ENTRY(CKF_GENERATE);
266 	CK2STR_ENTRY(CKF_GENERATE_KEY_PAIR);
267 	CK2STR_ENTRY(CKF_WRAP);
268 	CK2STR_ENTRY(CKF_UNWRAP);
269 	CK2STR_ENTRY(CKF_DERIVE);
270 	CK2STR_ENTRY(CKF_EC_F_P);
271 	CK2STR_ENTRY(CKF_EC_F_2M);
272 	CK2STR_ENTRY(CKF_EC_ECPARAMETERS);
273 	CK2STR_ENTRY(CKF_EC_NAMEDCURVE);
274 	CK2STR_ENTRY(CKF_EC_UNCOMPRESS);
275 	CK2STR_ENTRY(CKF_EC_COMPRESS);
276 	CK2STR_ENTRY(CKF_EXTENSION);
277 	default:
278 		return "Unknown flag";
279 	}
280 }
281 
session_ckf2str(CK_ULONG flag)282 const char *session_ckf2str(CK_ULONG flag)
283 {
284 	switch (flag) {
285 	CK2STR_ENTRY(CKF_RW_SESSION);
286 	CK2STR_ENTRY(CKF_SERIAL_SESSION);
287 	default:
288 		return "Unknown flag";
289 	}
290 }
291 
session_cks2str(CK_ULONG flag)292 const char *session_cks2str(CK_ULONG flag)
293 {
294 	switch (flag) {
295 	CK2STR_ENTRY(CKS_RO_PUBLIC_SESSION);
296 	CK2STR_ENTRY(CKS_RO_USER_FUNCTIONS);
297 	CK2STR_ENTRY(CKS_RW_PUBLIC_SESSION);
298 	CK2STR_ENTRY(CKS_RW_USER_FUNCTIONS);
299 	CK2STR_ENTRY(CKS_RW_SO_FUNCTIONS);
300 	default:
301 		return "Unknown flag";
302 	}
303 }
304 
cka2str(CK_ATTRIBUTE_TYPE id)305 const char *cka2str(CK_ATTRIBUTE_TYPE id)
306 {
307 	switch (id) {
308 	/* Standard CK attributes */
309 	CK2STR_ENTRY(CKA_CLASS);
310 	CK2STR_ENTRY(CKA_TOKEN);
311 	CK2STR_ENTRY(CKA_PRIVATE);
312 	CK2STR_ENTRY(CKA_LABEL);
313 	CK2STR_ENTRY(CKA_APPLICATION);
314 	CK2STR_ENTRY(CKA_VALUE);
315 	CK2STR_ENTRY(CKA_OBJECT_ID);
316 	CK2STR_ENTRY(CKA_CERTIFICATE_TYPE);
317 	CK2STR_ENTRY(CKA_ISSUER);
318 	CK2STR_ENTRY(CKA_SERIAL_NUMBER);
319 	CK2STR_ENTRY(CKA_AC_ISSUER);
320 	CK2STR_ENTRY(CKA_OWNER);
321 	CK2STR_ENTRY(CKA_ATTR_TYPES);
322 	CK2STR_ENTRY(CKA_TRUSTED);
323 	CK2STR_ENTRY(CKA_CERTIFICATE_CATEGORY);
324 	CK2STR_ENTRY(CKA_JAVA_MIDP_SECURITY_DOMAIN);
325 	CK2STR_ENTRY(CKA_URL);
326 	CK2STR_ENTRY(CKA_HASH_OF_SUBJECT_PUBLIC_KEY);
327 	CK2STR_ENTRY(CKA_HASH_OF_ISSUER_PUBLIC_KEY);
328 	CK2STR_ENTRY(CKA_NAME_HASH_ALGORITHM);
329 	CK2STR_ENTRY(CKA_CHECK_VALUE);
330 	CK2STR_ENTRY(CKA_KEY_TYPE);
331 	CK2STR_ENTRY(CKA_SUBJECT);
332 	CK2STR_ENTRY(CKA_ID);
333 	CK2STR_ENTRY(CKA_SENSITIVE);
334 	CK2STR_ENTRY(CKA_ENCRYPT);
335 	CK2STR_ENTRY(CKA_DECRYPT);
336 	CK2STR_ENTRY(CKA_WRAP);
337 	CK2STR_ENTRY(CKA_UNWRAP);
338 	CK2STR_ENTRY(CKA_SIGN);
339 	CK2STR_ENTRY(CKA_SIGN_RECOVER);
340 	CK2STR_ENTRY(CKA_VERIFY);
341 	CK2STR_ENTRY(CKA_VERIFY_RECOVER);
342 	CK2STR_ENTRY(CKA_DERIVE);
343 	CK2STR_ENTRY(CKA_START_DATE);
344 	CK2STR_ENTRY(CKA_END_DATE);
345 	CK2STR_ENTRY(CKA_MODULUS);
346 	CK2STR_ENTRY(CKA_MODULUS_BITS);
347 	CK2STR_ENTRY(CKA_PUBLIC_EXPONENT);
348 	CK2STR_ENTRY(CKA_PRIVATE_EXPONENT);
349 	CK2STR_ENTRY(CKA_PRIME_1);
350 	CK2STR_ENTRY(CKA_PRIME_2);
351 	CK2STR_ENTRY(CKA_EXPONENT_1);
352 	CK2STR_ENTRY(CKA_EXPONENT_2);
353 	CK2STR_ENTRY(CKA_COEFFICIENT);
354 	CK2STR_ENTRY(CKA_PUBLIC_KEY_INFO);
355 	CK2STR_ENTRY(CKA_PRIME);
356 	CK2STR_ENTRY(CKA_SUBPRIME);
357 	CK2STR_ENTRY(CKA_BASE);
358 	CK2STR_ENTRY(CKA_PRIME_BITS);
359 	CK2STR_ENTRY(CKA_SUBPRIME_BITS);
360 	CK2STR_ENTRY(CKA_VALUE_BITS);
361 	CK2STR_ENTRY(CKA_VALUE_LEN);
362 	CK2STR_ENTRY(CKA_EXTRACTABLE);
363 	CK2STR_ENTRY(CKA_LOCAL);
364 	CK2STR_ENTRY(CKA_NEVER_EXTRACTABLE);
365 	CK2STR_ENTRY(CKA_ALWAYS_SENSITIVE);
366 	CK2STR_ENTRY(CKA_KEY_GEN_MECHANISM);
367 	CK2STR_ENTRY(CKA_MODIFIABLE);
368 	CK2STR_ENTRY(CKA_COPYABLE);
369 	CK2STR_ENTRY(CKA_DESTROYABLE);
370 	CK2STR_ENTRY(CKA_EC_PARAMS);
371 	CK2STR_ENTRY(CKA_EC_POINT);
372 	CK2STR_ENTRY(CKA_ALWAYS_AUTHENTICATE);
373 	CK2STR_ENTRY(CKA_WRAP_WITH_TRUSTED);
374 	CK2STR_ENTRY(CKA_WRAP_TEMPLATE);
375 	CK2STR_ENTRY(CKA_UNWRAP_TEMPLATE);
376 	CK2STR_ENTRY(CKA_DERIVE_TEMPLATE);
377 	CK2STR_ENTRY(CKA_OTP_FORMAT);
378 	CK2STR_ENTRY(CKA_OTP_LENGTH);
379 	CK2STR_ENTRY(CKA_OTP_TIME_INTERVAL);
380 	CK2STR_ENTRY(CKA_OTP_USER_FRIENDLY_MODE);
381 	CK2STR_ENTRY(CKA_OTP_CHALLENGE_REQUIREMENT);
382 	CK2STR_ENTRY(CKA_OTP_TIME_REQUIREMENT);
383 	CK2STR_ENTRY(CKA_OTP_COUNTER_REQUIREMENT);
384 	CK2STR_ENTRY(CKA_OTP_PIN_REQUIREMENT);
385 	CK2STR_ENTRY(CKA_OTP_COUNTER);
386 	CK2STR_ENTRY(CKA_OTP_TIME);
387 	CK2STR_ENTRY(CKA_OTP_USER_IDENTIFIER);
388 	CK2STR_ENTRY(CKA_OTP_SERVICE_IDENTIFIER);
389 	CK2STR_ENTRY(CKA_OTP_SERVICE_LOGO);
390 	CK2STR_ENTRY(CKA_OTP_SERVICE_LOGO_TYPE);
391 	CK2STR_ENTRY(CKA_GOSTR3410_PARAMS);
392 	CK2STR_ENTRY(CKA_GOSTR3411_PARAMS);
393 	CK2STR_ENTRY(CKA_GOST28147_PARAMS);
394 	CK2STR_ENTRY(CKA_HW_FEATURE_TYPE);
395 	CK2STR_ENTRY(CKA_RESET_ON_INIT);
396 	CK2STR_ENTRY(CKA_HAS_RESET);
397 	CK2STR_ENTRY(CKA_PIXEL_X);
398 	CK2STR_ENTRY(CKA_PIXEL_Y);
399 	CK2STR_ENTRY(CKA_RESOLUTION);
400 	CK2STR_ENTRY(CKA_CHAR_ROWS);
401 	CK2STR_ENTRY(CKA_CHAR_COLUMNS);
402 	CK2STR_ENTRY(CKA_COLOR);
403 	CK2STR_ENTRY(CKA_BITS_PER_PIXEL);
404 	CK2STR_ENTRY(CKA_CHAR_SETS);
405 	CK2STR_ENTRY(CKA_ENCODING_METHODS);
406 	CK2STR_ENTRY(CKA_MIME_TYPES);
407 	CK2STR_ENTRY(CKA_MECHANISM_TYPE);
408 	CK2STR_ENTRY(CKA_REQUIRED_CMS_ATTRIBUTES);
409 	CK2STR_ENTRY(CKA_DEFAULT_CMS_ATTRIBUTES);
410 	CK2STR_ENTRY(CKA_SUPPORTED_CMS_ATTRIBUTES);
411 	CK2STR_ENTRY(CKA_ALLOWED_MECHANISMS);
412 	CK2STR_ENTRY(CKA_VENDOR_DEFINED);
413 	default:
414 		if (id & CKA_VENDOR_DEFINED)
415 			return "Vendor defined";
416 		else
417 			return "Unknown ID";
418 	}
419 }
420 
cko2str(CK_OBJECT_CLASS id)421 const char *cko2str(CK_OBJECT_CLASS id)
422 {
423 	switch (id) {
424 	CK2STR_ENTRY(CKO_DATA);
425 	CK2STR_ENTRY(CKO_CERTIFICATE);
426 	CK2STR_ENTRY(CKO_PUBLIC_KEY);
427 	CK2STR_ENTRY(CKO_PRIVATE_KEY);
428 	CK2STR_ENTRY(CKO_SECRET_KEY);
429 	CK2STR_ENTRY(CKO_HW_FEATURE);
430 	CK2STR_ENTRY(CKO_DOMAIN_PARAMETERS);
431 	CK2STR_ENTRY(CKO_MECHANISM);
432 	CK2STR_ENTRY(CKO_OTP_KEY);
433 	CK2STR_ENTRY(CKO_VENDOR_DEFINED);
434 	default:
435 		return "Unknown";
436 	}
437 }
438 
ckk2str(CK_KEY_TYPE id)439 const char *ckk2str(CK_KEY_TYPE id)
440 {
441 	switch (id) {
442 	CK2STR_ENTRY(CKK_RSA);
443 	CK2STR_ENTRY(CKK_DSA);
444 	CK2STR_ENTRY(CKK_DH);
445 	CK2STR_ENTRY(CKK_ECDSA);
446 	CK2STR_ENTRY(CKK_GENERIC_SECRET);
447 	CK2STR_ENTRY(CKK_DES3);
448 	CK2STR_ENTRY(CKK_AES);
449 	CK2STR_ENTRY(CKK_HOTP);
450 	CK2STR_ENTRY(CKK_MD5_HMAC);
451 	CK2STR_ENTRY(CKK_SHA_1_HMAC);
452 	CK2STR_ENTRY(CKK_SHA256_HMAC);
453 	CK2STR_ENTRY(CKK_SHA384_HMAC);
454 	CK2STR_ENTRY(CKK_SHA512_HMAC);
455 	CK2STR_ENTRY(CKK_SHA224_HMAC);
456 	CK2STR_ENTRY(CKK_VENDOR_DEFINED);
457 	default:
458 		return "Unknown";
459 	}
460 }
461