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