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