2 * Error message information
4 * Copyright The Mbed TLS Contributors
5 * SPDX-License-Identifier: Apache-2.0
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include "mbedtls/error.h"
24 #if defined(MBEDTLS_ERROR_C) || defined(MBEDTLS_ERROR_STRERROR_DUMMY)
26 #if defined(MBEDTLS_ERROR_C)
28 #if defined(MBEDTLS_PLATFORM_C)
29 #include "mbedtls/platform.h"
31 #define mbedtls_snprintf snprintf
37 #if defined(MBEDTLS_AES_C)
38 #include "mbedtls/aes.h"
41 #if defined(MBEDTLS_ARC4_C)
42 #include "mbedtls/arc4.h"
45 #if defined(MBEDTLS_ARIA_C)
46 #include "mbedtls/aria.h"
49 #if defined(MBEDTLS_ASN1_PARSE_C)
50 #include "mbedtls/asn1.h"
53 #if defined(MBEDTLS_BASE64_C)
54 #include "mbedtls/base64.h"
57 #if defined(MBEDTLS_BIGNUM_C)
58 #include "mbedtls/bignum.h"
61 #if defined(MBEDTLS_BLOWFISH_C)
62 #include "mbedtls/blowfish.h"
65 #if defined(MBEDTLS_CAMELLIA_C)
66 #include "mbedtls/camellia.h"
69 #if defined(MBEDTLS_CCM_C)
70 #include "mbedtls/ccm.h"
73 #if defined(MBEDTLS_CHACHA20_C)
74 #include "mbedtls/chacha20.h"
77 #if defined(MBEDTLS_CHACHAPOLY_C)
78 #include "mbedtls/chachapoly.h"
81 #if defined(MBEDTLS_CIPHER_C)
82 #include "mbedtls/cipher.h"
85 #if defined(MBEDTLS_CMAC_C)
86 #include "mbedtls/cmac.h"
89 #if defined(MBEDTLS_CTR_DRBG_C)
90 #include "mbedtls/ctr_drbg.h"
93 #if defined(MBEDTLS_DES_C)
94 #include "mbedtls/des.h"
97 #if defined(MBEDTLS_DHM_C)
98 #include "mbedtls/dhm.h"
101 #if defined(MBEDTLS_ECP_C)
102 #include "mbedtls/ecp.h"
105 #if defined(MBEDTLS_ENTROPY_C)
106 #include "mbedtls/entropy.h"
109 #if defined(MBEDTLS_ERROR_C)
110 #include "mbedtls/error.h"
113 #if defined(MBEDTLS_GCM_C)
114 #include "mbedtls/gcm.h"
117 #if defined(MBEDTLS_HKDF_C)
118 #include "mbedtls/hkdf.h"
121 #if defined(MBEDTLS_HMAC_DRBG_C)
122 #include "mbedtls/hmac_drbg.h"
125 #if defined(MBEDTLS_MD_C)
126 #include "mbedtls/md.h"
129 #if defined(MBEDTLS_MD2_C)
130 #include "mbedtls/md2.h"
133 #if defined(MBEDTLS_MD4_C)
134 #include "mbedtls/md4.h"
137 #if defined(MBEDTLS_MD5_C)
138 #include "mbedtls/md5.h"
141 #if defined(MBEDTLS_NET_C)
142 #include "mbedtls/net_sockets.h"
145 #if defined(MBEDTLS_OID_C)
146 #include "mbedtls/oid.h"
149 #if defined(MBEDTLS_PADLOCK_C)
150 #include "mbedtls/padlock.h"
153 #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
154 #include "mbedtls/pem.h"
157 #if defined(MBEDTLS_PK_C)
158 #include "mbedtls/pk.h"
161 #if defined(MBEDTLS_PKCS12_C)
162 #include "mbedtls/pkcs12.h"
165 #if defined(MBEDTLS_PKCS5_C)
166 #include "mbedtls/pkcs5.h"
169 #if defined(MBEDTLS_PLATFORM_C)
170 #include "mbedtls/platform.h"
173 #if defined(MBEDTLS_POLY1305_C)
174 #include "mbedtls/poly1305.h"
177 #if defined(MBEDTLS_RIPEMD160_C)
178 #include "mbedtls/ripemd160.h"
181 #if defined(MBEDTLS_RSA_C)
182 #include "mbedtls/rsa.h"
185 #if defined(MBEDTLS_SHA1_C)
186 #include "mbedtls/sha1.h"
189 #if defined(MBEDTLS_SHA256_C)
190 #include "mbedtls/sha256.h"
193 #if defined(MBEDTLS_SHA512_C)
194 #include "mbedtls/sha512.h"
197 #if defined(MBEDTLS_SSL_TLS_C)
198 #include "mbedtls/ssl.h"
201 #if defined(MBEDTLS_THREADING_C)
202 #include "mbedtls/threading.h"
205 #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
206 #include "mbedtls/x509.h"
209 #if defined(MBEDTLS_XTEA_C)
210 #include "mbedtls/xtea.h"
214 const char *mbedtls_high_level_strerr(int error_code
) {
215 int high_level_error_code
;
218 error_code
= -error_code
;
220 /* Extract the high-level part from the error code. */
221 high_level_error_code
= error_code
& 0xFF80;
223 switch (high_level_error_code
) {
224 /* Begin Auto-Generated Code. */
225 #if defined(MBEDTLS_CIPHER_C)
226 case -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE
):
227 return ("CIPHER - The selected feature is not available");
228 case -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA
):
229 return ("CIPHER - Bad input parameters");
230 case -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED
):
231 return ("CIPHER - Failed to allocate memory");
232 case -(MBEDTLS_ERR_CIPHER_INVALID_PADDING
):
233 return ("CIPHER - Input data contains invalid padding and is rejected");
234 case -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED
):
235 return ("CIPHER - Decryption of block requires a full block");
236 case -(MBEDTLS_ERR_CIPHER_AUTH_FAILED
):
237 return ("CIPHER - Authentication failed (for AEAD modes)");
238 case -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT
):
239 return ("CIPHER - The context is invalid. For example, because it was freed");
240 case -(MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED
):
241 return ("CIPHER - Cipher hardware accelerator failed");
242 #endif /* MBEDTLS_CIPHER_C */
244 #if defined(MBEDTLS_DHM_C)
245 case -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA
):
246 return ("DHM - Bad input parameters");
247 case -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED
):
248 return ("DHM - Reading of the DHM parameters failed");
249 case -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED
):
250 return ("DHM - Making of the DHM parameters failed");
251 case -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED
):
252 return ("DHM - Reading of the public values failed");
253 case -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED
):
254 return ("DHM - Making of the public value failed");
255 case -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED
):
256 return ("DHM - Calculation of the DHM secret failed");
257 case -(MBEDTLS_ERR_DHM_INVALID_FORMAT
):
258 return ("DHM - The ASN.1 data is not formatted correctly");
259 case -(MBEDTLS_ERR_DHM_ALLOC_FAILED
):
260 return ("DHM - Allocation of memory failed");
261 case -(MBEDTLS_ERR_DHM_FILE_IO_ERROR
):
262 return ("DHM - Read or write of file failed");
263 case -(MBEDTLS_ERR_DHM_HW_ACCEL_FAILED
):
264 return ("DHM - DHM hardware accelerator failed");
265 case -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED
):
266 return ("DHM - Setting the modulus and generator failed");
267 #endif /* MBEDTLS_DHM_C */
269 #if defined(MBEDTLS_ECP_C)
270 case -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA
):
271 return ("ECP - Bad input parameters to function");
272 case -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL
):
273 return ("ECP - The buffer is too small to write to");
274 case -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE
):
275 return ("ECP - The requested feature is not available, for example, the requested curve is not supported");
276 case -(MBEDTLS_ERR_ECP_VERIFY_FAILED
):
277 return ("ECP - The signature is not valid");
278 case -(MBEDTLS_ERR_ECP_ALLOC_FAILED
):
279 return ("ECP - Memory allocation failed");
280 case -(MBEDTLS_ERR_ECP_RANDOM_FAILED
):
281 return ("ECP - Generation of random value, such as ephemeral key, failed");
282 case -(MBEDTLS_ERR_ECP_INVALID_KEY
):
283 return ("ECP - Invalid private or public key");
284 case -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH
):
285 return ("ECP - The buffer contains a valid signature followed by more data");
286 case -(MBEDTLS_ERR_ECP_HW_ACCEL_FAILED
):
287 return ("ECP - The ECP hardware accelerator failed");
288 case -(MBEDTLS_ERR_ECP_IN_PROGRESS
):
289 return ("ECP - Operation in progress, call again with the same parameters to continue");
290 #endif /* MBEDTLS_ECP_C */
292 #if defined(MBEDTLS_MD_C)
293 case -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE
):
294 return ("MD - The selected feature is not available");
295 case -(MBEDTLS_ERR_MD_BAD_INPUT_DATA
):
296 return ("MD - Bad input parameters to function");
297 case -(MBEDTLS_ERR_MD_ALLOC_FAILED
):
298 return ("MD - Failed to allocate memory");
299 case -(MBEDTLS_ERR_MD_FILE_IO_ERROR
):
300 return ("MD - Opening or reading of file failed");
301 case -(MBEDTLS_ERR_MD_HW_ACCEL_FAILED
):
302 return ("MD - MD hardware accelerator failed");
303 #endif /* MBEDTLS_MD_C */
305 #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
306 case -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT
):
307 return ("PEM - No PEM header or footer found");
308 case -(MBEDTLS_ERR_PEM_INVALID_DATA
):
309 return ("PEM - PEM string is not as expected");
310 case -(MBEDTLS_ERR_PEM_ALLOC_FAILED
):
311 return ("PEM - Failed to allocate memory");
312 case -(MBEDTLS_ERR_PEM_INVALID_ENC_IV
):
313 return ("PEM - RSA IV is not in hex-format");
314 case -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG
):
315 return ("PEM - Unsupported key encryption algorithm");
316 case -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED
):
317 return ("PEM - Private key password can't be empty");
318 case -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH
):
319 return ("PEM - Given private key password does not allow for correct decryption");
320 case -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE
):
321 return ("PEM - Unavailable feature, e.g. hashing/encryption combination");
322 case -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA
):
323 return ("PEM - Bad input parameters to function");
324 #endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
326 #if defined(MBEDTLS_PK_C)
327 case -(MBEDTLS_ERR_PK_ALLOC_FAILED
):
328 return ("PK - Memory allocation failed");
329 case -(MBEDTLS_ERR_PK_TYPE_MISMATCH
):
330 return ("PK - Type mismatch, eg attempt to encrypt with an ECDSA key");
331 case -(MBEDTLS_ERR_PK_BAD_INPUT_DATA
):
332 return ("PK - Bad input parameters to function");
333 case -(MBEDTLS_ERR_PK_FILE_IO_ERROR
):
334 return ("PK - Read/write of file failed");
335 case -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION
):
336 return ("PK - Unsupported key version");
337 case -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT
):
338 return ("PK - Invalid key tag or value");
339 case -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG
):
340 return ("PK - Key algorithm is unsupported (only RSA and EC are supported)");
341 case -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED
):
342 return ("PK - Private key password can't be empty");
343 case -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH
):
344 return ("PK - Given private key password does not allow for correct decryption");
345 case -(MBEDTLS_ERR_PK_INVALID_PUBKEY
):
346 return ("PK - The pubkey tag or value is invalid (only RSA and EC are supported)");
347 case -(MBEDTLS_ERR_PK_INVALID_ALG
):
348 return ("PK - The algorithm tag or value is invalid");
349 case -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE
):
350 return ("PK - Elliptic curve is unsupported (only NIST curves are supported)");
351 case -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE
):
352 return ("PK - Unavailable feature, e.g. RSA disabled for RSA key");
353 case -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH
):
354 return ("PK - The buffer contains a valid signature followed by more data");
355 case -(MBEDTLS_ERR_PK_HW_ACCEL_FAILED
):
356 return ("PK - PK hardware accelerator failed");
357 #endif /* MBEDTLS_PK_C */
359 #if defined(MBEDTLS_PKCS12_C)
360 case -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA
):
361 return ("PKCS12 - Bad input parameters to function");
362 case -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE
):
363 return ("PKCS12 - Feature not available, e.g. unsupported encryption scheme");
364 case -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT
):
365 return ("PKCS12 - PBE ASN.1 data not as expected");
366 case -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH
):
367 return ("PKCS12 - Given private key password does not allow for correct decryption");
368 #endif /* MBEDTLS_PKCS12_C */
370 #if defined(MBEDTLS_PKCS5_C)
371 case -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA
):
372 return ("PKCS5 - Bad input parameters to function");
373 case -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT
):
374 return ("PKCS5 - Unexpected ASN.1 data");
375 case -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE
):
376 return ("PKCS5 - Requested encryption or digest alg not available");
377 case -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH
):
378 return ("PKCS5 - Given private key password does not allow for correct decryption");
379 #endif /* MBEDTLS_PKCS5_C */
381 #if defined(MBEDTLS_RSA_C)
382 case -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA
):
383 return ("RSA - Bad input parameters to function");
384 case -(MBEDTLS_ERR_RSA_INVALID_PADDING
):
385 return ("RSA - Input data contains invalid padding and is rejected");
386 case -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED
):
387 return ("RSA - Something failed during generation of a key");
388 case -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED
):
389 return ("RSA - Key failed to pass the validity check of the library");
390 case -(MBEDTLS_ERR_RSA_PUBLIC_FAILED
):
391 return ("RSA - The public key operation failed");
392 case -(MBEDTLS_ERR_RSA_PRIVATE_FAILED
):
393 return ("RSA - The private key operation failed");
394 case -(MBEDTLS_ERR_RSA_VERIFY_FAILED
):
395 return ("RSA - The PKCS#1 verification failed");
396 case -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE
):
397 return ("RSA - The output buffer for decryption is not large enough");
398 case -(MBEDTLS_ERR_RSA_RNG_FAILED
):
399 return ("RSA - The random generator failed to generate non-zeros");
400 case -(MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION
):
401 return ("RSA - The implementation does not offer the requested operation, for example, because of security violations or lack of functionality");
402 case -(MBEDTLS_ERR_RSA_HW_ACCEL_FAILED
):
403 return ("RSA - RSA hardware accelerator failed");
404 #endif /* MBEDTLS_RSA_C */
406 #if defined(MBEDTLS_SSL_TLS_C)
407 case -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE
):
408 return ("SSL - The requested feature is not available");
409 case -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA
):
410 return ("SSL - Bad input parameters to function");
411 case -(MBEDTLS_ERR_SSL_INVALID_MAC
):
412 return ("SSL - Verification of the message MAC failed");
413 case -(MBEDTLS_ERR_SSL_INVALID_RECORD
):
414 return ("SSL - An invalid SSL record was received");
415 case -(MBEDTLS_ERR_SSL_CONN_EOF
):
416 return ("SSL - The connection indicated an EOF");
417 case -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER
):
418 return ("SSL - An unknown cipher was received");
419 case -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN
):
420 return ("SSL - The server has no ciphersuites in common with the client");
421 case -(MBEDTLS_ERR_SSL_NO_RNG
):
422 return ("SSL - No RNG was provided to the SSL module");
423 case -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE
):
424 return ("SSL - No client certification received from the client, but required by the authentication mode");
425 case -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE
):
426 return ("SSL - Our own certificate(s) is/are too large to send in an SSL message");
427 case -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED
):
428 return ("SSL - The own certificate is not set, but needed by the server");
429 case -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED
):
430 return ("SSL - The own private key or pre-shared key is not set, but needed");
431 case -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED
):
432 return ("SSL - No CA Chain is set, but required to operate");
433 case -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE
):
434 return ("SSL - An unexpected message was received from our peer");
435 case -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE
):
436 return ("SSL - A fatal alert message was received from our peer");
437 case -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED
):
438 return ("SSL - Verification of our peer failed");
439 case -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY
):
440 return ("SSL - The peer notified us that the connection is going to be closed");
441 case -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO
):
442 return ("SSL - Processing of the ClientHello handshake message failed");
443 case -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO
):
444 return ("SSL - Processing of the ServerHello handshake message failed");
445 case -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE
):
446 return ("SSL - Processing of the Certificate handshake message failed");
447 case -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST
):
448 return ("SSL - Processing of the CertificateRequest handshake message failed");
449 case -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE
):
450 return ("SSL - Processing of the ServerKeyExchange handshake message failed");
451 case -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE
):
452 return ("SSL - Processing of the ServerHelloDone handshake message failed");
453 case -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE
):
454 return ("SSL - Processing of the ClientKeyExchange handshake message failed");
455 case -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP
):
456 return ("SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public");
457 case -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS
):
458 return ("SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret");
459 case -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY
):
460 return ("SSL - Processing of the CertificateVerify handshake message failed");
461 case -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC
):
462 return ("SSL - Processing of the ChangeCipherSpec handshake message failed");
463 case -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED
):
464 return ("SSL - Processing of the Finished handshake message failed");
465 case -(MBEDTLS_ERR_SSL_ALLOC_FAILED
):
466 return ("SSL - Memory allocation failed");
467 case -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED
):
468 return ("SSL - Hardware acceleration function returned with error");
469 case -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH
):
470 return ("SSL - Hardware acceleration function skipped / left alone data");
471 case -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED
):
472 return ("SSL - Processing of the compression / decompression failed");
473 case -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION
):
474 return ("SSL - Handshake protocol not within min/max boundaries");
475 case -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET
):
476 return ("SSL - Processing of the NewSessionTicket handshake message failed");
477 case -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED
):
478 return ("SSL - Session ticket has expired");
479 case -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH
):
480 return ("SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)");
481 case -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY
):
482 return ("SSL - Unknown identity received (eg, PSK identity)");
483 case -(MBEDTLS_ERR_SSL_INTERNAL_ERROR
):
484 return ("SSL - Internal error (eg, unexpected failure in lower-level module)");
485 case -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING
):
486 return ("SSL - A counter would wrap (eg, too many messages exchanged)");
487 case -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO
):
488 return ("SSL - Unexpected message at ServerHello in renegotiation");
489 case -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED
):
490 return ("SSL - DTLS client must retry for hello verification");
491 case -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL
):
492 return ("SSL - A buffer is too small to receive or write a message");
493 case -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE
):
494 return ("SSL - None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages)");
495 case -(MBEDTLS_ERR_SSL_WANT_READ
):
496 return ("SSL - No data of requested type currently available on underlying transport");
497 case -(MBEDTLS_ERR_SSL_WANT_WRITE
):
498 return ("SSL - Connection requires a write call");
499 case -(MBEDTLS_ERR_SSL_TIMEOUT
):
500 return ("SSL - The operation timed out");
501 case -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT
):
502 return ("SSL - The client initiated a reconnect from the same port");
503 case -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD
):
504 return ("SSL - Record header looks valid but is not expected");
505 case -(MBEDTLS_ERR_SSL_NON_FATAL
):
506 return ("SSL - The alert message received indicates a non-fatal error");
507 case -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH
):
508 return ("SSL - Couldn't set the hash for verifying CertificateVerify");
509 case -(MBEDTLS_ERR_SSL_CONTINUE_PROCESSING
):
510 return ("SSL - Internal-only message signaling that further message-processing should be done");
511 case -(MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS
):
512 return ("SSL - The asynchronous operation is not completed yet");
513 case -(MBEDTLS_ERR_SSL_EARLY_MESSAGE
):
514 return ("SSL - Internal-only message signaling that a message arrived early");
515 case -(MBEDTLS_ERR_SSL_UNEXPECTED_CID
):
516 return ("SSL - An encrypted DTLS-frame with an unexpected CID was received");
517 case -(MBEDTLS_ERR_SSL_VERSION_MISMATCH
):
518 return ("SSL - An operation failed due to an unexpected version or configuration");
519 case -(MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS
):
520 return ("SSL - A cryptographic operation is in progress. Try again later");
521 case -(MBEDTLS_ERR_SSL_BAD_CONFIG
):
522 return ("SSL - Invalid value in SSL config");
523 #endif /* MBEDTLS_SSL_TLS_C */
525 #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
526 case -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE
):
527 return ("X509 - Unavailable feature, e.g. RSA hashing/encryption combination");
528 case -(MBEDTLS_ERR_X509_UNKNOWN_OID
):
529 return ("X509 - Requested OID is unknown");
530 case -(MBEDTLS_ERR_X509_INVALID_FORMAT
):
531 return ("X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected");
532 case -(MBEDTLS_ERR_X509_INVALID_VERSION
):
533 return ("X509 - The CRT/CRL/CSR version element is invalid");
534 case -(MBEDTLS_ERR_X509_INVALID_SERIAL
):
535 return ("X509 - The serial tag or value is invalid");
536 case -(MBEDTLS_ERR_X509_INVALID_ALG
):
537 return ("X509 - The algorithm tag or value is invalid");
538 case -(MBEDTLS_ERR_X509_INVALID_NAME
):
539 return ("X509 - The name tag or value is invalid");
540 case -(MBEDTLS_ERR_X509_INVALID_DATE
):
541 return ("X509 - The date tag or value is invalid");
542 case -(MBEDTLS_ERR_X509_INVALID_SIGNATURE
):
543 return ("X509 - The signature tag or value invalid");
544 case -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS
):
545 return ("X509 - The extension tag or value is invalid");
546 case -(MBEDTLS_ERR_X509_UNKNOWN_VERSION
):
547 return ("X509 - CRT/CRL/CSR has an unsupported version number");
548 case -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG
):
549 return ("X509 - Signature algorithm (oid) is unsupported");
550 case -(MBEDTLS_ERR_X509_SIG_MISMATCH
):
551 return ("X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)");
552 case -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED
):
553 return ("X509 - Certificate verification failed, e.g. CRL, CA or signature check failed");
554 case -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT
):
555 return ("X509 - Format not recognized as DER or PEM");
556 case -(MBEDTLS_ERR_X509_BAD_INPUT_DATA
):
557 return ("X509 - Input invalid");
558 case -(MBEDTLS_ERR_X509_ALLOC_FAILED
):
559 return ("X509 - Allocation of memory failed");
560 case -(MBEDTLS_ERR_X509_FILE_IO_ERROR
):
561 return ("X509 - Read/write of file failed");
562 case -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL
):
563 return ("X509 - Destination buffer is too small");
564 case -(MBEDTLS_ERR_X509_FATAL_ERROR
):
565 return ("X509 - A fatal error occurred, eg the chain is too long or the vrfy callback failed");
566 #endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
567 /* End Auto-Generated Code. */
576 const char *mbedtls_low_level_strerr(int error_code
) {
577 int low_level_error_code
;
580 error_code
= -error_code
;
582 /* Extract the low-level part from the error code. */
583 low_level_error_code
= error_code
& ~0xFF80;
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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. */
892 void mbedtls_strerror(int ret
, char *buf
, size_t buflen
) {
895 const char *high_level_error_description
= NULL
;
896 const char *low_level_error_description
= NULL
;
901 memset(buf
, 0x00, buflen
);
907 use_ret
= ret
& 0xFF80;
909 // Translate high level error code.
910 high_level_error_description
= mbedtls_high_level_strerr(ret
);
912 if (high_level_error_description
== NULL
)
913 mbedtls_snprintf(buf
, buflen
, "UNKNOWN ERROR CODE (%04X)", (unsigned int) use_ret
);
915 mbedtls_snprintf(buf
, buflen
, "%s", high_level_error_description
);
917 #if defined(MBEDTLS_SSL_TLS_C)
918 // Early return in case of a fatal error - do not try to translate low
920 if (use_ret
== -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE
))
922 #endif /* MBEDTLS_SSL_TLS_C */
925 use_ret
= ret
& ~0xFF80;
930 // If high level code is present, make a concatenation between both
936 if (buflen
- len
< 5)
939 mbedtls_snprintf(buf
+ len
, buflen
- len
, " : ");
945 // Translate low level error code.
946 low_level_error_description
= mbedtls_low_level_strerr(ret
);
948 if (low_level_error_description
== NULL
)
949 mbedtls_snprintf(buf
, buflen
, "UNKNOWN ERROR CODE (%04X)", (unsigned int) use_ret
);
951 mbedtls_snprintf(buf
, buflen
, "%s", low_level_error_description
);
954 #else /* MBEDTLS_ERROR_C */
957 * Provide an non-function in case MBEDTLS_ERROR_C is not defined
959 void mbedtls_strerror(int ret
, char *buf
, size_t buflen
) {
966 #endif /* MBEDTLS_ERROR_C */
968 #endif /* MBEDTLS_ERROR_C || MBEDTLS_ERROR_STRERROR_DUMMY */