Renesas / SecureDweet
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers error.c Source File

error.c

00001 /* error.c
00002  *
00003  * Copyright (C) 2006-2016 wolfSSL Inc.
00004  *
00005  * This file is part of wolfSSL.
00006  *
00007  * wolfSSL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * wolfSSL is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
00020  */
00021 
00022 
00023 #ifdef HAVE_CONFIG_H
00024     #include <config.h>
00025 #endif
00026 
00027 #include <wolfssl/wolfcrypt/settings.h>
00028 
00029 #include <wolfssl/wolfcrypt/error-crypt.h>
00030 
00031 #ifdef _MSC_VER
00032     /* 4996 warning to use MS extensions e.g., strcpy_s instead of XSTRNCPY */
00033     #pragma warning(disable: 4996)
00034 #endif
00035 
00036 const char* wc_GetErrorString(int error)
00037 {
00038 #ifdef NO_ERROR_STRINGS
00039 
00040     (void)error;
00041     return "no support for error strings built in";
00042 
00043 #else
00044 
00045     switch (error) {
00046 
00047     case OPEN_RAN_E :
00048         return "opening random device error";
00049 
00050     case READ_RAN_E :
00051         return "reading random device error";
00052 
00053     case WINCRYPT_E :
00054         return "windows crypt init error";
00055 
00056     case CRYPTGEN_E :
00057         return "windows crypt generation error";
00058 
00059     case RAN_BLOCK_E :
00060         return "random device read would block error";
00061 
00062     case BAD_MUTEX_E :
00063         return "Bad mutex, operation failed";
00064 
00065     case MP_INIT_E :
00066         return "mp_init error state";
00067 
00068     case MP_READ_E :
00069         return "mp_read error state";
00070 
00071     case MP_EXPTMOD_E :
00072         return "mp_exptmod error state";
00073 
00074     case MP_TO_E :
00075         return "mp_to_xxx error state, can't convert";
00076 
00077     case MP_SUB_E :
00078         return "mp_sub error state, can't subtract";
00079 
00080     case MP_ADD_E :
00081         return "mp_add error state, can't add";
00082 
00083     case MP_MUL_E :
00084         return "mp_mul error state, can't multiply";
00085 
00086     case MP_MULMOD_E :
00087         return "mp_mulmod error state, can't multiply mod";
00088 
00089     case MP_MOD_E :
00090         return "mp_mod error state, can't mod";
00091 
00092     case MP_INVMOD_E :
00093         return "mp_invmod error state, can't inv mod";
00094 
00095     case MP_CMP_E :
00096         return "mp_cmp error state";
00097 
00098     case MP_ZERO_E :
00099         return "mp zero result, not expected";
00100 
00101     case MEMORY_E :
00102         return "out of memory error";
00103 
00104     case RSA_WRONG_TYPE_E :
00105         return "RSA wrong block type for RSA function";
00106 
00107     case RSA_BUFFER_E :
00108         return "RSA buffer error, output too small or input too big";
00109 
00110     case BUFFER_E :
00111         return "Buffer error, output too small or input too big";
00112 
00113     case ALGO_ID_E :
00114         return "Setting Cert AlgoID error";
00115 
00116     case PUBLIC_KEY_E :
00117         return "Setting Cert Public Key error";
00118 
00119     case DATE_E :
00120         return "Setting Cert Date validity error";
00121 
00122     case SUBJECT_E :
00123         return "Setting Cert Subject name error";
00124 
00125     case ISSUER_E :
00126         return "Setting Cert Issuer name error";
00127 
00128     case CA_TRUE_E :
00129         return "Setting basic constraint CA true error";
00130 
00131     case EXTENSIONS_E :
00132         return "Setting extensions error";
00133 
00134     case ASN_PARSE_E :
00135         return "ASN parsing error, invalid input";
00136 
00137     case ASN_VERSION_E :
00138         return "ASN version error, invalid number";
00139 
00140     case ASN_GETINT_E :
00141         return "ASN get big int error, invalid data";
00142 
00143     case ASN_RSA_KEY_E :
00144         return "ASN key init error, invalid input";
00145 
00146     case ASN_OBJECT_ID_E :
00147         return "ASN object id error, invalid id";
00148 
00149     case ASN_TAG_NULL_E :
00150         return "ASN tag error, not null";
00151 
00152     case ASN_EXPECT_0_E :
00153         return "ASN expect error, not zero";
00154 
00155     case ASN_BITSTR_E :
00156         return "ASN bit string error, wrong id";
00157 
00158     case ASN_UNKNOWN_OID_E :
00159         return "ASN oid error, unknown sum id";
00160 
00161     case ASN_DATE_SZ_E :
00162         return "ASN date error, bad size";
00163 
00164     case ASN_BEFORE_DATE_E :
00165         return "ASN date error, current date before";
00166 
00167     case ASN_AFTER_DATE_E :
00168         return "ASN date error, current date after";
00169 
00170     case ASN_SIG_OID_E :
00171         return "ASN signature error, mismatched oid";
00172 
00173     case ASN_TIME_E :
00174         return "ASN time error, unknown time type";
00175 
00176     case ASN_INPUT_E :
00177         return "ASN input error, not enough data";
00178 
00179     case ASN_SIG_CONFIRM_E :
00180         return "ASN sig error, confirm failure";
00181 
00182     case ASN_SIG_HASH_E :
00183         return "ASN sig error, unsupported hash type";
00184 
00185     case ASN_SIG_KEY_E :
00186         return "ASN sig error, unsupported key type";
00187 
00188     case ASN_DH_KEY_E :
00189         return "ASN key init error, invalid input";
00190 
00191     case ASN_NTRU_KEY_E :
00192         return "ASN NTRU key decode error, invalid input";
00193 
00194     case ASN_CRIT_EXT_E:
00195         return "X.509 Critical extension ignored";
00196 
00197     case ECC_BAD_ARG_E :
00198         return "ECC input argument wrong type, invalid input";
00199 
00200     case ASN_ECC_KEY_E :
00201         return "ECC ASN1 bad key data, invalid input";
00202 
00203     case ECC_CURVE_OID_E :
00204         return "ECC curve sum OID unsupported, invalid input";
00205 
00206     case BAD_FUNC_ARG :
00207         return "Bad function argument";
00208 
00209     case NOT_COMPILED_IN :
00210         return "Feature not compiled in";
00211 
00212     case UNICODE_SIZE_E :
00213         return "Unicode password too big";
00214 
00215     case NO_PASSWORD :
00216         return "No password provided by user";
00217 
00218     case ALT_NAME_E :
00219         return "Alt Name problem, too big";
00220 
00221     case AES_GCM_AUTH_E:
00222         return "AES-GCM Authentication check fail";
00223 
00224     case AES_CCM_AUTH_E:
00225         return "AES-CCM Authentication check fail";
00226 
00227     case CAVIUM_INIT_E:
00228         return "Cavium Init type error";
00229 
00230     case COMPRESS_INIT_E:
00231         return "Compress Init error";
00232 
00233     case COMPRESS_E:
00234         return "Compress error";
00235 
00236     case DECOMPRESS_INIT_E:
00237         return "DeCompress Init error";
00238 
00239     case DECOMPRESS_E:
00240         return "DeCompress error";
00241 
00242     case BAD_ALIGN_E:
00243         return "Bad alignment error, no alloc help";
00244 
00245     case ASN_NO_SIGNER_E :
00246         return "ASN no signer error to confirm failure";
00247 
00248     case ASN_CRL_CONFIRM_E :
00249         return "ASN CRL sig error, confirm failure";
00250 
00251     case ASN_CRL_NO_SIGNER_E :
00252         return "ASN CRL no signer error to confirm failure";
00253 
00254     case ASN_OCSP_CONFIRM_E :
00255         return "ASN OCSP sig error, confirm failure";
00256 
00257     case BAD_ENC_STATE_E:
00258         return "Bad ecc encrypt state operation";
00259 
00260     case BAD_PADDING_E:
00261         return "Bad padding, message wrong length";
00262 
00263     case REQ_ATTRIBUTE_E:
00264         return "Setting cert request attributes error";
00265 
00266     case PKCS7_OID_E:
00267         return "PKCS#7 error: mismatched OID value";
00268 
00269     case PKCS7_RECIP_E:
00270         return "PKCS#7 error: no matching recipient found";
00271 
00272     case FIPS_NOT_ALLOWED_E:
00273         return "FIPS mode not allowed error";
00274 
00275     case ASN_NAME_INVALID_E:
00276         return "Name Constraint error";
00277 
00278     case RNG_FAILURE_E:
00279         return "Random Number Generator failed";
00280 
00281     case HMAC_MIN_KEYLEN_E:
00282         return "FIPS Mode HMAC Minimum Key Length error";
00283 
00284     case RSA_PAD_E:
00285         return "Rsa Padding error";
00286 
00287     case LENGTH_ONLY_E:
00288         return "Output length only set, not for other use error";
00289 
00290     case IN_CORE_FIPS_E:
00291         return "In Core Integrity check FIPS error";
00292 
00293     case AES_KAT_FIPS_E:
00294         return "AES Known Answer Test check FIPS error";
00295 
00296     case DES3_KAT_FIPS_E:
00297         return "DES3 Known Answer Test check FIPS error";
00298 
00299     case HMAC_KAT_FIPS_E:
00300         return "HMAC Known Answer Test check FIPS error";
00301 
00302     case RSA_KAT_FIPS_E:
00303         return "RSA Known Answer Test check FIPS error";
00304 
00305     case DRBG_KAT_FIPS_E:
00306         return "DRBG Known Answer Test check FIPS error";
00307 
00308     case DRBG_CONT_FIPS_E:
00309         return "DRBG Continuous Test FIPS error";
00310 
00311     case AESGCM_KAT_FIPS_E:
00312         return "AESGCM Known Answer Test check FIPS error";
00313 
00314     case THREAD_STORE_KEY_E:
00315         return "Thread Storage Key Create error";
00316 
00317     case THREAD_STORE_SET_E:
00318         return "Thread Storage Set error";
00319 
00320     case MAC_CMP_FAILED_E:
00321         return "MAC comparison failed";
00322 
00323     case IS_POINT_E:
00324         return "ECC is point on curve failed";
00325 
00326     case ECC_INF_E:
00327         return " ECC point at infinity error";
00328 
00329     case ECC_PRIV_KEY_E:
00330         return " ECC private key is not valid error";
00331 
00332     case SRP_CALL_ORDER_E:
00333         return "SRP function called in the wrong order error";
00334 
00335     case SRP_VERIFY_E:
00336         return "SRP proof verification error";
00337 
00338     case SRP_BAD_KEY_E:
00339         return "SRP bad key values error";
00340 
00341     case ASN_NO_SKID:
00342         return "ASN no Subject Key Identifier found error";
00343 
00344     case ASN_NO_AKID:
00345         return "ASN no Authority Key Identifier found error";
00346 
00347     case ASN_NO_KEYUSAGE:
00348         return "ASN no Key Usage found error";
00349 
00350     case SKID_E:
00351         return "Setting Subject Key Identifier error";
00352 
00353     case AKID_E:
00354         return "Setting Authority Key Identifier error";
00355 
00356     case KEYUSAGE_E:
00357         return "Bad Key Usage value error";
00358 
00359     case CERTPOLICIES_E:
00360         return "Setting Certificate Policies error";
00361 
00362     case WC_INIT_E:
00363         return "wolfCrypt Initialize Failure error";
00364 
00365     case SIG_VERIFY_E:
00366         return "Signature verify error";
00367 
00368     case BAD_COND_E:
00369         return "Bad condition variable operation error";
00370 
00371     case SIG_TYPE_E:
00372         return "Signature type not enabled/available";
00373 
00374     case HASH_TYPE_E:
00375         return "Hash type not enabled/available";
00376 
00377     default:
00378         return "unknown error number";
00379 
00380     }
00381 
00382 #endif /* NO_ERROR_STRINGS */
00383 
00384 }
00385 
00386 void wc_ErrorString(int error, char* buffer)
00387 {
00388     XSTRNCPY(buffer, wc_GetErrorString(error), WOLFSSL_MAX_ERROR_SZ);
00389 }
00390