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