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