blob: 200e579778dba0fa024eacd31036b0e1f3b4765f [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 Aggarwala4a2aa52020-04-09 11:39:04 -0700218 const char *error_description = NULL;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700219
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700220 switch( error_code )
221 {
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700222#if defined(MBEDTLS_CIPHER_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700223 case -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE):
224 error_description = "CIPHER - The selected feature is not available";
225 break;
226 case -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA):
227 error_description = "CIPHER - Bad input parameters";
228 break;
229 case -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED):
230 error_description = "CIPHER - Failed to allocate memory";
231 break;
232 case -(MBEDTLS_ERR_CIPHER_INVALID_PADDING):
233 error_description = "CIPHER - Input data contains invalid padding and is rejected";
234 break;
235 case -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED):
236 error_description = "CIPHER - Decryption of block requires a full block";
237 break;
238 case -(MBEDTLS_ERR_CIPHER_AUTH_FAILED):
239 error_description = "CIPHER - Authentication failed (for AEAD modes)";
240 break;
241 case -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT):
242 error_description = "CIPHER - The context is invalid. For example, because it was freed";
243 break;
244 case -(MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED):
245 error_description = "CIPHER - Cipher hardware accelerator failed";
246 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700247#endif /* MBEDTLS_CIPHER_C */
248
249#if defined(MBEDTLS_DHM_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700250 case -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA):
251 error_description = "DHM - Bad input parameters";
252 break;
253 case -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED):
254 error_description = "DHM - Reading of the DHM parameters failed";
255 break;
256 case -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED):
257 error_description = "DHM - Making of the DHM parameters failed";
258 break;
259 case -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED):
260 error_description = "DHM - Reading of the public values failed";
261 break;
262 case -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED):
263 error_description = "DHM - Making of the public value failed";
264 break;
265 case -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED):
266 error_description = "DHM - Calculation of the DHM secret failed";
267 break;
268 case -(MBEDTLS_ERR_DHM_INVALID_FORMAT):
269 error_description = "DHM - The ASN.1 data is not formatted correctly";
270 break;
271 case -(MBEDTLS_ERR_DHM_ALLOC_FAILED):
272 error_description = "DHM - Allocation of memory failed";
273 break;
274 case -(MBEDTLS_ERR_DHM_FILE_IO_ERROR):
275 error_description = "DHM - Read or write of file failed";
276 break;
277 case -(MBEDTLS_ERR_DHM_HW_ACCEL_FAILED):
278 error_description = "DHM - DHM hardware accelerator failed";
279 break;
280 case -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED):
281 error_description = "DHM - Setting the modulus and generator failed";
282 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700283#endif /* MBEDTLS_DHM_C */
284
285#if defined(MBEDTLS_ECP_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700286 case -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA):
287 error_description = "ECP - Bad input parameters to function";
288 break;
289 case -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL):
290 error_description = "ECP - The buffer is too small to write to";
291 break;
292 case -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE):
293 error_description = "ECP - The requested feature is not available, for example, the requested curve is not supported";
294 break;
295 case -(MBEDTLS_ERR_ECP_VERIFY_FAILED):
296 error_description = "ECP - The signature is not valid";
297 break;
298 case -(MBEDTLS_ERR_ECP_ALLOC_FAILED):
299 error_description = "ECP - Memory allocation failed";
300 break;
301 case -(MBEDTLS_ERR_ECP_RANDOM_FAILED):
302 error_description = "ECP - Generation of random value, such as ephemeral key, failed";
303 break;
304 case -(MBEDTLS_ERR_ECP_INVALID_KEY):
305 error_description = "ECP - Invalid private or public key";
306 break;
307 case -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH):
308 error_description = "ECP - The buffer contains a valid signature followed by more data";
309 break;
310 case -(MBEDTLS_ERR_ECP_HW_ACCEL_FAILED):
311 error_description = "ECP - The ECP hardware accelerator failed";
312 break;
313 case -(MBEDTLS_ERR_ECP_IN_PROGRESS):
314 error_description = "ECP - Operation in progress, call again with the same parameters to continue";
315 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700316#endif /* MBEDTLS_ECP_C */
317
318#if defined(MBEDTLS_MD_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700319 case -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE):
320 error_description = "MD - The selected feature is not available";
321 break;
322 case -(MBEDTLS_ERR_MD_BAD_INPUT_DATA):
323 error_description = "MD - Bad input parameters to function";
324 break;
325 case -(MBEDTLS_ERR_MD_ALLOC_FAILED):
326 error_description = "MD - Failed to allocate memory";
327 break;
328 case -(MBEDTLS_ERR_MD_FILE_IO_ERROR):
329 error_description = "MD - Opening or reading of file failed";
330 break;
331 case -(MBEDTLS_ERR_MD_HW_ACCEL_FAILED):
332 error_description = "MD - MD hardware accelerator failed";
333 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700334#endif /* MBEDTLS_MD_C */
335
336#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700337 case -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT):
338 error_description = "PEM - No PEM header or footer found";
339 break;
340 case -(MBEDTLS_ERR_PEM_INVALID_DATA):
341 error_description = "PEM - PEM string is not as expected";
342 break;
343 case -(MBEDTLS_ERR_PEM_ALLOC_FAILED):
344 error_description = "PEM - Failed to allocate memory";
345 break;
346 case -(MBEDTLS_ERR_PEM_INVALID_ENC_IV):
347 error_description = "PEM - RSA IV is not in hex-format";
348 break;
349 case -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG):
350 error_description = "PEM - Unsupported key encryption algorithm";
351 break;
352 case -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED):
353 error_description = "PEM - Private key password can't be empty";
354 break;
355 case -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH):
356 error_description = "PEM - Given private key password does not allow for correct decryption";
357 break;
358 case -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE):
359 error_description = "PEM - Unavailable feature, e.g. hashing/encryption combination";
360 break;
361 case -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA):
362 error_description = "PEM - Bad input parameters to function";
363 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700364#endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
365
366#if defined(MBEDTLS_PK_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700367 case -(MBEDTLS_ERR_PK_ALLOC_FAILED):
368 error_description = "PK - Memory allocation failed";
369 break;
370 case -(MBEDTLS_ERR_PK_TYPE_MISMATCH):
371 error_description = "PK - Type mismatch, eg attempt to encrypt with an ECDSA key";
372 break;
373 case -(MBEDTLS_ERR_PK_BAD_INPUT_DATA):
374 error_description = "PK - Bad input parameters to function";
375 break;
376 case -(MBEDTLS_ERR_PK_FILE_IO_ERROR):
377 error_description = "PK - Read/write of file failed";
378 break;
379 case -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION):
380 error_description = "PK - Unsupported key version";
381 break;
382 case -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT):
383 error_description = "PK - Invalid key tag or value";
384 break;
385 case -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG):
386 error_description = "PK - Key algorithm is unsupported (only RSA and EC are supported)";
387 break;
388 case -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED):
389 error_description = "PK - Private key password can't be empty";
390 break;
391 case -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH):
392 error_description = "PK - Given private key password does not allow for correct decryption";
393 break;
394 case -(MBEDTLS_ERR_PK_INVALID_PUBKEY):
395 error_description = "PK - The pubkey tag or value is invalid (only RSA and EC are supported)";
396 break;
397 case -(MBEDTLS_ERR_PK_INVALID_ALG):
398 error_description = "PK - The algorithm tag or value is invalid";
399 break;
400 case -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE):
401 error_description = "PK - Elliptic curve is unsupported (only NIST curves are supported)";
402 break;
403 case -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE):
404 error_description = "PK - Unavailable feature, e.g. RSA disabled for RSA key";
405 break;
406 case -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH):
407 error_description = "PK - The buffer contains a valid signature followed by more data";
408 break;
409 case -(MBEDTLS_ERR_PK_HW_ACCEL_FAILED):
410 error_description = "PK - PK hardware accelerator failed";
411 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700412#endif /* MBEDTLS_PK_C */
413
414#if defined(MBEDTLS_PKCS12_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700415 case -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA):
416 error_description = "PKCS12 - Bad input parameters to function";
417 break;
418 case -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE):
419 error_description = "PKCS12 - Feature not available, e.g. unsupported encryption scheme";
420 break;
421 case -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT):
422 error_description = "PKCS12 - PBE ASN.1 data not as expected";
423 break;
424 case -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH):
425 error_description = "PKCS12 - Given private key password does not allow for correct decryption";
426 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700427#endif /* MBEDTLS_PKCS12_C */
428
429#if defined(MBEDTLS_PKCS5_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700430 case -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA):
431 error_description = "PKCS5 - Bad input parameters to function";
432 break;
433 case -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT):
434 error_description = "PKCS5 - Unexpected ASN.1 data";
435 break;
436 case -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE):
437 error_description = "PKCS5 - Requested encryption or digest alg not available";
438 break;
439 case -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH):
440 error_description = "PKCS5 - Given private key password does not allow for correct decryption";
441 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700442#endif /* MBEDTLS_PKCS5_C */
443
444#if defined(MBEDTLS_RSA_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700445 case -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA):
446 error_description = "RSA - Bad input parameters to function";
447 break;
448 case -(MBEDTLS_ERR_RSA_INVALID_PADDING):
449 error_description = "RSA - Input data contains invalid padding and is rejected";
450 break;
451 case -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED):
452 error_description = "RSA - Something failed during generation of a key";
453 break;
454 case -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED):
455 error_description = "RSA - Key failed to pass the validity check of the library";
456 break;
457 case -(MBEDTLS_ERR_RSA_PUBLIC_FAILED):
458 error_description = "RSA - The public key operation failed";
459 break;
460 case -(MBEDTLS_ERR_RSA_PRIVATE_FAILED):
461 error_description = "RSA - The private key operation failed";
462 break;
463 case -(MBEDTLS_ERR_RSA_VERIFY_FAILED):
464 error_description = "RSA - The PKCS#1 verification failed";
465 break;
466 case -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE):
467 error_description = "RSA - The output buffer for decryption is not large enough";
468 break;
469 case -(MBEDTLS_ERR_RSA_RNG_FAILED):
470 error_description = "RSA - The random generator failed to generate non-zeros";
471 break;
472 case -(MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION):
473 error_description = "RSA - The implementation does not offer the requested operation, for example, because of security violations or lack of functionality";
474 break;
475 case -(MBEDTLS_ERR_RSA_HW_ACCEL_FAILED):
476 error_description = "RSA - RSA hardware accelerator failed";
477 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700478#endif /* MBEDTLS_RSA_C */
479
480#if defined(MBEDTLS_SSL_TLS_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700481 case -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE):
482 error_description = "SSL - The requested feature is not available";
483 break;
484 case -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA):
485 error_description = "SSL - Bad input parameters to function";
486 break;
487 case -(MBEDTLS_ERR_SSL_INVALID_MAC):
488 error_description = "SSL - Verification of the message MAC failed";
489 break;
490 case -(MBEDTLS_ERR_SSL_INVALID_RECORD):
491 error_description = "SSL - An invalid SSL record was received";
492 break;
493 case -(MBEDTLS_ERR_SSL_CONN_EOF):
494 error_description = "SSL - The connection indicated an EOF";
495 break;
496 case -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER):
497 error_description = "SSL - An unknown cipher was received";
498 break;
499 case -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN):
500 error_description = "SSL - The server has no ciphersuites in common with the client";
501 break;
502 case -(MBEDTLS_ERR_SSL_NO_RNG):
503 error_description = "SSL - No RNG was provided to the SSL module";
504 break;
505 case -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE):
506 error_description = "SSL - No client certification received from the client, but required by the authentication mode";
507 break;
508 case -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE):
509 error_description = "SSL - Our own certificate(s) is/are too large to send in an SSL message";
510 break;
511 case -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED):
512 error_description = "SSL - The own certificate is not set, but needed by the server";
513 break;
514 case -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED):
515 error_description = "SSL - The own private key or pre-shared key is not set, but needed";
516 break;
517 case -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED):
518 error_description = "SSL - No CA Chain is set, but required to operate";
519 break;
520 case -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE):
521 error_description = "SSL - An unexpected message was received from our peer";
522 break;
523 case -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE):
524 error_description = "SSL - A fatal alert message was received from our peer";
525 break;
526 case -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED):
527 error_description = "SSL - Verification of our peer failed";
528 break;
529 case -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY):
530 error_description = "SSL - The peer notified us that the connection is going to be closed";
531 break;
532 case -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO):
533 error_description = "SSL - Processing of the ClientHello handshake message failed";
534 break;
535 case -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO):
536 error_description = "SSL - Processing of the ServerHello handshake message failed";
537 break;
538 case -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE):
539 error_description = "SSL - Processing of the Certificate handshake message failed";
540 break;
541 case -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST):
542 error_description = "SSL - Processing of the CertificateRequest handshake message failed";
543 break;
544 case -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE):
545 error_description = "SSL - Processing of the ServerKeyExchange handshake message failed";
546 break;
547 case -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE):
548 error_description = "SSL - Processing of the ServerHelloDone handshake message failed";
549 break;
550 case -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE):
551 error_description = "SSL - Processing of the ClientKeyExchange handshake message failed";
552 break;
553 case -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP):
554 error_description = "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public";
555 break;
556 case -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS):
557 error_description = "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret";
558 break;
559 case -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY):
560 error_description = "SSL - Processing of the CertificateVerify handshake message failed";
561 break;
562 case -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC):
563 error_description = "SSL - Processing of the ChangeCipherSpec handshake message failed";
564 break;
565 case -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED):
566 error_description = "SSL - Processing of the Finished handshake message failed";
567 break;
568 case -(MBEDTLS_ERR_SSL_ALLOC_FAILED):
569 error_description = "SSL - Memory allocation failed";
570 break;
571 case -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED):
572 error_description = "SSL - Hardware acceleration function returned with error";
573 break;
574 case -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH):
575 error_description = "SSL - Hardware acceleration function skipped / left alone data";
576 break;
577 case -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED):
578 error_description = "SSL - Processing of the compression / decompression failed";
579 break;
580 case -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION):
581 error_description = "SSL - Handshake protocol not within min/max boundaries";
582 break;
583 case -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET):
584 error_description = "SSL - Processing of the NewSessionTicket handshake message failed";
585 break;
586 case -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED):
587 error_description = "SSL - Session ticket has expired";
588 break;
589 case -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH):
590 error_description = "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)";
591 break;
592 case -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY):
593 error_description = "SSL - Unknown identity received (eg, PSK identity)";
594 break;
595 case -(MBEDTLS_ERR_SSL_INTERNAL_ERROR):
596 error_description = "SSL - Internal error (eg, unexpected failure in lower-level module)";
597 break;
598 case -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING):
599 error_description = "SSL - A counter would wrap (eg, too many messages exchanged)";
600 break;
601 case -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO):
602 error_description = "SSL - Unexpected message at ServerHello in renegotiation";
603 break;
604 case -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED):
605 error_description = "SSL - DTLS client must retry for hello verification";
606 break;
607 case -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL):
608 error_description = "SSL - A buffer is too small to receive or write a message";
609 break;
610 case -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE):
611 error_description = "SSL - None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages)";
612 break;
613 case -(MBEDTLS_ERR_SSL_WANT_READ):
614 error_description = "SSL - No data of requested type currently available on underlying transport";
615 break;
616 case -(MBEDTLS_ERR_SSL_WANT_WRITE):
617 error_description = "SSL - Connection requires a write call";
618 break;
619 case -(MBEDTLS_ERR_SSL_TIMEOUT):
620 error_description = "SSL - The operation timed out";
621 break;
622 case -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT):
623 error_description = "SSL - The client initiated a reconnect from the same port";
624 break;
625 case -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD):
626 error_description = "SSL - Record header looks valid but is not expected";
627 break;
628 case -(MBEDTLS_ERR_SSL_NON_FATAL):
629 error_description = "SSL - The alert message received indicates a non-fatal error";
630 break;
631 case -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH):
632 error_description = "SSL - Couldn't set the hash for verifying CertificateVerify";
633 break;
634 case -(MBEDTLS_ERR_SSL_CONTINUE_PROCESSING):
635 error_description = "SSL - Internal-only message signaling that further message-processing should be done";
636 break;
637 case -(MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS):
638 error_description = "SSL - The asynchronous operation is not completed yet";
639 break;
640 case -(MBEDTLS_ERR_SSL_EARLY_MESSAGE):
641 error_description = "SSL - Internal-only message signaling that a message arrived early";
642 break;
643 case -(MBEDTLS_ERR_SSL_UNEXPECTED_CID):
644 error_description = "SSL - An encrypted DTLS-frame with an unexpected CID was received";
645 break;
646 case -(MBEDTLS_ERR_SSL_VERSION_MISMATCH):
647 error_description = "SSL - An operation failed due to an unexpected version or configuration";
648 break;
649 case -(MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS):
650 error_description = "SSL - A cryptographic operation is in progress. Try again later";
651 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700652#endif /* MBEDTLS_SSL_TLS_C */
653
654#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700655 case -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE):
656 error_description = "X509 - Unavailable feature, e.g. RSA hashing/encryption combination";
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700657 break;
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700658 case -(MBEDTLS_ERR_X509_UNKNOWN_OID):
659 error_description = "X509 - Requested OID is unknown";
660 break;
661 case -(MBEDTLS_ERR_X509_INVALID_FORMAT):
662 error_description = "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected";
663 break;
664 case -(MBEDTLS_ERR_X509_INVALID_VERSION):
665 error_description = "X509 - The CRT/CRL/CSR version element is invalid";
666 break;
667 case -(MBEDTLS_ERR_X509_INVALID_SERIAL):
668 error_description = "X509 - The serial tag or value is invalid";
669 break;
670 case -(MBEDTLS_ERR_X509_INVALID_ALG):
671 error_description = "X509 - The algorithm tag or value is invalid";
672 break;
673 case -(MBEDTLS_ERR_X509_INVALID_NAME):
674 error_description = "X509 - The name tag or value is invalid";
675 break;
676 case -(MBEDTLS_ERR_X509_INVALID_DATE):
677 error_description = "X509 - The date tag or value is invalid";
678 break;
679 case -(MBEDTLS_ERR_X509_INVALID_SIGNATURE):
680 error_description = "X509 - The signature tag or value invalid";
681 break;
682 case -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS):
683 error_description = "X509 - The extension tag or value is invalid";
684 break;
685 case -(MBEDTLS_ERR_X509_UNKNOWN_VERSION):
686 error_description = "X509 - CRT/CRL/CSR has an unsupported version number";
687 break;
688 case -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG):
689 error_description = "X509 - Signature algorithm (oid) is unsupported";
690 break;
691 case -(MBEDTLS_ERR_X509_SIG_MISMATCH):
692 error_description = "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)";
693 break;
694 case -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED):
695 error_description = "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed";
696 break;
697 case -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT):
698 error_description = "X509 - Format not recognized as DER or PEM";
699 break;
700 case -(MBEDTLS_ERR_X509_BAD_INPUT_DATA):
701 error_description = "X509 - Input invalid";
702 break;
703 case -(MBEDTLS_ERR_X509_ALLOC_FAILED):
704 error_description = "X509 - Allocation of memory failed";
705 break;
706 case -(MBEDTLS_ERR_X509_FILE_IO_ERROR):
707 error_description = "X509 - Read/write of file failed";
708 break;
709 case -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL):
710 error_description = "X509 - Destination buffer is too small";
711 break;
712 case -(MBEDTLS_ERR_X509_FATAL_ERROR):
713 error_description = "X509 - A fatal error occurred, eg the chain is too long or the vrfy callback failed";
714 break;
715#endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
716
717 default:
718 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700719 }
720
721 return error_description;
722}
723
724const char * mbedtls_low_level_strerr( int error_code )
725{
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700726 const char *error_description = NULL;
727
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700728 switch( error_code )
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700729 {
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700730#if defined(MBEDTLS_AES_C)
731 case -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH):
732 error_description = "AES - Invalid key length";
Gaurav Aggarwala9f64002020-04-09 01:44:52 -0700733 break;
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -0700734 case -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH):
735 error_description = "AES - Invalid data input length";
736 break;
737 case -(MBEDTLS_ERR_AES_BAD_INPUT_DATA):
738 error_description = "AES - Invalid input data";
739 break;
740 case -(MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE):
741 error_description = "AES - Feature not available. For example, an unsupported AES key size";
742 break;
743 case -(MBEDTLS_ERR_AES_HW_ACCEL_FAILED):
744 error_description = "AES - AES hardware accelerator failed";
745 break;
746#endif /* MBEDTLS_AES_C */
747
748#if defined(MBEDTLS_ARC4_C)
749 case -(MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED):
750 error_description = "ARC4 - ARC4 hardware accelerator failed";
751 break;
752#endif /* MBEDTLS_ARC4_C */
753
754#if defined(MBEDTLS_ARIA_C)
755 case -(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA):
756 error_description = "ARIA - Bad input data";
757 break;
758 case -(MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH):
759 error_description = "ARIA - Invalid data input length";
760 break;
761 case -(MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE):
762 error_description = "ARIA - Feature not available. For example, an unsupported ARIA key size";
763 break;
764 case -(MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED):
765 error_description = "ARIA - ARIA hardware accelerator failed";
766 break;
767#endif /* MBEDTLS_ARIA_C */
768
769#if defined(MBEDTLS_ASN1_PARSE_C)
770 case -(MBEDTLS_ERR_ASN1_OUT_OF_DATA):
771 error_description = "ASN1 - Out of data when parsing an ASN1 data structure";
772 break;
773 case -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG):
774 error_description = "ASN1 - ASN1 tag was of an unexpected value";
775 break;
776 case -(MBEDTLS_ERR_ASN1_INVALID_LENGTH):
777 error_description = "ASN1 - Error when trying to determine the length or invalid length";
778 break;
779 case -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH):
780 error_description = "ASN1 - Actual length differs from expected length";
781 break;
782 case -(MBEDTLS_ERR_ASN1_INVALID_DATA):
783 error_description = "ASN1 - Data is invalid";
784 break;
785 case -(MBEDTLS_ERR_ASN1_ALLOC_FAILED):
786 error_description = "ASN1 - Memory allocation failed";
787 break;
788 case -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL):
789 error_description = "ASN1 - Buffer too small when writing ASN.1 data structure";
790 break;
791#endif /* MBEDTLS_ASN1_PARSE_C */
792
793#if defined(MBEDTLS_BASE64_C)
794 case -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL):
795 error_description = "BASE64 - Output buffer too small";
796 break;
797 case -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER):
798 error_description = "BASE64 - Invalid character in input";
799 break;
800#endif /* MBEDTLS_BASE64_C */
801
802#if defined(MBEDTLS_BIGNUM_C)
803 case -(MBEDTLS_ERR_MPI_FILE_IO_ERROR):
804 error_description = "BIGNUM - An error occurred while reading from or writing to a file";
805 break;
806 case -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA):
807 error_description = "BIGNUM - Bad input parameters to function";
808 break;
809 case -(MBEDTLS_ERR_MPI_INVALID_CHARACTER):
810 error_description = "BIGNUM - There is an invalid character in the digit string";
811 break;
812 case -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL):
813 error_description = "BIGNUM - The buffer is too small to write to";
814 break;
815 case -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE):
816 error_description = "BIGNUM - The input arguments are negative or result in illegal output";
817 break;
818 case -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO):
819 error_description = "BIGNUM - The input argument for division is zero, which is not allowed";
820 break;
821 case -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE):
822 error_description = "BIGNUM - The input arguments are not acceptable";
823 break;
824 case -(MBEDTLS_ERR_MPI_ALLOC_FAILED):
825 error_description = "BIGNUM - Memory allocation failed";
826 break;
827#endif /* MBEDTLS_BIGNUM_C */
828
829#if defined(MBEDTLS_BLOWFISH_C)
830 case -(MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA):
831 error_description = "BLOWFISH - Bad input data";
832 break;
833 case -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH):
834 error_description = "BLOWFISH - Invalid data input length";
835 break;
836 case -(MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED):
837 error_description = "BLOWFISH - Blowfish hardware accelerator failed";
838 break;
839#endif /* MBEDTLS_BLOWFISH_C */
840
841#if defined(MBEDTLS_CAMELLIA_C)
842 case -(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA):
843 error_description = "CAMELLIA - Bad input data";
844 break;
845 case -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH):
846 error_description = "CAMELLIA - Invalid data input length";
847 break;
848 case -(MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED):
849 error_description = "CAMELLIA - Camellia hardware accelerator failed";
850 break;
851#endif /* MBEDTLS_CAMELLIA_C */
852
853#if defined(MBEDTLS_CCM_C)
854 case -(MBEDTLS_ERR_CCM_BAD_INPUT):
855 error_description = "CCM - Bad input parameters to the function";
856 break;
857 case -(MBEDTLS_ERR_CCM_AUTH_FAILED):
858 error_description = "CCM - Authenticated decryption failed";
859 break;
860 case -(MBEDTLS_ERR_CCM_HW_ACCEL_FAILED):
861 error_description = "CCM - CCM hardware accelerator failed";
862 break;
863#endif /* MBEDTLS_CCM_C */
864
865#if defined(MBEDTLS_CHACHA20_C)
866 case -(MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA):
867 error_description = "CHACHA20 - Invalid input parameter(s)";
868 break;
869 case -(MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE):
870 error_description = "CHACHA20 - Feature not available. For example, s part of the API is not implemented";
871 break;
872 case -(MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED):
873 error_description = "CHACHA20 - Chacha20 hardware accelerator failed";
874 break;
875#endif /* MBEDTLS_CHACHA20_C */
876
877#if defined(MBEDTLS_CHACHAPOLY_C)
878 case -(MBEDTLS_ERR_CHACHAPOLY_BAD_STATE):
879 error_description = "CHACHAPOLY - The requested operation is not permitted in the current state";
880 break;
881 case -(MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED):
882 error_description = "CHACHAPOLY - Authenticated decryption failed: data was not authentic";
883 break;
884#endif /* MBEDTLS_CHACHAPOLY_C */
885
886#if defined(MBEDTLS_CMAC_C)
887 case -(MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED):
888 error_description = "CMAC - CMAC hardware accelerator failed";
889 break;
890#endif /* MBEDTLS_CMAC_C */
891
892#if defined(MBEDTLS_CTR_DRBG_C)
893 case -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED):
894 error_description = "CTR_DRBG - The entropy source failed";
895 break;
896 case -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG):
897 error_description = "CTR_DRBG - The requested random buffer length is too big";
898 break;
899 case -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG):
900 error_description = "CTR_DRBG - The input (entropy + additional data) is too large";
901 break;
902 case -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR):
903 error_description = "CTR_DRBG - Read or write error in file";
904 break;
905#endif /* MBEDTLS_CTR_DRBG_C */
906
907#if defined(MBEDTLS_DES_C)
908 case -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH):
909 error_description = "DES - The data input has an invalid length";
910 break;
911 case -(MBEDTLS_ERR_DES_HW_ACCEL_FAILED):
912 error_description = "DES - DES hardware accelerator failed";
913 break;
914#endif /* MBEDTLS_DES_C */
915
916#if defined(MBEDTLS_ENTROPY_C)
917 case -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED):
918 error_description = "ENTROPY - Critical entropy source failure";
919 break;
920 case -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES):
921 error_description = "ENTROPY - No more sources can be added";
922 break;
923 case -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED):
924 error_description = "ENTROPY - No sources have been added to poll";
925 break;
926 case -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE):
927 error_description = "ENTROPY - No strong sources have been added to poll";
928 break;
929 case -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR):
930 error_description = "ENTROPY - Read/write error in file";
931 break;
932#endif /* MBEDTLS_ENTROPY_C */
933
934#if defined(MBEDTLS_ERROR_C)
935 case -(MBEDTLS_ERR_ERROR_GENERIC_ERROR):
936 error_description = "ERROR - Generic error";
937 break;
938 case -(MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED):
939 error_description = "ERROR - This is a bug in the library";
940 break;
941#endif /* MBEDTLS_ERROR_C */
942
943#if defined(MBEDTLS_GCM_C)
944 case -(MBEDTLS_ERR_GCM_AUTH_FAILED):
945 error_description = "GCM - Authenticated decryption failed";
946 break;
947 case -(MBEDTLS_ERR_GCM_HW_ACCEL_FAILED):
948 error_description = "GCM - GCM hardware accelerator failed";
949 break;
950 case -(MBEDTLS_ERR_GCM_BAD_INPUT):
951 error_description = "GCM - Bad input parameters to function";
952 break;
953#endif /* MBEDTLS_GCM_C */
954
955#if defined(MBEDTLS_HKDF_C)
956 case -(MBEDTLS_ERR_HKDF_BAD_INPUT_DATA):
957 error_description = "HKDF - Bad input parameters to function";
958 break;
959#endif /* MBEDTLS_HKDF_C */
960
961#if defined(MBEDTLS_HMAC_DRBG_C)
962 case -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG):
963 error_description = "HMAC_DRBG - Too many random requested in single call";
964 break;
965 case -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG):
966 error_description = "HMAC_DRBG - Input too large (Entropy + additional)";
967 break;
968 case -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR):
969 error_description = "HMAC_DRBG - Read/write error in file";
970 break;
971 case -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED):
972 error_description = "HMAC_DRBG - The entropy source failed";
973 break;
974#endif /* MBEDTLS_HMAC_DRBG_C */
975
976#if defined(MBEDTLS_MD2_C)
977 case -(MBEDTLS_ERR_MD2_HW_ACCEL_FAILED):
978 error_description = "MD2 - MD2 hardware accelerator failed";
979 break;
980#endif /* MBEDTLS_MD2_C */
981
982#if defined(MBEDTLS_MD4_C)
983 case -(MBEDTLS_ERR_MD4_HW_ACCEL_FAILED):
984 error_description = "MD4 - MD4 hardware accelerator failed";
985 break;
986#endif /* MBEDTLS_MD4_C */
987
988#if defined(MBEDTLS_MD5_C)
989 case -(MBEDTLS_ERR_MD5_HW_ACCEL_FAILED):
990 error_description = "MD5 - MD5 hardware accelerator failed";
991 break;
992#endif /* MBEDTLS_MD5_C */
993
994#if defined(MBEDTLS_NET_C)
995 case -(MBEDTLS_ERR_NET_SOCKET_FAILED):
996 error_description = "NET - Failed to open a socket";
997 break;
998 case -(MBEDTLS_ERR_NET_CONNECT_FAILED):
999 error_description = "NET - The connection to the given server / port failed";
1000 break;
1001 case -(MBEDTLS_ERR_NET_BIND_FAILED):
1002 error_description = "NET - Binding of the socket failed";
1003 break;
1004 case -(MBEDTLS_ERR_NET_LISTEN_FAILED):
1005 error_description = "NET - Could not listen on the socket";
1006 break;
1007 case -(MBEDTLS_ERR_NET_ACCEPT_FAILED):
1008 error_description = "NET - Could not accept the incoming connection";
1009 break;
1010 case -(MBEDTLS_ERR_NET_RECV_FAILED):
1011 error_description = "NET - Reading information from the socket failed";
1012 break;
1013 case -(MBEDTLS_ERR_NET_SEND_FAILED):
1014 error_description = "NET - Sending information through the socket failed";
1015 break;
1016 case -(MBEDTLS_ERR_NET_CONN_RESET):
1017 error_description = "NET - Connection was reset by peer";
1018 break;
1019 case -(MBEDTLS_ERR_NET_UNKNOWN_HOST):
1020 error_description = "NET - Failed to get an IP address for the given hostname";
1021 break;
1022 case -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL):
1023 error_description = "NET - Buffer is too small to hold the data";
1024 break;
1025 case -(MBEDTLS_ERR_NET_INVALID_CONTEXT):
1026 error_description = "NET - The context is invalid, eg because it was free()ed";
1027 break;
1028 case -(MBEDTLS_ERR_NET_POLL_FAILED):
1029 error_description = "NET - Polling the net context failed";
1030 break;
1031 case -(MBEDTLS_ERR_NET_BAD_INPUT_DATA):
1032 error_description = "NET - Input invalid";
1033 break;
1034#endif /* MBEDTLS_NET_C */
1035
1036#if defined(MBEDTLS_OID_C)
1037 case -(MBEDTLS_ERR_OID_NOT_FOUND):
1038 error_description = "OID - OID is not found";
1039 break;
1040 case -(MBEDTLS_ERR_OID_BUF_TOO_SMALL):
1041 error_description = "OID - output buffer is too small";
1042 break;
1043#endif /* MBEDTLS_OID_C */
1044
1045#if defined(MBEDTLS_PADLOCK_C)
1046 case -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED):
1047 error_description = "PADLOCK - Input data should be aligned";
1048 break;
1049#endif /* MBEDTLS_PADLOCK_C */
1050
1051#if defined(MBEDTLS_PLATFORM_C)
1052 case -(MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED):
1053 error_description = "PLATFORM - Hardware accelerator failed";
1054 break;
1055 case -(MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED):
1056 error_description = "PLATFORM - The requested feature is not supported by the platform";
1057 break;
1058#endif /* MBEDTLS_PLATFORM_C */
1059
1060#if defined(MBEDTLS_POLY1305_C)
1061 case -(MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA):
1062 error_description = "POLY1305 - Invalid input parameter(s)";
1063 break;
1064 case -(MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE):
1065 error_description = "POLY1305 - Feature not available. For example, s part of the API is not implemented";
1066 break;
1067 case -(MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED):
1068 error_description = "POLY1305 - Poly1305 hardware accelerator failed";
1069 break;
1070#endif /* MBEDTLS_POLY1305_C */
1071
1072#if defined(MBEDTLS_RIPEMD160_C)
1073 case -(MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED):
1074 error_description = "RIPEMD160 - RIPEMD160 hardware accelerator failed";
1075 break;
1076#endif /* MBEDTLS_RIPEMD160_C */
1077
1078#if defined(MBEDTLS_SHA1_C)
1079 case -(MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED):
1080 error_description = "SHA1 - SHA-1 hardware accelerator failed";
1081 break;
1082 case -(MBEDTLS_ERR_SHA1_BAD_INPUT_DATA):
1083 error_description = "SHA1 - SHA-1 input data was malformed";
1084 break;
1085#endif /* MBEDTLS_SHA1_C */
1086
1087#if defined(MBEDTLS_SHA256_C)
1088 case -(MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED):
1089 error_description = "SHA256 - SHA-256 hardware accelerator failed";
1090 break;
1091 case -(MBEDTLS_ERR_SHA256_BAD_INPUT_DATA):
1092 error_description = "SHA256 - SHA-256 input data was malformed";
1093 break;
1094#endif /* MBEDTLS_SHA256_C */
1095
1096#if defined(MBEDTLS_SHA512_C)
1097 case -(MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED):
1098 error_description = "SHA512 - SHA-512 hardware accelerator failed";
1099 break;
1100 case -(MBEDTLS_ERR_SHA512_BAD_INPUT_DATA):
1101 error_description = "SHA512 - SHA-512 input data was malformed";
1102 break;
1103#endif /* MBEDTLS_SHA512_C */
1104
1105#if defined(MBEDTLS_THREADING_C)
1106 case -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE):
1107 error_description = "THREADING - The selected feature is not available";
1108 break;
1109 case -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA):
1110 error_description = "THREADING - Bad input parameters to function";
1111 break;
1112 case -(MBEDTLS_ERR_THREADING_MUTEX_ERROR):
1113 error_description = "THREADING - Locking / unlocking / free failed with error code";
1114 break;
1115#endif /* MBEDTLS_THREADING_C */
1116
1117#if defined(MBEDTLS_XTEA_C)
1118 case -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH):
1119 error_description = "XTEA - The data input has an invalid length";
1120 break;
1121 case -(MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED):
1122 error_description = "XTEA - XTEA hardware accelerator failed";
1123 break;
1124#endif /* MBEDTLS_XTEA_C */
1125
1126 default:
1127 break;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -07001128 }
1129
1130 return error_description;
1131}
1132
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001133void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker9d781402011-05-09 16:17:09 +00001134{
1135 size_t len;
1136 int use_ret;
Gaurav Aggarwala9f64002020-04-09 01:44:52 -07001137 const char * high_level_error_description = NULL;
1138 const char * low_level_error_description = NULL;
Paul Bakker9d781402011-05-09 16:17:09 +00001139
Paul Bakkerb9cfaa02013-10-11 18:58:55 +02001140 if( buflen == 0 )
1141 return;
1142
Paul Bakker9d781402011-05-09 16:17:09 +00001143 memset( buf, 0x00, buflen );
Paul Bakkerb9cfaa02013-10-11 18:58:55 +02001144
Paul Bakker9d781402011-05-09 16:17:09 +00001145 if( ret < 0 )
1146 ret = -ret;
1147
1148 if( ret & 0xFF80 )
1149 {
1150 use_ret = ret & 0xFF80;
1151
Gaurav Aggarwala9f64002020-04-09 01:44:52 -07001152 // Translate high level error code.
1153 high_level_error_description = mbedtls_high_level_strerr(use_ret);
Paul Bakkerff61a782011-06-09 15:42:02 +00001154
Gaurav Aggarwala9f64002020-04-09 01:44:52 -07001155 if( high_level_error_description == NULL )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001156 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Gaurav Aggarwala9f64002020-04-09 01:44:52 -07001157 else
1158 mbedtls_snprintf( buf, buflen, "%s", high_level_error_description );
1159
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -07001160#if defined(MBEDTLS_SSL_TLS_C)
Gaurav Aggarwala9f64002020-04-09 01:44:52 -07001161 // Early return in case of a fatal error - do not try to translate low
1162 // level code.
1163 if(use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE))
1164 return;
Gaurav Aggarwala4a2aa52020-04-09 11:39:04 -07001165#endif /* MBEDTLS_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +00001166 }
1167
1168 use_ret = ret & ~0xFF80;
1169
1170 if( use_ret == 0 )
1171 return;
1172
1173 // If high level code is present, make a concatenation between both
1174 // error strings.
1175 //
1176 len = strlen( buf );
1177
1178 if( len > 0 )
1179 {
1180 if( buflen - len < 5 )
1181 return;
1182
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001183 mbedtls_snprintf( buf + len, buflen - len, " : " );
Paul Bakker9d781402011-05-09 16:17:09 +00001184
1185 buf += len + 3;
1186 buflen -= len + 3;
1187 }
1188
Gaurav Aggarwala9f64002020-04-09 01:44:52 -07001189 // Translate low level error code.
1190 low_level_error_description = mbedtls_low_level_strerr( use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +00001191
Gaurav Aggarwala9f64002020-04-09 01:44:52 -07001192 if( low_level_error_description == NULL )
1193 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
1194 else
1195 mbedtls_snprintf( buf, buflen, "%s", low_level_error_description );
Paul Bakker9d781402011-05-09 16:17:09 +00001196}
1197
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001198#else /* MBEDTLS_ERROR_C */
Paul Bakker8fe40dc2013-02-02 12:43:08 +01001199
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001200#if defined(MBEDTLS_ERROR_STRERROR_DUMMY)
Paul Bakker8fe40dc2013-02-02 12:43:08 +01001201
Paul Bakker8fe40dc2013-02-02 12:43:08 +01001202/*
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001203 * Provide an non-function in case MBEDTLS_ERROR_C is not defined
Paul Bakker8fe40dc2013-02-02 12:43:08 +01001204 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001205void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker8fe40dc2013-02-02 12:43:08 +01001206{
1207 ((void) ret);
1208
1209 if( buflen > 0 )
1210 buf[0] = '\0';
1211}
1212
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001213#endif /* MBEDTLS_ERROR_STRERROR_DUMMY */
Paul Bakkere2ab84f2013-06-29 18:24:32 +02001214
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001215#endif /* MBEDTLS_ERROR_C */