blob: 4ab8733e0cd271964565eeec194f78b2632c3e61 [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
Bence Szépkútif744bd72020-06-05 13:02:18 +02005 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
6 *
7 * This file is provided under the Apache License 2.0, or the
8 * GNU General Public License v2.0 or later.
9 *
10 * **********
11 * Apache License 2.0:
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020012 *
13 * Licensed under the Apache License, Version 2.0 (the "License"); you may
14 * not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 * http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
21 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
Paul Bakker9d781402011-05-09 16:17:09 +000024 *
Bence Szépkútif744bd72020-06-05 13:02:18 +020025 * **********
26 *
27 * **********
28 * GNU General Public License v2.0 or later:
29 *
30 * This program is free software; you can redistribute it and/or modify
31 * it under the terms of the GNU General Public License as published by
32 * the Free Software Foundation; either version 2 of the License, or
33 * (at your option) any later version.
34 *
35 * This program is distributed in the hope that it will be useful,
36 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38 * GNU General Public License for more details.
39 *
40 * You should have received a copy of the GNU General Public License along
41 * with this program; if not, write to the Free Software Foundation, Inc.,
42 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
43 *
44 * **********
45 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000046 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker9d781402011-05-09 16:17:09 +000047 */
48
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020049#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000050#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020051#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020053#endif
Paul Bakker9d781402011-05-09 16:17:09 +000054
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055#if defined(MBEDTLS_ERROR_C) || defined(MBEDTLS_ERROR_STRERROR_DUMMY)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000056#include "mbedtls/error.h"
Rich Evans00ab4702015-02-06 13:43:58 +000057#include <string.h>
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020058#endif
59
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000061#include "mbedtls/platform.h"
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +000062#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063#define mbedtls_snprintf snprintf
-~- redtangent ~-~9fa2e862016-05-26 10:07:49 +010064#define mbedtls_time_t time_t
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020065#endif
66
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020067#if defined(MBEDTLS_ERROR_C)
Paul Bakker3c2122f2013-06-24 19:03:14 +020068
Rich Evans00ab4702015-02-06 13:43:58 +000069#include <stdio.h>
70
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020071#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000072#include "mbedtls/aes.h"
Paul Bakker9d781402011-05-09 16:17:09 +000073#endif
74
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010075#if defined(MBEDTLS_ARC4_C)
76#include "mbedtls/arc4.h"
77#endif
78
Markku-Juhani O. Saarinen07478d62017-12-01 16:20:15 +000079#if defined(MBEDTLS_ARIA_C)
80#include "mbedtls/aria.h"
81#endif
82
Gilles Peskined2f00732020-05-25 12:23:55 +020083#if defined(MBEDTLS_ASN1_PARSE_C)
84#include "mbedtls/asn1.h"
85#endif
86
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020087#if defined(MBEDTLS_BASE64_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000088#include "mbedtls/base64.h"
Paul Bakker9d781402011-05-09 16:17:09 +000089#endif
90
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020091#if defined(MBEDTLS_BIGNUM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000092#include "mbedtls/bignum.h"
Paul Bakker9d781402011-05-09 16:17:09 +000093#endif
94
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020095#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000096#include "mbedtls/blowfish.h"
Paul Bakker83f00bb2012-07-04 11:08:50 +000097#endif
98
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020099#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000100#include "mbedtls/camellia.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000101#endif
102
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200103#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000104#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200105#endif
106
Daniel King34b822c2016-05-15 17:28:08 -0300107#if defined(MBEDTLS_CHACHA20_C)
108#include "mbedtls/chacha20.h"
109#endif
110
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200111#if defined(MBEDTLS_CHACHAPOLY_C)
112#include "mbedtls/chachapoly.h"
113#endif
114
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200115#if defined(MBEDTLS_CIPHER_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000116#include "mbedtls/cipher.h"
Paul Bakkerff61a782011-06-09 15:42:02 +0000117#endif
118
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100119#if defined(MBEDTLS_CMAC_C)
120#include "mbedtls/cmac.h"
121#endif
122
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200123#if defined(MBEDTLS_CTR_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000124#include "mbedtls/ctr_drbg.h"
Paul Bakker880ac7e2011-11-27 14:50:49 +0000125#endif
126
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000128#include "mbedtls/des.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000129#endif
130
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131#if defined(MBEDTLS_DHM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000132#include "mbedtls/dhm.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000133#endif
134
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200135#if defined(MBEDTLS_ECP_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000136#include "mbedtls/ecp.h"
Paul Bakkercf4365f2013-01-16 17:00:43 +0100137#endif
138
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200139#if defined(MBEDTLS_ENTROPY_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000140#include "mbedtls/entropy.h"
Paul Bakker6083fd22011-12-03 21:45:14 +0000141#endif
142
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200143#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000144#include "mbedtls/gcm.h"
Paul Bakker030277a2012-04-17 12:24:26 +0000145#endif
146
Thomas Fossati656864b2016-07-17 08:51:22 +0100147#if defined(MBEDTLS_HKDF_C)
148#include "mbedtls/hkdf.h"
149#endif
150
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200151#if defined(MBEDTLS_HMAC_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000152#include "mbedtls/hmac_drbg.h"
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100153#endif
154
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200155#if defined(MBEDTLS_MD_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000156#include "mbedtls/md.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000157#endif
158
Gilles Peskinea381fe82018-01-23 18:16:11 +0100159#if defined(MBEDTLS_MD2_C)
160#include "mbedtls/md2.h"
161#endif
162
163#if defined(MBEDTLS_MD4_C)
164#include "mbedtls/md4.h"
165#endif
166
167#if defined(MBEDTLS_MD5_C)
168#include "mbedtls/md5.h"
169#endif
170
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200171#if defined(MBEDTLS_NET_C)
Andres AG3616f6f2016-09-14 14:32:09 +0100172#include "mbedtls/net_sockets.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000173#endif
174
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200175#if defined(MBEDTLS_OID_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000176#include "mbedtls/oid.h"
Paul Bakkerc70b9822013-04-07 22:00:46 +0200177#endif
178
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200179#if defined(MBEDTLS_PADLOCK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000180#include "mbedtls/padlock.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000181#endif
182
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200183#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000184#include "mbedtls/pem.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000185#endif
186
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200187#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000188#include "mbedtls/pk.h"
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200189#endif
190
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200191#if defined(MBEDTLS_PKCS12_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000192#include "mbedtls/pkcs12.h"
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200193#endif
194
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200195#if defined(MBEDTLS_PKCS5_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000196#include "mbedtls/pkcs5.h"
Paul Bakkerb0c19a42013-06-24 19:26:38 +0200197#endif
198
Ron Eldor0ff4e0b2018-08-29 18:53:20 +0300199#if defined(MBEDTLS_PLATFORM_C)
200#include "mbedtls/platform.h"
201#endif
202
Daniel Kingadc32c02016-05-16 18:25:45 -0300203#if defined(MBEDTLS_POLY1305_C)
204#include "mbedtls/poly1305.h"
205#endif
206
Gilles Peskinea381fe82018-01-23 18:16:11 +0100207#if defined(MBEDTLS_RIPEMD160_C)
208#include "mbedtls/ripemd160.h"
209#endif
210
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200211#if defined(MBEDTLS_RSA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000212#include "mbedtls/rsa.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000213#endif
214
Gilles Peskinea381fe82018-01-23 18:16:11 +0100215#if defined(MBEDTLS_SHA1_C)
216#include "mbedtls/sha1.h"
217#endif
218
219#if defined(MBEDTLS_SHA256_C)
220#include "mbedtls/sha256.h"
221#endif
222
223#if defined(MBEDTLS_SHA512_C)
224#include "mbedtls/sha512.h"
225#endif
226
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200227#if defined(MBEDTLS_SSL_TLS_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000228#include "mbedtls/ssl.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000229#endif
230
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200231#if defined(MBEDTLS_THREADING_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000232#include "mbedtls/threading.h"
Paul Bakker2466d932013-09-28 14:40:38 +0200233#endif
234
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200235#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000236#include "mbedtls/x509.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000237#endif
238
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200239#if defined(MBEDTLS_XTEA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000240#include "mbedtls/xtea.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000241#endif
242
Paul Bakkerdceecd82011-11-15 16:38:34 +0000243
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200244void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker9d781402011-05-09 16:17:09 +0000245{
246 size_t len;
247 int use_ret;
248
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200249 if( buflen == 0 )
250 return;
251
Paul Bakker9d781402011-05-09 16:17:09 +0000252 memset( buf, 0x00, buflen );
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200253
Paul Bakker9d781402011-05-09 16:17:09 +0000254 if( ret < 0 )
255 ret = -ret;
256
257 if( ret & 0xFF80 )
258 {
259 use_ret = ret & 0xFF80;
260
261 // High level error codes
262 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200263 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200264#if defined(MBEDTLS_CIPHER_C)
265 if( use_ret == -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE) )
266 mbedtls_snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
267 if( use_ret == -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA) )
Rose Zadik9ba6b622018-01-24 12:59:19 +0000268 mbedtls_snprintf( buf, buflen, "CIPHER - Bad input parameters" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200269 if( use_ret == -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED) )
270 mbedtls_snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
271 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_PADDING) )
272 mbedtls_snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
273 if( use_ret == -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
274 mbedtls_snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
275 if( use_ret == -(MBEDTLS_ERR_CIPHER_AUTH_FAILED) )
276 mbedtls_snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
Janos Follath98e28a72016-05-31 14:03:54 +0100277 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT) )
Rose Zadik9ba6b622018-01-24 12:59:19 +0000278 mbedtls_snprintf( buf, buflen, "CIPHER - The context is invalid. For example, because it was freed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100279 if( use_ret == -(MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED) )
280 mbedtls_snprintf( buf, buflen, "CIPHER - Cipher hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200281#endif /* MBEDTLS_CIPHER_C */
Paul Bakkerff61a782011-06-09 15:42:02 +0000282
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200283#if defined(MBEDTLS_DHM_C)
284 if( use_ret == -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA) )
Rose Zadik41ad0822018-01-26 10:54:57 +0000285 mbedtls_snprintf( buf, buflen, "DHM - Bad input parameters" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200286 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED) )
287 mbedtls_snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
288 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED) )
289 mbedtls_snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
290 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED) )
291 mbedtls_snprintf( buf, buflen, "DHM - Reading of the public values failed" );
292 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED) )
293 mbedtls_snprintf( buf, buflen, "DHM - Making of the public value failed" );
294 if( use_ret == -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED) )
295 mbedtls_snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
296 if( use_ret == -(MBEDTLS_ERR_DHM_INVALID_FORMAT) )
297 mbedtls_snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200298 if( use_ret == -(MBEDTLS_ERR_DHM_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200299 mbedtls_snprintf( buf, buflen, "DHM - Allocation of memory failed" );
300 if( use_ret == -(MBEDTLS_ERR_DHM_FILE_IO_ERROR) )
Rose Zadik41ad0822018-01-26 10:54:57 +0000301 mbedtls_snprintf( buf, buflen, "DHM - Read or write of file failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100302 if( use_ret == -(MBEDTLS_ERR_DHM_HW_ACCEL_FAILED) )
303 mbedtls_snprintf( buf, buflen, "DHM - DHM hardware accelerator failed" );
Hanno Beckera6dd90d2017-10-04 13:15:54 +0100304 if( use_ret == -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED) )
Jaeden Amero784de592018-01-26 17:52:01 +0000305 mbedtls_snprintf( buf, buflen, "DHM - Setting the modulus and generator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200306#endif /* MBEDTLS_DHM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000307
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200308#if defined(MBEDTLS_ECP_C)
309 if( use_ret == -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA) )
310 mbedtls_snprintf( buf, buflen, "ECP - Bad input parameters to function" );
311 if( use_ret == -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL) )
312 mbedtls_snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
313 if( use_ret == -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) )
Jaeden Amero3dd8abd2018-04-24 10:56:55 +0100314 mbedtls_snprintf( buf, buflen, "ECP - The requested feature is not available, for example, the requested curve is not supported" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200315 if( use_ret == -(MBEDTLS_ERR_ECP_VERIFY_FAILED) )
316 mbedtls_snprintf( buf, buflen, "ECP - The signature is not valid" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200317 if( use_ret == -(MBEDTLS_ERR_ECP_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200318 mbedtls_snprintf( buf, buflen, "ECP - Memory allocation failed" );
319 if( use_ret == -(MBEDTLS_ERR_ECP_RANDOM_FAILED) )
Jaeden Amero3dd8abd2018-04-24 10:56:55 +0100320 mbedtls_snprintf( buf, buflen, "ECP - Generation of random value, such as ephemeral key, failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200321 if( use_ret == -(MBEDTLS_ERR_ECP_INVALID_KEY) )
322 mbedtls_snprintf( buf, buflen, "ECP - Invalid private or public key" );
323 if( use_ret == -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) )
Gilles Peskinecc78ac42018-03-30 18:52:10 +0200324 mbedtls_snprintf( buf, buflen, "ECP - The buffer contains a valid signature followed by more data" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100325 if( use_ret == -(MBEDTLS_ERR_ECP_HW_ACCEL_FAILED) )
Jaeden Amero3dd8abd2018-04-24 10:56:55 +0100326 mbedtls_snprintf( buf, buflen, "ECP - The ECP hardware accelerator failed" );
Manuel Pégourié-Gonnard5e3c62f2017-03-08 10:14:11 +0100327 if( use_ret == -(MBEDTLS_ERR_ECP_IN_PROGRESS) )
Manuel Pégourié-Gonnardf0bbd7e2018-10-15 13:22:41 +0200328 mbedtls_snprintf( buf, buflen, "ECP - Operation in progress, call again with the same parameters to continue" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200329#endif /* MBEDTLS_ECP_C */
Paul Bakkercf4365f2013-01-16 17:00:43 +0100330
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200331#if defined(MBEDTLS_MD_C)
332 if( use_ret == -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE) )
333 mbedtls_snprintf( buf, buflen, "MD - The selected feature is not available" );
334 if( use_ret == -(MBEDTLS_ERR_MD_BAD_INPUT_DATA) )
335 mbedtls_snprintf( buf, buflen, "MD - Bad input parameters to function" );
336 if( use_ret == -(MBEDTLS_ERR_MD_ALLOC_FAILED) )
337 mbedtls_snprintf( buf, buflen, "MD - Failed to allocate memory" );
338 if( use_ret == -(MBEDTLS_ERR_MD_FILE_IO_ERROR) )
339 mbedtls_snprintf( buf, buflen, "MD - Opening or reading of file failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100340 if( use_ret == -(MBEDTLS_ERR_MD_HW_ACCEL_FAILED) )
341 mbedtls_snprintf( buf, buflen, "MD - MD hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200342#endif /* MBEDTLS_MD_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000343
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200344#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
345 if( use_ret == -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
346 mbedtls_snprintf( buf, buflen, "PEM - No PEM header or footer found" );
347 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_DATA) )
348 mbedtls_snprintf( buf, buflen, "PEM - PEM string is not as expected" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200349 if( use_ret == -(MBEDTLS_ERR_PEM_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200350 mbedtls_snprintf( buf, buflen, "PEM - Failed to allocate memory" );
351 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_ENC_IV) )
352 mbedtls_snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
353 if( use_ret == -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG) )
354 mbedtls_snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
355 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) )
356 mbedtls_snprintf( buf, buflen, "PEM - Private key password can't be empty" );
357 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) )
358 mbedtls_snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
359 if( use_ret == -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE) )
360 mbedtls_snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
361 if( use_ret == -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA) )
362 mbedtls_snprintf( buf, buflen, "PEM - Bad input parameters to function" );
363#endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000364
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200365#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200366 if( use_ret == -(MBEDTLS_ERR_PK_ALLOC_FAILED) )
Manuel Pégourié-Gonnard41b9c2b2015-05-28 14:56:20 +0200367 mbedtls_snprintf( buf, buflen, "PK - Memory allocation failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200368 if( use_ret == -(MBEDTLS_ERR_PK_TYPE_MISMATCH) )
369 mbedtls_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
370 if( use_ret == -(MBEDTLS_ERR_PK_BAD_INPUT_DATA) )
371 mbedtls_snprintf( buf, buflen, "PK - Bad input parameters to function" );
372 if( use_ret == -(MBEDTLS_ERR_PK_FILE_IO_ERROR) )
373 mbedtls_snprintf( buf, buflen, "PK - Read/write of file failed" );
374 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION) )
375 mbedtls_snprintf( buf, buflen, "PK - Unsupported key version" );
376 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT) )
377 mbedtls_snprintf( buf, buflen, "PK - Invalid key tag or value" );
378 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG) )
379 mbedtls_snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
380 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED) )
381 mbedtls_snprintf( buf, buflen, "PK - Private key password can't be empty" );
382 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH) )
383 mbedtls_snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
384 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_PUBKEY) )
385 mbedtls_snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
386 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_ALG) )
387 mbedtls_snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
388 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE) )
389 mbedtls_snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
390 if( use_ret == -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) )
391 mbedtls_snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
392 if( use_ret == -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH) )
Gilles Peskinecc78ac42018-03-30 18:52:10 +0200393 mbedtls_snprintf( buf, buflen, "PK - The buffer contains a valid signature followed by more data" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100394 if( use_ret == -(MBEDTLS_ERR_PK_HW_ACCEL_FAILED) )
395 mbedtls_snprintf( buf, buflen, "PK - PK hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200396#endif /* MBEDTLS_PK_C */
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200397
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200398#if defined(MBEDTLS_PKCS12_C)
399 if( use_ret == -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA) )
400 mbedtls_snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
401 if( use_ret == -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE) )
402 mbedtls_snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
403 if( use_ret == -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT) )
404 mbedtls_snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
405 if( use_ret == -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) )
406 mbedtls_snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
407#endif /* MBEDTLS_PKCS12_C */
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200408
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200409#if defined(MBEDTLS_PKCS5_C)
410 if( use_ret == -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA) )
411 mbedtls_snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
412 if( use_ret == -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT) )
413 mbedtls_snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
414 if( use_ret == -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE) )
415 mbedtls_snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
416 if( use_ret == -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) )
417 mbedtls_snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
418#endif /* MBEDTLS_PKCS5_C */
Paul Bakker28144de2013-06-24 19:28:55 +0200419
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200420#if defined(MBEDTLS_RSA_C)
421 if( use_ret == -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA) )
422 mbedtls_snprintf( buf, buflen, "RSA - Bad input parameters to function" );
423 if( use_ret == -(MBEDTLS_ERR_RSA_INVALID_PADDING) )
424 mbedtls_snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
425 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED) )
426 mbedtls_snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
427 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED) )
Rose Zadik042e97f2018-01-26 16:35:10 +0000428 mbedtls_snprintf( buf, buflen, "RSA - Key failed to pass the validity check of the library" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200429 if( use_ret == -(MBEDTLS_ERR_RSA_PUBLIC_FAILED) )
430 mbedtls_snprintf( buf, buflen, "RSA - The public key operation failed" );
431 if( use_ret == -(MBEDTLS_ERR_RSA_PRIVATE_FAILED) )
432 mbedtls_snprintf( buf, buflen, "RSA - The private key operation failed" );
433 if( use_ret == -(MBEDTLS_ERR_RSA_VERIFY_FAILED) )
434 mbedtls_snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
435 if( use_ret == -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE) )
436 mbedtls_snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
437 if( use_ret == -(MBEDTLS_ERR_RSA_RNG_FAILED) )
438 mbedtls_snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
Hanno Becker3cdc7112017-10-05 10:09:31 +0100439 if( use_ret == -(MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION) )
Rose Zadik042e97f2018-01-26 16:35:10 +0000440 mbedtls_snprintf( buf, buflen, "RSA - The implementation does not offer the requested operation, for example, because of security violations or lack of functionality" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100441 if( use_ret == -(MBEDTLS_ERR_RSA_HW_ACCEL_FAILED) )
442 mbedtls_snprintf( buf, buflen, "RSA - RSA hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200443#endif /* MBEDTLS_RSA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000444
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200445#if defined(MBEDTLS_SSL_TLS_C)
446 if( use_ret == -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE) )
447 mbedtls_snprintf( buf, buflen, "SSL - The requested feature is not available" );
448 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA) )
449 mbedtls_snprintf( buf, buflen, "SSL - Bad input parameters to function" );
450 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_MAC) )
451 mbedtls_snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
452 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_RECORD) )
453 mbedtls_snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
454 if( use_ret == -(MBEDTLS_ERR_SSL_CONN_EOF) )
455 mbedtls_snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
456 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER) )
457 mbedtls_snprintf( buf, buflen, "SSL - An unknown cipher was received" );
458 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN) )
459 mbedtls_snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
460 if( use_ret == -(MBEDTLS_ERR_SSL_NO_RNG) )
461 mbedtls_snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
462 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE) )
463 mbedtls_snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
464 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE) )
465 mbedtls_snprintf( buf, buflen, "SSL - Our own certificate(s) is/are too large to send in an SSL message" );
466 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED) )
467 mbedtls_snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
468 if( use_ret == -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED) )
469 mbedtls_snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
470 if( use_ret == -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED) )
471 mbedtls_snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
472 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE) )
473 mbedtls_snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
474 if( use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE) )
Paul Bakker3aac1da2012-05-08 13:12:27 +0000475 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200476 mbedtls_snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
Paul Bakker3aac1da2012-05-08 13:12:27 +0000477 return;
478 }
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200479 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED) )
480 mbedtls_snprintf( buf, buflen, "SSL - Verification of our peer failed" );
481 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) )
482 mbedtls_snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
483 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO) )
484 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
485 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO) )
486 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
487 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE) )
488 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
489 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
490 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
491 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
492 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
493 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
494 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
495 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
496 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
497 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
498 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
499 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
500 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
501 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
502 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
503 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
504 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
505 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED) )
506 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200507 if( use_ret == -(MBEDTLS_ERR_SSL_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200508 mbedtls_snprintf( buf, buflen, "SSL - Memory allocation failed" );
509 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED) )
510 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
511 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
512 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
513 if( use_ret == -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED) )
514 mbedtls_snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
515 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
516 mbedtls_snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
517 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
518 mbedtls_snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
519 if( use_ret == -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED) )
520 mbedtls_snprintf( buf, buflen, "SSL - Session ticket has expired" );
521 if( use_ret == -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH) )
522 mbedtls_snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
523 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY) )
524 mbedtls_snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
525 if( use_ret == -(MBEDTLS_ERR_SSL_INTERNAL_ERROR) )
526 mbedtls_snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
527 if( use_ret == -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING) )
528 mbedtls_snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
529 if( use_ret == -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO) )
530 mbedtls_snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" );
531 if( use_ret == -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED) )
532 mbedtls_snprintf( buf, buflen, "SSL - DTLS client must retry for hello verification" );
533 if( use_ret == -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL) )
534 mbedtls_snprintf( buf, buflen, "SSL - A buffer is too small to receive or write a message" );
535 if( use_ret == -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE) )
536 mbedtls_snprintf( buf, buflen, "SSL - None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages)" );
Manuel Pégourié-Gonnard88369942015-05-06 16:19:31 +0100537 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_READ) )
Hanno Becker8ec81022017-10-10 10:35:08 +0100538 mbedtls_snprintf( buf, buflen, "SSL - No data of requested type currently available on underlying transport" );
Manuel Pégourié-Gonnard88369942015-05-06 16:19:31 +0100539 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_WRITE) )
540 mbedtls_snprintf( buf, buflen, "SSL - Connection requires a write call" );
541 if( use_ret == -(MBEDTLS_ERR_SSL_TIMEOUT) )
542 mbedtls_snprintf( buf, buflen, "SSL - The operation timed out" );
Manuel Pégourié-Gonnardbe619c12015-09-08 11:21:21 +0200543 if( use_ret == -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT) )
544 mbedtls_snprintf( buf, buflen, "SSL - The client initiated a reconnect from the same port" );
Manuel Pégourié-Gonnarde2e25e72015-12-03 16:13:17 +0100545 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD) )
546 mbedtls_snprintf( buf, buflen, "SSL - Record header looks valid but is not expected" );
Simon Butcher99000142016-10-13 17:21:01 +0100547 if( use_ret == -(MBEDTLS_ERR_SSL_NON_FATAL) )
548 mbedtls_snprintf( buf, buflen, "SSL - The alert message received indicates a non-fatal error" );
549 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH) )
550 mbedtls_snprintf( buf, buflen, "SSL - Couldn't set the hash for verifying CertificateVerify" );
Hanno Becker8ec81022017-10-10 10:35:08 +0100551 if( use_ret == -(MBEDTLS_ERR_SSL_CONTINUE_PROCESSING) )
Hanno Beckerc9f4d6d2018-03-19 09:23:13 +0000552 mbedtls_snprintf( buf, buflen, "SSL - Internal-only message signaling that further message-processing should be done" );
Gilles Peskine8bf79f62018-01-05 21:11:53 +0100553 if( use_ret == -(MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS) )
Gilles Peskineb44692f2018-04-24 12:18:19 +0200554 mbedtls_snprintf( buf, buflen, "SSL - The asynchronous operation is not completed yet" );
Hanno Beckerb063a5f2018-08-16 16:06:44 +0100555 if( use_ret == -(MBEDTLS_ERR_SSL_EARLY_MESSAGE) )
556 mbedtls_snprintf( buf, buflen, "SSL - Internal-only message signaling that a message arrived early" );
Manuel Pégourié-Gonnard558da9c2018-06-13 12:02:12 +0200557 if( use_ret == -(MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS) )
558 mbedtls_snprintf( buf, buflen, "SSL - A cryptographic operation is in progress. Try again later" );
Hanno Beckerd7296022017-04-12 14:54:42 +0100559 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_CONFIG) )
560 mbedtls_snprintf( buf, buflen, "SSL - Invalid value in SSL config" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200561#endif /* MBEDTLS_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000562
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200563#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
564 if( use_ret == -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) )
565 mbedtls_snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
566 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_OID) )
567 mbedtls_snprintf( buf, buflen, "X509 - Requested OID is unknown" );
568 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_FORMAT) )
569 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
570 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_VERSION) )
571 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
572 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SERIAL) )
573 mbedtls_snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
574 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_ALG) )
575 mbedtls_snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
576 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_NAME) )
577 mbedtls_snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
578 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_DATE) )
579 mbedtls_snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
580 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SIGNATURE) )
581 mbedtls_snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
582 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS) )
583 mbedtls_snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
584 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_VERSION) )
585 mbedtls_snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
586 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG) )
587 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
588 if( use_ret == -(MBEDTLS_ERR_X509_SIG_MISMATCH) )
589 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" );
590 if( use_ret == -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) )
591 mbedtls_snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
592 if( use_ret == -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT) )
593 mbedtls_snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
594 if( use_ret == -(MBEDTLS_ERR_X509_BAD_INPUT_DATA) )
595 mbedtls_snprintf( buf, buflen, "X509 - Input invalid" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200596 if( use_ret == -(MBEDTLS_ERR_X509_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200597 mbedtls_snprintf( buf, buflen, "X509 - Allocation of memory failed" );
598 if( use_ret == -(MBEDTLS_ERR_X509_FILE_IO_ERROR) )
599 mbedtls_snprintf( buf, buflen, "X509 - Read/write of file failed" );
Manuel Pégourié-Gonnard9dbaf402015-06-22 11:50:58 +0200600 if( use_ret == -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL) )
601 mbedtls_snprintf( buf, buflen, "X509 - Destination buffer is too small" );
Manuel Pégourié-Gonnard31458a12017-06-26 10:11:49 +0200602 if( use_ret == -(MBEDTLS_ERR_X509_FATAL_ERROR) )
Antonin Décimod5f47592019-01-23 15:24:37 +0100603 mbedtls_snprintf( buf, buflen, "X509 - A fatal error occurred, eg the chain is too long or the vrfy callback failed" );
Manuel Pégourié-Gonnarde546ad42015-04-08 20:27:02 +0200604#endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200605 // END generated code
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200606
Paul Bakker9d781402011-05-09 16:17:09 +0000607 if( strlen( buf ) == 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200608 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000609 }
610
611 use_ret = ret & ~0xFF80;
612
613 if( use_ret == 0 )
614 return;
615
616 // If high level code is present, make a concatenation between both
617 // error strings.
618 //
619 len = strlen( buf );
620
621 if( len > 0 )
622 {
623 if( buflen - len < 5 )
624 return;
625
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200626 mbedtls_snprintf( buf + len, buflen - len, " : " );
Paul Bakker9d781402011-05-09 16:17:09 +0000627
628 buf += len + 3;
629 buflen -= len + 3;
630 }
631
632 // Low level error codes
633 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200634 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200635#if defined(MBEDTLS_AES_C)
636 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH) )
637 mbedtls_snprintf( buf, buflen, "AES - Invalid key length" );
638 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH) )
639 mbedtls_snprintf( buf, buflen, "AES - Invalid data input length" );
Mohammad Azim Khane5b5bd72017-11-24 10:52:51 +0000640 if( use_ret == -(MBEDTLS_ERR_AES_BAD_INPUT_DATA) )
641 mbedtls_snprintf( buf, buflen, "AES - Invalid input data" );
Andres Amaya Garciafd487392017-06-14 16:19:12 +0100642 if( use_ret == -(MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE) )
Rose Zadik7f441272018-01-22 11:48:23 +0000643 mbedtls_snprintf( buf, buflen, "AES - Feature not available. For example, an unsupported AES key size" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100644 if( use_ret == -(MBEDTLS_ERR_AES_HW_ACCEL_FAILED) )
645 mbedtls_snprintf( buf, buflen, "AES - AES hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200646#endif /* MBEDTLS_AES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000647
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100648#if defined(MBEDTLS_ARC4_C)
649 if( use_ret == -(MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED) )
650 mbedtls_snprintf( buf, buflen, "ARC4 - ARC4 hardware accelerator failed" );
651#endif /* MBEDTLS_ARC4_C */
652
Markku-Juhani O. Saarinen07478d62017-12-01 16:20:15 +0000653#if defined(MBEDTLS_ARIA_C)
Hanno Becker32142152018-12-17 13:25:58 +0000654 if( use_ret == -(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA) )
655 mbedtls_snprintf( buf, buflen, "ARIA - Bad input data" );
Hanno Beckera0343692018-12-18 09:42:58 +0000656 if( use_ret == -(MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH) )
657 mbedtls_snprintf( buf, buflen, "ARIA - Invalid data input length" );
Manuel Pégourié-Gonnard3c800092018-03-01 09:02:16 +0100658 if( use_ret == -(MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE) )
659 mbedtls_snprintf( buf, buflen, "ARIA - Feature not available. For example, an unsupported ARIA key size" );
660 if( use_ret == -(MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED) )
661 mbedtls_snprintf( buf, buflen, "ARIA - ARIA hardware accelerator failed" );
Markku-Juhani O. Saarinen07478d62017-12-01 16:20:15 +0000662#endif /* MBEDTLS_ARIA_C */
663
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200664#if defined(MBEDTLS_ASN1_PARSE_C)
665 if( use_ret == -(MBEDTLS_ERR_ASN1_OUT_OF_DATA) )
666 mbedtls_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
667 if( use_ret == -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) )
668 mbedtls_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
669 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_LENGTH) )
670 mbedtls_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
671 if( use_ret == -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH) )
672 mbedtls_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
673 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_DATA) )
674 mbedtls_snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200675 if( use_ret == -(MBEDTLS_ERR_ASN1_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200676 mbedtls_snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
677 if( use_ret == -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL) )
678 mbedtls_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
679#endif /* MBEDTLS_ASN1_PARSE_C */
Paul Bakkerdceecd82011-11-15 16:38:34 +0000680
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200681#if defined(MBEDTLS_BASE64_C)
682 if( use_ret == -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) )
683 mbedtls_snprintf( buf, buflen, "BASE64 - Output buffer too small" );
684 if( use_ret == -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER) )
685 mbedtls_snprintf( buf, buflen, "BASE64 - Invalid character in input" );
686#endif /* MBEDTLS_BASE64_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000687
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200688#if defined(MBEDTLS_BIGNUM_C)
689 if( use_ret == -(MBEDTLS_ERR_MPI_FILE_IO_ERROR) )
690 mbedtls_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
691 if( use_ret == -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA) )
692 mbedtls_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
693 if( use_ret == -(MBEDTLS_ERR_MPI_INVALID_CHARACTER) )
694 mbedtls_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
695 if( use_ret == -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL) )
696 mbedtls_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
697 if( use_ret == -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE) )
698 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
699 if( use_ret == -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO) )
700 mbedtls_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
701 if( use_ret == -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) )
702 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200703 if( use_ret == -(MBEDTLS_ERR_MPI_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200704 mbedtls_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
705#endif /* MBEDTLS_BIGNUM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000706
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200707#if defined(MBEDTLS_BLOWFISH_C)
Hanno Becker32142152018-12-17 13:25:58 +0000708 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA) )
709 mbedtls_snprintf( buf, buflen, "BLOWFISH - Bad input data" );
Hanno Becker6640b0d2018-12-18 09:45:17 +0000710 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
711 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100712 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED) )
713 mbedtls_snprintf( buf, buflen, "BLOWFISH - Blowfish hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200714#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker83f00bb2012-07-04 11:08:50 +0000715
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200716#if defined(MBEDTLS_CAMELLIA_C)
Hanno Becker32142152018-12-17 13:25:58 +0000717 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA) )
718 mbedtls_snprintf( buf, buflen, "CAMELLIA - Bad input data" );
Hanno Becker938f9e92018-12-18 09:40:25 +0000719 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
720 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100721 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED) )
722 mbedtls_snprintf( buf, buflen, "CAMELLIA - Camellia hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200723#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000724
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200725#if defined(MBEDTLS_CCM_C)
726 if( use_ret == -(MBEDTLS_ERR_CCM_BAD_INPUT) )
Rose Zadikeecdbea2018-01-24 12:56:53 +0000727 mbedtls_snprintf( buf, buflen, "CCM - Bad input parameters to the function" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200728 if( use_ret == -(MBEDTLS_ERR_CCM_AUTH_FAILED) )
729 mbedtls_snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100730 if( use_ret == -(MBEDTLS_ERR_CCM_HW_ACCEL_FAILED) )
731 mbedtls_snprintf( buf, buflen, "CCM - CCM hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200732#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200733
Daniel King34b822c2016-05-15 17:28:08 -0300734#if defined(MBEDTLS_CHACHA20_C)
735 if( use_ret == -(MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA) )
736 mbedtls_snprintf( buf, buflen, "CHACHA20 - Invalid input parameter(s)" );
Manuel Pégourié-Gonnardb8bd80a2018-05-09 09:54:51 +0200737 if( use_ret == -(MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE) )
738 mbedtls_snprintf( buf, buflen, "CHACHA20 - Feature not available. For example, s part of the API is not implemented" );
Manuel Pégourié-Gonnard3798b6b2018-05-24 13:27:45 +0200739 if( use_ret == -(MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED) )
740 mbedtls_snprintf( buf, buflen, "CHACHA20 - Chacha20 hardware accelerator failed" );
Daniel King34b822c2016-05-15 17:28:08 -0300741#endif /* MBEDTLS_CHACHA20_C */
742
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200743#if defined(MBEDTLS_CHACHAPOLY_C)
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200744 if( use_ret == -(MBEDTLS_ERR_CHACHAPOLY_BAD_STATE) )
745 mbedtls_snprintf( buf, buflen, "CHACHAPOLY - The requested operation is not permitted in the current state" );
Manuel Pégourié-Gonnardb8bd80a2018-05-09 09:54:51 +0200746 if( use_ret == -(MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED) )
747 mbedtls_snprintf( buf, buflen, "CHACHAPOLY - Authenticated decryption failed: data was not authentic" );
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200748#endif /* MBEDTLS_CHACHAPOLY_C */
749
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100750#if defined(MBEDTLS_CMAC_C)
751 if( use_ret == -(MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED) )
752 mbedtls_snprintf( buf, buflen, "CMAC - CMAC hardware accelerator failed" );
753#endif /* MBEDTLS_CMAC_C */
754
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200755#if defined(MBEDTLS_CTR_DRBG_C)
756 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
757 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
758 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000759 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The requested random buffer length is too big" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200760 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000761 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The input (entropy + additional data) is too large" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200762 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000763 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Read or write error in file" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200764#endif /* MBEDTLS_CTR_DRBG_C */
Paul Bakker880ac7e2011-11-27 14:50:49 +0000765
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200766#if defined(MBEDTLS_DES_C)
767 if( use_ret == -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH) )
768 mbedtls_snprintf( buf, buflen, "DES - The data input has an invalid length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100769 if( use_ret == -(MBEDTLS_ERR_DES_HW_ACCEL_FAILED) )
770 mbedtls_snprintf( buf, buflen, "DES - DES hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200771#endif /* MBEDTLS_DES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000772
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200773#if defined(MBEDTLS_ENTROPY_C)
774 if( use_ret == -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED) )
775 mbedtls_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
776 if( use_ret == -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES) )
777 mbedtls_snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
778 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED) )
779 mbedtls_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
Manuel Pégourié-Gonnardf9cbd732015-06-22 12:06:50 +0200780 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE) )
781 mbedtls_snprintf( buf, buflen, "ENTROPY - No strong sources have been added to poll" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200782 if( use_ret == -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR) )
783 mbedtls_snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
784#endif /* MBEDTLS_ENTROPY_C */
Paul Bakker6083fd22011-12-03 21:45:14 +0000785
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200786#if defined(MBEDTLS_GCM_C)
787 if( use_ret == -(MBEDTLS_ERR_GCM_AUTH_FAILED) )
788 mbedtls_snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100789 if( use_ret == -(MBEDTLS_ERR_GCM_HW_ACCEL_FAILED) )
790 mbedtls_snprintf( buf, buflen, "GCM - GCM hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200791 if( use_ret == -(MBEDTLS_ERR_GCM_BAD_INPUT) )
792 mbedtls_snprintf( buf, buflen, "GCM - Bad input parameters to function" );
793#endif /* MBEDTLS_GCM_C */
Paul Bakker030277a2012-04-17 12:24:26 +0000794
Thomas Fossati656864b2016-07-17 08:51:22 +0100795#if defined(MBEDTLS_HKDF_C)
796 if( use_ret == -(MBEDTLS_ERR_HKDF_BAD_INPUT_DATA) )
797 mbedtls_snprintf( buf, buflen, "HKDF - Bad input parameters to function" );
798#endif /* MBEDTLS_HKDF_C */
799
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200800#if defined(MBEDTLS_HMAC_DRBG_C)
801 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
802 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
803 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
804 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
805 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR) )
806 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
807 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
808 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
809#endif /* MBEDTLS_HMAC_DRBG_C */
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100810
Gilles Peskinea381fe82018-01-23 18:16:11 +0100811#if defined(MBEDTLS_MD2_C)
812 if( use_ret == -(MBEDTLS_ERR_MD2_HW_ACCEL_FAILED) )
813 mbedtls_snprintf( buf, buflen, "MD2 - MD2 hardware accelerator failed" );
814#endif /* MBEDTLS_MD2_C */
815
816#if defined(MBEDTLS_MD4_C)
817 if( use_ret == -(MBEDTLS_ERR_MD4_HW_ACCEL_FAILED) )
818 mbedtls_snprintf( buf, buflen, "MD4 - MD4 hardware accelerator failed" );
819#endif /* MBEDTLS_MD4_C */
820
821#if defined(MBEDTLS_MD5_C)
822 if( use_ret == -(MBEDTLS_ERR_MD5_HW_ACCEL_FAILED) )
823 mbedtls_snprintf( buf, buflen, "MD5 - MD5 hardware accelerator failed" );
824#endif /* MBEDTLS_MD5_C */
825
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200826#if defined(MBEDTLS_NET_C)
827 if( use_ret == -(MBEDTLS_ERR_NET_SOCKET_FAILED) )
828 mbedtls_snprintf( buf, buflen, "NET - Failed to open a socket" );
829 if( use_ret == -(MBEDTLS_ERR_NET_CONNECT_FAILED) )
830 mbedtls_snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
831 if( use_ret == -(MBEDTLS_ERR_NET_BIND_FAILED) )
832 mbedtls_snprintf( buf, buflen, "NET - Binding of the socket failed" );
833 if( use_ret == -(MBEDTLS_ERR_NET_LISTEN_FAILED) )
834 mbedtls_snprintf( buf, buflen, "NET - Could not listen on the socket" );
835 if( use_ret == -(MBEDTLS_ERR_NET_ACCEPT_FAILED) )
836 mbedtls_snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
837 if( use_ret == -(MBEDTLS_ERR_NET_RECV_FAILED) )
838 mbedtls_snprintf( buf, buflen, "NET - Reading information from the socket failed" );
839 if( use_ret == -(MBEDTLS_ERR_NET_SEND_FAILED) )
840 mbedtls_snprintf( buf, buflen, "NET - Sending information through the socket failed" );
841 if( use_ret == -(MBEDTLS_ERR_NET_CONN_RESET) )
842 mbedtls_snprintf( buf, buflen, "NET - Connection was reset by peer" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200843 if( use_ret == -(MBEDTLS_ERR_NET_UNKNOWN_HOST) )
844 mbedtls_snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
Manuel Pégourié-Gonnard0b104b02015-05-14 21:52:40 +0200845 if( use_ret == -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL) )
846 mbedtls_snprintf( buf, buflen, "NET - Buffer is too small to hold the data" );
Manuel Pégourié-Gonnard9bd0afd2015-07-01 19:03:27 +0200847 if( use_ret == -(MBEDTLS_ERR_NET_INVALID_CONTEXT) )
848 mbedtls_snprintf( buf, buflen, "NET - The context is invalid, eg because it was free()ed" );
Hanno Beckere09ca3d2017-05-22 15:06:06 +0100849 if( use_ret == -(MBEDTLS_ERR_NET_POLL_FAILED) )
850 mbedtls_snprintf( buf, buflen, "NET - Polling the net context failed" );
851 if( use_ret == -(MBEDTLS_ERR_NET_BAD_INPUT_DATA) )
852 mbedtls_snprintf( buf, buflen, "NET - Input invalid" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200853#endif /* MBEDTLS_NET_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000854
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200855#if defined(MBEDTLS_OID_C)
856 if( use_ret == -(MBEDTLS_ERR_OID_NOT_FOUND) )
857 mbedtls_snprintf( buf, buflen, "OID - OID is not found" );
858 if( use_ret == -(MBEDTLS_ERR_OID_BUF_TOO_SMALL) )
859 mbedtls_snprintf( buf, buflen, "OID - output buffer is too small" );
860#endif /* MBEDTLS_OID_C */
Paul Bakkerc70b9822013-04-07 22:00:46 +0200861
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200862#if defined(MBEDTLS_PADLOCK_C)
863 if( use_ret == -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED) )
864 mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
865#endif /* MBEDTLS_PADLOCK_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000866
Ron Eldor0ff4e0b2018-08-29 18:53:20 +0300867#if defined(MBEDTLS_PLATFORM_C)
Ron Eldora27190b2018-10-15 16:33:43 +0300868 if( use_ret == -(MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED) )
Ron Eldor5267b622018-10-15 18:44:42 +0300869 mbedtls_snprintf( buf, buflen, "PLATFORM - Hardware accelerator failed" );
Ron Eldorbcca58c2018-10-03 16:33:21 +0300870 if( use_ret == -(MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) )
871 mbedtls_snprintf( buf, buflen, "PLATFORM - The requested feature is not supported by the platform" );
Ron Eldor0ff4e0b2018-08-29 18:53:20 +0300872#endif /* MBEDTLS_PLATFORM_C */
873
Daniel Kingadc32c02016-05-16 18:25:45 -0300874#if defined(MBEDTLS_POLY1305_C)
875 if( use_ret == -(MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA) )
876 mbedtls_snprintf( buf, buflen, "POLY1305 - Invalid input parameter(s)" );
Manuel Pégourié-Gonnardb8bd80a2018-05-09 09:54:51 +0200877 if( use_ret == -(MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE) )
878 mbedtls_snprintf( buf, buflen, "POLY1305 - Feature not available. For example, s part of the API is not implemented" );
Manuel Pégourié-Gonnard3798b6b2018-05-24 13:27:45 +0200879 if( use_ret == -(MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED) )
880 mbedtls_snprintf( buf, buflen, "POLY1305 - Poly1305 hardware accelerator failed" );
Daniel Kingadc32c02016-05-16 18:25:45 -0300881#endif /* MBEDTLS_POLY1305_C */
882
Gilles Peskinea381fe82018-01-23 18:16:11 +0100883#if defined(MBEDTLS_RIPEMD160_C)
884 if( use_ret == -(MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED) )
885 mbedtls_snprintf( buf, buflen, "RIPEMD160 - RIPEMD160 hardware accelerator failed" );
886#endif /* MBEDTLS_RIPEMD160_C */
887
888#if defined(MBEDTLS_SHA1_C)
889 if( use_ret == -(MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED) )
890 mbedtls_snprintf( buf, buflen, "SHA1 - SHA-1 hardware accelerator failed" );
Andres Amaya Garciaa685d4f2018-12-09 19:13:01 +0000891 if( use_ret == -(MBEDTLS_ERR_SHA1_BAD_INPUT_DATA) )
Hanno Becker859522a2018-12-19 09:54:14 +0000892 mbedtls_snprintf( buf, buflen, "SHA1 - SHA-1 input data was malformed" );
Gilles Peskinea381fe82018-01-23 18:16:11 +0100893#endif /* MBEDTLS_SHA1_C */
894
895#if defined(MBEDTLS_SHA256_C)
896 if( use_ret == -(MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED) )
897 mbedtls_snprintf( buf, buflen, "SHA256 - SHA-256 hardware accelerator failed" );
Andres Amaya Garcia9e76c0e2018-12-09 20:42:05 +0000898 if( use_ret == -(MBEDTLS_ERR_SHA256_BAD_INPUT_DATA) )
Hanno Beckerd8e4f4a2018-12-19 09:54:55 +0000899 mbedtls_snprintf( buf, buflen, "SHA256 - SHA-256 input data was malformed" );
Gilles Peskinea381fe82018-01-23 18:16:11 +0100900#endif /* MBEDTLS_SHA256_C */
901
902#if defined(MBEDTLS_SHA512_C)
903 if( use_ret == -(MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED) )
904 mbedtls_snprintf( buf, buflen, "SHA512 - SHA-512 hardware accelerator failed" );
Andres Amaya Garcia863d4832018-12-09 20:58:52 +0000905 if( use_ret == -(MBEDTLS_ERR_SHA512_BAD_INPUT_DATA) )
Hanno Becker9994e0d2018-12-19 09:55:40 +0000906 mbedtls_snprintf( buf, buflen, "SHA512 - SHA-512 input data was malformed" );
Gilles Peskinea381fe82018-01-23 18:16:11 +0100907#endif /* MBEDTLS_SHA512_C */
908
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200909#if defined(MBEDTLS_THREADING_C)
910 if( use_ret == -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE) )
911 mbedtls_snprintf( buf, buflen, "THREADING - The selected feature is not available" );
912 if( use_ret == -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA) )
913 mbedtls_snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
914 if( use_ret == -(MBEDTLS_ERR_THREADING_MUTEX_ERROR) )
915 mbedtls_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
916#endif /* MBEDTLS_THREADING_C */
Paul Bakker2466d932013-09-28 14:40:38 +0200917
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200918#if defined(MBEDTLS_XTEA_C)
919 if( use_ret == -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH) )
920 mbedtls_snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100921 if( use_ret == -(MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED) )
922 mbedtls_snprintf( buf, buflen, "XTEA - XTEA hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200923#endif /* MBEDTLS_XTEA_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200924 // END generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000925
926 if( strlen( buf ) != 0 )
927 return;
928
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200929 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000930}
931
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200932#else /* MBEDTLS_ERROR_C */
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100933
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200934#if defined(MBEDTLS_ERROR_STRERROR_DUMMY)
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100935
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100936/*
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200937 * Provide an non-function in case MBEDTLS_ERROR_C is not defined
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100938 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200939void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100940{
941 ((void) ret);
942
943 if( buflen > 0 )
944 buf[0] = '\0';
945}
946
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200947#endif /* MBEDTLS_ERROR_STRERROR_DUMMY */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200948
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200949#endif /* MBEDTLS_ERROR_C */