blob: 9b04dcd2067fc3f76e84a245e40c7beb5b694b67 [file] [log] [blame]
Paul Bakker9d781402011-05-09 16:17:09 +00001/*
2 * Error message information
3 *
Bence Szépkúti44bfbe32020-08-19 16:54:51 +02004 * Copyright The Mbed TLS Contributors
Bence Szépkúti4e9f7122020-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úti4e9f7122020-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 * **********
Paul Bakker9d781402011-05-09 16:17:09 +000045 */
46
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020047#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000048#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020049#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020050#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020051#endif
Paul Bakker9d781402011-05-09 16:17:09 +000052
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020053#if defined(MBEDTLS_ERROR_C) || defined(MBEDTLS_ERROR_STRERROR_DUMMY)
Gilles Peskine4159c712020-11-09 15:14:10 +010054
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000055#include "mbedtls/error.h"
Gilles Peskine4159c712020-11-09 15:14:10 +010056
57#if defined(MBEDTLS_ERROR_C)
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020058
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000060#include "mbedtls/platform.h"
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +000061#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020062#define mbedtls_snprintf snprintf
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020063#endif
64
Rich Evans00ab4702015-02-06 13:43:58 +000065#include <stdio.h>
Gilles Peskine4159c712020-11-09 15:14:10 +010066#include <string.h>
Rich Evans00ab4702015-02-06 13:43:58 +000067
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000069#include "mbedtls/aes.h"
Paul Bakker9d781402011-05-09 16:17:09 +000070#endif
71
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010072#if defined(MBEDTLS_ARC4_C)
73#include "mbedtls/arc4.h"
74#endif
75
Gilles Peskineac631bb2020-05-25 12:23:55 +020076#if defined(MBEDTLS_ASN1_PARSE_C)
77#include "mbedtls/asn1.h"
78#endif
79
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020080#if defined(MBEDTLS_BASE64_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000081#include "mbedtls/base64.h"
Paul Bakker9d781402011-05-09 16:17:09 +000082#endif
83
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020084#if defined(MBEDTLS_BIGNUM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000085#include "mbedtls/bignum.h"
Paul Bakker9d781402011-05-09 16:17:09 +000086#endif
87
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020088#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000089#include "mbedtls/blowfish.h"
Paul Bakker83f00bb2012-07-04 11:08:50 +000090#endif
91
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000093#include "mbedtls/camellia.h"
Paul Bakker9d781402011-05-09 16:17:09 +000094#endif
95
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000097#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +020098#endif
99
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200100#if defined(MBEDTLS_CIPHER_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000101#include "mbedtls/cipher.h"
Paul Bakkerff61a782011-06-09 15:42:02 +0000102#endif
103
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100104#if defined(MBEDTLS_CMAC_C)
105#include "mbedtls/cmac.h"
106#endif
107
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200108#if defined(MBEDTLS_CTR_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000109#include "mbedtls/ctr_drbg.h"
Paul Bakker880ac7e2011-11-27 14:50:49 +0000110#endif
111
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200112#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000113#include "mbedtls/des.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000114#endif
115
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200116#if defined(MBEDTLS_DHM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000117#include "mbedtls/dhm.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000118#endif
119
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200120#if defined(MBEDTLS_ECP_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000121#include "mbedtls/ecp.h"
Paul Bakkercf4365f2013-01-16 17:00:43 +0100122#endif
123
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124#if defined(MBEDTLS_ENTROPY_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000125#include "mbedtls/entropy.h"
Paul Bakker6083fd22011-12-03 21:45:14 +0000126#endif
127
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000129#include "mbedtls/gcm.h"
Paul Bakker030277a2012-04-17 12:24:26 +0000130#endif
131
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200132#if defined(MBEDTLS_HMAC_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000133#include "mbedtls/hmac_drbg.h"
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100134#endif
135
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200136#if defined(MBEDTLS_MD_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000137#include "mbedtls/md.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000138#endif
139
Gilles Peskinea381fe82018-01-23 18:16:11 +0100140#if defined(MBEDTLS_MD2_C)
141#include "mbedtls/md2.h"
142#endif
143
144#if defined(MBEDTLS_MD4_C)
145#include "mbedtls/md4.h"
146#endif
147
148#if defined(MBEDTLS_MD5_C)
149#include "mbedtls/md5.h"
150#endif
151
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200152#if defined(MBEDTLS_NET_C)
Andres AG3616f6f2016-09-14 14:32:09 +0100153#include "mbedtls/net_sockets.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000154#endif
155
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200156#if defined(MBEDTLS_OID_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000157#include "mbedtls/oid.h"
Paul Bakkerc70b9822013-04-07 22:00:46 +0200158#endif
159
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200160#if defined(MBEDTLS_PADLOCK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000161#include "mbedtls/padlock.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000162#endif
163
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200164#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000165#include "mbedtls/pem.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000166#endif
167
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200168#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000169#include "mbedtls/pk.h"
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200170#endif
171
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200172#if defined(MBEDTLS_PKCS12_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000173#include "mbedtls/pkcs12.h"
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200174#endif
175
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200176#if defined(MBEDTLS_PKCS5_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000177#include "mbedtls/pkcs5.h"
Paul Bakkerb0c19a42013-06-24 19:26:38 +0200178#endif
179
Gilles Peskinea381fe82018-01-23 18:16:11 +0100180#if defined(MBEDTLS_RIPEMD160_C)
181#include "mbedtls/ripemd160.h"
182#endif
183
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200184#if defined(MBEDTLS_RSA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000185#include "mbedtls/rsa.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000186#endif
187
Gilles Peskinea381fe82018-01-23 18:16:11 +0100188#if defined(MBEDTLS_SHA1_C)
189#include "mbedtls/sha1.h"
190#endif
191
192#if defined(MBEDTLS_SHA256_C)
193#include "mbedtls/sha256.h"
194#endif
195
196#if defined(MBEDTLS_SHA512_C)
197#include "mbedtls/sha512.h"
198#endif
199
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200200#if defined(MBEDTLS_SSL_TLS_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000201#include "mbedtls/ssl.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000202#endif
203
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200204#if defined(MBEDTLS_THREADING_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000205#include "mbedtls/threading.h"
Paul Bakker2466d932013-09-28 14:40:38 +0200206#endif
207
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200208#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000209#include "mbedtls/x509.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000210#endif
211
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200212#if defined(MBEDTLS_XTEA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000213#include "mbedtls/xtea.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000214#endif
215
Paul Bakkerdceecd82011-11-15 16:38:34 +0000216
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200217void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker9d781402011-05-09 16:17:09 +0000218{
219 size_t len;
220 int use_ret;
221
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200222 if( buflen == 0 )
223 return;
224
Paul Bakker9d781402011-05-09 16:17:09 +0000225 memset( buf, 0x00, buflen );
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200226
Paul Bakker9d781402011-05-09 16:17:09 +0000227 if( ret < 0 )
228 ret = -ret;
229
230 if( ret & 0xFF80 )
231 {
232 use_ret = ret & 0xFF80;
233
234 // High level error codes
235 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200236 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200237#if defined(MBEDTLS_CIPHER_C)
238 if( use_ret == -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE) )
239 mbedtls_snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
240 if( use_ret == -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA) )
Rose Zadik9ba6b622018-01-24 12:59:19 +0000241 mbedtls_snprintf( buf, buflen, "CIPHER - Bad input parameters" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200242 if( use_ret == -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED) )
243 mbedtls_snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
244 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_PADDING) )
245 mbedtls_snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
246 if( use_ret == -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
247 mbedtls_snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
248 if( use_ret == -(MBEDTLS_ERR_CIPHER_AUTH_FAILED) )
249 mbedtls_snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
Janos Follath98e28a72016-05-31 14:03:54 +0100250 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT) )
Rose Zadik9ba6b622018-01-24 12:59:19 +0000251 mbedtls_snprintf( buf, buflen, "CIPHER - The context is invalid. For example, because it was freed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100252 if( use_ret == -(MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED) )
253 mbedtls_snprintf( buf, buflen, "CIPHER - Cipher hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200254#endif /* MBEDTLS_CIPHER_C */
Paul Bakkerff61a782011-06-09 15:42:02 +0000255
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200256#if defined(MBEDTLS_DHM_C)
257 if( use_ret == -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA) )
Rose Zadik41ad0822018-01-26 10:54:57 +0000258 mbedtls_snprintf( buf, buflen, "DHM - Bad input parameters" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200259 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED) )
260 mbedtls_snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
261 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED) )
262 mbedtls_snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
263 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED) )
264 mbedtls_snprintf( buf, buflen, "DHM - Reading of the public values failed" );
265 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED) )
266 mbedtls_snprintf( buf, buflen, "DHM - Making of the public value failed" );
267 if( use_ret == -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED) )
268 mbedtls_snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
269 if( use_ret == -(MBEDTLS_ERR_DHM_INVALID_FORMAT) )
270 mbedtls_snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200271 if( use_ret == -(MBEDTLS_ERR_DHM_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200272 mbedtls_snprintf( buf, buflen, "DHM - Allocation of memory failed" );
273 if( use_ret == -(MBEDTLS_ERR_DHM_FILE_IO_ERROR) )
Rose Zadik41ad0822018-01-26 10:54:57 +0000274 mbedtls_snprintf( buf, buflen, "DHM - Read or write of file failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100275 if( use_ret == -(MBEDTLS_ERR_DHM_HW_ACCEL_FAILED) )
276 mbedtls_snprintf( buf, buflen, "DHM - DHM hardware accelerator failed" );
Hanno Beckera6dd90d2017-10-04 13:15:54 +0100277 if( use_ret == -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED) )
Jaeden Amero784de592018-01-26 17:52:01 +0000278 mbedtls_snprintf( buf, buflen, "DHM - Setting the modulus and generator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200279#endif /* MBEDTLS_DHM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000280
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200281#if defined(MBEDTLS_ECP_C)
282 if( use_ret == -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA) )
283 mbedtls_snprintf( buf, buflen, "ECP - Bad input parameters to function" );
284 if( use_ret == -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL) )
285 mbedtls_snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
286 if( use_ret == -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) )
287 mbedtls_snprintf( buf, buflen, "ECP - Requested curve not available" );
288 if( use_ret == -(MBEDTLS_ERR_ECP_VERIFY_FAILED) )
289 mbedtls_snprintf( buf, buflen, "ECP - The signature is not valid" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200290 if( use_ret == -(MBEDTLS_ERR_ECP_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200291 mbedtls_snprintf( buf, buflen, "ECP - Memory allocation failed" );
292 if( use_ret == -(MBEDTLS_ERR_ECP_RANDOM_FAILED) )
293 mbedtls_snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
294 if( use_ret == -(MBEDTLS_ERR_ECP_INVALID_KEY) )
295 mbedtls_snprintf( buf, buflen, "ECP - Invalid private or public key" );
296 if( use_ret == -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) )
Gilles Peskinecc78ac42018-03-30 18:52:10 +0200297 mbedtls_snprintf( buf, buflen, "ECP - The buffer contains a valid signature followed by more data" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100298 if( use_ret == -(MBEDTLS_ERR_ECP_HW_ACCEL_FAILED) )
299 mbedtls_snprintf( buf, buflen, "ECP - ECP hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200300#endif /* MBEDTLS_ECP_C */
Paul Bakkercf4365f2013-01-16 17:00:43 +0100301
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200302#if defined(MBEDTLS_MD_C)
303 if( use_ret == -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE) )
304 mbedtls_snprintf( buf, buflen, "MD - The selected feature is not available" );
305 if( use_ret == -(MBEDTLS_ERR_MD_BAD_INPUT_DATA) )
306 mbedtls_snprintf( buf, buflen, "MD - Bad input parameters to function" );
307 if( use_ret == -(MBEDTLS_ERR_MD_ALLOC_FAILED) )
308 mbedtls_snprintf( buf, buflen, "MD - Failed to allocate memory" );
309 if( use_ret == -(MBEDTLS_ERR_MD_FILE_IO_ERROR) )
310 mbedtls_snprintf( buf, buflen, "MD - Opening or reading of file failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100311 if( use_ret == -(MBEDTLS_ERR_MD_HW_ACCEL_FAILED) )
312 mbedtls_snprintf( buf, buflen, "MD - MD hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200313#endif /* MBEDTLS_MD_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000314
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200315#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
316 if( use_ret == -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
317 mbedtls_snprintf( buf, buflen, "PEM - No PEM header or footer found" );
318 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_DATA) )
319 mbedtls_snprintf( buf, buflen, "PEM - PEM string is not as expected" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200320 if( use_ret == -(MBEDTLS_ERR_PEM_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200321 mbedtls_snprintf( buf, buflen, "PEM - Failed to allocate memory" );
322 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_ENC_IV) )
323 mbedtls_snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
324 if( use_ret == -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG) )
325 mbedtls_snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
326 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) )
327 mbedtls_snprintf( buf, buflen, "PEM - Private key password can't be empty" );
328 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) )
329 mbedtls_snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
330 if( use_ret == -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE) )
331 mbedtls_snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
332 if( use_ret == -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA) )
333 mbedtls_snprintf( buf, buflen, "PEM - Bad input parameters to function" );
334#endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000335
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200336#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200337 if( use_ret == -(MBEDTLS_ERR_PK_ALLOC_FAILED) )
Manuel Pégourié-Gonnard41b9c2b2015-05-28 14:56:20 +0200338 mbedtls_snprintf( buf, buflen, "PK - Memory allocation failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200339 if( use_ret == -(MBEDTLS_ERR_PK_TYPE_MISMATCH) )
340 mbedtls_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
341 if( use_ret == -(MBEDTLS_ERR_PK_BAD_INPUT_DATA) )
342 mbedtls_snprintf( buf, buflen, "PK - Bad input parameters to function" );
343 if( use_ret == -(MBEDTLS_ERR_PK_FILE_IO_ERROR) )
344 mbedtls_snprintf( buf, buflen, "PK - Read/write of file failed" );
345 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION) )
346 mbedtls_snprintf( buf, buflen, "PK - Unsupported key version" );
347 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT) )
348 mbedtls_snprintf( buf, buflen, "PK - Invalid key tag or value" );
349 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG) )
350 mbedtls_snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
351 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED) )
352 mbedtls_snprintf( buf, buflen, "PK - Private key password can't be empty" );
353 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH) )
354 mbedtls_snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
355 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_PUBKEY) )
356 mbedtls_snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
357 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_ALG) )
358 mbedtls_snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
359 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE) )
360 mbedtls_snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
361 if( use_ret == -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) )
362 mbedtls_snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
363 if( use_ret == -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH) )
Gilles Peskinecc78ac42018-03-30 18:52:10 +0200364 mbedtls_snprintf( buf, buflen, "PK - The buffer contains a valid signature followed by more data" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100365 if( use_ret == -(MBEDTLS_ERR_PK_HW_ACCEL_FAILED) )
366 mbedtls_snprintf( buf, buflen, "PK - PK hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200367#endif /* MBEDTLS_PK_C */
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200368
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200369#if defined(MBEDTLS_PKCS12_C)
370 if( use_ret == -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA) )
371 mbedtls_snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
372 if( use_ret == -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE) )
373 mbedtls_snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
374 if( use_ret == -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT) )
375 mbedtls_snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
376 if( use_ret == -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) )
377 mbedtls_snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
378#endif /* MBEDTLS_PKCS12_C */
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200379
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200380#if defined(MBEDTLS_PKCS5_C)
381 if( use_ret == -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA) )
382 mbedtls_snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
383 if( use_ret == -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT) )
384 mbedtls_snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
385 if( use_ret == -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE) )
386 mbedtls_snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
387 if( use_ret == -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) )
388 mbedtls_snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
389#endif /* MBEDTLS_PKCS5_C */
Paul Bakker28144de2013-06-24 19:28:55 +0200390
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200391#if defined(MBEDTLS_RSA_C)
392 if( use_ret == -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA) )
393 mbedtls_snprintf( buf, buflen, "RSA - Bad input parameters to function" );
394 if( use_ret == -(MBEDTLS_ERR_RSA_INVALID_PADDING) )
395 mbedtls_snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
396 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED) )
397 mbedtls_snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
398 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED) )
Rose Zadik042e97f2018-01-26 16:35:10 +0000399 mbedtls_snprintf( buf, buflen, "RSA - Key failed to pass the validity check of the library" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200400 if( use_ret == -(MBEDTLS_ERR_RSA_PUBLIC_FAILED) )
401 mbedtls_snprintf( buf, buflen, "RSA - The public key operation failed" );
402 if( use_ret == -(MBEDTLS_ERR_RSA_PRIVATE_FAILED) )
403 mbedtls_snprintf( buf, buflen, "RSA - The private key operation failed" );
404 if( use_ret == -(MBEDTLS_ERR_RSA_VERIFY_FAILED) )
405 mbedtls_snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
406 if( use_ret == -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE) )
407 mbedtls_snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
408 if( use_ret == -(MBEDTLS_ERR_RSA_RNG_FAILED) )
409 mbedtls_snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
Hanno Becker3cdc7112017-10-05 10:09:31 +0100410 if( use_ret == -(MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION) )
Rose Zadik042e97f2018-01-26 16:35:10 +0000411 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 +0100412 if( use_ret == -(MBEDTLS_ERR_RSA_HW_ACCEL_FAILED) )
413 mbedtls_snprintf( buf, buflen, "RSA - RSA hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200414#endif /* MBEDTLS_RSA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000415
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200416#if defined(MBEDTLS_SSL_TLS_C)
417 if( use_ret == -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE) )
418 mbedtls_snprintf( buf, buflen, "SSL - The requested feature is not available" );
419 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA) )
420 mbedtls_snprintf( buf, buflen, "SSL - Bad input parameters to function" );
421 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_MAC) )
422 mbedtls_snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
423 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_RECORD) )
424 mbedtls_snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
425 if( use_ret == -(MBEDTLS_ERR_SSL_CONN_EOF) )
426 mbedtls_snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
427 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER) )
428 mbedtls_snprintf( buf, buflen, "SSL - An unknown cipher was received" );
429 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN) )
430 mbedtls_snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
431 if( use_ret == -(MBEDTLS_ERR_SSL_NO_RNG) )
432 mbedtls_snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
433 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE) )
434 mbedtls_snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
435 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE) )
436 mbedtls_snprintf( buf, buflen, "SSL - Our own certificate(s) is/are too large to send in an SSL message" );
437 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED) )
438 mbedtls_snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
439 if( use_ret == -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED) )
440 mbedtls_snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
441 if( use_ret == -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED) )
442 mbedtls_snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
443 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE) )
444 mbedtls_snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
445 if( use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE) )
Paul Bakker3aac1da2012-05-08 13:12:27 +0000446 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200447 mbedtls_snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
Paul Bakker3aac1da2012-05-08 13:12:27 +0000448 return;
449 }
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200450 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED) )
451 mbedtls_snprintf( buf, buflen, "SSL - Verification of our peer failed" );
452 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) )
453 mbedtls_snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
454 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO) )
455 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
456 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO) )
457 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
458 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE) )
459 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
460 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
461 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
462 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
463 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
464 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
465 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
466 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
467 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
468 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
469 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
470 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
471 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
472 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
473 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
474 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
475 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
476 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED) )
477 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200478 if( use_ret == -(MBEDTLS_ERR_SSL_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200479 mbedtls_snprintf( buf, buflen, "SSL - Memory allocation failed" );
480 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED) )
481 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
482 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
483 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
484 if( use_ret == -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED) )
485 mbedtls_snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
486 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
487 mbedtls_snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
488 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
489 mbedtls_snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
490 if( use_ret == -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED) )
491 mbedtls_snprintf( buf, buflen, "SSL - Session ticket has expired" );
492 if( use_ret == -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH) )
493 mbedtls_snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
494 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY) )
495 mbedtls_snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
496 if( use_ret == -(MBEDTLS_ERR_SSL_INTERNAL_ERROR) )
497 mbedtls_snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
498 if( use_ret == -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING) )
499 mbedtls_snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
500 if( use_ret == -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO) )
501 mbedtls_snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" );
502 if( use_ret == -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED) )
503 mbedtls_snprintf( buf, buflen, "SSL - DTLS client must retry for hello verification" );
504 if( use_ret == -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL) )
505 mbedtls_snprintf( buf, buflen, "SSL - A buffer is too small to receive or write a message" );
506 if( use_ret == -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE) )
507 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 +0100508 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_READ) )
509 mbedtls_snprintf( buf, buflen, "SSL - Connection requires a read call" );
510 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_WRITE) )
511 mbedtls_snprintf( buf, buflen, "SSL - Connection requires a write call" );
512 if( use_ret == -(MBEDTLS_ERR_SSL_TIMEOUT) )
513 mbedtls_snprintf( buf, buflen, "SSL - The operation timed out" );
Manuel Pégourié-Gonnardbe619c12015-09-08 11:21:21 +0200514 if( use_ret == -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT) )
515 mbedtls_snprintf( buf, buflen, "SSL - The client initiated a reconnect from the same port" );
Manuel Pégourié-Gonnarde2e25e72015-12-03 16:13:17 +0100516 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD) )
517 mbedtls_snprintf( buf, buflen, "SSL - Record header looks valid but is not expected" );
Simon Butcher99000142016-10-13 17:21:01 +0100518 if( use_ret == -(MBEDTLS_ERR_SSL_NON_FATAL) )
519 mbedtls_snprintf( buf, buflen, "SSL - The alert message received indicates a non-fatal error" );
520 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH) )
521 mbedtls_snprintf( buf, buflen, "SSL - Couldn't set the hash for verifying CertificateVerify" );
Hanno Beckerd8562b52017-04-12 14:54:42 +0100522 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_CONFIG) )
523 mbedtls_snprintf( buf, buflen, "SSL - Invalid value in SSL config" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200524#endif /* MBEDTLS_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000525
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200526#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
527 if( use_ret == -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) )
528 mbedtls_snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
529 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_OID) )
530 mbedtls_snprintf( buf, buflen, "X509 - Requested OID is unknown" );
531 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_FORMAT) )
532 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
533 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_VERSION) )
534 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
535 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SERIAL) )
536 mbedtls_snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
537 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_ALG) )
538 mbedtls_snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
539 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_NAME) )
540 mbedtls_snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
541 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_DATE) )
542 mbedtls_snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
543 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SIGNATURE) )
544 mbedtls_snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
545 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS) )
546 mbedtls_snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
547 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_VERSION) )
548 mbedtls_snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
549 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG) )
550 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
551 if( use_ret == -(MBEDTLS_ERR_X509_SIG_MISMATCH) )
552 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" );
553 if( use_ret == -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) )
554 mbedtls_snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
555 if( use_ret == -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT) )
556 mbedtls_snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
557 if( use_ret == -(MBEDTLS_ERR_X509_BAD_INPUT_DATA) )
558 mbedtls_snprintf( buf, buflen, "X509 - Input invalid" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200559 if( use_ret == -(MBEDTLS_ERR_X509_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200560 mbedtls_snprintf( buf, buflen, "X509 - Allocation of memory failed" );
561 if( use_ret == -(MBEDTLS_ERR_X509_FILE_IO_ERROR) )
562 mbedtls_snprintf( buf, buflen, "X509 - Read/write of file failed" );
Manuel Pégourié-Gonnard9dbaf402015-06-22 11:50:58 +0200563 if( use_ret == -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL) )
564 mbedtls_snprintf( buf, buflen, "X509 - Destination buffer is too small" );
Manuel Pégourié-Gonnard31458a12017-06-26 10:11:49 +0200565 if( use_ret == -(MBEDTLS_ERR_X509_FATAL_ERROR) )
Antonin Décimo8fd91562019-01-23 15:24:37 +0100566 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 +0200567#endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200568 // END generated code
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200569
Paul Bakker9d781402011-05-09 16:17:09 +0000570 if( strlen( buf ) == 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200571 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000572 }
573
574 use_ret = ret & ~0xFF80;
575
576 if( use_ret == 0 )
577 return;
578
579 // If high level code is present, make a concatenation between both
580 // error strings.
581 //
582 len = strlen( buf );
583
584 if( len > 0 )
585 {
586 if( buflen - len < 5 )
587 return;
588
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200589 mbedtls_snprintf( buf + len, buflen - len, " : " );
Paul Bakker9d781402011-05-09 16:17:09 +0000590
591 buf += len + 3;
592 buflen -= len + 3;
593 }
594
595 // Low level error codes
596 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200597 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200598#if defined(MBEDTLS_AES_C)
599 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH) )
600 mbedtls_snprintf( buf, buflen, "AES - Invalid key length" );
601 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH) )
602 mbedtls_snprintf( buf, buflen, "AES - Invalid data input length" );
Andres Amaya Garciafd487392017-06-14 16:19:12 +0100603 if( use_ret == -(MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE) )
Rose Zadik7f441272018-01-22 11:48:23 +0000604 mbedtls_snprintf( buf, buflen, "AES - Feature not available. For example, an unsupported AES key size" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100605 if( use_ret == -(MBEDTLS_ERR_AES_HW_ACCEL_FAILED) )
606 mbedtls_snprintf( buf, buflen, "AES - AES hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200607#endif /* MBEDTLS_AES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000608
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100609#if defined(MBEDTLS_ARC4_C)
610 if( use_ret == -(MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED) )
611 mbedtls_snprintf( buf, buflen, "ARC4 - ARC4 hardware accelerator failed" );
612#endif /* MBEDTLS_ARC4_C */
613
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200614#if defined(MBEDTLS_ASN1_PARSE_C)
615 if( use_ret == -(MBEDTLS_ERR_ASN1_OUT_OF_DATA) )
616 mbedtls_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
617 if( use_ret == -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) )
618 mbedtls_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
619 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_LENGTH) )
620 mbedtls_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
621 if( use_ret == -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH) )
622 mbedtls_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
623 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_DATA) )
624 mbedtls_snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200625 if( use_ret == -(MBEDTLS_ERR_ASN1_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200626 mbedtls_snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
627 if( use_ret == -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL) )
628 mbedtls_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
629#endif /* MBEDTLS_ASN1_PARSE_C */
Paul Bakkerdceecd82011-11-15 16:38:34 +0000630
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200631#if defined(MBEDTLS_BASE64_C)
632 if( use_ret == -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) )
633 mbedtls_snprintf( buf, buflen, "BASE64 - Output buffer too small" );
634 if( use_ret == -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER) )
635 mbedtls_snprintf( buf, buflen, "BASE64 - Invalid character in input" );
636#endif /* MBEDTLS_BASE64_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000637
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200638#if defined(MBEDTLS_BIGNUM_C)
639 if( use_ret == -(MBEDTLS_ERR_MPI_FILE_IO_ERROR) )
640 mbedtls_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
641 if( use_ret == -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA) )
642 mbedtls_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
643 if( use_ret == -(MBEDTLS_ERR_MPI_INVALID_CHARACTER) )
644 mbedtls_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
645 if( use_ret == -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL) )
646 mbedtls_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
647 if( use_ret == -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE) )
648 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
649 if( use_ret == -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO) )
650 mbedtls_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
651 if( use_ret == -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) )
652 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200653 if( use_ret == -(MBEDTLS_ERR_MPI_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200654 mbedtls_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
655#endif /* MBEDTLS_BIGNUM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000656
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200657#if defined(MBEDTLS_BLOWFISH_C)
658 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
659 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100660 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED) )
661 mbedtls_snprintf( buf, buflen, "BLOWFISH - Blowfish hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200662 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
663 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
664#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker83f00bb2012-07-04 11:08:50 +0000665
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200666#if defined(MBEDTLS_CAMELLIA_C)
667 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
668 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
669 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
670 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100671 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED) )
672 mbedtls_snprintf( buf, buflen, "CAMELLIA - Camellia hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200673#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000674
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200675#if defined(MBEDTLS_CCM_C)
676 if( use_ret == -(MBEDTLS_ERR_CCM_BAD_INPUT) )
Rose Zadikeecdbea2018-01-24 12:56:53 +0000677 mbedtls_snprintf( buf, buflen, "CCM - Bad input parameters to the function" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200678 if( use_ret == -(MBEDTLS_ERR_CCM_AUTH_FAILED) )
679 mbedtls_snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100680 if( use_ret == -(MBEDTLS_ERR_CCM_HW_ACCEL_FAILED) )
681 mbedtls_snprintf( buf, buflen, "CCM - CCM hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200682#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200683
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100684#if defined(MBEDTLS_CMAC_C)
685 if( use_ret == -(MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED) )
686 mbedtls_snprintf( buf, buflen, "CMAC - CMAC hardware accelerator failed" );
687#endif /* MBEDTLS_CMAC_C */
688
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200689#if defined(MBEDTLS_CTR_DRBG_C)
690 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
691 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
692 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000693 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The requested random buffer length is too big" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200694 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000695 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The input (entropy + additional data) is too large" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200696 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000697 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Read or write error in file" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200698#endif /* MBEDTLS_CTR_DRBG_C */
Paul Bakker880ac7e2011-11-27 14:50:49 +0000699
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200700#if defined(MBEDTLS_DES_C)
701 if( use_ret == -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH) )
702 mbedtls_snprintf( buf, buflen, "DES - The data input has an invalid length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100703 if( use_ret == -(MBEDTLS_ERR_DES_HW_ACCEL_FAILED) )
704 mbedtls_snprintf( buf, buflen, "DES - DES hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200705#endif /* MBEDTLS_DES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000706
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200707#if defined(MBEDTLS_ENTROPY_C)
708 if( use_ret == -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED) )
709 mbedtls_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
710 if( use_ret == -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES) )
711 mbedtls_snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
712 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED) )
713 mbedtls_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
Manuel Pégourié-Gonnardf9cbd732015-06-22 12:06:50 +0200714 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE) )
715 mbedtls_snprintf( buf, buflen, "ENTROPY - No strong sources have been added to poll" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200716 if( use_ret == -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR) )
717 mbedtls_snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
718#endif /* MBEDTLS_ENTROPY_C */
Paul Bakker6083fd22011-12-03 21:45:14 +0000719
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200720#if defined(MBEDTLS_GCM_C)
721 if( use_ret == -(MBEDTLS_ERR_GCM_AUTH_FAILED) )
722 mbedtls_snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100723 if( use_ret == -(MBEDTLS_ERR_GCM_HW_ACCEL_FAILED) )
724 mbedtls_snprintf( buf, buflen, "GCM - GCM hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200725 if( use_ret == -(MBEDTLS_ERR_GCM_BAD_INPUT) )
726 mbedtls_snprintf( buf, buflen, "GCM - Bad input parameters to function" );
727#endif /* MBEDTLS_GCM_C */
Paul Bakker030277a2012-04-17 12:24:26 +0000728
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200729#if defined(MBEDTLS_HMAC_DRBG_C)
730 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
731 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
732 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
733 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
734 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR) )
735 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
736 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
737 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
738#endif /* MBEDTLS_HMAC_DRBG_C */
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100739
Gilles Peskinea381fe82018-01-23 18:16:11 +0100740#if defined(MBEDTLS_MD2_C)
741 if( use_ret == -(MBEDTLS_ERR_MD2_HW_ACCEL_FAILED) )
742 mbedtls_snprintf( buf, buflen, "MD2 - MD2 hardware accelerator failed" );
743#endif /* MBEDTLS_MD2_C */
744
745#if defined(MBEDTLS_MD4_C)
746 if( use_ret == -(MBEDTLS_ERR_MD4_HW_ACCEL_FAILED) )
747 mbedtls_snprintf( buf, buflen, "MD4 - MD4 hardware accelerator failed" );
748#endif /* MBEDTLS_MD4_C */
749
750#if defined(MBEDTLS_MD5_C)
751 if( use_ret == -(MBEDTLS_ERR_MD5_HW_ACCEL_FAILED) )
752 mbedtls_snprintf( buf, buflen, "MD5 - MD5 hardware accelerator failed" );
753#endif /* MBEDTLS_MD5_C */
754
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200755#if defined(MBEDTLS_NET_C)
756 if( use_ret == -(MBEDTLS_ERR_NET_SOCKET_FAILED) )
757 mbedtls_snprintf( buf, buflen, "NET - Failed to open a socket" );
758 if( use_ret == -(MBEDTLS_ERR_NET_CONNECT_FAILED) )
759 mbedtls_snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
760 if( use_ret == -(MBEDTLS_ERR_NET_BIND_FAILED) )
761 mbedtls_snprintf( buf, buflen, "NET - Binding of the socket failed" );
762 if( use_ret == -(MBEDTLS_ERR_NET_LISTEN_FAILED) )
763 mbedtls_snprintf( buf, buflen, "NET - Could not listen on the socket" );
764 if( use_ret == -(MBEDTLS_ERR_NET_ACCEPT_FAILED) )
765 mbedtls_snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
766 if( use_ret == -(MBEDTLS_ERR_NET_RECV_FAILED) )
767 mbedtls_snprintf( buf, buflen, "NET - Reading information from the socket failed" );
768 if( use_ret == -(MBEDTLS_ERR_NET_SEND_FAILED) )
769 mbedtls_snprintf( buf, buflen, "NET - Sending information through the socket failed" );
770 if( use_ret == -(MBEDTLS_ERR_NET_CONN_RESET) )
771 mbedtls_snprintf( buf, buflen, "NET - Connection was reset by peer" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200772 if( use_ret == -(MBEDTLS_ERR_NET_UNKNOWN_HOST) )
773 mbedtls_snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
Manuel Pégourié-Gonnard0b104b02015-05-14 21:52:40 +0200774 if( use_ret == -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL) )
775 mbedtls_snprintf( buf, buflen, "NET - Buffer is too small to hold the data" );
Manuel Pégourié-Gonnard9bd0afd2015-07-01 19:03:27 +0200776 if( use_ret == -(MBEDTLS_ERR_NET_INVALID_CONTEXT) )
777 mbedtls_snprintf( buf, buflen, "NET - The context is invalid, eg because it was free()ed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200778#endif /* MBEDTLS_NET_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000779
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200780#if defined(MBEDTLS_OID_C)
781 if( use_ret == -(MBEDTLS_ERR_OID_NOT_FOUND) )
782 mbedtls_snprintf( buf, buflen, "OID - OID is not found" );
783 if( use_ret == -(MBEDTLS_ERR_OID_BUF_TOO_SMALL) )
784 mbedtls_snprintf( buf, buflen, "OID - output buffer is too small" );
785#endif /* MBEDTLS_OID_C */
Paul Bakkerc70b9822013-04-07 22:00:46 +0200786
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200787#if defined(MBEDTLS_PADLOCK_C)
788 if( use_ret == -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED) )
789 mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
790#endif /* MBEDTLS_PADLOCK_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000791
Gilles Peskinea381fe82018-01-23 18:16:11 +0100792#if defined(MBEDTLS_RIPEMD160_C)
793 if( use_ret == -(MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED) )
794 mbedtls_snprintf( buf, buflen, "RIPEMD160 - RIPEMD160 hardware accelerator failed" );
795#endif /* MBEDTLS_RIPEMD160_C */
796
797#if defined(MBEDTLS_SHA1_C)
798 if( use_ret == -(MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED) )
799 mbedtls_snprintf( buf, buflen, "SHA1 - SHA-1 hardware accelerator failed" );
800#endif /* MBEDTLS_SHA1_C */
801
802#if defined(MBEDTLS_SHA256_C)
803 if( use_ret == -(MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED) )
804 mbedtls_snprintf( buf, buflen, "SHA256 - SHA-256 hardware accelerator failed" );
805#endif /* MBEDTLS_SHA256_C */
806
807#if defined(MBEDTLS_SHA512_C)
808 if( use_ret == -(MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED) )
809 mbedtls_snprintf( buf, buflen, "SHA512 - SHA-512 hardware accelerator failed" );
810#endif /* MBEDTLS_SHA512_C */
811
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200812#if defined(MBEDTLS_THREADING_C)
813 if( use_ret == -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE) )
814 mbedtls_snprintf( buf, buflen, "THREADING - The selected feature is not available" );
815 if( use_ret == -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA) )
816 mbedtls_snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
817 if( use_ret == -(MBEDTLS_ERR_THREADING_MUTEX_ERROR) )
818 mbedtls_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
819#endif /* MBEDTLS_THREADING_C */
Paul Bakker2466d932013-09-28 14:40:38 +0200820
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200821#if defined(MBEDTLS_XTEA_C)
822 if( use_ret == -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH) )
823 mbedtls_snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100824 if( use_ret == -(MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED) )
825 mbedtls_snprintf( buf, buflen, "XTEA - XTEA hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200826#endif /* MBEDTLS_XTEA_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200827 // END generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000828
829 if( strlen( buf ) != 0 )
830 return;
831
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200832 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000833}
834
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200835#else /* MBEDTLS_ERROR_C */
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100836
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100837/*
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200838 * Provide an non-function in case MBEDTLS_ERROR_C is not defined
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100839 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200840void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100841{
842 ((void) ret);
843
844 if( buflen > 0 )
845 buf[0] = '\0';
846}
847
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200848#endif /* MBEDTLS_ERROR_C */
Gilles Peskine4159c712020-11-09 15:14:10 +0100849
850#endif /* MBEDTLS_ERROR_C || MBEDTLS_ERROR_STRERROR_DUMMY */