blob: c993524fe3635c1e2aa0ecd7d253fcb6a838dcc0 [file] [log] [blame]
Paul Bakker9d781402011-05-09 16:17:09 +00001/*
2 * Error message information
3 *
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02004 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02005 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
Paul Bakker9d781402011-05-09 16:17:09 +000018 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000019 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker9d781402011-05-09 16:17:09 +000020 */
21
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020022#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000023#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020024#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020025#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020026#endif
Paul Bakker9d781402011-05-09 16:17:09 +000027
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028#if defined(MBEDTLS_ERROR_C) || defined(MBEDTLS_ERROR_STRERROR_DUMMY)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000029#include "mbedtls/error.h"
Rich Evans00ab4702015-02-06 13:43:58 +000030#include <string.h>
Manuel Pégourié-Gonnard52207812019-10-02 15:55:23 +020031#include "mbedtls/platform_util.h"
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020032#endif
33
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020034#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000035#include "mbedtls/platform.h"
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +000036#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020037#define mbedtls_snprintf snprintf
-~- redtangent ~-~9fa2e862016-05-26 10:07:49 +010038#define mbedtls_time_t time_t
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020039#endif
40
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020041#if defined(MBEDTLS_ERROR_C)
Paul Bakker3c2122f2013-06-24 19:03:14 +020042
Rich Evans00ab4702015-02-06 13:43:58 +000043#include <stdio.h>
44
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020045#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000046#include "mbedtls/aes.h"
Paul Bakker9d781402011-05-09 16:17:09 +000047#endif
48
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010049#if defined(MBEDTLS_ARC4_C)
50#include "mbedtls/arc4.h"
51#endif
52
Markku-Juhani O. Saarinen07478d62017-12-01 16:20:15 +000053#if defined(MBEDTLS_ARIA_C)
54#include "mbedtls/aria.h"
55#endif
56
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020057#if defined(MBEDTLS_BASE64_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000058#include "mbedtls/base64.h"
Paul Bakker9d781402011-05-09 16:17:09 +000059#endif
60
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061#if defined(MBEDTLS_BIGNUM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000062#include "mbedtls/bignum.h"
Paul Bakker9d781402011-05-09 16:17:09 +000063#endif
64
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020065#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000066#include "mbedtls/blowfish.h"
Paul Bakker83f00bb2012-07-04 11:08:50 +000067#endif
68
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020069#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000070#include "mbedtls/camellia.h"
Paul Bakker9d781402011-05-09 16:17:09 +000071#endif
72
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020073#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000074#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +020075#endif
76
Daniel King34b822c2016-05-15 17:28:08 -030077#if defined(MBEDTLS_CHACHA20_C)
78#include "mbedtls/chacha20.h"
79#endif
80
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020081#if defined(MBEDTLS_CHACHAPOLY_C)
82#include "mbedtls/chachapoly.h"
83#endif
84
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020085#if defined(MBEDTLS_CIPHER_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000086#include "mbedtls/cipher.h"
Paul Bakkerff61a782011-06-09 15:42:02 +000087#endif
88
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010089#if defined(MBEDTLS_CMAC_C)
90#include "mbedtls/cmac.h"
91#endif
92
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020093#if defined(MBEDTLS_CTR_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000094#include "mbedtls/ctr_drbg.h"
Paul Bakker880ac7e2011-11-27 14:50:49 +000095#endif
96
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020097#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000098#include "mbedtls/des.h"
Paul Bakker9d781402011-05-09 16:17:09 +000099#endif
100
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200101#if defined(MBEDTLS_DHM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000102#include "mbedtls/dhm.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000103#endif
104
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200105#if defined(MBEDTLS_ECP_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000106#include "mbedtls/ecp.h"
Paul Bakkercf4365f2013-01-16 17:00:43 +0100107#endif
108
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200109#if defined(MBEDTLS_ENTROPY_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000110#include "mbedtls/entropy.h"
Paul Bakker6083fd22011-12-03 21:45:14 +0000111#endif
112
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200113#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000114#include "mbedtls/gcm.h"
Paul Bakker030277a2012-04-17 12:24:26 +0000115#endif
116
Thomas Fossati656864b2016-07-17 08:51:22 +0100117#if defined(MBEDTLS_HKDF_C)
118#include "mbedtls/hkdf.h"
119#endif
120
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200121#if defined(MBEDTLS_HMAC_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000122#include "mbedtls/hmac_drbg.h"
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100123#endif
124
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200125#if defined(MBEDTLS_MD_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000126#include "mbedtls/md.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000127#endif
128
Gilles Peskinea381fe82018-01-23 18:16:11 +0100129#if defined(MBEDTLS_MD2_C)
130#include "mbedtls/md2.h"
131#endif
132
133#if defined(MBEDTLS_MD4_C)
134#include "mbedtls/md4.h"
135#endif
136
137#if defined(MBEDTLS_MD5_C)
138#include "mbedtls/md5.h"
139#endif
140
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200141#if defined(MBEDTLS_NET_C)
Andres AG3616f6f2016-09-14 14:32:09 +0100142#include "mbedtls/net_sockets.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000143#endif
144
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200145#if defined(MBEDTLS_OID_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000146#include "mbedtls/oid.h"
Paul Bakkerc70b9822013-04-07 22:00:46 +0200147#endif
148
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200149#if defined(MBEDTLS_PADLOCK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000150#include "mbedtls/padlock.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000151#endif
152
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200153#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000154#include "mbedtls/pem.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000155#endif
156
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200157#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000158#include "mbedtls/pk.h"
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200159#endif
160
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200161#if defined(MBEDTLS_PKCS12_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000162#include "mbedtls/pkcs12.h"
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200163#endif
164
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200165#if defined(MBEDTLS_PKCS5_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000166#include "mbedtls/pkcs5.h"
Paul Bakkerb0c19a42013-06-24 19:26:38 +0200167#endif
168
Ron Eldor0ff4e0b2018-08-29 18:53:20 +0300169#if defined(MBEDTLS_PLATFORM_C)
170#include "mbedtls/platform.h"
171#endif
172
Daniel Kingadc32c02016-05-16 18:25:45 -0300173#if defined(MBEDTLS_POLY1305_C)
174#include "mbedtls/poly1305.h"
175#endif
176
Gilles Peskinea381fe82018-01-23 18:16:11 +0100177#if defined(MBEDTLS_RIPEMD160_C)
178#include "mbedtls/ripemd160.h"
179#endif
180
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200181#if defined(MBEDTLS_RSA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000182#include "mbedtls/rsa.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000183#endif
184
Gilles Peskinea381fe82018-01-23 18:16:11 +0100185#if defined(MBEDTLS_SHA1_C)
186#include "mbedtls/sha1.h"
187#endif
188
189#if defined(MBEDTLS_SHA256_C)
190#include "mbedtls/sha256.h"
191#endif
192
193#if defined(MBEDTLS_SHA512_C)
194#include "mbedtls/sha512.h"
195#endif
196
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200197#if defined(MBEDTLS_SSL_TLS_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000198#include "mbedtls/ssl.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000199#endif
200
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200201#if defined(MBEDTLS_THREADING_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000202#include "mbedtls/threading.h"
Paul Bakker2466d932013-09-28 14:40:38 +0200203#endif
204
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200205#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000206#include "mbedtls/x509.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000207#endif
208
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200209#if defined(MBEDTLS_XTEA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000210#include "mbedtls/xtea.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000211#endif
212
Paul Bakkerdceecd82011-11-15 16:38:34 +0000213
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200214void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker9d781402011-05-09 16:17:09 +0000215{
216 size_t len;
217 int use_ret;
218
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200219 if( buflen == 0 )
220 return;
221
Manuel Pégourié-Gonnard7a346b82019-10-02 14:47:01 +0200222 mbedtls_platform_memset( buf, 0x00, buflen );
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200223
Paul Bakker9d781402011-05-09 16:17:09 +0000224 if( ret < 0 )
225 ret = -ret;
226
227 if( ret & 0xFF80 )
228 {
229 use_ret = ret & 0xFF80;
230
231 // High level error codes
232 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200233 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200234#if defined(MBEDTLS_CIPHER_C)
235 if( use_ret == -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE) )
236 mbedtls_snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
237 if( use_ret == -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA) )
Rose Zadik9ba6b622018-01-24 12:59:19 +0000238 mbedtls_snprintf( buf, buflen, "CIPHER - Bad input parameters" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200239 if( use_ret == -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED) )
240 mbedtls_snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
241 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_PADDING) )
242 mbedtls_snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
243 if( use_ret == -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
244 mbedtls_snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
245 if( use_ret == -(MBEDTLS_ERR_CIPHER_AUTH_FAILED) )
246 mbedtls_snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
Janos Follath98e28a72016-05-31 14:03:54 +0100247 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT) )
Rose Zadik9ba6b622018-01-24 12:59:19 +0000248 mbedtls_snprintf( buf, buflen, "CIPHER - The context is invalid. For example, because it was freed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100249 if( use_ret == -(MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED) )
250 mbedtls_snprintf( buf, buflen, "CIPHER - Cipher hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200251#endif /* MBEDTLS_CIPHER_C */
Paul Bakkerff61a782011-06-09 15:42:02 +0000252
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200253#if defined(MBEDTLS_DHM_C)
254 if( use_ret == -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA) )
Rose Zadik41ad0822018-01-26 10:54:57 +0000255 mbedtls_snprintf( buf, buflen, "DHM - Bad input parameters" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200256 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED) )
257 mbedtls_snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
258 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED) )
259 mbedtls_snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
260 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED) )
261 mbedtls_snprintf( buf, buflen, "DHM - Reading of the public values failed" );
262 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED) )
263 mbedtls_snprintf( buf, buflen, "DHM - Making of the public value failed" );
264 if( use_ret == -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED) )
265 mbedtls_snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
266 if( use_ret == -(MBEDTLS_ERR_DHM_INVALID_FORMAT) )
267 mbedtls_snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200268 if( use_ret == -(MBEDTLS_ERR_DHM_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200269 mbedtls_snprintf( buf, buflen, "DHM - Allocation of memory failed" );
270 if( use_ret == -(MBEDTLS_ERR_DHM_FILE_IO_ERROR) )
Rose Zadik41ad0822018-01-26 10:54:57 +0000271 mbedtls_snprintf( buf, buflen, "DHM - Read or write of file failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100272 if( use_ret == -(MBEDTLS_ERR_DHM_HW_ACCEL_FAILED) )
273 mbedtls_snprintf( buf, buflen, "DHM - DHM hardware accelerator failed" );
Hanno Beckera6dd90d2017-10-04 13:15:54 +0100274 if( use_ret == -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED) )
Jaeden Amero784de592018-01-26 17:52:01 +0000275 mbedtls_snprintf( buf, buflen, "DHM - Setting the modulus and generator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200276#endif /* MBEDTLS_DHM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000277
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200278#if defined(MBEDTLS_ECP_C)
279 if( use_ret == -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA) )
280 mbedtls_snprintf( buf, buflen, "ECP - Bad input parameters to function" );
281 if( use_ret == -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL) )
282 mbedtls_snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
283 if( use_ret == -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) )
Jaeden Amero3dd8abd2018-04-24 10:56:55 +0100284 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 +0200285 if( use_ret == -(MBEDTLS_ERR_ECP_VERIFY_FAILED) )
286 mbedtls_snprintf( buf, buflen, "ECP - The signature is not valid" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200287 if( use_ret == -(MBEDTLS_ERR_ECP_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200288 mbedtls_snprintf( buf, buflen, "ECP - Memory allocation failed" );
289 if( use_ret == -(MBEDTLS_ERR_ECP_RANDOM_FAILED) )
Jaeden Amero3dd8abd2018-04-24 10:56:55 +0100290 mbedtls_snprintf( buf, buflen, "ECP - Generation of random value, such as ephemeral key, failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200291 if( use_ret == -(MBEDTLS_ERR_ECP_INVALID_KEY) )
292 mbedtls_snprintf( buf, buflen, "ECP - Invalid private or public key" );
293 if( use_ret == -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) )
Gilles Peskinecc78ac42018-03-30 18:52:10 +0200294 mbedtls_snprintf( buf, buflen, "ECP - The buffer contains a valid signature followed by more data" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100295 if( use_ret == -(MBEDTLS_ERR_ECP_HW_ACCEL_FAILED) )
Jaeden Amero3dd8abd2018-04-24 10:56:55 +0100296 mbedtls_snprintf( buf, buflen, "ECP - The ECP hardware accelerator failed" );
Manuel Pégourié-Gonnard5e3c62f2017-03-08 10:14:11 +0100297 if( use_ret == -(MBEDTLS_ERR_ECP_IN_PROGRESS) )
Manuel Pégourié-Gonnardf0bbd7e2018-10-15 13:22:41 +0200298 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 +0200299#endif /* MBEDTLS_ECP_C */
Paul Bakkercf4365f2013-01-16 17:00:43 +0100300
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200301#if defined(MBEDTLS_MD_C)
302 if( use_ret == -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE) )
303 mbedtls_snprintf( buf, buflen, "MD - The selected feature is not available" );
304 if( use_ret == -(MBEDTLS_ERR_MD_BAD_INPUT_DATA) )
305 mbedtls_snprintf( buf, buflen, "MD - Bad input parameters to function" );
306 if( use_ret == -(MBEDTLS_ERR_MD_ALLOC_FAILED) )
307 mbedtls_snprintf( buf, buflen, "MD - Failed to allocate memory" );
308 if( use_ret == -(MBEDTLS_ERR_MD_FILE_IO_ERROR) )
309 mbedtls_snprintf( buf, buflen, "MD - Opening or reading of file failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100310 if( use_ret == -(MBEDTLS_ERR_MD_HW_ACCEL_FAILED) )
311 mbedtls_snprintf( buf, buflen, "MD - MD hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200312#endif /* MBEDTLS_MD_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000313
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200314#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
315 if( use_ret == -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
316 mbedtls_snprintf( buf, buflen, "PEM - No PEM header or footer found" );
317 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_DATA) )
318 mbedtls_snprintf( buf, buflen, "PEM - PEM string is not as expected" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200319 if( use_ret == -(MBEDTLS_ERR_PEM_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200320 mbedtls_snprintf( buf, buflen, "PEM - Failed to allocate memory" );
321 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_ENC_IV) )
322 mbedtls_snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
323 if( use_ret == -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG) )
324 mbedtls_snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
325 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) )
326 mbedtls_snprintf( buf, buflen, "PEM - Private key password can't be empty" );
327 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) )
328 mbedtls_snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
329 if( use_ret == -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE) )
330 mbedtls_snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
331 if( use_ret == -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA) )
332 mbedtls_snprintf( buf, buflen, "PEM - Bad input parameters to function" );
333#endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000334
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200335#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200336 if( use_ret == -(MBEDTLS_ERR_PK_ALLOC_FAILED) )
Manuel Pégourié-Gonnard41b9c2b2015-05-28 14:56:20 +0200337 mbedtls_snprintf( buf, buflen, "PK - Memory allocation failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200338 if( use_ret == -(MBEDTLS_ERR_PK_TYPE_MISMATCH) )
339 mbedtls_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
340 if( use_ret == -(MBEDTLS_ERR_PK_BAD_INPUT_DATA) )
341 mbedtls_snprintf( buf, buflen, "PK - Bad input parameters to function" );
342 if( use_ret == -(MBEDTLS_ERR_PK_FILE_IO_ERROR) )
343 mbedtls_snprintf( buf, buflen, "PK - Read/write of file failed" );
344 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION) )
345 mbedtls_snprintf( buf, buflen, "PK - Unsupported key version" );
346 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT) )
347 mbedtls_snprintf( buf, buflen, "PK - Invalid key tag or value" );
348 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG) )
349 mbedtls_snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
350 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED) )
351 mbedtls_snprintf( buf, buflen, "PK - Private key password can't be empty" );
352 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH) )
353 mbedtls_snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
354 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_PUBKEY) )
355 mbedtls_snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
356 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_ALG) )
357 mbedtls_snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
358 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE) )
359 mbedtls_snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
360 if( use_ret == -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) )
361 mbedtls_snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
362 if( use_ret == -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH) )
Gilles Peskinecc78ac42018-03-30 18:52:10 +0200363 mbedtls_snprintf( buf, buflen, "PK - The buffer contains a valid signature followed by more data" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100364 if( use_ret == -(MBEDTLS_ERR_PK_HW_ACCEL_FAILED) )
365 mbedtls_snprintf( buf, buflen, "PK - PK hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200366#endif /* MBEDTLS_PK_C */
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200367
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200368#if defined(MBEDTLS_PKCS12_C)
369 if( use_ret == -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA) )
370 mbedtls_snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
371 if( use_ret == -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE) )
372 mbedtls_snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
373 if( use_ret == -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT) )
374 mbedtls_snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
375 if( use_ret == -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) )
376 mbedtls_snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
377#endif /* MBEDTLS_PKCS12_C */
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200378
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200379#if defined(MBEDTLS_PKCS5_C)
380 if( use_ret == -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA) )
381 mbedtls_snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
382 if( use_ret == -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT) )
383 mbedtls_snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
384 if( use_ret == -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE) )
385 mbedtls_snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
386 if( use_ret == -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) )
387 mbedtls_snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
388#endif /* MBEDTLS_PKCS5_C */
Paul Bakker28144de2013-06-24 19:28:55 +0200389
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200390#if defined(MBEDTLS_RSA_C)
391 if( use_ret == -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA) )
392 mbedtls_snprintf( buf, buflen, "RSA - Bad input parameters to function" );
393 if( use_ret == -(MBEDTLS_ERR_RSA_INVALID_PADDING) )
394 mbedtls_snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
395 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED) )
396 mbedtls_snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
397 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED) )
Rose Zadik042e97f2018-01-26 16:35:10 +0000398 mbedtls_snprintf( buf, buflen, "RSA - Key failed to pass the validity check of the library" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200399 if( use_ret == -(MBEDTLS_ERR_RSA_PUBLIC_FAILED) )
400 mbedtls_snprintf( buf, buflen, "RSA - The public key operation failed" );
401 if( use_ret == -(MBEDTLS_ERR_RSA_PRIVATE_FAILED) )
402 mbedtls_snprintf( buf, buflen, "RSA - The private key operation failed" );
403 if( use_ret == -(MBEDTLS_ERR_RSA_VERIFY_FAILED) )
404 mbedtls_snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
405 if( use_ret == -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE) )
406 mbedtls_snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
407 if( use_ret == -(MBEDTLS_ERR_RSA_RNG_FAILED) )
408 mbedtls_snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
Hanno Becker3cdc7112017-10-05 10:09:31 +0100409 if( use_ret == -(MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION) )
Rose Zadik042e97f2018-01-26 16:35:10 +0000410 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 +0100411 if( use_ret == -(MBEDTLS_ERR_RSA_HW_ACCEL_FAILED) )
412 mbedtls_snprintf( buf, buflen, "RSA - RSA hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200413#endif /* MBEDTLS_RSA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000414
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200415#if defined(MBEDTLS_SSL_TLS_C)
416 if( use_ret == -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE) )
417 mbedtls_snprintf( buf, buflen, "SSL - The requested feature is not available" );
418 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA) )
419 mbedtls_snprintf( buf, buflen, "SSL - Bad input parameters to function" );
420 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_MAC) )
421 mbedtls_snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
422 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_RECORD) )
423 mbedtls_snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
424 if( use_ret == -(MBEDTLS_ERR_SSL_CONN_EOF) )
425 mbedtls_snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
426 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER) )
427 mbedtls_snprintf( buf, buflen, "SSL - An unknown cipher was received" );
428 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN) )
429 mbedtls_snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
430 if( use_ret == -(MBEDTLS_ERR_SSL_NO_RNG) )
431 mbedtls_snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
432 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE) )
433 mbedtls_snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
434 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE) )
435 mbedtls_snprintf( buf, buflen, "SSL - Our own certificate(s) is/are too large to send in an SSL message" );
436 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED) )
437 mbedtls_snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
438 if( use_ret == -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED) )
439 mbedtls_snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
440 if( use_ret == -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED) )
441 mbedtls_snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
442 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE) )
443 mbedtls_snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
444 if( use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE) )
Paul Bakker3aac1da2012-05-08 13:12:27 +0000445 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200446 mbedtls_snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
Paul Bakker3aac1da2012-05-08 13:12:27 +0000447 return;
448 }
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200449 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED) )
450 mbedtls_snprintf( buf, buflen, "SSL - Verification of our peer failed" );
451 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) )
452 mbedtls_snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
453 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO) )
454 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
455 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO) )
456 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
457 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE) )
458 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
459 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
460 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
461 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
462 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
463 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
464 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
465 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
466 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
467 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
468 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
469 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
470 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
471 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
472 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
473 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
474 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
475 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED) )
476 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200477 if( use_ret == -(MBEDTLS_ERR_SSL_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200478 mbedtls_snprintf( buf, buflen, "SSL - Memory allocation failed" );
479 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED) )
480 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
481 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
482 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
483 if( use_ret == -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED) )
484 mbedtls_snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
485 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
486 mbedtls_snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
487 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
488 mbedtls_snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
489 if( use_ret == -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED) )
490 mbedtls_snprintf( buf, buflen, "SSL - Session ticket has expired" );
491 if( use_ret == -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH) )
492 mbedtls_snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
493 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY) )
494 mbedtls_snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
495 if( use_ret == -(MBEDTLS_ERR_SSL_INTERNAL_ERROR) )
496 mbedtls_snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
497 if( use_ret == -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING) )
498 mbedtls_snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
499 if( use_ret == -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO) )
500 mbedtls_snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" );
501 if( use_ret == -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED) )
502 mbedtls_snprintf( buf, buflen, "SSL - DTLS client must retry for hello verification" );
503 if( use_ret == -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL) )
504 mbedtls_snprintf( buf, buflen, "SSL - A buffer is too small to receive or write a message" );
505 if( use_ret == -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE) )
506 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 +0100507 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_READ) )
Hanno Becker8ec81022017-10-10 10:35:08 +0100508 mbedtls_snprintf( buf, buflen, "SSL - No data of requested type currently available on underlying transport" );
Manuel Pégourié-Gonnard88369942015-05-06 16:19:31 +0100509 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_WRITE) )
510 mbedtls_snprintf( buf, buflen, "SSL - Connection requires a write call" );
511 if( use_ret == -(MBEDTLS_ERR_SSL_TIMEOUT) )
512 mbedtls_snprintf( buf, buflen, "SSL - The operation timed out" );
Manuel Pégourié-Gonnardbe619c12015-09-08 11:21:21 +0200513 if( use_ret == -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT) )
514 mbedtls_snprintf( buf, buflen, "SSL - The client initiated a reconnect from the same port" );
Manuel Pégourié-Gonnarde2e25e72015-12-03 16:13:17 +0100515 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD) )
516 mbedtls_snprintf( buf, buflen, "SSL - Record header looks valid but is not expected" );
Simon Butcher99000142016-10-13 17:21:01 +0100517 if( use_ret == -(MBEDTLS_ERR_SSL_NON_FATAL) )
518 mbedtls_snprintf( buf, buflen, "SSL - The alert message received indicates a non-fatal error" );
519 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH) )
520 mbedtls_snprintf( buf, buflen, "SSL - Couldn't set the hash for verifying CertificateVerify" );
Hanno Becker8ec81022017-10-10 10:35:08 +0100521 if( use_ret == -(MBEDTLS_ERR_SSL_CONTINUE_PROCESSING) )
Hanno Beckerc9f4d6d2018-03-19 09:23:13 +0000522 mbedtls_snprintf( buf, buflen, "SSL - Internal-only message signaling that further message-processing should be done" );
Gilles Peskine8bf79f62018-01-05 21:11:53 +0100523 if( use_ret == -(MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS) )
Gilles Peskineb44692f2018-04-24 12:18:19 +0200524 mbedtls_snprintf( buf, buflen, "SSL - The asynchronous operation is not completed yet" );
Hanno Beckerb063a5f2018-08-16 16:06:44 +0100525 if( use_ret == -(MBEDTLS_ERR_SSL_EARLY_MESSAGE) )
526 mbedtls_snprintf( buf, buflen, "SSL - Internal-only message signaling that a message arrived early" );
Hanno Becker7c3cdb62019-05-14 11:02:36 +0100527 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_CID) )
528 mbedtls_snprintf( buf, buflen, "SSL - An encrypted DTLS-frame with an unexpected CID was received" );
Hanno Becker5dbcc9f2019-06-03 12:58:39 +0100529 if( use_ret == -(MBEDTLS_ERR_SSL_VERSION_MISMATCH) )
530 mbedtls_snprintf( buf, buflen, "SSL - An operation failed due to an unexpected version or configuration" );
Manuel Pégourié-Gonnard558da9c2018-06-13 12:02:12 +0200531 if( use_ret == -(MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS) )
532 mbedtls_snprintf( buf, buflen, "SSL - A cryptographic operation is in progress. Try again later" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200533#endif /* MBEDTLS_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000534
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200535#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
536 if( use_ret == -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) )
537 mbedtls_snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
538 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_OID) )
539 mbedtls_snprintf( buf, buflen, "X509 - Requested OID is unknown" );
540 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_FORMAT) )
541 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
542 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_VERSION) )
543 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
544 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SERIAL) )
545 mbedtls_snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
546 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_ALG) )
547 mbedtls_snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
548 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_NAME) )
549 mbedtls_snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
550 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_DATE) )
551 mbedtls_snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
552 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SIGNATURE) )
553 mbedtls_snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
554 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS) )
555 mbedtls_snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
556 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_VERSION) )
557 mbedtls_snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
558 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG) )
559 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
560 if( use_ret == -(MBEDTLS_ERR_X509_SIG_MISMATCH) )
561 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" );
562 if( use_ret == -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) )
563 mbedtls_snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
564 if( use_ret == -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT) )
565 mbedtls_snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
566 if( use_ret == -(MBEDTLS_ERR_X509_BAD_INPUT_DATA) )
567 mbedtls_snprintf( buf, buflen, "X509 - Input invalid" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200568 if( use_ret == -(MBEDTLS_ERR_X509_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200569 mbedtls_snprintf( buf, buflen, "X509 - Allocation of memory failed" );
570 if( use_ret == -(MBEDTLS_ERR_X509_FILE_IO_ERROR) )
571 mbedtls_snprintf( buf, buflen, "X509 - Read/write of file failed" );
Manuel Pégourié-Gonnard9dbaf402015-06-22 11:50:58 +0200572 if( use_ret == -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL) )
573 mbedtls_snprintf( buf, buflen, "X509 - Destination buffer is too small" );
Manuel Pégourié-Gonnard31458a12017-06-26 10:11:49 +0200574 if( use_ret == -(MBEDTLS_ERR_X509_FATAL_ERROR) )
Antonin Décimod5f47592019-01-23 15:24:37 +0100575 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 +0200576#endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200577 // END generated code
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200578
Paul Bakker9d781402011-05-09 16:17:09 +0000579 if( strlen( buf ) == 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200580 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000581 }
582
583 use_ret = ret & ~0xFF80;
584
585 if( use_ret == 0 )
586 return;
587
588 // If high level code is present, make a concatenation between both
589 // error strings.
590 //
591 len = strlen( buf );
592
593 if( len > 0 )
594 {
595 if( buflen - len < 5 )
596 return;
597
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200598 mbedtls_snprintf( buf + len, buflen - len, " : " );
Paul Bakker9d781402011-05-09 16:17:09 +0000599
600 buf += len + 3;
601 buflen -= len + 3;
602 }
603
604 // Low level error codes
605 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200606 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200607#if defined(MBEDTLS_AES_C)
608 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH) )
609 mbedtls_snprintf( buf, buflen, "AES - Invalid key length" );
610 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH) )
611 mbedtls_snprintf( buf, buflen, "AES - Invalid data input length" );
Mohammad Azim Khane5b5bd72017-11-24 10:52:51 +0000612 if( use_ret == -(MBEDTLS_ERR_AES_BAD_INPUT_DATA) )
613 mbedtls_snprintf( buf, buflen, "AES - Invalid input data" );
Andres Amaya Garciafd487392017-06-14 16:19:12 +0100614 if( use_ret == -(MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE) )
Rose Zadik7f441272018-01-22 11:48:23 +0000615 mbedtls_snprintf( buf, buflen, "AES - Feature not available. For example, an unsupported AES key size" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100616 if( use_ret == -(MBEDTLS_ERR_AES_HW_ACCEL_FAILED) )
617 mbedtls_snprintf( buf, buflen, "AES - AES hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200618#endif /* MBEDTLS_AES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000619
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100620#if defined(MBEDTLS_ARC4_C)
621 if( use_ret == -(MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED) )
622 mbedtls_snprintf( buf, buflen, "ARC4 - ARC4 hardware accelerator failed" );
623#endif /* MBEDTLS_ARC4_C */
624
Markku-Juhani O. Saarinen07478d62017-12-01 16:20:15 +0000625#if defined(MBEDTLS_ARIA_C)
Hanno Becker32142152018-12-17 13:25:58 +0000626 if( use_ret == -(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA) )
627 mbedtls_snprintf( buf, buflen, "ARIA - Bad input data" );
Hanno Beckera0343692018-12-18 09:42:58 +0000628 if( use_ret == -(MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH) )
629 mbedtls_snprintf( buf, buflen, "ARIA - Invalid data input length" );
Manuel Pégourié-Gonnard3c800092018-03-01 09:02:16 +0100630 if( use_ret == -(MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE) )
631 mbedtls_snprintf( buf, buflen, "ARIA - Feature not available. For example, an unsupported ARIA key size" );
632 if( use_ret == -(MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED) )
633 mbedtls_snprintf( buf, buflen, "ARIA - ARIA hardware accelerator failed" );
Markku-Juhani O. Saarinen07478d62017-12-01 16:20:15 +0000634#endif /* MBEDTLS_ARIA_C */
635
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200636#if defined(MBEDTLS_ASN1_PARSE_C)
637 if( use_ret == -(MBEDTLS_ERR_ASN1_OUT_OF_DATA) )
638 mbedtls_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
639 if( use_ret == -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) )
640 mbedtls_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
641 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_LENGTH) )
642 mbedtls_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
643 if( use_ret == -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH) )
644 mbedtls_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
645 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_DATA) )
646 mbedtls_snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200647 if( use_ret == -(MBEDTLS_ERR_ASN1_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200648 mbedtls_snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
649 if( use_ret == -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL) )
650 mbedtls_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
651#endif /* MBEDTLS_ASN1_PARSE_C */
Paul Bakkerdceecd82011-11-15 16:38:34 +0000652
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200653#if defined(MBEDTLS_BASE64_C)
654 if( use_ret == -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) )
655 mbedtls_snprintf( buf, buflen, "BASE64 - Output buffer too small" );
656 if( use_ret == -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER) )
657 mbedtls_snprintf( buf, buflen, "BASE64 - Invalid character in input" );
658#endif /* MBEDTLS_BASE64_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000659
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200660#if defined(MBEDTLS_BIGNUM_C)
661 if( use_ret == -(MBEDTLS_ERR_MPI_FILE_IO_ERROR) )
662 mbedtls_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
663 if( use_ret == -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA) )
664 mbedtls_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
665 if( use_ret == -(MBEDTLS_ERR_MPI_INVALID_CHARACTER) )
666 mbedtls_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
667 if( use_ret == -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL) )
668 mbedtls_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
669 if( use_ret == -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE) )
670 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
671 if( use_ret == -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO) )
672 mbedtls_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
673 if( use_ret == -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) )
674 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200675 if( use_ret == -(MBEDTLS_ERR_MPI_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200676 mbedtls_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
677#endif /* MBEDTLS_BIGNUM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000678
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200679#if defined(MBEDTLS_BLOWFISH_C)
Hanno Becker32142152018-12-17 13:25:58 +0000680 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA) )
681 mbedtls_snprintf( buf, buflen, "BLOWFISH - Bad input data" );
Hanno Becker6640b0d2018-12-18 09:45:17 +0000682 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
683 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100684 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED) )
685 mbedtls_snprintf( buf, buflen, "BLOWFISH - Blowfish hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200686#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker83f00bb2012-07-04 11:08:50 +0000687
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200688#if defined(MBEDTLS_CAMELLIA_C)
Hanno Becker32142152018-12-17 13:25:58 +0000689 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA) )
690 mbedtls_snprintf( buf, buflen, "CAMELLIA - Bad input data" );
Hanno Becker938f9e92018-12-18 09:40:25 +0000691 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
692 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100693 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED) )
694 mbedtls_snprintf( buf, buflen, "CAMELLIA - Camellia hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200695#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000696
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200697#if defined(MBEDTLS_CCM_C)
698 if( use_ret == -(MBEDTLS_ERR_CCM_BAD_INPUT) )
Rose Zadikeecdbea2018-01-24 12:56:53 +0000699 mbedtls_snprintf( buf, buflen, "CCM - Bad input parameters to the function" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200700 if( use_ret == -(MBEDTLS_ERR_CCM_AUTH_FAILED) )
701 mbedtls_snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100702 if( use_ret == -(MBEDTLS_ERR_CCM_HW_ACCEL_FAILED) )
703 mbedtls_snprintf( buf, buflen, "CCM - CCM hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200704#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200705
Daniel King34b822c2016-05-15 17:28:08 -0300706#if defined(MBEDTLS_CHACHA20_C)
707 if( use_ret == -(MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA) )
708 mbedtls_snprintf( buf, buflen, "CHACHA20 - Invalid input parameter(s)" );
Manuel Pégourié-Gonnardb8bd80a2018-05-09 09:54:51 +0200709 if( use_ret == -(MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE) )
710 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 +0200711 if( use_ret == -(MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED) )
712 mbedtls_snprintf( buf, buflen, "CHACHA20 - Chacha20 hardware accelerator failed" );
Daniel King34b822c2016-05-15 17:28:08 -0300713#endif /* MBEDTLS_CHACHA20_C */
714
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200715#if defined(MBEDTLS_CHACHAPOLY_C)
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200716 if( use_ret == -(MBEDTLS_ERR_CHACHAPOLY_BAD_STATE) )
717 mbedtls_snprintf( buf, buflen, "CHACHAPOLY - The requested operation is not permitted in the current state" );
Manuel Pégourié-Gonnardb8bd80a2018-05-09 09:54:51 +0200718 if( use_ret == -(MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED) )
719 mbedtls_snprintf( buf, buflen, "CHACHAPOLY - Authenticated decryption failed: data was not authentic" );
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200720#endif /* MBEDTLS_CHACHAPOLY_C */
721
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100722#if defined(MBEDTLS_CMAC_C)
723 if( use_ret == -(MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED) )
724 mbedtls_snprintf( buf, buflen, "CMAC - CMAC hardware accelerator failed" );
725#endif /* MBEDTLS_CMAC_C */
726
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200727#if defined(MBEDTLS_CTR_DRBG_C)
728 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
729 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
730 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000731 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The requested random buffer length is too big" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200732 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000733 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The input (entropy + additional data) is too large" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200734 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000735 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Read or write error in file" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200736#endif /* MBEDTLS_CTR_DRBG_C */
Paul Bakker880ac7e2011-11-27 14:50:49 +0000737
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200738#if defined(MBEDTLS_DES_C)
739 if( use_ret == -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH) )
740 mbedtls_snprintf( buf, buflen, "DES - The data input has an invalid length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100741 if( use_ret == -(MBEDTLS_ERR_DES_HW_ACCEL_FAILED) )
742 mbedtls_snprintf( buf, buflen, "DES - DES hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200743#endif /* MBEDTLS_DES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000744
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200745#if defined(MBEDTLS_ENTROPY_C)
746 if( use_ret == -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED) )
747 mbedtls_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
748 if( use_ret == -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES) )
749 mbedtls_snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
750 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED) )
751 mbedtls_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
Manuel Pégourié-Gonnardf9cbd732015-06-22 12:06:50 +0200752 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE) )
753 mbedtls_snprintf( buf, buflen, "ENTROPY - No strong sources have been added to poll" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200754 if( use_ret == -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR) )
755 mbedtls_snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
756#endif /* MBEDTLS_ENTROPY_C */
Paul Bakker6083fd22011-12-03 21:45:14 +0000757
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200758#if defined(MBEDTLS_GCM_C)
759 if( use_ret == -(MBEDTLS_ERR_GCM_AUTH_FAILED) )
760 mbedtls_snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100761 if( use_ret == -(MBEDTLS_ERR_GCM_HW_ACCEL_FAILED) )
762 mbedtls_snprintf( buf, buflen, "GCM - GCM hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200763 if( use_ret == -(MBEDTLS_ERR_GCM_BAD_INPUT) )
764 mbedtls_snprintf( buf, buflen, "GCM - Bad input parameters to function" );
765#endif /* MBEDTLS_GCM_C */
Paul Bakker030277a2012-04-17 12:24:26 +0000766
Thomas Fossati656864b2016-07-17 08:51:22 +0100767#if defined(MBEDTLS_HKDF_C)
768 if( use_ret == -(MBEDTLS_ERR_HKDF_BAD_INPUT_DATA) )
769 mbedtls_snprintf( buf, buflen, "HKDF - Bad input parameters to function" );
770#endif /* MBEDTLS_HKDF_C */
771
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200772#if defined(MBEDTLS_HMAC_DRBG_C)
773 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
774 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
775 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
776 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
777 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR) )
778 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
779 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
780 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
781#endif /* MBEDTLS_HMAC_DRBG_C */
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100782
Gilles Peskinea381fe82018-01-23 18:16:11 +0100783#if defined(MBEDTLS_MD2_C)
784 if( use_ret == -(MBEDTLS_ERR_MD2_HW_ACCEL_FAILED) )
785 mbedtls_snprintf( buf, buflen, "MD2 - MD2 hardware accelerator failed" );
786#endif /* MBEDTLS_MD2_C */
787
788#if defined(MBEDTLS_MD4_C)
789 if( use_ret == -(MBEDTLS_ERR_MD4_HW_ACCEL_FAILED) )
790 mbedtls_snprintf( buf, buflen, "MD4 - MD4 hardware accelerator failed" );
791#endif /* MBEDTLS_MD4_C */
792
793#if defined(MBEDTLS_MD5_C)
794 if( use_ret == -(MBEDTLS_ERR_MD5_HW_ACCEL_FAILED) )
795 mbedtls_snprintf( buf, buflen, "MD5 - MD5 hardware accelerator failed" );
796#endif /* MBEDTLS_MD5_C */
797
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200798#if defined(MBEDTLS_NET_C)
799 if( use_ret == -(MBEDTLS_ERR_NET_SOCKET_FAILED) )
800 mbedtls_snprintf( buf, buflen, "NET - Failed to open a socket" );
801 if( use_ret == -(MBEDTLS_ERR_NET_CONNECT_FAILED) )
802 mbedtls_snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
803 if( use_ret == -(MBEDTLS_ERR_NET_BIND_FAILED) )
804 mbedtls_snprintf( buf, buflen, "NET - Binding of the socket failed" );
805 if( use_ret == -(MBEDTLS_ERR_NET_LISTEN_FAILED) )
806 mbedtls_snprintf( buf, buflen, "NET - Could not listen on the socket" );
807 if( use_ret == -(MBEDTLS_ERR_NET_ACCEPT_FAILED) )
808 mbedtls_snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
809 if( use_ret == -(MBEDTLS_ERR_NET_RECV_FAILED) )
810 mbedtls_snprintf( buf, buflen, "NET - Reading information from the socket failed" );
811 if( use_ret == -(MBEDTLS_ERR_NET_SEND_FAILED) )
812 mbedtls_snprintf( buf, buflen, "NET - Sending information through the socket failed" );
813 if( use_ret == -(MBEDTLS_ERR_NET_CONN_RESET) )
814 mbedtls_snprintf( buf, buflen, "NET - Connection was reset by peer" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200815 if( use_ret == -(MBEDTLS_ERR_NET_UNKNOWN_HOST) )
816 mbedtls_snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
Manuel Pégourié-Gonnard0b104b02015-05-14 21:52:40 +0200817 if( use_ret == -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL) )
818 mbedtls_snprintf( buf, buflen, "NET - Buffer is too small to hold the data" );
Manuel Pégourié-Gonnard9bd0afd2015-07-01 19:03:27 +0200819 if( use_ret == -(MBEDTLS_ERR_NET_INVALID_CONTEXT) )
820 mbedtls_snprintf( buf, buflen, "NET - The context is invalid, eg because it was free()ed" );
Hanno Beckere09ca3d2017-05-22 15:06:06 +0100821 if( use_ret == -(MBEDTLS_ERR_NET_POLL_FAILED) )
822 mbedtls_snprintf( buf, buflen, "NET - Polling the net context failed" );
823 if( use_ret == -(MBEDTLS_ERR_NET_BAD_INPUT_DATA) )
824 mbedtls_snprintf( buf, buflen, "NET - Input invalid" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200825#endif /* MBEDTLS_NET_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000826
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200827#if defined(MBEDTLS_OID_C)
828 if( use_ret == -(MBEDTLS_ERR_OID_NOT_FOUND) )
829 mbedtls_snprintf( buf, buflen, "OID - OID is not found" );
830 if( use_ret == -(MBEDTLS_ERR_OID_BUF_TOO_SMALL) )
831 mbedtls_snprintf( buf, buflen, "OID - output buffer is too small" );
832#endif /* MBEDTLS_OID_C */
Paul Bakkerc70b9822013-04-07 22:00:46 +0200833
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200834#if defined(MBEDTLS_PADLOCK_C)
835 if( use_ret == -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED) )
836 mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
837#endif /* MBEDTLS_PADLOCK_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000838
Ron Eldor0ff4e0b2018-08-29 18:53:20 +0300839#if defined(MBEDTLS_PLATFORM_C)
Ron Eldora27190b2018-10-15 16:33:43 +0300840 if( use_ret == -(MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED) )
Ron Eldor5267b622018-10-15 18:44:42 +0300841 mbedtls_snprintf( buf, buflen, "PLATFORM - Hardware accelerator failed" );
Ron Eldorbcca58c2018-10-03 16:33:21 +0300842 if( use_ret == -(MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) )
843 mbedtls_snprintf( buf, buflen, "PLATFORM - The requested feature is not supported by the platform" );
Ron Eldor0ff4e0b2018-08-29 18:53:20 +0300844#endif /* MBEDTLS_PLATFORM_C */
845
Daniel Kingadc32c02016-05-16 18:25:45 -0300846#if defined(MBEDTLS_POLY1305_C)
847 if( use_ret == -(MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA) )
848 mbedtls_snprintf( buf, buflen, "POLY1305 - Invalid input parameter(s)" );
Manuel Pégourié-Gonnardb8bd80a2018-05-09 09:54:51 +0200849 if( use_ret == -(MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE) )
850 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 +0200851 if( use_ret == -(MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED) )
852 mbedtls_snprintf( buf, buflen, "POLY1305 - Poly1305 hardware accelerator failed" );
Daniel Kingadc32c02016-05-16 18:25:45 -0300853#endif /* MBEDTLS_POLY1305_C */
854
Gilles Peskinea381fe82018-01-23 18:16:11 +0100855#if defined(MBEDTLS_RIPEMD160_C)
856 if( use_ret == -(MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED) )
857 mbedtls_snprintf( buf, buflen, "RIPEMD160 - RIPEMD160 hardware accelerator failed" );
858#endif /* MBEDTLS_RIPEMD160_C */
859
860#if defined(MBEDTLS_SHA1_C)
861 if( use_ret == -(MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED) )
862 mbedtls_snprintf( buf, buflen, "SHA1 - SHA-1 hardware accelerator failed" );
Andres Amaya Garciaa685d4f2018-12-09 19:13:01 +0000863 if( use_ret == -(MBEDTLS_ERR_SHA1_BAD_INPUT_DATA) )
Hanno Becker859522a2018-12-19 09:54:14 +0000864 mbedtls_snprintf( buf, buflen, "SHA1 - SHA-1 input data was malformed" );
Gilles Peskinea381fe82018-01-23 18:16:11 +0100865#endif /* MBEDTLS_SHA1_C */
866
867#if defined(MBEDTLS_SHA256_C)
868 if( use_ret == -(MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED) )
869 mbedtls_snprintf( buf, buflen, "SHA256 - SHA-256 hardware accelerator failed" );
Andres Amaya Garcia9e76c0e2018-12-09 20:42:05 +0000870 if( use_ret == -(MBEDTLS_ERR_SHA256_BAD_INPUT_DATA) )
Hanno Beckerd8e4f4a2018-12-19 09:54:55 +0000871 mbedtls_snprintf( buf, buflen, "SHA256 - SHA-256 input data was malformed" );
Gilles Peskinea381fe82018-01-23 18:16:11 +0100872#endif /* MBEDTLS_SHA256_C */
873
874#if defined(MBEDTLS_SHA512_C)
875 if( use_ret == -(MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED) )
876 mbedtls_snprintf( buf, buflen, "SHA512 - SHA-512 hardware accelerator failed" );
Andres Amaya Garcia863d4832018-12-09 20:58:52 +0000877 if( use_ret == -(MBEDTLS_ERR_SHA512_BAD_INPUT_DATA) )
Hanno Becker9994e0d2018-12-19 09:55:40 +0000878 mbedtls_snprintf( buf, buflen, "SHA512 - SHA-512 input data was malformed" );
Gilles Peskinea381fe82018-01-23 18:16:11 +0100879#endif /* MBEDTLS_SHA512_C */
880
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200881#if defined(MBEDTLS_THREADING_C)
882 if( use_ret == -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE) )
883 mbedtls_snprintf( buf, buflen, "THREADING - The selected feature is not available" );
884 if( use_ret == -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA) )
885 mbedtls_snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
886 if( use_ret == -(MBEDTLS_ERR_THREADING_MUTEX_ERROR) )
887 mbedtls_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
888#endif /* MBEDTLS_THREADING_C */
Paul Bakker2466d932013-09-28 14:40:38 +0200889
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200890#if defined(MBEDTLS_XTEA_C)
891 if( use_ret == -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH) )
892 mbedtls_snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100893 if( use_ret == -(MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED) )
894 mbedtls_snprintf( buf, buflen, "XTEA - XTEA hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200895#endif /* MBEDTLS_XTEA_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200896 // END generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000897
898 if( strlen( buf ) != 0 )
899 return;
900
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200901 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000902}
903
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200904#else /* MBEDTLS_ERROR_C */
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100905
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200906#if defined(MBEDTLS_ERROR_STRERROR_DUMMY)
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100907
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100908/*
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200909 * Provide an non-function in case MBEDTLS_ERROR_C is not defined
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100910 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200911void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100912{
913 ((void) ret);
914
915 if( buflen > 0 )
916 buf[0] = '\0';
917}
918
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200919#endif /* MBEDTLS_ERROR_STRERROR_DUMMY */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200920
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200921#endif /* MBEDTLS_ERROR_C */