Coverage Report

Created: 2022-08-24 06:37

/src/wolfssl-sp-math-all-8bit/wolfcrypt/src/error.c
Line
Count
Source (jump to first uncovered line)
1
/* error.c
2
 *
3
 * Copyright (C) 2006-2022 wolfSSL Inc.
4
 *
5
 * This file is part of wolfSSL.
6
 *
7
 * wolfSSL 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
 * wolfSSL 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20
 */
21
22
23
#ifdef HAVE_CONFIG_H
24
    #include <config.h>
25
#endif
26
27
#include <wolfssl/wolfcrypt/settings.h>
28
29
#include <wolfssl/wolfcrypt/error-crypt.h>
30
31
#ifdef _MSC_VER
32
    /* 4996 warning to use MS extensions e.g., strcpy_s instead of XSTRNCPY */
33
    #pragma warning(disable: 4996)
34
#endif
35
36
#ifndef NO_ERROR_STRINGS
37
WOLFSSL_ABI
38
const char* wc_GetErrorString(int error)
39
0
{
40
0
    switch (error) {
41
42
0
    case OPEN_RAN_E :
43
0
        return "opening random device error";
44
45
0
    case READ_RAN_E :
46
0
        return "reading random device error";
47
48
0
    case WINCRYPT_E :
49
0
        return "windows crypt init error";
50
51
0
    case CRYPTGEN_E :
52
0
        return "windows crypt generation error";
53
54
0
    case RAN_BLOCK_E :
55
0
        return "random device read would block error";
56
57
0
    case BAD_MUTEX_E :
58
0
        return "Bad mutex, operation failed";
59
60
0
    case WC_TIMEOUT_E:
61
0
        return "Timeout error";
62
63
0
    case WC_PENDING_E:
64
0
        return "wolfCrypt Operation Pending (would block / eagain) error";
65
66
0
    case WC_NOT_PENDING_E:
67
0
        return "wolfCrypt operation not pending error";
68
69
0
    case MP_INIT_E :
70
0
        return "mp_init error state";
71
72
0
    case MP_READ_E :
73
0
        return "mp_read error state";
74
75
0
    case MP_EXPTMOD_E :
76
0
        return "mp_exptmod error state";
77
78
0
    case MP_TO_E :
79
0
        return "mp_to_xxx error state, can't convert";
80
81
0
    case MP_SUB_E :
82
0
        return "mp_sub error state, can't subtract";
83
84
0
    case MP_ADD_E :
85
0
        return "mp_add error state, can't add";
86
87
0
    case MP_MUL_E :
88
0
        return "mp_mul error state, can't multiply";
89
90
0
    case MP_MULMOD_E :
91
0
        return "mp_mulmod error state, can't multiply mod";
92
93
0
    case MP_MOD_E :
94
0
        return "mp_mod error state, can't mod";
95
96
0
    case MP_INVMOD_E :
97
0
        return "mp_invmod error state, can't inv mod";
98
99
0
    case MP_CMP_E :
100
0
        return "mp_cmp error state";
101
102
0
    case MP_ZERO_E :
103
0
        return "mp zero result, not expected";
104
105
0
    case MEMORY_E :
106
0
        return "out of memory error";
107
108
0
    case VAR_STATE_CHANGE_E :
109
0
        return "Variable state modified by different thread";
110
111
0
    case RSA_WRONG_TYPE_E :
112
0
        return "RSA wrong block type for RSA function";
113
114
0
    case RSA_BUFFER_E :
115
0
        return "RSA buffer error, output too small or input too big";
116
117
0
    case BUFFER_E :
118
0
        return "Buffer error, output too small or input too big";
119
120
0
    case ALGO_ID_E :
121
0
        return "Setting Cert AlgoID error";
122
123
0
    case PUBLIC_KEY_E :
124
0
        return "Setting Cert Public Key error";
125
126
0
    case DATE_E :
127
0
        return "Setting Cert Date validity error";
128
129
0
    case SUBJECT_E :
130
0
        return "Setting Cert Subject name error";
131
132
0
    case ISSUER_E :
133
0
        return "Setting Cert Issuer name error";
134
135
0
    case CA_TRUE_E :
136
0
        return "Setting basic constraint CA true error";
137
138
0
    case EXTENSIONS_E :
139
0
        return "Setting extensions error";
140
141
0
    case ASN_PARSE_E :
142
0
        return "ASN parsing error, invalid input";
143
144
0
    case ASN_VERSION_E :
145
0
        return "ASN version error, invalid number";
146
147
0
    case ASN_GETINT_E :
148
0
        return "ASN get big int error, invalid data";
149
150
0
    case ASN_RSA_KEY_E :
151
0
        return "ASN key init error, invalid input";
152
153
0
    case ASN_OBJECT_ID_E :
154
0
        return "ASN object id error, invalid id";
155
156
0
    case ASN_TAG_NULL_E :
157
0
        return "ASN tag error, not null";
158
159
0
    case ASN_EXPECT_0_E :
160
0
        return "ASN expect error, not zero";
161
162
0
    case ASN_BITSTR_E :
163
0
        return "ASN bit string error, wrong id";
164
165
0
    case ASN_UNKNOWN_OID_E :
166
0
        return "ASN oid error, unknown sum id";
167
168
0
    case ASN_DATE_SZ_E :
169
0
        return "ASN date error, bad size";
170
171
0
    case ASN_BEFORE_DATE_E :
172
0
        return "ASN date error, current date before";
173
174
0
    case ASN_AFTER_DATE_E :
175
0
        return "ASN date error, current date after";
176
177
0
    case ASN_SIG_OID_E :
178
0
        return "ASN signature error, mismatched oid";
179
180
0
    case ASN_TIME_E :
181
0
        return "ASN time error, unknown time type";
182
183
0
    case ASN_INPUT_E :
184
0
        return "ASN input error, not enough data";
185
186
0
    case ASN_SIG_CONFIRM_E :
187
0
        return "ASN sig error, confirm failure";
188
189
0
    case ASN_SIG_HASH_E :
190
0
        return "ASN sig error, unsupported hash type";
191
192
0
    case ASN_SIG_KEY_E :
193
0
        return "ASN sig error, unsupported key type";
194
195
0
    case ASN_DH_KEY_E :
196
0
        return "ASN key init error, invalid input";
197
198
0
    case ASN_CRIT_EXT_E:
199
0
        return "X.509 Critical extension ignored or invalid";
200
201
0
    case ASN_ALT_NAME_E:
202
0
        return "ASN alternate name error";
203
204
0
    case ECC_BAD_ARG_E :
205
0
        return "ECC input argument wrong type, invalid input";
206
207
0
    case ASN_ECC_KEY_E :
208
0
        return "ECC ASN1 bad key data, invalid input";
209
210
0
    case ECC_CURVE_OID_E :
211
0
        return "ECC curve sum OID unsupported, invalid input";
212
213
0
    case BAD_FUNC_ARG :
214
0
        return "Bad function argument";
215
216
0
    case NOT_COMPILED_IN :
217
0
        return "Feature not compiled in";
218
219
0
    case UNICODE_SIZE_E :
220
0
        return "Unicode password too big";
221
222
0
    case NO_PASSWORD :
223
0
        return "No password provided by user";
224
225
0
    case ALT_NAME_E :
226
0
        return "Alt Name problem, too big";
227
228
0
    case AES_GCM_AUTH_E:
229
0
        return "AES-GCM Authentication check fail";
230
231
0
    case AES_CCM_AUTH_E:
232
0
        return "AES-CCM Authentication check fail";
233
234
0
    case AES_SIV_AUTH_E:
235
0
        return "AES-SIV authentication failure";
236
237
0
    case ASYNC_INIT_E:
238
0
        return "Async Init error";
239
240
0
    case COMPRESS_INIT_E:
241
0
        return "Compress Init error";
242
243
0
    case COMPRESS_E:
244
0
        return "Compress error";
245
246
0
    case DECOMPRESS_INIT_E:
247
0
        return "DeCompress Init error";
248
249
0
    case DECOMPRESS_E:
250
0
        return "DeCompress error";
251
252
0
    case BAD_ALIGN_E:
253
0
        return "Bad alignment error, no alloc help";
254
255
0
    case ASN_NO_SIGNER_E :
256
0
#ifndef OPENSSL_EXTRA
257
0
        return "ASN no signer error to confirm failure";
258
#else
259
        return "certificate verify failed";
260
#endif
261
262
0
    case ASN_CRL_CONFIRM_E :
263
0
        return "ASN CRL sig error, confirm failure";
264
265
0
    case ASN_CRL_NO_SIGNER_E :
266
0
        return "ASN CRL no signer error to confirm failure";
267
268
0
    case CRL_CERT_DATE_ERR:
269
0
        return "CRL date error";
270
271
0
    case ASN_OCSP_CONFIRM_E :
272
0
        return "ASN OCSP sig error, confirm failure";
273
274
0
    case ASN_NO_PEM_HEADER:
275
0
        return "ASN no PEM Header Error";
276
277
0
    case BAD_STATE_E:
278
0
        return "Bad state operation";
279
280
0
    case BAD_PADDING_E:
281
0
        return "Bad padding, message wrong length";
282
283
0
    case REQ_ATTRIBUTE_E:
284
0
        return "Setting cert request attributes error";
285
286
0
    case PKCS7_OID_E:
287
0
        return "PKCS#7 error: mismatched OID value";
288
289
0
    case PKCS7_RECIP_E:
290
0
        return "PKCS#7 error: no matching recipient found";
291
292
0
    case WC_PKCS7_WANT_READ_E:
293
0
        return "PKCS#7 operations wants more input, call again";
294
295
0
    case FIPS_NOT_ALLOWED_E:
296
0
        return "FIPS mode not allowed error";
297
298
0
    case ASN_NAME_INVALID_E:
299
0
        return "Name Constraint error";
300
301
0
    case RNG_FAILURE_E:
302
0
        return "Random Number Generator failed";
303
304
0
    case HMAC_MIN_KEYLEN_E:
305
0
        return "FIPS Mode HMAC Minimum Key Length error";
306
307
0
    case RSA_PAD_E:
308
0
        return "Rsa Padding error";
309
310
0
    case LENGTH_ONLY_E:
311
0
        return "Output length only set, not for other use error";
312
313
0
    case IN_CORE_FIPS_E:
314
0
        return "In Core Integrity check FIPS error";
315
316
0
    case AES_KAT_FIPS_E:
317
0
        return "AES Known Answer Test check FIPS error";
318
319
0
    case DES3_KAT_FIPS_E:
320
0
        return "DES3 Known Answer Test check FIPS error";
321
322
0
    case HMAC_KAT_FIPS_E:
323
0
        return "HMAC Known Answer Test check FIPS error";
324
325
0
    case RSA_KAT_FIPS_E:
326
0
        return "RSA Known Answer Test check FIPS error";
327
328
0
    case DRBG_KAT_FIPS_E:
329
0
        return "DRBG Known Answer Test check FIPS error";
330
331
0
    case DRBG_CONT_FIPS_E:
332
0
        return "DRBG Continuous Test FIPS error";
333
334
0
    case AESGCM_KAT_FIPS_E:
335
0
        return "AESGCM Known Answer Test check FIPS error";
336
337
0
    case THREAD_STORE_KEY_E:
338
0
        return "Thread Storage Key Create error";
339
340
0
    case THREAD_STORE_SET_E:
341
0
        return "Thread Storage Set error";
342
343
0
    case MAC_CMP_FAILED_E:
344
0
        return "MAC comparison failed";
345
346
0
    case IS_POINT_E:
347
0
        return "ECC is point on curve failed";
348
349
0
    case ECC_INF_E:
350
0
        return " ECC point at infinity error";
351
352
0
    case ECC_OUT_OF_RANGE_E:
353
0
        return " ECC Qx or Qy out of range error";
354
355
0
    case ECC_PRIV_KEY_E:
356
0
        return " ECC private key is not valid error";
357
358
0
    case SRP_CALL_ORDER_E:
359
0
        return "SRP function called in the wrong order error";
360
361
0
    case SRP_VERIFY_E:
362
0
        return "SRP proof verification error";
363
364
0
    case SRP_BAD_KEY_E:
365
0
        return "SRP bad key values error";
366
367
0
    case ASN_NO_SKID:
368
0
        return "ASN no Subject Key Identifier found error";
369
370
0
    case ASN_NO_AKID:
371
0
        return "ASN no Authority Key Identifier found error";
372
373
0
    case ASN_NO_KEYUSAGE:
374
0
        return "ASN no Key Usage found error";
375
376
0
    case SKID_E:
377
0
        return "Setting Subject Key Identifier error";
378
379
0
    case AKID_E:
380
0
        return "Setting Authority Key Identifier error";
381
382
0
    case KEYUSAGE_E:
383
0
        return "Key Usage value error";
384
385
0
    case EXTKEYUSAGE_E:
386
0
        return "Extended Key Usage value error";
387
388
0
    case CERTPOLICIES_E:
389
0
        return "Setting Certificate Policies error";
390
391
0
    case WC_INIT_E:
392
0
        return "wolfCrypt Initialize Failure error";
393
394
0
    case SIG_VERIFY_E:
395
0
        return "Signature verify error";
396
397
0
    case BAD_COND_E:
398
0
        return "Bad condition variable operation error";
399
400
0
    case SIG_TYPE_E:
401
0
        return "Signature type not enabled/available";
402
403
0
    case HASH_TYPE_E:
404
0
        return "Hash type not enabled/available";
405
406
0
    case WC_KEY_SIZE_E:
407
0
        return "Key size error, either too small or large";
408
409
0
    case ASN_COUNTRY_SIZE_E:
410
0
        return "Country code size error, either too small or large";
411
412
0
    case MISSING_RNG_E:
413
0
        return "RNG required but not provided";
414
415
0
    case ASN_PATHLEN_SIZE_E:
416
0
        return "ASN CA path length value too large error";
417
418
0
    case ASN_PATHLEN_INV_E:
419
0
        return "ASN CA path length larger than signer error";
420
421
0
    case BAD_KEYWRAP_ALG_E:
422
0
        return "Unsupported key wrap algorithm error";
423
424
0
    case BAD_KEYWRAP_IV_E:
425
0
        return "Decrypted AES key wrap IV does not match expected";
426
427
0
    case WC_CLEANUP_E:
428
0
        return "wolfcrypt cleanup failed";
429
430
0
    case ECC_CDH_KAT_FIPS_E:
431
0
        return "wolfcrypt FIPS ECC CDH Known Answer Test Failure";
432
433
0
    case DH_CHECK_PUB_E:
434
0
        return "DH Check Public Key failure";
435
436
0
    case BAD_PATH_ERROR:
437
0
        return "Bad path for opendir error";
438
439
0
    case ASYNC_OP_E:
440
0
        return "Async operation error";
441
442
0
    case BAD_OCSP_RESPONDER:
443
0
        return "Invalid OCSP Responder, missing specific key usage extensions";
444
445
0
    case ECC_PRIVATEONLY_E:
446
0
        return "Invalid use of private only ECC key";
447
448
0
    case WC_HW_E:
449
0
        return "Error with hardware crypto use";
450
451
0
    case WC_HW_WAIT_E:
452
0
        return "Hardware waiting on resource";
453
454
0
    case PSS_SALTLEN_E:
455
0
        return "PSS - Length of salt is too big for hash algorithm";
456
457
0
    case PRIME_GEN_E:
458
0
        return "Unable to find a prime for RSA key";
459
460
0
    case BER_INDEF_E:
461
0
        return "Unable to decode an indefinite length encoded message";
462
463
0
    case RSA_OUT_OF_RANGE_E:
464
0
        return "Ciphertext to decrypt is out of range";
465
466
0
    case RSAPSS_PAT_FIPS_E:
467
0
        return "wolfcrypt FIPS RSA-PSS Pairwise Agreement Test Failure";
468
469
0
    case ECDSA_PAT_FIPS_E:
470
0
        return "wolfcrypt FIPS ECDSA Pairwise Agreement Test Failure";
471
472
0
    case DH_KAT_FIPS_E:
473
0
        return "wolfcrypt FIPS DH Known Answer Test Failure";
474
475
0
    case AESCCM_KAT_FIPS_E:
476
0
        return "AESCCM Known Answer Test check FIPS error";
477
478
0
    case SHA3_KAT_FIPS_E:
479
0
        return "SHA-3 Known Answer Test check FIPS error";
480
481
0
    case ECDHE_KAT_FIPS_E:
482
0
        return "wolfcrypt FIPS ECDHE Known Answer Test Failure";
483
484
0
    case AES_GCM_OVERFLOW_E:
485
0
        return "AES-GCM invocation counter overflow";
486
487
0
    case AES_CCM_OVERFLOW_E:
488
0
        return "AES-CCM invocation counter overflow";
489
490
0
    case RSA_KEY_PAIR_E:
491
0
        return "RSA Key Pair-Wise Consistency check fail";
492
493
0
    case DH_CHECK_PRIV_E:
494
0
        return "DH Check Private Key failure";
495
496
0
    case WC_AFALG_SOCK_E:
497
0
        return "AF_ALG socket error";
498
499
0
    case WC_DEVCRYPTO_E:
500
0
        return "Error with /dev/crypto";
501
502
0
    case ZLIB_INIT_ERROR:
503
0
        return "zlib init error";
504
505
0
    case ZLIB_COMPRESS_ERROR:
506
0
        return "zlib compress error";
507
508
0
    case ZLIB_DECOMPRESS_ERROR:
509
0
        return "zlib decompress error";
510
511
0
    case PKCS7_NO_SIGNER_E:
512
0
        return "No signer in PKCS#7 signed data";
513
514
0
    case CRYPTOCB_UNAVAILABLE:
515
0
        return "Crypto callback unavailable";
516
517
0
    case PKCS7_SIGNEEDS_CHECK:
518
0
        return "Signature found but no certificate to verify";
519
520
0
    case PSS_SALTLEN_RECOVER_E:
521
0
        return "PSS - Salt length unable to be recovered";
522
523
0
    case CHACHA_POLY_OVERFLOW:
524
0
        return "wolfcrypt - ChaCha20_Poly1305 limit overflow 4GB";
525
526
0
    case ASN_SELF_SIGNED_E:
527
0
        return "ASN self-signed certificate error";
528
529
0
    case SAKKE_VERIFY_FAIL_E:
530
0
        return "SAKKE derivation verification error";
531
532
0
    case MISSING_IV:
533
0
        return "Required IV not set";
534
535
0
    case MISSING_KEY:
536
0
        return "Required key not set";
537
538
0
    case BAD_LENGTH_E:
539
0
        return "Value of length parameter is invalid.";
540
541
0
    case ECDSA_KAT_FIPS_E:
542
0
        return "wolfcrypt FIPS ECDSA Known Answer Test Failure";
543
544
0
    case RSA_PAT_FIPS_E:
545
0
        return "wolfcrypt FIPS RSA Pairwise Agreement Test Failure";
546
547
0
    case KDF_TLS12_KAT_FIPS_E:
548
0
        return "wolfcrypt FIPS TLSv1.2 KDF Known Answer Test Failure";
549
550
0
    case KDF_TLS13_KAT_FIPS_E:
551
0
        return "wolfcrypt FIPS TLSv1.3 KDF Known Answer Test Failure";
552
553
0
    case KDF_SSH_KAT_FIPS_E:
554
0
        return "wolfcrypt FIPS SSH KDF Known Answer Test Failure";
555
556
0
     case DHE_PCT_E:
557
0
        return "wolfcrypt DHE Pairwise Consistency Test Failure";
558
559
0
    case ECC_PCT_E:
560
0
        return "wolfcrypt ECDHE Pairwise Consistency Test Failure";
561
562
0
    case FIPS_PRIVATE_KEY_LOCKED_E:
563
0
        return "Cannot export private key, locked";
564
565
0
    case PROTOCOLCB_UNAVAILABLE:
566
0
        return "Protocol callback unavailable";
567
568
0
    case NO_VALID_DEVID:
569
0
        return "No valid device ID set";
570
571
0
    case IO_FAILED_E:
572
0
        return "Input/output failure";
573
574
0
    case SYSLIB_FAILED_E:
575
0
        return "System/library call failed";
576
577
0
    default:
578
0
        return "unknown error number";
579
580
0
    }
581
0
}
582
583
void wc_ErrorString(int error, char* buffer)
584
0
{
585
0
    XSTRNCPY(buffer, wc_GetErrorString(error), WOLFSSL_MAX_ERROR_SZ);
586
0
    buffer[WOLFSSL_MAX_ERROR_SZ-1] = 0;
587
0
}
588
#endif /* !NO_ERROR_STRINGS */
589