blob: b83b8d1f1ba86a8ff9793be181b12439ac87e33d [file] [log] [blame]
Paul Bakker9d781402011-05-09 16:17:09 +00001/*
2 * Error message information
3 *
Bence Szépkútia2947ac2020-08-19 16:37:36 +02004 * Copyright The Mbed TLS Contributors
Bence Szépkútif744bd72020-06-05 13:02:18 +02005 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
6 *
7 * This file is provided under the Apache License 2.0, or the
8 * GNU General Public License v2.0 or later.
9 *
10 * **********
11 * Apache License 2.0:
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020012 *
13 * Licensed under the Apache License, Version 2.0 (the "License"); you may
14 * not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 * http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
21 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
Paul Bakker9d781402011-05-09 16:17:09 +000024 *
Bence Szépkútif744bd72020-06-05 13:02:18 +020025 * **********
26 *
27 * **********
28 * GNU General Public License v2.0 or later:
29 *
30 * This program is free software; you can redistribute it and/or modify
31 * it under the terms of the GNU General Public License as published by
32 * the Free Software Foundation; either version 2 of the License, or
33 * (at your option) any later version.
34 *
35 * This program is distributed in the hope that it will be useful,
36 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38 * GNU General Public License for more details.
39 *
40 * You should have received a copy of the GNU General Public License along
41 * with this program; if not, write to the Free Software Foundation, Inc.,
42 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
43 *
44 * **********
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 Peskine076c97e2020-11-09 15:14:10 +010054
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000055#include "mbedtls/error.h"
Gilles Peskine076c97e2020-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 Peskine076c97e2020-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
Markku-Juhani O. Saarinen07478d62017-12-01 16:20:15 +000076#if defined(MBEDTLS_ARIA_C)
77#include "mbedtls/aria.h"
78#endif
79
Gilles Peskined2f00732020-05-25 12:23:55 +020080#if defined(MBEDTLS_ASN1_PARSE_C)
81#include "mbedtls/asn1.h"
82#endif
83
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020084#if defined(MBEDTLS_BASE64_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000085#include "mbedtls/base64.h"
Paul Bakker9d781402011-05-09 16:17:09 +000086#endif
87
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020088#if defined(MBEDTLS_BIGNUM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000089#include "mbedtls/bignum.h"
Paul Bakker9d781402011-05-09 16:17:09 +000090#endif
91
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000093#include "mbedtls/blowfish.h"
Paul Bakker83f00bb2012-07-04 11:08:50 +000094#endif
95
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000097#include "mbedtls/camellia.h"
Paul Bakker9d781402011-05-09 16:17:09 +000098#endif
99
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200100#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000101#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200102#endif
103
Daniel King34b822c2016-05-15 17:28:08 -0300104#if defined(MBEDTLS_CHACHA20_C)
105#include "mbedtls/chacha20.h"
106#endif
107
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200108#if defined(MBEDTLS_CHACHAPOLY_C)
109#include "mbedtls/chachapoly.h"
110#endif
111
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200112#if defined(MBEDTLS_CIPHER_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000113#include "mbedtls/cipher.h"
Paul Bakkerff61a782011-06-09 15:42:02 +0000114#endif
115
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100116#if defined(MBEDTLS_CMAC_C)
117#include "mbedtls/cmac.h"
118#endif
119
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200120#if defined(MBEDTLS_CTR_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000121#include "mbedtls/ctr_drbg.h"
Paul Bakker880ac7e2011-11-27 14:50:49 +0000122#endif
123
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000125#include "mbedtls/des.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000126#endif
127
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128#if defined(MBEDTLS_DHM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000129#include "mbedtls/dhm.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000130#endif
131
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200132#if defined(MBEDTLS_ECP_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000133#include "mbedtls/ecp.h"
Paul Bakkercf4365f2013-01-16 17:00:43 +0100134#endif
135
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200136#if defined(MBEDTLS_ENTROPY_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000137#include "mbedtls/entropy.h"
Paul Bakker6083fd22011-12-03 21:45:14 +0000138#endif
139
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000141#include "mbedtls/gcm.h"
Paul Bakker030277a2012-04-17 12:24:26 +0000142#endif
143
Thomas Fossati656864b2016-07-17 08:51:22 +0100144#if defined(MBEDTLS_HKDF_C)
145#include "mbedtls/hkdf.h"
146#endif
147
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200148#if defined(MBEDTLS_HMAC_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000149#include "mbedtls/hmac_drbg.h"
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100150#endif
151
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200152#if defined(MBEDTLS_MD_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000153#include "mbedtls/md.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000154#endif
155
Gilles Peskinea381fe82018-01-23 18:16:11 +0100156#if defined(MBEDTLS_MD2_C)
157#include "mbedtls/md2.h"
158#endif
159
160#if defined(MBEDTLS_MD4_C)
161#include "mbedtls/md4.h"
162#endif
163
164#if defined(MBEDTLS_MD5_C)
165#include "mbedtls/md5.h"
166#endif
167
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200168#if defined(MBEDTLS_NET_C)
Andres AG3616f6f2016-09-14 14:32:09 +0100169#include "mbedtls/net_sockets.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000170#endif
171
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200172#if defined(MBEDTLS_OID_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000173#include "mbedtls/oid.h"
Paul Bakkerc70b9822013-04-07 22:00:46 +0200174#endif
175
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200176#if defined(MBEDTLS_PADLOCK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000177#include "mbedtls/padlock.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000178#endif
179
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200180#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000181#include "mbedtls/pem.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000182#endif
183
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200184#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000185#include "mbedtls/pk.h"
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200186#endif
187
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200188#if defined(MBEDTLS_PKCS12_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000189#include "mbedtls/pkcs12.h"
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200190#endif
191
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200192#if defined(MBEDTLS_PKCS5_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000193#include "mbedtls/pkcs5.h"
Paul Bakkerb0c19a42013-06-24 19:26:38 +0200194#endif
195
Ron Eldor0ff4e0b2018-08-29 18:53:20 +0300196#if defined(MBEDTLS_PLATFORM_C)
197#include "mbedtls/platform.h"
198#endif
199
Daniel Kingadc32c02016-05-16 18:25:45 -0300200#if defined(MBEDTLS_POLY1305_C)
201#include "mbedtls/poly1305.h"
202#endif
203
Gilles Peskinea381fe82018-01-23 18:16:11 +0100204#if defined(MBEDTLS_RIPEMD160_C)
205#include "mbedtls/ripemd160.h"
206#endif
207
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200208#if defined(MBEDTLS_RSA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000209#include "mbedtls/rsa.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000210#endif
211
Gilles Peskinea381fe82018-01-23 18:16:11 +0100212#if defined(MBEDTLS_SHA1_C)
213#include "mbedtls/sha1.h"
214#endif
215
216#if defined(MBEDTLS_SHA256_C)
217#include "mbedtls/sha256.h"
218#endif
219
220#if defined(MBEDTLS_SHA512_C)
221#include "mbedtls/sha512.h"
222#endif
223
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200224#if defined(MBEDTLS_SSL_TLS_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000225#include "mbedtls/ssl.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000226#endif
227
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200228#if defined(MBEDTLS_THREADING_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000229#include "mbedtls/threading.h"
Paul Bakker2466d932013-09-28 14:40:38 +0200230#endif
231
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200232#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000233#include "mbedtls/x509.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000234#endif
235
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200236#if defined(MBEDTLS_XTEA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000237#include "mbedtls/xtea.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000238#endif
239
Paul Bakkerdceecd82011-11-15 16:38:34 +0000240
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200241void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker9d781402011-05-09 16:17:09 +0000242{
243 size_t len;
244 int use_ret;
245
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200246 if( buflen == 0 )
247 return;
248
Paul Bakker9d781402011-05-09 16:17:09 +0000249 memset( buf, 0x00, buflen );
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200250
Paul Bakker9d781402011-05-09 16:17:09 +0000251 if( ret < 0 )
252 ret = -ret;
253
254 if( ret & 0xFF80 )
255 {
256 use_ret = ret & 0xFF80;
257
258 // High level error codes
259 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200260 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200261#if defined(MBEDTLS_CIPHER_C)
262 if( use_ret == -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE) )
263 mbedtls_snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
264 if( use_ret == -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA) )
Rose Zadik9ba6b622018-01-24 12:59:19 +0000265 mbedtls_snprintf( buf, buflen, "CIPHER - Bad input parameters" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200266 if( use_ret == -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED) )
267 mbedtls_snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
268 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_PADDING) )
269 mbedtls_snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
270 if( use_ret == -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
271 mbedtls_snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
272 if( use_ret == -(MBEDTLS_ERR_CIPHER_AUTH_FAILED) )
273 mbedtls_snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
Janos Follath98e28a72016-05-31 14:03:54 +0100274 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT) )
Rose Zadik9ba6b622018-01-24 12:59:19 +0000275 mbedtls_snprintf( buf, buflen, "CIPHER - The context is invalid. For example, because it was freed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100276 if( use_ret == -(MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED) )
277 mbedtls_snprintf( buf, buflen, "CIPHER - Cipher hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200278#endif /* MBEDTLS_CIPHER_C */
Paul Bakkerff61a782011-06-09 15:42:02 +0000279
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200280#if defined(MBEDTLS_DHM_C)
281 if( use_ret == -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA) )
Rose Zadik41ad0822018-01-26 10:54:57 +0000282 mbedtls_snprintf( buf, buflen, "DHM - Bad input parameters" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200283 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED) )
284 mbedtls_snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
285 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED) )
286 mbedtls_snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
287 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED) )
288 mbedtls_snprintf( buf, buflen, "DHM - Reading of the public values failed" );
289 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED) )
290 mbedtls_snprintf( buf, buflen, "DHM - Making of the public value failed" );
291 if( use_ret == -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED) )
292 mbedtls_snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
293 if( use_ret == -(MBEDTLS_ERR_DHM_INVALID_FORMAT) )
294 mbedtls_snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200295 if( use_ret == -(MBEDTLS_ERR_DHM_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200296 mbedtls_snprintf( buf, buflen, "DHM - Allocation of memory failed" );
297 if( use_ret == -(MBEDTLS_ERR_DHM_FILE_IO_ERROR) )
Rose Zadik41ad0822018-01-26 10:54:57 +0000298 mbedtls_snprintf( buf, buflen, "DHM - Read or write of file failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100299 if( use_ret == -(MBEDTLS_ERR_DHM_HW_ACCEL_FAILED) )
300 mbedtls_snprintf( buf, buflen, "DHM - DHM hardware accelerator failed" );
Hanno Beckera6dd90d2017-10-04 13:15:54 +0100301 if( use_ret == -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED) )
Jaeden Amero784de592018-01-26 17:52:01 +0000302 mbedtls_snprintf( buf, buflen, "DHM - Setting the modulus and generator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200303#endif /* MBEDTLS_DHM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000304
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200305#if defined(MBEDTLS_ECP_C)
306 if( use_ret == -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA) )
307 mbedtls_snprintf( buf, buflen, "ECP - Bad input parameters to function" );
308 if( use_ret == -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL) )
309 mbedtls_snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
310 if( use_ret == -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) )
Jaeden Amero3dd8abd2018-04-24 10:56:55 +0100311 mbedtls_snprintf( buf, buflen, "ECP - The requested feature is not available, for example, the requested curve is not supported" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200312 if( use_ret == -(MBEDTLS_ERR_ECP_VERIFY_FAILED) )
313 mbedtls_snprintf( buf, buflen, "ECP - The signature is not valid" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200314 if( use_ret == -(MBEDTLS_ERR_ECP_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200315 mbedtls_snprintf( buf, buflen, "ECP - Memory allocation failed" );
316 if( use_ret == -(MBEDTLS_ERR_ECP_RANDOM_FAILED) )
Jaeden Amero3dd8abd2018-04-24 10:56:55 +0100317 mbedtls_snprintf( buf, buflen, "ECP - Generation of random value, such as ephemeral key, failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200318 if( use_ret == -(MBEDTLS_ERR_ECP_INVALID_KEY) )
319 mbedtls_snprintf( buf, buflen, "ECP - Invalid private or public key" );
320 if( use_ret == -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) )
Gilles Peskinecc78ac42018-03-30 18:52:10 +0200321 mbedtls_snprintf( buf, buflen, "ECP - The buffer contains a valid signature followed by more data" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100322 if( use_ret == -(MBEDTLS_ERR_ECP_HW_ACCEL_FAILED) )
Jaeden Amero3dd8abd2018-04-24 10:56:55 +0100323 mbedtls_snprintf( buf, buflen, "ECP - The ECP hardware accelerator failed" );
Manuel Pégourié-Gonnard5e3c62f2017-03-08 10:14:11 +0100324 if( use_ret == -(MBEDTLS_ERR_ECP_IN_PROGRESS) )
Manuel Pégourié-Gonnardf0bbd7e2018-10-15 13:22:41 +0200325 mbedtls_snprintf( buf, buflen, "ECP - Operation in progress, call again with the same parameters to continue" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200326#endif /* MBEDTLS_ECP_C */
Paul Bakkercf4365f2013-01-16 17:00:43 +0100327
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200328#if defined(MBEDTLS_MD_C)
329 if( use_ret == -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE) )
330 mbedtls_snprintf( buf, buflen, "MD - The selected feature is not available" );
331 if( use_ret == -(MBEDTLS_ERR_MD_BAD_INPUT_DATA) )
332 mbedtls_snprintf( buf, buflen, "MD - Bad input parameters to function" );
333 if( use_ret == -(MBEDTLS_ERR_MD_ALLOC_FAILED) )
334 mbedtls_snprintf( buf, buflen, "MD - Failed to allocate memory" );
335 if( use_ret == -(MBEDTLS_ERR_MD_FILE_IO_ERROR) )
336 mbedtls_snprintf( buf, buflen, "MD - Opening or reading of file failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100337 if( use_ret == -(MBEDTLS_ERR_MD_HW_ACCEL_FAILED) )
338 mbedtls_snprintf( buf, buflen, "MD - MD hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200339#endif /* MBEDTLS_MD_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000340
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200341#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
342 if( use_ret == -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
343 mbedtls_snprintf( buf, buflen, "PEM - No PEM header or footer found" );
344 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_DATA) )
345 mbedtls_snprintf( buf, buflen, "PEM - PEM string is not as expected" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200346 if( use_ret == -(MBEDTLS_ERR_PEM_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200347 mbedtls_snprintf( buf, buflen, "PEM - Failed to allocate memory" );
348 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_ENC_IV) )
349 mbedtls_snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
350 if( use_ret == -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG) )
351 mbedtls_snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
352 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) )
353 mbedtls_snprintf( buf, buflen, "PEM - Private key password can't be empty" );
354 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) )
355 mbedtls_snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
356 if( use_ret == -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE) )
357 mbedtls_snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
358 if( use_ret == -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA) )
359 mbedtls_snprintf( buf, buflen, "PEM - Bad input parameters to function" );
360#endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000361
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200362#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200363 if( use_ret == -(MBEDTLS_ERR_PK_ALLOC_FAILED) )
Manuel Pégourié-Gonnard41b9c2b2015-05-28 14:56:20 +0200364 mbedtls_snprintf( buf, buflen, "PK - Memory allocation failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200365 if( use_ret == -(MBEDTLS_ERR_PK_TYPE_MISMATCH) )
366 mbedtls_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
367 if( use_ret == -(MBEDTLS_ERR_PK_BAD_INPUT_DATA) )
368 mbedtls_snprintf( buf, buflen, "PK - Bad input parameters to function" );
369 if( use_ret == -(MBEDTLS_ERR_PK_FILE_IO_ERROR) )
370 mbedtls_snprintf( buf, buflen, "PK - Read/write of file failed" );
371 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION) )
372 mbedtls_snprintf( buf, buflen, "PK - Unsupported key version" );
373 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT) )
374 mbedtls_snprintf( buf, buflen, "PK - Invalid key tag or value" );
375 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG) )
376 mbedtls_snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
377 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED) )
378 mbedtls_snprintf( buf, buflen, "PK - Private key password can't be empty" );
379 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH) )
380 mbedtls_snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
381 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_PUBKEY) )
382 mbedtls_snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
383 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_ALG) )
384 mbedtls_snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
385 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE) )
386 mbedtls_snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
387 if( use_ret == -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) )
388 mbedtls_snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
389 if( use_ret == -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH) )
Gilles Peskinecc78ac42018-03-30 18:52:10 +0200390 mbedtls_snprintf( buf, buflen, "PK - The buffer contains a valid signature followed by more data" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100391 if( use_ret == -(MBEDTLS_ERR_PK_HW_ACCEL_FAILED) )
392 mbedtls_snprintf( buf, buflen, "PK - PK hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200393#endif /* MBEDTLS_PK_C */
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200394
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200395#if defined(MBEDTLS_PKCS12_C)
396 if( use_ret == -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA) )
397 mbedtls_snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
398 if( use_ret == -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE) )
399 mbedtls_snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
400 if( use_ret == -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT) )
401 mbedtls_snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
402 if( use_ret == -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) )
403 mbedtls_snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
404#endif /* MBEDTLS_PKCS12_C */
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200405
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200406#if defined(MBEDTLS_PKCS5_C)
407 if( use_ret == -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA) )
408 mbedtls_snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
409 if( use_ret == -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT) )
410 mbedtls_snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
411 if( use_ret == -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE) )
412 mbedtls_snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
413 if( use_ret == -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) )
414 mbedtls_snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
415#endif /* MBEDTLS_PKCS5_C */
Paul Bakker28144de2013-06-24 19:28:55 +0200416
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200417#if defined(MBEDTLS_RSA_C)
418 if( use_ret == -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA) )
419 mbedtls_snprintf( buf, buflen, "RSA - Bad input parameters to function" );
420 if( use_ret == -(MBEDTLS_ERR_RSA_INVALID_PADDING) )
421 mbedtls_snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
422 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED) )
423 mbedtls_snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
424 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED) )
Rose Zadik042e97f2018-01-26 16:35:10 +0000425 mbedtls_snprintf( buf, buflen, "RSA - Key failed to pass the validity check of the library" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200426 if( use_ret == -(MBEDTLS_ERR_RSA_PUBLIC_FAILED) )
427 mbedtls_snprintf( buf, buflen, "RSA - The public key operation failed" );
428 if( use_ret == -(MBEDTLS_ERR_RSA_PRIVATE_FAILED) )
429 mbedtls_snprintf( buf, buflen, "RSA - The private key operation failed" );
430 if( use_ret == -(MBEDTLS_ERR_RSA_VERIFY_FAILED) )
431 mbedtls_snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
432 if( use_ret == -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE) )
433 mbedtls_snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
434 if( use_ret == -(MBEDTLS_ERR_RSA_RNG_FAILED) )
435 mbedtls_snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
Hanno Becker3cdc7112017-10-05 10:09:31 +0100436 if( use_ret == -(MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION) )
Rose Zadik042e97f2018-01-26 16:35:10 +0000437 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 +0100438 if( use_ret == -(MBEDTLS_ERR_RSA_HW_ACCEL_FAILED) )
439 mbedtls_snprintf( buf, buflen, "RSA - RSA hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200440#endif /* MBEDTLS_RSA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000441
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200442#if defined(MBEDTLS_SSL_TLS_C)
443 if( use_ret == -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE) )
444 mbedtls_snprintf( buf, buflen, "SSL - The requested feature is not available" );
445 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA) )
446 mbedtls_snprintf( buf, buflen, "SSL - Bad input parameters to function" );
447 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_MAC) )
448 mbedtls_snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
449 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_RECORD) )
450 mbedtls_snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
451 if( use_ret == -(MBEDTLS_ERR_SSL_CONN_EOF) )
452 mbedtls_snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
453 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER) )
454 mbedtls_snprintf( buf, buflen, "SSL - An unknown cipher was received" );
455 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN) )
456 mbedtls_snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
457 if( use_ret == -(MBEDTLS_ERR_SSL_NO_RNG) )
458 mbedtls_snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
459 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE) )
460 mbedtls_snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
461 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE) )
462 mbedtls_snprintf( buf, buflen, "SSL - Our own certificate(s) is/are too large to send in an SSL message" );
463 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED) )
464 mbedtls_snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
465 if( use_ret == -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED) )
466 mbedtls_snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
467 if( use_ret == -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED) )
468 mbedtls_snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
469 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE) )
470 mbedtls_snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
471 if( use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE) )
Paul Bakker3aac1da2012-05-08 13:12:27 +0000472 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200473 mbedtls_snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
Paul Bakker3aac1da2012-05-08 13:12:27 +0000474 return;
475 }
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200476 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED) )
477 mbedtls_snprintf( buf, buflen, "SSL - Verification of our peer failed" );
478 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) )
479 mbedtls_snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
480 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO) )
481 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
482 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO) )
483 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
484 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE) )
485 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
486 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
487 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
488 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
489 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
490 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
491 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
492 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
493 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
494 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
495 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
496 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
497 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
498 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
499 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
500 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
501 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
502 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED) )
503 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200504 if( use_ret == -(MBEDTLS_ERR_SSL_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200505 mbedtls_snprintf( buf, buflen, "SSL - Memory allocation failed" );
506 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED) )
507 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
508 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
509 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
510 if( use_ret == -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED) )
511 mbedtls_snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
512 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
513 mbedtls_snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
514 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
515 mbedtls_snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
516 if( use_ret == -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED) )
517 mbedtls_snprintf( buf, buflen, "SSL - Session ticket has expired" );
518 if( use_ret == -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH) )
519 mbedtls_snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
520 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY) )
521 mbedtls_snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
522 if( use_ret == -(MBEDTLS_ERR_SSL_INTERNAL_ERROR) )
523 mbedtls_snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
524 if( use_ret == -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING) )
525 mbedtls_snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
526 if( use_ret == -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO) )
527 mbedtls_snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" );
528 if( use_ret == -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED) )
529 mbedtls_snprintf( buf, buflen, "SSL - DTLS client must retry for hello verification" );
530 if( use_ret == -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL) )
531 mbedtls_snprintf( buf, buflen, "SSL - A buffer is too small to receive or write a message" );
532 if( use_ret == -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE) )
533 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 +0100534 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_READ) )
Hanno Becker8ec81022017-10-10 10:35:08 +0100535 mbedtls_snprintf( buf, buflen, "SSL - No data of requested type currently available on underlying transport" );
Manuel Pégourié-Gonnard88369942015-05-06 16:19:31 +0100536 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_WRITE) )
537 mbedtls_snprintf( buf, buflen, "SSL - Connection requires a write call" );
538 if( use_ret == -(MBEDTLS_ERR_SSL_TIMEOUT) )
539 mbedtls_snprintf( buf, buflen, "SSL - The operation timed out" );
Manuel Pégourié-Gonnardbe619c12015-09-08 11:21:21 +0200540 if( use_ret == -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT) )
541 mbedtls_snprintf( buf, buflen, "SSL - The client initiated a reconnect from the same port" );
Manuel Pégourié-Gonnarde2e25e72015-12-03 16:13:17 +0100542 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD) )
543 mbedtls_snprintf( buf, buflen, "SSL - Record header looks valid but is not expected" );
Simon Butcher99000142016-10-13 17:21:01 +0100544 if( use_ret == -(MBEDTLS_ERR_SSL_NON_FATAL) )
545 mbedtls_snprintf( buf, buflen, "SSL - The alert message received indicates a non-fatal error" );
546 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH) )
547 mbedtls_snprintf( buf, buflen, "SSL - Couldn't set the hash for verifying CertificateVerify" );
Hanno Becker8ec81022017-10-10 10:35:08 +0100548 if( use_ret == -(MBEDTLS_ERR_SSL_CONTINUE_PROCESSING) )
Hanno Beckerc9f4d6d2018-03-19 09:23:13 +0000549 mbedtls_snprintf( buf, buflen, "SSL - Internal-only message signaling that further message-processing should be done" );
Gilles Peskine8bf79f62018-01-05 21:11:53 +0100550 if( use_ret == -(MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS) )
Gilles Peskineb44692f2018-04-24 12:18:19 +0200551 mbedtls_snprintf( buf, buflen, "SSL - The asynchronous operation is not completed yet" );
Hanno Beckerb063a5f2018-08-16 16:06:44 +0100552 if( use_ret == -(MBEDTLS_ERR_SSL_EARLY_MESSAGE) )
553 mbedtls_snprintf( buf, buflen, "SSL - Internal-only message signaling that a message arrived early" );
Manuel Pégourié-Gonnard558da9c2018-06-13 12:02:12 +0200554 if( use_ret == -(MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS) )
555 mbedtls_snprintf( buf, buflen, "SSL - A cryptographic operation is in progress. Try again later" );
Hanno Beckerd7296022017-04-12 14:54:42 +0100556 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_CONFIG) )
557 mbedtls_snprintf( buf, buflen, "SSL - Invalid value in SSL config" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200558#endif /* MBEDTLS_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000559
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200560#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
561 if( use_ret == -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) )
562 mbedtls_snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
563 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_OID) )
564 mbedtls_snprintf( buf, buflen, "X509 - Requested OID is unknown" );
565 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_FORMAT) )
566 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
567 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_VERSION) )
568 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
569 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SERIAL) )
570 mbedtls_snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
571 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_ALG) )
572 mbedtls_snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
573 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_NAME) )
574 mbedtls_snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
575 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_DATE) )
576 mbedtls_snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
577 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SIGNATURE) )
578 mbedtls_snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
579 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS) )
580 mbedtls_snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
581 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_VERSION) )
582 mbedtls_snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
583 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG) )
584 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
585 if( use_ret == -(MBEDTLS_ERR_X509_SIG_MISMATCH) )
586 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" );
587 if( use_ret == -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) )
588 mbedtls_snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
589 if( use_ret == -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT) )
590 mbedtls_snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
591 if( use_ret == -(MBEDTLS_ERR_X509_BAD_INPUT_DATA) )
592 mbedtls_snprintf( buf, buflen, "X509 - Input invalid" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200593 if( use_ret == -(MBEDTLS_ERR_X509_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200594 mbedtls_snprintf( buf, buflen, "X509 - Allocation of memory failed" );
595 if( use_ret == -(MBEDTLS_ERR_X509_FILE_IO_ERROR) )
596 mbedtls_snprintf( buf, buflen, "X509 - Read/write of file failed" );
Manuel Pégourié-Gonnard9dbaf402015-06-22 11:50:58 +0200597 if( use_ret == -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL) )
598 mbedtls_snprintf( buf, buflen, "X509 - Destination buffer is too small" );
Manuel Pégourié-Gonnard31458a12017-06-26 10:11:49 +0200599 if( use_ret == -(MBEDTLS_ERR_X509_FATAL_ERROR) )
Antonin Décimod5f47592019-01-23 15:24:37 +0100600 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 +0200601#endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200602 // END generated code
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200603
Paul Bakker9d781402011-05-09 16:17:09 +0000604 if( strlen( buf ) == 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200605 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000606 }
607
608 use_ret = ret & ~0xFF80;
609
610 if( use_ret == 0 )
611 return;
612
613 // If high level code is present, make a concatenation between both
614 // error strings.
615 //
616 len = strlen( buf );
617
618 if( len > 0 )
619 {
620 if( buflen - len < 5 )
621 return;
622
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200623 mbedtls_snprintf( buf + len, buflen - len, " : " );
Paul Bakker9d781402011-05-09 16:17:09 +0000624
625 buf += len + 3;
626 buflen -= len + 3;
627 }
628
629 // Low level error codes
630 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200631 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200632#if defined(MBEDTLS_AES_C)
633 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH) )
634 mbedtls_snprintf( buf, buflen, "AES - Invalid key length" );
635 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH) )
636 mbedtls_snprintf( buf, buflen, "AES - Invalid data input length" );
Mohammad Azim Khane5b5bd72017-11-24 10:52:51 +0000637 if( use_ret == -(MBEDTLS_ERR_AES_BAD_INPUT_DATA) )
638 mbedtls_snprintf( buf, buflen, "AES - Invalid input data" );
Andres Amaya Garciafd487392017-06-14 16:19:12 +0100639 if( use_ret == -(MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE) )
Rose Zadik7f441272018-01-22 11:48:23 +0000640 mbedtls_snprintf( buf, buflen, "AES - Feature not available. For example, an unsupported AES key size" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100641 if( use_ret == -(MBEDTLS_ERR_AES_HW_ACCEL_FAILED) )
642 mbedtls_snprintf( buf, buflen, "AES - AES hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200643#endif /* MBEDTLS_AES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000644
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100645#if defined(MBEDTLS_ARC4_C)
646 if( use_ret == -(MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED) )
647 mbedtls_snprintf( buf, buflen, "ARC4 - ARC4 hardware accelerator failed" );
648#endif /* MBEDTLS_ARC4_C */
649
Markku-Juhani O. Saarinen07478d62017-12-01 16:20:15 +0000650#if defined(MBEDTLS_ARIA_C)
Hanno Becker32142152018-12-17 13:25:58 +0000651 if( use_ret == -(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA) )
652 mbedtls_snprintf( buf, buflen, "ARIA - Bad input data" );
Hanno Beckera0343692018-12-18 09:42:58 +0000653 if( use_ret == -(MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH) )
654 mbedtls_snprintf( buf, buflen, "ARIA - Invalid data input length" );
Manuel Pégourié-Gonnard3c800092018-03-01 09:02:16 +0100655 if( use_ret == -(MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE) )
656 mbedtls_snprintf( buf, buflen, "ARIA - Feature not available. For example, an unsupported ARIA key size" );
657 if( use_ret == -(MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED) )
658 mbedtls_snprintf( buf, buflen, "ARIA - ARIA hardware accelerator failed" );
Markku-Juhani O. Saarinen07478d62017-12-01 16:20:15 +0000659#endif /* MBEDTLS_ARIA_C */
660
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200661#if defined(MBEDTLS_ASN1_PARSE_C)
662 if( use_ret == -(MBEDTLS_ERR_ASN1_OUT_OF_DATA) )
663 mbedtls_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
664 if( use_ret == -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) )
665 mbedtls_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
666 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_LENGTH) )
667 mbedtls_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
668 if( use_ret == -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH) )
669 mbedtls_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
670 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_DATA) )
671 mbedtls_snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200672 if( use_ret == -(MBEDTLS_ERR_ASN1_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200673 mbedtls_snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
674 if( use_ret == -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL) )
675 mbedtls_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
676#endif /* MBEDTLS_ASN1_PARSE_C */
Paul Bakkerdceecd82011-11-15 16:38:34 +0000677
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200678#if defined(MBEDTLS_BASE64_C)
679 if( use_ret == -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) )
680 mbedtls_snprintf( buf, buflen, "BASE64 - Output buffer too small" );
681 if( use_ret == -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER) )
682 mbedtls_snprintf( buf, buflen, "BASE64 - Invalid character in input" );
683#endif /* MBEDTLS_BASE64_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000684
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200685#if defined(MBEDTLS_BIGNUM_C)
686 if( use_ret == -(MBEDTLS_ERR_MPI_FILE_IO_ERROR) )
687 mbedtls_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
688 if( use_ret == -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA) )
689 mbedtls_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
690 if( use_ret == -(MBEDTLS_ERR_MPI_INVALID_CHARACTER) )
691 mbedtls_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
692 if( use_ret == -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL) )
693 mbedtls_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
694 if( use_ret == -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE) )
695 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
696 if( use_ret == -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO) )
697 mbedtls_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
698 if( use_ret == -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) )
699 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200700 if( use_ret == -(MBEDTLS_ERR_MPI_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200701 mbedtls_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
702#endif /* MBEDTLS_BIGNUM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000703
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200704#if defined(MBEDTLS_BLOWFISH_C)
Hanno Becker32142152018-12-17 13:25:58 +0000705 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA) )
706 mbedtls_snprintf( buf, buflen, "BLOWFISH - Bad input data" );
Hanno Becker6640b0d2018-12-18 09:45:17 +0000707 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
708 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100709 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED) )
710 mbedtls_snprintf( buf, buflen, "BLOWFISH - Blowfish hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200711#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker83f00bb2012-07-04 11:08:50 +0000712
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200713#if defined(MBEDTLS_CAMELLIA_C)
Hanno Becker32142152018-12-17 13:25:58 +0000714 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA) )
715 mbedtls_snprintf( buf, buflen, "CAMELLIA - Bad input data" );
Hanno Becker938f9e92018-12-18 09:40:25 +0000716 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
717 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100718 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED) )
719 mbedtls_snprintf( buf, buflen, "CAMELLIA - Camellia hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200720#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000721
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200722#if defined(MBEDTLS_CCM_C)
723 if( use_ret == -(MBEDTLS_ERR_CCM_BAD_INPUT) )
Rose Zadikeecdbea2018-01-24 12:56:53 +0000724 mbedtls_snprintf( buf, buflen, "CCM - Bad input parameters to the function" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200725 if( use_ret == -(MBEDTLS_ERR_CCM_AUTH_FAILED) )
726 mbedtls_snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100727 if( use_ret == -(MBEDTLS_ERR_CCM_HW_ACCEL_FAILED) )
728 mbedtls_snprintf( buf, buflen, "CCM - CCM hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200729#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200730
Daniel King34b822c2016-05-15 17:28:08 -0300731#if defined(MBEDTLS_CHACHA20_C)
732 if( use_ret == -(MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA) )
733 mbedtls_snprintf( buf, buflen, "CHACHA20 - Invalid input parameter(s)" );
Manuel Pégourié-Gonnardb8bd80a2018-05-09 09:54:51 +0200734 if( use_ret == -(MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE) )
735 mbedtls_snprintf( buf, buflen, "CHACHA20 - Feature not available. For example, s part of the API is not implemented" );
Manuel Pégourié-Gonnard3798b6b2018-05-24 13:27:45 +0200736 if( use_ret == -(MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED) )
737 mbedtls_snprintf( buf, buflen, "CHACHA20 - Chacha20 hardware accelerator failed" );
Daniel King34b822c2016-05-15 17:28:08 -0300738#endif /* MBEDTLS_CHACHA20_C */
739
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200740#if defined(MBEDTLS_CHACHAPOLY_C)
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200741 if( use_ret == -(MBEDTLS_ERR_CHACHAPOLY_BAD_STATE) )
742 mbedtls_snprintf( buf, buflen, "CHACHAPOLY - The requested operation is not permitted in the current state" );
Manuel Pégourié-Gonnardb8bd80a2018-05-09 09:54:51 +0200743 if( use_ret == -(MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED) )
744 mbedtls_snprintf( buf, buflen, "CHACHAPOLY - Authenticated decryption failed: data was not authentic" );
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200745#endif /* MBEDTLS_CHACHAPOLY_C */
746
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100747#if defined(MBEDTLS_CMAC_C)
748 if( use_ret == -(MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED) )
749 mbedtls_snprintf( buf, buflen, "CMAC - CMAC hardware accelerator failed" );
750#endif /* MBEDTLS_CMAC_C */
751
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200752#if defined(MBEDTLS_CTR_DRBG_C)
753 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
754 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
755 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000756 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The requested random buffer length is too big" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200757 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000758 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The input (entropy + additional data) is too large" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200759 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000760 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Read or write error in file" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200761#endif /* MBEDTLS_CTR_DRBG_C */
Paul Bakker880ac7e2011-11-27 14:50:49 +0000762
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200763#if defined(MBEDTLS_DES_C)
764 if( use_ret == -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH) )
765 mbedtls_snprintf( buf, buflen, "DES - The data input has an invalid length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100766 if( use_ret == -(MBEDTLS_ERR_DES_HW_ACCEL_FAILED) )
767 mbedtls_snprintf( buf, buflen, "DES - DES hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200768#endif /* MBEDTLS_DES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000769
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200770#if defined(MBEDTLS_ENTROPY_C)
771 if( use_ret == -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED) )
772 mbedtls_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
773 if( use_ret == -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES) )
774 mbedtls_snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
775 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED) )
776 mbedtls_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
Manuel Pégourié-Gonnardf9cbd732015-06-22 12:06:50 +0200777 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE) )
778 mbedtls_snprintf( buf, buflen, "ENTROPY - No strong sources have been added to poll" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200779 if( use_ret == -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR) )
780 mbedtls_snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
781#endif /* MBEDTLS_ENTROPY_C */
Paul Bakker6083fd22011-12-03 21:45:14 +0000782
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200783#if defined(MBEDTLS_GCM_C)
784 if( use_ret == -(MBEDTLS_ERR_GCM_AUTH_FAILED) )
785 mbedtls_snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100786 if( use_ret == -(MBEDTLS_ERR_GCM_HW_ACCEL_FAILED) )
787 mbedtls_snprintf( buf, buflen, "GCM - GCM hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200788 if( use_ret == -(MBEDTLS_ERR_GCM_BAD_INPUT) )
789 mbedtls_snprintf( buf, buflen, "GCM - Bad input parameters to function" );
790#endif /* MBEDTLS_GCM_C */
Paul Bakker030277a2012-04-17 12:24:26 +0000791
Thomas Fossati656864b2016-07-17 08:51:22 +0100792#if defined(MBEDTLS_HKDF_C)
793 if( use_ret == -(MBEDTLS_ERR_HKDF_BAD_INPUT_DATA) )
794 mbedtls_snprintf( buf, buflen, "HKDF - Bad input parameters to function" );
795#endif /* MBEDTLS_HKDF_C */
796
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200797#if defined(MBEDTLS_HMAC_DRBG_C)
798 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
799 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
800 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
801 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
802 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR) )
803 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
804 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
805 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
806#endif /* MBEDTLS_HMAC_DRBG_C */
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100807
Gilles Peskinea381fe82018-01-23 18:16:11 +0100808#if defined(MBEDTLS_MD2_C)
809 if( use_ret == -(MBEDTLS_ERR_MD2_HW_ACCEL_FAILED) )
810 mbedtls_snprintf( buf, buflen, "MD2 - MD2 hardware accelerator failed" );
811#endif /* MBEDTLS_MD2_C */
812
813#if defined(MBEDTLS_MD4_C)
814 if( use_ret == -(MBEDTLS_ERR_MD4_HW_ACCEL_FAILED) )
815 mbedtls_snprintf( buf, buflen, "MD4 - MD4 hardware accelerator failed" );
816#endif /* MBEDTLS_MD4_C */
817
818#if defined(MBEDTLS_MD5_C)
819 if( use_ret == -(MBEDTLS_ERR_MD5_HW_ACCEL_FAILED) )
820 mbedtls_snprintf( buf, buflen, "MD5 - MD5 hardware accelerator failed" );
821#endif /* MBEDTLS_MD5_C */
822
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200823#if defined(MBEDTLS_NET_C)
824 if( use_ret == -(MBEDTLS_ERR_NET_SOCKET_FAILED) )
825 mbedtls_snprintf( buf, buflen, "NET - Failed to open a socket" );
826 if( use_ret == -(MBEDTLS_ERR_NET_CONNECT_FAILED) )
827 mbedtls_snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
828 if( use_ret == -(MBEDTLS_ERR_NET_BIND_FAILED) )
829 mbedtls_snprintf( buf, buflen, "NET - Binding of the socket failed" );
830 if( use_ret == -(MBEDTLS_ERR_NET_LISTEN_FAILED) )
831 mbedtls_snprintf( buf, buflen, "NET - Could not listen on the socket" );
832 if( use_ret == -(MBEDTLS_ERR_NET_ACCEPT_FAILED) )
833 mbedtls_snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
834 if( use_ret == -(MBEDTLS_ERR_NET_RECV_FAILED) )
835 mbedtls_snprintf( buf, buflen, "NET - Reading information from the socket failed" );
836 if( use_ret == -(MBEDTLS_ERR_NET_SEND_FAILED) )
837 mbedtls_snprintf( buf, buflen, "NET - Sending information through the socket failed" );
838 if( use_ret == -(MBEDTLS_ERR_NET_CONN_RESET) )
839 mbedtls_snprintf( buf, buflen, "NET - Connection was reset by peer" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200840 if( use_ret == -(MBEDTLS_ERR_NET_UNKNOWN_HOST) )
841 mbedtls_snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
Manuel Pégourié-Gonnard0b104b02015-05-14 21:52:40 +0200842 if( use_ret == -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL) )
843 mbedtls_snprintf( buf, buflen, "NET - Buffer is too small to hold the data" );
Manuel Pégourié-Gonnard9bd0afd2015-07-01 19:03:27 +0200844 if( use_ret == -(MBEDTLS_ERR_NET_INVALID_CONTEXT) )
845 mbedtls_snprintf( buf, buflen, "NET - The context is invalid, eg because it was free()ed" );
Hanno Beckere09ca3d2017-05-22 15:06:06 +0100846 if( use_ret == -(MBEDTLS_ERR_NET_POLL_FAILED) )
847 mbedtls_snprintf( buf, buflen, "NET - Polling the net context failed" );
848 if( use_ret == -(MBEDTLS_ERR_NET_BAD_INPUT_DATA) )
849 mbedtls_snprintf( buf, buflen, "NET - Input invalid" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200850#endif /* MBEDTLS_NET_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000851
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200852#if defined(MBEDTLS_OID_C)
853 if( use_ret == -(MBEDTLS_ERR_OID_NOT_FOUND) )
854 mbedtls_snprintf( buf, buflen, "OID - OID is not found" );
855 if( use_ret == -(MBEDTLS_ERR_OID_BUF_TOO_SMALL) )
856 mbedtls_snprintf( buf, buflen, "OID - output buffer is too small" );
857#endif /* MBEDTLS_OID_C */
Paul Bakkerc70b9822013-04-07 22:00:46 +0200858
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200859#if defined(MBEDTLS_PADLOCK_C)
860 if( use_ret == -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED) )
861 mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
862#endif /* MBEDTLS_PADLOCK_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000863
Ron Eldor0ff4e0b2018-08-29 18:53:20 +0300864#if defined(MBEDTLS_PLATFORM_C)
Ron Eldora27190b2018-10-15 16:33:43 +0300865 if( use_ret == -(MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED) )
Ron Eldor5267b622018-10-15 18:44:42 +0300866 mbedtls_snprintf( buf, buflen, "PLATFORM - Hardware accelerator failed" );
Ron Eldorbcca58c2018-10-03 16:33:21 +0300867 if( use_ret == -(MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) )
868 mbedtls_snprintf( buf, buflen, "PLATFORM - The requested feature is not supported by the platform" );
Ron Eldor0ff4e0b2018-08-29 18:53:20 +0300869#endif /* MBEDTLS_PLATFORM_C */
870
Daniel Kingadc32c02016-05-16 18:25:45 -0300871#if defined(MBEDTLS_POLY1305_C)
872 if( use_ret == -(MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA) )
873 mbedtls_snprintf( buf, buflen, "POLY1305 - Invalid input parameter(s)" );
Manuel Pégourié-Gonnardb8bd80a2018-05-09 09:54:51 +0200874 if( use_ret == -(MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE) )
875 mbedtls_snprintf( buf, buflen, "POLY1305 - Feature not available. For example, s part of the API is not implemented" );
Manuel Pégourié-Gonnard3798b6b2018-05-24 13:27:45 +0200876 if( use_ret == -(MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED) )
877 mbedtls_snprintf( buf, buflen, "POLY1305 - Poly1305 hardware accelerator failed" );
Daniel Kingadc32c02016-05-16 18:25:45 -0300878#endif /* MBEDTLS_POLY1305_C */
879
Gilles Peskinea381fe82018-01-23 18:16:11 +0100880#if defined(MBEDTLS_RIPEMD160_C)
881 if( use_ret == -(MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED) )
882 mbedtls_snprintf( buf, buflen, "RIPEMD160 - RIPEMD160 hardware accelerator failed" );
883#endif /* MBEDTLS_RIPEMD160_C */
884
885#if defined(MBEDTLS_SHA1_C)
886 if( use_ret == -(MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED) )
887 mbedtls_snprintf( buf, buflen, "SHA1 - SHA-1 hardware accelerator failed" );
Andres Amaya Garciaa685d4f2018-12-09 19:13:01 +0000888 if( use_ret == -(MBEDTLS_ERR_SHA1_BAD_INPUT_DATA) )
Hanno Becker859522a2018-12-19 09:54:14 +0000889 mbedtls_snprintf( buf, buflen, "SHA1 - SHA-1 input data was malformed" );
Gilles Peskinea381fe82018-01-23 18:16:11 +0100890#endif /* MBEDTLS_SHA1_C */
891
892#if defined(MBEDTLS_SHA256_C)
893 if( use_ret == -(MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED) )
894 mbedtls_snprintf( buf, buflen, "SHA256 - SHA-256 hardware accelerator failed" );
Andres Amaya Garcia9e76c0e2018-12-09 20:42:05 +0000895 if( use_ret == -(MBEDTLS_ERR_SHA256_BAD_INPUT_DATA) )
Hanno Beckerd8e4f4a2018-12-19 09:54:55 +0000896 mbedtls_snprintf( buf, buflen, "SHA256 - SHA-256 input data was malformed" );
Gilles Peskinea381fe82018-01-23 18:16:11 +0100897#endif /* MBEDTLS_SHA256_C */
898
899#if defined(MBEDTLS_SHA512_C)
900 if( use_ret == -(MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED) )
901 mbedtls_snprintf( buf, buflen, "SHA512 - SHA-512 hardware accelerator failed" );
Andres Amaya Garcia863d4832018-12-09 20:58:52 +0000902 if( use_ret == -(MBEDTLS_ERR_SHA512_BAD_INPUT_DATA) )
Hanno Becker9994e0d2018-12-19 09:55:40 +0000903 mbedtls_snprintf( buf, buflen, "SHA512 - SHA-512 input data was malformed" );
Gilles Peskinea381fe82018-01-23 18:16:11 +0100904#endif /* MBEDTLS_SHA512_C */
905
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200906#if defined(MBEDTLS_THREADING_C)
907 if( use_ret == -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE) )
908 mbedtls_snprintf( buf, buflen, "THREADING - The selected feature is not available" );
909 if( use_ret == -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA) )
910 mbedtls_snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
911 if( use_ret == -(MBEDTLS_ERR_THREADING_MUTEX_ERROR) )
912 mbedtls_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
913#endif /* MBEDTLS_THREADING_C */
Paul Bakker2466d932013-09-28 14:40:38 +0200914
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200915#if defined(MBEDTLS_XTEA_C)
916 if( use_ret == -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH) )
917 mbedtls_snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100918 if( use_ret == -(MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED) )
919 mbedtls_snprintf( buf, buflen, "XTEA - XTEA hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200920#endif /* MBEDTLS_XTEA_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200921 // END generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000922
923 if( strlen( buf ) != 0 )
924 return;
925
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200926 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000927}
928
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200929#else /* MBEDTLS_ERROR_C */
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100930
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100931/*
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200932 * Provide an non-function in case MBEDTLS_ERROR_C is not defined
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100933 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200934void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100935{
936 ((void) ret);
937
938 if( buflen > 0 )
939 buf[0] = '\0';
940}
941
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200942#endif /* MBEDTLS_ERROR_C */
Gilles Peskine076c97e2020-11-09 15:14:10 +0100943
944#endif /* MBEDTLS_ERROR_C || MBEDTLS_ERROR_STRERROR_DUMMY */