blob: fdeb12ab86ac9f3e76844e43ca9b42ffcfa4d20f [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_NET_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000105#include "mbedtls/net.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000106#endif
107
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200108#if defined(MBEDTLS_OID_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000109#include "mbedtls/oid.h"
Paul Bakkerc70b9822013-04-07 22:00:46 +0200110#endif
111
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200112#if defined(MBEDTLS_PADLOCK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000113#include "mbedtls/padlock.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000114#endif
115
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200116#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000117#include "mbedtls/pem.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000118#endif
119
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200120#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000121#include "mbedtls/pk.h"
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200122#endif
123
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124#if defined(MBEDTLS_PKCS12_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000125#include "mbedtls/pkcs12.h"
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200126#endif
127
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128#if defined(MBEDTLS_PKCS5_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000129#include "mbedtls/pkcs5.h"
Paul Bakkerb0c19a42013-06-24 19:26:38 +0200130#endif
131
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200132#if defined(MBEDTLS_RSA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000133#include "mbedtls/rsa.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000134#endif
135
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200136#if defined(MBEDTLS_SSL_TLS_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000137#include "mbedtls/ssl.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000138#endif
139
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140#if defined(MBEDTLS_THREADING_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000141#include "mbedtls/threading.h"
Paul Bakker2466d932013-09-28 14:40:38 +0200142#endif
143
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200144#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000145#include "mbedtls/x509.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000146#endif
147
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200148#if defined(MBEDTLS_XTEA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000149#include "mbedtls/xtea.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000150#endif
151
Paul Bakker6edcd412013-10-29 15:22:54 +0100152#if defined(_MSC_VER) && !defined snprintf && !defined(EFIX64) && \
153 !defined(EFI32)
Paul Bakkerdceecd82011-11-15 16:38:34 +0000154#define snprintf _snprintf
155#endif
156
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200157void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker9d781402011-05-09 16:17:09 +0000158{
159 size_t len;
160 int use_ret;
161
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200162 if( buflen == 0 )
163 return;
164
Paul Bakker9d781402011-05-09 16:17:09 +0000165 memset( buf, 0x00, buflen );
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200166 /* Reduce buflen to make sure MSVC _snprintf() ends with \0 as well */
167 buflen -= 1;
168
Paul Bakker9d781402011-05-09 16:17:09 +0000169 if( ret < 0 )
170 ret = -ret;
171
172 if( ret & 0xFF80 )
173 {
174 use_ret = ret & 0xFF80;
175
176 // High level error codes
177 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200178 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200179#if defined(MBEDTLS_CIPHER_C)
180 if( use_ret == -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE) )
181 mbedtls_snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
182 if( use_ret == -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA) )
183 mbedtls_snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
184 if( use_ret == -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED) )
185 mbedtls_snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
186 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_PADDING) )
187 mbedtls_snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
188 if( use_ret == -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
189 mbedtls_snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
190 if( use_ret == -(MBEDTLS_ERR_CIPHER_AUTH_FAILED) )
191 mbedtls_snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
192#endif /* MBEDTLS_CIPHER_C */
Paul Bakkerff61a782011-06-09 15:42:02 +0000193
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200194#if defined(MBEDTLS_DHM_C)
195 if( use_ret == -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA) )
196 mbedtls_snprintf( buf, buflen, "DHM - Bad input parameters to function" );
197 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED) )
198 mbedtls_snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
199 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED) )
200 mbedtls_snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
201 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED) )
202 mbedtls_snprintf( buf, buflen, "DHM - Reading of the public values failed" );
203 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED) )
204 mbedtls_snprintf( buf, buflen, "DHM - Making of the public value failed" );
205 if( use_ret == -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED) )
206 mbedtls_snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
207 if( use_ret == -(MBEDTLS_ERR_DHM_INVALID_FORMAT) )
208 mbedtls_snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200209 if( use_ret == -(MBEDTLS_ERR_DHM_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200210 mbedtls_snprintf( buf, buflen, "DHM - Allocation of memory failed" );
211 if( use_ret == -(MBEDTLS_ERR_DHM_FILE_IO_ERROR) )
212 mbedtls_snprintf( buf, buflen, "DHM - Read/write of file failed" );
213#endif /* MBEDTLS_DHM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000214
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200215#if defined(MBEDTLS_ECP_C)
216 if( use_ret == -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA) )
217 mbedtls_snprintf( buf, buflen, "ECP - Bad input parameters to function" );
218 if( use_ret == -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL) )
219 mbedtls_snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
220 if( use_ret == -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) )
221 mbedtls_snprintf( buf, buflen, "ECP - Requested curve not available" );
222 if( use_ret == -(MBEDTLS_ERR_ECP_VERIFY_FAILED) )
223 mbedtls_snprintf( buf, buflen, "ECP - The signature is not valid" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200224 if( use_ret == -(MBEDTLS_ERR_ECP_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200225 mbedtls_snprintf( buf, buflen, "ECP - Memory allocation failed" );
226 if( use_ret == -(MBEDTLS_ERR_ECP_RANDOM_FAILED) )
227 mbedtls_snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
228 if( use_ret == -(MBEDTLS_ERR_ECP_INVALID_KEY) )
229 mbedtls_snprintf( buf, buflen, "ECP - Invalid private or public key" );
230 if( use_ret == -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) )
231 mbedtls_snprintf( buf, buflen, "ECP - Signature is valid but shorter than the user-supplied length" );
232#endif /* MBEDTLS_ECP_C */
Paul Bakkercf4365f2013-01-16 17:00:43 +0100233
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200234#if defined(MBEDTLS_MD_C)
235 if( use_ret == -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE) )
236 mbedtls_snprintf( buf, buflen, "MD - The selected feature is not available" );
237 if( use_ret == -(MBEDTLS_ERR_MD_BAD_INPUT_DATA) )
238 mbedtls_snprintf( buf, buflen, "MD - Bad input parameters to function" );
239 if( use_ret == -(MBEDTLS_ERR_MD_ALLOC_FAILED) )
240 mbedtls_snprintf( buf, buflen, "MD - Failed to allocate memory" );
241 if( use_ret == -(MBEDTLS_ERR_MD_FILE_IO_ERROR) )
242 mbedtls_snprintf( buf, buflen, "MD - Opening or reading of file failed" );
243#endif /* MBEDTLS_MD_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000244
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200245#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
246 if( use_ret == -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
247 mbedtls_snprintf( buf, buflen, "PEM - No PEM header or footer found" );
248 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_DATA) )
249 mbedtls_snprintf( buf, buflen, "PEM - PEM string is not as expected" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200250 if( use_ret == -(MBEDTLS_ERR_PEM_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200251 mbedtls_snprintf( buf, buflen, "PEM - Failed to allocate memory" );
252 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_ENC_IV) )
253 mbedtls_snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
254 if( use_ret == -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG) )
255 mbedtls_snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
256 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) )
257 mbedtls_snprintf( buf, buflen, "PEM - Private key password can't be empty" );
258 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) )
259 mbedtls_snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
260 if( use_ret == -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE) )
261 mbedtls_snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
262 if( use_ret == -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA) )
263 mbedtls_snprintf( buf, buflen, "PEM - Bad input parameters to function" );
264#endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000265
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200266#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200267 if( use_ret == -(MBEDTLS_ERR_PK_ALLOC_FAILED) )
Manuel Pégourié-Gonnard41b9c2b2015-05-28 14:56:20 +0200268 mbedtls_snprintf( buf, buflen, "PK - Memory allocation failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200269 if( use_ret == -(MBEDTLS_ERR_PK_TYPE_MISMATCH) )
270 mbedtls_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
271 if( use_ret == -(MBEDTLS_ERR_PK_BAD_INPUT_DATA) )
272 mbedtls_snprintf( buf, buflen, "PK - Bad input parameters to function" );
273 if( use_ret == -(MBEDTLS_ERR_PK_FILE_IO_ERROR) )
274 mbedtls_snprintf( buf, buflen, "PK - Read/write of file failed" );
275 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION) )
276 mbedtls_snprintf( buf, buflen, "PK - Unsupported key version" );
277 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT) )
278 mbedtls_snprintf( buf, buflen, "PK - Invalid key tag or value" );
279 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG) )
280 mbedtls_snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
281 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED) )
282 mbedtls_snprintf( buf, buflen, "PK - Private key password can't be empty" );
283 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH) )
284 mbedtls_snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
285 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_PUBKEY) )
286 mbedtls_snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
287 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_ALG) )
288 mbedtls_snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
289 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE) )
290 mbedtls_snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
291 if( use_ret == -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) )
292 mbedtls_snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
293 if( use_ret == -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH) )
294 mbedtls_snprintf( buf, buflen, "PK - The signature is valid but its length is less than expected" );
295#endif /* MBEDTLS_PK_C */
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200296
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200297#if defined(MBEDTLS_PKCS12_C)
298 if( use_ret == -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA) )
299 mbedtls_snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
300 if( use_ret == -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE) )
301 mbedtls_snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
302 if( use_ret == -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT) )
303 mbedtls_snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
304 if( use_ret == -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) )
305 mbedtls_snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
306#endif /* MBEDTLS_PKCS12_C */
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200307
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200308#if defined(MBEDTLS_PKCS5_C)
309 if( use_ret == -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA) )
310 mbedtls_snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
311 if( use_ret == -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT) )
312 mbedtls_snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
313 if( use_ret == -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE) )
314 mbedtls_snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
315 if( use_ret == -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) )
316 mbedtls_snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
317#endif /* MBEDTLS_PKCS5_C */
Paul Bakker28144de2013-06-24 19:28:55 +0200318
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200319#if defined(MBEDTLS_RSA_C)
320 if( use_ret == -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA) )
321 mbedtls_snprintf( buf, buflen, "RSA - Bad input parameters to function" );
322 if( use_ret == -(MBEDTLS_ERR_RSA_INVALID_PADDING) )
323 mbedtls_snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
324 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED) )
325 mbedtls_snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
326 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED) )
Manuel Pégourié-Gonnardeecb43c2015-05-12 12:56:41 +0200327 mbedtls_snprintf( buf, buflen, "RSA - Key failed to pass the library's validity check" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200328 if( use_ret == -(MBEDTLS_ERR_RSA_PUBLIC_FAILED) )
329 mbedtls_snprintf( buf, buflen, "RSA - The public key operation failed" );
330 if( use_ret == -(MBEDTLS_ERR_RSA_PRIVATE_FAILED) )
331 mbedtls_snprintf( buf, buflen, "RSA - The private key operation failed" );
332 if( use_ret == -(MBEDTLS_ERR_RSA_VERIFY_FAILED) )
333 mbedtls_snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
334 if( use_ret == -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE) )
335 mbedtls_snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
336 if( use_ret == -(MBEDTLS_ERR_RSA_RNG_FAILED) )
337 mbedtls_snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
338#endif /* MBEDTLS_RSA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000339
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200340#if defined(MBEDTLS_SSL_TLS_C)
341 if( use_ret == -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE) )
342 mbedtls_snprintf( buf, buflen, "SSL - The requested feature is not available" );
343 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA) )
344 mbedtls_snprintf( buf, buflen, "SSL - Bad input parameters to function" );
345 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_MAC) )
346 mbedtls_snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
347 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_RECORD) )
348 mbedtls_snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
349 if( use_ret == -(MBEDTLS_ERR_SSL_CONN_EOF) )
350 mbedtls_snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
351 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER) )
352 mbedtls_snprintf( buf, buflen, "SSL - An unknown cipher was received" );
353 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN) )
354 mbedtls_snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
355 if( use_ret == -(MBEDTLS_ERR_SSL_NO_RNG) )
356 mbedtls_snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
357 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE) )
358 mbedtls_snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
359 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE) )
360 mbedtls_snprintf( buf, buflen, "SSL - Our own certificate(s) is/are too large to send in an SSL message" );
361 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED) )
362 mbedtls_snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
363 if( use_ret == -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED) )
364 mbedtls_snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
365 if( use_ret == -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED) )
366 mbedtls_snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
367 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE) )
368 mbedtls_snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
369 if( use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE) )
Paul Bakker3aac1da2012-05-08 13:12:27 +0000370 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200371 mbedtls_snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
Paul Bakker3aac1da2012-05-08 13:12:27 +0000372 return;
373 }
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200374 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED) )
375 mbedtls_snprintf( buf, buflen, "SSL - Verification of our peer failed" );
376 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) )
377 mbedtls_snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
378 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO) )
379 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
380 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO) )
381 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
382 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE) )
383 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
384 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
385 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
386 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
387 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
388 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
389 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
390 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
391 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
392 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
393 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
394 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
395 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
396 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
397 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
398 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
399 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
400 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED) )
401 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200402 if( use_ret == -(MBEDTLS_ERR_SSL_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200403 mbedtls_snprintf( buf, buflen, "SSL - Memory allocation failed" );
404 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED) )
405 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
406 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
407 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
408 if( use_ret == -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED) )
409 mbedtls_snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
410 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
411 mbedtls_snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
412 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
413 mbedtls_snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
414 if( use_ret == -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED) )
415 mbedtls_snprintf( buf, buflen, "SSL - Session ticket has expired" );
416 if( use_ret == -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH) )
417 mbedtls_snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
418 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY) )
419 mbedtls_snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
420 if( use_ret == -(MBEDTLS_ERR_SSL_INTERNAL_ERROR) )
421 mbedtls_snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
422 if( use_ret == -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING) )
423 mbedtls_snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
424 if( use_ret == -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO) )
425 mbedtls_snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" );
426 if( use_ret == -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED) )
427 mbedtls_snprintf( buf, buflen, "SSL - DTLS client must retry for hello verification" );
428 if( use_ret == -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL) )
429 mbedtls_snprintf( buf, buflen, "SSL - A buffer is too small to receive or write a message" );
430 if( use_ret == -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE) )
431 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 +0100432 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_READ) )
433 mbedtls_snprintf( buf, buflen, "SSL - Connection requires a read call" );
434 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_WRITE) )
435 mbedtls_snprintf( buf, buflen, "SSL - Connection requires a write call" );
436 if( use_ret == -(MBEDTLS_ERR_SSL_TIMEOUT) )
437 mbedtls_snprintf( buf, buflen, "SSL - The operation timed out" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200438#endif /* MBEDTLS_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000439
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200440#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
441 if( use_ret == -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) )
442 mbedtls_snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
443 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_OID) )
444 mbedtls_snprintf( buf, buflen, "X509 - Requested OID is unknown" );
445 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_FORMAT) )
446 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
447 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_VERSION) )
448 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
449 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SERIAL) )
450 mbedtls_snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
451 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_ALG) )
452 mbedtls_snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
453 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_NAME) )
454 mbedtls_snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
455 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_DATE) )
456 mbedtls_snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
457 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SIGNATURE) )
458 mbedtls_snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
459 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS) )
460 mbedtls_snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
461 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_VERSION) )
462 mbedtls_snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
463 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG) )
464 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
465 if( use_ret == -(MBEDTLS_ERR_X509_SIG_MISMATCH) )
466 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" );
467 if( use_ret == -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) )
468 mbedtls_snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
469 if( use_ret == -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT) )
470 mbedtls_snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
471 if( use_ret == -(MBEDTLS_ERR_X509_BAD_INPUT_DATA) )
472 mbedtls_snprintf( buf, buflen, "X509 - Input invalid" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200473 if( use_ret == -(MBEDTLS_ERR_X509_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200474 mbedtls_snprintf( buf, buflen, "X509 - Allocation of memory failed" );
475 if( use_ret == -(MBEDTLS_ERR_X509_FILE_IO_ERROR) )
476 mbedtls_snprintf( buf, buflen, "X509 - Read/write of file failed" );
Manuel Pégourié-Gonnarde546ad42015-04-08 20:27:02 +0200477#endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200478 // END generated code
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200479
Paul Bakker9d781402011-05-09 16:17:09 +0000480 if( strlen( buf ) == 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200481 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000482 }
483
484 use_ret = ret & ~0xFF80;
485
486 if( use_ret == 0 )
487 return;
488
489 // If high level code is present, make a concatenation between both
490 // error strings.
491 //
492 len = strlen( buf );
493
494 if( len > 0 )
495 {
496 if( buflen - len < 5 )
497 return;
498
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200499 mbedtls_snprintf( buf + len, buflen - len, " : " );
Paul Bakker9d781402011-05-09 16:17:09 +0000500
501 buf += len + 3;
502 buflen -= len + 3;
503 }
504
505 // Low level error codes
506 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200507 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200508#if defined(MBEDTLS_AES_C)
509 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH) )
510 mbedtls_snprintf( buf, buflen, "AES - Invalid key length" );
511 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH) )
512 mbedtls_snprintf( buf, buflen, "AES - Invalid data input length" );
513#endif /* MBEDTLS_AES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000514
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200515#if defined(MBEDTLS_ASN1_PARSE_C)
516 if( use_ret == -(MBEDTLS_ERR_ASN1_OUT_OF_DATA) )
517 mbedtls_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
518 if( use_ret == -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) )
519 mbedtls_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
520 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_LENGTH) )
521 mbedtls_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
522 if( use_ret == -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH) )
523 mbedtls_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
524 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_DATA) )
525 mbedtls_snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200526 if( use_ret == -(MBEDTLS_ERR_ASN1_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200527 mbedtls_snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
528 if( use_ret == -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL) )
529 mbedtls_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
530#endif /* MBEDTLS_ASN1_PARSE_C */
Paul Bakkerdceecd82011-11-15 16:38:34 +0000531
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200532#if defined(MBEDTLS_BASE64_C)
533 if( use_ret == -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) )
534 mbedtls_snprintf( buf, buflen, "BASE64 - Output buffer too small" );
535 if( use_ret == -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER) )
536 mbedtls_snprintf( buf, buflen, "BASE64 - Invalid character in input" );
537#endif /* MBEDTLS_BASE64_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000538
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200539#if defined(MBEDTLS_BIGNUM_C)
540 if( use_ret == -(MBEDTLS_ERR_MPI_FILE_IO_ERROR) )
541 mbedtls_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
542 if( use_ret == -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA) )
543 mbedtls_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
544 if( use_ret == -(MBEDTLS_ERR_MPI_INVALID_CHARACTER) )
545 mbedtls_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
546 if( use_ret == -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL) )
547 mbedtls_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
548 if( use_ret == -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE) )
549 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
550 if( use_ret == -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO) )
551 mbedtls_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
552 if( use_ret == -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) )
553 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200554 if( use_ret == -(MBEDTLS_ERR_MPI_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200555 mbedtls_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
556#endif /* MBEDTLS_BIGNUM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000557
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200558#if defined(MBEDTLS_BLOWFISH_C)
559 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
560 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
561 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
562 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
563#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker83f00bb2012-07-04 11:08:50 +0000564
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200565#if defined(MBEDTLS_CAMELLIA_C)
566 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
567 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
568 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
569 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
570#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000571
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200572#if defined(MBEDTLS_CCM_C)
573 if( use_ret == -(MBEDTLS_ERR_CCM_BAD_INPUT) )
574 mbedtls_snprintf( buf, buflen, "CCM - Bad input parameters to function" );
575 if( use_ret == -(MBEDTLS_ERR_CCM_AUTH_FAILED) )
576 mbedtls_snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
577#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200578
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200579#if defined(MBEDTLS_CTR_DRBG_C)
580 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
581 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
582 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
583 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
584 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG) )
585 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
586 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR) )
587 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
588#endif /* MBEDTLS_CTR_DRBG_C */
Paul Bakker880ac7e2011-11-27 14:50:49 +0000589
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200590#if defined(MBEDTLS_DES_C)
591 if( use_ret == -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH) )
592 mbedtls_snprintf( buf, buflen, "DES - The data input has an invalid length" );
593#endif /* MBEDTLS_DES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000594
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200595#if defined(MBEDTLS_ENTROPY_C)
596 if( use_ret == -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED) )
597 mbedtls_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
598 if( use_ret == -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES) )
599 mbedtls_snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
600 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED) )
601 mbedtls_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
602 if( use_ret == -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR) )
603 mbedtls_snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
604#endif /* MBEDTLS_ENTROPY_C */
Paul Bakker6083fd22011-12-03 21:45:14 +0000605
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200606#if defined(MBEDTLS_GCM_C)
607 if( use_ret == -(MBEDTLS_ERR_GCM_AUTH_FAILED) )
608 mbedtls_snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
609 if( use_ret == -(MBEDTLS_ERR_GCM_BAD_INPUT) )
610 mbedtls_snprintf( buf, buflen, "GCM - Bad input parameters to function" );
611#endif /* MBEDTLS_GCM_C */
Paul Bakker030277a2012-04-17 12:24:26 +0000612
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200613#if defined(MBEDTLS_HMAC_DRBG_C)
614 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
615 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
616 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
617 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
618 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR) )
619 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
620 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
621 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
622#endif /* MBEDTLS_HMAC_DRBG_C */
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100623
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200624#if defined(MBEDTLS_NET_C)
625 if( use_ret == -(MBEDTLS_ERR_NET_SOCKET_FAILED) )
626 mbedtls_snprintf( buf, buflen, "NET - Failed to open a socket" );
627 if( use_ret == -(MBEDTLS_ERR_NET_CONNECT_FAILED) )
628 mbedtls_snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
629 if( use_ret == -(MBEDTLS_ERR_NET_BIND_FAILED) )
630 mbedtls_snprintf( buf, buflen, "NET - Binding of the socket failed" );
631 if( use_ret == -(MBEDTLS_ERR_NET_LISTEN_FAILED) )
632 mbedtls_snprintf( buf, buflen, "NET - Could not listen on the socket" );
633 if( use_ret == -(MBEDTLS_ERR_NET_ACCEPT_FAILED) )
634 mbedtls_snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
635 if( use_ret == -(MBEDTLS_ERR_NET_RECV_FAILED) )
636 mbedtls_snprintf( buf, buflen, "NET - Reading information from the socket failed" );
637 if( use_ret == -(MBEDTLS_ERR_NET_SEND_FAILED) )
638 mbedtls_snprintf( buf, buflen, "NET - Sending information through the socket failed" );
639 if( use_ret == -(MBEDTLS_ERR_NET_CONN_RESET) )
640 mbedtls_snprintf( buf, buflen, "NET - Connection was reset by peer" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200641 if( use_ret == -(MBEDTLS_ERR_NET_UNKNOWN_HOST) )
642 mbedtls_snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
Manuel Pégourié-Gonnard0b104b02015-05-14 21:52:40 +0200643 if( use_ret == -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL) )
644 mbedtls_snprintf( buf, buflen, "NET - Buffer is too small to hold the data" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200645#endif /* MBEDTLS_NET_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000646
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200647#if defined(MBEDTLS_OID_C)
648 if( use_ret == -(MBEDTLS_ERR_OID_NOT_FOUND) )
649 mbedtls_snprintf( buf, buflen, "OID - OID is not found" );
650 if( use_ret == -(MBEDTLS_ERR_OID_BUF_TOO_SMALL) )
651 mbedtls_snprintf( buf, buflen, "OID - output buffer is too small" );
652#endif /* MBEDTLS_OID_C */
Paul Bakkerc70b9822013-04-07 22:00:46 +0200653
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200654#if defined(MBEDTLS_PADLOCK_C)
655 if( use_ret == -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED) )
656 mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
657#endif /* MBEDTLS_PADLOCK_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000658
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200659#if defined(MBEDTLS_THREADING_C)
660 if( use_ret == -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE) )
661 mbedtls_snprintf( buf, buflen, "THREADING - The selected feature is not available" );
662 if( use_ret == -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA) )
663 mbedtls_snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
664 if( use_ret == -(MBEDTLS_ERR_THREADING_MUTEX_ERROR) )
665 mbedtls_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
666#endif /* MBEDTLS_THREADING_C */
Paul Bakker2466d932013-09-28 14:40:38 +0200667
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200668#if defined(MBEDTLS_XTEA_C)
669 if( use_ret == -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH) )
670 mbedtls_snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
671#endif /* MBEDTLS_XTEA_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200672 // END generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000673
674 if( strlen( buf ) != 0 )
675 return;
676
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200677 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000678}
679
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200680#else /* MBEDTLS_ERROR_C */
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100681
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200682#if defined(MBEDTLS_ERROR_STRERROR_DUMMY)
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100683
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100684/*
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200685 * Provide an non-function in case MBEDTLS_ERROR_C is not defined
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100686 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200687void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100688{
689 ((void) ret);
690
691 if( buflen > 0 )
692 buf[0] = '\0';
693}
694
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200695#endif /* MBEDTLS_ERROR_STRERROR_DUMMY */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200696
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200697#endif /* MBEDTLS_ERROR_C */