blob: 91e804ba5330e255117eb6d90607d8cc709d08ea [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é-Gonnard860b5162015-01-28 17:12:07 +00006 * This file is part of mbed TLS (https://polarssl.org)
Paul Bakker9d781402011-05-09 16:17:09 +00007 *
Paul Bakker9d781402011-05-09 16:17:09 +00008 * 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)
Paul Bakker9d781402011-05-09 16:17:09 +000024#include "polarssl/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)
Paul Bakker3c2122f2013-06-24 19:03:14 +020030#include "polarssl/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)
35#include "polarssl/platform.h"
36#else
37#define polarssl_snprintf snprintf
38#endif
39
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020040#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)
45#include "polarssl/aes.h"
46#endif
47
48#if defined(POLARSSL_BASE64_C)
49#include "polarssl/base64.h"
50#endif
51
52#if defined(POLARSSL_BIGNUM_C)
53#include "polarssl/bignum.h"
54#endif
55
Paul Bakker83f00bb2012-07-04 11:08:50 +000056#if defined(POLARSSL_BLOWFISH_C)
57#include "polarssl/blowfish.h"
58#endif
59
Paul Bakker9d781402011-05-09 16:17:09 +000060#if defined(POLARSSL_CAMELLIA_C)
61#include "polarssl/camellia.h"
62#endif
63
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +020064#if defined(POLARSSL_CCM_C)
65#include "polarssl/ccm.h"
66#endif
67
Paul Bakkerff61a782011-06-09 15:42:02 +000068#if defined(POLARSSL_CIPHER_C)
69#include "polarssl/cipher.h"
70#endif
71
Paul Bakker880ac7e2011-11-27 14:50:49 +000072#if defined(POLARSSL_CTR_DRBG_C)
73#include "polarssl/ctr_drbg.h"
74#endif
75
Paul Bakker9d781402011-05-09 16:17:09 +000076#if defined(POLARSSL_DES_C)
77#include "polarssl/des.h"
78#endif
79
80#if defined(POLARSSL_DHM_C)
81#include "polarssl/dhm.h"
82#endif
83
Paul Bakkercf4365f2013-01-16 17:00:43 +010084#if defined(POLARSSL_ECP_C)
85#include "polarssl/ecp.h"
86#endif
87
Paul Bakker6083fd22011-12-03 21:45:14 +000088#if defined(POLARSSL_ENTROPY_C)
89#include "polarssl/entropy.h"
90#endif
91
Paul Bakker030277a2012-04-17 12:24:26 +000092#if defined(POLARSSL_GCM_C)
93#include "polarssl/gcm.h"
94#endif
95
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010096#if defined(POLARSSL_HMAC_DRBG_C)
97#include "polarssl/hmac_drbg.h"
98#endif
99
Paul Bakker9d781402011-05-09 16:17:09 +0000100#if defined(POLARSSL_MD_C)
101#include "polarssl/md.h"
102#endif
103
Paul Bakker69e095c2011-12-10 21:55:01 +0000104#if defined(POLARSSL_MD2_C)
105#include "polarssl/md2.h"
106#endif
107
108#if defined(POLARSSL_MD4_C)
109#include "polarssl/md4.h"
110#endif
111
112#if defined(POLARSSL_MD5_C)
113#include "polarssl/md5.h"
114#endif
115
Paul Bakker9d781402011-05-09 16:17:09 +0000116#if defined(POLARSSL_NET_C)
117#include "polarssl/net.h"
118#endif
119
Paul Bakkerc70b9822013-04-07 22:00:46 +0200120#if defined(POLARSSL_OID_C)
121#include "polarssl/oid.h"
122#endif
123
Paul Bakker9d781402011-05-09 16:17:09 +0000124#if defined(POLARSSL_PADLOCK_C)
125#include "polarssl/padlock.h"
126#endif
127
Paul Bakkerd14277d2012-09-26 15:19:05 +0000128#if defined(POLARSSL_PBKDF2_C)
129#include "polarssl/pbkdf2.h"
130#endif
131
Paul Bakkercff68422013-09-15 20:43:33 +0200132#if defined(POLARSSL_PEM_PARSE_C) || defined(POLARSSL_PEM_WRITE_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000133#include "polarssl/pem.h"
134#endif
135
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200136#if defined(POLARSSL_PK_C)
137#include "polarssl/pk.h"
138#endif
139
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200140#if defined(POLARSSL_PKCS12_C)
141#include "polarssl/pkcs12.h"
142#endif
143
Paul Bakkerb0c19a42013-06-24 19:26:38 +0200144#if defined(POLARSSL_PKCS5_C)
145#include "polarssl/pkcs5.h"
146#endif
147
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100148#if defined(POLARSSL_RIPEMD160_C)
149#include "polarssl/ripemd160.h"
150#endif
151
Paul Bakker9d781402011-05-09 16:17:09 +0000152#if defined(POLARSSL_RSA_C)
153#include "polarssl/rsa.h"
154#endif
155
Paul Bakker69e095c2011-12-10 21:55:01 +0000156#if defined(POLARSSL_SHA1_C)
157#include "polarssl/sha1.h"
158#endif
159
Paul Bakker9e36f042013-06-30 14:34:05 +0200160#if defined(POLARSSL_SHA256_C)
Paul Bakkerd2681d82013-06-30 14:49:12 +0200161#include "polarssl/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)
Paul Bakkerd2681d82013-06-30 14:49:12 +0200165#include "polarssl/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)
Paul Bakker9d781402011-05-09 16:17:09 +0000169#include "polarssl/ssl.h"
170#endif
171
Paul Bakker2466d932013-09-28 14:40:38 +0200172#if defined(POLARSSL_THREADING_C)
173#include "polarssl/threading.h"
174#endif
175
Paul Bakker36713e82013-09-17 13:25:29 +0200176#if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000177#include "polarssl/x509.h"
178#endif
179
180#if defined(POLARSSL_XTEA_C)
181#include "polarssl/xtea.h"
182#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é-Gonnardf01768c2015-01-08 17:06:16 +0100458 if( use_ret == -(POLARSSL_ERR_SSL_NO_USABLE_CIPHERSUITE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000459 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 +0000460#endif /* POLARSSL_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000461
Paul Bakker36713e82013-09-17 13:25:29 +0200462#if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000463 if( use_ret == -(POLARSSL_ERR_X509_FEATURE_UNAVAILABLE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000464 polarssl_snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
Paul Bakker51876562013-09-17 14:36:05 +0200465 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_OID) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000466 polarssl_snprintf( buf, buflen, "X509 - Requested OID is unknown" );
Paul Bakker51876562013-09-17 14:36:05 +0200467 if( use_ret == -(POLARSSL_ERR_X509_INVALID_FORMAT) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000468 polarssl_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
Paul Bakker51876562013-09-17 14:36:05 +0200469 if( use_ret == -(POLARSSL_ERR_X509_INVALID_VERSION) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000470 polarssl_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200471 if( use_ret == -(POLARSSL_ERR_X509_INVALID_SERIAL) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000472 polarssl_snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200473 if( use_ret == -(POLARSSL_ERR_X509_INVALID_ALG) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000474 polarssl_snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200475 if( use_ret == -(POLARSSL_ERR_X509_INVALID_NAME) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000476 polarssl_snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200477 if( use_ret == -(POLARSSL_ERR_X509_INVALID_DATE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000478 polarssl_snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200479 if( use_ret == -(POLARSSL_ERR_X509_INVALID_SIGNATURE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000480 polarssl_snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200481 if( use_ret == -(POLARSSL_ERR_X509_INVALID_EXTENSIONS) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000482 polarssl_snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200483 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_VERSION) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000484 polarssl_snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
Paul Bakker51876562013-09-17 14:36:05 +0200485 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_SIG_ALG) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000486 polarssl_snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
Paul Bakker51876562013-09-17 14:36:05 +0200487 if( use_ret == -(POLARSSL_ERR_X509_SIG_MISMATCH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000488 polarssl_snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::x509_crt sig_oid)" );
Paul Bakker9d781402011-05-09 16:17:09 +0000489 if( use_ret == -(POLARSSL_ERR_X509_CERT_VERIFY_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000490 polarssl_snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
Paul Bakker6c0ceb32011-12-04 12:24:18 +0000491 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000492 polarssl_snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
Paul Bakker51876562013-09-17 14:36:05 +0200493 if( use_ret == -(POLARSSL_ERR_X509_BAD_INPUT_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000494 polarssl_snprintf( buf, buflen, "X509 - Input invalid" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000495 if( use_ret == -(POLARSSL_ERR_X509_MALLOC_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000496 polarssl_snprintf( buf, buflen, "X509 - Allocation of memory failed" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000497 if( use_ret == -(POLARSSL_ERR_X509_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000498 polarssl_snprintf( buf, buflen, "X509 - Read/write of file failed" );
Paul Bakker36713e82013-09-17 13:25:29 +0200499#endif /* POLARSSL_X509_USE,X509_CREATE_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200500 // END generated code
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200501
Paul Bakker9d781402011-05-09 16:17:09 +0000502 if( strlen( buf ) == 0 )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000503 polarssl_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000504 }
505
506 use_ret = ret & ~0xFF80;
507
508 if( use_ret == 0 )
509 return;
510
511 // If high level code is present, make a concatenation between both
512 // error strings.
513 //
514 len = strlen( buf );
515
516 if( len > 0 )
517 {
518 if( buflen - len < 5 )
519 return;
520
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000521 polarssl_snprintf( buf + len, buflen - len, " : " );
Paul Bakker9d781402011-05-09 16:17:09 +0000522
523 buf += len + 3;
524 buflen -= len + 3;
525 }
526
527 // Low level error codes
528 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200529 // BEGIN generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000530#if defined(POLARSSL_AES_C)
531 if( use_ret == -(POLARSSL_ERR_AES_INVALID_KEY_LENGTH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000532 polarssl_snprintf( buf, buflen, "AES - Invalid key length" );
Paul Bakker9d781402011-05-09 16:17:09 +0000533 if( use_ret == -(POLARSSL_ERR_AES_INVALID_INPUT_LENGTH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000534 polarssl_snprintf( buf, buflen, "AES - Invalid data input length" );
Paul Bakker9d781402011-05-09 16:17:09 +0000535#endif /* POLARSSL_AES_C */
536
Paul Bakkerdceecd82011-11-15 16:38:34 +0000537#if defined(POLARSSL_ASN1_PARSE_C)
538 if( use_ret == -(POLARSSL_ERR_ASN1_OUT_OF_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000539 polarssl_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
Paul Bakkerdceecd82011-11-15 16:38:34 +0000540 if( use_ret == -(POLARSSL_ERR_ASN1_UNEXPECTED_TAG) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000541 polarssl_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
Paul Bakkerdceecd82011-11-15 16:38:34 +0000542 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_LENGTH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000543 polarssl_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
Paul Bakkerdceecd82011-11-15 16:38:34 +0000544 if( use_ret == -(POLARSSL_ERR_ASN1_LENGTH_MISMATCH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000545 polarssl_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
Paul Bakkerdceecd82011-11-15 16:38:34 +0000546 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000547 polarssl_snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000548 if( use_ret == -(POLARSSL_ERR_ASN1_MALLOC_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000549 polarssl_snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000550 if( use_ret == -(POLARSSL_ERR_ASN1_BUF_TOO_SMALL) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000551 polarssl_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
Paul Bakkerdceecd82011-11-15 16:38:34 +0000552#endif /* POLARSSL_ASN1_PARSE_C */
553
Paul Bakker9d781402011-05-09 16:17:09 +0000554#if defined(POLARSSL_BASE64_C)
555 if( use_ret == -(POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000556 polarssl_snprintf( buf, buflen, "BASE64 - Output buffer too small" );
Paul Bakker9d781402011-05-09 16:17:09 +0000557 if( use_ret == -(POLARSSL_ERR_BASE64_INVALID_CHARACTER) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000558 polarssl_snprintf( buf, buflen, "BASE64 - Invalid character in input" );
Paul Bakker9d781402011-05-09 16:17:09 +0000559#endif /* POLARSSL_BASE64_C */
560
561#if defined(POLARSSL_BIGNUM_C)
562 if( use_ret == -(POLARSSL_ERR_MPI_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000563 polarssl_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
Paul Bakker9d781402011-05-09 16:17:09 +0000564 if( use_ret == -(POLARSSL_ERR_MPI_BAD_INPUT_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000565 polarssl_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
Paul Bakker9d781402011-05-09 16:17:09 +0000566 if( use_ret == -(POLARSSL_ERR_MPI_INVALID_CHARACTER) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000567 polarssl_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
Paul Bakker9d781402011-05-09 16:17:09 +0000568 if( use_ret == -(POLARSSL_ERR_MPI_BUFFER_TOO_SMALL) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000569 polarssl_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
Paul Bakker9d781402011-05-09 16:17:09 +0000570 if( use_ret == -(POLARSSL_ERR_MPI_NEGATIVE_VALUE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000571 polarssl_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
Paul Bakker9d781402011-05-09 16:17:09 +0000572 if( use_ret == -(POLARSSL_ERR_MPI_DIVISION_BY_ZERO) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000573 polarssl_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000574 if( use_ret == -(POLARSSL_ERR_MPI_NOT_ACCEPTABLE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000575 polarssl_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000576 if( use_ret == -(POLARSSL_ERR_MPI_MALLOC_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000577 polarssl_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000578#endif /* POLARSSL_BIGNUM_C */
579
Paul Bakker83f00bb2012-07-04 11:08:50 +0000580#if defined(POLARSSL_BLOWFISH_C)
581 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000582 polarssl_snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
Paul Bakker83f00bb2012-07-04 11:08:50 +0000583 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000584 polarssl_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
Paul Bakker83f00bb2012-07-04 11:08:50 +0000585#endif /* POLARSSL_BLOWFISH_C */
586
Paul Bakker9d781402011-05-09 16:17:09 +0000587#if defined(POLARSSL_CAMELLIA_C)
588 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000589 polarssl_snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
Paul Bakker9d781402011-05-09 16:17:09 +0000590 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000591 polarssl_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
Paul Bakker9d781402011-05-09 16:17:09 +0000592#endif /* POLARSSL_CAMELLIA_C */
593
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200594#if defined(POLARSSL_CCM_C)
595 if( use_ret == -(POLARSSL_ERR_CCM_BAD_INPUT) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000596 polarssl_snprintf( buf, buflen, "CCM - Bad input parameters to function" );
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200597 if( use_ret == -(POLARSSL_ERR_CCM_AUTH_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000598 polarssl_snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200599#endif /* POLARSSL_CCM_C */
600
Paul Bakker880ac7e2011-11-27 14:50:49 +0000601#if defined(POLARSSL_CTR_DRBG_C)
602 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000603 polarssl_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
Paul Bakker880ac7e2011-11-27 14:50:49 +0000604 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000605 polarssl_snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
Paul Bakker880ac7e2011-11-27 14:50:49 +0000606 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000607 polarssl_snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000608 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000609 polarssl_snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
Paul Bakker880ac7e2011-11-27 14:50:49 +0000610#endif /* POLARSSL_CTR_DRBG_C */
611
Paul Bakker9d781402011-05-09 16:17:09 +0000612#if defined(POLARSSL_DES_C)
613 if( use_ret == -(POLARSSL_ERR_DES_INVALID_INPUT_LENGTH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000614 polarssl_snprintf( buf, buflen, "DES - The data input has an invalid length" );
Paul Bakker9d781402011-05-09 16:17:09 +0000615#endif /* POLARSSL_DES_C */
616
Paul Bakker6083fd22011-12-03 21:45:14 +0000617#if defined(POLARSSL_ENTROPY_C)
618 if( use_ret == -(POLARSSL_ERR_ENTROPY_SOURCE_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000619 polarssl_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
Paul Bakker6083fd22011-12-03 21:45:14 +0000620 if( use_ret == -(POLARSSL_ERR_ENTROPY_MAX_SOURCES) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000621 polarssl_snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
Paul Bakker43655f42011-12-15 20:11:16 +0000622 if( use_ret == -(POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000623 polarssl_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
Paul Bakker66ff70d2014-03-26 11:54:05 +0100624 if( use_ret == -(POLARSSL_ERR_ENTROPY_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000625 polarssl_snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
Paul Bakker6083fd22011-12-03 21:45:14 +0000626#endif /* POLARSSL_ENTROPY_C */
627
Paul Bakker030277a2012-04-17 12:24:26 +0000628#if defined(POLARSSL_GCM_C)
629 if( use_ret == -(POLARSSL_ERR_GCM_AUTH_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000630 polarssl_snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
Paul Bakkerd8ef1672012-04-18 14:17:32 +0000631 if( use_ret == -(POLARSSL_ERR_GCM_BAD_INPUT) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000632 polarssl_snprintf( buf, buflen, "GCM - Bad input parameters to function" );
Paul Bakker030277a2012-04-17 12:24:26 +0000633#endif /* POLARSSL_GCM_C */
634
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100635#if defined(POLARSSL_HMAC_DRBG_C)
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100636 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000637 polarssl_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100638 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000639 polarssl_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100640 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000641 polarssl_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
Manuel Pégourié-Gonnard9a6e93e2014-03-11 09:34:02 +0100642 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000643 polarssl_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100644#endif /* POLARSSL_HMAC_DRBG_C */
645
Paul Bakker69e095c2011-12-10 21:55:01 +0000646#if defined(POLARSSL_MD2_C)
647 if( use_ret == -(POLARSSL_ERR_MD2_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000648 polarssl_snprintf( buf, buflen, "MD2 - Read/write error in file" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000649#endif /* POLARSSL_MD2_C */
650
651#if defined(POLARSSL_MD4_C)
652 if( use_ret == -(POLARSSL_ERR_MD4_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000653 polarssl_snprintf( buf, buflen, "MD4 - Read/write error in file" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000654#endif /* POLARSSL_MD4_C */
655
656#if defined(POLARSSL_MD5_C)
657 if( use_ret == -(POLARSSL_ERR_MD5_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000658 polarssl_snprintf( buf, buflen, "MD5 - Read/write error in file" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000659#endif /* POLARSSL_MD5_C */
660
Paul Bakker9d781402011-05-09 16:17:09 +0000661#if defined(POLARSSL_NET_C)
662 if( use_ret == -(POLARSSL_ERR_NET_UNKNOWN_HOST) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000663 polarssl_snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
Paul Bakker9d781402011-05-09 16:17:09 +0000664 if( use_ret == -(POLARSSL_ERR_NET_SOCKET_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000665 polarssl_snprintf( buf, buflen, "NET - Failed to open a socket" );
Paul Bakker9d781402011-05-09 16:17:09 +0000666 if( use_ret == -(POLARSSL_ERR_NET_CONNECT_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000667 polarssl_snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000668 if( use_ret == -(POLARSSL_ERR_NET_BIND_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000669 polarssl_snprintf( buf, buflen, "NET - Binding of the socket failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000670 if( use_ret == -(POLARSSL_ERR_NET_LISTEN_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000671 polarssl_snprintf( buf, buflen, "NET - Could not listen on the socket" );
Paul Bakker9d781402011-05-09 16:17:09 +0000672 if( use_ret == -(POLARSSL_ERR_NET_ACCEPT_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000673 polarssl_snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
Paul Bakker9d781402011-05-09 16:17:09 +0000674 if( use_ret == -(POLARSSL_ERR_NET_RECV_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000675 polarssl_snprintf( buf, buflen, "NET - Reading information from the socket failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000676 if( use_ret == -(POLARSSL_ERR_NET_SEND_FAILED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000677 polarssl_snprintf( buf, buflen, "NET - Sending information through the socket failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000678 if( use_ret == -(POLARSSL_ERR_NET_CONN_RESET) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000679 polarssl_snprintf( buf, buflen, "NET - Connection was reset by peer" );
Paul Bakker831a7552011-05-18 13:32:51 +0000680 if( use_ret == -(POLARSSL_ERR_NET_WANT_READ) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000681 polarssl_snprintf( buf, buflen, "NET - Connection requires a read call" );
Paul Bakker831a7552011-05-18 13:32:51 +0000682 if( use_ret == -(POLARSSL_ERR_NET_WANT_WRITE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000683 polarssl_snprintf( buf, buflen, "NET - Connection requires a write call" );
Paul Bakker9d781402011-05-09 16:17:09 +0000684#endif /* POLARSSL_NET_C */
685
Paul Bakkerc70b9822013-04-07 22:00:46 +0200686#if defined(POLARSSL_OID_C)
687 if( use_ret == -(POLARSSL_ERR_OID_NOT_FOUND) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000688 polarssl_snprintf( buf, buflen, "OID - OID is not found" );
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100689 if( use_ret == -(POLARSSL_ERR_OID_BUF_TOO_SMALL) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000690 polarssl_snprintf( buf, buflen, "OID - output buffer is too small" );
Paul Bakkerc70b9822013-04-07 22:00:46 +0200691#endif /* POLARSSL_OID_C */
692
Paul Bakker9d781402011-05-09 16:17:09 +0000693#if defined(POLARSSL_PADLOCK_C)
694 if( use_ret == -(POLARSSL_ERR_PADLOCK_DATA_MISALIGNED) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000695 polarssl_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
Paul Bakker9d781402011-05-09 16:17:09 +0000696#endif /* POLARSSL_PADLOCK_C */
697
Paul Bakkerd14277d2012-09-26 15:19:05 +0000698#if defined(POLARSSL_PBKDF2_C)
699 if( use_ret == -(POLARSSL_ERR_PBKDF2_BAD_INPUT_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000700 polarssl_snprintf( buf, buflen, "PBKDF2 - Bad input parameters to function" );
Paul Bakkerd14277d2012-09-26 15:19:05 +0000701#endif /* POLARSSL_PBKDF2_C */
702
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100703#if defined(POLARSSL_RIPEMD160_C)
704 if( use_ret == -(POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000705 polarssl_snprintf( buf, buflen, "RIPEMD160 - Read/write error in file" );
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100706#endif /* POLARSSL_RIPEMD160_C */
707
Paul Bakker69e095c2011-12-10 21:55:01 +0000708#if defined(POLARSSL_SHA1_C)
709 if( use_ret == -(POLARSSL_ERR_SHA1_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000710 polarssl_snprintf( buf, buflen, "SHA1 - Read/write error in file" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000711#endif /* POLARSSL_SHA1_C */
712
Paul Bakker9e36f042013-06-30 14:34:05 +0200713#if defined(POLARSSL_SHA256_C)
714 if( use_ret == -(POLARSSL_ERR_SHA256_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000715 polarssl_snprintf( buf, buflen, "SHA256 - Read/write error in file" );
Paul Bakker9e36f042013-06-30 14:34:05 +0200716#endif /* POLARSSL_SHA256_C */
Paul Bakker69e095c2011-12-10 21:55:01 +0000717
Paul Bakker9e36f042013-06-30 14:34:05 +0200718#if defined(POLARSSL_SHA512_C)
719 if( use_ret == -(POLARSSL_ERR_SHA512_FILE_IO_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000720 polarssl_snprintf( buf, buflen, "SHA512 - Read/write error in file" );
Paul Bakker9e36f042013-06-30 14:34:05 +0200721#endif /* POLARSSL_SHA512_C */
Paul Bakker69e095c2011-12-10 21:55:01 +0000722
Paul Bakker2466d932013-09-28 14:40:38 +0200723#if defined(POLARSSL_THREADING_C)
724 if( use_ret == -(POLARSSL_ERR_THREADING_FEATURE_UNAVAILABLE) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000725 polarssl_snprintf( buf, buflen, "THREADING - The selected feature is not available" );
Paul Bakker2466d932013-09-28 14:40:38 +0200726 if( use_ret == -(POLARSSL_ERR_THREADING_BAD_INPUT_DATA) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000727 polarssl_snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
Paul Bakker2466d932013-09-28 14:40:38 +0200728 if( use_ret == -(POLARSSL_ERR_THREADING_MUTEX_ERROR) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000729 polarssl_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
Paul Bakker2466d932013-09-28 14:40:38 +0200730#endif /* POLARSSL_THREADING_C */
731
Paul Bakker9d781402011-05-09 16:17:09 +0000732#if defined(POLARSSL_XTEA_C)
733 if( use_ret == -(POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH) )
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000734 polarssl_snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
Paul Bakker9d781402011-05-09 16:17:09 +0000735#endif /* POLARSSL_XTEA_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200736 // END generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000737
738 if( strlen( buf ) != 0 )
739 return;
740
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +0000741 polarssl_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000742}
743
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200744#if defined(POLARSSL_ERROR_STRERROR_BC)
745void error_strerror( int ret, char *buf, size_t buflen )
746{
Paul Bakkerb887f112013-10-11 15:09:40 +0200747 polarssl_strerror( ret, buf, buflen );
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200748}
749#endif /* POLARSSL_ERROR_STRERROR_BC */
750
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100751#else /* POLARSSL_ERROR_C */
752
753#if defined(POLARSSL_ERROR_STRERROR_DUMMY)
754
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100755/*
756 * Provide an non-function in case POLARSSL_ERROR_C is not defined
757 */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200758void polarssl_strerror( int ret, char *buf, size_t buflen )
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100759{
760 ((void) ret);
761
762 if( buflen > 0 )
763 buf[0] = '\0';
764}
765
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200766#if defined(POLARSSL_ERROR_STRERROR_BC)
767void error_strerror( int ret, char *buf, size_t buflen )
768{
Paul Bakkerb887f112013-10-11 15:09:40 +0200769 polarssl_strerror( ret, buf, buflen );
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200770}
771#endif /* POLARSSL_ERROR_STRERROR_BC */
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100772#endif /* POLARSSL_ERROR_STRERROR_DUMMY */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200773
Paul Bakker9a736322012-11-14 12:39:52 +0000774#endif /* POLARSSL_ERROR_C */