PageRenderTime 50ms CodeModel.GetById 29ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/ctaocrypt/src/error.c

https://github.com/andersmalm/cyassl
C | 291 lines | 198 code | 72 blank | 21 comment | 1 complexity | fab77272a5a1ce0fc635263f6fb17442 MD5 | raw file
  1/* error.c
  2 *
  3 * Copyright (C) 2006-2012 Sawtooth Consulting Ltd.
  4 *
  5 * This file is part of CyaSSL.
  6 *
  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.
 11 *
 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.
 16 *
 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 20 */
 21
 22#ifdef HAVE_CONFIG_H
 23    #include <config.h>
 24#endif
 25 
 26#include <cyassl/ctaocrypt/error.h>
 27
 28#ifdef _MSC_VER
 29    /* 4996 warning to use MS extensions e.g., strcpy_s instead of XSTRNCPY */
 30    #pragma warning(disable: 4996)
 31#endif
 32
 33
 34void CTaoCryptErrorString(int error, char* buffer)
 35{
 36    const int max = MAX_ERROR_SZ;   /* shorthand */
 37
 38#ifdef NO_ERROR_STRINGS
 39
 40    (void)error;
 41    XSTRNCPY(buffer, "no support for error strings built in", max);
 42
 43#else
 44
 45    switch (error) {
 46
 47    case OPEN_RAN_E :        
 48        XSTRNCPY(buffer, "opening random device error", max);
 49        break;
 50
 51    case READ_RAN_E :
 52        XSTRNCPY(buffer, "reading random device error", max);
 53        break;
 54
 55    case WINCRYPT_E :
 56        XSTRNCPY(buffer, "windows crypt init error", max);
 57        break;
 58
 59    case CRYPTGEN_E : 
 60        XSTRNCPY(buffer, "windows crypt generation error", max);
 61        break;
 62
 63    case RAN_BLOCK_E : 
 64        XSTRNCPY(buffer, "random device read would block error", max);
 65        break;
 66
 67    case MP_INIT_E :
 68        XSTRNCPY(buffer, "mp_init error state", max);
 69        break;
 70
 71    case MP_READ_E :
 72        XSTRNCPY(buffer, "mp_read error state", max);
 73        break;
 74
 75    case MP_EXPTMOD_E :
 76        XSTRNCPY(buffer, "mp_exptmod error state", max);
 77        break;
 78
 79    case MP_TO_E :
 80        XSTRNCPY(buffer, "mp_to_xxx error state, can't convert", max);
 81        break;
 82
 83    case MP_SUB_E :
 84        XSTRNCPY(buffer, "mp_sub error state, can't subtract", max);
 85        break;
 86
 87    case MP_ADD_E :
 88        XSTRNCPY(buffer, "mp_add error state, can't add", max);
 89        break;
 90
 91    case MP_MUL_E :
 92        XSTRNCPY(buffer, "mp_mul error state, can't multiply", max);
 93        break;
 94
 95    case MP_MULMOD_E :
 96        XSTRNCPY(buffer, "mp_mulmod error state, can't multiply mod", max);
 97        break;
 98
 99    case MP_MOD_E :
100        XSTRNCPY(buffer, "mp_mod error state, can't mod", max);
101        break;
102
103    case MP_INVMOD_E :
104        XSTRNCPY(buffer, "mp_invmod error state, can't inv mod", max);
105        break; 
106        
107    case MP_CMP_E :
108        XSTRNCPY(buffer, "mp_cmp error state", max);
109        break; 
110        
111    case MP_ZERO_E :
112        XSTRNCPY(buffer, "mp zero result, not expected", max);
113        break; 
114        
115    case MEMORY_E :
116        XSTRNCPY(buffer, "out of memory error", max);
117        break;
118
119    case RSA_WRONG_TYPE_E :
120        XSTRNCPY(buffer, "RSA wrong block type for RSA function", max);
121        break; 
122
123    case RSA_BUFFER_E :
124        XSTRNCPY(buffer, "RSA buffer error, output too small or input too big",
125                max);
126        break; 
127
128    case BUFFER_E :
129        XSTRNCPY(buffer, "Buffer error, output too small or input too big",max);
130        break; 
131
132    case ALGO_ID_E :
133        XSTRNCPY(buffer, "Setting Cert AlogID error", max);
134        break; 
135
136    case PUBLIC_KEY_E :
137        XSTRNCPY(buffer, "Setting Cert Public Key error", max);
138        break; 
139
140    case DATE_E :
141        XSTRNCPY(buffer, "Setting Cert Date validity error", max);
142        break; 
143
144    case SUBJECT_E :
145        XSTRNCPY(buffer, "Setting Cert Subject name error", max);
146        break; 
147
148    case ISSUER_E :
149        XSTRNCPY(buffer, "Setting Cert Issuer name error", max);
150        break; 
151
152    case CA_TRUE_E :
153        XSTRNCPY(buffer, "Setting basic constraint CA true error", max);
154        break; 
155
156    case EXTENSIONS_E :
157        XSTRNCPY(buffer, "Setting extensions error", max);
158        break; 
159
160    case ASN_PARSE_E :
161        XSTRNCPY(buffer, "ASN parsing error, invalid input", max);
162        break;
163
164    case ASN_VERSION_E :
165        XSTRNCPY(buffer, "ASN version error, invalid number", max);
166        break;
167
168    case ASN_GETINT_E :
169        XSTRNCPY(buffer, "ASN get big int error, invalid data", max);
170        break;
171
172    case ASN_RSA_KEY_E :
173        XSTRNCPY(buffer, "ASN key init error, invalid input", max);
174        break;
175
176    case ASN_OBJECT_ID_E :
177        XSTRNCPY(buffer, "ASN object id error, invalid id", max);
178        break;
179
180    case ASN_TAG_NULL_E :
181        XSTRNCPY(buffer, "ASN tag error, not null", max);
182        break;
183
184    case ASN_EXPECT_0_E :
185        XSTRNCPY(buffer, "ASN expect error, not zero", max);
186        break;
187
188    case ASN_BITSTR_E :
189        XSTRNCPY(buffer, "ASN bit string error, wrong id", max);
190        break;
191
192    case ASN_UNKNOWN_OID_E :
193        XSTRNCPY(buffer, "ASN oid error, unknown sum id", max);
194        break;
195
196    case ASN_DATE_SZ_E :
197        XSTRNCPY(buffer, "ASN date error, bad size", max);
198        break;
199
200    case ASN_BEFORE_DATE_E :
201        XSTRNCPY(buffer, "ASN date error, current date before", max);
202        break;
203
204    case ASN_AFTER_DATE_E :
205        XSTRNCPY(buffer, "ASN date error, current date after", max);
206        break;
207
208    case ASN_SIG_OID_E :
209        XSTRNCPY(buffer, "ASN signature error, mismatched oid", max);
210        break;
211
212    case ASN_TIME_E :
213        XSTRNCPY(buffer, "ASN time error, unkown time type", max);
214        break;
215
216    case ASN_INPUT_E :
217        XSTRNCPY(buffer, "ASN input error, not enough data", max);
218        break;
219
220    case ASN_SIG_CONFIRM_E :
221        XSTRNCPY(buffer, "ASN sig error, confirm failure", max);
222        break;
223
224    case ASN_SIG_HASH_E :
225        XSTRNCPY(buffer, "ASN sig error, unsupported hash type", max);
226        break;
227
228    case ASN_SIG_KEY_E :
229        XSTRNCPY(buffer, "ASN sig error, unsupported key type", max);
230        break;
231
232    case ASN_DH_KEY_E :
233        XSTRNCPY(buffer, "ASN key init error, invalid input", max);
234        break;
235
236    case ASN_NTRU_KEY_E :
237        XSTRNCPY(buffer, "ASN NTRU key decode error, invalid input", max);
238        break;
239
240    case ECC_BAD_ARG_E :
241        XSTRNCPY(buffer, "ECC input argument wrong type, invalid input", max);
242        break;
243
244    case ASN_ECC_KEY_E :
245        XSTRNCPY(buffer, "ECC ASN1 bad key data, invalid input", max);
246        break;
247
248    case ECC_CURVE_OID_E :
249        XSTRNCPY(buffer, "ECC curve sum OID unsupported, invalid input", max);
250        break;
251
252    case BAD_FUNC_ARG :
253        XSTRNCPY(buffer, "Bad function argument", max);
254        break;
255
256    case NOT_COMPILED_IN :
257        XSTRNCPY(buffer, "Feature not compiled in", max);
258        break;
259
260    case UNICODE_SIZE_E :
261        XSTRNCPY(buffer, "Unicode password too big", max);
262        break;
263
264    case NO_PASSWORD :
265        XSTRNCPY(buffer, "No password provided by user", max);
266        break;
267
268    case ALT_NAME_E :
269        XSTRNCPY(buffer, "Alt Name problem, too big", max);
270        break;
271
272    case AES_GCM_AUTH_E:
273        XSTRNCPY(buffer, "AES-GCM Authentication check fail", max);
274        break;
275
276    case AES_CCM_AUTH_E:
277        XSTRNCPY(buffer, "AES-CCM Authentication check fail", max);
278        break;
279
280    case CAVIUM_INIT_E:
281        XSTRNCPY(buffer, "Cavium Init type error", max);
282        break;
283
284    default:
285        XSTRNCPY(buffer, "unknown error number", max);
286
287    }
288
289#endif /* NO_ERROR_STRINGS */
290
291}