Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
error.c
00001 /* 00002 * Error message information 00003 * 00004 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 00005 * SPDX-License-Identifier: Apache-2.0 00006 * 00007 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00008 * not use this file except in compliance with the License. 00009 * You may obtain a copy of the License at 00010 * 00011 * http://www.apache.org/licenses/LICENSE-2.0 00012 * 00013 * Unless required by applicable law or agreed to in writing, software 00014 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00015 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00016 * See the License for the specific language governing permissions and 00017 * limitations under the License. 00018 * 00019 * This file is part of mbed TLS (https://tls.mbed.org) 00020 */ 00021 00022 #if !defined(MBEDTLS_CONFIG_FILE) 00023 #include "mbedtls/config.h" 00024 #else 00025 #include MBEDTLS_CONFIG_FILE 00026 #endif 00027 00028 #if defined(MBEDTLS_ERROR_C) || defined(MBEDTLS_ERROR_STRERROR_DUMMY) 00029 #include "mbedtls/error.h" 00030 #include <string.h> 00031 #endif 00032 00033 #if defined(MBEDTLS_PLATFORM_C) 00034 #include "mbedtls/platform.h" 00035 #else 00036 #define mbedtls_snprintf snprintf 00037 #define mbedtls_time_t time_t 00038 #endif 00039 00040 #if defined(MBEDTLS_ERROR_C) 00041 00042 #include <stdio.h> 00043 00044 #if defined(MBEDTLS_AES_C) 00045 #include "mbedtls/aes.h" 00046 #endif 00047 00048 #if defined(MBEDTLS_ARC4_C) 00049 #include "mbedtls/arc4.h" 00050 #endif 00051 00052 #if defined(MBEDTLS_ARIA_C) 00053 #include "mbedtls/aria.h" 00054 #endif 00055 00056 #if defined(MBEDTLS_BASE64_C) 00057 #include "mbedtls/base64.h" 00058 #endif 00059 00060 #if defined(MBEDTLS_BIGNUM_C) 00061 #include "mbedtls/bignum.h" 00062 #endif 00063 00064 #if defined(MBEDTLS_BLOWFISH_C) 00065 #include "mbedtls/blowfish.h" 00066 #endif 00067 00068 #if defined(MBEDTLS_CAMELLIA_C) 00069 #include "mbedtls/camellia.h" 00070 #endif 00071 00072 #if defined(MBEDTLS_CCM_C) 00073 #include "mbedtls/ccm.h" 00074 #endif 00075 00076 #if defined(MBEDTLS_CHACHA20_C) 00077 #include "mbedtls/chacha20.h" 00078 #endif 00079 00080 #if defined(MBEDTLS_CHACHAPOLY_C) 00081 #include "mbedtls/chachapoly.h" 00082 #endif 00083 00084 #if defined(MBEDTLS_CIPHER_C) 00085 #include "mbedtls/cipher.h" 00086 #endif 00087 00088 #if defined(MBEDTLS_CMAC_C) 00089 #include "mbedtls/cmac.h" 00090 #endif 00091 00092 #if defined(MBEDTLS_CTR_DRBG_C) 00093 #include "mbedtls/ctr_drbg.h" 00094 #endif 00095 00096 #if defined(MBEDTLS_DES_C) 00097 #include "mbedtls/des.h" 00098 #endif 00099 00100 #if defined(MBEDTLS_DHM_C) 00101 #include "mbedtls/dhm.h" 00102 #endif 00103 00104 #if defined(MBEDTLS_ECP_C) 00105 #include "mbedtls/ecp.h" 00106 #endif 00107 00108 #if defined(MBEDTLS_ENTROPY_C) 00109 #include "mbedtls/entropy.h" 00110 #endif 00111 00112 #if defined(MBEDTLS_GCM_C) 00113 #include "mbedtls/gcm.h" 00114 #endif 00115 00116 #if defined(MBEDTLS_HKDF_C) 00117 #include "mbedtls/hkdf.h" 00118 #endif 00119 00120 #if defined(MBEDTLS_HMAC_DRBG_C) 00121 #include "mbedtls/hmac_drbg.h" 00122 #endif 00123 00124 #if defined(MBEDTLS_MD_C) 00125 #include "mbedtls/md.h" 00126 #endif 00127 00128 #if defined(MBEDTLS_MD2_C) 00129 #include "mbedtls/md2.h" 00130 #endif 00131 00132 #if defined(MBEDTLS_MD4_C) 00133 #include "mbedtls/md4.h" 00134 #endif 00135 00136 #if defined(MBEDTLS_MD5_C) 00137 #include "mbedtls/md5.h" 00138 #endif 00139 00140 #if defined(MBEDTLS_NET_C) 00141 #include "mbedtls/net_sockets.h" 00142 #endif 00143 00144 #if defined(MBEDTLS_OID_C) 00145 #include "mbedtls/oid.h" 00146 #endif 00147 00148 #if defined(MBEDTLS_PADLOCK_C) 00149 #include "mbedtls/padlock.h" 00150 #endif 00151 00152 #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C) 00153 #include "mbedtls/pem.h" 00154 #endif 00155 00156 #if defined(MBEDTLS_PK_C) 00157 #include "mbedtls/pk.h" 00158 #endif 00159 00160 #if defined(MBEDTLS_PKCS12_C) 00161 #include "mbedtls/pkcs12.h" 00162 #endif 00163 00164 #if defined(MBEDTLS_PKCS5_C) 00165 #include "mbedtls/pkcs5.h" 00166 #endif 00167 00168 #if defined(MBEDTLS_POLY1305_C) 00169 #include "mbedtls/poly1305.h" 00170 #endif 00171 00172 #if defined(MBEDTLS_RIPEMD160_C) 00173 #include "mbedtls/ripemd160.h" 00174 #endif 00175 00176 #if defined(MBEDTLS_RSA_C) 00177 #include "mbedtls/rsa.h" 00178 #endif 00179 00180 #if defined(MBEDTLS_SHA1_C) 00181 #include "mbedtls/sha1.h" 00182 #endif 00183 00184 #if defined(MBEDTLS_SHA256_C) 00185 #include "mbedtls/sha256.h" 00186 #endif 00187 00188 #if defined(MBEDTLS_SHA512_C) 00189 #include "mbedtls/sha512.h" 00190 #endif 00191 00192 #if defined(MBEDTLS_SSL_TLS_C) 00193 #include "mbedtls/ssl.h" 00194 #endif 00195 00196 #if defined(MBEDTLS_THREADING_C) 00197 #include "mbedtls/threading.h" 00198 #endif 00199 00200 #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C) 00201 #include "mbedtls/x509.h" 00202 #endif 00203 00204 #if defined(MBEDTLS_XTEA_C) 00205 #include "mbedtls/xtea.h" 00206 #endif 00207 00208 00209 void mbedtls_strerror( int ret, char *buf, size_t buflen ) 00210 { 00211 size_t len; 00212 int use_ret; 00213 00214 if( buflen == 0 ) 00215 return; 00216 00217 memset( buf, 0x00, buflen ); 00218 00219 if( ret < 0 ) 00220 ret = -ret; 00221 00222 if( ret & 0xFF80 ) 00223 { 00224 use_ret = ret & 0xFF80; 00225 00226 // High level error codes 00227 // 00228 // BEGIN generated code 00229 #if defined(MBEDTLS_CIPHER_C) 00230 if( use_ret == -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE) ) 00231 mbedtls_snprintf( buf, buflen, "CIPHER - The selected feature is not available" ); 00232 if( use_ret == -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA) ) 00233 mbedtls_snprintf( buf, buflen, "CIPHER - Bad input parameters" ); 00234 if( use_ret == -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED) ) 00235 mbedtls_snprintf( buf, buflen, "CIPHER - Failed to allocate memory" ); 00236 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_PADDING) ) 00237 mbedtls_snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" ); 00238 if( use_ret == -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED) ) 00239 mbedtls_snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" ); 00240 if( use_ret == -(MBEDTLS_ERR_CIPHER_AUTH_FAILED) ) 00241 mbedtls_snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" ); 00242 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT) ) 00243 mbedtls_snprintf( buf, buflen, "CIPHER - The context is invalid. For example, because it was freed" ); 00244 if( use_ret == -(MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED) ) 00245 mbedtls_snprintf( buf, buflen, "CIPHER - Cipher hardware accelerator failed" ); 00246 #endif /* MBEDTLS_CIPHER_C */ 00247 00248 #if defined(MBEDTLS_DHM_C) 00249 if( use_ret == -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA) ) 00250 mbedtls_snprintf( buf, buflen, "DHM - Bad input parameters" ); 00251 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED) ) 00252 mbedtls_snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" ); 00253 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED) ) 00254 mbedtls_snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" ); 00255 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED) ) 00256 mbedtls_snprintf( buf, buflen, "DHM - Reading of the public values failed" ); 00257 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED) ) 00258 mbedtls_snprintf( buf, buflen, "DHM - Making of the public value failed" ); 00259 if( use_ret == -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED) ) 00260 mbedtls_snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" ); 00261 if( use_ret == -(MBEDTLS_ERR_DHM_INVALID_FORMAT) ) 00262 mbedtls_snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" ); 00263 if( use_ret == -(MBEDTLS_ERR_DHM_ALLOC_FAILED) ) 00264 mbedtls_snprintf( buf, buflen, "DHM - Allocation of memory failed" ); 00265 if( use_ret == -(MBEDTLS_ERR_DHM_FILE_IO_ERROR) ) 00266 mbedtls_snprintf( buf, buflen, "DHM - Read or write of file failed" ); 00267 if( use_ret == -(MBEDTLS_ERR_DHM_HW_ACCEL_FAILED) ) 00268 mbedtls_snprintf( buf, buflen, "DHM - DHM hardware accelerator failed" ); 00269 if( use_ret == -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED) ) 00270 mbedtls_snprintf( buf, buflen, "DHM - Setting the modulus and generator failed" ); 00271 #endif /* MBEDTLS_DHM_C */ 00272 00273 #if defined(MBEDTLS_ECP_C) 00274 if( use_ret == -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA) ) 00275 mbedtls_snprintf( buf, buflen, "ECP - Bad input parameters to function" ); 00276 if( use_ret == -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL) ) 00277 mbedtls_snprintf( buf, buflen, "ECP - The buffer is too small to write to" ); 00278 if( use_ret == -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) ) 00279 mbedtls_snprintf( buf, buflen, "ECP - The requested feature is not available, for example, the requested curve is not supported" ); 00280 if( use_ret == -(MBEDTLS_ERR_ECP_VERIFY_FAILED) ) 00281 mbedtls_snprintf( buf, buflen, "ECP - The signature is not valid" ); 00282 if( use_ret == -(MBEDTLS_ERR_ECP_ALLOC_FAILED) ) 00283 mbedtls_snprintf( buf, buflen, "ECP - Memory allocation failed" ); 00284 if( use_ret == -(MBEDTLS_ERR_ECP_RANDOM_FAILED) ) 00285 mbedtls_snprintf( buf, buflen, "ECP - Generation of random value, such as ephemeral key, failed" ); 00286 if( use_ret == -(MBEDTLS_ERR_ECP_INVALID_KEY) ) 00287 mbedtls_snprintf( buf, buflen, "ECP - Invalid private or public key" ); 00288 if( use_ret == -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) ) 00289 mbedtls_snprintf( buf, buflen, "ECP - The buffer contains a valid signature followed by more data" ); 00290 if( use_ret == -(MBEDTLS_ERR_ECP_HW_ACCEL_FAILED) ) 00291 mbedtls_snprintf( buf, buflen, "ECP - The ECP hardware accelerator failed" ); 00292 #endif /* MBEDTLS_ECP_C */ 00293 00294 #if defined(MBEDTLS_MD_C) 00295 if( use_ret == -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE) ) 00296 mbedtls_snprintf( buf, buflen, "MD - The selected feature is not available" ); 00297 if( use_ret == -(MBEDTLS_ERR_MD_BAD_INPUT_DATA) ) 00298 mbedtls_snprintf( buf, buflen, "MD - Bad input parameters to function" ); 00299 if( use_ret == -(MBEDTLS_ERR_MD_ALLOC_FAILED) ) 00300 mbedtls_snprintf( buf, buflen, "MD - Failed to allocate memory" ); 00301 if( use_ret == -(MBEDTLS_ERR_MD_FILE_IO_ERROR) ) 00302 mbedtls_snprintf( buf, buflen, "MD - Opening or reading of file failed" ); 00303 if( use_ret == -(MBEDTLS_ERR_MD_HW_ACCEL_FAILED) ) 00304 mbedtls_snprintf( buf, buflen, "MD - MD hardware accelerator failed" ); 00305 #endif /* MBEDTLS_MD_C */ 00306 00307 #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C) 00308 if( use_ret == -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) ) 00309 mbedtls_snprintf( buf, buflen, "PEM - No PEM header or footer found" ); 00310 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_DATA) ) 00311 mbedtls_snprintf( buf, buflen, "PEM - PEM string is not as expected" ); 00312 if( use_ret == -(MBEDTLS_ERR_PEM_ALLOC_FAILED) ) 00313 mbedtls_snprintf( buf, buflen, "PEM - Failed to allocate memory" ); 00314 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_ENC_IV) ) 00315 mbedtls_snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" ); 00316 if( use_ret == -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG) ) 00317 mbedtls_snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" ); 00318 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) ) 00319 mbedtls_snprintf( buf, buflen, "PEM - Private key password can't be empty" ); 00320 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) ) 00321 mbedtls_snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" ); 00322 if( use_ret == -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE) ) 00323 mbedtls_snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" ); 00324 if( use_ret == -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA) ) 00325 mbedtls_snprintf( buf, buflen, "PEM - Bad input parameters to function" ); 00326 #endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */ 00327 00328 #if defined(MBEDTLS_PK_C) 00329 if( use_ret == -(MBEDTLS_ERR_PK_ALLOC_FAILED) ) 00330 mbedtls_snprintf( buf, buflen, "PK - Memory allocation failed" ); 00331 if( use_ret == -(MBEDTLS_ERR_PK_TYPE_MISMATCH) ) 00332 mbedtls_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" ); 00333 if( use_ret == -(MBEDTLS_ERR_PK_BAD_INPUT_DATA) ) 00334 mbedtls_snprintf( buf, buflen, "PK - Bad input parameters to function" ); 00335 if( use_ret == -(MBEDTLS_ERR_PK_FILE_IO_ERROR) ) 00336 mbedtls_snprintf( buf, buflen, "PK - Read/write of file failed" ); 00337 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION) ) 00338 mbedtls_snprintf( buf, buflen, "PK - Unsupported key version" ); 00339 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT) ) 00340 mbedtls_snprintf( buf, buflen, "PK - Invalid key tag or value" ); 00341 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG) ) 00342 mbedtls_snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" ); 00343 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED) ) 00344 mbedtls_snprintf( buf, buflen, "PK - Private key password can't be empty" ); 00345 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH) ) 00346 mbedtls_snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" ); 00347 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_PUBKEY) ) 00348 mbedtls_snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" ); 00349 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_ALG) ) 00350 mbedtls_snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" ); 00351 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE) ) 00352 mbedtls_snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" ); 00353 if( use_ret == -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) ) 00354 mbedtls_snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" ); 00355 if( use_ret == -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH) ) 00356 mbedtls_snprintf( buf, buflen, "PK - The buffer contains a valid signature followed by more data" ); 00357 if( use_ret == -(MBEDTLS_ERR_PK_HW_ACCEL_FAILED) ) 00358 mbedtls_snprintf( buf, buflen, "PK - PK hardware accelerator failed" ); 00359 #endif /* MBEDTLS_PK_C */ 00360 00361 #if defined(MBEDTLS_PKCS12_C) 00362 if( use_ret == -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA) ) 00363 mbedtls_snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" ); 00364 if( use_ret == -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE) ) 00365 mbedtls_snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" ); 00366 if( use_ret == -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT) ) 00367 mbedtls_snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" ); 00368 if( use_ret == -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) ) 00369 mbedtls_snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" ); 00370 #endif /* MBEDTLS_PKCS12_C */ 00371 00372 #if defined(MBEDTLS_PKCS5_C) 00373 if( use_ret == -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA) ) 00374 mbedtls_snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" ); 00375 if( use_ret == -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT) ) 00376 mbedtls_snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" ); 00377 if( use_ret == -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE) ) 00378 mbedtls_snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" ); 00379 if( use_ret == -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) ) 00380 mbedtls_snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" ); 00381 #endif /* MBEDTLS_PKCS5_C */ 00382 00383 #if defined(MBEDTLS_RSA_C) 00384 if( use_ret == -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA) ) 00385 mbedtls_snprintf( buf, buflen, "RSA - Bad input parameters to function" ); 00386 if( use_ret == -(MBEDTLS_ERR_RSA_INVALID_PADDING) ) 00387 mbedtls_snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" ); 00388 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED) ) 00389 mbedtls_snprintf( buf, buflen, "RSA - Something failed during generation of a key" ); 00390 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED) ) 00391 mbedtls_snprintf( buf, buflen, "RSA - Key failed to pass the validity check of the library" ); 00392 if( use_ret == -(MBEDTLS_ERR_RSA_PUBLIC_FAILED) ) 00393 mbedtls_snprintf( buf, buflen, "RSA - The public key operation failed" ); 00394 if( use_ret == -(MBEDTLS_ERR_RSA_PRIVATE_FAILED) ) 00395 mbedtls_snprintf( buf, buflen, "RSA - The private key operation failed" ); 00396 if( use_ret == -(MBEDTLS_ERR_RSA_VERIFY_FAILED) ) 00397 mbedtls_snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" ); 00398 if( use_ret == -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE) ) 00399 mbedtls_snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" ); 00400 if( use_ret == -(MBEDTLS_ERR_RSA_RNG_FAILED) ) 00401 mbedtls_snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" ); 00402 if( use_ret == -(MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION) ) 00403 mbedtls_snprintf( buf, buflen, "RSA - The implementation does not offer the requested operation, for example, because of security violations or lack of functionality" ); 00404 if( use_ret == -(MBEDTLS_ERR_RSA_HW_ACCEL_FAILED) ) 00405 mbedtls_snprintf( buf, buflen, "RSA - RSA hardware accelerator failed" ); 00406 #endif /* MBEDTLS_RSA_C */ 00407 00408 #if defined(MBEDTLS_SSL_TLS_C) 00409 if( use_ret == -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE) ) 00410 mbedtls_snprintf( buf, buflen, "SSL - The requested feature is not available" ); 00411 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA) ) 00412 mbedtls_snprintf( buf, buflen, "SSL - Bad input parameters to function" ); 00413 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_MAC) ) 00414 mbedtls_snprintf( buf, buflen, "SSL - Verification of the message MAC failed" ); 00415 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_RECORD) ) 00416 mbedtls_snprintf( buf, buflen, "SSL - An invalid SSL record was received" ); 00417 if( use_ret == -(MBEDTLS_ERR_SSL_CONN_EOF) ) 00418 mbedtls_snprintf( buf, buflen, "SSL - The connection indicated an EOF" ); 00419 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER) ) 00420 mbedtls_snprintf( buf, buflen, "SSL - An unknown cipher was received" ); 00421 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN) ) 00422 mbedtls_snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" ); 00423 if( use_ret == -(MBEDTLS_ERR_SSL_NO_RNG) ) 00424 mbedtls_snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" ); 00425 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE) ) 00426 mbedtls_snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" ); 00427 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE) ) 00428 mbedtls_snprintf( buf, buflen, "SSL - Our own certificate(s) is/are too large to send in an SSL message" ); 00429 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED) ) 00430 mbedtls_snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" ); 00431 if( use_ret == -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED) ) 00432 mbedtls_snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" ); 00433 if( use_ret == -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED) ) 00434 mbedtls_snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" ); 00435 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE) ) 00436 mbedtls_snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" ); 00437 if( use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE) ) 00438 { 00439 mbedtls_snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" ); 00440 return; 00441 } 00442 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED) ) 00443 mbedtls_snprintf( buf, buflen, "SSL - Verification of our peer failed" ); 00444 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) ) 00445 mbedtls_snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" ); 00446 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO) ) 00447 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" ); 00448 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO) ) 00449 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" ); 00450 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE) ) 00451 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" ); 00452 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) ) 00453 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" ); 00454 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) ) 00455 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" ); 00456 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) ) 00457 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" ); 00458 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) ) 00459 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" ); 00460 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) ) 00461 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" ); 00462 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) ) 00463 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" ); 00464 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) ) 00465 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" ); 00466 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) ) 00467 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" ); 00468 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED) ) 00469 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" ); 00470 if( use_ret == -(MBEDTLS_ERR_SSL_ALLOC_FAILED) ) 00471 mbedtls_snprintf( buf, buflen, "SSL - Memory allocation failed" ); 00472 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED) ) 00473 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" ); 00474 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH) ) 00475 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" ); 00476 if( use_ret == -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED) ) 00477 mbedtls_snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" ); 00478 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION) ) 00479 mbedtls_snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" ); 00480 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) ) 00481 mbedtls_snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" ); 00482 if( use_ret == -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED) ) 00483 mbedtls_snprintf( buf, buflen, "SSL - Session ticket has expired" ); 00484 if( use_ret == -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH) ) 00485 mbedtls_snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" ); 00486 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY) ) 00487 mbedtls_snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" ); 00488 if( use_ret == -(MBEDTLS_ERR_SSL_INTERNAL_ERROR) ) 00489 mbedtls_snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" ); 00490 if( use_ret == -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING) ) 00491 mbedtls_snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" ); 00492 if( use_ret == -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO) ) 00493 mbedtls_snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" ); 00494 if( use_ret == -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED) ) 00495 mbedtls_snprintf( buf, buflen, "SSL - DTLS client must retry for hello verification" ); 00496 if( use_ret == -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL) ) 00497 mbedtls_snprintf( buf, buflen, "SSL - A buffer is too small to receive or write a message" ); 00498 if( use_ret == -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE) ) 00499 mbedtls_snprintf( buf, buflen, "SSL - None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages)" ); 00500 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_READ) ) 00501 mbedtls_snprintf( buf, buflen, "SSL - No data of requested type currently available on underlying transport" ); 00502 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_WRITE) ) 00503 mbedtls_snprintf( buf, buflen, "SSL - Connection requires a write call" ); 00504 if( use_ret == -(MBEDTLS_ERR_SSL_TIMEOUT) ) 00505 mbedtls_snprintf( buf, buflen, "SSL - The operation timed out" ); 00506 if( use_ret == -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT) ) 00507 mbedtls_snprintf( buf, buflen, "SSL - The client initiated a reconnect from the same port" ); 00508 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD) ) 00509 mbedtls_snprintf( buf, buflen, "SSL - Record header looks valid but is not expected" ); 00510 if( use_ret == -(MBEDTLS_ERR_SSL_NON_FATAL) ) 00511 mbedtls_snprintf( buf, buflen, "SSL - The alert message received indicates a non-fatal error" ); 00512 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH) ) 00513 mbedtls_snprintf( buf, buflen, "SSL - Couldn't set the hash for verifying CertificateVerify" ); 00514 if( use_ret == -(MBEDTLS_ERR_SSL_CONTINUE_PROCESSING) ) 00515 mbedtls_snprintf( buf, buflen, "SSL - Internal-only message signaling that further message-processing should be done" ); 00516 if( use_ret == -(MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS) ) 00517 mbedtls_snprintf( buf, buflen, "SSL - The asynchronous operation is not completed yet" ); 00518 if( use_ret == -(MBEDTLS_ERR_SSL_EARLY_MESSAGE) ) 00519 mbedtls_snprintf( buf, buflen, "SSL - Internal-only message signaling that a message arrived early" ); 00520 #endif /* MBEDTLS_SSL_TLS_C */ 00521 00522 #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C) 00523 if( use_ret == -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) ) 00524 mbedtls_snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" ); 00525 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_OID) ) 00526 mbedtls_snprintf( buf, buflen, "X509 - Requested OID is unknown" ); 00527 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_FORMAT) ) 00528 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" ); 00529 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_VERSION) ) 00530 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" ); 00531 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SERIAL) ) 00532 mbedtls_snprintf( buf, buflen, "X509 - The serial tag or value is invalid" ); 00533 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_ALG) ) 00534 mbedtls_snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" ); 00535 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_NAME) ) 00536 mbedtls_snprintf( buf, buflen, "X509 - The name tag or value is invalid" ); 00537 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_DATE) ) 00538 mbedtls_snprintf( buf, buflen, "X509 - The date tag or value is invalid" ); 00539 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SIGNATURE) ) 00540 mbedtls_snprintf( buf, buflen, "X509 - The signature tag or value invalid" ); 00541 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS) ) 00542 mbedtls_snprintf( buf, buflen, "X509 - The extension tag or value is invalid" ); 00543 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_VERSION) ) 00544 mbedtls_snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" ); 00545 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG) ) 00546 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" ); 00547 if( use_ret == -(MBEDTLS_ERR_X509_SIG_MISMATCH) ) 00548 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" ); 00549 if( use_ret == -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) ) 00550 mbedtls_snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" ); 00551 if( use_ret == -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT) ) 00552 mbedtls_snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" ); 00553 if( use_ret == -(MBEDTLS_ERR_X509_BAD_INPUT_DATA) ) 00554 mbedtls_snprintf( buf, buflen, "X509 - Input invalid" ); 00555 if( use_ret == -(MBEDTLS_ERR_X509_ALLOC_FAILED) ) 00556 mbedtls_snprintf( buf, buflen, "X509 - Allocation of memory failed" ); 00557 if( use_ret == -(MBEDTLS_ERR_X509_FILE_IO_ERROR) ) 00558 mbedtls_snprintf( buf, buflen, "X509 - Read/write of file failed" ); 00559 if( use_ret == -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL) ) 00560 mbedtls_snprintf( buf, buflen, "X509 - Destination buffer is too small" ); 00561 if( use_ret == -(MBEDTLS_ERR_X509_FATAL_ERROR) ) 00562 mbedtls_snprintf( buf, buflen, "X509 - A fatal error occured, eg the chain is too long or the vrfy callback failed" ); 00563 #endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */ 00564 // END generated code 00565 00566 if( strlen( buf ) == 0 ) 00567 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret ); 00568 } 00569 00570 use_ret = ret & ~0xFF80; 00571 00572 if( use_ret == 0 ) 00573 return; 00574 00575 // If high level code is present, make a concatenation between both 00576 // error strings. 00577 // 00578 len = strlen( buf ); 00579 00580 if( len > 0 ) 00581 { 00582 if( buflen - len < 5 ) 00583 return; 00584 00585 mbedtls_snprintf( buf + len, buflen - len, " : " ); 00586 00587 buf += len + 3; 00588 buflen -= len + 3; 00589 } 00590 00591 // Low level error codes 00592 // 00593 // BEGIN generated code 00594 #if defined(MBEDTLS_AES_C) 00595 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH) ) 00596 mbedtls_snprintf( buf, buflen, "AES - Invalid key length" ); 00597 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH) ) 00598 mbedtls_snprintf( buf, buflen, "AES - Invalid data input length" ); 00599 if( use_ret == -(MBEDTLS_ERR_AES_BAD_INPUT_DATA) ) 00600 mbedtls_snprintf( buf, buflen, "AES - Invalid input data" ); 00601 if( use_ret == -(MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE) ) 00602 mbedtls_snprintf( buf, buflen, "AES - Feature not available. For example, an unsupported AES key size" ); 00603 if( use_ret == -(MBEDTLS_ERR_AES_HW_ACCEL_FAILED) ) 00604 mbedtls_snprintf( buf, buflen, "AES - AES hardware accelerator failed" ); 00605 #endif /* MBEDTLS_AES_C */ 00606 00607 #if defined(MBEDTLS_ARC4_C) 00608 if( use_ret == -(MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED) ) 00609 mbedtls_snprintf( buf, buflen, "ARC4 - ARC4 hardware accelerator failed" ); 00610 #endif /* MBEDTLS_ARC4_C */ 00611 00612 #if defined(MBEDTLS_ARIA_C) 00613 if( use_ret == -(MBEDTLS_ERR_ARIA_INVALID_KEY_LENGTH) ) 00614 mbedtls_snprintf( buf, buflen, "ARIA - Invalid key length" ); 00615 if( use_ret == -(MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH) ) 00616 mbedtls_snprintf( buf, buflen, "ARIA - Invalid data input length" ); 00617 if( use_ret == -(MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE) ) 00618 mbedtls_snprintf( buf, buflen, "ARIA - Feature not available. For example, an unsupported ARIA key size" ); 00619 if( use_ret == -(MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED) ) 00620 mbedtls_snprintf( buf, buflen, "ARIA - ARIA hardware accelerator failed" ); 00621 #endif /* MBEDTLS_ARIA_C */ 00622 00623 #if defined(MBEDTLS_ASN1_PARSE_C) 00624 if( use_ret == -(MBEDTLS_ERR_ASN1_OUT_OF_DATA) ) 00625 mbedtls_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" ); 00626 if( use_ret == -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) ) 00627 mbedtls_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" ); 00628 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_LENGTH) ) 00629 mbedtls_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" ); 00630 if( use_ret == -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH) ) 00631 mbedtls_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" ); 00632 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_DATA) ) 00633 mbedtls_snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" ); 00634 if( use_ret == -(MBEDTLS_ERR_ASN1_ALLOC_FAILED) ) 00635 mbedtls_snprintf( buf, buflen, "ASN1 - Memory allocation failed" ); 00636 if( use_ret == -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL) ) 00637 mbedtls_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" ); 00638 #endif /* MBEDTLS_ASN1_PARSE_C */ 00639 00640 #if defined(MBEDTLS_BASE64_C) 00641 if( use_ret == -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) ) 00642 mbedtls_snprintf( buf, buflen, "BASE64 - Output buffer too small" ); 00643 if( use_ret == -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER) ) 00644 mbedtls_snprintf( buf, buflen, "BASE64 - Invalid character in input" ); 00645 #endif /* MBEDTLS_BASE64_C */ 00646 00647 #if defined(MBEDTLS_BIGNUM_C) 00648 if( use_ret == -(MBEDTLS_ERR_MPI_FILE_IO_ERROR) ) 00649 mbedtls_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" ); 00650 if( use_ret == -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA) ) 00651 mbedtls_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" ); 00652 if( use_ret == -(MBEDTLS_ERR_MPI_INVALID_CHARACTER) ) 00653 mbedtls_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" ); 00654 if( use_ret == -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL) ) 00655 mbedtls_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" ); 00656 if( use_ret == -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE) ) 00657 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" ); 00658 if( use_ret == -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO) ) 00659 mbedtls_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" ); 00660 if( use_ret == -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) ) 00661 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" ); 00662 if( use_ret == -(MBEDTLS_ERR_MPI_ALLOC_FAILED) ) 00663 mbedtls_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" ); 00664 #endif /* MBEDTLS_BIGNUM_C */ 00665 00666 #if defined(MBEDTLS_BLOWFISH_C) 00667 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH) ) 00668 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid key length" ); 00669 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED) ) 00670 mbedtls_snprintf( buf, buflen, "BLOWFISH - Blowfish hardware accelerator failed" ); 00671 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH) ) 00672 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" ); 00673 #endif /* MBEDTLS_BLOWFISH_C */ 00674 00675 #if defined(MBEDTLS_CAMELLIA_C) 00676 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH) ) 00677 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid key length" ); 00678 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH) ) 00679 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" ); 00680 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED) ) 00681 mbedtls_snprintf( buf, buflen, "CAMELLIA - Camellia hardware accelerator failed" ); 00682 #endif /* MBEDTLS_CAMELLIA_C */ 00683 00684 #if defined(MBEDTLS_CCM_C) 00685 if( use_ret == -(MBEDTLS_ERR_CCM_BAD_INPUT) ) 00686 mbedtls_snprintf( buf, buflen, "CCM - Bad input parameters to the function" ); 00687 if( use_ret == -(MBEDTLS_ERR_CCM_AUTH_FAILED) ) 00688 mbedtls_snprintf( buf, buflen, "CCM - Authenticated decryption failed" ); 00689 if( use_ret == -(MBEDTLS_ERR_CCM_HW_ACCEL_FAILED) ) 00690 mbedtls_snprintf( buf, buflen, "CCM - CCM hardware accelerator failed" ); 00691 #endif /* MBEDTLS_CCM_C */ 00692 00693 #if defined(MBEDTLS_CHACHA20_C) 00694 if( use_ret == -(MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA) ) 00695 mbedtls_snprintf( buf, buflen, "CHACHA20 - Invalid input parameter(s)" ); 00696 if( use_ret == -(MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE) ) 00697 mbedtls_snprintf( buf, buflen, "CHACHA20 - Feature not available. For example, s part of the API is not implemented" ); 00698 if( use_ret == -(MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED) ) 00699 mbedtls_snprintf( buf, buflen, "CHACHA20 - Chacha20 hardware accelerator failed" ); 00700 #endif /* MBEDTLS_CHACHA20_C */ 00701 00702 #if defined(MBEDTLS_CHACHAPOLY_C) 00703 if( use_ret == -(MBEDTLS_ERR_CHACHAPOLY_BAD_STATE) ) 00704 mbedtls_snprintf( buf, buflen, "CHACHAPOLY - The requested operation is not permitted in the current state" ); 00705 if( use_ret == -(MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED) ) 00706 mbedtls_snprintf( buf, buflen, "CHACHAPOLY - Authenticated decryption failed: data was not authentic" ); 00707 #endif /* MBEDTLS_CHACHAPOLY_C */ 00708 00709 #if defined(MBEDTLS_CMAC_C) 00710 if( use_ret == -(MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED) ) 00711 mbedtls_snprintf( buf, buflen, "CMAC - CMAC hardware accelerator failed" ); 00712 #endif /* MBEDTLS_CMAC_C */ 00713 00714 #if defined(MBEDTLS_CTR_DRBG_C) 00715 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) ) 00716 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" ); 00717 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG) ) 00718 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The requested random buffer length is too big" ); 00719 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG) ) 00720 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The input (entropy + additional data) is too large" ); 00721 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR) ) 00722 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Read or write error in file" ); 00723 #endif /* MBEDTLS_CTR_DRBG_C */ 00724 00725 #if defined(MBEDTLS_DES_C) 00726 if( use_ret == -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH) ) 00727 mbedtls_snprintf( buf, buflen, "DES - The data input has an invalid length" ); 00728 if( use_ret == -(MBEDTLS_ERR_DES_HW_ACCEL_FAILED) ) 00729 mbedtls_snprintf( buf, buflen, "DES - DES hardware accelerator failed" ); 00730 #endif /* MBEDTLS_DES_C */ 00731 00732 #if defined(MBEDTLS_ENTROPY_C) 00733 if( use_ret == -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED) ) 00734 mbedtls_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" ); 00735 if( use_ret == -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES) ) 00736 mbedtls_snprintf( buf, buflen, "ENTROPY - No more sources can be added" ); 00737 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED) ) 00738 mbedtls_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" ); 00739 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE) ) 00740 mbedtls_snprintf( buf, buflen, "ENTROPY - No strong sources have been added to poll" ); 00741 if( use_ret == -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR) ) 00742 mbedtls_snprintf( buf, buflen, "ENTROPY - Read/write error in file" ); 00743 #endif /* MBEDTLS_ENTROPY_C */ 00744 00745 #if defined(MBEDTLS_GCM_C) 00746 if( use_ret == -(MBEDTLS_ERR_GCM_AUTH_FAILED) ) 00747 mbedtls_snprintf( buf, buflen, "GCM - Authenticated decryption failed" ); 00748 if( use_ret == -(MBEDTLS_ERR_GCM_HW_ACCEL_FAILED) ) 00749 mbedtls_snprintf( buf, buflen, "GCM - GCM hardware accelerator failed" ); 00750 if( use_ret == -(MBEDTLS_ERR_GCM_BAD_INPUT) ) 00751 mbedtls_snprintf( buf, buflen, "GCM - Bad input parameters to function" ); 00752 #endif /* MBEDTLS_GCM_C */ 00753 00754 #if defined(MBEDTLS_HKDF_C) 00755 if( use_ret == -(MBEDTLS_ERR_HKDF_BAD_INPUT_DATA) ) 00756 mbedtls_snprintf( buf, buflen, "HKDF - Bad input parameters to function" ); 00757 #endif /* MBEDTLS_HKDF_C */ 00758 00759 #if defined(MBEDTLS_HMAC_DRBG_C) 00760 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG) ) 00761 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" ); 00762 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG) ) 00763 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" ); 00764 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR) ) 00765 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" ); 00766 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) ) 00767 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" ); 00768 #endif /* MBEDTLS_HMAC_DRBG_C */ 00769 00770 #if defined(MBEDTLS_MD2_C) 00771 if( use_ret == -(MBEDTLS_ERR_MD2_HW_ACCEL_FAILED) ) 00772 mbedtls_snprintf( buf, buflen, "MD2 - MD2 hardware accelerator failed" ); 00773 #endif /* MBEDTLS_MD2_C */ 00774 00775 #if defined(MBEDTLS_MD4_C) 00776 if( use_ret == -(MBEDTLS_ERR_MD4_HW_ACCEL_FAILED) ) 00777 mbedtls_snprintf( buf, buflen, "MD4 - MD4 hardware accelerator failed" ); 00778 #endif /* MBEDTLS_MD4_C */ 00779 00780 #if defined(MBEDTLS_MD5_C) 00781 if( use_ret == -(MBEDTLS_ERR_MD5_HW_ACCEL_FAILED) ) 00782 mbedtls_snprintf( buf, buflen, "MD5 - MD5 hardware accelerator failed" ); 00783 #endif /* MBEDTLS_MD5_C */ 00784 00785 #if defined(MBEDTLS_NET_C) 00786 if( use_ret == -(MBEDTLS_ERR_NET_SOCKET_FAILED) ) 00787 mbedtls_snprintf( buf, buflen, "NET - Failed to open a socket" ); 00788 if( use_ret == -(MBEDTLS_ERR_NET_CONNECT_FAILED) ) 00789 mbedtls_snprintf( buf, buflen, "NET - The connection to the given server / port failed" ); 00790 if( use_ret == -(MBEDTLS_ERR_NET_BIND_FAILED) ) 00791 mbedtls_snprintf( buf, buflen, "NET - Binding of the socket failed" ); 00792 if( use_ret == -(MBEDTLS_ERR_NET_LISTEN_FAILED) ) 00793 mbedtls_snprintf( buf, buflen, "NET - Could not listen on the socket" ); 00794 if( use_ret == -(MBEDTLS_ERR_NET_ACCEPT_FAILED) ) 00795 mbedtls_snprintf( buf, buflen, "NET - Could not accept the incoming connection" ); 00796 if( use_ret == -(MBEDTLS_ERR_NET_RECV_FAILED) ) 00797 mbedtls_snprintf( buf, buflen, "NET - Reading information from the socket failed" ); 00798 if( use_ret == -(MBEDTLS_ERR_NET_SEND_FAILED) ) 00799 mbedtls_snprintf( buf, buflen, "NET - Sending information through the socket failed" ); 00800 if( use_ret == -(MBEDTLS_ERR_NET_CONN_RESET) ) 00801 mbedtls_snprintf( buf, buflen, "NET - Connection was reset by peer" ); 00802 if( use_ret == -(MBEDTLS_ERR_NET_UNKNOWN_HOST) ) 00803 mbedtls_snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" ); 00804 if( use_ret == -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL) ) 00805 mbedtls_snprintf( buf, buflen, "NET - Buffer is too small to hold the data" ); 00806 if( use_ret == -(MBEDTLS_ERR_NET_INVALID_CONTEXT) ) 00807 mbedtls_snprintf( buf, buflen, "NET - The context is invalid, eg because it was free()ed" ); 00808 if( use_ret == -(MBEDTLS_ERR_NET_POLL_FAILED) ) 00809 mbedtls_snprintf( buf, buflen, "NET - Polling the net context failed" ); 00810 if( use_ret == -(MBEDTLS_ERR_NET_BAD_INPUT_DATA) ) 00811 mbedtls_snprintf( buf, buflen, "NET - Input invalid" ); 00812 #endif /* MBEDTLS_NET_C */ 00813 00814 #if defined(MBEDTLS_OID_C) 00815 if( use_ret == -(MBEDTLS_ERR_OID_NOT_FOUND) ) 00816 mbedtls_snprintf( buf, buflen, "OID - OID is not found" ); 00817 if( use_ret == -(MBEDTLS_ERR_OID_BUF_TOO_SMALL) ) 00818 mbedtls_snprintf( buf, buflen, "OID - output buffer is too small" ); 00819 #endif /* MBEDTLS_OID_C */ 00820 00821 #if defined(MBEDTLS_PADLOCK_C) 00822 if( use_ret == -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED) ) 00823 mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" ); 00824 #endif /* MBEDTLS_PADLOCK_C */ 00825 00826 #if defined(MBEDTLS_POLY1305_C) 00827 if( use_ret == -(MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA) ) 00828 mbedtls_snprintf( buf, buflen, "POLY1305 - Invalid input parameter(s)" ); 00829 if( use_ret == -(MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE) ) 00830 mbedtls_snprintf( buf, buflen, "POLY1305 - Feature not available. For example, s part of the API is not implemented" ); 00831 if( use_ret == -(MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED) ) 00832 mbedtls_snprintf( buf, buflen, "POLY1305 - Poly1305 hardware accelerator failed" ); 00833 #endif /* MBEDTLS_POLY1305_C */ 00834 00835 #if defined(MBEDTLS_RIPEMD160_C) 00836 if( use_ret == -(MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED) ) 00837 mbedtls_snprintf( buf, buflen, "RIPEMD160 - RIPEMD160 hardware accelerator failed" ); 00838 #endif /* MBEDTLS_RIPEMD160_C */ 00839 00840 #if defined(MBEDTLS_SHA1_C) 00841 if( use_ret == -(MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED) ) 00842 mbedtls_snprintf( buf, buflen, "SHA1 - SHA-1 hardware accelerator failed" ); 00843 #endif /* MBEDTLS_SHA1_C */ 00844 00845 #if defined(MBEDTLS_SHA256_C) 00846 if( use_ret == -(MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED) ) 00847 mbedtls_snprintf( buf, buflen, "SHA256 - SHA-256 hardware accelerator failed" ); 00848 #endif /* MBEDTLS_SHA256_C */ 00849 00850 #if defined(MBEDTLS_SHA512_C) 00851 if( use_ret == -(MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED) ) 00852 mbedtls_snprintf( buf, buflen, "SHA512 - SHA-512 hardware accelerator failed" ); 00853 #endif /* MBEDTLS_SHA512_C */ 00854 00855 #if defined(MBEDTLS_THREADING_C) 00856 if( use_ret == -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE) ) 00857 mbedtls_snprintf( buf, buflen, "THREADING - The selected feature is not available" ); 00858 if( use_ret == -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA) ) 00859 mbedtls_snprintf( buf, buflen, "THREADING - Bad input parameters to function" ); 00860 if( use_ret == -(MBEDTLS_ERR_THREADING_MUTEX_ERROR) ) 00861 mbedtls_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" ); 00862 #endif /* MBEDTLS_THREADING_C */ 00863 00864 #if defined(MBEDTLS_XTEA_C) 00865 if( use_ret == -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH) ) 00866 mbedtls_snprintf( buf, buflen, "XTEA - The data input has an invalid length" ); 00867 if( use_ret == -(MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED) ) 00868 mbedtls_snprintf( buf, buflen, "XTEA - XTEA hardware accelerator failed" ); 00869 #endif /* MBEDTLS_XTEA_C */ 00870 // END generated code 00871 00872 if( strlen( buf ) != 0 ) 00873 return; 00874 00875 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret ); 00876 } 00877 00878 #else /* MBEDTLS_ERROR_C */ 00879 00880 #if defined(MBEDTLS_ERROR_STRERROR_DUMMY) 00881 00882 /* 00883 * Provide an non-function in case MBEDTLS_ERROR_C is not defined 00884 */ 00885 void mbedtls_strerror( int ret, char *buf, size_t buflen ) 00886 { 00887 ((void) ret); 00888 00889 if( buflen > 0 ) 00890 buf[0] = '\0'; 00891 } 00892 00893 #endif /* MBEDTLS_ERROR_STRERROR_DUMMY */ 00894 00895 #endif /* MBEDTLS_ERROR_C */
Generated on Tue Jul 12 2022 20:52:41 by
1.7.2