blob: 38b658006d0822a6f1c3fd888314d25ff7966e32 [file] [log] [blame]
Paul Bakker9d781402011-05-09 16:17:09 +00001/*
2 * Error message information
3 *
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02004 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02005 * 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.
Paul Bakker9d781402011-05-09 16:17:09 +000018 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000019 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker9d781402011-05-09 16:17:09 +000020 */
21
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020022#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000023#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020024#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020025#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020026#endif
Paul Bakker9d781402011-05-09 16:17:09 +000027
Janos Follathdf587ee2019-12-18 13:16:46 +000028#if defined(MBEDTLS_ERROR_STRERROR_DUMMY)
Rich Evans00ab4702015-02-06 13:43:58 +000029#include <string.h>
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020030#endif
31
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020032#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000033#include "mbedtls/platform.h"
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +000034#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020035#define mbedtls_snprintf snprintf
-~- redtangent ~-~9fa2e862016-05-26 10:07:49 +010036#define mbedtls_time_t time_t
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020037#endif
38
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020039#if defined(MBEDTLS_ERROR_C)
Paul Bakker3c2122f2013-06-24 19:03:14 +020040
Rich Evans00ab4702015-02-06 13:43:58 +000041#include <stdio.h>
42
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020043#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000044#include "mbedtls/aes.h"
Paul Bakker9d781402011-05-09 16:17:09 +000045#endif
46
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010047#if defined(MBEDTLS_ARC4_C)
48#include "mbedtls/arc4.h"
49#endif
50
Markku-Juhani O. Saarinen07478d62017-12-01 16:20:15 +000051#if defined(MBEDTLS_ARIA_C)
52#include "mbedtls/aria.h"
53#endif
54
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055#if defined(MBEDTLS_BASE64_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000056#include "mbedtls/base64.h"
Paul Bakker9d781402011-05-09 16:17:09 +000057#endif
58
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059#if defined(MBEDTLS_BIGNUM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000060#include "mbedtls/bignum.h"
Paul Bakker9d781402011-05-09 16:17:09 +000061#endif
62
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000064#include "mbedtls/blowfish.h"
Paul Bakker83f00bb2012-07-04 11:08:50 +000065#endif
66
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020067#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000068#include "mbedtls/camellia.h"
Paul Bakker9d781402011-05-09 16:17:09 +000069#endif
70
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020071#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000072#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +020073#endif
74
Daniel King34b822c2016-05-15 17:28:08 -030075#if defined(MBEDTLS_CHACHA20_C)
76#include "mbedtls/chacha20.h"
77#endif
78
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020079#if defined(MBEDTLS_CHACHAPOLY_C)
80#include "mbedtls/chachapoly.h"
81#endif
82
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083#if defined(MBEDTLS_CIPHER_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000084#include "mbedtls/cipher.h"
Paul Bakkerff61a782011-06-09 15:42:02 +000085#endif
86
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010087#if defined(MBEDTLS_CMAC_C)
88#include "mbedtls/cmac.h"
89#endif
90
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020091#if defined(MBEDTLS_CTR_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000092#include "mbedtls/ctr_drbg.h"
Paul Bakker880ac7e2011-11-27 14:50:49 +000093#endif
94
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020095#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000096#include "mbedtls/des.h"
Paul Bakker9d781402011-05-09 16:17:09 +000097#endif
98
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020099#if defined(MBEDTLS_DHM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000100#include "mbedtls/dhm.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000101#endif
102
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200103#if defined(MBEDTLS_ECP_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000104#include "mbedtls/ecp.h"
Paul Bakkercf4365f2013-01-16 17:00:43 +0100105#endif
106
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200107#if defined(MBEDTLS_ENTROPY_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000108#include "mbedtls/entropy.h"
Paul Bakker6083fd22011-12-03 21:45:14 +0000109#endif
110
Janos Follath60f6b642019-12-03 15:55:56 +0000111#if defined(MBEDTLS_ERROR_C)
112#include "mbedtls/error.h"
113#endif
114
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200115#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000116#include "mbedtls/gcm.h"
Paul Bakker030277a2012-04-17 12:24:26 +0000117#endif
118
Thomas Fossati656864b2016-07-17 08:51:22 +0100119#if defined(MBEDTLS_HKDF_C)
120#include "mbedtls/hkdf.h"
121#endif
122
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200123#if defined(MBEDTLS_HMAC_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000124#include "mbedtls/hmac_drbg.h"
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100125#endif
126
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127#if defined(MBEDTLS_MD_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000128#include "mbedtls/md.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000129#endif
130
Gilles Peskinea381fe82018-01-23 18:16:11 +0100131#if defined(MBEDTLS_MD2_C)
132#include "mbedtls/md2.h"
133#endif
134
135#if defined(MBEDTLS_MD4_C)
136#include "mbedtls/md4.h"
137#endif
138
139#if defined(MBEDTLS_MD5_C)
140#include "mbedtls/md5.h"
141#endif
142
Gilles Peskine458b8f22020-02-26 18:28:28 +0100143#if defined(MBEDTLS_NET_C)
144#include "mbedtls/net_sockets.h"
145#endif
146
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200147#if defined(MBEDTLS_OID_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000148#include "mbedtls/oid.h"
Paul Bakkerc70b9822013-04-07 22:00:46 +0200149#endif
150
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200151#if defined(MBEDTLS_PADLOCK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000152#include "mbedtls/padlock.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000153#endif
154
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200155#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000156#include "mbedtls/pem.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000157#endif
158
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200159#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000160#include "mbedtls/pk.h"
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200161#endif
162
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200163#if defined(MBEDTLS_PKCS12_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000164#include "mbedtls/pkcs12.h"
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200165#endif
166
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200167#if defined(MBEDTLS_PKCS5_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000168#include "mbedtls/pkcs5.h"
Paul Bakkerb0c19a42013-06-24 19:26:38 +0200169#endif
170
Ron Eldor0ff4e0b2018-08-29 18:53:20 +0300171#if defined(MBEDTLS_PLATFORM_C)
172#include "mbedtls/platform.h"
173#endif
174
Daniel Kingadc32c02016-05-16 18:25:45 -0300175#if defined(MBEDTLS_POLY1305_C)
176#include "mbedtls/poly1305.h"
177#endif
178
Gilles Peskinea381fe82018-01-23 18:16:11 +0100179#if defined(MBEDTLS_RIPEMD160_C)
180#include "mbedtls/ripemd160.h"
181#endif
182
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200183#if defined(MBEDTLS_RSA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000184#include "mbedtls/rsa.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000185#endif
186
Gilles Peskinea381fe82018-01-23 18:16:11 +0100187#if defined(MBEDTLS_SHA1_C)
188#include "mbedtls/sha1.h"
189#endif
190
191#if defined(MBEDTLS_SHA256_C)
192#include "mbedtls/sha256.h"
193#endif
194
195#if defined(MBEDTLS_SHA512_C)
196#include "mbedtls/sha512.h"
197#endif
198
Gilles Peskine458b8f22020-02-26 18:28:28 +0100199#if defined(MBEDTLS_SSL_TLS_C)
200#include "mbedtls/ssl.h"
201#endif
202
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200203#if defined(MBEDTLS_THREADING_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000204#include "mbedtls/threading.h"
Paul Bakker2466d932013-09-28 14:40:38 +0200205#endif
206
Gilles Peskine458b8f22020-02-26 18:28:28 +0100207#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
208#include "mbedtls/x509.h"
209#endif
210
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200211#if defined(MBEDTLS_XTEA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000212#include "mbedtls/xtea.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000213#endif
214
Paul Bakkerdceecd82011-11-15 16:38:34 +0000215
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700216const char * mbedtls_high_level_strerr( int error_code )
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700217{
Gaurav Aggarwal6ea4fc72020-04-20 16:03:46 -0700218 int high_level_error_code;
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700219 const char *error_description = NULL;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700220
Gaurav Aggarwal6ea4fc72020-04-20 16:03:46 -0700221 if( error_code < 0 )
222 error_code = -error_code;
223
224 /* Extract the high-level part from the error code. */
225 high_level_error_code = error_code & 0xFF80;
226
227 switch( high_level_error_code )
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700228 {
Gaurav Aggarwal3d02db22020-04-11 17:14:03 -0700229 /* Begin Auto-Generated Code. */
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700230#if defined(MBEDTLS_CIPHER_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700231 case -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE):
232 error_description = "CIPHER - The selected feature is not available";
233 break;
234 case -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA):
235 error_description = "CIPHER - Bad input parameters";
236 break;
237 case -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED):
238 error_description = "CIPHER - Failed to allocate memory";
239 break;
240 case -(MBEDTLS_ERR_CIPHER_INVALID_PADDING):
241 error_description = "CIPHER - Input data contains invalid padding and is rejected";
242 break;
243 case -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED):
244 error_description = "CIPHER - Decryption of block requires a full block";
245 break;
246 case -(MBEDTLS_ERR_CIPHER_AUTH_FAILED):
247 error_description = "CIPHER - Authentication failed (for AEAD modes)";
248 break;
249 case -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT):
250 error_description = "CIPHER - The context is invalid. For example, because it was freed";
251 break;
252 case -(MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED):
253 error_description = "CIPHER - Cipher hardware accelerator failed";
254 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700255#endif /* MBEDTLS_CIPHER_C */
256
257#if defined(MBEDTLS_DHM_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700258 case -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA):
259 error_description = "DHM - Bad input parameters";
260 break;
261 case -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED):
262 error_description = "DHM - Reading of the DHM parameters failed";
263 break;
264 case -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED):
265 error_description = "DHM - Making of the DHM parameters failed";
266 break;
267 case -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED):
268 error_description = "DHM - Reading of the public values failed";
269 break;
270 case -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED):
271 error_description = "DHM - Making of the public value failed";
272 break;
273 case -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED):
274 error_description = "DHM - Calculation of the DHM secret failed";
275 break;
276 case -(MBEDTLS_ERR_DHM_INVALID_FORMAT):
277 error_description = "DHM - The ASN.1 data is not formatted correctly";
278 break;
279 case -(MBEDTLS_ERR_DHM_ALLOC_FAILED):
280 error_description = "DHM - Allocation of memory failed";
281 break;
282 case -(MBEDTLS_ERR_DHM_FILE_IO_ERROR):
283 error_description = "DHM - Read or write of file failed";
284 break;
285 case -(MBEDTLS_ERR_DHM_HW_ACCEL_FAILED):
286 error_description = "DHM - DHM hardware accelerator failed";
287 break;
288 case -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED):
289 error_description = "DHM - Setting the modulus and generator failed";
290 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700291#endif /* MBEDTLS_DHM_C */
292
293#if defined(MBEDTLS_ECP_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700294 case -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA):
295 error_description = "ECP - Bad input parameters to function";
296 break;
297 case -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL):
298 error_description = "ECP - The buffer is too small to write to";
299 break;
300 case -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE):
301 error_description = "ECP - The requested feature is not available, for example, the requested curve is not supported";
302 break;
303 case -(MBEDTLS_ERR_ECP_VERIFY_FAILED):
304 error_description = "ECP - The signature is not valid";
305 break;
306 case -(MBEDTLS_ERR_ECP_ALLOC_FAILED):
307 error_description = "ECP - Memory allocation failed";
308 break;
309 case -(MBEDTLS_ERR_ECP_RANDOM_FAILED):
310 error_description = "ECP - Generation of random value, such as ephemeral key, failed";
311 break;
312 case -(MBEDTLS_ERR_ECP_INVALID_KEY):
313 error_description = "ECP - Invalid private or public key";
314 break;
315 case -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH):
316 error_description = "ECP - The buffer contains a valid signature followed by more data";
317 break;
318 case -(MBEDTLS_ERR_ECP_HW_ACCEL_FAILED):
319 error_description = "ECP - The ECP hardware accelerator failed";
320 break;
321 case -(MBEDTLS_ERR_ECP_IN_PROGRESS):
322 error_description = "ECP - Operation in progress, call again with the same parameters to continue";
323 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700324#endif /* MBEDTLS_ECP_C */
325
326#if defined(MBEDTLS_MD_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700327 case -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE):
328 error_description = "MD - The selected feature is not available";
329 break;
330 case -(MBEDTLS_ERR_MD_BAD_INPUT_DATA):
331 error_description = "MD - Bad input parameters to function";
332 break;
333 case -(MBEDTLS_ERR_MD_ALLOC_FAILED):
334 error_description = "MD - Failed to allocate memory";
335 break;
336 case -(MBEDTLS_ERR_MD_FILE_IO_ERROR):
337 error_description = "MD - Opening or reading of file failed";
338 break;
339 case -(MBEDTLS_ERR_MD_HW_ACCEL_FAILED):
340 error_description = "MD - MD hardware accelerator failed";
341 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700342#endif /* MBEDTLS_MD_C */
343
344#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700345 case -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT):
346 error_description = "PEM - No PEM header or footer found";
347 break;
348 case -(MBEDTLS_ERR_PEM_INVALID_DATA):
349 error_description = "PEM - PEM string is not as expected";
350 break;
351 case -(MBEDTLS_ERR_PEM_ALLOC_FAILED):
352 error_description = "PEM - Failed to allocate memory";
353 break;
354 case -(MBEDTLS_ERR_PEM_INVALID_ENC_IV):
355 error_description = "PEM - RSA IV is not in hex-format";
356 break;
357 case -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG):
358 error_description = "PEM - Unsupported key encryption algorithm";
359 break;
360 case -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED):
361 error_description = "PEM - Private key password can't be empty";
362 break;
363 case -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH):
364 error_description = "PEM - Given private key password does not allow for correct decryption";
365 break;
366 case -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE):
367 error_description = "PEM - Unavailable feature, e.g. hashing/encryption combination";
368 break;
369 case -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA):
370 error_description = "PEM - Bad input parameters to function";
371 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700372#endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
373
374#if defined(MBEDTLS_PK_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700375 case -(MBEDTLS_ERR_PK_ALLOC_FAILED):
376 error_description = "PK - Memory allocation failed";
377 break;
378 case -(MBEDTLS_ERR_PK_TYPE_MISMATCH):
379 error_description = "PK - Type mismatch, eg attempt to encrypt with an ECDSA key";
380 break;
381 case -(MBEDTLS_ERR_PK_BAD_INPUT_DATA):
382 error_description = "PK - Bad input parameters to function";
383 break;
384 case -(MBEDTLS_ERR_PK_FILE_IO_ERROR):
385 error_description = "PK - Read/write of file failed";
386 break;
387 case -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION):
388 error_description = "PK - Unsupported key version";
389 break;
390 case -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT):
391 error_description = "PK - Invalid key tag or value";
392 break;
393 case -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG):
394 error_description = "PK - Key algorithm is unsupported (only RSA and EC are supported)";
395 break;
396 case -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED):
397 error_description = "PK - Private key password can't be empty";
398 break;
399 case -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH):
400 error_description = "PK - Given private key password does not allow for correct decryption";
401 break;
402 case -(MBEDTLS_ERR_PK_INVALID_PUBKEY):
403 error_description = "PK - The pubkey tag or value is invalid (only RSA and EC are supported)";
404 break;
405 case -(MBEDTLS_ERR_PK_INVALID_ALG):
406 error_description = "PK - The algorithm tag or value is invalid";
407 break;
408 case -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE):
409 error_description = "PK - Elliptic curve is unsupported (only NIST curves are supported)";
410 break;
411 case -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE):
412 error_description = "PK - Unavailable feature, e.g. RSA disabled for RSA key";
413 break;
414 case -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH):
415 error_description = "PK - The buffer contains a valid signature followed by more data";
416 break;
417 case -(MBEDTLS_ERR_PK_HW_ACCEL_FAILED):
418 error_description = "PK - PK hardware accelerator failed";
419 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700420#endif /* MBEDTLS_PK_C */
421
422#if defined(MBEDTLS_PKCS12_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700423 case -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA):
424 error_description = "PKCS12 - Bad input parameters to function";
425 break;
426 case -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE):
427 error_description = "PKCS12 - Feature not available, e.g. unsupported encryption scheme";
428 break;
429 case -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT):
430 error_description = "PKCS12 - PBE ASN.1 data not as expected";
431 break;
432 case -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH):
433 error_description = "PKCS12 - Given private key password does not allow for correct decryption";
434 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700435#endif /* MBEDTLS_PKCS12_C */
436
437#if defined(MBEDTLS_PKCS5_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700438 case -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA):
439 error_description = "PKCS5 - Bad input parameters to function";
440 break;
441 case -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT):
442 error_description = "PKCS5 - Unexpected ASN.1 data";
443 break;
444 case -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE):
445 error_description = "PKCS5 - Requested encryption or digest alg not available";
446 break;
447 case -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH):
448 error_description = "PKCS5 - Given private key password does not allow for correct decryption";
449 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700450#endif /* MBEDTLS_PKCS5_C */
451
452#if defined(MBEDTLS_RSA_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700453 case -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA):
454 error_description = "RSA - Bad input parameters to function";
455 break;
456 case -(MBEDTLS_ERR_RSA_INVALID_PADDING):
457 error_description = "RSA - Input data contains invalid padding and is rejected";
458 break;
459 case -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED):
460 error_description = "RSA - Something failed during generation of a key";
461 break;
462 case -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED):
463 error_description = "RSA - Key failed to pass the validity check of the library";
464 break;
465 case -(MBEDTLS_ERR_RSA_PUBLIC_FAILED):
466 error_description = "RSA - The public key operation failed";
467 break;
468 case -(MBEDTLS_ERR_RSA_PRIVATE_FAILED):
469 error_description = "RSA - The private key operation failed";
470 break;
471 case -(MBEDTLS_ERR_RSA_VERIFY_FAILED):
472 error_description = "RSA - The PKCS#1 verification failed";
473 break;
474 case -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE):
475 error_description = "RSA - The output buffer for decryption is not large enough";
476 break;
477 case -(MBEDTLS_ERR_RSA_RNG_FAILED):
478 error_description = "RSA - The random generator failed to generate non-zeros";
479 break;
480 case -(MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION):
481 error_description = "RSA - The implementation does not offer the requested operation, for example, because of security violations or lack of functionality";
482 break;
483 case -(MBEDTLS_ERR_RSA_HW_ACCEL_FAILED):
484 error_description = "RSA - RSA hardware accelerator failed";
485 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700486#endif /* MBEDTLS_RSA_C */
487
488#if defined(MBEDTLS_SSL_TLS_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700489 case -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE):
490 error_description = "SSL - The requested feature is not available";
491 break;
492 case -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA):
493 error_description = "SSL - Bad input parameters to function";
494 break;
495 case -(MBEDTLS_ERR_SSL_INVALID_MAC):
496 error_description = "SSL - Verification of the message MAC failed";
497 break;
498 case -(MBEDTLS_ERR_SSL_INVALID_RECORD):
499 error_description = "SSL - An invalid SSL record was received";
500 break;
501 case -(MBEDTLS_ERR_SSL_CONN_EOF):
502 error_description = "SSL - The connection indicated an EOF";
503 break;
504 case -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER):
505 error_description = "SSL - An unknown cipher was received";
506 break;
507 case -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN):
508 error_description = "SSL - The server has no ciphersuites in common with the client";
509 break;
510 case -(MBEDTLS_ERR_SSL_NO_RNG):
511 error_description = "SSL - No RNG was provided to the SSL module";
512 break;
513 case -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE):
514 error_description = "SSL - No client certification received from the client, but required by the authentication mode";
515 break;
516 case -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE):
517 error_description = "SSL - Our own certificate(s) is/are too large to send in an SSL message";
518 break;
519 case -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED):
520 error_description = "SSL - The own certificate is not set, but needed by the server";
521 break;
522 case -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED):
523 error_description = "SSL - The own private key or pre-shared key is not set, but needed";
524 break;
525 case -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED):
526 error_description = "SSL - No CA Chain is set, but required to operate";
527 break;
528 case -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE):
529 error_description = "SSL - An unexpected message was received from our peer";
530 break;
531 case -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE):
532 error_description = "SSL - A fatal alert message was received from our peer";
533 break;
534 case -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED):
535 error_description = "SSL - Verification of our peer failed";
536 break;
537 case -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY):
538 error_description = "SSL - The peer notified us that the connection is going to be closed";
539 break;
540 case -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO):
541 error_description = "SSL - Processing of the ClientHello handshake message failed";
542 break;
543 case -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO):
544 error_description = "SSL - Processing of the ServerHello handshake message failed";
545 break;
546 case -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE):
547 error_description = "SSL - Processing of the Certificate handshake message failed";
548 break;
549 case -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST):
550 error_description = "SSL - Processing of the CertificateRequest handshake message failed";
551 break;
552 case -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE):
553 error_description = "SSL - Processing of the ServerKeyExchange handshake message failed";
554 break;
555 case -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE):
556 error_description = "SSL - Processing of the ServerHelloDone handshake message failed";
557 break;
558 case -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE):
559 error_description = "SSL - Processing of the ClientKeyExchange handshake message failed";
560 break;
561 case -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP):
562 error_description = "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public";
563 break;
564 case -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS):
565 error_description = "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret";
566 break;
567 case -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY):
568 error_description = "SSL - Processing of the CertificateVerify handshake message failed";
569 break;
570 case -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC):
571 error_description = "SSL - Processing of the ChangeCipherSpec handshake message failed";
572 break;
573 case -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED):
574 error_description = "SSL - Processing of the Finished handshake message failed";
575 break;
576 case -(MBEDTLS_ERR_SSL_ALLOC_FAILED):
577 error_description = "SSL - Memory allocation failed";
578 break;
579 case -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED):
580 error_description = "SSL - Hardware acceleration function returned with error";
581 break;
582 case -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH):
583 error_description = "SSL - Hardware acceleration function skipped / left alone data";
584 break;
585 case -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED):
586 error_description = "SSL - Processing of the compression / decompression failed";
587 break;
588 case -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION):
589 error_description = "SSL - Handshake protocol not within min/max boundaries";
590 break;
591 case -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET):
592 error_description = "SSL - Processing of the NewSessionTicket handshake message failed";
593 break;
594 case -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED):
595 error_description = "SSL - Session ticket has expired";
596 break;
597 case -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH):
598 error_description = "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)";
599 break;
600 case -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY):
601 error_description = "SSL - Unknown identity received (eg, PSK identity)";
602 break;
603 case -(MBEDTLS_ERR_SSL_INTERNAL_ERROR):
604 error_description = "SSL - Internal error (eg, unexpected failure in lower-level module)";
605 break;
606 case -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING):
607 error_description = "SSL - A counter would wrap (eg, too many messages exchanged)";
608 break;
609 case -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO):
610 error_description = "SSL - Unexpected message at ServerHello in renegotiation";
611 break;
612 case -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED):
613 error_description = "SSL - DTLS client must retry for hello verification";
614 break;
615 case -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL):
616 error_description = "SSL - A buffer is too small to receive or write a message";
617 break;
618 case -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE):
619 error_description = "SSL - None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages)";
620 break;
621 case -(MBEDTLS_ERR_SSL_WANT_READ):
622 error_description = "SSL - No data of requested type currently available on underlying transport";
623 break;
624 case -(MBEDTLS_ERR_SSL_WANT_WRITE):
625 error_description = "SSL - Connection requires a write call";
626 break;
627 case -(MBEDTLS_ERR_SSL_TIMEOUT):
628 error_description = "SSL - The operation timed out";
629 break;
630 case -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT):
631 error_description = "SSL - The client initiated a reconnect from the same port";
632 break;
633 case -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD):
634 error_description = "SSL - Record header looks valid but is not expected";
635 break;
636 case -(MBEDTLS_ERR_SSL_NON_FATAL):
637 error_description = "SSL - The alert message received indicates a non-fatal error";
638 break;
639 case -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH):
640 error_description = "SSL - Couldn't set the hash for verifying CertificateVerify";
641 break;
642 case -(MBEDTLS_ERR_SSL_CONTINUE_PROCESSING):
643 error_description = "SSL - Internal-only message signaling that further message-processing should be done";
644 break;
645 case -(MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS):
646 error_description = "SSL - The asynchronous operation is not completed yet";
647 break;
648 case -(MBEDTLS_ERR_SSL_EARLY_MESSAGE):
649 error_description = "SSL - Internal-only message signaling that a message arrived early";
650 break;
651 case -(MBEDTLS_ERR_SSL_UNEXPECTED_CID):
652 error_description = "SSL - An encrypted DTLS-frame with an unexpected CID was received";
653 break;
654 case -(MBEDTLS_ERR_SSL_VERSION_MISMATCH):
655 error_description = "SSL - An operation failed due to an unexpected version or configuration";
656 break;
657 case -(MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS):
658 error_description = "SSL - A cryptographic operation is in progress. Try again later";
659 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700660#endif /* MBEDTLS_SSL_TLS_C */
661
662#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700663 case -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE):
664 error_description = "X509 - Unavailable feature, e.g. RSA hashing/encryption combination";
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700665 break;
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700666 case -(MBEDTLS_ERR_X509_UNKNOWN_OID):
667 error_description = "X509 - Requested OID is unknown";
668 break;
669 case -(MBEDTLS_ERR_X509_INVALID_FORMAT):
670 error_description = "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected";
671 break;
672 case -(MBEDTLS_ERR_X509_INVALID_VERSION):
673 error_description = "X509 - The CRT/CRL/CSR version element is invalid";
674 break;
675 case -(MBEDTLS_ERR_X509_INVALID_SERIAL):
676 error_description = "X509 - The serial tag or value is invalid";
677 break;
678 case -(MBEDTLS_ERR_X509_INVALID_ALG):
679 error_description = "X509 - The algorithm tag or value is invalid";
680 break;
681 case -(MBEDTLS_ERR_X509_INVALID_NAME):
682 error_description = "X509 - The name tag or value is invalid";
683 break;
684 case -(MBEDTLS_ERR_X509_INVALID_DATE):
685 error_description = "X509 - The date tag or value is invalid";
686 break;
687 case -(MBEDTLS_ERR_X509_INVALID_SIGNATURE):
688 error_description = "X509 - The signature tag or value invalid";
689 break;
690 case -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS):
691 error_description = "X509 - The extension tag or value is invalid";
692 break;
693 case -(MBEDTLS_ERR_X509_UNKNOWN_VERSION):
694 error_description = "X509 - CRT/CRL/CSR has an unsupported version number";
695 break;
696 case -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG):
697 error_description = "X509 - Signature algorithm (oid) is unsupported";
698 break;
699 case -(MBEDTLS_ERR_X509_SIG_MISMATCH):
700 error_description = "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)";
701 break;
702 case -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED):
703 error_description = "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed";
704 break;
705 case -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT):
706 error_description = "X509 - Format not recognized as DER or PEM";
707 break;
708 case -(MBEDTLS_ERR_X509_BAD_INPUT_DATA):
709 error_description = "X509 - Input invalid";
710 break;
711 case -(MBEDTLS_ERR_X509_ALLOC_FAILED):
712 error_description = "X509 - Allocation of memory failed";
713 break;
714 case -(MBEDTLS_ERR_X509_FILE_IO_ERROR):
715 error_description = "X509 - Read/write of file failed";
716 break;
717 case -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL):
718 error_description = "X509 - Destination buffer is too small";
719 break;
720 case -(MBEDTLS_ERR_X509_FATAL_ERROR):
721 error_description = "X509 - A fatal error occurred, eg the chain is too long or the vrfy callback failed";
722 break;
723#endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
Gaurav Aggarwal3d02db22020-04-11 17:14:03 -0700724 /* End Auto-Generated Code. */
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700725
726 default:
727 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700728 }
729
730 return error_description;
731}
732
733const char * mbedtls_low_level_strerr( int error_code )
734{
Gaurav Aggarwal6ea4fc72020-04-20 16:03:46 -0700735 int low_level_error_code;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700736 const char *error_description = NULL;
737
Gaurav Aggarwal6ea4fc72020-04-20 16:03:46 -0700738 if( error_code < 0 )
739 error_code = -error_code;
740
741 /* Extract the low-level part from the error code. */
742 low_level_error_code = error_code & ~0xFF80;
743
744 switch( low_level_error_code )
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700745 {
Gaurav Aggarwal3d02db22020-04-11 17:14:03 -0700746 /* Begin Auto-Generated Code. */
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700747#if defined(MBEDTLS_AES_C)
748 case -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH):
749 error_description = "AES - Invalid key length";
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700750 break;
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700751 case -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH):
752 error_description = "AES - Invalid data input length";
753 break;
754 case -(MBEDTLS_ERR_AES_BAD_INPUT_DATA):
755 error_description = "AES - Invalid input data";
756 break;
757 case -(MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE):
758 error_description = "AES - Feature not available. For example, an unsupported AES key size";
759 break;
760 case -(MBEDTLS_ERR_AES_HW_ACCEL_FAILED):
761 error_description = "AES - AES hardware accelerator failed";
762 break;
763#endif /* MBEDTLS_AES_C */
764
765#if defined(MBEDTLS_ARC4_C)
766 case -(MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED):
767 error_description = "ARC4 - ARC4 hardware accelerator failed";
768 break;
769#endif /* MBEDTLS_ARC4_C */
770
771#if defined(MBEDTLS_ARIA_C)
772 case -(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA):
773 error_description = "ARIA - Bad input data";
774 break;
775 case -(MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH):
776 error_description = "ARIA - Invalid data input length";
777 break;
778 case -(MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE):
779 error_description = "ARIA - Feature not available. For example, an unsupported ARIA key size";
780 break;
781 case -(MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED):
782 error_description = "ARIA - ARIA hardware accelerator failed";
783 break;
784#endif /* MBEDTLS_ARIA_C */
785
786#if defined(MBEDTLS_ASN1_PARSE_C)
787 case -(MBEDTLS_ERR_ASN1_OUT_OF_DATA):
788 error_description = "ASN1 - Out of data when parsing an ASN1 data structure";
789 break;
790 case -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG):
791 error_description = "ASN1 - ASN1 tag was of an unexpected value";
792 break;
793 case -(MBEDTLS_ERR_ASN1_INVALID_LENGTH):
794 error_description = "ASN1 - Error when trying to determine the length or invalid length";
795 break;
796 case -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH):
797 error_description = "ASN1 - Actual length differs from expected length";
798 break;
799 case -(MBEDTLS_ERR_ASN1_INVALID_DATA):
800 error_description = "ASN1 - Data is invalid";
801 break;
802 case -(MBEDTLS_ERR_ASN1_ALLOC_FAILED):
803 error_description = "ASN1 - Memory allocation failed";
804 break;
805 case -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL):
806 error_description = "ASN1 - Buffer too small when writing ASN.1 data structure";
807 break;
808#endif /* MBEDTLS_ASN1_PARSE_C */
809
810#if defined(MBEDTLS_BASE64_C)
811 case -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL):
812 error_description = "BASE64 - Output buffer too small";
813 break;
814 case -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER):
815 error_description = "BASE64 - Invalid character in input";
816 break;
817#endif /* MBEDTLS_BASE64_C */
818
819#if defined(MBEDTLS_BIGNUM_C)
820 case -(MBEDTLS_ERR_MPI_FILE_IO_ERROR):
821 error_description = "BIGNUM - An error occurred while reading from or writing to a file";
822 break;
823 case -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA):
824 error_description = "BIGNUM - Bad input parameters to function";
825 break;
826 case -(MBEDTLS_ERR_MPI_INVALID_CHARACTER):
827 error_description = "BIGNUM - There is an invalid character in the digit string";
828 break;
829 case -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL):
830 error_description = "BIGNUM - The buffer is too small to write to";
831 break;
832 case -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE):
833 error_description = "BIGNUM - The input arguments are negative or result in illegal output";
834 break;
835 case -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO):
836 error_description = "BIGNUM - The input argument for division is zero, which is not allowed";
837 break;
838 case -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE):
839 error_description = "BIGNUM - The input arguments are not acceptable";
840 break;
841 case -(MBEDTLS_ERR_MPI_ALLOC_FAILED):
842 error_description = "BIGNUM - Memory allocation failed";
843 break;
844#endif /* MBEDTLS_BIGNUM_C */
845
846#if defined(MBEDTLS_BLOWFISH_C)
847 case -(MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA):
848 error_description = "BLOWFISH - Bad input data";
849 break;
850 case -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH):
851 error_description = "BLOWFISH - Invalid data input length";
852 break;
853 case -(MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED):
854 error_description = "BLOWFISH - Blowfish hardware accelerator failed";
855 break;
856#endif /* MBEDTLS_BLOWFISH_C */
857
858#if defined(MBEDTLS_CAMELLIA_C)
859 case -(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA):
860 error_description = "CAMELLIA - Bad input data";
861 break;
862 case -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH):
863 error_description = "CAMELLIA - Invalid data input length";
864 break;
865 case -(MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED):
866 error_description = "CAMELLIA - Camellia hardware accelerator failed";
867 break;
868#endif /* MBEDTLS_CAMELLIA_C */
869
870#if defined(MBEDTLS_CCM_C)
871 case -(MBEDTLS_ERR_CCM_BAD_INPUT):
872 error_description = "CCM - Bad input parameters to the function";
873 break;
874 case -(MBEDTLS_ERR_CCM_AUTH_FAILED):
875 error_description = "CCM - Authenticated decryption failed";
876 break;
877 case -(MBEDTLS_ERR_CCM_HW_ACCEL_FAILED):
878 error_description = "CCM - CCM hardware accelerator failed";
879 break;
880#endif /* MBEDTLS_CCM_C */
881
882#if defined(MBEDTLS_CHACHA20_C)
883 case -(MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA):
884 error_description = "CHACHA20 - Invalid input parameter(s)";
885 break;
886 case -(MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE):
887 error_description = "CHACHA20 - Feature not available. For example, s part of the API is not implemented";
888 break;
889 case -(MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED):
890 error_description = "CHACHA20 - Chacha20 hardware accelerator failed";
891 break;
892#endif /* MBEDTLS_CHACHA20_C */
893
894#if defined(MBEDTLS_CHACHAPOLY_C)
895 case -(MBEDTLS_ERR_CHACHAPOLY_BAD_STATE):
896 error_description = "CHACHAPOLY - The requested operation is not permitted in the current state";
897 break;
898 case -(MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED):
899 error_description = "CHACHAPOLY - Authenticated decryption failed: data was not authentic";
900 break;
901#endif /* MBEDTLS_CHACHAPOLY_C */
902
903#if defined(MBEDTLS_CMAC_C)
904 case -(MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED):
905 error_description = "CMAC - CMAC hardware accelerator failed";
906 break;
907#endif /* MBEDTLS_CMAC_C */
908
909#if defined(MBEDTLS_CTR_DRBG_C)
910 case -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED):
911 error_description = "CTR_DRBG - The entropy source failed";
912 break;
913 case -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG):
914 error_description = "CTR_DRBG - The requested random buffer length is too big";
915 break;
916 case -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG):
917 error_description = "CTR_DRBG - The input (entropy + additional data) is too large";
918 break;
919 case -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR):
920 error_description = "CTR_DRBG - Read or write error in file";
921 break;
922#endif /* MBEDTLS_CTR_DRBG_C */
923
924#if defined(MBEDTLS_DES_C)
925 case -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH):
926 error_description = "DES - The data input has an invalid length";
927 break;
928 case -(MBEDTLS_ERR_DES_HW_ACCEL_FAILED):
929 error_description = "DES - DES hardware accelerator failed";
930 break;
931#endif /* MBEDTLS_DES_C */
932
933#if defined(MBEDTLS_ENTROPY_C)
934 case -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED):
935 error_description = "ENTROPY - Critical entropy source failure";
936 break;
937 case -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES):
938 error_description = "ENTROPY - No more sources can be added";
939 break;
940 case -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED):
941 error_description = "ENTROPY - No sources have been added to poll";
942 break;
943 case -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE):
944 error_description = "ENTROPY - No strong sources have been added to poll";
945 break;
946 case -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR):
947 error_description = "ENTROPY - Read/write error in file";
948 break;
949#endif /* MBEDTLS_ENTROPY_C */
950
951#if defined(MBEDTLS_ERROR_C)
952 case -(MBEDTLS_ERR_ERROR_GENERIC_ERROR):
953 error_description = "ERROR - Generic error";
954 break;
955 case -(MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED):
956 error_description = "ERROR - This is a bug in the library";
957 break;
958#endif /* MBEDTLS_ERROR_C */
959
960#if defined(MBEDTLS_GCM_C)
961 case -(MBEDTLS_ERR_GCM_AUTH_FAILED):
962 error_description = "GCM - Authenticated decryption failed";
963 break;
964 case -(MBEDTLS_ERR_GCM_HW_ACCEL_FAILED):
965 error_description = "GCM - GCM hardware accelerator failed";
966 break;
967 case -(MBEDTLS_ERR_GCM_BAD_INPUT):
968 error_description = "GCM - Bad input parameters to function";
969 break;
970#endif /* MBEDTLS_GCM_C */
971
972#if defined(MBEDTLS_HKDF_C)
973 case -(MBEDTLS_ERR_HKDF_BAD_INPUT_DATA):
974 error_description = "HKDF - Bad input parameters to function";
975 break;
976#endif /* MBEDTLS_HKDF_C */
977
978#if defined(MBEDTLS_HMAC_DRBG_C)
979 case -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG):
980 error_description = "HMAC_DRBG - Too many random requested in single call";
981 break;
982 case -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG):
983 error_description = "HMAC_DRBG - Input too large (Entropy + additional)";
984 break;
985 case -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR):
986 error_description = "HMAC_DRBG - Read/write error in file";
987 break;
988 case -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED):
989 error_description = "HMAC_DRBG - The entropy source failed";
990 break;
991#endif /* MBEDTLS_HMAC_DRBG_C */
992
993#if defined(MBEDTLS_MD2_C)
994 case -(MBEDTLS_ERR_MD2_HW_ACCEL_FAILED):
995 error_description = "MD2 - MD2 hardware accelerator failed";
996 break;
997#endif /* MBEDTLS_MD2_C */
998
999#if defined(MBEDTLS_MD4_C)
1000 case -(MBEDTLS_ERR_MD4_HW_ACCEL_FAILED):
1001 error_description = "MD4 - MD4 hardware accelerator failed";
1002 break;
1003#endif /* MBEDTLS_MD4_C */
1004
1005#if defined(MBEDTLS_MD5_C)
1006 case -(MBEDTLS_ERR_MD5_HW_ACCEL_FAILED):
1007 error_description = "MD5 - MD5 hardware accelerator failed";
1008 break;
1009#endif /* MBEDTLS_MD5_C */
1010
1011#if defined(MBEDTLS_NET_C)
1012 case -(MBEDTLS_ERR_NET_SOCKET_FAILED):
1013 error_description = "NET - Failed to open a socket";
1014 break;
1015 case -(MBEDTLS_ERR_NET_CONNECT_FAILED):
1016 error_description = "NET - The connection to the given server / port failed";
1017 break;
1018 case -(MBEDTLS_ERR_NET_BIND_FAILED):
1019 error_description = "NET - Binding of the socket failed";
1020 break;
1021 case -(MBEDTLS_ERR_NET_LISTEN_FAILED):
1022 error_description = "NET - Could not listen on the socket";
1023 break;
1024 case -(MBEDTLS_ERR_NET_ACCEPT_FAILED):
1025 error_description = "NET - Could not accept the incoming connection";
1026 break;
1027 case -(MBEDTLS_ERR_NET_RECV_FAILED):
1028 error_description = "NET - Reading information from the socket failed";
1029 break;
1030 case -(MBEDTLS_ERR_NET_SEND_FAILED):
1031 error_description = "NET - Sending information through the socket failed";
1032 break;
1033 case -(MBEDTLS_ERR_NET_CONN_RESET):
1034 error_description = "NET - Connection was reset by peer";
1035 break;
1036 case -(MBEDTLS_ERR_NET_UNKNOWN_HOST):
1037 error_description = "NET - Failed to get an IP address for the given hostname";
1038 break;
1039 case -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL):
1040 error_description = "NET - Buffer is too small to hold the data";
1041 break;
1042 case -(MBEDTLS_ERR_NET_INVALID_CONTEXT):
1043 error_description = "NET - The context is invalid, eg because it was free()ed";
1044 break;
1045 case -(MBEDTLS_ERR_NET_POLL_FAILED):
1046 error_description = "NET - Polling the net context failed";
1047 break;
1048 case -(MBEDTLS_ERR_NET_BAD_INPUT_DATA):
1049 error_description = "NET - Input invalid";
1050 break;
1051#endif /* MBEDTLS_NET_C */
1052
1053#if defined(MBEDTLS_OID_C)
1054 case -(MBEDTLS_ERR_OID_NOT_FOUND):
1055 error_description = "OID - OID is not found";
1056 break;
1057 case -(MBEDTLS_ERR_OID_BUF_TOO_SMALL):
1058 error_description = "OID - output buffer is too small";
1059 break;
1060#endif /* MBEDTLS_OID_C */
1061
1062#if defined(MBEDTLS_PADLOCK_C)
1063 case -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED):
1064 error_description = "PADLOCK - Input data should be aligned";
1065 break;
1066#endif /* MBEDTLS_PADLOCK_C */
1067
1068#if defined(MBEDTLS_PLATFORM_C)
1069 case -(MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED):
1070 error_description = "PLATFORM - Hardware accelerator failed";
1071 break;
1072 case -(MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED):
1073 error_description = "PLATFORM - The requested feature is not supported by the platform";
1074 break;
1075#endif /* MBEDTLS_PLATFORM_C */
1076
1077#if defined(MBEDTLS_POLY1305_C)
1078 case -(MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA):
1079 error_description = "POLY1305 - Invalid input parameter(s)";
1080 break;
1081 case -(MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE):
1082 error_description = "POLY1305 - Feature not available. For example, s part of the API is not implemented";
1083 break;
1084 case -(MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED):
1085 error_description = "POLY1305 - Poly1305 hardware accelerator failed";
1086 break;
1087#endif /* MBEDTLS_POLY1305_C */
1088
1089#if defined(MBEDTLS_RIPEMD160_C)
1090 case -(MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED):
1091 error_description = "RIPEMD160 - RIPEMD160 hardware accelerator failed";
1092 break;
1093#endif /* MBEDTLS_RIPEMD160_C */
1094
1095#if defined(MBEDTLS_SHA1_C)
1096 case -(MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED):
1097 error_description = "SHA1 - SHA-1 hardware accelerator failed";
1098 break;
1099 case -(MBEDTLS_ERR_SHA1_BAD_INPUT_DATA):
1100 error_description = "SHA1 - SHA-1 input data was malformed";
1101 break;
1102#endif /* MBEDTLS_SHA1_C */
1103
1104#if defined(MBEDTLS_SHA256_C)
1105 case -(MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED):
1106 error_description = "SHA256 - SHA-256 hardware accelerator failed";
1107 break;
1108 case -(MBEDTLS_ERR_SHA256_BAD_INPUT_DATA):
1109 error_description = "SHA256 - SHA-256 input data was malformed";
1110 break;
1111#endif /* MBEDTLS_SHA256_C */
1112
1113#if defined(MBEDTLS_SHA512_C)
1114 case -(MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED):
1115 error_description = "SHA512 - SHA-512 hardware accelerator failed";
1116 break;
1117 case -(MBEDTLS_ERR_SHA512_BAD_INPUT_DATA):
1118 error_description = "SHA512 - SHA-512 input data was malformed";
1119 break;
1120#endif /* MBEDTLS_SHA512_C */
1121
1122#if defined(MBEDTLS_THREADING_C)
1123 case -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE):
1124 error_description = "THREADING - The selected feature is not available";
1125 break;
1126 case -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA):
1127 error_description = "THREADING - Bad input parameters to function";
1128 break;
1129 case -(MBEDTLS_ERR_THREADING_MUTEX_ERROR):
1130 error_description = "THREADING - Locking / unlocking / free failed with error code";
1131 break;
1132#endif /* MBEDTLS_THREADING_C */
1133
1134#if defined(MBEDTLS_XTEA_C)
1135 case -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH):
1136 error_description = "XTEA - The data input has an invalid length";
1137 break;
1138 case -(MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED):
1139 error_description = "XTEA - XTEA hardware accelerator failed";
1140 break;
1141#endif /* MBEDTLS_XTEA_C */
Gaurav Aggarwal3d02db22020-04-11 17:14:03 -07001142 /* End Auto-Generated Code. */
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -07001143
1144 default:
1145 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -07001146 }
1147
1148 return error_description;
1149}
1150
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001151void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker9d781402011-05-09 16:17:09 +00001152{
1153 size_t len;
1154 int use_ret;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -07001155 const char * high_level_error_description = NULL;
1156 const char * low_level_error_description = NULL;
Paul Bakker9d781402011-05-09 16:17:09 +00001157
Paul Bakkerb9cfaa02013-10-11 18:58:55 +02001158 if( buflen == 0 )
1159 return;
1160
Paul Bakker9d781402011-05-09 16:17:09 +00001161 memset( buf, 0x00, buflen );
Paul Bakkerb9cfaa02013-10-11 18:58:55 +02001162
Paul Bakker9d781402011-05-09 16:17:09 +00001163 if( ret < 0 )
1164 ret = -ret;
1165
1166 if( ret & 0xFF80 )
1167 {
1168 use_ret = ret & 0xFF80;
1169
Gaurav Aggarwala9f64002020-04-09 01:44:52 -07001170 // Translate high level error code.
Gaurav Aggarwal6ea4fc72020-04-20 16:03:46 -07001171 high_level_error_description = mbedtls_high_level_strerr( ret );
Paul Bakkerff61a782011-06-09 15:42:02 +00001172
Gaurav Aggarwala9f64002020-04-09 01:44:52 -07001173 if( high_level_error_description == NULL )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001174 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Gaurav Aggarwala9f64002020-04-09 01:44:52 -07001175 else
1176 mbedtls_snprintf( buf, buflen, "%s", high_level_error_description );
1177
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -07001178#if defined(MBEDTLS_SSL_TLS_C)
Gaurav Aggarwala9f64002020-04-09 01:44:52 -07001179 // Early return in case of a fatal error - do not try to translate low
1180 // level code.
1181 if(use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE))
1182 return;
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -07001183#endif /* MBEDTLS_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +00001184 }
1185
1186 use_ret = ret & ~0xFF80;
1187
1188 if( use_ret == 0 )
1189 return;
1190
1191 // If high level code is present, make a concatenation between both
1192 // error strings.
1193 //
1194 len = strlen( buf );
1195
1196 if( len > 0 )
1197 {
1198 if( buflen - len < 5 )
1199 return;
1200
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001201 mbedtls_snprintf( buf + len, buflen - len, " : " );
Paul Bakker9d781402011-05-09 16:17:09 +00001202
1203 buf += len + 3;
1204 buflen -= len + 3;
1205 }
1206
Gaurav Aggarwala9f64002020-04-09 01:44:52 -07001207 // Translate low level error code.
Gaurav Aggarwal6ea4fc72020-04-20 16:03:46 -07001208 low_level_error_description = mbedtls_low_level_strerr( ret );
Paul Bakker9d781402011-05-09 16:17:09 +00001209
Gaurav Aggarwala9f64002020-04-09 01:44:52 -07001210 if( low_level_error_description == NULL )
1211 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
1212 else
1213 mbedtls_snprintf( buf, buflen, "%s", low_level_error_description );
Paul Bakker9d781402011-05-09 16:17:09 +00001214}
1215
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001216#else /* MBEDTLS_ERROR_C */
Paul Bakker8fe40dc2013-02-02 12:43:08 +01001217
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001218#if defined(MBEDTLS_ERROR_STRERROR_DUMMY)
Paul Bakker8fe40dc2013-02-02 12:43:08 +01001219
Paul Bakker8fe40dc2013-02-02 12:43:08 +01001220/*
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001221 * Provide an non-function in case MBEDTLS_ERROR_C is not defined
Paul Bakker8fe40dc2013-02-02 12:43:08 +01001222 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001223void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker8fe40dc2013-02-02 12:43:08 +01001224{
1225 ((void) ret);
1226
1227 if( buflen > 0 )
1228 buf[0] = '\0';
1229}
1230
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001231#endif /* MBEDTLS_ERROR_STRERROR_DUMMY */
Paul Bakkere2ab84f2013-06-29 18:24:32 +02001232
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001233#endif /* MBEDTLS_ERROR_C */