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.
Dependents: mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510
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_BASE64_C) 00049 #include "mbedtls/base64.h" 00050 #endif 00051 00052 #if defined(MBEDTLS_BIGNUM_C) 00053 #include "mbedtls/bignum.h" 00054 #endif 00055 00056 #if defined(MBEDTLS_BLOWFISH_C) 00057 #include "mbedtls/blowfish.h" 00058 #endif 00059 00060 #if defined(MBEDTLS_CAMELLIA_C) 00061 #include "mbedtls/camellia.h" 00062 #endif 00063 00064 #if defined(MBEDTLS_CCM_C) 00065 #include "mbedtls/ccm.h" 00066 #endif 00067 00068 #if defined(MBEDTLS_CIPHER_C) 00069 #include "mbedtls/cipher.h" 00070 #endif 00071 00072 #if defined(MBEDTLS_CTR_DRBG_C) 00073 #include "mbedtls/ctr_drbg.h" 00074 #endif 00075 00076 #if defined(MBEDTLS_DES_C) 00077 #include "mbedtls/des.h" 00078 #endif 00079 00080 #if defined(MBEDTLS_DHM_C) 00081 #include "mbedtls/dhm.h" 00082 #endif 00083 00084 #if defined(MBEDTLS_ECP_C) 00085 #include "mbedtls/ecp.h" 00086 #endif 00087 00088 #if defined(MBEDTLS_ENTROPY_C) 00089 #include "mbedtls/entropy.h" 00090 #endif 00091 00092 #if defined(MBEDTLS_GCM_C) 00093 #include "mbedtls/gcm.h" 00094 #endif 00095 00096 #if defined(MBEDTLS_HMAC_DRBG_C) 00097 #include "mbedtls/hmac_drbg.h" 00098 #endif 00099 00100 #if defined(MBEDTLS_MD_C) 00101 #include "mbedtls/md.h" 00102 #endif 00103 00104 #if defined(MBEDTLS_NET_C) 00105 #include "mbedtls/net_sockets.h" 00106 #endif 00107 00108 #if defined(MBEDTLS_OID_C) 00109 #include "mbedtls/oid.h" 00110 #endif 00111 00112 #if defined(MBEDTLS_PADLOCK_C) 00113 #include "mbedtls/padlock.h" 00114 #endif 00115 00116 #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C) 00117 #include "mbedtls/pem.h" 00118 #endif 00119 00120 #if defined(MBEDTLS_PK_C) 00121 #include "mbedtls/pk.h" 00122 #endif 00123 00124 #if defined(MBEDTLS_PKCS12_C) 00125 #include "mbedtls/pkcs12.h" 00126 #endif 00127 00128 #if defined(MBEDTLS_PKCS5_C) 00129 #include "mbedtls/pkcs5.h" 00130 #endif 00131 00132 #if defined(MBEDTLS_RSA_C) 00133 #include "mbedtls/rsa.h" 00134 #endif 00135 00136 #if defined(MBEDTLS_SSL_TLS_C) 00137 #include "mbedtls/ssl.h" 00138 #endif 00139 00140 #if defined(MBEDTLS_THREADING_C) 00141 #include "mbedtls/threading.h" 00142 #endif 00143 00144 #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C) 00145 #include "mbedtls/x509.h" 00146 #endif 00147 00148 #if defined(MBEDTLS_XTEA_C) 00149 #include "mbedtls/xtea.h" 00150 #endif 00151 00152 00153 void mbedtls_strerror( int ret, char *buf, size_t buflen ) 00154 { 00155 size_t len; 00156 int use_ret; 00157 00158 if( buflen == 0 ) 00159 return; 00160 00161 memset( buf, 0x00, buflen ); 00162 00163 if( ret < 0 ) 00164 ret = -ret; 00165 00166 if( ret & 0xFF80 ) 00167 { 00168 use_ret = ret & 0xFF80; 00169 00170 // High level error codes 00171 // 00172 // BEGIN generated code 00173 #if defined(MBEDTLS_CIPHER_C) 00174 if( use_ret == -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE) ) 00175 mbedtls_snprintf( buf, buflen, "CIPHER - The selected feature is not available" ); 00176 if( use_ret == -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA) ) 00177 mbedtls_snprintf( buf, buflen, "CIPHER - Bad input parameters to function" ); 00178 if( use_ret == -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED) ) 00179 mbedtls_snprintf( buf, buflen, "CIPHER - Failed to allocate memory" ); 00180 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_PADDING) ) 00181 mbedtls_snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" ); 00182 if( use_ret == -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED) ) 00183 mbedtls_snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" ); 00184 if( use_ret == -(MBEDTLS_ERR_CIPHER_AUTH_FAILED) ) 00185 mbedtls_snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" ); 00186 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT) ) 00187 mbedtls_snprintf( buf, buflen, "CIPHER - The context is invalid, eg because it was free()ed" ); 00188 #endif /* MBEDTLS_CIPHER_C */ 00189 00190 #if defined(MBEDTLS_DHM_C) 00191 if( use_ret == -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA) ) 00192 mbedtls_snprintf( buf, buflen, "DHM - Bad input parameters to function" ); 00193 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED) ) 00194 mbedtls_snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" ); 00195 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED) ) 00196 mbedtls_snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" ); 00197 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED) ) 00198 mbedtls_snprintf( buf, buflen, "DHM - Reading of the public values failed" ); 00199 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED) ) 00200 mbedtls_snprintf( buf, buflen, "DHM - Making of the public value failed" ); 00201 if( use_ret == -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED) ) 00202 mbedtls_snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" ); 00203 if( use_ret == -(MBEDTLS_ERR_DHM_INVALID_FORMAT) ) 00204 mbedtls_snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" ); 00205 if( use_ret == -(MBEDTLS_ERR_DHM_ALLOC_FAILED) ) 00206 mbedtls_snprintf( buf, buflen, "DHM - Allocation of memory failed" ); 00207 if( use_ret == -(MBEDTLS_ERR_DHM_FILE_IO_ERROR) ) 00208 mbedtls_snprintf( buf, buflen, "DHM - Read/write of file failed" ); 00209 #endif /* MBEDTLS_DHM_C */ 00210 00211 #if defined(MBEDTLS_ECP_C) 00212 if( use_ret == -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA) ) 00213 mbedtls_snprintf( buf, buflen, "ECP - Bad input parameters to function" ); 00214 if( use_ret == -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL) ) 00215 mbedtls_snprintf( buf, buflen, "ECP - The buffer is too small to write to" ); 00216 if( use_ret == -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) ) 00217 mbedtls_snprintf( buf, buflen, "ECP - Requested curve not available" ); 00218 if( use_ret == -(MBEDTLS_ERR_ECP_VERIFY_FAILED) ) 00219 mbedtls_snprintf( buf, buflen, "ECP - The signature is not valid" ); 00220 if( use_ret == -(MBEDTLS_ERR_ECP_ALLOC_FAILED) ) 00221 mbedtls_snprintf( buf, buflen, "ECP - Memory allocation failed" ); 00222 if( use_ret == -(MBEDTLS_ERR_ECP_RANDOM_FAILED) ) 00223 mbedtls_snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" ); 00224 if( use_ret == -(MBEDTLS_ERR_ECP_INVALID_KEY) ) 00225 mbedtls_snprintf( buf, buflen, "ECP - Invalid private or public key" ); 00226 if( use_ret == -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) ) 00227 mbedtls_snprintf( buf, buflen, "ECP - Signature is valid but shorter than the user-supplied length" ); 00228 #endif /* MBEDTLS_ECP_C */ 00229 00230 #if defined(MBEDTLS_MD_C) 00231 if( use_ret == -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE) ) 00232 mbedtls_snprintf( buf, buflen, "MD - The selected feature is not available" ); 00233 if( use_ret == -(MBEDTLS_ERR_MD_BAD_INPUT_DATA) ) 00234 mbedtls_snprintf( buf, buflen, "MD - Bad input parameters to function" ); 00235 if( use_ret == -(MBEDTLS_ERR_MD_ALLOC_FAILED) ) 00236 mbedtls_snprintf( buf, buflen, "MD - Failed to allocate memory" ); 00237 if( use_ret == -(MBEDTLS_ERR_MD_FILE_IO_ERROR) ) 00238 mbedtls_snprintf( buf, buflen, "MD - Opening or reading of file failed" ); 00239 #endif /* MBEDTLS_MD_C */ 00240 00241 #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C) 00242 if( use_ret == -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) ) 00243 mbedtls_snprintf( buf, buflen, "PEM - No PEM header or footer found" ); 00244 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_DATA) ) 00245 mbedtls_snprintf( buf, buflen, "PEM - PEM string is not as expected" ); 00246 if( use_ret == -(MBEDTLS_ERR_PEM_ALLOC_FAILED) ) 00247 mbedtls_snprintf( buf, buflen, "PEM - Failed to allocate memory" ); 00248 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_ENC_IV) ) 00249 mbedtls_snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" ); 00250 if( use_ret == -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG) ) 00251 mbedtls_snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" ); 00252 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) ) 00253 mbedtls_snprintf( buf, buflen, "PEM - Private key password can't be empty" ); 00254 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) ) 00255 mbedtls_snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" ); 00256 if( use_ret == -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE) ) 00257 mbedtls_snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" ); 00258 if( use_ret == -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA) ) 00259 mbedtls_snprintf( buf, buflen, "PEM - Bad input parameters to function" ); 00260 #endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */ 00261 00262 #if defined(MBEDTLS_PK_C) 00263 if( use_ret == -(MBEDTLS_ERR_PK_ALLOC_FAILED) ) 00264 mbedtls_snprintf( buf, buflen, "PK - Memory allocation failed" ); 00265 if( use_ret == -(MBEDTLS_ERR_PK_TYPE_MISMATCH) ) 00266 mbedtls_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" ); 00267 if( use_ret == -(MBEDTLS_ERR_PK_BAD_INPUT_DATA) ) 00268 mbedtls_snprintf( buf, buflen, "PK - Bad input parameters to function" ); 00269 if( use_ret == -(MBEDTLS_ERR_PK_FILE_IO_ERROR) ) 00270 mbedtls_snprintf( buf, buflen, "PK - Read/write of file failed" ); 00271 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION) ) 00272 mbedtls_snprintf( buf, buflen, "PK - Unsupported key version" ); 00273 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT) ) 00274 mbedtls_snprintf( buf, buflen, "PK - Invalid key tag or value" ); 00275 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG) ) 00276 mbedtls_snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" ); 00277 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED) ) 00278 mbedtls_snprintf( buf, buflen, "PK - Private key password can't be empty" ); 00279 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH) ) 00280 mbedtls_snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" ); 00281 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_PUBKEY) ) 00282 mbedtls_snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" ); 00283 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_ALG) ) 00284 mbedtls_snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" ); 00285 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE) ) 00286 mbedtls_snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" ); 00287 if( use_ret == -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) ) 00288 mbedtls_snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" ); 00289 if( use_ret == -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH) ) 00290 mbedtls_snprintf( buf, buflen, "PK - The signature is valid but its length is less than expected" ); 00291 #endif /* MBEDTLS_PK_C */ 00292 00293 #if defined(MBEDTLS_PKCS12_C) 00294 if( use_ret == -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA) ) 00295 mbedtls_snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" ); 00296 if( use_ret == -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE) ) 00297 mbedtls_snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" ); 00298 if( use_ret == -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT) ) 00299 mbedtls_snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" ); 00300 if( use_ret == -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) ) 00301 mbedtls_snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" ); 00302 #endif /* MBEDTLS_PKCS12_C */ 00303 00304 #if defined(MBEDTLS_PKCS5_C) 00305 if( use_ret == -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA) ) 00306 mbedtls_snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" ); 00307 if( use_ret == -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT) ) 00308 mbedtls_snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" ); 00309 if( use_ret == -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE) ) 00310 mbedtls_snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" ); 00311 if( use_ret == -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) ) 00312 mbedtls_snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" ); 00313 #endif /* MBEDTLS_PKCS5_C */ 00314 00315 #if defined(MBEDTLS_RSA_C) 00316 if( use_ret == -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA) ) 00317 mbedtls_snprintf( buf, buflen, "RSA - Bad input parameters to function" ); 00318 if( use_ret == -(MBEDTLS_ERR_RSA_INVALID_PADDING) ) 00319 mbedtls_snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" ); 00320 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED) ) 00321 mbedtls_snprintf( buf, buflen, "RSA - Something failed during generation of a key" ); 00322 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED) ) 00323 mbedtls_snprintf( buf, buflen, "RSA - Key failed to pass the library's validity check" ); 00324 if( use_ret == -(MBEDTLS_ERR_RSA_PUBLIC_FAILED) ) 00325 mbedtls_snprintf( buf, buflen, "RSA - The public key operation failed" ); 00326 if( use_ret == -(MBEDTLS_ERR_RSA_PRIVATE_FAILED) ) 00327 mbedtls_snprintf( buf, buflen, "RSA - The private key operation failed" ); 00328 if( use_ret == -(MBEDTLS_ERR_RSA_VERIFY_FAILED) ) 00329 mbedtls_snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" ); 00330 if( use_ret == -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE) ) 00331 mbedtls_snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" ); 00332 if( use_ret == -(MBEDTLS_ERR_RSA_RNG_FAILED) ) 00333 mbedtls_snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" ); 00334 #endif /* MBEDTLS_RSA_C */ 00335 00336 #if defined(MBEDTLS_SSL_TLS_C) 00337 if( use_ret == -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE) ) 00338 mbedtls_snprintf( buf, buflen, "SSL - The requested feature is not available" ); 00339 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA) ) 00340 mbedtls_snprintf( buf, buflen, "SSL - Bad input parameters to function" ); 00341 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_MAC) ) 00342 mbedtls_snprintf( buf, buflen, "SSL - Verification of the message MAC failed" ); 00343 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_RECORD) ) 00344 mbedtls_snprintf( buf, buflen, "SSL - An invalid SSL record was received" ); 00345 if( use_ret == -(MBEDTLS_ERR_SSL_CONN_EOF) ) 00346 mbedtls_snprintf( buf, buflen, "SSL - The connection indicated an EOF" ); 00347 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER) ) 00348 mbedtls_snprintf( buf, buflen, "SSL - An unknown cipher was received" ); 00349 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN) ) 00350 mbedtls_snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" ); 00351 if( use_ret == -(MBEDTLS_ERR_SSL_NO_RNG) ) 00352 mbedtls_snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" ); 00353 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE) ) 00354 mbedtls_snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" ); 00355 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE) ) 00356 mbedtls_snprintf( buf, buflen, "SSL - Our own certificate(s) is/are too large to send in an SSL message" ); 00357 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED) ) 00358 mbedtls_snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" ); 00359 if( use_ret == -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED) ) 00360 mbedtls_snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" ); 00361 if( use_ret == -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED) ) 00362 mbedtls_snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" ); 00363 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE) ) 00364 mbedtls_snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" ); 00365 if( use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE) ) 00366 { 00367 mbedtls_snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" ); 00368 return; 00369 } 00370 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED) ) 00371 mbedtls_snprintf( buf, buflen, "SSL - Verification of our peer failed" ); 00372 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) ) 00373 mbedtls_snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" ); 00374 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO) ) 00375 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" ); 00376 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO) ) 00377 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" ); 00378 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE) ) 00379 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" ); 00380 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) ) 00381 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" ); 00382 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) ) 00383 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" ); 00384 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) ) 00385 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" ); 00386 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) ) 00387 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" ); 00388 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) ) 00389 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" ); 00390 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) ) 00391 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" ); 00392 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) ) 00393 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" ); 00394 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) ) 00395 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" ); 00396 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED) ) 00397 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" ); 00398 if( use_ret == -(MBEDTLS_ERR_SSL_ALLOC_FAILED) ) 00399 mbedtls_snprintf( buf, buflen, "SSL - Memory allocation failed" ); 00400 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED) ) 00401 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" ); 00402 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH) ) 00403 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" ); 00404 if( use_ret == -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED) ) 00405 mbedtls_snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" ); 00406 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION) ) 00407 mbedtls_snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" ); 00408 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) ) 00409 mbedtls_snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" ); 00410 if( use_ret == -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED) ) 00411 mbedtls_snprintf( buf, buflen, "SSL - Session ticket has expired" ); 00412 if( use_ret == -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH) ) 00413 mbedtls_snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" ); 00414 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY) ) 00415 mbedtls_snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" ); 00416 if( use_ret == -(MBEDTLS_ERR_SSL_INTERNAL_ERROR) ) 00417 mbedtls_snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" ); 00418 if( use_ret == -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING) ) 00419 mbedtls_snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" ); 00420 if( use_ret == -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO) ) 00421 mbedtls_snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" ); 00422 if( use_ret == -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED) ) 00423 mbedtls_snprintf( buf, buflen, "SSL - DTLS client must retry for hello verification" ); 00424 if( use_ret == -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL) ) 00425 mbedtls_snprintf( buf, buflen, "SSL - A buffer is too small to receive or write a message" ); 00426 if( use_ret == -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE) ) 00427 mbedtls_snprintf( buf, buflen, "SSL - None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages)" ); 00428 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_READ) ) 00429 mbedtls_snprintf( buf, buflen, "SSL - Connection requires a read call" ); 00430 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_WRITE) ) 00431 mbedtls_snprintf( buf, buflen, "SSL - Connection requires a write call" ); 00432 if( use_ret == -(MBEDTLS_ERR_SSL_TIMEOUT) ) 00433 mbedtls_snprintf( buf, buflen, "SSL - The operation timed out" ); 00434 if( use_ret == -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT) ) 00435 mbedtls_snprintf( buf, buflen, "SSL - The client initiated a reconnect from the same port" ); 00436 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD) ) 00437 mbedtls_snprintf( buf, buflen, "SSL - Record header looks valid but is not expected" ); 00438 if( use_ret == -(MBEDTLS_ERR_SSL_NON_FATAL) ) 00439 mbedtls_snprintf( buf, buflen, "SSL - The alert message received indicates a non-fatal error" ); 00440 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH) ) 00441 mbedtls_snprintf( buf, buflen, "SSL - Couldn't set the hash for verifying CertificateVerify" ); 00442 #endif /* MBEDTLS_SSL_TLS_C */ 00443 00444 #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C) 00445 if( use_ret == -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) ) 00446 mbedtls_snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" ); 00447 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_OID) ) 00448 mbedtls_snprintf( buf, buflen, "X509 - Requested OID is unknown" ); 00449 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_FORMAT) ) 00450 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" ); 00451 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_VERSION) ) 00452 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" ); 00453 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SERIAL) ) 00454 mbedtls_snprintf( buf, buflen, "X509 - The serial tag or value is invalid" ); 00455 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_ALG) ) 00456 mbedtls_snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" ); 00457 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_NAME) ) 00458 mbedtls_snprintf( buf, buflen, "X509 - The name tag or value is invalid" ); 00459 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_DATE) ) 00460 mbedtls_snprintf( buf, buflen, "X509 - The date tag or value is invalid" ); 00461 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SIGNATURE) ) 00462 mbedtls_snprintf( buf, buflen, "X509 - The signature tag or value invalid" ); 00463 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS) ) 00464 mbedtls_snprintf( buf, buflen, "X509 - The extension tag or value is invalid" ); 00465 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_VERSION) ) 00466 mbedtls_snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" ); 00467 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG) ) 00468 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" ); 00469 if( use_ret == -(MBEDTLS_ERR_X509_SIG_MISMATCH) ) 00470 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" ); 00471 if( use_ret == -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) ) 00472 mbedtls_snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" ); 00473 if( use_ret == -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT) ) 00474 mbedtls_snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" ); 00475 if( use_ret == -(MBEDTLS_ERR_X509_BAD_INPUT_DATA) ) 00476 mbedtls_snprintf( buf, buflen, "X509 - Input invalid" ); 00477 if( use_ret == -(MBEDTLS_ERR_X509_ALLOC_FAILED) ) 00478 mbedtls_snprintf( buf, buflen, "X509 - Allocation of memory failed" ); 00479 if( use_ret == -(MBEDTLS_ERR_X509_FILE_IO_ERROR) ) 00480 mbedtls_snprintf( buf, buflen, "X509 - Read/write of file failed" ); 00481 if( use_ret == -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL) ) 00482 mbedtls_snprintf( buf, buflen, "X509 - Destination buffer is too small" ); 00483 #endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */ 00484 // END generated code 00485 00486 if( strlen( buf ) == 0 ) 00487 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret ); 00488 } 00489 00490 use_ret = ret & ~0xFF80; 00491 00492 if( use_ret == 0 ) 00493 return; 00494 00495 // If high level code is present, make a concatenation between both 00496 // error strings. 00497 // 00498 len = strlen( buf ); 00499 00500 if( len > 0 ) 00501 { 00502 if( buflen - len < 5 ) 00503 return; 00504 00505 mbedtls_snprintf( buf + len, buflen - len, " : " ); 00506 00507 buf += len + 3; 00508 buflen -= len + 3; 00509 } 00510 00511 // Low level error codes 00512 // 00513 // BEGIN generated code 00514 #if defined(MBEDTLS_AES_C) 00515 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH) ) 00516 mbedtls_snprintf( buf, buflen, "AES - Invalid key length" ); 00517 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH) ) 00518 mbedtls_snprintf( buf, buflen, "AES - Invalid data input length" ); 00519 #endif /* MBEDTLS_AES_C */ 00520 00521 #if defined(MBEDTLS_ASN1_PARSE_C) 00522 if( use_ret == -(MBEDTLS_ERR_ASN1_OUT_OF_DATA) ) 00523 mbedtls_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" ); 00524 if( use_ret == -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) ) 00525 mbedtls_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" ); 00526 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_LENGTH) ) 00527 mbedtls_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" ); 00528 if( use_ret == -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH) ) 00529 mbedtls_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" ); 00530 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_DATA) ) 00531 mbedtls_snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" ); 00532 if( use_ret == -(MBEDTLS_ERR_ASN1_ALLOC_FAILED) ) 00533 mbedtls_snprintf( buf, buflen, "ASN1 - Memory allocation failed" ); 00534 if( use_ret == -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL) ) 00535 mbedtls_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" ); 00536 #endif /* MBEDTLS_ASN1_PARSE_C */ 00537 00538 #if defined(MBEDTLS_BASE64_C) 00539 if( use_ret == -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) ) 00540 mbedtls_snprintf( buf, buflen, "BASE64 - Output buffer too small" ); 00541 if( use_ret == -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER) ) 00542 mbedtls_snprintf( buf, buflen, "BASE64 - Invalid character in input" ); 00543 #endif /* MBEDTLS_BASE64_C */ 00544 00545 #if defined(MBEDTLS_BIGNUM_C) 00546 if( use_ret == -(MBEDTLS_ERR_MPI_FILE_IO_ERROR) ) 00547 mbedtls_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" ); 00548 if( use_ret == -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA) ) 00549 mbedtls_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" ); 00550 if( use_ret == -(MBEDTLS_ERR_MPI_INVALID_CHARACTER) ) 00551 mbedtls_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" ); 00552 if( use_ret == -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL) ) 00553 mbedtls_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" ); 00554 if( use_ret == -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE) ) 00555 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" ); 00556 if( use_ret == -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO) ) 00557 mbedtls_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" ); 00558 if( use_ret == -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) ) 00559 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" ); 00560 if( use_ret == -(MBEDTLS_ERR_MPI_ALLOC_FAILED) ) 00561 mbedtls_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" ); 00562 #endif /* MBEDTLS_BIGNUM_C */ 00563 00564 #if defined(MBEDTLS_BLOWFISH_C) 00565 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH) ) 00566 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid key length" ); 00567 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH) ) 00568 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" ); 00569 #endif /* MBEDTLS_BLOWFISH_C */ 00570 00571 #if defined(MBEDTLS_CAMELLIA_C) 00572 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH) ) 00573 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid key length" ); 00574 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH) ) 00575 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" ); 00576 #endif /* MBEDTLS_CAMELLIA_C */ 00577 00578 #if defined(MBEDTLS_CCM_C) 00579 if( use_ret == -(MBEDTLS_ERR_CCM_BAD_INPUT) ) 00580 mbedtls_snprintf( buf, buflen, "CCM - Bad input parameters to function" ); 00581 if( use_ret == -(MBEDTLS_ERR_CCM_AUTH_FAILED) ) 00582 mbedtls_snprintf( buf, buflen, "CCM - Authenticated decryption failed" ); 00583 #endif /* MBEDTLS_CCM_C */ 00584 00585 #if defined(MBEDTLS_CTR_DRBG_C) 00586 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) ) 00587 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" ); 00588 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG) ) 00589 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" ); 00590 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG) ) 00591 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" ); 00592 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR) ) 00593 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" ); 00594 #endif /* MBEDTLS_CTR_DRBG_C */ 00595 00596 #if defined(MBEDTLS_DES_C) 00597 if( use_ret == -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH) ) 00598 mbedtls_snprintf( buf, buflen, "DES - The data input has an invalid length" ); 00599 #endif /* MBEDTLS_DES_C */ 00600 00601 #if defined(MBEDTLS_ENTROPY_C) 00602 if( use_ret == -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED) ) 00603 mbedtls_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" ); 00604 if( use_ret == -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES) ) 00605 mbedtls_snprintf( buf, buflen, "ENTROPY - No more sources can be added" ); 00606 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED) ) 00607 mbedtls_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" ); 00608 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE) ) 00609 mbedtls_snprintf( buf, buflen, "ENTROPY - No strong sources have been added to poll" ); 00610 if( use_ret == -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR) ) 00611 mbedtls_snprintf( buf, buflen, "ENTROPY - Read/write error in file" ); 00612 #endif /* MBEDTLS_ENTROPY_C */ 00613 00614 #if defined(MBEDTLS_GCM_C) 00615 if( use_ret == -(MBEDTLS_ERR_GCM_AUTH_FAILED) ) 00616 mbedtls_snprintf( buf, buflen, "GCM - Authenticated decryption failed" ); 00617 if( use_ret == -(MBEDTLS_ERR_GCM_BAD_INPUT) ) 00618 mbedtls_snprintf( buf, buflen, "GCM - Bad input parameters to function" ); 00619 #endif /* MBEDTLS_GCM_C */ 00620 00621 #if defined(MBEDTLS_HMAC_DRBG_C) 00622 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG) ) 00623 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" ); 00624 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG) ) 00625 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" ); 00626 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR) ) 00627 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" ); 00628 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) ) 00629 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" ); 00630 #endif /* MBEDTLS_HMAC_DRBG_C */ 00631 00632 #if defined(MBEDTLS_NET_C) 00633 if( use_ret == -(MBEDTLS_ERR_NET_SOCKET_FAILED) ) 00634 mbedtls_snprintf( buf, buflen, "NET - Failed to open a socket" ); 00635 if( use_ret == -(MBEDTLS_ERR_NET_CONNECT_FAILED) ) 00636 mbedtls_snprintf( buf, buflen, "NET - The connection to the given server / port failed" ); 00637 if( use_ret == -(MBEDTLS_ERR_NET_BIND_FAILED) ) 00638 mbedtls_snprintf( buf, buflen, "NET - Binding of the socket failed" ); 00639 if( use_ret == -(MBEDTLS_ERR_NET_LISTEN_FAILED) ) 00640 mbedtls_snprintf( buf, buflen, "NET - Could not listen on the socket" ); 00641 if( use_ret == -(MBEDTLS_ERR_NET_ACCEPT_FAILED) ) 00642 mbedtls_snprintf( buf, buflen, "NET - Could not accept the incoming connection" ); 00643 if( use_ret == -(MBEDTLS_ERR_NET_RECV_FAILED) ) 00644 mbedtls_snprintf( buf, buflen, "NET - Reading information from the socket failed" ); 00645 if( use_ret == -(MBEDTLS_ERR_NET_SEND_FAILED) ) 00646 mbedtls_snprintf( buf, buflen, "NET - Sending information through the socket failed" ); 00647 if( use_ret == -(MBEDTLS_ERR_NET_CONN_RESET) ) 00648 mbedtls_snprintf( buf, buflen, "NET - Connection was reset by peer" ); 00649 if( use_ret == -(MBEDTLS_ERR_NET_UNKNOWN_HOST) ) 00650 mbedtls_snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" ); 00651 if( use_ret == -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL) ) 00652 mbedtls_snprintf( buf, buflen, "NET - Buffer is too small to hold the data" ); 00653 if( use_ret == -(MBEDTLS_ERR_NET_INVALID_CONTEXT) ) 00654 mbedtls_snprintf( buf, buflen, "NET - The context is invalid, eg because it was free()ed" ); 00655 #endif /* MBEDTLS_NET_C */ 00656 00657 #if defined(MBEDTLS_OID_C) 00658 if( use_ret == -(MBEDTLS_ERR_OID_NOT_FOUND) ) 00659 mbedtls_snprintf( buf, buflen, "OID - OID is not found" ); 00660 if( use_ret == -(MBEDTLS_ERR_OID_BUF_TOO_SMALL) ) 00661 mbedtls_snprintf( buf, buflen, "OID - output buffer is too small" ); 00662 #endif /* MBEDTLS_OID_C */ 00663 00664 #if defined(MBEDTLS_PADLOCK_C) 00665 if( use_ret == -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED) ) 00666 mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" ); 00667 #endif /* MBEDTLS_PADLOCK_C */ 00668 00669 #if defined(MBEDTLS_THREADING_C) 00670 if( use_ret == -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE) ) 00671 mbedtls_snprintf( buf, buflen, "THREADING - The selected feature is not available" ); 00672 if( use_ret == -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA) ) 00673 mbedtls_snprintf( buf, buflen, "THREADING - Bad input parameters to function" ); 00674 if( use_ret == -(MBEDTLS_ERR_THREADING_MUTEX_ERROR) ) 00675 mbedtls_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" ); 00676 #endif /* MBEDTLS_THREADING_C */ 00677 00678 #if defined(MBEDTLS_XTEA_C) 00679 if( use_ret == -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH) ) 00680 mbedtls_snprintf( buf, buflen, "XTEA - The data input has an invalid length" ); 00681 #endif /* MBEDTLS_XTEA_C */ 00682 // END generated code 00683 00684 if( strlen( buf ) != 0 ) 00685 return; 00686 00687 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret ); 00688 } 00689 00690 #else /* MBEDTLS_ERROR_C */ 00691 00692 #if defined(MBEDTLS_ERROR_STRERROR_DUMMY) 00693 00694 /* 00695 * Provide an non-function in case MBEDTLS_ERROR_C is not defined 00696 */ 00697 void mbedtls_strerror( int ret, char *buf, size_t buflen ) 00698 { 00699 ((void) ret); 00700 00701 if( buflen > 0 ) 00702 buf[0] = '\0'; 00703 } 00704 00705 #endif /* MBEDTLS_ERROR_STRERROR_DUMMY */ 00706 00707 #endif /* MBEDTLS_ERROR_C */
Generated on Tue Jul 12 2022 11:02:37 by
