xref: /titanic_52/usr/src/lib/libcryptoutil/common/pkcserror.c (revision d58fda4376e4bf67072ce2e69f6f47036f9dbb68)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * Block comment which describes the contents of this file.
31  */
32 
33 #include <stdio.h>
34 #include <security/cryptoki.h>
35 
36 /*
37  * pkcs11_strerror: returns a string representation of the given return code.
38  * The string returned is static pointer.  It doesn't need to be free'd
39  * by the caller.
40  */
41 char *
42 pkcs11_strerror(CK_RV rv)
43 {
44 	static char errstr[128];
45 
46 	switch (rv) {
47 		case CKR_OK:
48 			return ("CKR_OK");
49 			break;
50 		case CKR_CANCEL:
51 			return ("CKR_CANCEL");
52 			break;
53 		case CKR_HOST_MEMORY:
54 			return ("CKR_HOST_MEMORY");
55 			break;
56 		case CKR_SLOT_ID_INVALID:
57 			return ("CKR_SLOT_ID_INVALID");
58 			break;
59 		case CKR_GENERAL_ERROR:
60 			return ("CKR_GENERAL_ERROR");
61 			break;
62 		case CKR_FUNCTION_FAILED:
63 			return ("CKR_FUNCTION_FAILED");
64 			break;
65 		case CKR_ARGUMENTS_BAD:
66 			return ("CKR_ARGUMENTS_BAD");
67 			break;
68 		case CKR_NO_EVENT:
69 			return ("CKR_NO_EVENT");
70 			break;
71 		case CKR_NEED_TO_CREATE_THREADS:
72 			return ("CKR_NEED_TO_CREATE_THREADS");
73 			break;
74 		case CKR_CANT_LOCK:
75 			return ("CKR_CANT_LOCK");
76 			break;
77 		case CKR_ATTRIBUTE_READ_ONLY:
78 			return ("CKR_ATTRIBUTE_READ_ONLY");
79 			break;
80 		case CKR_ATTRIBUTE_SENSITIVE:
81 			return ("CKR_ATTRIBUTE_SENSITIVE");
82 			break;
83 		case CKR_ATTRIBUTE_TYPE_INVALID:
84 			return ("CKR_ATTRIBUTE_TYPE_INVALID");
85 			break;
86 		case CKR_ATTRIBUTE_VALUE_INVALID:
87 			return ("CKR_ATTRIBUTE_VALUE_INVALID");
88 			break;
89 		case CKR_DATA_INVALID:
90 			return ("CKR_DATA_INVALID");
91 			break;
92 		case CKR_DATA_LEN_RANGE:
93 			return ("CKR_DATA_LEN_RANGE");
94 			break;
95 		case CKR_DEVICE_ERROR:
96 			return ("CKR_DEVICE_ERROR");
97 			break;
98 		case CKR_DEVICE_MEMORY:
99 			return ("CKR_DEVICE_MEMORY");
100 			break;
101 		case CKR_DEVICE_REMOVED:
102 			return ("CKR_DEVICE_REMOVED");
103 			break;
104 		case CKR_ENCRYPTED_DATA_INVALID:
105 			return ("CKR_ENCRYPTED_DATA_INVALID");
106 			break;
107 		case CKR_ENCRYPTED_DATA_LEN_RANGE:
108 			return ("CKR_ENCRYPTED_DATA_LEN_RANGE");
109 			break;
110 		case CKR_FUNCTION_CANCELED:
111 			return ("CKR_FUNCTION_CANCELED");
112 			break;
113 		case CKR_FUNCTION_NOT_PARALLEL:
114 			return ("CKR_FUNCTION_NOT_PARALLEL");
115 			break;
116 		case CKR_FUNCTION_NOT_SUPPORTED:
117 			return ("CKR_FUNCTION_NOT_SUPPORTED");
118 			break;
119 		case CKR_KEY_HANDLE_INVALID:
120 			return ("CKR_KEY_HANDLE_INVALID");
121 			break;
122 		case CKR_KEY_SIZE_RANGE:
123 			return ("CKR_KEY_SIZE_RANGE");
124 			break;
125 		case CKR_KEY_TYPE_INCONSISTENT:
126 			return ("CKR_KEY_TYPE_INCONSISTENT");
127 			break;
128 		case CKR_KEY_NOT_NEEDED:
129 			return ("CKR_KEY_NOT_NEEDED");
130 			break;
131 		case CKR_KEY_CHANGED:
132 			return ("CKR_KEY_CHANGED");
133 			break;
134 		case CKR_KEY_NEEDED:
135 			return ("CKR_KEY_NEEDED");
136 			break;
137 		case CKR_KEY_INDIGESTIBLE:
138 			return ("CKR_KEY_INDIGESTIBLE");
139 			break;
140 		case CKR_KEY_FUNCTION_NOT_PERMITTED:
141 			return ("CKR_KEY_FUNCTION_NOT_PERMITTED");
142 			break;
143 		case CKR_KEY_NOT_WRAPPABLE:
144 			return ("CKR_KEY_NOT_WRAPPABLE");
145 			break;
146 		case CKR_KEY_UNEXTRACTABLE:
147 			return ("CKR_KEY_UNEXTRACTABLE");
148 			break;
149 		case CKR_MECHANISM_INVALID:
150 			return ("CKR_MECHANISM_INVALID");
151 			break;
152 		case CKR_MECHANISM_PARAM_INVALID:
153 			return ("CKR_MECHANISM_PARAM_INVALID");
154 			break;
155 		case CKR_OBJECT_HANDLE_INVALID:
156 			return ("CKR_OBJECT_HANDLE_INVALID");
157 			break;
158 		case CKR_OPERATION_ACTIVE:
159 			return ("CKR_OPERATION_ACTIVE");
160 			break;
161 		case CKR_OPERATION_NOT_INITIALIZED:
162 			return ("CKR_OPERATION_NOT_INITIALIZED");
163 			break;
164 		case CKR_PIN_INCORRECT:
165 			return ("CKR_PIN_INCORRECT");
166 			break;
167 		case CKR_PIN_INVALID:
168 			return ("CKR_PIN_INVALID");
169 			break;
170 		case CKR_PIN_LEN_RANGE:
171 			return ("CKR_PIN_LEN_RANGE");
172 			break;
173 		case CKR_PIN_EXPIRED:
174 			return ("CKR_PIN_EXPIRED");
175 			break;
176 		case CKR_PIN_LOCKED:
177 			return ("CKR_PIN_LOCKED");
178 			break;
179 		case CKR_SESSION_CLOSED:
180 			return ("CKR_SESSION_CLOSED");
181 			break;
182 		case CKR_SESSION_COUNT:
183 			return ("CKR_SESSION_COUNT");
184 			break;
185 		case CKR_SESSION_HANDLE_INVALID:
186 			return ("CKR_SESSION_HANDLE_INVALID");
187 			break;
188 		case CKR_SESSION_PARALLEL_NOT_SUPPORTED:
189 			return ("CKR_SESSION_PARALLEL_NOT_SUPPORTED");
190 			break;
191 		case CKR_SESSION_READ_ONLY:
192 			return ("CKR_SESSION_READ_ONLY");
193 			break;
194 		case CKR_SESSION_EXISTS:
195 			return ("CKR_SESSION_EXISTS");
196 			break;
197 		case CKR_SESSION_READ_ONLY_EXISTS:
198 			return ("CKR_SESSION_READ_ONLY_EXISTS");
199 			break;
200 		case CKR_SESSION_READ_WRITE_SO_EXISTS:
201 			return ("CKR_SESSION_READ_WRITE_SO_EXISTS");
202 			break;
203 		case CKR_SIGNATURE_INVALID:
204 			return ("CKR_SIGNATURE_INVALID");
205 			break;
206 		case CKR_SIGNATURE_LEN_RANGE:
207 			return ("CKR_SIGNATURE_LEN_RANGE");
208 			break;
209 		case CKR_TEMPLATE_INCOMPLETE:
210 			return ("CKR_TEMPLATE_INCOMPLETE");
211 			break;
212 		case CKR_TEMPLATE_INCONSISTENT:
213 			return ("CKR_TEMPLATE_INCONSISTENT");
214 			break;
215 		case CKR_TOKEN_NOT_PRESENT:
216 			return ("CKR_TOKEN_NOT_PRESENT");
217 			break;
218 		case CKR_TOKEN_NOT_RECOGNIZED:
219 			return ("CKR_TOKEN_NOT_RECOGNIZED");
220 			break;
221 		case CKR_TOKEN_WRITE_PROTECTED:
222 			return ("CKR_TOKEN_WRITE_PROTECTED");
223 			break;
224 		case CKR_UNWRAPPING_KEY_HANDLE_INVALID:
225 			return ("CKR_UNWRAPPING_KEY_HANDLE_INVALID");
226 			break;
227 		case CKR_UNWRAPPING_KEY_SIZE_RANGE:
228 			return ("CKR_UNWRAPPING_KEY_SIZE_RANGE");
229 			break;
230 		case CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT:
231 			return ("CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT");
232 			break;
233 		case CKR_USER_ALREADY_LOGGED_IN:
234 			return ("CKR_USER_ALREADY_LOGGED_IN");
235 			break;
236 		case CKR_USER_NOT_LOGGED_IN:
237 			return ("CKR_USER_NOT_LOGGED_IN");
238 			break;
239 		case CKR_USER_PIN_NOT_INITIALIZED:
240 			return ("CKR_USER_PIN_NOT_INITIALIZED");
241 			break;
242 		case CKR_USER_TYPE_INVALID:
243 			return ("CKR_USER_TYPE_INVALID");
244 			break;
245 		case CKR_USER_ANOTHER_ALREADY_LOGGED_IN:
246 			return ("CKR_USER_ANOTHER_ALREADY_LOGGED_IN");
247 			break;
248 		case CKR_USER_TOO_MANY_TYPES:
249 			return ("CKR_USER_TOO_MANY_TYPES");
250 			break;
251 		case CKR_WRAPPED_KEY_INVALID:
252 			return ("CKR_WRAPPED_KEY_INVALID");
253 			break;
254 		case CKR_WRAPPED_KEY_LEN_RANGE:
255 			return ("CKR_WRAPPED_KEY_LEN_RANGE");
256 			break;
257 		case CKR_WRAPPING_KEY_HANDLE_INVALID:
258 			return ("CKR_WRAPPING_KEY_HANDLE_INVALID");
259 			break;
260 		case CKR_WRAPPING_KEY_SIZE_RANGE:
261 			return ("CKR_WRAPPING_KEY_SIZE_RANGE");
262 			break;
263 		case CKR_WRAPPING_KEY_TYPE_INCONSISTENT:
264 			return ("CKR_WRAPPING_KEY_TYPE_INCONSISTENT");
265 			break;
266 		case CKR_RANDOM_SEED_NOT_SUPPORTED:
267 			return ("CKR_RANDOM_SEED_NOT_SUPPORTED");
268 			break;
269 		case CKR_RANDOM_NO_RNG:
270 			return ("CKR_RANDOM_NO_RNG");
271 			break;
272 		case CKR_DOMAIN_PARAMS_INVALID:
273 			return ("CKR_DOMAIN_PARAMS_INVALID");
274 			break;
275 		case CKR_BUFFER_TOO_SMALL:
276 			return ("CKR_BUFFER_TOO_SMALL");
277 			break;
278 		case CKR_SAVED_STATE_INVALID:
279 			return ("CKR_SAVED_STATE_INVALID");
280 			break;
281 		case CKR_INFORMATION_SENSITIVE:
282 			return ("CKR_INFORMATION_SENSITIVE");
283 			break;
284 		case CKR_STATE_UNSAVEABLE:
285 			return ("CKR_STATE_UNSAVEABLE");
286 			break;
287 		case CKR_CRYPTOKI_NOT_INITIALIZED:
288 			return ("CKR_CRYPTOKI_NOT_INITIALIZED");
289 			break;
290 		case CKR_CRYPTOKI_ALREADY_INITIALIZED:
291 			return ("CKR_CRYPTOKI_ALREADY_INITIALIZED");
292 			break;
293 		case CKR_MUTEX_BAD:
294 			return ("CKR_MUTEX_BAD");
295 			break;
296 		case CKR_MUTEX_NOT_LOCKED:
297 			return ("CKR_MUTEX_NOT_LOCKED");
298 			break;
299 		case CKR_VENDOR_DEFINED:
300 			return ("CKR_VENDOR_DEFINED");
301 			break;
302 		default:
303 			/* rv not found */
304 			(void) snprintf(errstr, sizeof (errstr),
305 			    "Unknown return code: 0x%lx", rv);
306 			return (errstr);
307 			break;
308 	}
309 }
310