[352] | 1 | /* error.c
|
---|
| 2 | *
|
---|
| 3 | * Copyright (C) 2006-2017 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 | const char* wc_GetErrorString(int error)
|
---|
| 37 | {
|
---|
| 38 | #ifdef NO_ERROR_STRINGS
|
---|
| 39 |
|
---|
| 40 | (void)error;
|
---|
| 41 | return "no support for error strings built in";
|
---|
| 42 |
|
---|
| 43 | #else
|
---|
| 44 |
|
---|
| 45 | switch (error) {
|
---|
| 46 |
|
---|
| 47 | case OPEN_RAN_E :
|
---|
| 48 | return "opening random device error";
|
---|
| 49 |
|
---|
| 50 | case READ_RAN_E :
|
---|
| 51 | return "reading random device error";
|
---|
| 52 |
|
---|
| 53 | case WINCRYPT_E :
|
---|
| 54 | return "windows crypt init error";
|
---|
| 55 |
|
---|
| 56 | case CRYPTGEN_E :
|
---|
| 57 | return "windows crypt generation error";
|
---|
| 58 |
|
---|
| 59 | case RAN_BLOCK_E :
|
---|
| 60 | return "random device read would block error";
|
---|
| 61 |
|
---|
| 62 | case BAD_MUTEX_E :
|
---|
| 63 | return "Bad mutex, operation failed";
|
---|
| 64 |
|
---|
| 65 | case WC_TIMEOUT_E:
|
---|
| 66 | return "Timeout error";
|
---|
| 67 |
|
---|
| 68 | case WC_PENDING_E:
|
---|
| 69 | return "wolfCrypt Operation Pending (would block / eagain) error";
|
---|
| 70 |
|
---|
| 71 | case WC_NOT_PENDING_E:
|
---|
| 72 | return "wolfCrypt operation not pending error";
|
---|
| 73 |
|
---|
| 74 | case MP_INIT_E :
|
---|
| 75 | return "mp_init error state";
|
---|
| 76 |
|
---|
| 77 | case MP_READ_E :
|
---|
| 78 | return "mp_read error state";
|
---|
| 79 |
|
---|
| 80 | case MP_EXPTMOD_E :
|
---|
| 81 | return "mp_exptmod error state";
|
---|
| 82 |
|
---|
| 83 | case MP_TO_E :
|
---|
| 84 | return "mp_to_xxx error state, can't convert";
|
---|
| 85 |
|
---|
| 86 | case MP_SUB_E :
|
---|
| 87 | return "mp_sub error state, can't subtract";
|
---|
| 88 |
|
---|
| 89 | case MP_ADD_E :
|
---|
| 90 | return "mp_add error state, can't add";
|
---|
| 91 |
|
---|
| 92 | case MP_MUL_E :
|
---|
| 93 | return "mp_mul error state, can't multiply";
|
---|
| 94 |
|
---|
| 95 | case MP_MULMOD_E :
|
---|
| 96 | return "mp_mulmod error state, can't multiply mod";
|
---|
| 97 |
|
---|
| 98 | case MP_MOD_E :
|
---|
| 99 | return "mp_mod error state, can't mod";
|
---|
| 100 |
|
---|
| 101 | case MP_INVMOD_E :
|
---|
| 102 | return "mp_invmod error state, can't inv mod";
|
---|
| 103 |
|
---|
| 104 | case MP_CMP_E :
|
---|
| 105 | return "mp_cmp error state";
|
---|
| 106 |
|
---|
| 107 | case MP_ZERO_E :
|
---|
| 108 | return "mp zero result, not expected";
|
---|
| 109 |
|
---|
| 110 | case MEMORY_E :
|
---|
| 111 | return "out of memory error";
|
---|
| 112 |
|
---|
| 113 | case VAR_STATE_CHANGE_E :
|
---|
| 114 | return "Variable state modified by different thread";
|
---|
| 115 |
|
---|
| 116 | case RSA_WRONG_TYPE_E :
|
---|
| 117 | return "RSA wrong block type for RSA function";
|
---|
| 118 |
|
---|
| 119 | case RSA_BUFFER_E :
|
---|
| 120 | return "RSA buffer error, output too small or input too big";
|
---|
| 121 |
|
---|
| 122 | case BUFFER_E :
|
---|
| 123 | return "Buffer error, output too small or input too big";
|
---|
| 124 |
|
---|
| 125 | case ALGO_ID_E :
|
---|
| 126 | return "Setting Cert AlgoID error";
|
---|
| 127 |
|
---|
| 128 | case PUBLIC_KEY_E :
|
---|
| 129 | return "Setting Cert Public Key error";
|
---|
| 130 |
|
---|
| 131 | case DATE_E :
|
---|
| 132 | return "Setting Cert Date validity error";
|
---|
| 133 |
|
---|
| 134 | case SUBJECT_E :
|
---|
| 135 | return "Setting Cert Subject name error";
|
---|
| 136 |
|
---|
| 137 | case ISSUER_E :
|
---|
| 138 | return "Setting Cert Issuer name error";
|
---|
| 139 |
|
---|
| 140 | case CA_TRUE_E :
|
---|
| 141 | return "Setting basic constraint CA true error";
|
---|
| 142 |
|
---|
| 143 | case EXTENSIONS_E :
|
---|
| 144 | return "Setting extensions error";
|
---|
| 145 |
|
---|
| 146 | case ASN_PARSE_E :
|
---|
| 147 | return "ASN parsing error, invalid input";
|
---|
| 148 |
|
---|
| 149 | case ASN_VERSION_E :
|
---|
| 150 | return "ASN version error, invalid number";
|
---|
| 151 |
|
---|
| 152 | case ASN_GETINT_E :
|
---|
| 153 | return "ASN get big int error, invalid data";
|
---|
| 154 |
|
---|
| 155 | case ASN_RSA_KEY_E :
|
---|
| 156 | return "ASN key init error, invalid input";
|
---|
| 157 |
|
---|
| 158 | case ASN_OBJECT_ID_E :
|
---|
| 159 | return "ASN object id error, invalid id";
|
---|
| 160 |
|
---|
| 161 | case ASN_TAG_NULL_E :
|
---|
| 162 | return "ASN tag error, not null";
|
---|
| 163 |
|
---|
| 164 | case ASN_EXPECT_0_E :
|
---|
| 165 | return "ASN expect error, not zero";
|
---|
| 166 |
|
---|
| 167 | case ASN_BITSTR_E :
|
---|
| 168 | return "ASN bit string error, wrong id";
|
---|
| 169 |
|
---|
| 170 | case ASN_UNKNOWN_OID_E :
|
---|
| 171 | return "ASN oid error, unknown sum id";
|
---|
| 172 |
|
---|
| 173 | case ASN_DATE_SZ_E :
|
---|
| 174 | return "ASN date error, bad size";
|
---|
| 175 |
|
---|
| 176 | case ASN_BEFORE_DATE_E :
|
---|
| 177 | return "ASN date error, current date before";
|
---|
| 178 |
|
---|
| 179 | case ASN_AFTER_DATE_E :
|
---|
| 180 | return "ASN date error, current date after";
|
---|
| 181 |
|
---|
| 182 | case ASN_SIG_OID_E :
|
---|
| 183 | return "ASN signature error, mismatched oid";
|
---|
| 184 |
|
---|
| 185 | case ASN_TIME_E :
|
---|
| 186 | return "ASN time error, unknown time type";
|
---|
| 187 |
|
---|
| 188 | case ASN_INPUT_E :
|
---|
| 189 | return "ASN input error, not enough data";
|
---|
| 190 |
|
---|
| 191 | case ASN_SIG_CONFIRM_E :
|
---|
| 192 | return "ASN sig error, confirm failure";
|
---|
| 193 |
|
---|
| 194 | case ASN_SIG_HASH_E :
|
---|
| 195 | return "ASN sig error, unsupported hash type";
|
---|
| 196 |
|
---|
| 197 | case ASN_SIG_KEY_E :
|
---|
| 198 | return "ASN sig error, unsupported key type";
|
---|
| 199 |
|
---|
| 200 | case ASN_DH_KEY_E :
|
---|
| 201 | return "ASN key init error, invalid input";
|
---|
| 202 |
|
---|
| 203 | case ASN_NTRU_KEY_E :
|
---|
| 204 | return "ASN NTRU key decode error, invalid input";
|
---|
| 205 |
|
---|
| 206 | case ASN_CRIT_EXT_E:
|
---|
| 207 | return "X.509 Critical extension ignored or invalid";
|
---|
| 208 |
|
---|
| 209 | case ECC_BAD_ARG_E :
|
---|
| 210 | return "ECC input argument wrong type, invalid input";
|
---|
| 211 |
|
---|
| 212 | case ASN_ECC_KEY_E :
|
---|
| 213 | return "ECC ASN1 bad key data, invalid input";
|
---|
| 214 |
|
---|
| 215 | case ECC_CURVE_OID_E :
|
---|
| 216 | return "ECC curve sum OID unsupported, invalid input";
|
---|
| 217 |
|
---|
| 218 | case BAD_FUNC_ARG :
|
---|
| 219 | return "Bad function argument";
|
---|
| 220 |
|
---|
| 221 | case NOT_COMPILED_IN :
|
---|
| 222 | return "Feature not compiled in";
|
---|
| 223 |
|
---|
| 224 | case UNICODE_SIZE_E :
|
---|
| 225 | return "Unicode password too big";
|
---|
| 226 |
|
---|
| 227 | case NO_PASSWORD :
|
---|
| 228 | return "No password provided by user";
|
---|
| 229 |
|
---|
| 230 | case ALT_NAME_E :
|
---|
| 231 | return "Alt Name problem, too big";
|
---|
| 232 |
|
---|
| 233 | case AES_GCM_AUTH_E:
|
---|
| 234 | return "AES-GCM Authentication check fail";
|
---|
| 235 |
|
---|
| 236 | case AES_CCM_AUTH_E:
|
---|
| 237 | return "AES-CCM Authentication check fail";
|
---|
| 238 |
|
---|
| 239 | case ASYNC_INIT_E:
|
---|
| 240 | return "Async Init error";
|
---|
| 241 |
|
---|
| 242 | case COMPRESS_INIT_E:
|
---|
| 243 | return "Compress Init error";
|
---|
| 244 |
|
---|
| 245 | case COMPRESS_E:
|
---|
| 246 | return "Compress error";
|
---|
| 247 |
|
---|
| 248 | case DECOMPRESS_INIT_E:
|
---|
| 249 | return "DeCompress Init error";
|
---|
| 250 |
|
---|
| 251 | case DECOMPRESS_E:
|
---|
| 252 | return "DeCompress error";
|
---|
| 253 |
|
---|
| 254 | case BAD_ALIGN_E:
|
---|
| 255 | return "Bad alignment error, no alloc help";
|
---|
| 256 |
|
---|
| 257 | case ASN_NO_SIGNER_E :
|
---|
| 258 | return "ASN no signer error to confirm failure";
|
---|
| 259 |
|
---|
| 260 | case ASN_CRL_CONFIRM_E :
|
---|
| 261 | return "ASN CRL sig error, confirm failure";
|
---|
| 262 |
|
---|
| 263 | case ASN_CRL_NO_SIGNER_E :
|
---|
| 264 | return "ASN CRL no signer error to confirm failure";
|
---|
| 265 |
|
---|
| 266 | case ASN_OCSP_CONFIRM_E :
|
---|
| 267 | return "ASN OCSP sig error, confirm failure";
|
---|
| 268 |
|
---|
| 269 | case BAD_STATE_E:
|
---|
| 270 | return "Bad state operation";
|
---|
| 271 |
|
---|
| 272 | case BAD_PADDING_E:
|
---|
| 273 | return "Bad padding, message wrong length";
|
---|
| 274 |
|
---|
| 275 | case REQ_ATTRIBUTE_E:
|
---|
| 276 | return "Setting cert request attributes error";
|
---|
| 277 |
|
---|
| 278 | case PKCS7_OID_E:
|
---|
| 279 | return "PKCS#7 error: mismatched OID value";
|
---|
| 280 |
|
---|
| 281 | case PKCS7_RECIP_E:
|
---|
| 282 | return "PKCS#7 error: no matching recipient found";
|
---|
| 283 |
|
---|
| 284 | case FIPS_NOT_ALLOWED_E:
|
---|
| 285 | return "FIPS mode not allowed error";
|
---|
| 286 |
|
---|
| 287 | case ASN_NAME_INVALID_E:
|
---|
| 288 | return "Name Constraint error";
|
---|
| 289 |
|
---|
| 290 | case RNG_FAILURE_E:
|
---|
| 291 | return "Random Number Generator failed";
|
---|
| 292 |
|
---|
| 293 | case HMAC_MIN_KEYLEN_E:
|
---|
| 294 | return "FIPS Mode HMAC Minimum Key Length error";
|
---|
| 295 |
|
---|
| 296 | case RSA_PAD_E:
|
---|
| 297 | return "Rsa Padding error";
|
---|
| 298 |
|
---|
| 299 | case LENGTH_ONLY_E:
|
---|
| 300 | return "Output length only set, not for other use error";
|
---|
| 301 |
|
---|
| 302 | case IN_CORE_FIPS_E:
|
---|
| 303 | return "In Core Integrity check FIPS error";
|
---|
| 304 |
|
---|
| 305 | case AES_KAT_FIPS_E:
|
---|
| 306 | return "AES Known Answer Test check FIPS error";
|
---|
| 307 |
|
---|
| 308 | case DES3_KAT_FIPS_E:
|
---|
| 309 | return "DES3 Known Answer Test check FIPS error";
|
---|
| 310 |
|
---|
| 311 | case HMAC_KAT_FIPS_E:
|
---|
| 312 | return "HMAC Known Answer Test check FIPS error";
|
---|
| 313 |
|
---|
| 314 | case RSA_KAT_FIPS_E:
|
---|
| 315 | return "RSA Known Answer Test check FIPS error";
|
---|
| 316 |
|
---|
| 317 | case DRBG_KAT_FIPS_E:
|
---|
| 318 | return "DRBG Known Answer Test check FIPS error";
|
---|
| 319 |
|
---|
| 320 | case DRBG_CONT_FIPS_E:
|
---|
| 321 | return "DRBG Continuous Test FIPS error";
|
---|
| 322 |
|
---|
| 323 | case AESGCM_KAT_FIPS_E:
|
---|
| 324 | return "AESGCM Known Answer Test check FIPS error";
|
---|
| 325 |
|
---|
| 326 | case THREAD_STORE_KEY_E:
|
---|
| 327 | return "Thread Storage Key Create error";
|
---|
| 328 |
|
---|
| 329 | case THREAD_STORE_SET_E:
|
---|
| 330 | return "Thread Storage Set error";
|
---|
| 331 |
|
---|
| 332 | case MAC_CMP_FAILED_E:
|
---|
| 333 | return "MAC comparison failed";
|
---|
| 334 |
|
---|
| 335 | case IS_POINT_E:
|
---|
| 336 | return "ECC is point on curve failed";
|
---|
| 337 |
|
---|
| 338 | case ECC_INF_E:
|
---|
| 339 | return " ECC point at infinity error";
|
---|
| 340 |
|
---|
| 341 | case ECC_OUT_OF_RANGE_E:
|
---|
| 342 | return " ECC Qx or Qy out of range error";
|
---|
| 343 |
|
---|
| 344 | case ECC_PRIV_KEY_E:
|
---|
| 345 | return " ECC private key is not valid error";
|
---|
| 346 |
|
---|
| 347 | case SRP_CALL_ORDER_E:
|
---|
| 348 | return "SRP function called in the wrong order error";
|
---|
| 349 |
|
---|
| 350 | case SRP_VERIFY_E:
|
---|
| 351 | return "SRP proof verification error";
|
---|
| 352 |
|
---|
| 353 | case SRP_BAD_KEY_E:
|
---|
| 354 | return "SRP bad key values error";
|
---|
| 355 |
|
---|
| 356 | case ASN_NO_SKID:
|
---|
| 357 | return "ASN no Subject Key Identifier found error";
|
---|
| 358 |
|
---|
| 359 | case ASN_NO_AKID:
|
---|
| 360 | return "ASN no Authority Key Identifier found error";
|
---|
| 361 |
|
---|
| 362 | case ASN_NO_KEYUSAGE:
|
---|
| 363 | return "ASN no Key Usage found error";
|
---|
| 364 |
|
---|
| 365 | case SKID_E:
|
---|
| 366 | return "Setting Subject Key Identifier error";
|
---|
| 367 |
|
---|
| 368 | case AKID_E:
|
---|
| 369 | return "Setting Authority Key Identifier error";
|
---|
| 370 |
|
---|
| 371 | case KEYUSAGE_E:
|
---|
| 372 | return "Key Usage value error";
|
---|
| 373 |
|
---|
| 374 | case EXTKEYUSAGE_E:
|
---|
| 375 | return "Extended Key Usage value error";
|
---|
| 376 |
|
---|
| 377 | case CERTPOLICIES_E:
|
---|
| 378 | return "Setting Certificate Policies error";
|
---|
| 379 |
|
---|
| 380 | case WC_INIT_E:
|
---|
| 381 | return "wolfCrypt Initialize Failure error";
|
---|
| 382 |
|
---|
| 383 | case SIG_VERIFY_E:
|
---|
| 384 | return "Signature verify error";
|
---|
| 385 |
|
---|
| 386 | case BAD_COND_E:
|
---|
| 387 | return "Bad condition variable operation error";
|
---|
| 388 |
|
---|
| 389 | case SIG_TYPE_E:
|
---|
| 390 | return "Signature type not enabled/available";
|
---|
| 391 |
|
---|
| 392 | case HASH_TYPE_E:
|
---|
| 393 | return "Hash type not enabled/available";
|
---|
| 394 |
|
---|
| 395 | case WC_KEY_SIZE_E:
|
---|
| 396 | return "Key size error, either too small or large";
|
---|
| 397 |
|
---|
| 398 | case ASN_COUNTRY_SIZE_E:
|
---|
| 399 | return "Country code size error, either too small or large";
|
---|
| 400 |
|
---|
| 401 | case MISSING_RNG_E:
|
---|
| 402 | return "RNG required but not provided";
|
---|
| 403 |
|
---|
| 404 | case ASN_PATHLEN_SIZE_E:
|
---|
| 405 | return "ASN CA path length value too large error";
|
---|
| 406 |
|
---|
| 407 | case ASN_PATHLEN_INV_E:
|
---|
| 408 | return "ASN CA path length larger than signer error";
|
---|
| 409 |
|
---|
| 410 | case BAD_KEYWRAP_ALG_E:
|
---|
| 411 | return "Unsupported key wrap algorithm error";
|
---|
| 412 |
|
---|
| 413 | case BAD_KEYWRAP_IV_E:
|
---|
| 414 | return "Decrypted AES key wrap IV does not match expected";
|
---|
| 415 |
|
---|
| 416 | case WC_CLEANUP_E:
|
---|
| 417 | return "wolfcrypt cleanup failed";
|
---|
| 418 |
|
---|
| 419 | case ECC_CDH_KAT_FIPS_E:
|
---|
| 420 | return "wolfcrypt FIPS ECC CDH Known Answer Test Failure";
|
---|
| 421 |
|
---|
| 422 | case DH_CHECK_PUB_E:
|
---|
| 423 | return "DH Check Public Key failure";
|
---|
| 424 |
|
---|
| 425 | case BAD_PATH_ERROR:
|
---|
| 426 | return "Bad path for opendir error";
|
---|
| 427 |
|
---|
| 428 | case ASYNC_OP_E:
|
---|
| 429 | return "Async operation error";
|
---|
| 430 |
|
---|
| 431 | case BAD_OCSP_RESPONDER:
|
---|
| 432 | return "Invalid OCSP Responder, missing specific key usage extensions";
|
---|
| 433 |
|
---|
| 434 | case ECC_PRIVATEONLY_E:
|
---|
| 435 | return "Invalid use of private only ECC key";
|
---|
| 436 |
|
---|
| 437 | default:
|
---|
| 438 | return "unknown error number";
|
---|
| 439 |
|
---|
| 440 | }
|
---|
| 441 |
|
---|
| 442 | #endif /* NO_ERROR_STRINGS */
|
---|
| 443 |
|
---|
| 444 | }
|
---|
| 445 |
|
---|
| 446 | void wc_ErrorString(int error, char* buffer)
|
---|
| 447 | {
|
---|
| 448 | XSTRNCPY(buffer, wc_GetErrorString(error), WOLFSSL_MAX_ERROR_SZ);
|
---|
| 449 | }
|
---|