blob: 0757268f25068e61eca2e21c377a494adca51010 [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)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000054#include "mbedtls/error.h"
Rich Evans00ab4702015-02-06 13:43:58 +000055#include <string.h>
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020056#endif
57
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020058#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000059#include "mbedtls/platform.h"
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +000060#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061#define mbedtls_snprintf snprintf
-~- redtangent ~-~9fa2e862016-05-26 10:07:49 +010062#define mbedtls_time_t time_t
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020063#endif
64
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020065#if defined(MBEDTLS_ERROR_C)
Paul Bakker3c2122f2013-06-24 19:03:14 +020066
Rich Evans00ab4702015-02-06 13:43:58 +000067#include <stdio.h>
68
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020069#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000070#include "mbedtls/aes.h"
Paul Bakker9d781402011-05-09 16:17:09 +000071#endif
72
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010073#if defined(MBEDTLS_ARC4_C)
74#include "mbedtls/arc4.h"
75#endif
76
Gilles Peskineac631bb2020-05-25 12:23:55 +020077#if defined(MBEDTLS_ASN1_PARSE_C)
78#include "mbedtls/asn1.h"
79#endif
80
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020081#if defined(MBEDTLS_BASE64_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000082#include "mbedtls/base64.h"
Paul Bakker9d781402011-05-09 16:17:09 +000083#endif
84
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020085#if defined(MBEDTLS_BIGNUM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000086#include "mbedtls/bignum.h"
Paul Bakker9d781402011-05-09 16:17:09 +000087#endif
88
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020089#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000090#include "mbedtls/blowfish.h"
Paul Bakker83f00bb2012-07-04 11:08:50 +000091#endif
92
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020093#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000094#include "mbedtls/camellia.h"
Paul Bakker9d781402011-05-09 16:17:09 +000095#endif
96
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020097#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000098#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +020099#endif
100
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200101#if defined(MBEDTLS_CIPHER_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000102#include "mbedtls/cipher.h"
Paul Bakkerff61a782011-06-09 15:42:02 +0000103#endif
104
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100105#if defined(MBEDTLS_CMAC_C)
106#include "mbedtls/cmac.h"
107#endif
108
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200109#if defined(MBEDTLS_CTR_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000110#include "mbedtls/ctr_drbg.h"
Paul Bakker880ac7e2011-11-27 14:50:49 +0000111#endif
112
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200113#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000114#include "mbedtls/des.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000115#endif
116
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200117#if defined(MBEDTLS_DHM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000118#include "mbedtls/dhm.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000119#endif
120
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200121#if defined(MBEDTLS_ECP_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000122#include "mbedtls/ecp.h"
Paul Bakkercf4365f2013-01-16 17:00:43 +0100123#endif
124
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200125#if defined(MBEDTLS_ENTROPY_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000126#include "mbedtls/entropy.h"
Paul Bakker6083fd22011-12-03 21:45:14 +0000127#endif
128
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200129#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000130#include "mbedtls/gcm.h"
Paul Bakker030277a2012-04-17 12:24:26 +0000131#endif
132
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200133#if defined(MBEDTLS_HMAC_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000134#include "mbedtls/hmac_drbg.h"
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100135#endif
136
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200137#if defined(MBEDTLS_MD_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000138#include "mbedtls/md.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000139#endif
140
Gilles Peskinea381fe82018-01-23 18:16:11 +0100141#if defined(MBEDTLS_MD2_C)
142#include "mbedtls/md2.h"
143#endif
144
145#if defined(MBEDTLS_MD4_C)
146#include "mbedtls/md4.h"
147#endif
148
149#if defined(MBEDTLS_MD5_C)
150#include "mbedtls/md5.h"
151#endif
152
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200153#if defined(MBEDTLS_NET_C)
Andres AG3616f6f2016-09-14 14:32:09 +0100154#include "mbedtls/net_sockets.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000155#endif
156
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200157#if defined(MBEDTLS_OID_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000158#include "mbedtls/oid.h"
Paul Bakkerc70b9822013-04-07 22:00:46 +0200159#endif
160
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200161#if defined(MBEDTLS_PADLOCK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000162#include "mbedtls/padlock.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000163#endif
164
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200165#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000166#include "mbedtls/pem.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000167#endif
168
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200169#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000170#include "mbedtls/pk.h"
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200171#endif
172
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200173#if defined(MBEDTLS_PKCS12_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000174#include "mbedtls/pkcs12.h"
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200175#endif
176
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200177#if defined(MBEDTLS_PKCS5_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000178#include "mbedtls/pkcs5.h"
Paul Bakkerb0c19a42013-06-24 19:26:38 +0200179#endif
180
Gilles Peskinea381fe82018-01-23 18:16:11 +0100181#if defined(MBEDTLS_RIPEMD160_C)
182#include "mbedtls/ripemd160.h"
183#endif
184
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200185#if defined(MBEDTLS_RSA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000186#include "mbedtls/rsa.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000187#endif
188
Gilles Peskinea381fe82018-01-23 18:16:11 +0100189#if defined(MBEDTLS_SHA1_C)
190#include "mbedtls/sha1.h"
191#endif
192
193#if defined(MBEDTLS_SHA256_C)
194#include "mbedtls/sha256.h"
195#endif
196
197#if defined(MBEDTLS_SHA512_C)
198#include "mbedtls/sha512.h"
199#endif
200
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200201#if defined(MBEDTLS_SSL_TLS_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000202#include "mbedtls/ssl.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000203#endif
204
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200205#if defined(MBEDTLS_THREADING_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000206#include "mbedtls/threading.h"
Paul Bakker2466d932013-09-28 14:40:38 +0200207#endif
208
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200209#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000210#include "mbedtls/x509.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000211#endif
212
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200213#if defined(MBEDTLS_XTEA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000214#include "mbedtls/xtea.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000215#endif
216
Paul Bakkerdceecd82011-11-15 16:38:34 +0000217
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200218void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker9d781402011-05-09 16:17:09 +0000219{
220 size_t len;
221 int use_ret;
222
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200223 if( buflen == 0 )
224 return;
225
Paul Bakker9d781402011-05-09 16:17:09 +0000226 memset( buf, 0x00, buflen );
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200227
Paul Bakker9d781402011-05-09 16:17:09 +0000228 if( ret < 0 )
229 ret = -ret;
230
231 if( ret & 0xFF80 )
232 {
233 use_ret = ret & 0xFF80;
234
235 // High level error codes
236 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200237 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200238#if defined(MBEDTLS_CIPHER_C)
239 if( use_ret == -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE) )
240 mbedtls_snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
241 if( use_ret == -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA) )
Rose Zadik9ba6b622018-01-24 12:59:19 +0000242 mbedtls_snprintf( buf, buflen, "CIPHER - Bad input parameters" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200243 if( use_ret == -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED) )
244 mbedtls_snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
245 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_PADDING) )
246 mbedtls_snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
247 if( use_ret == -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
248 mbedtls_snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
249 if( use_ret == -(MBEDTLS_ERR_CIPHER_AUTH_FAILED) )
250 mbedtls_snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
Janos Follath98e28a72016-05-31 14:03:54 +0100251 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT) )
Rose Zadik9ba6b622018-01-24 12:59:19 +0000252 mbedtls_snprintf( buf, buflen, "CIPHER - The context is invalid. For example, because it was freed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100253 if( use_ret == -(MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED) )
254 mbedtls_snprintf( buf, buflen, "CIPHER - Cipher hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200255#endif /* MBEDTLS_CIPHER_C */
Paul Bakkerff61a782011-06-09 15:42:02 +0000256
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200257#if defined(MBEDTLS_DHM_C)
258 if( use_ret == -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA) )
Rose Zadik41ad0822018-01-26 10:54:57 +0000259 mbedtls_snprintf( buf, buflen, "DHM - Bad input parameters" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200260 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED) )
261 mbedtls_snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
262 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED) )
263 mbedtls_snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
264 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED) )
265 mbedtls_snprintf( buf, buflen, "DHM - Reading of the public values failed" );
266 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED) )
267 mbedtls_snprintf( buf, buflen, "DHM - Making of the public value failed" );
268 if( use_ret == -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED) )
269 mbedtls_snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
270 if( use_ret == -(MBEDTLS_ERR_DHM_INVALID_FORMAT) )
271 mbedtls_snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200272 if( use_ret == -(MBEDTLS_ERR_DHM_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200273 mbedtls_snprintf( buf, buflen, "DHM - Allocation of memory failed" );
274 if( use_ret == -(MBEDTLS_ERR_DHM_FILE_IO_ERROR) )
Rose Zadik41ad0822018-01-26 10:54:57 +0000275 mbedtls_snprintf( buf, buflen, "DHM - Read or write of file failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100276 if( use_ret == -(MBEDTLS_ERR_DHM_HW_ACCEL_FAILED) )
277 mbedtls_snprintf( buf, buflen, "DHM - DHM hardware accelerator failed" );
Hanno Beckera6dd90d2017-10-04 13:15:54 +0100278 if( use_ret == -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED) )
Jaeden Amero784de592018-01-26 17:52:01 +0000279 mbedtls_snprintf( buf, buflen, "DHM - Setting the modulus and generator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200280#endif /* MBEDTLS_DHM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000281
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200282#if defined(MBEDTLS_ECP_C)
283 if( use_ret == -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA) )
284 mbedtls_snprintf( buf, buflen, "ECP - Bad input parameters to function" );
285 if( use_ret == -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL) )
286 mbedtls_snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
287 if( use_ret == -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) )
288 mbedtls_snprintf( buf, buflen, "ECP - Requested curve not available" );
289 if( use_ret == -(MBEDTLS_ERR_ECP_VERIFY_FAILED) )
290 mbedtls_snprintf( buf, buflen, "ECP - The signature is not valid" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200291 if( use_ret == -(MBEDTLS_ERR_ECP_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200292 mbedtls_snprintf( buf, buflen, "ECP - Memory allocation failed" );
293 if( use_ret == -(MBEDTLS_ERR_ECP_RANDOM_FAILED) )
294 mbedtls_snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
295 if( use_ret == -(MBEDTLS_ERR_ECP_INVALID_KEY) )
296 mbedtls_snprintf( buf, buflen, "ECP - Invalid private or public key" );
297 if( use_ret == -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) )
Gilles Peskinecc78ac42018-03-30 18:52:10 +0200298 mbedtls_snprintf( buf, buflen, "ECP - The buffer contains a valid signature followed by more data" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100299 if( use_ret == -(MBEDTLS_ERR_ECP_HW_ACCEL_FAILED) )
300 mbedtls_snprintf( buf, buflen, "ECP - ECP hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200301#endif /* MBEDTLS_ECP_C */
Paul Bakkercf4365f2013-01-16 17:00:43 +0100302
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200303#if defined(MBEDTLS_MD_C)
304 if( use_ret == -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE) )
305 mbedtls_snprintf( buf, buflen, "MD - The selected feature is not available" );
306 if( use_ret == -(MBEDTLS_ERR_MD_BAD_INPUT_DATA) )
307 mbedtls_snprintf( buf, buflen, "MD - Bad input parameters to function" );
308 if( use_ret == -(MBEDTLS_ERR_MD_ALLOC_FAILED) )
309 mbedtls_snprintf( buf, buflen, "MD - Failed to allocate memory" );
310 if( use_ret == -(MBEDTLS_ERR_MD_FILE_IO_ERROR) )
311 mbedtls_snprintf( buf, buflen, "MD - Opening or reading of file failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100312 if( use_ret == -(MBEDTLS_ERR_MD_HW_ACCEL_FAILED) )
313 mbedtls_snprintf( buf, buflen, "MD - MD hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200314#endif /* MBEDTLS_MD_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000315
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200316#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
317 if( use_ret == -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
318 mbedtls_snprintf( buf, buflen, "PEM - No PEM header or footer found" );
319 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_DATA) )
320 mbedtls_snprintf( buf, buflen, "PEM - PEM string is not as expected" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200321 if( use_ret == -(MBEDTLS_ERR_PEM_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200322 mbedtls_snprintf( buf, buflen, "PEM - Failed to allocate memory" );
323 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_ENC_IV) )
324 mbedtls_snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
325 if( use_ret == -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG) )
326 mbedtls_snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
327 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) )
328 mbedtls_snprintf( buf, buflen, "PEM - Private key password can't be empty" );
329 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) )
330 mbedtls_snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
331 if( use_ret == -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE) )
332 mbedtls_snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
333 if( use_ret == -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA) )
334 mbedtls_snprintf( buf, buflen, "PEM - Bad input parameters to function" );
335#endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000336
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200337#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200338 if( use_ret == -(MBEDTLS_ERR_PK_ALLOC_FAILED) )
Manuel Pégourié-Gonnard41b9c2b2015-05-28 14:56:20 +0200339 mbedtls_snprintf( buf, buflen, "PK - Memory allocation failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200340 if( use_ret == -(MBEDTLS_ERR_PK_TYPE_MISMATCH) )
341 mbedtls_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
342 if( use_ret == -(MBEDTLS_ERR_PK_BAD_INPUT_DATA) )
343 mbedtls_snprintf( buf, buflen, "PK - Bad input parameters to function" );
344 if( use_ret == -(MBEDTLS_ERR_PK_FILE_IO_ERROR) )
345 mbedtls_snprintf( buf, buflen, "PK - Read/write of file failed" );
346 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION) )
347 mbedtls_snprintf( buf, buflen, "PK - Unsupported key version" );
348 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT) )
349 mbedtls_snprintf( buf, buflen, "PK - Invalid key tag or value" );
350 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG) )
351 mbedtls_snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
352 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED) )
353 mbedtls_snprintf( buf, buflen, "PK - Private key password can't be empty" );
354 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH) )
355 mbedtls_snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
356 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_PUBKEY) )
357 mbedtls_snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
358 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_ALG) )
359 mbedtls_snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
360 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE) )
361 mbedtls_snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
362 if( use_ret == -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) )
363 mbedtls_snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
364 if( use_ret == -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH) )
Gilles Peskinecc78ac42018-03-30 18:52:10 +0200365 mbedtls_snprintf( buf, buflen, "PK - The buffer contains a valid signature followed by more data" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100366 if( use_ret == -(MBEDTLS_ERR_PK_HW_ACCEL_FAILED) )
367 mbedtls_snprintf( buf, buflen, "PK - PK hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200368#endif /* MBEDTLS_PK_C */
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200369
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200370#if defined(MBEDTLS_PKCS12_C)
371 if( use_ret == -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA) )
372 mbedtls_snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
373 if( use_ret == -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE) )
374 mbedtls_snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
375 if( use_ret == -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT) )
376 mbedtls_snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
377 if( use_ret == -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) )
378 mbedtls_snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
379#endif /* MBEDTLS_PKCS12_C */
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200380
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200381#if defined(MBEDTLS_PKCS5_C)
382 if( use_ret == -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA) )
383 mbedtls_snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
384 if( use_ret == -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT) )
385 mbedtls_snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
386 if( use_ret == -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE) )
387 mbedtls_snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
388 if( use_ret == -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) )
389 mbedtls_snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
390#endif /* MBEDTLS_PKCS5_C */
Paul Bakker28144de2013-06-24 19:28:55 +0200391
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200392#if defined(MBEDTLS_RSA_C)
393 if( use_ret == -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA) )
394 mbedtls_snprintf( buf, buflen, "RSA - Bad input parameters to function" );
395 if( use_ret == -(MBEDTLS_ERR_RSA_INVALID_PADDING) )
396 mbedtls_snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
397 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED) )
398 mbedtls_snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
399 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED) )
Rose Zadik042e97f2018-01-26 16:35:10 +0000400 mbedtls_snprintf( buf, buflen, "RSA - Key failed to pass the validity check of the library" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200401 if( use_ret == -(MBEDTLS_ERR_RSA_PUBLIC_FAILED) )
402 mbedtls_snprintf( buf, buflen, "RSA - The public key operation failed" );
403 if( use_ret == -(MBEDTLS_ERR_RSA_PRIVATE_FAILED) )
404 mbedtls_snprintf( buf, buflen, "RSA - The private key operation failed" );
405 if( use_ret == -(MBEDTLS_ERR_RSA_VERIFY_FAILED) )
406 mbedtls_snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
407 if( use_ret == -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE) )
408 mbedtls_snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
409 if( use_ret == -(MBEDTLS_ERR_RSA_RNG_FAILED) )
410 mbedtls_snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
Hanno Becker3cdc7112017-10-05 10:09:31 +0100411 if( use_ret == -(MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION) )
Rose Zadik042e97f2018-01-26 16:35:10 +0000412 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 +0100413 if( use_ret == -(MBEDTLS_ERR_RSA_HW_ACCEL_FAILED) )
414 mbedtls_snprintf( buf, buflen, "RSA - RSA hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200415#endif /* MBEDTLS_RSA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000416
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200417#if defined(MBEDTLS_SSL_TLS_C)
418 if( use_ret == -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE) )
419 mbedtls_snprintf( buf, buflen, "SSL - The requested feature is not available" );
420 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA) )
421 mbedtls_snprintf( buf, buflen, "SSL - Bad input parameters to function" );
422 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_MAC) )
423 mbedtls_snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
424 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_RECORD) )
425 mbedtls_snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
426 if( use_ret == -(MBEDTLS_ERR_SSL_CONN_EOF) )
427 mbedtls_snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
428 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER) )
429 mbedtls_snprintf( buf, buflen, "SSL - An unknown cipher was received" );
430 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN) )
431 mbedtls_snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
432 if( use_ret == -(MBEDTLS_ERR_SSL_NO_RNG) )
433 mbedtls_snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
434 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE) )
435 mbedtls_snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
436 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE) )
437 mbedtls_snprintf( buf, buflen, "SSL - Our own certificate(s) is/are too large to send in an SSL message" );
438 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED) )
439 mbedtls_snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
440 if( use_ret == -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED) )
441 mbedtls_snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
442 if( use_ret == -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED) )
443 mbedtls_snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
444 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE) )
445 mbedtls_snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
446 if( use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE) )
Paul Bakker3aac1da2012-05-08 13:12:27 +0000447 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200448 mbedtls_snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
Paul Bakker3aac1da2012-05-08 13:12:27 +0000449 return;
450 }
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200451 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED) )
452 mbedtls_snprintf( buf, buflen, "SSL - Verification of our peer failed" );
453 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) )
454 mbedtls_snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
455 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO) )
456 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
457 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO) )
458 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
459 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE) )
460 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
461 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
462 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
463 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
464 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
465 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
466 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
467 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
468 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
469 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
470 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
471 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
472 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
473 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
474 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
475 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
476 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
477 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED) )
478 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200479 if( use_ret == -(MBEDTLS_ERR_SSL_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200480 mbedtls_snprintf( buf, buflen, "SSL - Memory allocation failed" );
481 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED) )
482 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
483 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
484 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
485 if( use_ret == -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED) )
486 mbedtls_snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
487 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
488 mbedtls_snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
489 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
490 mbedtls_snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
491 if( use_ret == -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED) )
492 mbedtls_snprintf( buf, buflen, "SSL - Session ticket has expired" );
493 if( use_ret == -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH) )
494 mbedtls_snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
495 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY) )
496 mbedtls_snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
497 if( use_ret == -(MBEDTLS_ERR_SSL_INTERNAL_ERROR) )
498 mbedtls_snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
499 if( use_ret == -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING) )
500 mbedtls_snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
501 if( use_ret == -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO) )
502 mbedtls_snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" );
503 if( use_ret == -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED) )
504 mbedtls_snprintf( buf, buflen, "SSL - DTLS client must retry for hello verification" );
505 if( use_ret == -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL) )
506 mbedtls_snprintf( buf, buflen, "SSL - A buffer is too small to receive or write a message" );
507 if( use_ret == -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE) )
508 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 +0100509 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_READ) )
510 mbedtls_snprintf( buf, buflen, "SSL - Connection requires a read call" );
511 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_WRITE) )
512 mbedtls_snprintf( buf, buflen, "SSL - Connection requires a write call" );
513 if( use_ret == -(MBEDTLS_ERR_SSL_TIMEOUT) )
514 mbedtls_snprintf( buf, buflen, "SSL - The operation timed out" );
Manuel Pégourié-Gonnardbe619c12015-09-08 11:21:21 +0200515 if( use_ret == -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT) )
516 mbedtls_snprintf( buf, buflen, "SSL - The client initiated a reconnect from the same port" );
Manuel Pégourié-Gonnarde2e25e72015-12-03 16:13:17 +0100517 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD) )
518 mbedtls_snprintf( buf, buflen, "SSL - Record header looks valid but is not expected" );
Simon Butcher99000142016-10-13 17:21:01 +0100519 if( use_ret == -(MBEDTLS_ERR_SSL_NON_FATAL) )
520 mbedtls_snprintf( buf, buflen, "SSL - The alert message received indicates a non-fatal error" );
521 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH) )
522 mbedtls_snprintf( buf, buflen, "SSL - Couldn't set the hash for verifying CertificateVerify" );
Hanno Beckerd8562b52017-04-12 14:54:42 +0100523 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_CONFIG) )
524 mbedtls_snprintf( buf, buflen, "SSL - Invalid value in SSL config" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200525#endif /* MBEDTLS_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000526
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200527#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
528 if( use_ret == -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) )
529 mbedtls_snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
530 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_OID) )
531 mbedtls_snprintf( buf, buflen, "X509 - Requested OID is unknown" );
532 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_FORMAT) )
533 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
534 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_VERSION) )
535 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
536 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SERIAL) )
537 mbedtls_snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
538 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_ALG) )
539 mbedtls_snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
540 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_NAME) )
541 mbedtls_snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
542 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_DATE) )
543 mbedtls_snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
544 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SIGNATURE) )
545 mbedtls_snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
546 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS) )
547 mbedtls_snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
548 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_VERSION) )
549 mbedtls_snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
550 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG) )
551 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
552 if( use_ret == -(MBEDTLS_ERR_X509_SIG_MISMATCH) )
553 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" );
554 if( use_ret == -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) )
555 mbedtls_snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
556 if( use_ret == -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT) )
557 mbedtls_snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
558 if( use_ret == -(MBEDTLS_ERR_X509_BAD_INPUT_DATA) )
559 mbedtls_snprintf( buf, buflen, "X509 - Input invalid" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200560 if( use_ret == -(MBEDTLS_ERR_X509_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200561 mbedtls_snprintf( buf, buflen, "X509 - Allocation of memory failed" );
562 if( use_ret == -(MBEDTLS_ERR_X509_FILE_IO_ERROR) )
563 mbedtls_snprintf( buf, buflen, "X509 - Read/write of file failed" );
Manuel Pégourié-Gonnard9dbaf402015-06-22 11:50:58 +0200564 if( use_ret == -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL) )
565 mbedtls_snprintf( buf, buflen, "X509 - Destination buffer is too small" );
Manuel Pégourié-Gonnard31458a12017-06-26 10:11:49 +0200566 if( use_ret == -(MBEDTLS_ERR_X509_FATAL_ERROR) )
Antonin Décimo8fd91562019-01-23 15:24:37 +0100567 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 +0200568#endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200569 // END generated code
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200570
Paul Bakker9d781402011-05-09 16:17:09 +0000571 if( strlen( buf ) == 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200572 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000573 }
574
575 use_ret = ret & ~0xFF80;
576
577 if( use_ret == 0 )
578 return;
579
580 // If high level code is present, make a concatenation between both
581 // error strings.
582 //
583 len = strlen( buf );
584
585 if( len > 0 )
586 {
587 if( buflen - len < 5 )
588 return;
589
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200590 mbedtls_snprintf( buf + len, buflen - len, " : " );
Paul Bakker9d781402011-05-09 16:17:09 +0000591
592 buf += len + 3;
593 buflen -= len + 3;
594 }
595
596 // Low level error codes
597 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200598 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200599#if defined(MBEDTLS_AES_C)
600 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH) )
601 mbedtls_snprintf( buf, buflen, "AES - Invalid key length" );
602 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH) )
603 mbedtls_snprintf( buf, buflen, "AES - Invalid data input length" );
Andres Amaya Garciafd487392017-06-14 16:19:12 +0100604 if( use_ret == -(MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE) )
Rose Zadik7f441272018-01-22 11:48:23 +0000605 mbedtls_snprintf( buf, buflen, "AES - Feature not available. For example, an unsupported AES key size" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100606 if( use_ret == -(MBEDTLS_ERR_AES_HW_ACCEL_FAILED) )
607 mbedtls_snprintf( buf, buflen, "AES - AES hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200608#endif /* MBEDTLS_AES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000609
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100610#if defined(MBEDTLS_ARC4_C)
611 if( use_ret == -(MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED) )
612 mbedtls_snprintf( buf, buflen, "ARC4 - ARC4 hardware accelerator failed" );
613#endif /* MBEDTLS_ARC4_C */
614
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200615#if defined(MBEDTLS_ASN1_PARSE_C)
616 if( use_ret == -(MBEDTLS_ERR_ASN1_OUT_OF_DATA) )
617 mbedtls_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
618 if( use_ret == -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) )
619 mbedtls_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
620 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_LENGTH) )
621 mbedtls_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
622 if( use_ret == -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH) )
623 mbedtls_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
624 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_DATA) )
625 mbedtls_snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200626 if( use_ret == -(MBEDTLS_ERR_ASN1_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200627 mbedtls_snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
628 if( use_ret == -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL) )
629 mbedtls_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
630#endif /* MBEDTLS_ASN1_PARSE_C */
Paul Bakkerdceecd82011-11-15 16:38:34 +0000631
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200632#if defined(MBEDTLS_BASE64_C)
633 if( use_ret == -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) )
634 mbedtls_snprintf( buf, buflen, "BASE64 - Output buffer too small" );
635 if( use_ret == -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER) )
636 mbedtls_snprintf( buf, buflen, "BASE64 - Invalid character in input" );
637#endif /* MBEDTLS_BASE64_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000638
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200639#if defined(MBEDTLS_BIGNUM_C)
640 if( use_ret == -(MBEDTLS_ERR_MPI_FILE_IO_ERROR) )
641 mbedtls_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
642 if( use_ret == -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA) )
643 mbedtls_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
644 if( use_ret == -(MBEDTLS_ERR_MPI_INVALID_CHARACTER) )
645 mbedtls_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
646 if( use_ret == -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL) )
647 mbedtls_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
648 if( use_ret == -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE) )
649 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
650 if( use_ret == -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO) )
651 mbedtls_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
652 if( use_ret == -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) )
653 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200654 if( use_ret == -(MBEDTLS_ERR_MPI_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200655 mbedtls_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
656#endif /* MBEDTLS_BIGNUM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000657
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200658#if defined(MBEDTLS_BLOWFISH_C)
659 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
660 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100661 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED) )
662 mbedtls_snprintf( buf, buflen, "BLOWFISH - Blowfish hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200663 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
664 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
665#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker83f00bb2012-07-04 11:08:50 +0000666
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200667#if defined(MBEDTLS_CAMELLIA_C)
668 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
669 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
670 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
671 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100672 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED) )
673 mbedtls_snprintf( buf, buflen, "CAMELLIA - Camellia hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200674#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000675
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200676#if defined(MBEDTLS_CCM_C)
677 if( use_ret == -(MBEDTLS_ERR_CCM_BAD_INPUT) )
Rose Zadikeecdbea2018-01-24 12:56:53 +0000678 mbedtls_snprintf( buf, buflen, "CCM - Bad input parameters to the function" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200679 if( use_ret == -(MBEDTLS_ERR_CCM_AUTH_FAILED) )
680 mbedtls_snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100681 if( use_ret == -(MBEDTLS_ERR_CCM_HW_ACCEL_FAILED) )
682 mbedtls_snprintf( buf, buflen, "CCM - CCM hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200683#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200684
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100685#if defined(MBEDTLS_CMAC_C)
686 if( use_ret == -(MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED) )
687 mbedtls_snprintf( buf, buflen, "CMAC - CMAC hardware accelerator failed" );
688#endif /* MBEDTLS_CMAC_C */
689
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200690#if defined(MBEDTLS_CTR_DRBG_C)
691 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
692 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
693 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000694 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The requested random buffer length is too big" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200695 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000696 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The input (entropy + additional data) is too large" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200697 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000698 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Read or write error in file" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200699#endif /* MBEDTLS_CTR_DRBG_C */
Paul Bakker880ac7e2011-11-27 14:50:49 +0000700
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200701#if defined(MBEDTLS_DES_C)
702 if( use_ret == -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH) )
703 mbedtls_snprintf( buf, buflen, "DES - The data input has an invalid length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100704 if( use_ret == -(MBEDTLS_ERR_DES_HW_ACCEL_FAILED) )
705 mbedtls_snprintf( buf, buflen, "DES - DES hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200706#endif /* MBEDTLS_DES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000707
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200708#if defined(MBEDTLS_ENTROPY_C)
709 if( use_ret == -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED) )
710 mbedtls_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
711 if( use_ret == -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES) )
712 mbedtls_snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
713 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED) )
714 mbedtls_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
Manuel Pégourié-Gonnardf9cbd732015-06-22 12:06:50 +0200715 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE) )
716 mbedtls_snprintf( buf, buflen, "ENTROPY - No strong sources have been added to poll" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200717 if( use_ret == -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR) )
718 mbedtls_snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
719#endif /* MBEDTLS_ENTROPY_C */
Paul Bakker6083fd22011-12-03 21:45:14 +0000720
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200721#if defined(MBEDTLS_GCM_C)
722 if( use_ret == -(MBEDTLS_ERR_GCM_AUTH_FAILED) )
723 mbedtls_snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100724 if( use_ret == -(MBEDTLS_ERR_GCM_HW_ACCEL_FAILED) )
725 mbedtls_snprintf( buf, buflen, "GCM - GCM hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200726 if( use_ret == -(MBEDTLS_ERR_GCM_BAD_INPUT) )
727 mbedtls_snprintf( buf, buflen, "GCM - Bad input parameters to function" );
728#endif /* MBEDTLS_GCM_C */
Paul Bakker030277a2012-04-17 12:24:26 +0000729
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200730#if defined(MBEDTLS_HMAC_DRBG_C)
731 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
732 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
733 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
734 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
735 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR) )
736 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
737 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
738 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
739#endif /* MBEDTLS_HMAC_DRBG_C */
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100740
Gilles Peskinea381fe82018-01-23 18:16:11 +0100741#if defined(MBEDTLS_MD2_C)
742 if( use_ret == -(MBEDTLS_ERR_MD2_HW_ACCEL_FAILED) )
743 mbedtls_snprintf( buf, buflen, "MD2 - MD2 hardware accelerator failed" );
744#endif /* MBEDTLS_MD2_C */
745
746#if defined(MBEDTLS_MD4_C)
747 if( use_ret == -(MBEDTLS_ERR_MD4_HW_ACCEL_FAILED) )
748 mbedtls_snprintf( buf, buflen, "MD4 - MD4 hardware accelerator failed" );
749#endif /* MBEDTLS_MD4_C */
750
751#if defined(MBEDTLS_MD5_C)
752 if( use_ret == -(MBEDTLS_ERR_MD5_HW_ACCEL_FAILED) )
753 mbedtls_snprintf( buf, buflen, "MD5 - MD5 hardware accelerator failed" );
754#endif /* MBEDTLS_MD5_C */
755
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200756#if defined(MBEDTLS_NET_C)
757 if( use_ret == -(MBEDTLS_ERR_NET_SOCKET_FAILED) )
758 mbedtls_snprintf( buf, buflen, "NET - Failed to open a socket" );
759 if( use_ret == -(MBEDTLS_ERR_NET_CONNECT_FAILED) )
760 mbedtls_snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
761 if( use_ret == -(MBEDTLS_ERR_NET_BIND_FAILED) )
762 mbedtls_snprintf( buf, buflen, "NET - Binding of the socket failed" );
763 if( use_ret == -(MBEDTLS_ERR_NET_LISTEN_FAILED) )
764 mbedtls_snprintf( buf, buflen, "NET - Could not listen on the socket" );
765 if( use_ret == -(MBEDTLS_ERR_NET_ACCEPT_FAILED) )
766 mbedtls_snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
767 if( use_ret == -(MBEDTLS_ERR_NET_RECV_FAILED) )
768 mbedtls_snprintf( buf, buflen, "NET - Reading information from the socket failed" );
769 if( use_ret == -(MBEDTLS_ERR_NET_SEND_FAILED) )
770 mbedtls_snprintf( buf, buflen, "NET - Sending information through the socket failed" );
771 if( use_ret == -(MBEDTLS_ERR_NET_CONN_RESET) )
772 mbedtls_snprintf( buf, buflen, "NET - Connection was reset by peer" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200773 if( use_ret == -(MBEDTLS_ERR_NET_UNKNOWN_HOST) )
774 mbedtls_snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
Manuel Pégourié-Gonnard0b104b02015-05-14 21:52:40 +0200775 if( use_ret == -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL) )
776 mbedtls_snprintf( buf, buflen, "NET - Buffer is too small to hold the data" );
Manuel Pégourié-Gonnard9bd0afd2015-07-01 19:03:27 +0200777 if( use_ret == -(MBEDTLS_ERR_NET_INVALID_CONTEXT) )
778 mbedtls_snprintf( buf, buflen, "NET - The context is invalid, eg because it was free()ed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200779#endif /* MBEDTLS_NET_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000780
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200781#if defined(MBEDTLS_OID_C)
782 if( use_ret == -(MBEDTLS_ERR_OID_NOT_FOUND) )
783 mbedtls_snprintf( buf, buflen, "OID - OID is not found" );
784 if( use_ret == -(MBEDTLS_ERR_OID_BUF_TOO_SMALL) )
785 mbedtls_snprintf( buf, buflen, "OID - output buffer is too small" );
786#endif /* MBEDTLS_OID_C */
Paul Bakkerc70b9822013-04-07 22:00:46 +0200787
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200788#if defined(MBEDTLS_PADLOCK_C)
789 if( use_ret == -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED) )
790 mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
791#endif /* MBEDTLS_PADLOCK_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000792
Gilles Peskinea381fe82018-01-23 18:16:11 +0100793#if defined(MBEDTLS_RIPEMD160_C)
794 if( use_ret == -(MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED) )
795 mbedtls_snprintf( buf, buflen, "RIPEMD160 - RIPEMD160 hardware accelerator failed" );
796#endif /* MBEDTLS_RIPEMD160_C */
797
798#if defined(MBEDTLS_SHA1_C)
799 if( use_ret == -(MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED) )
800 mbedtls_snprintf( buf, buflen, "SHA1 - SHA-1 hardware accelerator failed" );
801#endif /* MBEDTLS_SHA1_C */
802
803#if defined(MBEDTLS_SHA256_C)
804 if( use_ret == -(MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED) )
805 mbedtls_snprintf( buf, buflen, "SHA256 - SHA-256 hardware accelerator failed" );
806#endif /* MBEDTLS_SHA256_C */
807
808#if defined(MBEDTLS_SHA512_C)
809 if( use_ret == -(MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED) )
810 mbedtls_snprintf( buf, buflen, "SHA512 - SHA-512 hardware accelerator failed" );
811#endif /* MBEDTLS_SHA512_C */
812
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200813#if defined(MBEDTLS_THREADING_C)
814 if( use_ret == -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE) )
815 mbedtls_snprintf( buf, buflen, "THREADING - The selected feature is not available" );
816 if( use_ret == -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA) )
817 mbedtls_snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
818 if( use_ret == -(MBEDTLS_ERR_THREADING_MUTEX_ERROR) )
819 mbedtls_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
820#endif /* MBEDTLS_THREADING_C */
Paul Bakker2466d932013-09-28 14:40:38 +0200821
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200822#if defined(MBEDTLS_XTEA_C)
823 if( use_ret == -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH) )
824 mbedtls_snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100825 if( use_ret == -(MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED) )
826 mbedtls_snprintf( buf, buflen, "XTEA - XTEA hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200827#endif /* MBEDTLS_XTEA_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200828 // END generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000829
830 if( strlen( buf ) != 0 )
831 return;
832
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200833 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000834}
835
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200836#else /* MBEDTLS_ERROR_C */
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100837
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200838#if defined(MBEDTLS_ERROR_STRERROR_DUMMY)
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100839
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100840/*
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200841 * Provide an non-function in case MBEDTLS_ERROR_C is not defined
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100842 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200843void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100844{
845 ((void) ret);
846
847 if( buflen > 0 )
848 buf[0] = '\0';
849}
850
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200851#endif /* MBEDTLS_ERROR_STRERROR_DUMMY */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200852
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200853#endif /* MBEDTLS_ERROR_C */