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