Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers error.c Source File

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