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