blob: 38be879355b9b2b3c6971ac7fc47a8e0051eaba3 [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é-Gonnardcef4ad22014-04-29 12:39:06 +020023#if !defined(POLARSSL_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
26#include POLARSSL_CONFIG_FILE
27#endif
Paul Bakker9d781402011-05-09 16:17:09 +000028
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020029#if defined(POLARSSL_ERROR_C) || defined(POLARSSL_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é-Gonnard09286402015-02-13 15:18:33 +000034#if defined(POLARSSL_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
37#define polarssl_snprintf snprintf
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020038#endif
39
40#if defined(POLARSSL_ERROR_C)
Paul Bakker3c2122f2013-06-24 19:03:14 +020041
Rich Evans00ab4702015-02-06 13:43:58 +000042#include <stdio.h>
43
Paul Bakker9d781402011-05-09 16:17:09 +000044#if defined(POLARSSL_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
48#if defined(POLARSSL_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
52#if defined(POLARSSL_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
Paul Bakker83f00bb2012-07-04 11:08:50 +000056#if defined(POLARSSL_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
Paul Bakker9d781402011-05-09 16:17:09 +000060#if defined(POLARSSL_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é-Gonnarda6916fa2014-05-02 15:17:29 +020064#if defined(POLARSSL_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
Paul Bakkerff61a782011-06-09 15:42:02 +000068#if defined(POLARSSL_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
Paul Bakker880ac7e2011-11-27 14:50:49 +000072#if defined(POLARSSL_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
Paul Bakker9d781402011-05-09 16:17:09 +000076#if defined(POLARSSL_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
80#if defined(POLARSSL_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
Paul Bakkercf4365f2013-01-16 17:00:43 +010084#if defined(POLARSSL_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
Paul Bakker6083fd22011-12-03 21:45:14 +000088#if defined(POLARSSL_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
Paul Bakker030277a2012-04-17 12:24:26 +000092#if defined(POLARSSL_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é-Gonnardcf383672014-02-01 10:22:21 +010096#if defined(POLARSSL_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
Paul Bakker9d781402011-05-09 16:17:09 +0000100#if defined(POLARSSL_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
Paul Bakker69e095c2011-12-10 21:55:01 +0000104#if defined(POLARSSL_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
108#if defined(POLARSSL_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
112#if defined(POLARSSL_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
Paul Bakker9d781402011-05-09 16:17:09 +0000116#if defined(POLARSSL_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
Paul Bakkerc70b9822013-04-07 22:00:46 +0200120#if defined(POLARSSL_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
Paul Bakker9d781402011-05-09 16:17:09 +0000124#if defined(POLARSSL_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
Paul Bakkerd14277d2012-09-26 15:19:05 +0000128#if defined(POLARSSL_PBKDF2_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000129#include "mbedtls/pbkdf2.h"
Paul Bakkerd14277d2012-09-26 15:19:05 +0000130#endif
131
Paul Bakkercff68422013-09-15 20:43:33 +0200132#if defined(POLARSSL_PEM_PARSE_C) || defined(POLARSSL_PEM_WRITE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000133#include "mbedtls/pem.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000134#endif
135
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200136#if defined(POLARSSL_PK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000137#include "mbedtls/pk.h"
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200138#endif
139
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200140#if defined(POLARSSL_PKCS12_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000141#include "mbedtls/pkcs12.h"
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200142#endif
143
Paul Bakkerb0c19a42013-06-24 19:26:38 +0200144#if defined(POLARSSL_PKCS5_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000145#include "mbedtls/pkcs5.h"
Paul Bakkerb0c19a42013-06-24 19:26:38 +0200146#endif
147
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100148#if defined(POLARSSL_RIPEMD160_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000149#include "mbedtls/ripemd160.h"
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100150#endif
151
Paul Bakker9d781402011-05-09 16:17:09 +0000152#if defined(POLARSSL_RSA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000153#include "mbedtls/rsa.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000154#endif
155
Paul Bakker69e095c2011-12-10 21:55:01 +0000156#if defined(POLARSSL_SHA1_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000157#include "mbedtls/sha1.h"
Paul Bakker69e095c2011-12-10 21:55:01 +0000158#endif
159
Paul Bakker9e36f042013-06-30 14:34:05 +0200160#if defined(POLARSSL_SHA256_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000161#include "mbedtls/sha256.h"
Paul Bakker69e095c2011-12-10 21:55:01 +0000162#endif
163
Paul Bakker9e36f042013-06-30 14:34:05 +0200164#if defined(POLARSSL_SHA512_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000165#include "mbedtls/sha512.h"
Paul Bakker69e095c2011-12-10 21:55:01 +0000166#endif
167
Paul Bakker831a7552011-05-18 13:32:51 +0000168#if defined(POLARSSL_SSL_TLS_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000169#include "mbedtls/ssl.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000170#endif
171
Paul Bakker2466d932013-09-28 14:40:38 +0200172#if defined(POLARSSL_THREADING_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000173#include "mbedtls/threading.h"
Paul Bakker2466d932013-09-28 14:40:38 +0200174#endif
175
Paul Bakker36713e82013-09-17 13:25:29 +0200176#if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000177#include "mbedtls/x509.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000178#endif
179
180#if defined(POLARSSL_XTEA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000181#include "mbedtls/xtea.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000182#endif
183
Paul Bakker6edcd412013-10-29 15:22:54 +0100184#if defined(_MSC_VER) && !defined snprintf && !defined(EFIX64) && \
185 !defined(EFI32)
Paul Bakkerdceecd82011-11-15 16:38:34 +0000186#define snprintf _snprintf
187#endif
188
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200189void polarssl_strerror( int ret, char *buf, size_t buflen )
Paul Bakker9d781402011-05-09 16:17:09 +0000190{
191 size_t len;
192 int use_ret;
193
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200194 if( buflen == 0 )
195 return;
196
Paul Bakker9d781402011-05-09 16:17:09 +0000197 memset( buf, 0x00, buflen );
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200198 /* Reduce buflen to make sure MSVC _snprintf() ends with \0 as well */
199 buflen -= 1;
200
Paul Bakker9d781402011-05-09 16:17:09 +0000201 if( ret < 0 )
202 ret = -ret;
203
204 if( ret & 0xFF80 )
205 {
206 use_ret = ret & 0xFF80;
207
208 // High level error codes
209 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200210 // BEGIN generated code
Paul Bakkerff61a782011-06-09 15:42:02 +0000211#if defined(POLARSSL_CIPHER_C)
212 if( use_ret == -(POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000213 polarssl_snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
Paul Bakkerff61a782011-06-09 15:42:02 +0000214 if( use_ret == -(POLARSSL_ERR_CIPHER_BAD_INPUT_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000215 polarssl_snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
Paul Bakkerff61a782011-06-09 15:42:02 +0000216 if( use_ret == -(POLARSSL_ERR_CIPHER_ALLOC_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000217 polarssl_snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
Paul Bakkerff61a782011-06-09 15:42:02 +0000218 if( use_ret == -(POLARSSL_ERR_CIPHER_INVALID_PADDING) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000219 polarssl_snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
Paul Bakkerff61a782011-06-09 15:42:02 +0000220 if( use_ret == -(POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000221 polarssl_snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
Manuel Pégourié-Gonnard4fee79b2013-09-19 18:09:14 +0200222 if( use_ret == -(POLARSSL_ERR_CIPHER_AUTH_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000223 polarssl_snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
Paul Bakkerff61a782011-06-09 15:42:02 +0000224#endif /* POLARSSL_CIPHER_C */
225
Paul Bakker9d781402011-05-09 16:17:09 +0000226#if defined(POLARSSL_DHM_C)
227 if( use_ret == -(POLARSSL_ERR_DHM_BAD_INPUT_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000228 polarssl_snprintf( buf, buflen, "DHM - Bad input parameters to function" );
Paul Bakker9d781402011-05-09 16:17:09 +0000229 if( use_ret == -(POLARSSL_ERR_DHM_READ_PARAMS_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000230 polarssl_snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000231 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PARAMS_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000232 polarssl_snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000233 if( use_ret == -(POLARSSL_ERR_DHM_READ_PUBLIC_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000234 polarssl_snprintf( buf, buflen, "DHM - Reading of the public values failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000235 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PUBLIC_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000236 polarssl_snprintf( buf, buflen, "DHM - Making of the public value failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000237 if( use_ret == -(POLARSSL_ERR_DHM_CALC_SECRET_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000238 polarssl_snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
Paul Bakker40ce79f2013-09-15 17:43:54 +0200239 if( use_ret == -(POLARSSL_ERR_DHM_INVALID_FORMAT) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000240 polarssl_snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
Paul Bakker40ce79f2013-09-15 17:43:54 +0200241 if( use_ret == -(POLARSSL_ERR_DHM_MALLOC_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000242 polarssl_snprintf( buf, buflen, "DHM - Allocation of memory failed" );
Paul Bakker40ce79f2013-09-15 17:43:54 +0200243 if( use_ret == -(POLARSSL_ERR_DHM_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000244 polarssl_snprintf( buf, buflen, "DHM - Read/write of file failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000245#endif /* POLARSSL_DHM_C */
246
Paul Bakkercf4365f2013-01-16 17:00:43 +0100247#if defined(POLARSSL_ECP_C)
248 if( use_ret == -(POLARSSL_ERR_ECP_BAD_INPUT_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000249 polarssl_snprintf( buf, buflen, "ECP - Bad input parameters to function" );
Paul Bakker41c83d32013-03-20 14:39:14 +0100250 if( use_ret == -(POLARSSL_ERR_ECP_BUFFER_TOO_SMALL) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000251 polarssl_snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
Paul Bakkerfd3eac52013-06-29 23:31:33 +0200252 if( use_ret == -(POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000253 polarssl_snprintf( buf, buflen, "ECP - Requested curve not available" );
Paul Bakker1a7550a2013-09-15 13:01:22 +0200254 if( use_ret == -(POLARSSL_ERR_ECP_VERIFY_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000255 polarssl_snprintf( buf, buflen, "ECP - The signature is not valid" );
Manuel Pégourié-Gonnard456d3b92013-09-16 18:04:38 +0200256 if( use_ret == -(POLARSSL_ERR_ECP_MALLOC_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000257 polarssl_snprintf( buf, buflen, "ECP - Memory allocation failed" );
Manuel Pégourié-Gonnard456d3b92013-09-16 18:04:38 +0200258 if( use_ret == -(POLARSSL_ERR_ECP_RANDOM_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000259 polarssl_snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
Manuel Pégourié-Gonnard456d3b92013-09-16 18:04:38 +0200260 if( use_ret == -(POLARSSL_ERR_ECP_INVALID_KEY) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000261 polarssl_snprintf( buf, buflen, "ECP - Invalid private or public key" );
Manuel Pégourié-Gonnard35e95dd2014-04-08 12:17:41 +0200262 if( use_ret == -(POLARSSL_ERR_ECP_SIG_LEN_MISMATCH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000263 polarssl_snprintf( buf, buflen, "ECP - Signature is valid but shorter than the user-supplied length" );
Paul Bakkercf4365f2013-01-16 17:00:43 +0100264#endif /* POLARSSL_ECP_C */
265
Paul Bakker9d781402011-05-09 16:17:09 +0000266#if defined(POLARSSL_MD_C)
267 if( use_ret == -(POLARSSL_ERR_MD_FEATURE_UNAVAILABLE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000268 polarssl_snprintf( buf, buflen, "MD - The selected feature is not available" );
Paul Bakker9c021ad2011-06-09 15:55:11 +0000269 if( use_ret == -(POLARSSL_ERR_MD_BAD_INPUT_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000270 polarssl_snprintf( buf, buflen, "MD - Bad input parameters to function" );
Paul Bakker9c021ad2011-06-09 15:55:11 +0000271 if( use_ret == -(POLARSSL_ERR_MD_ALLOC_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000272 polarssl_snprintf( buf, buflen, "MD - Failed to allocate memory" );
Paul Bakker8913f822012-01-14 18:07:41 +0000273 if( use_ret == -(POLARSSL_ERR_MD_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000274 polarssl_snprintf( buf, buflen, "MD - Opening or reading of file failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000275#endif /* POLARSSL_MD_C */
276
Paul Bakkercff68422013-09-15 20:43:33 +0200277#if defined(POLARSSL_PEM_PARSE_C) || defined(POLARSSL_PEM_WRITE_C)
Paul Bakker00b28602013-06-24 13:02:41 +0200278 if( use_ret == -(POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000279 polarssl_snprintf( buf, buflen, "PEM - No PEM header or footer found" );
Paul Bakker9d781402011-05-09 16:17:09 +0000280 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000281 polarssl_snprintf( buf, buflen, "PEM - PEM string is not as expected" );
Paul Bakker9d781402011-05-09 16:17:09 +0000282 if( use_ret == -(POLARSSL_ERR_PEM_MALLOC_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000283 polarssl_snprintf( buf, buflen, "PEM - Failed to allocate memory" );
Paul Bakker9d781402011-05-09 16:17:09 +0000284 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_ENC_IV) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000285 polarssl_snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
Paul Bakker9d781402011-05-09 16:17:09 +0000286 if( use_ret == -(POLARSSL_ERR_PEM_UNKNOWN_ENC_ALG) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000287 polarssl_snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
Paul Bakker9d781402011-05-09 16:17:09 +0000288 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_REQUIRED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000289 polarssl_snprintf( buf, buflen, "PEM - Private key password can't be empty" );
Paul Bakker9d781402011-05-09 16:17:09 +0000290 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_MISMATCH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000291 polarssl_snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
Paul Bakker9d781402011-05-09 16:17:09 +0000292 if( use_ret == -(POLARSSL_ERR_PEM_FEATURE_UNAVAILABLE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000293 polarssl_snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
Paul Bakker00b28602013-06-24 13:02:41 +0200294 if( use_ret == -(POLARSSL_ERR_PEM_BAD_INPUT_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000295 polarssl_snprintf( buf, buflen, "PEM - Bad input parameters to function" );
Paul Bakkercff68422013-09-15 20:43:33 +0200296#endif /* POLARSSL_PEM_PARSE_C || POLARSSL_PEM_WRITE_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000297
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200298#if defined(POLARSSL_PK_C)
299 if( use_ret == -(POLARSSL_ERR_PK_MALLOC_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000300 polarssl_snprintf( buf, buflen, "PK - Memory alloation failed" );
Manuel Pégourié-Gonnard374e4b82013-07-09 10:21:34 +0200301 if( use_ret == -(POLARSSL_ERR_PK_TYPE_MISMATCH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000302 polarssl_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
Manuel Pégourié-Gonnard15699382013-08-14 19:22:48 +0200303 if( use_ret == -(POLARSSL_ERR_PK_BAD_INPUT_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000304 polarssl_snprintf( buf, buflen, "PK - Bad input parameters to function" );
Paul Bakker1a7550a2013-09-15 13:01:22 +0200305 if( use_ret == -(POLARSSL_ERR_PK_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000306 polarssl_snprintf( buf, buflen, "PK - Read/write of file failed" );
Paul Bakker1a7550a2013-09-15 13:01:22 +0200307 if( use_ret == -(POLARSSL_ERR_PK_KEY_INVALID_VERSION) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000308 polarssl_snprintf( buf, buflen, "PK - Unsupported key version" );
Paul Bakker1a7550a2013-09-15 13:01:22 +0200309 if( use_ret == -(POLARSSL_ERR_PK_KEY_INVALID_FORMAT) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000310 polarssl_snprintf( buf, buflen, "PK - Invalid key tag or value" );
Paul Bakker1a7550a2013-09-15 13:01:22 +0200311 if( use_ret == -(POLARSSL_ERR_PK_UNKNOWN_PK_ALG) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000312 polarssl_snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
Paul Bakker1a7550a2013-09-15 13:01:22 +0200313 if( use_ret == -(POLARSSL_ERR_PK_PASSWORD_REQUIRED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000314 polarssl_snprintf( buf, buflen, "PK - Private key password can't be empty" );
Paul Bakker1a7550a2013-09-15 13:01:22 +0200315 if( use_ret == -(POLARSSL_ERR_PK_PASSWORD_MISMATCH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000316 polarssl_snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
Paul Bakker1a7550a2013-09-15 13:01:22 +0200317 if( use_ret == -(POLARSSL_ERR_PK_INVALID_PUBKEY) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000318 polarssl_snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
Paul Bakker1a7550a2013-09-15 13:01:22 +0200319 if( use_ret == -(POLARSSL_ERR_PK_INVALID_ALG) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000320 polarssl_snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
Paul Bakker1a7550a2013-09-15 13:01:22 +0200321 if( use_ret == -(POLARSSL_ERR_PK_UNKNOWN_NAMED_CURVE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000322 polarssl_snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
Paul Bakker1a7550a2013-09-15 13:01:22 +0200323 if( use_ret == -(POLARSSL_ERR_PK_FEATURE_UNAVAILABLE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000324 polarssl_snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
Manuel Pégourié-Gonnard2abed842014-04-08 12:40:15 +0200325 if( use_ret == -(POLARSSL_ERR_PK_SIG_LEN_MISMATCH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000326 polarssl_snprintf( buf, buflen, "PK - The signature is valid but its length is less than expected" );
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200327#endif /* POLARSSL_PK_C */
328
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200329#if defined(POLARSSL_PKCS12_C)
330 if( use_ret == -(POLARSSL_ERR_PKCS12_BAD_INPUT_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000331 polarssl_snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200332 if( use_ret == -(POLARSSL_ERR_PKCS12_FEATURE_UNAVAILABLE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000333 polarssl_snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200334 if( use_ret == -(POLARSSL_ERR_PKCS12_PBE_INVALID_FORMAT) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000335 polarssl_snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
Paul Bakker38b50d72013-06-24 19:33:27 +0200336 if( use_ret == -(POLARSSL_ERR_PKCS12_PASSWORD_MISMATCH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000337 polarssl_snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200338#endif /* POLARSSL_PKCS12_C */
339
Paul Bakker28144de2013-06-24 19:28:55 +0200340#if defined(POLARSSL_PKCS5_C)
341 if( use_ret == -(POLARSSL_ERR_PKCS5_BAD_INPUT_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000342 polarssl_snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
Paul Bakker28144de2013-06-24 19:28:55 +0200343 if( use_ret == -(POLARSSL_ERR_PKCS5_INVALID_FORMAT) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000344 polarssl_snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
Paul Bakker28144de2013-06-24 19:28:55 +0200345 if( use_ret == -(POLARSSL_ERR_PKCS5_FEATURE_UNAVAILABLE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000346 polarssl_snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
Paul Bakker28144de2013-06-24 19:28:55 +0200347 if( use_ret == -(POLARSSL_ERR_PKCS5_PASSWORD_MISMATCH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000348 polarssl_snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
Paul Bakker28144de2013-06-24 19:28:55 +0200349#endif /* POLARSSL_PKCS5_C */
350
Paul Bakker9d781402011-05-09 16:17:09 +0000351#if defined(POLARSSL_RSA_C)
352 if( use_ret == -(POLARSSL_ERR_RSA_BAD_INPUT_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000353 polarssl_snprintf( buf, buflen, "RSA - Bad input parameters to function" );
Paul Bakker9d781402011-05-09 16:17:09 +0000354 if( use_ret == -(POLARSSL_ERR_RSA_INVALID_PADDING) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000355 polarssl_snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
Paul Bakker9d781402011-05-09 16:17:09 +0000356 if( use_ret == -(POLARSSL_ERR_RSA_KEY_GEN_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000357 polarssl_snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
Paul Bakker9d781402011-05-09 16:17:09 +0000358 if( use_ret == -(POLARSSL_ERR_RSA_KEY_CHECK_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000359 polarssl_snprintf( buf, buflen, "RSA - Key failed to pass the libraries validity check" );
Paul Bakker9d781402011-05-09 16:17:09 +0000360 if( use_ret == -(POLARSSL_ERR_RSA_PUBLIC_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000361 polarssl_snprintf( buf, buflen, "RSA - The public key operation failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000362 if( use_ret == -(POLARSSL_ERR_RSA_PRIVATE_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000363 polarssl_snprintf( buf, buflen, "RSA - The private key operation failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000364 if( use_ret == -(POLARSSL_ERR_RSA_VERIFY_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000365 polarssl_snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000366 if( use_ret == -(POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000367 polarssl_snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
Paul Bakker9d781402011-05-09 16:17:09 +0000368 if( use_ret == -(POLARSSL_ERR_RSA_RNG_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000369 polarssl_snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
Paul Bakker9d781402011-05-09 16:17:09 +0000370#endif /* POLARSSL_RSA_C */
371
Paul Bakker831a7552011-05-18 13:32:51 +0000372#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000373 if( use_ret == -(POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000374 polarssl_snprintf( buf, buflen, "SSL - The requested feature is not available" );
Paul Bakker9d781402011-05-09 16:17:09 +0000375 if( use_ret == -(POLARSSL_ERR_SSL_BAD_INPUT_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000376 polarssl_snprintf( buf, buflen, "SSL - Bad input parameters to function" );
Paul Bakker9d781402011-05-09 16:17:09 +0000377 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_MAC) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000378 polarssl_snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000379 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_RECORD) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000380 polarssl_snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
Paul Bakker831a7552011-05-18 13:32:51 +0000381 if( use_ret == -(POLARSSL_ERR_SSL_CONN_EOF) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000382 polarssl_snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
Paul Bakker9d781402011-05-09 16:17:09 +0000383 if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_CIPHER) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000384 polarssl_snprintf( buf, buflen, "SSL - An unknown cipher was received" );
Paul Bakker9d781402011-05-09 16:17:09 +0000385 if( use_ret == -(POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000386 polarssl_snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
Paul Bakkera9a028e2013-11-21 17:31:06 +0100387 if( use_ret == -(POLARSSL_ERR_SSL_NO_RNG) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000388 polarssl_snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
Paul Bakker9d781402011-05-09 16:17:09 +0000389 if( use_ret == -(POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000390 polarssl_snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
Paul Bakker9d781402011-05-09 16:17:09 +0000391 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000392 polarssl_snprintf( buf, buflen, "SSL - Our own certificate(s) is/are too large to send in an SSL message" );
Paul Bakker9d781402011-05-09 16:17:09 +0000393 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000394 polarssl_snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
Paul Bakker9d781402011-05-09 16:17:09 +0000395 if( use_ret == -(POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000396 polarssl_snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000397 if( use_ret == -(POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000398 polarssl_snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
Paul Bakker9d781402011-05-09 16:17:09 +0000399 if( use_ret == -(POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000400 polarssl_snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
Paul Bakker9d781402011-05-09 16:17:09 +0000401 if( use_ret == -(POLARSSL_ERR_SSL_FATAL_ALERT_MESSAGE) )
Paul Bakker3aac1da2012-05-08 13:12:27 +0000402 {
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000403 polarssl_snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
Paul Bakker3aac1da2012-05-08 13:12:27 +0000404 return;
405 }
Paul Bakker9d781402011-05-09 16:17:09 +0000406 if( use_ret == -(POLARSSL_ERR_SSL_PEER_VERIFY_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000407 polarssl_snprintf( buf, buflen, "SSL - Verification of our peer failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000408 if( use_ret == -(POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000409 polarssl_snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000410 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000411 polarssl_snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000412 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000413 polarssl_snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000414 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000415 polarssl_snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000416 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000417 polarssl_snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000418 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000419 polarssl_snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000420 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000421 polarssl_snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000422 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000423 polarssl_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
Paul Bakker41c83d32013-03-20 14:39:14 +0100424 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000425 polarssl_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
Paul Bakker41c83d32013-03-20 14:39:14 +0100426 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000427 polarssl_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
Paul Bakker9d781402011-05-09 16:17:09 +0000428 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000429 polarssl_snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000430 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000431 polarssl_snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000432 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_FINISHED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000433 polarssl_snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000434 if( use_ret == -(POLARSSL_ERR_SSL_MALLOC_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000435 polarssl_snprintf( buf, buflen, "SSL - Memory allocation failed" );
Paul Bakker05ef8352012-05-08 09:17:57 +0000436 if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000437 polarssl_snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
Paul Bakker05ef8352012-05-08 09:17:57 +0000438 if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000439 polarssl_snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
Paul Bakker83f00bb2012-07-04 11:08:50 +0000440 if( use_ret == -(POLARSSL_ERR_SSL_COMPRESSION_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000441 polarssl_snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
Paul Bakker1d29fb52012-09-28 13:28:45 +0000442 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000443 polarssl_snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
Manuel Pégourié-Gonnarda5cc6022013-07-31 12:58:16 +0200444 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000445 polarssl_snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
Paul Bakker606b4ba2013-08-14 16:52:14 +0200446 if( use_ret == -(POLARSSL_ERR_SSL_SESSION_TICKET_EXPIRED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000447 polarssl_snprintf( buf, buflen, "SSL - Session ticket has expired" );
Manuel Pégourié-Gonnardb3d91872013-08-14 15:56:19 +0200448 if( use_ret == -(POLARSSL_ERR_SSL_PK_TYPE_MISMATCH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000449 polarssl_snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
Paul Bakker6db455e2013-09-18 17:29:31 +0200450 if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_IDENTITY) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000451 polarssl_snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
Manuel Pégourié-Gonnarda8a25ae2013-10-27 13:48:15 +0100452 if( use_ret == -(POLARSSL_ERR_SSL_INTERNAL_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000453 polarssl_snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
Manuel Pégourié-Gonnard83cdffc2014-03-10 21:20:29 +0100454 if( use_ret == -(POLARSSL_ERR_SSL_COUNTER_WRAPPING) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000455 polarssl_snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
Manuel Pégourié-Gonnard65919622014-08-19 12:50:30 +0200456 if( use_ret == -(POLARSSL_ERR_SSL_WAITING_SERVER_HELLO_RENEGO) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000457 polarssl_snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" );
Manuel Pégourié-Gonnard2c9ee812014-07-22 11:45:03 +0200458 if( use_ret == -(POLARSSL_ERR_SSL_HELLO_VERIFY_REQUIRED) )
Manuel Pégourié-Gonnardd901d172015-02-16 18:37:53 +0000459 polarssl_snprintf( buf, buflen, "SSL - DTLS client must retry for hello verification" );
Manuel Pégourié-Gonnard562eb782014-07-23 23:41:53 +0200460 if( use_ret == -(POLARSSL_ERR_SSL_BUFFER_TOO_SMALL) )
Manuel Pégourié-Gonnardd901d172015-02-16 18:37:53 +0000461 polarssl_snprintf( buf, buflen, "SSL - A buffer is too small to receive or write a message" );
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +0100462 if( use_ret == -(POLARSSL_ERR_SSL_NO_USABLE_CIPHERSUITE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000463 polarssl_snprintf( buf, buflen, "SSL - None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages)" );
Paul Bakker831a7552011-05-18 13:32:51 +0000464#endif /* POLARSSL_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000465
Paul Bakker36713e82013-09-17 13:25:29 +0200466#if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000467 if( use_ret == -(POLARSSL_ERR_X509_FEATURE_UNAVAILABLE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000468 polarssl_snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
Paul Bakker51876562013-09-17 14:36:05 +0200469 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_OID) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000470 polarssl_snprintf( buf, buflen, "X509 - Requested OID is unknown" );
Paul Bakker51876562013-09-17 14:36:05 +0200471 if( use_ret == -(POLARSSL_ERR_X509_INVALID_FORMAT) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000472 polarssl_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
Paul Bakker51876562013-09-17 14:36:05 +0200473 if( use_ret == -(POLARSSL_ERR_X509_INVALID_VERSION) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000474 polarssl_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200475 if( use_ret == -(POLARSSL_ERR_X509_INVALID_SERIAL) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000476 polarssl_snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200477 if( use_ret == -(POLARSSL_ERR_X509_INVALID_ALG) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000478 polarssl_snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200479 if( use_ret == -(POLARSSL_ERR_X509_INVALID_NAME) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000480 polarssl_snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200481 if( use_ret == -(POLARSSL_ERR_X509_INVALID_DATE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000482 polarssl_snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200483 if( use_ret == -(POLARSSL_ERR_X509_INVALID_SIGNATURE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000484 polarssl_snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200485 if( use_ret == -(POLARSSL_ERR_X509_INVALID_EXTENSIONS) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000486 polarssl_snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200487 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_VERSION) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000488 polarssl_snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
Paul Bakker51876562013-09-17 14:36:05 +0200489 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_SIG_ALG) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000490 polarssl_snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
Paul Bakker51876562013-09-17 14:36:05 +0200491 if( use_ret == -(POLARSSL_ERR_X509_SIG_MISMATCH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000492 polarssl_snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::x509_crt sig_oid)" );
Paul Bakker9d781402011-05-09 16:17:09 +0000493 if( use_ret == -(POLARSSL_ERR_X509_CERT_VERIFY_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000494 polarssl_snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
Paul Bakker6c0ceb32011-12-04 12:24:18 +0000495 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000496 polarssl_snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
Paul Bakker51876562013-09-17 14:36:05 +0200497 if( use_ret == -(POLARSSL_ERR_X509_BAD_INPUT_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000498 polarssl_snprintf( buf, buflen, "X509 - Input invalid" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000499 if( use_ret == -(POLARSSL_ERR_X509_MALLOC_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000500 polarssl_snprintf( buf, buflen, "X509 - Allocation of memory failed" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000501 if( use_ret == -(POLARSSL_ERR_X509_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000502 polarssl_snprintf( buf, buflen, "X509 - Read/write of file failed" );
Paul Bakker36713e82013-09-17 13:25:29 +0200503#endif /* POLARSSL_X509_USE,X509_CREATE_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200504 // END generated code
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200505
Paul Bakker9d781402011-05-09 16:17:09 +0000506 if( strlen( buf ) == 0 )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000507 polarssl_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000508 }
509
510 use_ret = ret & ~0xFF80;
511
512 if( use_ret == 0 )
513 return;
514
515 // If high level code is present, make a concatenation between both
516 // error strings.
517 //
518 len = strlen( buf );
519
520 if( len > 0 )
521 {
522 if( buflen - len < 5 )
523 return;
524
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000525 polarssl_snprintf( buf + len, buflen - len, " : " );
Paul Bakker9d781402011-05-09 16:17:09 +0000526
527 buf += len + 3;
528 buflen -= len + 3;
529 }
530
531 // Low level error codes
532 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200533 // BEGIN generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000534#if defined(POLARSSL_AES_C)
535 if( use_ret == -(POLARSSL_ERR_AES_INVALID_KEY_LENGTH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000536 polarssl_snprintf( buf, buflen, "AES - Invalid key length" );
Paul Bakker9d781402011-05-09 16:17:09 +0000537 if( use_ret == -(POLARSSL_ERR_AES_INVALID_INPUT_LENGTH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000538 polarssl_snprintf( buf, buflen, "AES - Invalid data input length" );
Paul Bakker9d781402011-05-09 16:17:09 +0000539#endif /* POLARSSL_AES_C */
540
Paul Bakkerdceecd82011-11-15 16:38:34 +0000541#if defined(POLARSSL_ASN1_PARSE_C)
542 if( use_ret == -(POLARSSL_ERR_ASN1_OUT_OF_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000543 polarssl_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
Paul Bakkerdceecd82011-11-15 16:38:34 +0000544 if( use_ret == -(POLARSSL_ERR_ASN1_UNEXPECTED_TAG) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000545 polarssl_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
Paul Bakkerdceecd82011-11-15 16:38:34 +0000546 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_LENGTH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000547 polarssl_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
Paul Bakkerdceecd82011-11-15 16:38:34 +0000548 if( use_ret == -(POLARSSL_ERR_ASN1_LENGTH_MISMATCH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000549 polarssl_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
Paul Bakkerdceecd82011-11-15 16:38:34 +0000550 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000551 polarssl_snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000552 if( use_ret == -(POLARSSL_ERR_ASN1_MALLOC_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000553 polarssl_snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000554 if( use_ret == -(POLARSSL_ERR_ASN1_BUF_TOO_SMALL) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000555 polarssl_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
Paul Bakkerdceecd82011-11-15 16:38:34 +0000556#endif /* POLARSSL_ASN1_PARSE_C */
557
Paul Bakker9d781402011-05-09 16:17:09 +0000558#if defined(POLARSSL_BASE64_C)
559 if( use_ret == -(POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000560 polarssl_snprintf( buf, buflen, "BASE64 - Output buffer too small" );
Paul Bakker9d781402011-05-09 16:17:09 +0000561 if( use_ret == -(POLARSSL_ERR_BASE64_INVALID_CHARACTER) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000562 polarssl_snprintf( buf, buflen, "BASE64 - Invalid character in input" );
Paul Bakker9d781402011-05-09 16:17:09 +0000563#endif /* POLARSSL_BASE64_C */
564
565#if defined(POLARSSL_BIGNUM_C)
566 if( use_ret == -(POLARSSL_ERR_MPI_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000567 polarssl_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
Paul Bakker9d781402011-05-09 16:17:09 +0000568 if( use_ret == -(POLARSSL_ERR_MPI_BAD_INPUT_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000569 polarssl_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
Paul Bakker9d781402011-05-09 16:17:09 +0000570 if( use_ret == -(POLARSSL_ERR_MPI_INVALID_CHARACTER) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000571 polarssl_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
Paul Bakker9d781402011-05-09 16:17:09 +0000572 if( use_ret == -(POLARSSL_ERR_MPI_BUFFER_TOO_SMALL) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000573 polarssl_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
Paul Bakker9d781402011-05-09 16:17:09 +0000574 if( use_ret == -(POLARSSL_ERR_MPI_NEGATIVE_VALUE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000575 polarssl_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
Paul Bakker9d781402011-05-09 16:17:09 +0000576 if( use_ret == -(POLARSSL_ERR_MPI_DIVISION_BY_ZERO) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000577 polarssl_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000578 if( use_ret == -(POLARSSL_ERR_MPI_NOT_ACCEPTABLE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000579 polarssl_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000580 if( use_ret == -(POLARSSL_ERR_MPI_MALLOC_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000581 polarssl_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000582#endif /* POLARSSL_BIGNUM_C */
583
Paul Bakker83f00bb2012-07-04 11:08:50 +0000584#if defined(POLARSSL_BLOWFISH_C)
585 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000586 polarssl_snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
Paul Bakker83f00bb2012-07-04 11:08:50 +0000587 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000588 polarssl_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
Paul Bakker83f00bb2012-07-04 11:08:50 +0000589#endif /* POLARSSL_BLOWFISH_C */
590
Paul Bakker9d781402011-05-09 16:17:09 +0000591#if defined(POLARSSL_CAMELLIA_C)
592 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000593 polarssl_snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
Paul Bakker9d781402011-05-09 16:17:09 +0000594 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000595 polarssl_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
Paul Bakker9d781402011-05-09 16:17:09 +0000596#endif /* POLARSSL_CAMELLIA_C */
597
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200598#if defined(POLARSSL_CCM_C)
599 if( use_ret == -(POLARSSL_ERR_CCM_BAD_INPUT) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000600 polarssl_snprintf( buf, buflen, "CCM - Bad input parameters to function" );
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200601 if( use_ret == -(POLARSSL_ERR_CCM_AUTH_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000602 polarssl_snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200603#endif /* POLARSSL_CCM_C */
604
Paul Bakker880ac7e2011-11-27 14:50:49 +0000605#if defined(POLARSSL_CTR_DRBG_C)
606 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000607 polarssl_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
Paul Bakker880ac7e2011-11-27 14:50:49 +0000608 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000609 polarssl_snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
Paul Bakker880ac7e2011-11-27 14:50:49 +0000610 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000611 polarssl_snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000612 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000613 polarssl_snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
Paul Bakker880ac7e2011-11-27 14:50:49 +0000614#endif /* POLARSSL_CTR_DRBG_C */
615
Paul Bakker9d781402011-05-09 16:17:09 +0000616#if defined(POLARSSL_DES_C)
617 if( use_ret == -(POLARSSL_ERR_DES_INVALID_INPUT_LENGTH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000618 polarssl_snprintf( buf, buflen, "DES - The data input has an invalid length" );
Paul Bakker9d781402011-05-09 16:17:09 +0000619#endif /* POLARSSL_DES_C */
620
Paul Bakker6083fd22011-12-03 21:45:14 +0000621#if defined(POLARSSL_ENTROPY_C)
622 if( use_ret == -(POLARSSL_ERR_ENTROPY_SOURCE_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000623 polarssl_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
Paul Bakker6083fd22011-12-03 21:45:14 +0000624 if( use_ret == -(POLARSSL_ERR_ENTROPY_MAX_SOURCES) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000625 polarssl_snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
Paul Bakker43655f42011-12-15 20:11:16 +0000626 if( use_ret == -(POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000627 polarssl_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
Paul Bakker66ff70d2014-03-26 11:54:05 +0100628 if( use_ret == -(POLARSSL_ERR_ENTROPY_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000629 polarssl_snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
Paul Bakker6083fd22011-12-03 21:45:14 +0000630#endif /* POLARSSL_ENTROPY_C */
631
Paul Bakker030277a2012-04-17 12:24:26 +0000632#if defined(POLARSSL_GCM_C)
633 if( use_ret == -(POLARSSL_ERR_GCM_AUTH_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000634 polarssl_snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
Paul Bakkerd8ef1672012-04-18 14:17:32 +0000635 if( use_ret == -(POLARSSL_ERR_GCM_BAD_INPUT) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000636 polarssl_snprintf( buf, buflen, "GCM - Bad input parameters to function" );
Paul Bakker030277a2012-04-17 12:24:26 +0000637#endif /* POLARSSL_GCM_C */
638
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100639#if defined(POLARSSL_HMAC_DRBG_C)
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100640 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000641 polarssl_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100642 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000643 polarssl_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100644 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000645 polarssl_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
Manuel Pégourié-Gonnard9a6e93e2014-03-11 09:34:02 +0100646 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000647 polarssl_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100648#endif /* POLARSSL_HMAC_DRBG_C */
649
Paul Bakker69e095c2011-12-10 21:55:01 +0000650#if defined(POLARSSL_MD2_C)
651 if( use_ret == -(POLARSSL_ERR_MD2_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000652 polarssl_snprintf( buf, buflen, "MD2 - Read/write error in file" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000653#endif /* POLARSSL_MD2_C */
654
655#if defined(POLARSSL_MD4_C)
656 if( use_ret == -(POLARSSL_ERR_MD4_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000657 polarssl_snprintf( buf, buflen, "MD4 - Read/write error in file" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000658#endif /* POLARSSL_MD4_C */
659
660#if defined(POLARSSL_MD5_C)
661 if( use_ret == -(POLARSSL_ERR_MD5_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000662 polarssl_snprintf( buf, buflen, "MD5 - Read/write error in file" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000663#endif /* POLARSSL_MD5_C */
664
Paul Bakker9d781402011-05-09 16:17:09 +0000665#if defined(POLARSSL_NET_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000666 if( use_ret == -(POLARSSL_ERR_NET_SOCKET_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000667 polarssl_snprintf( buf, buflen, "NET - Failed to open a socket" );
Paul Bakker9d781402011-05-09 16:17:09 +0000668 if( use_ret == -(POLARSSL_ERR_NET_CONNECT_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000669 polarssl_snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000670 if( use_ret == -(POLARSSL_ERR_NET_BIND_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000671 polarssl_snprintf( buf, buflen, "NET - Binding of the socket failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000672 if( use_ret == -(POLARSSL_ERR_NET_LISTEN_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000673 polarssl_snprintf( buf, buflen, "NET - Could not listen on the socket" );
Paul Bakker9d781402011-05-09 16:17:09 +0000674 if( use_ret == -(POLARSSL_ERR_NET_ACCEPT_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000675 polarssl_snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
Paul Bakker9d781402011-05-09 16:17:09 +0000676 if( use_ret == -(POLARSSL_ERR_NET_RECV_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000677 polarssl_snprintf( buf, buflen, "NET - Reading information from the socket failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000678 if( use_ret == -(POLARSSL_ERR_NET_SEND_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000679 polarssl_snprintf( buf, buflen, "NET - Sending information through the socket failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000680 if( use_ret == -(POLARSSL_ERR_NET_CONN_RESET) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000681 polarssl_snprintf( buf, buflen, "NET - Connection was reset by peer" );
Paul Bakker831a7552011-05-18 13:32:51 +0000682 if( use_ret == -(POLARSSL_ERR_NET_WANT_READ) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000683 polarssl_snprintf( buf, buflen, "NET - Connection requires a read call" );
Paul Bakker831a7552011-05-18 13:32:51 +0000684 if( use_ret == -(POLARSSL_ERR_NET_WANT_WRITE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000685 polarssl_snprintf( buf, buflen, "NET - Connection requires a write call" );
Manuel Pégourié-Gonnard9d9b0032014-09-18 11:22:45 +0200686 if( use_ret == -(POLARSSL_ERR_NET_UNKNOWN_HOST) )
Manuel Pégourié-Gonnardd901d172015-02-16 18:37:53 +0000687 polarssl_snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
Manuel Pégourié-Gonnard9d9b0032014-09-18 11:22:45 +0200688 if( use_ret == -(POLARSSL_ERR_NET_TIMEOUT) )
Manuel Pégourié-Gonnardd901d172015-02-16 18:37:53 +0000689 polarssl_snprintf( buf, buflen, "NET - The operation timed out" );
Paul Bakker9d781402011-05-09 16:17:09 +0000690#endif /* POLARSSL_NET_C */
691
Paul Bakkerc70b9822013-04-07 22:00:46 +0200692#if defined(POLARSSL_OID_C)
693 if( use_ret == -(POLARSSL_ERR_OID_NOT_FOUND) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000694 polarssl_snprintf( buf, buflen, "OID - OID is not found" );
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100695 if( use_ret == -(POLARSSL_ERR_OID_BUF_TOO_SMALL) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000696 polarssl_snprintf( buf, buflen, "OID - output buffer is too small" );
Paul Bakkerc70b9822013-04-07 22:00:46 +0200697#endif /* POLARSSL_OID_C */
698
Paul Bakker9d781402011-05-09 16:17:09 +0000699#if defined(POLARSSL_PADLOCK_C)
700 if( use_ret == -(POLARSSL_ERR_PADLOCK_DATA_MISALIGNED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000701 polarssl_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
Paul Bakker9d781402011-05-09 16:17:09 +0000702#endif /* POLARSSL_PADLOCK_C */
703
Paul Bakkerd14277d2012-09-26 15:19:05 +0000704#if defined(POLARSSL_PBKDF2_C)
705 if( use_ret == -(POLARSSL_ERR_PBKDF2_BAD_INPUT_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000706 polarssl_snprintf( buf, buflen, "PBKDF2 - Bad input parameters to function" );
Paul Bakkerd14277d2012-09-26 15:19:05 +0000707#endif /* POLARSSL_PBKDF2_C */
708
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100709#if defined(POLARSSL_RIPEMD160_C)
710 if( use_ret == -(POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000711 polarssl_snprintf( buf, buflen, "RIPEMD160 - Read/write error in file" );
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100712#endif /* POLARSSL_RIPEMD160_C */
713
Paul Bakker69e095c2011-12-10 21:55:01 +0000714#if defined(POLARSSL_SHA1_C)
715 if( use_ret == -(POLARSSL_ERR_SHA1_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000716 polarssl_snprintf( buf, buflen, "SHA1 - Read/write error in file" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000717#endif /* POLARSSL_SHA1_C */
718
Paul Bakker9e36f042013-06-30 14:34:05 +0200719#if defined(POLARSSL_SHA256_C)
720 if( use_ret == -(POLARSSL_ERR_SHA256_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000721 polarssl_snprintf( buf, buflen, "SHA256 - Read/write error in file" );
Paul Bakker9e36f042013-06-30 14:34:05 +0200722#endif /* POLARSSL_SHA256_C */
Paul Bakker69e095c2011-12-10 21:55:01 +0000723
Paul Bakker9e36f042013-06-30 14:34:05 +0200724#if defined(POLARSSL_SHA512_C)
725 if( use_ret == -(POLARSSL_ERR_SHA512_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000726 polarssl_snprintf( buf, buflen, "SHA512 - Read/write error in file" );
Paul Bakker9e36f042013-06-30 14:34:05 +0200727#endif /* POLARSSL_SHA512_C */
Paul Bakker69e095c2011-12-10 21:55:01 +0000728
Paul Bakker2466d932013-09-28 14:40:38 +0200729#if defined(POLARSSL_THREADING_C)
730 if( use_ret == -(POLARSSL_ERR_THREADING_FEATURE_UNAVAILABLE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000731 polarssl_snprintf( buf, buflen, "THREADING - The selected feature is not available" );
Paul Bakker2466d932013-09-28 14:40:38 +0200732 if( use_ret == -(POLARSSL_ERR_THREADING_BAD_INPUT_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000733 polarssl_snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
Paul Bakker2466d932013-09-28 14:40:38 +0200734 if( use_ret == -(POLARSSL_ERR_THREADING_MUTEX_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000735 polarssl_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
Paul Bakker2466d932013-09-28 14:40:38 +0200736#endif /* POLARSSL_THREADING_C */
737
Paul Bakker9d781402011-05-09 16:17:09 +0000738#if defined(POLARSSL_XTEA_C)
739 if( use_ret == -(POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000740 polarssl_snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
Paul Bakker9d781402011-05-09 16:17:09 +0000741#endif /* POLARSSL_XTEA_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200742 // END generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000743
744 if( strlen( buf ) != 0 )
745 return;
746
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000747 polarssl_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000748}
749
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200750#if defined(POLARSSL_ERROR_STRERROR_BC)
751void error_strerror( int ret, char *buf, size_t buflen )
752{
Paul Bakkerb887f112013-10-11 15:09:40 +0200753 polarssl_strerror( ret, buf, buflen );
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200754}
755#endif /* POLARSSL_ERROR_STRERROR_BC */
756
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100757#else /* POLARSSL_ERROR_C */
758
759#if defined(POLARSSL_ERROR_STRERROR_DUMMY)
760
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100761/*
762 * Provide an non-function in case POLARSSL_ERROR_C is not defined
763 */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200764void polarssl_strerror( int ret, char *buf, size_t buflen )
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100765{
766 ((void) ret);
767
768 if( buflen > 0 )
769 buf[0] = '\0';
770}
771
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200772#if defined(POLARSSL_ERROR_STRERROR_BC)
773void error_strerror( int ret, char *buf, size_t buflen )
774{
Paul Bakkerb887f112013-10-11 15:09:40 +0200775 polarssl_strerror( ret, buf, buflen );
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200776}
777#endif /* POLARSSL_ERROR_STRERROR_BC */
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100778#endif /* POLARSSL_ERROR_STRERROR_DUMMY */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200779
Paul Bakker9a736322012-11-14 12:39:52 +0000780#endif /* POLARSSL_ERROR_C */