blob: 4281e89a740ebbbf79edd3d848697d9ce46be6bc [file] [log] [blame]
Paul Bakker9d781402011-05-09 16:17:09 +00001/*
2 * Error message information
3 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00004 * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
Paul Bakker9d781402011-05-09 16:17:09 +00005 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +00006 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker9d781402011-05-09 16:17:09 +00007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020023#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000024#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020025#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020027#endif
Paul Bakker9d781402011-05-09 16:17:09 +000028
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020029#if defined(MBEDTLS_ERROR_C) || defined(MBEDTLS_ERROR_STRERROR_DUMMY)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000030#include "mbedtls/error.h"
Rich Evans00ab4702015-02-06 13:43:58 +000031#include <string.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
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020038#endif
39
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020040#if defined(MBEDTLS_ERROR_C)
Paul Bakker3c2122f2013-06-24 19:03:14 +020041
Rich Evans00ab4702015-02-06 13:43:58 +000042#include <stdio.h>
43
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020044#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000045#include "mbedtls/aes.h"
Paul Bakker9d781402011-05-09 16:17:09 +000046#endif
47
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020048#if defined(MBEDTLS_BASE64_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000049#include "mbedtls/base64.h"
Paul Bakker9d781402011-05-09 16:17:09 +000050#endif
51
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052#if defined(MBEDTLS_BIGNUM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000053#include "mbedtls/bignum.h"
Paul Bakker9d781402011-05-09 16:17:09 +000054#endif
55
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000057#include "mbedtls/blowfish.h"
Paul Bakker83f00bb2012-07-04 11:08:50 +000058#endif
59
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000061#include "mbedtls/camellia.h"
Paul Bakker9d781402011-05-09 16:17:09 +000062#endif
63
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000065#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +020066#endif
67
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068#if defined(MBEDTLS_CIPHER_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000069#include "mbedtls/cipher.h"
Paul Bakkerff61a782011-06-09 15:42:02 +000070#endif
71
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020072#if defined(MBEDTLS_CTR_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000073#include "mbedtls/ctr_drbg.h"
Paul Bakker880ac7e2011-11-27 14:50:49 +000074#endif
75
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020076#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000077#include "mbedtls/des.h"
Paul Bakker9d781402011-05-09 16:17:09 +000078#endif
79
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020080#if defined(MBEDTLS_DHM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000081#include "mbedtls/dhm.h"
Paul Bakker9d781402011-05-09 16:17:09 +000082#endif
83
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020084#if defined(MBEDTLS_ECP_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000085#include "mbedtls/ecp.h"
Paul Bakkercf4365f2013-01-16 17:00:43 +010086#endif
87
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020088#if defined(MBEDTLS_ENTROPY_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000089#include "mbedtls/entropy.h"
Paul Bakker6083fd22011-12-03 21:45:14 +000090#endif
91
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000093#include "mbedtls/gcm.h"
Paul Bakker030277a2012-04-17 12:24:26 +000094#endif
95
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096#if defined(MBEDTLS_HMAC_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000097#include "mbedtls/hmac_drbg.h"
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010098#endif
99
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200100#if defined(MBEDTLS_MD_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000101#include "mbedtls/md.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000102#endif
103
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200104#if defined(MBEDTLS_MD2_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000105#include "mbedtls/md2.h"
Paul Bakker69e095c2011-12-10 21:55:01 +0000106#endif
107
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200108#if defined(MBEDTLS_MD4_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000109#include "mbedtls/md4.h"
Paul Bakker69e095c2011-12-10 21:55:01 +0000110#endif
111
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200112#if defined(MBEDTLS_MD5_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000113#include "mbedtls/md5.h"
Paul Bakker69e095c2011-12-10 21:55:01 +0000114#endif
115
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200116#if defined(MBEDTLS_NET_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000117#include "mbedtls/net.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000118#endif
119
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200120#if defined(MBEDTLS_OID_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000121#include "mbedtls/oid.h"
Paul Bakkerc70b9822013-04-07 22:00:46 +0200122#endif
123
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124#if defined(MBEDTLS_PADLOCK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000125#include "mbedtls/padlock.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000126#endif
127
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000129#include "mbedtls/pem.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000130#endif
131
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200132#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000133#include "mbedtls/pk.h"
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200134#endif
135
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200136#if defined(MBEDTLS_PKCS12_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000137#include "mbedtls/pkcs12.h"
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200138#endif
139
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140#if defined(MBEDTLS_PKCS5_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000141#include "mbedtls/pkcs5.h"
Paul Bakkerb0c19a42013-06-24 19:26:38 +0200142#endif
143
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200144#if defined(MBEDTLS_RIPEMD160_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000145#include "mbedtls/ripemd160.h"
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100146#endif
147
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200148#if defined(MBEDTLS_RSA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000149#include "mbedtls/rsa.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000150#endif
151
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200152#if defined(MBEDTLS_SHA1_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000153#include "mbedtls/sha1.h"
Paul Bakker69e095c2011-12-10 21:55:01 +0000154#endif
155
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200156#if defined(MBEDTLS_SHA256_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000157#include "mbedtls/sha256.h"
Paul Bakker69e095c2011-12-10 21:55:01 +0000158#endif
159
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200160#if defined(MBEDTLS_SHA512_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000161#include "mbedtls/sha512.h"
Paul Bakker69e095c2011-12-10 21:55:01 +0000162#endif
163
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200164#if defined(MBEDTLS_SSL_TLS_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000165#include "mbedtls/ssl.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000166#endif
167
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200168#if defined(MBEDTLS_THREADING_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000169#include "mbedtls/threading.h"
Paul Bakker2466d932013-09-28 14:40:38 +0200170#endif
171
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200172#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000173#include "mbedtls/x509.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000174#endif
175
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200176#if defined(MBEDTLS_XTEA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000177#include "mbedtls/xtea.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000178#endif
179
Paul Bakker6edcd412013-10-29 15:22:54 +0100180#if defined(_MSC_VER) && !defined snprintf && !defined(EFIX64) && \
181 !defined(EFI32)
Paul Bakkerdceecd82011-11-15 16:38:34 +0000182#define snprintf _snprintf
183#endif
184
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200185void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker9d781402011-05-09 16:17:09 +0000186{
187 size_t len;
188 int use_ret;
189
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200190 if( buflen == 0 )
191 return;
192
Paul Bakker9d781402011-05-09 16:17:09 +0000193 memset( buf, 0x00, buflen );
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200194 /* Reduce buflen to make sure MSVC _snprintf() ends with \0 as well */
195 buflen -= 1;
196
Paul Bakker9d781402011-05-09 16:17:09 +0000197 if( ret < 0 )
198 ret = -ret;
199
200 if( ret & 0xFF80 )
201 {
202 use_ret = ret & 0xFF80;
203
204 // High level error codes
205 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200206 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200207#if defined(MBEDTLS_CIPHER_C)
208 if( use_ret == -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE) )
209 mbedtls_snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
210 if( use_ret == -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA) )
211 mbedtls_snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
212 if( use_ret == -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED) )
213 mbedtls_snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
214 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_PADDING) )
215 mbedtls_snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
216 if( use_ret == -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
217 mbedtls_snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
218 if( use_ret == -(MBEDTLS_ERR_CIPHER_AUTH_FAILED) )
219 mbedtls_snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
220#endif /* MBEDTLS_CIPHER_C */
Paul Bakkerff61a782011-06-09 15:42:02 +0000221
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200222#if defined(MBEDTLS_DHM_C)
223 if( use_ret == -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA) )
224 mbedtls_snprintf( buf, buflen, "DHM - Bad input parameters to function" );
225 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED) )
226 mbedtls_snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
227 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED) )
228 mbedtls_snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
229 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED) )
230 mbedtls_snprintf( buf, buflen, "DHM - Reading of the public values failed" );
231 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED) )
232 mbedtls_snprintf( buf, buflen, "DHM - Making of the public value failed" );
233 if( use_ret == -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED) )
234 mbedtls_snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
235 if( use_ret == -(MBEDTLS_ERR_DHM_INVALID_FORMAT) )
236 mbedtls_snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
237 if( use_ret == -(MBEDTLS_ERR_DHM_MALLOC_FAILED) )
238 mbedtls_snprintf( buf, buflen, "DHM - Allocation of memory failed" );
239 if( use_ret == -(MBEDTLS_ERR_DHM_FILE_IO_ERROR) )
240 mbedtls_snprintf( buf, buflen, "DHM - Read/write of file failed" );
241#endif /* MBEDTLS_DHM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000242
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200243#if defined(MBEDTLS_ECP_C)
244 if( use_ret == -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA) )
245 mbedtls_snprintf( buf, buflen, "ECP - Bad input parameters to function" );
246 if( use_ret == -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL) )
247 mbedtls_snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
248 if( use_ret == -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) )
249 mbedtls_snprintf( buf, buflen, "ECP - Requested curve not available" );
250 if( use_ret == -(MBEDTLS_ERR_ECP_VERIFY_FAILED) )
251 mbedtls_snprintf( buf, buflen, "ECP - The signature is not valid" );
252 if( use_ret == -(MBEDTLS_ERR_ECP_MALLOC_FAILED) )
253 mbedtls_snprintf( buf, buflen, "ECP - Memory allocation failed" );
254 if( use_ret == -(MBEDTLS_ERR_ECP_RANDOM_FAILED) )
255 mbedtls_snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
256 if( use_ret == -(MBEDTLS_ERR_ECP_INVALID_KEY) )
257 mbedtls_snprintf( buf, buflen, "ECP - Invalid private or public key" );
258 if( use_ret == -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) )
259 mbedtls_snprintf( buf, buflen, "ECP - Signature is valid but shorter than the user-supplied length" );
260#endif /* MBEDTLS_ECP_C */
Paul Bakkercf4365f2013-01-16 17:00:43 +0100261
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200262#if defined(MBEDTLS_MD_C)
263 if( use_ret == -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE) )
264 mbedtls_snprintf( buf, buflen, "MD - The selected feature is not available" );
265 if( use_ret == -(MBEDTLS_ERR_MD_BAD_INPUT_DATA) )
266 mbedtls_snprintf( buf, buflen, "MD - Bad input parameters to function" );
267 if( use_ret == -(MBEDTLS_ERR_MD_ALLOC_FAILED) )
268 mbedtls_snprintf( buf, buflen, "MD - Failed to allocate memory" );
269 if( use_ret == -(MBEDTLS_ERR_MD_FILE_IO_ERROR) )
270 mbedtls_snprintf( buf, buflen, "MD - Opening or reading of file failed" );
271#endif /* MBEDTLS_MD_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000272
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200273#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
274 if( use_ret == -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
275 mbedtls_snprintf( buf, buflen, "PEM - No PEM header or footer found" );
276 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_DATA) )
277 mbedtls_snprintf( buf, buflen, "PEM - PEM string is not as expected" );
278 if( use_ret == -(MBEDTLS_ERR_PEM_MALLOC_FAILED) )
279 mbedtls_snprintf( buf, buflen, "PEM - Failed to allocate memory" );
280 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_ENC_IV) )
281 mbedtls_snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
282 if( use_ret == -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG) )
283 mbedtls_snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
284 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) )
285 mbedtls_snprintf( buf, buflen, "PEM - Private key password can't be empty" );
286 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) )
287 mbedtls_snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
288 if( use_ret == -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE) )
289 mbedtls_snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
290 if( use_ret == -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA) )
291 mbedtls_snprintf( buf, buflen, "PEM - Bad input parameters to function" );
292#endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000293
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200294#if defined(MBEDTLS_PK_C)
295 if( use_ret == -(MBEDTLS_ERR_PK_MALLOC_FAILED) )
296 mbedtls_snprintf( buf, buflen, "PK - Memory alloation failed" );
297 if( use_ret == -(MBEDTLS_ERR_PK_TYPE_MISMATCH) )
298 mbedtls_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
299 if( use_ret == -(MBEDTLS_ERR_PK_BAD_INPUT_DATA) )
300 mbedtls_snprintf( buf, buflen, "PK - Bad input parameters to function" );
301 if( use_ret == -(MBEDTLS_ERR_PK_FILE_IO_ERROR) )
302 mbedtls_snprintf( buf, buflen, "PK - Read/write of file failed" );
303 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION) )
304 mbedtls_snprintf( buf, buflen, "PK - Unsupported key version" );
305 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT) )
306 mbedtls_snprintf( buf, buflen, "PK - Invalid key tag or value" );
307 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG) )
308 mbedtls_snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
309 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED) )
310 mbedtls_snprintf( buf, buflen, "PK - Private key password can't be empty" );
311 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH) )
312 mbedtls_snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
313 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_PUBKEY) )
314 mbedtls_snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
315 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_ALG) )
316 mbedtls_snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
317 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE) )
318 mbedtls_snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
319 if( use_ret == -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) )
320 mbedtls_snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
321 if( use_ret == -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH) )
322 mbedtls_snprintf( buf, buflen, "PK - The signature is valid but its length is less than expected" );
323#endif /* MBEDTLS_PK_C */
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200324
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200325#if defined(MBEDTLS_PKCS12_C)
326 if( use_ret == -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA) )
327 mbedtls_snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
328 if( use_ret == -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE) )
329 mbedtls_snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
330 if( use_ret == -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT) )
331 mbedtls_snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
332 if( use_ret == -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) )
333 mbedtls_snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
334#endif /* MBEDTLS_PKCS12_C */
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200335
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200336#if defined(MBEDTLS_PKCS5_C)
337 if( use_ret == -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA) )
338 mbedtls_snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
339 if( use_ret == -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT) )
340 mbedtls_snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
341 if( use_ret == -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE) )
342 mbedtls_snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
343 if( use_ret == -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) )
344 mbedtls_snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
345#endif /* MBEDTLS_PKCS5_C */
Paul Bakker28144de2013-06-24 19:28:55 +0200346
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200347#if defined(MBEDTLS_RSA_C)
348 if( use_ret == -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA) )
349 mbedtls_snprintf( buf, buflen, "RSA - Bad input parameters to function" );
350 if( use_ret == -(MBEDTLS_ERR_RSA_INVALID_PADDING) )
351 mbedtls_snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
352 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED) )
353 mbedtls_snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
354 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED) )
355 mbedtls_snprintf( buf, buflen, "RSA - Key failed to pass the libraries validity check" );
356 if( use_ret == -(MBEDTLS_ERR_RSA_PUBLIC_FAILED) )
357 mbedtls_snprintf( buf, buflen, "RSA - The public key operation failed" );
358 if( use_ret == -(MBEDTLS_ERR_RSA_PRIVATE_FAILED) )
359 mbedtls_snprintf( buf, buflen, "RSA - The private key operation failed" );
360 if( use_ret == -(MBEDTLS_ERR_RSA_VERIFY_FAILED) )
361 mbedtls_snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
362 if( use_ret == -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE) )
363 mbedtls_snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
364 if( use_ret == -(MBEDTLS_ERR_RSA_RNG_FAILED) )
365 mbedtls_snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
366#endif /* MBEDTLS_RSA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000367
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200368#if defined(MBEDTLS_SSL_TLS_C)
369 if( use_ret == -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE) )
370 mbedtls_snprintf( buf, buflen, "SSL - The requested feature is not available" );
371 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA) )
372 mbedtls_snprintf( buf, buflen, "SSL - Bad input parameters to function" );
373 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_MAC) )
374 mbedtls_snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
375 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_RECORD) )
376 mbedtls_snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
377 if( use_ret == -(MBEDTLS_ERR_SSL_CONN_EOF) )
378 mbedtls_snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
379 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER) )
380 mbedtls_snprintf( buf, buflen, "SSL - An unknown cipher was received" );
381 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN) )
382 mbedtls_snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
383 if( use_ret == -(MBEDTLS_ERR_SSL_NO_RNG) )
384 mbedtls_snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
385 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE) )
386 mbedtls_snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
387 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE) )
388 mbedtls_snprintf( buf, buflen, "SSL - Our own certificate(s) is/are too large to send in an SSL message" );
389 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED) )
390 mbedtls_snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
391 if( use_ret == -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED) )
392 mbedtls_snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
393 if( use_ret == -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED) )
394 mbedtls_snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
395 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE) )
396 mbedtls_snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
397 if( use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE) )
Paul Bakker3aac1da2012-05-08 13:12:27 +0000398 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200399 mbedtls_snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
Paul Bakker3aac1da2012-05-08 13:12:27 +0000400 return;
401 }
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200402 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED) )
403 mbedtls_snprintf( buf, buflen, "SSL - Verification of our peer failed" );
404 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) )
405 mbedtls_snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
406 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO) )
407 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
408 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO) )
409 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
410 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE) )
411 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
412 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
413 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
414 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
415 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
416 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
417 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
418 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
419 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
420 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
421 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
422 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
423 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
424 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
425 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
426 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
427 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
428 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED) )
429 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
430 if( use_ret == -(MBEDTLS_ERR_SSL_MALLOC_FAILED) )
431 mbedtls_snprintf( buf, buflen, "SSL - Memory allocation failed" );
432 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED) )
433 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
434 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
435 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
436 if( use_ret == -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED) )
437 mbedtls_snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
438 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
439 mbedtls_snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
440 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
441 mbedtls_snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
442 if( use_ret == -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED) )
443 mbedtls_snprintf( buf, buflen, "SSL - Session ticket has expired" );
444 if( use_ret == -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH) )
445 mbedtls_snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
446 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY) )
447 mbedtls_snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
448 if( use_ret == -(MBEDTLS_ERR_SSL_INTERNAL_ERROR) )
449 mbedtls_snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
450 if( use_ret == -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING) )
451 mbedtls_snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
452 if( use_ret == -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO) )
453 mbedtls_snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" );
454 if( use_ret == -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED) )
455 mbedtls_snprintf( buf, buflen, "SSL - DTLS client must retry for hello verification" );
456 if( use_ret == -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL) )
457 mbedtls_snprintf( buf, buflen, "SSL - A buffer is too small to receive or write a message" );
458 if( use_ret == -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE) )
459 mbedtls_snprintf( buf, buflen, "SSL - None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages)" );
460#endif /* MBEDTLS_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000461
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200462#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
463 if( use_ret == -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) )
464 mbedtls_snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
465 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_OID) )
466 mbedtls_snprintf( buf, buflen, "X509 - Requested OID is unknown" );
467 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_FORMAT) )
468 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
469 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_VERSION) )
470 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
471 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SERIAL) )
472 mbedtls_snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
473 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_ALG) )
474 mbedtls_snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
475 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_NAME) )
476 mbedtls_snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
477 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_DATE) )
478 mbedtls_snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
479 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SIGNATURE) )
480 mbedtls_snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
481 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS) )
482 mbedtls_snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
483 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_VERSION) )
484 mbedtls_snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
485 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG) )
486 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
487 if( use_ret == -(MBEDTLS_ERR_X509_SIG_MISMATCH) )
488 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" );
489 if( use_ret == -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) )
490 mbedtls_snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
491 if( use_ret == -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT) )
492 mbedtls_snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
493 if( use_ret == -(MBEDTLS_ERR_X509_BAD_INPUT_DATA) )
494 mbedtls_snprintf( buf, buflen, "X509 - Input invalid" );
495 if( use_ret == -(MBEDTLS_ERR_X509_MALLOC_FAILED) )
496 mbedtls_snprintf( buf, buflen, "X509 - Allocation of memory failed" );
497 if( use_ret == -(MBEDTLS_ERR_X509_FILE_IO_ERROR) )
498 mbedtls_snprintf( buf, buflen, "X509 - Read/write of file failed" );
Manuel Pégourié-Gonnarde546ad42015-04-08 20:27:02 +0200499#endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200500 // END generated code
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200501
Paul Bakker9d781402011-05-09 16:17:09 +0000502 if( strlen( buf ) == 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200503 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000504 }
505
506 use_ret = ret & ~0xFF80;
507
508 if( use_ret == 0 )
509 return;
510
511 // If high level code is present, make a concatenation between both
512 // error strings.
513 //
514 len = strlen( buf );
515
516 if( len > 0 )
517 {
518 if( buflen - len < 5 )
519 return;
520
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200521 mbedtls_snprintf( buf + len, buflen - len, " : " );
Paul Bakker9d781402011-05-09 16:17:09 +0000522
523 buf += len + 3;
524 buflen -= len + 3;
525 }
526
527 // Low level error codes
528 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200529 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200530#if defined(MBEDTLS_AES_C)
531 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH) )
532 mbedtls_snprintf( buf, buflen, "AES - Invalid key length" );
533 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH) )
534 mbedtls_snprintf( buf, buflen, "AES - Invalid data input length" );
535#endif /* MBEDTLS_AES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000536
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200537#if defined(MBEDTLS_ASN1_PARSE_C)
538 if( use_ret == -(MBEDTLS_ERR_ASN1_OUT_OF_DATA) )
539 mbedtls_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
540 if( use_ret == -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) )
541 mbedtls_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
542 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_LENGTH) )
543 mbedtls_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
544 if( use_ret == -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH) )
545 mbedtls_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
546 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_DATA) )
547 mbedtls_snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
548 if( use_ret == -(MBEDTLS_ERR_ASN1_MALLOC_FAILED) )
549 mbedtls_snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
550 if( use_ret == -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL) )
551 mbedtls_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
552#endif /* MBEDTLS_ASN1_PARSE_C */
Paul Bakkerdceecd82011-11-15 16:38:34 +0000553
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200554#if defined(MBEDTLS_BASE64_C)
555 if( use_ret == -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) )
556 mbedtls_snprintf( buf, buflen, "BASE64 - Output buffer too small" );
557 if( use_ret == -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER) )
558 mbedtls_snprintf( buf, buflen, "BASE64 - Invalid character in input" );
559#endif /* MBEDTLS_BASE64_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000560
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200561#if defined(MBEDTLS_BIGNUM_C)
562 if( use_ret == -(MBEDTLS_ERR_MPI_FILE_IO_ERROR) )
563 mbedtls_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
564 if( use_ret == -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA) )
565 mbedtls_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
566 if( use_ret == -(MBEDTLS_ERR_MPI_INVALID_CHARACTER) )
567 mbedtls_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
568 if( use_ret == -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL) )
569 mbedtls_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
570 if( use_ret == -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE) )
571 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
572 if( use_ret == -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO) )
573 mbedtls_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
574 if( use_ret == -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) )
575 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
576 if( use_ret == -(MBEDTLS_ERR_MPI_MALLOC_FAILED) )
577 mbedtls_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
578#endif /* MBEDTLS_BIGNUM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000579
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200580#if defined(MBEDTLS_BLOWFISH_C)
581 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
582 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
583 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
584 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
585#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker83f00bb2012-07-04 11:08:50 +0000586
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200587#if defined(MBEDTLS_CAMELLIA_C)
588 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
589 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
590 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
591 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
592#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000593
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200594#if defined(MBEDTLS_CCM_C)
595 if( use_ret == -(MBEDTLS_ERR_CCM_BAD_INPUT) )
596 mbedtls_snprintf( buf, buflen, "CCM - Bad input parameters to function" );
597 if( use_ret == -(MBEDTLS_ERR_CCM_AUTH_FAILED) )
598 mbedtls_snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
599#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200600
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200601#if defined(MBEDTLS_CTR_DRBG_C)
602 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
603 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
604 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
605 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
606 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG) )
607 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
608 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR) )
609 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
610#endif /* MBEDTLS_CTR_DRBG_C */
Paul Bakker880ac7e2011-11-27 14:50:49 +0000611
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200612#if defined(MBEDTLS_DES_C)
613 if( use_ret == -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH) )
614 mbedtls_snprintf( buf, buflen, "DES - The data input has an invalid length" );
615#endif /* MBEDTLS_DES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000616
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200617#if defined(MBEDTLS_ENTROPY_C)
618 if( use_ret == -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED) )
619 mbedtls_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
620 if( use_ret == -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES) )
621 mbedtls_snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
622 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED) )
623 mbedtls_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
624 if( use_ret == -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR) )
625 mbedtls_snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
626#endif /* MBEDTLS_ENTROPY_C */
Paul Bakker6083fd22011-12-03 21:45:14 +0000627
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200628#if defined(MBEDTLS_GCM_C)
629 if( use_ret == -(MBEDTLS_ERR_GCM_AUTH_FAILED) )
630 mbedtls_snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
631 if( use_ret == -(MBEDTLS_ERR_GCM_BAD_INPUT) )
632 mbedtls_snprintf( buf, buflen, "GCM - Bad input parameters to function" );
633#endif /* MBEDTLS_GCM_C */
Paul Bakker030277a2012-04-17 12:24:26 +0000634
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200635#if defined(MBEDTLS_HMAC_DRBG_C)
636 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
637 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
638 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
639 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
640 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR) )
641 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
642 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
643 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
644#endif /* MBEDTLS_HMAC_DRBG_C */
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100645
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200646#if defined(MBEDTLS_MD2_C)
647 if( use_ret == -(MBEDTLS_ERR_MD2_FILE_IO_ERROR) )
648 mbedtls_snprintf( buf, buflen, "MD2 - Read/write error in file" );
649#endif /* MBEDTLS_MD2_C */
Paul Bakker69e095c2011-12-10 21:55:01 +0000650
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200651#if defined(MBEDTLS_MD4_C)
652 if( use_ret == -(MBEDTLS_ERR_MD4_FILE_IO_ERROR) )
653 mbedtls_snprintf( buf, buflen, "MD4 - Read/write error in file" );
654#endif /* MBEDTLS_MD4_C */
Paul Bakker69e095c2011-12-10 21:55:01 +0000655
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200656#if defined(MBEDTLS_MD5_C)
657 if( use_ret == -(MBEDTLS_ERR_MD5_FILE_IO_ERROR) )
658 mbedtls_snprintf( buf, buflen, "MD5 - Read/write error in file" );
659#endif /* MBEDTLS_MD5_C */
Paul Bakker69e095c2011-12-10 21:55:01 +0000660
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200661#if defined(MBEDTLS_NET_C)
662 if( use_ret == -(MBEDTLS_ERR_NET_SOCKET_FAILED) )
663 mbedtls_snprintf( buf, buflen, "NET - Failed to open a socket" );
664 if( use_ret == -(MBEDTLS_ERR_NET_CONNECT_FAILED) )
665 mbedtls_snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
666 if( use_ret == -(MBEDTLS_ERR_NET_BIND_FAILED) )
667 mbedtls_snprintf( buf, buflen, "NET - Binding of the socket failed" );
668 if( use_ret == -(MBEDTLS_ERR_NET_LISTEN_FAILED) )
669 mbedtls_snprintf( buf, buflen, "NET - Could not listen on the socket" );
670 if( use_ret == -(MBEDTLS_ERR_NET_ACCEPT_FAILED) )
671 mbedtls_snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
672 if( use_ret == -(MBEDTLS_ERR_NET_RECV_FAILED) )
673 mbedtls_snprintf( buf, buflen, "NET - Reading information from the socket failed" );
674 if( use_ret == -(MBEDTLS_ERR_NET_SEND_FAILED) )
675 mbedtls_snprintf( buf, buflen, "NET - Sending information through the socket failed" );
676 if( use_ret == -(MBEDTLS_ERR_NET_CONN_RESET) )
677 mbedtls_snprintf( buf, buflen, "NET - Connection was reset by peer" );
678 if( use_ret == -(MBEDTLS_ERR_NET_WANT_READ) )
679 mbedtls_snprintf( buf, buflen, "NET - Connection requires a read call" );
680 if( use_ret == -(MBEDTLS_ERR_NET_WANT_WRITE) )
681 mbedtls_snprintf( buf, buflen, "NET - Connection requires a write call" );
682 if( use_ret == -(MBEDTLS_ERR_NET_UNKNOWN_HOST) )
683 mbedtls_snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
684 if( use_ret == -(MBEDTLS_ERR_NET_TIMEOUT) )
685 mbedtls_snprintf( buf, buflen, "NET - The operation timed out" );
686#endif /* MBEDTLS_NET_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000687
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200688#if defined(MBEDTLS_OID_C)
689 if( use_ret == -(MBEDTLS_ERR_OID_NOT_FOUND) )
690 mbedtls_snprintf( buf, buflen, "OID - OID is not found" );
691 if( use_ret == -(MBEDTLS_ERR_OID_BUF_TOO_SMALL) )
692 mbedtls_snprintf( buf, buflen, "OID - output buffer is too small" );
693#endif /* MBEDTLS_OID_C */
Paul Bakkerc70b9822013-04-07 22:00:46 +0200694
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200695#if defined(MBEDTLS_PADLOCK_C)
696 if( use_ret == -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED) )
697 mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
698#endif /* MBEDTLS_PADLOCK_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000699
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200700#if defined(MBEDTLS_RIPEMD160_C)
701 if( use_ret == -(MBEDTLS_ERR_RIPEMD160_FILE_IO_ERROR) )
702 mbedtls_snprintf( buf, buflen, "RIPEMD160 - Read/write error in file" );
703#endif /* MBEDTLS_RIPEMD160_C */
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100704
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200705#if defined(MBEDTLS_SHA1_C)
706 if( use_ret == -(MBEDTLS_ERR_SHA1_FILE_IO_ERROR) )
707 mbedtls_snprintf( buf, buflen, "SHA1 - Read/write error in file" );
708#endif /* MBEDTLS_SHA1_C */
Paul Bakker69e095c2011-12-10 21:55:01 +0000709
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200710#if defined(MBEDTLS_SHA256_C)
711 if( use_ret == -(MBEDTLS_ERR_SHA256_FILE_IO_ERROR) )
712 mbedtls_snprintf( buf, buflen, "SHA256 - Read/write error in file" );
713#endif /* MBEDTLS_SHA256_C */
Paul Bakker69e095c2011-12-10 21:55:01 +0000714
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200715#if defined(MBEDTLS_SHA512_C)
716 if( use_ret == -(MBEDTLS_ERR_SHA512_FILE_IO_ERROR) )
717 mbedtls_snprintf( buf, buflen, "SHA512 - Read/write error in file" );
718#endif /* MBEDTLS_SHA512_C */
Paul Bakker69e095c2011-12-10 21:55:01 +0000719
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200720#if defined(MBEDTLS_THREADING_C)
721 if( use_ret == -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE) )
722 mbedtls_snprintf( buf, buflen, "THREADING - The selected feature is not available" );
723 if( use_ret == -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA) )
724 mbedtls_snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
725 if( use_ret == -(MBEDTLS_ERR_THREADING_MUTEX_ERROR) )
726 mbedtls_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
727#endif /* MBEDTLS_THREADING_C */
Paul Bakker2466d932013-09-28 14:40:38 +0200728
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200729#if defined(MBEDTLS_XTEA_C)
730 if( use_ret == -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH) )
731 mbedtls_snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
732#endif /* MBEDTLS_XTEA_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200733 // END generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000734
735 if( strlen( buf ) != 0 )
736 return;
737
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200738 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000739}
740
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200741#else /* MBEDTLS_ERROR_C */
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100742
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200743#if defined(MBEDTLS_ERROR_STRERROR_DUMMY)
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100744
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100745/*
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200746 * Provide an non-function in case MBEDTLS_ERROR_C is not defined
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100747 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200748void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100749{
750 ((void) ret);
751
752 if( buflen > 0 )
753 buf[0] = '\0';
754}
755
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200756#endif /* MBEDTLS_ERROR_STRERROR_DUMMY */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200757
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200758#endif /* MBEDTLS_ERROR_C */