3 * Copyright (C) 2006-2014 wolfSSL Inc.
5 * This file is part of CyaSSL.
7 * CyaSSL is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * CyaSSL is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 #include <cyassl/ctaocrypt/settings.h>
28 #include <cyassl/ctaocrypt/error-crypt.h>
31 /* 4996 warning to use MS extensions e.g., strcpy_s instead of XSTRNCPY */
32 #pragma warning(disable: 4996)
35 const char* CTaoCryptGetErrorString(int error)
37 #ifdef NO_ERROR_STRINGS
40 return "no support for error strings built in";
47 return "opening random device error";
50 return "reading random device error";
53 return "windows crypt init error";
56 return "windows crypt generation error";
59 return "random device read would block error";
62 return "Bad mutex, operation failed";
65 return "mp_init error state";
68 return "mp_read error state";
71 return "mp_exptmod error state";
74 return "mp_to_xxx error state, can't convert";
77 return "mp_sub error state, can't subtract";
80 return "mp_add error state, can't add";
83 return "mp_mul error state, can't multiply";
86 return "mp_mulmod error state, can't multiply mod";
89 return "mp_mod error state, can't mod";
92 return "mp_invmod error state, can't inv mod";
95 return "mp_cmp error state";
98 return "mp zero result, not expected";
101 return "out of memory error";
103 case RSA_WRONG_TYPE_E :
104 return "RSA wrong block type for RSA function";
107 return "RSA buffer error, output too small or input too big";
110 return "Buffer error, output too small or input too big";
113 return "Setting Cert AlogID error";
116 return "Setting Cert Public Key error";
119 return "Setting Cert Date validity error";
122 return "Setting Cert Subject name error";
125 return "Setting Cert Issuer name error";
128 return "Setting basic constraint CA true error";
131 return "Setting extensions error";
134 return "ASN parsing error, invalid input";
137 return "ASN version error, invalid number";
140 return "ASN get big int error, invalid data";
143 return "ASN key init error, invalid input";
145 case ASN_OBJECT_ID_E :
146 return "ASN object id error, invalid id";
148 case ASN_TAG_NULL_E :
149 return "ASN tag error, not null";
151 case ASN_EXPECT_0_E :
152 return "ASN expect error, not zero";
155 return "ASN bit string error, wrong id";
157 case ASN_UNKNOWN_OID_E :
158 return "ASN oid error, unknown sum id";
161 return "ASN date error, bad size";
163 case ASN_BEFORE_DATE_E :
164 return "ASN date error, current date before";
166 case ASN_AFTER_DATE_E :
167 return "ASN date error, current date after";
170 return "ASN signature error, mismatched oid";
173 return "ASN time error, unkown time type";
176 return "ASN input error, not enough data";
178 case ASN_SIG_CONFIRM_E :
179 return "ASN sig error, confirm failure";
181 case ASN_SIG_HASH_E :
182 return "ASN sig error, unsupported hash type";
185 return "ASN sig error, unsupported key type";
188 return "ASN key init error, invalid input";
190 case ASN_NTRU_KEY_E :
191 return "ASN NTRU key decode error, invalid input";
194 return "X.509 Critical extension ignored";
197 return "ECC input argument wrong type, invalid input";
200 return "ECC ASN1 bad key data, invalid input";
202 case ECC_CURVE_OID_E :
203 return "ECC curve sum OID unsupported, invalid input";
206 return "Bad function argument";
208 case NOT_COMPILED_IN :
209 return "Feature not compiled in";
211 case UNICODE_SIZE_E :
212 return "Unicode password too big";
215 return "No password provided by user";
218 return "Alt Name problem, too big";
221 return "AES-GCM Authentication check fail";
224 return "AES-CCM Authentication check fail";
227 return "Cavium Init type error";
229 case COMPRESS_INIT_E:
230 return "Compress Init error";
233 return "Compress error";
235 case DECOMPRESS_INIT_E:
236 return "DeCompress Init error";
239 return "DeCompress error";
242 return "Bad alignment error, no alloc help";
244 case ASN_NO_SIGNER_E :
245 return "ASN no signer error to confirm failure";
247 case ASN_CRL_CONFIRM_E :
248 return "ASN CRL sig error, confirm failure";
250 case ASN_CRL_NO_SIGNER_E :
251 return "ASN CRL no signer error to confirm failure";
253 case ASN_OCSP_CONFIRM_E :
254 return "ASN OCSP sig error, confirm failure";
256 case BAD_ENC_STATE_E:
257 return "Bad ecc encrypt state operation";
260 return "Bad padding, message wrong length";
262 case REQ_ATTRIBUTE_E:
263 return "Setting cert request attributes error";
266 return "PKCS#7 error: mismatched OID value";
269 return "PKCS#7 error: no matching recipient found";
271 case FIPS_NOT_ALLOWED_E:
272 return "FIPS mode not allowed error";
274 case ASN_NAME_INVALID_E:
275 return "Name Constraint error";
278 return "Random Number Generator failed";
280 case HMAC_MIN_KEYLEN_E:
281 return "FIPS Mode HMAC Minimum Key Length error";
284 return "unknown error number";
288 #endif /* NO_ERROR_STRINGS */
292 void CTaoCryptErrorString(int error, char* buffer)
294 XSTRNCPY(buffer, CTaoCryptGetErrorString(error), CYASSL_MAX_ERROR_SZ);