Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

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