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