xref: /reactos/dll/3rdparty/mbedtls/error.c (revision ede7a20a)
1 /*
2  *  Error message information
3  *
4  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
5  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
6  *
7  *  This file is provided under the Apache License 2.0, or the
8  *  GNU General Public License v2.0 or later.
9  *
10  *  **********
11  *  Apache License 2.0:
12  *
13  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
14  *  not use this file except in compliance with the License.
15  *  You may obtain a copy of the License at
16  *
17  *  http://www.apache.org/licenses/LICENSE-2.0
18  *
19  *  Unless required by applicable law or agreed to in writing, software
20  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
21  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22  *  See the License for the specific language governing permissions and
23  *  limitations under the License.
24  *
25  *  **********
26  *
27  *  **********
28  *  GNU General Public License v2.0 or later:
29  *
30  *  This program is free software; you can redistribute it and/or modify
31  *  it under the terms of the GNU General Public License as published by
32  *  the Free Software Foundation; either version 2 of the License, or
33  *  (at your option) any later version.
34  *
35  *  This program is distributed in the hope that it will be useful,
36  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
37  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
38  *  GNU General Public License for more details.
39  *
40  *  You should have received a copy of the GNU General Public License along
41  *  with this program; if not, write to the Free Software Foundation, Inc.,
42  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
43  *
44  *  **********
45  *
46  *  This file is part of mbed TLS (https://tls.mbed.org)
47  */
48 
49 #if !defined(MBEDTLS_CONFIG_FILE)
50 #include "mbedtls/config.h"
51 #else
52 #include MBEDTLS_CONFIG_FILE
53 #endif
54 
55 #if defined(MBEDTLS_ERROR_C) || defined(MBEDTLS_ERROR_STRERROR_DUMMY)
56 #include "mbedtls/error.h"
57 #include <string.h>
58 #endif
59 
60 #if defined(MBEDTLS_PLATFORM_C)
61 #include "mbedtls/platform.h"
62 #else
63 #define mbedtls_snprintf snprintf
64 #define mbedtls_time_t   time_t
65 #endif
66 
67 #if defined(MBEDTLS_ERROR_C)
68 
69 #include <stdio.h>
70 
71 #if defined(MBEDTLS_AES_C)
72 #include "mbedtls/aes.h"
73 #endif
74 
75 #if defined(MBEDTLS_ARC4_C)
76 #include "mbedtls/arc4.h"
77 #endif
78 
79 #if defined(MBEDTLS_ASN1_PARSE_C)
80 #include "mbedtls/asn1.h"
81 #endif
82 
83 #if defined(MBEDTLS_BASE64_C)
84 #include "mbedtls/base64.h"
85 #endif
86 
87 #if defined(MBEDTLS_BIGNUM_C)
88 #include "mbedtls/bignum.h"
89 #endif
90 
91 #if defined(MBEDTLS_BLOWFISH_C)
92 #include "mbedtls/blowfish.h"
93 #endif
94 
95 #if defined(MBEDTLS_CAMELLIA_C)
96 #include "mbedtls/camellia.h"
97 #endif
98 
99 #if defined(MBEDTLS_CCM_C)
100 #include "mbedtls/ccm.h"
101 #endif
102 
103 #if defined(MBEDTLS_CIPHER_C)
104 #include "mbedtls/cipher.h"
105 #endif
106 
107 #if defined(MBEDTLS_CMAC_C)
108 #include "mbedtls/cmac.h"
109 #endif
110 
111 #if defined(MBEDTLS_CTR_DRBG_C)
112 #include "mbedtls/ctr_drbg.h"
113 #endif
114 
115 #if defined(MBEDTLS_DES_C)
116 #include "mbedtls/des.h"
117 #endif
118 
119 #if defined(MBEDTLS_DHM_C)
120 #include "mbedtls/dhm.h"
121 #endif
122 
123 #if defined(MBEDTLS_ECP_C)
124 #include "mbedtls/ecp.h"
125 #endif
126 
127 #if defined(MBEDTLS_ENTROPY_C)
128 #include "mbedtls/entropy.h"
129 #endif
130 
131 #if defined(MBEDTLS_GCM_C)
132 #include "mbedtls/gcm.h"
133 #endif
134 
135 #if defined(MBEDTLS_HMAC_DRBG_C)
136 #include "mbedtls/hmac_drbg.h"
137 #endif
138 
139 #if defined(MBEDTLS_MD_C)
140 #include "mbedtls/md.h"
141 #endif
142 
143 #if defined(MBEDTLS_MD2_C)
144 #include "mbedtls/md2.h"
145 #endif
146 
147 #if defined(MBEDTLS_MD4_C)
148 #include "mbedtls/md4.h"
149 #endif
150 
151 #if defined(MBEDTLS_MD5_C)
152 #include "mbedtls/md5.h"
153 #endif
154 
155 #if defined(MBEDTLS_NET_C)
156 #include "mbedtls/net_sockets.h"
157 #endif
158 
159 #if defined(MBEDTLS_OID_C)
160 #include "mbedtls/oid.h"
161 #endif
162 
163 #if defined(MBEDTLS_PADLOCK_C)
164 #include "mbedtls/padlock.h"
165 #endif
166 
167 #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
168 #include "mbedtls/pem.h"
169 #endif
170 
171 #if defined(MBEDTLS_PK_C)
172 #include "mbedtls/pk.h"
173 #endif
174 
175 #if defined(MBEDTLS_PKCS12_C)
176 #include "mbedtls/pkcs12.h"
177 #endif
178 
179 #if defined(MBEDTLS_PKCS5_C)
180 #include "mbedtls/pkcs5.h"
181 #endif
182 
183 #if defined(MBEDTLS_RIPEMD160_C)
184 #include "mbedtls/ripemd160.h"
185 #endif
186 
187 #if defined(MBEDTLS_RSA_C)
188 #include "mbedtls/rsa.h"
189 #endif
190 
191 #if defined(MBEDTLS_SHA1_C)
192 #include "mbedtls/sha1.h"
193 #endif
194 
195 #if defined(MBEDTLS_SHA256_C)
196 #include "mbedtls/sha256.h"
197 #endif
198 
199 #if defined(MBEDTLS_SHA512_C)
200 #include "mbedtls/sha512.h"
201 #endif
202 
203 #if defined(MBEDTLS_SSL_TLS_C)
204 #include "mbedtls/ssl.h"
205 #endif
206 
207 #if defined(MBEDTLS_THREADING_C)
208 #include "mbedtls/threading.h"
209 #endif
210 
211 #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
212 #include "mbedtls/x509.h"
213 #endif
214 
215 #if defined(MBEDTLS_XTEA_C)
216 #include "mbedtls/xtea.h"
217 #endif
218 
219 
220 void mbedtls_strerror( int ret, char *buf, size_t buflen )
221 {
222     size_t len;
223     int use_ret;
224 
225     if( buflen == 0 )
226         return;
227 
228     memset( buf, 0x00, buflen );
229 
230     if( ret < 0 )
231         ret = -ret;
232 
233     if( ret & 0xFF80 )
234     {
235         use_ret = ret & 0xFF80;
236 
237         // High level error codes
238         //
239         // BEGIN generated code
240 #if defined(MBEDTLS_CIPHER_C)
241         if( use_ret == -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE) )
242             mbedtls_snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
243         if( use_ret == -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA) )
244             mbedtls_snprintf( buf, buflen, "CIPHER - Bad input parameters" );
245         if( use_ret == -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED) )
246             mbedtls_snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
247         if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_PADDING) )
248             mbedtls_snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
249         if( use_ret == -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
250             mbedtls_snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
251         if( use_ret == -(MBEDTLS_ERR_CIPHER_AUTH_FAILED) )
252             mbedtls_snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
253         if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT) )
254             mbedtls_snprintf( buf, buflen, "CIPHER - The context is invalid. For example, because it was freed" );
255         if( use_ret == -(MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED) )
256             mbedtls_snprintf( buf, buflen, "CIPHER - Cipher hardware accelerator failed" );
257 #endif /* MBEDTLS_CIPHER_C */
258 
259 #if defined(MBEDTLS_DHM_C)
260         if( use_ret == -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA) )
261             mbedtls_snprintf( buf, buflen, "DHM - Bad input parameters" );
262         if( use_ret == -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED) )
263             mbedtls_snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
264         if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED) )
265             mbedtls_snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
266         if( use_ret == -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED) )
267             mbedtls_snprintf( buf, buflen, "DHM - Reading of the public values failed" );
268         if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED) )
269             mbedtls_snprintf( buf, buflen, "DHM - Making of the public value failed" );
270         if( use_ret == -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED) )
271             mbedtls_snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
272         if( use_ret == -(MBEDTLS_ERR_DHM_INVALID_FORMAT) )
273             mbedtls_snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
274         if( use_ret == -(MBEDTLS_ERR_DHM_ALLOC_FAILED) )
275             mbedtls_snprintf( buf, buflen, "DHM - Allocation of memory failed" );
276         if( use_ret == -(MBEDTLS_ERR_DHM_FILE_IO_ERROR) )
277             mbedtls_snprintf( buf, buflen, "DHM - Read or write of file failed" );
278         if( use_ret == -(MBEDTLS_ERR_DHM_HW_ACCEL_FAILED) )
279             mbedtls_snprintf( buf, buflen, "DHM - DHM hardware accelerator failed" );
280         if( use_ret == -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED) )
281             mbedtls_snprintf( buf, buflen, "DHM - Setting the modulus and generator failed" );
282 #endif /* MBEDTLS_DHM_C */
283 
284 #if defined(MBEDTLS_ECP_C)
285         if( use_ret == -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA) )
286             mbedtls_snprintf( buf, buflen, "ECP - Bad input parameters to function" );
287         if( use_ret == -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL) )
288             mbedtls_snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
289         if( use_ret == -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) )
290             mbedtls_snprintf( buf, buflen, "ECP - Requested curve not available" );
291         if( use_ret == -(MBEDTLS_ERR_ECP_VERIFY_FAILED) )
292             mbedtls_snprintf( buf, buflen, "ECP - The signature is not valid" );
293         if( use_ret == -(MBEDTLS_ERR_ECP_ALLOC_FAILED) )
294             mbedtls_snprintf( buf, buflen, "ECP - Memory allocation failed" );
295         if( use_ret == -(MBEDTLS_ERR_ECP_RANDOM_FAILED) )
296             mbedtls_snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
297         if( use_ret == -(MBEDTLS_ERR_ECP_INVALID_KEY) )
298             mbedtls_snprintf( buf, buflen, "ECP - Invalid private or public key" );
299         if( use_ret == -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) )
300             mbedtls_snprintf( buf, buflen, "ECP - The buffer contains a valid signature followed by more data" );
301         if( use_ret == -(MBEDTLS_ERR_ECP_HW_ACCEL_FAILED) )
302             mbedtls_snprintf( buf, buflen, "ECP - ECP hardware accelerator failed" );
303 #endif /* MBEDTLS_ECP_C */
304 
305 #if defined(MBEDTLS_MD_C)
306         if( use_ret == -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE) )
307             mbedtls_snprintf( buf, buflen, "MD - The selected feature is not available" );
308         if( use_ret == -(MBEDTLS_ERR_MD_BAD_INPUT_DATA) )
309             mbedtls_snprintf( buf, buflen, "MD - Bad input parameters to function" );
310         if( use_ret == -(MBEDTLS_ERR_MD_ALLOC_FAILED) )
311             mbedtls_snprintf( buf, buflen, "MD - Failed to allocate memory" );
312         if( use_ret == -(MBEDTLS_ERR_MD_FILE_IO_ERROR) )
313             mbedtls_snprintf( buf, buflen, "MD - Opening or reading of file failed" );
314         if( use_ret == -(MBEDTLS_ERR_MD_HW_ACCEL_FAILED) )
315             mbedtls_snprintf( buf, buflen, "MD - MD hardware accelerator failed" );
316 #endif /* MBEDTLS_MD_C */
317 
318 #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
319         if( use_ret == -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
320             mbedtls_snprintf( buf, buflen, "PEM - No PEM header or footer found" );
321         if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_DATA) )
322             mbedtls_snprintf( buf, buflen, "PEM - PEM string is not as expected" );
323         if( use_ret == -(MBEDTLS_ERR_PEM_ALLOC_FAILED) )
324             mbedtls_snprintf( buf, buflen, "PEM - Failed to allocate memory" );
325         if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_ENC_IV) )
326             mbedtls_snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
327         if( use_ret == -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG) )
328             mbedtls_snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
329         if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) )
330             mbedtls_snprintf( buf, buflen, "PEM - Private key password can't be empty" );
331         if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) )
332             mbedtls_snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
333         if( use_ret == -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE) )
334             mbedtls_snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
335         if( use_ret == -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA) )
336             mbedtls_snprintf( buf, buflen, "PEM - Bad input parameters to function" );
337 #endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
338 
339 #if defined(MBEDTLS_PK_C)
340         if( use_ret == -(MBEDTLS_ERR_PK_ALLOC_FAILED) )
341             mbedtls_snprintf( buf, buflen, "PK - Memory allocation failed" );
342         if( use_ret == -(MBEDTLS_ERR_PK_TYPE_MISMATCH) )
343             mbedtls_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
344         if( use_ret == -(MBEDTLS_ERR_PK_BAD_INPUT_DATA) )
345             mbedtls_snprintf( buf, buflen, "PK - Bad input parameters to function" );
346         if( use_ret == -(MBEDTLS_ERR_PK_FILE_IO_ERROR) )
347             mbedtls_snprintf( buf, buflen, "PK - Read/write of file failed" );
348         if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION) )
349             mbedtls_snprintf( buf, buflen, "PK - Unsupported key version" );
350         if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT) )
351             mbedtls_snprintf( buf, buflen, "PK - Invalid key tag or value" );
352         if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG) )
353             mbedtls_snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
354         if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED) )
355             mbedtls_snprintf( buf, buflen, "PK - Private key password can't be empty" );
356         if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH) )
357             mbedtls_snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
358         if( use_ret == -(MBEDTLS_ERR_PK_INVALID_PUBKEY) )
359             mbedtls_snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
360         if( use_ret == -(MBEDTLS_ERR_PK_INVALID_ALG) )
361             mbedtls_snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
362         if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE) )
363             mbedtls_snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
364         if( use_ret == -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) )
365             mbedtls_snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
366         if( use_ret == -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH) )
367             mbedtls_snprintf( buf, buflen, "PK - The buffer contains a valid signature followed by more data" );
368         if( use_ret == -(MBEDTLS_ERR_PK_HW_ACCEL_FAILED) )
369             mbedtls_snprintf( buf, buflen, "PK - PK hardware accelerator failed" );
370 #endif /* MBEDTLS_PK_C */
371 
372 #if defined(MBEDTLS_PKCS12_C)
373         if( use_ret == -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA) )
374             mbedtls_snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
375         if( use_ret == -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE) )
376             mbedtls_snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
377         if( use_ret == -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT) )
378             mbedtls_snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
379         if( use_ret == -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) )
380             mbedtls_snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
381 #endif /* MBEDTLS_PKCS12_C */
382 
383 #if defined(MBEDTLS_PKCS5_C)
384         if( use_ret == -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA) )
385             mbedtls_snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
386         if( use_ret == -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT) )
387             mbedtls_snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
388         if( use_ret == -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE) )
389             mbedtls_snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
390         if( use_ret == -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) )
391             mbedtls_snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
392 #endif /* MBEDTLS_PKCS5_C */
393 
394 #if defined(MBEDTLS_RSA_C)
395         if( use_ret == -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA) )
396             mbedtls_snprintf( buf, buflen, "RSA - Bad input parameters to function" );
397         if( use_ret == -(MBEDTLS_ERR_RSA_INVALID_PADDING) )
398             mbedtls_snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
399         if( use_ret == -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED) )
400             mbedtls_snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
401         if( use_ret == -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED) )
402             mbedtls_snprintf( buf, buflen, "RSA - Key failed to pass the validity check of the library" );
403         if( use_ret == -(MBEDTLS_ERR_RSA_PUBLIC_FAILED) )
404             mbedtls_snprintf( buf, buflen, "RSA - The public key operation failed" );
405         if( use_ret == -(MBEDTLS_ERR_RSA_PRIVATE_FAILED) )
406             mbedtls_snprintf( buf, buflen, "RSA - The private key operation failed" );
407         if( use_ret == -(MBEDTLS_ERR_RSA_VERIFY_FAILED) )
408             mbedtls_snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
409         if( use_ret == -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE) )
410             mbedtls_snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
411         if( use_ret == -(MBEDTLS_ERR_RSA_RNG_FAILED) )
412             mbedtls_snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
413         if( use_ret == -(MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION) )
414             mbedtls_snprintf( buf, buflen, "RSA - The implementation does not offer the requested operation, for example, because of security violations or lack of functionality" );
415         if( use_ret == -(MBEDTLS_ERR_RSA_HW_ACCEL_FAILED) )
416             mbedtls_snprintf( buf, buflen, "RSA - RSA hardware accelerator failed" );
417 #endif /* MBEDTLS_RSA_C */
418 
419 #if defined(MBEDTLS_SSL_TLS_C)
420         if( use_ret == -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE) )
421             mbedtls_snprintf( buf, buflen, "SSL - The requested feature is not available" );
422         if( use_ret == -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA) )
423             mbedtls_snprintf( buf, buflen, "SSL - Bad input parameters to function" );
424         if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_MAC) )
425             mbedtls_snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
426         if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_RECORD) )
427             mbedtls_snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
428         if( use_ret == -(MBEDTLS_ERR_SSL_CONN_EOF) )
429             mbedtls_snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
430         if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER) )
431             mbedtls_snprintf( buf, buflen, "SSL - An unknown cipher was received" );
432         if( use_ret == -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN) )
433             mbedtls_snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
434         if( use_ret == -(MBEDTLS_ERR_SSL_NO_RNG) )
435             mbedtls_snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
436         if( use_ret == -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE) )
437             mbedtls_snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
438         if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE) )
439             mbedtls_snprintf( buf, buflen, "SSL - Our own certificate(s) is/are too large to send in an SSL message" );
440         if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED) )
441             mbedtls_snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
442         if( use_ret == -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED) )
443             mbedtls_snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
444         if( use_ret == -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED) )
445             mbedtls_snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
446         if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE) )
447             mbedtls_snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
448         if( use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE) )
449         {
450             mbedtls_snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
451             return;
452         }
453         if( use_ret == -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED) )
454             mbedtls_snprintf( buf, buflen, "SSL - Verification of our peer failed" );
455         if( use_ret == -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) )
456             mbedtls_snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
457         if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO) )
458             mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
459         if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO) )
460             mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
461         if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE) )
462             mbedtls_snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
463         if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
464             mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
465         if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
466             mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
467         if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
468             mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
469         if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
470             mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
471         if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
472             mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
473         if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
474             mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
475         if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
476             mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
477         if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
478             mbedtls_snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
479         if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED) )
480             mbedtls_snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
481         if( use_ret == -(MBEDTLS_ERR_SSL_ALLOC_FAILED) )
482             mbedtls_snprintf( buf, buflen, "SSL - Memory allocation failed" );
483         if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED) )
484             mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
485         if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
486             mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
487         if( use_ret == -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED) )
488             mbedtls_snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
489         if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
490             mbedtls_snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
491         if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
492             mbedtls_snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
493         if( use_ret == -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED) )
494             mbedtls_snprintf( buf, buflen, "SSL - Session ticket has expired" );
495         if( use_ret == -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH) )
496             mbedtls_snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
497         if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY) )
498             mbedtls_snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
499         if( use_ret == -(MBEDTLS_ERR_SSL_INTERNAL_ERROR) )
500             mbedtls_snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
501         if( use_ret == -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING) )
502             mbedtls_snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
503         if( use_ret == -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO) )
504             mbedtls_snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" );
505         if( use_ret == -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED) )
506             mbedtls_snprintf( buf, buflen, "SSL - DTLS client must retry for hello verification" );
507         if( use_ret == -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL) )
508             mbedtls_snprintf( buf, buflen, "SSL - A buffer is too small to receive or write a message" );
509         if( use_ret == -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE) )
510             mbedtls_snprintf( buf, buflen, "SSL - None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages)" );
511         if( use_ret == -(MBEDTLS_ERR_SSL_WANT_READ) )
512             mbedtls_snprintf( buf, buflen, "SSL - Connection requires a read call" );
513         if( use_ret == -(MBEDTLS_ERR_SSL_WANT_WRITE) )
514             mbedtls_snprintf( buf, buflen, "SSL - Connection requires a write call" );
515         if( use_ret == -(MBEDTLS_ERR_SSL_TIMEOUT) )
516             mbedtls_snprintf( buf, buflen, "SSL - The operation timed out" );
517         if( use_ret == -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT) )
518             mbedtls_snprintf( buf, buflen, "SSL - The client initiated a reconnect from the same port" );
519         if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD) )
520             mbedtls_snprintf( buf, buflen, "SSL - Record header looks valid but is not expected" );
521         if( use_ret == -(MBEDTLS_ERR_SSL_NON_FATAL) )
522             mbedtls_snprintf( buf, buflen, "SSL - The alert message received indicates a non-fatal error" );
523         if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH) )
524             mbedtls_snprintf( buf, buflen, "SSL - Couldn't set the hash for verifying CertificateVerify" );
525         if( use_ret == -(MBEDTLS_ERR_SSL_BAD_CONFIG) )
526             mbedtls_snprintf( buf, buflen, "SSL - Invalid value in SSL config" );
527 #endif /* MBEDTLS_SSL_TLS_C */
528 
529 #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
530         if( use_ret == -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) )
531             mbedtls_snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
532         if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_OID) )
533             mbedtls_snprintf( buf, buflen, "X509 - Requested OID is unknown" );
534         if( use_ret == -(MBEDTLS_ERR_X509_INVALID_FORMAT) )
535             mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
536         if( use_ret == -(MBEDTLS_ERR_X509_INVALID_VERSION) )
537             mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
538         if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SERIAL) )
539             mbedtls_snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
540         if( use_ret == -(MBEDTLS_ERR_X509_INVALID_ALG) )
541             mbedtls_snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
542         if( use_ret == -(MBEDTLS_ERR_X509_INVALID_NAME) )
543             mbedtls_snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
544         if( use_ret == -(MBEDTLS_ERR_X509_INVALID_DATE) )
545             mbedtls_snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
546         if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SIGNATURE) )
547             mbedtls_snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
548         if( use_ret == -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS) )
549             mbedtls_snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
550         if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_VERSION) )
551             mbedtls_snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
552         if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG) )
553             mbedtls_snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
554         if( use_ret == -(MBEDTLS_ERR_X509_SIG_MISMATCH) )
555             mbedtls_snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" );
556         if( use_ret == -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) )
557             mbedtls_snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
558         if( use_ret == -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT) )
559             mbedtls_snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
560         if( use_ret == -(MBEDTLS_ERR_X509_BAD_INPUT_DATA) )
561             mbedtls_snprintf( buf, buflen, "X509 - Input invalid" );
562         if( use_ret == -(MBEDTLS_ERR_X509_ALLOC_FAILED) )
563             mbedtls_snprintf( buf, buflen, "X509 - Allocation of memory failed" );
564         if( use_ret == -(MBEDTLS_ERR_X509_FILE_IO_ERROR) )
565             mbedtls_snprintf( buf, buflen, "X509 - Read/write of file failed" );
566         if( use_ret == -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL) )
567             mbedtls_snprintf( buf, buflen, "X509 - Destination buffer is too small" );
568         if( use_ret == -(MBEDTLS_ERR_X509_FATAL_ERROR) )
569             mbedtls_snprintf( buf, buflen, "X509 - A fatal error occurred, eg the chain is too long or the vrfy callback failed" );
570 #endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
571         // END generated code
572 
573         if( strlen( buf ) == 0 )
574             mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
575     }
576 
577     use_ret = ret & ~0xFF80;
578 
579     if( use_ret == 0 )
580         return;
581 
582     // If high level code is present, make a concatenation between both
583     // error strings.
584     //
585     len = strlen( buf );
586 
587     if( len > 0 )
588     {
589         if( buflen - len < 5 )
590             return;
591 
592         mbedtls_snprintf( buf + len, buflen - len, " : " );
593 
594         buf += len + 3;
595         buflen -= len + 3;
596     }
597 
598     // Low level error codes
599     //
600     // BEGIN generated code
601 #if defined(MBEDTLS_AES_C)
602     if( use_ret == -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH) )
603         mbedtls_snprintf( buf, buflen, "AES - Invalid key length" );
604     if( use_ret == -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH) )
605         mbedtls_snprintf( buf, buflen, "AES - Invalid data input length" );
606     if( use_ret == -(MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE) )
607         mbedtls_snprintf( buf, buflen, "AES - Feature not available. For example, an unsupported AES key size" );
608     if( use_ret == -(MBEDTLS_ERR_AES_HW_ACCEL_FAILED) )
609         mbedtls_snprintf( buf, buflen, "AES - AES hardware accelerator failed" );
610 #endif /* MBEDTLS_AES_C */
611 
612 #if defined(MBEDTLS_ARC4_C)
613     if( use_ret == -(MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED) )
614         mbedtls_snprintf( buf, buflen, "ARC4 - ARC4 hardware accelerator failed" );
615 #endif /* MBEDTLS_ARC4_C */
616 
617 #if defined(MBEDTLS_ASN1_PARSE_C)
618     if( use_ret == -(MBEDTLS_ERR_ASN1_OUT_OF_DATA) )
619         mbedtls_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
620     if( use_ret == -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) )
621         mbedtls_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
622     if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_LENGTH) )
623         mbedtls_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
624     if( use_ret == -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH) )
625         mbedtls_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
626     if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_DATA) )
627         mbedtls_snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
628     if( use_ret == -(MBEDTLS_ERR_ASN1_ALLOC_FAILED) )
629         mbedtls_snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
630     if( use_ret == -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL) )
631         mbedtls_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
632 #endif /* MBEDTLS_ASN1_PARSE_C */
633 
634 #if defined(MBEDTLS_BASE64_C)
635     if( use_ret == -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) )
636         mbedtls_snprintf( buf, buflen, "BASE64 - Output buffer too small" );
637     if( use_ret == -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER) )
638         mbedtls_snprintf( buf, buflen, "BASE64 - Invalid character in input" );
639 #endif /* MBEDTLS_BASE64_C */
640 
641 #if defined(MBEDTLS_BIGNUM_C)
642     if( use_ret == -(MBEDTLS_ERR_MPI_FILE_IO_ERROR) )
643         mbedtls_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
644     if( use_ret == -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA) )
645         mbedtls_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
646     if( use_ret == -(MBEDTLS_ERR_MPI_INVALID_CHARACTER) )
647         mbedtls_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
648     if( use_ret == -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL) )
649         mbedtls_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
650     if( use_ret == -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE) )
651         mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
652     if( use_ret == -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO) )
653         mbedtls_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
654     if( use_ret == -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) )
655         mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
656     if( use_ret == -(MBEDTLS_ERR_MPI_ALLOC_FAILED) )
657         mbedtls_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
658 #endif /* MBEDTLS_BIGNUM_C */
659 
660 #if defined(MBEDTLS_BLOWFISH_C)
661     if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
662         mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
663     if( use_ret == -(MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED) )
664         mbedtls_snprintf( buf, buflen, "BLOWFISH - Blowfish hardware accelerator failed" );
665     if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
666         mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
667 #endif /* MBEDTLS_BLOWFISH_C */
668 
669 #if defined(MBEDTLS_CAMELLIA_C)
670     if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
671         mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
672     if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
673         mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
674     if( use_ret == -(MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED) )
675         mbedtls_snprintf( buf, buflen, "CAMELLIA - Camellia hardware accelerator failed" );
676 #endif /* MBEDTLS_CAMELLIA_C */
677 
678 #if defined(MBEDTLS_CCM_C)
679     if( use_ret == -(MBEDTLS_ERR_CCM_BAD_INPUT) )
680         mbedtls_snprintf( buf, buflen, "CCM - Bad input parameters to the function" );
681     if( use_ret == -(MBEDTLS_ERR_CCM_AUTH_FAILED) )
682         mbedtls_snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
683     if( use_ret == -(MBEDTLS_ERR_CCM_HW_ACCEL_FAILED) )
684         mbedtls_snprintf( buf, buflen, "CCM - CCM hardware accelerator failed" );
685 #endif /* MBEDTLS_CCM_C */
686 
687 #if defined(MBEDTLS_CMAC_C)
688     if( use_ret == -(MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED) )
689         mbedtls_snprintf( buf, buflen, "CMAC - CMAC hardware accelerator failed" );
690 #endif /* MBEDTLS_CMAC_C */
691 
692 #if defined(MBEDTLS_CTR_DRBG_C)
693     if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
694         mbedtls_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
695     if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
696         mbedtls_snprintf( buf, buflen, "CTR_DRBG - The requested random buffer length is too big" );
697     if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG) )
698         mbedtls_snprintf( buf, buflen, "CTR_DRBG - The input (entropy + additional data) is too large" );
699     if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR) )
700         mbedtls_snprintf( buf, buflen, "CTR_DRBG - Read or write error in file" );
701 #endif /* MBEDTLS_CTR_DRBG_C */
702 
703 #if defined(MBEDTLS_DES_C)
704     if( use_ret == -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH) )
705         mbedtls_snprintf( buf, buflen, "DES - The data input has an invalid length" );
706     if( use_ret == -(MBEDTLS_ERR_DES_HW_ACCEL_FAILED) )
707         mbedtls_snprintf( buf, buflen, "DES - DES hardware accelerator failed" );
708 #endif /* MBEDTLS_DES_C */
709 
710 #if defined(MBEDTLS_ENTROPY_C)
711     if( use_ret == -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED) )
712         mbedtls_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
713     if( use_ret == -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES) )
714         mbedtls_snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
715     if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED) )
716         mbedtls_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
717     if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE) )
718         mbedtls_snprintf( buf, buflen, "ENTROPY - No strong sources have been added to poll" );
719     if( use_ret == -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR) )
720         mbedtls_snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
721 #endif /* MBEDTLS_ENTROPY_C */
722 
723 #if defined(MBEDTLS_GCM_C)
724     if( use_ret == -(MBEDTLS_ERR_GCM_AUTH_FAILED) )
725         mbedtls_snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
726     if( use_ret == -(MBEDTLS_ERR_GCM_HW_ACCEL_FAILED) )
727         mbedtls_snprintf( buf, buflen, "GCM - GCM hardware accelerator failed" );
728     if( use_ret == -(MBEDTLS_ERR_GCM_BAD_INPUT) )
729         mbedtls_snprintf( buf, buflen, "GCM - Bad input parameters to function" );
730 #endif /* MBEDTLS_GCM_C */
731 
732 #if defined(MBEDTLS_HMAC_DRBG_C)
733     if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
734         mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
735     if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
736         mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
737     if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR) )
738         mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
739     if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
740         mbedtls_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
741 #endif /* MBEDTLS_HMAC_DRBG_C */
742 
743 #if defined(MBEDTLS_MD2_C)
744     if( use_ret == -(MBEDTLS_ERR_MD2_HW_ACCEL_FAILED) )
745         mbedtls_snprintf( buf, buflen, "MD2 - MD2 hardware accelerator failed" );
746 #endif /* MBEDTLS_MD2_C */
747 
748 #if defined(MBEDTLS_MD4_C)
749     if( use_ret == -(MBEDTLS_ERR_MD4_HW_ACCEL_FAILED) )
750         mbedtls_snprintf( buf, buflen, "MD4 - MD4 hardware accelerator failed" );
751 #endif /* MBEDTLS_MD4_C */
752 
753 #if defined(MBEDTLS_MD5_C)
754     if( use_ret == -(MBEDTLS_ERR_MD5_HW_ACCEL_FAILED) )
755         mbedtls_snprintf( buf, buflen, "MD5 - MD5 hardware accelerator failed" );
756 #endif /* MBEDTLS_MD5_C */
757 
758 #if defined(MBEDTLS_NET_C)
759     if( use_ret == -(MBEDTLS_ERR_NET_SOCKET_FAILED) )
760         mbedtls_snprintf( buf, buflen, "NET - Failed to open a socket" );
761     if( use_ret == -(MBEDTLS_ERR_NET_CONNECT_FAILED) )
762         mbedtls_snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
763     if( use_ret == -(MBEDTLS_ERR_NET_BIND_FAILED) )
764         mbedtls_snprintf( buf, buflen, "NET - Binding of the socket failed" );
765     if( use_ret == -(MBEDTLS_ERR_NET_LISTEN_FAILED) )
766         mbedtls_snprintf( buf, buflen, "NET - Could not listen on the socket" );
767     if( use_ret == -(MBEDTLS_ERR_NET_ACCEPT_FAILED) )
768         mbedtls_snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
769     if( use_ret == -(MBEDTLS_ERR_NET_RECV_FAILED) )
770         mbedtls_snprintf( buf, buflen, "NET - Reading information from the socket failed" );
771     if( use_ret == -(MBEDTLS_ERR_NET_SEND_FAILED) )
772         mbedtls_snprintf( buf, buflen, "NET - Sending information through the socket failed" );
773     if( use_ret == -(MBEDTLS_ERR_NET_CONN_RESET) )
774         mbedtls_snprintf( buf, buflen, "NET - Connection was reset by peer" );
775     if( use_ret == -(MBEDTLS_ERR_NET_UNKNOWN_HOST) )
776         mbedtls_snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
777     if( use_ret == -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL) )
778         mbedtls_snprintf( buf, buflen, "NET - Buffer is too small to hold the data" );
779     if( use_ret == -(MBEDTLS_ERR_NET_INVALID_CONTEXT) )
780         mbedtls_snprintf( buf, buflen, "NET - The context is invalid, eg because it was free()ed" );
781 #endif /* MBEDTLS_NET_C */
782 
783 #if defined(MBEDTLS_OID_C)
784     if( use_ret == -(MBEDTLS_ERR_OID_NOT_FOUND) )
785         mbedtls_snprintf( buf, buflen, "OID - OID is not found" );
786     if( use_ret == -(MBEDTLS_ERR_OID_BUF_TOO_SMALL) )
787         mbedtls_snprintf( buf, buflen, "OID - output buffer is too small" );
788 #endif /* MBEDTLS_OID_C */
789 
790 #if defined(MBEDTLS_PADLOCK_C)
791     if( use_ret == -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED) )
792         mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
793 #endif /* MBEDTLS_PADLOCK_C */
794 
795 #if defined(MBEDTLS_RIPEMD160_C)
796     if( use_ret == -(MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED) )
797         mbedtls_snprintf( buf, buflen, "RIPEMD160 - RIPEMD160 hardware accelerator failed" );
798 #endif /* MBEDTLS_RIPEMD160_C */
799 
800 #if defined(MBEDTLS_SHA1_C)
801     if( use_ret == -(MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED) )
802         mbedtls_snprintf( buf, buflen, "SHA1 - SHA-1 hardware accelerator failed" );
803 #endif /* MBEDTLS_SHA1_C */
804 
805 #if defined(MBEDTLS_SHA256_C)
806     if( use_ret == -(MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED) )
807         mbedtls_snprintf( buf, buflen, "SHA256 - SHA-256 hardware accelerator failed" );
808 #endif /* MBEDTLS_SHA256_C */
809 
810 #if defined(MBEDTLS_SHA512_C)
811     if( use_ret == -(MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED) )
812         mbedtls_snprintf( buf, buflen, "SHA512 - SHA-512 hardware accelerator failed" );
813 #endif /* MBEDTLS_SHA512_C */
814 
815 #if defined(MBEDTLS_THREADING_C)
816     if( use_ret == -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE) )
817         mbedtls_snprintf( buf, buflen, "THREADING - The selected feature is not available" );
818     if( use_ret == -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA) )
819         mbedtls_snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
820     if( use_ret == -(MBEDTLS_ERR_THREADING_MUTEX_ERROR) )
821         mbedtls_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
822 #endif /* MBEDTLS_THREADING_C */
823 
824 #if defined(MBEDTLS_XTEA_C)
825     if( use_ret == -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH) )
826         mbedtls_snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
827     if( use_ret == -(MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED) )
828         mbedtls_snprintf( buf, buflen, "XTEA - XTEA hardware accelerator failed" );
829 #endif /* MBEDTLS_XTEA_C */
830     // END generated code
831 
832     if( strlen( buf ) != 0 )
833         return;
834 
835     mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
836 }
837 
838 #else /* MBEDTLS_ERROR_C */
839 
840 #if defined(MBEDTLS_ERROR_STRERROR_DUMMY)
841 
842 /*
843  * Provide an non-function in case MBEDTLS_ERROR_C is not defined
844  */
845 void mbedtls_strerror( int ret, char *buf, size_t buflen )
846 {
847     ((void) ret);
848 
849     if( buflen > 0 )
850         buf[0] = '\0';
851 }
852 
853 #endif /* MBEDTLS_ERROR_STRERROR_DUMMY */
854 
855 #endif /* MBEDTLS_ERROR_C */
856