blob: 1a57ee9dadc5d791ae05de949478cd15333bade2 [file] [log] [blame]
Paul Bakker9d781402011-05-09 16:17:09 +00001/*
2 * Error message information
3 *
Paul Bakker2ca1dc82014-04-30 17:01:25 +02004 * Copyright (C) 2006-2014, Brainspark B.V.
Paul Bakker9d781402011-05-09 16:17:09 +00005 *
6 * This file is part of PolarSSL (http://www.polarssl.org)
7 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
8 *
9 * All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 */
25
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020026#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker9d781402011-05-09 16:17:09 +000027#include "polarssl/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020028#else
29#include POLARSSL_CONFIG_FILE
30#endif
Paul Bakker9d781402011-05-09 16:17:09 +000031
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020032#if defined(POLARSSL_ERROR_C) || defined(POLARSSL_ERROR_STRERROR_DUMMY)
Paul Bakker3c2122f2013-06-24 19:03:14 +020033#include "polarssl/error.h"
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020034#endif
35
36#if defined(POLARSSL_ERROR_C)
Paul Bakker3c2122f2013-06-24 19:03:14 +020037
Paul Bakker9d781402011-05-09 16:17:09 +000038#if defined(POLARSSL_AES_C)
39#include "polarssl/aes.h"
40#endif
41
42#if defined(POLARSSL_BASE64_C)
43#include "polarssl/base64.h"
44#endif
45
46#if defined(POLARSSL_BIGNUM_C)
47#include "polarssl/bignum.h"
48#endif
49
Paul Bakker83f00bb2012-07-04 11:08:50 +000050#if defined(POLARSSL_BLOWFISH_C)
51#include "polarssl/blowfish.h"
52#endif
53
Paul Bakker9d781402011-05-09 16:17:09 +000054#if defined(POLARSSL_CAMELLIA_C)
55#include "polarssl/camellia.h"
56#endif
57
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +020058#if defined(POLARSSL_CCM_C)
59#include "polarssl/ccm.h"
60#endif
61
Paul Bakkerff61a782011-06-09 15:42:02 +000062#if defined(POLARSSL_CIPHER_C)
63#include "polarssl/cipher.h"
64#endif
65
Paul Bakker880ac7e2011-11-27 14:50:49 +000066#if defined(POLARSSL_CTR_DRBG_C)
67#include "polarssl/ctr_drbg.h"
68#endif
69
Paul Bakker9d781402011-05-09 16:17:09 +000070#if defined(POLARSSL_DES_C)
71#include "polarssl/des.h"
72#endif
73
74#if defined(POLARSSL_DHM_C)
75#include "polarssl/dhm.h"
76#endif
77
Paul Bakkercf4365f2013-01-16 17:00:43 +010078#if defined(POLARSSL_ECP_C)
79#include "polarssl/ecp.h"
80#endif
81
Paul Bakker6083fd22011-12-03 21:45:14 +000082#if defined(POLARSSL_ENTROPY_C)
83#include "polarssl/entropy.h"
84#endif
85
Paul Bakker030277a2012-04-17 12:24:26 +000086#if defined(POLARSSL_GCM_C)
87#include "polarssl/gcm.h"
88#endif
89
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010090#if defined(POLARSSL_HMAC_DRBG_C)
91#include "polarssl/hmac_drbg.h"
92#endif
93
Paul Bakker9d781402011-05-09 16:17:09 +000094#if defined(POLARSSL_MD_C)
95#include "polarssl/md.h"
96#endif
97
Paul Bakker69e095c2011-12-10 21:55:01 +000098#if defined(POLARSSL_MD2_C)
99#include "polarssl/md2.h"
100#endif
101
102#if defined(POLARSSL_MD4_C)
103#include "polarssl/md4.h"
104#endif
105
106#if defined(POLARSSL_MD5_C)
107#include "polarssl/md5.h"
108#endif
109
Paul Bakker9d781402011-05-09 16:17:09 +0000110#if defined(POLARSSL_NET_C)
111#include "polarssl/net.h"
112#endif
113
Paul Bakkerc70b9822013-04-07 22:00:46 +0200114#if defined(POLARSSL_OID_C)
115#include "polarssl/oid.h"
116#endif
117
Paul Bakker9d781402011-05-09 16:17:09 +0000118#if defined(POLARSSL_PADLOCK_C)
119#include "polarssl/padlock.h"
120#endif
121
Paul Bakkerd14277d2012-09-26 15:19:05 +0000122#if defined(POLARSSL_PBKDF2_C)
123#include "polarssl/pbkdf2.h"
124#endif
125
Paul Bakkercff68422013-09-15 20:43:33 +0200126#if defined(POLARSSL_PEM_PARSE_C) || defined(POLARSSL_PEM_WRITE_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000127#include "polarssl/pem.h"
128#endif
129
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200130#if defined(POLARSSL_PK_C)
131#include "polarssl/pk.h"
132#endif
133
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200134#if defined(POLARSSL_PKCS12_C)
135#include "polarssl/pkcs12.h"
136#endif
137
Paul Bakkerb0c19a42013-06-24 19:26:38 +0200138#if defined(POLARSSL_PKCS5_C)
139#include "polarssl/pkcs5.h"
140#endif
141
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100142#if defined(POLARSSL_RIPEMD160_C)
143#include "polarssl/ripemd160.h"
144#endif
145
Paul Bakker9d781402011-05-09 16:17:09 +0000146#if defined(POLARSSL_RSA_C)
147#include "polarssl/rsa.h"
148#endif
149
Paul Bakker69e095c2011-12-10 21:55:01 +0000150#if defined(POLARSSL_SHA1_C)
151#include "polarssl/sha1.h"
152#endif
153
Paul Bakker9e36f042013-06-30 14:34:05 +0200154#if defined(POLARSSL_SHA256_C)
Paul Bakkerd2681d82013-06-30 14:49:12 +0200155#include "polarssl/sha256.h"
Paul Bakker69e095c2011-12-10 21:55:01 +0000156#endif
157
Paul Bakker9e36f042013-06-30 14:34:05 +0200158#if defined(POLARSSL_SHA512_C)
Paul Bakkerd2681d82013-06-30 14:49:12 +0200159#include "polarssl/sha512.h"
Paul Bakker69e095c2011-12-10 21:55:01 +0000160#endif
161
Paul Bakker831a7552011-05-18 13:32:51 +0000162#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000163#include "polarssl/ssl.h"
164#endif
165
Paul Bakker2466d932013-09-28 14:40:38 +0200166#if defined(POLARSSL_THREADING_C)
167#include "polarssl/threading.h"
168#endif
169
Paul Bakker36713e82013-09-17 13:25:29 +0200170#if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000171#include "polarssl/x509.h"
172#endif
173
174#if defined(POLARSSL_XTEA_C)
175#include "polarssl/xtea.h"
176#endif
177
178
179#include <string.h>
180
Paul Bakker6edcd412013-10-29 15:22:54 +0100181#if defined(_MSC_VER) && !defined snprintf && !defined(EFIX64) && \
182 !defined(EFI32)
Paul Bakkerdceecd82011-11-15 16:38:34 +0000183#define snprintf _snprintf
184#endif
185
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200186void polarssl_strerror( int ret, char *buf, size_t buflen )
Paul Bakker9d781402011-05-09 16:17:09 +0000187{
188 size_t len;
189 int use_ret;
190
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200191 if( buflen == 0 )
192 return;
193
Paul Bakker9d781402011-05-09 16:17:09 +0000194 memset( buf, 0x00, buflen );
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200195 /* Reduce buflen to make sure MSVC _snprintf() ends with \0 as well */
196 buflen -= 1;
197
Paul Bakker9d781402011-05-09 16:17:09 +0000198 if( ret < 0 )
199 ret = -ret;
200
201 if( ret & 0xFF80 )
202 {
203 use_ret = ret & 0xFF80;
204
205 // High level error codes
206 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200207 // BEGIN generated code
Paul Bakkerff61a782011-06-09 15:42:02 +0000208#if defined(POLARSSL_CIPHER_C)
209 if( use_ret == -(POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE) )
210 snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
211 if( use_ret == -(POLARSSL_ERR_CIPHER_BAD_INPUT_DATA) )
212 snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
213 if( use_ret == -(POLARSSL_ERR_CIPHER_ALLOC_FAILED) )
214 snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
215 if( use_ret == -(POLARSSL_ERR_CIPHER_INVALID_PADDING) )
216 snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
217 if( use_ret == -(POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
218 snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
Manuel Pégourié-Gonnard4fee79b2013-09-19 18:09:14 +0200219 if( use_ret == -(POLARSSL_ERR_CIPHER_AUTH_FAILED) )
220 snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
Paul Bakkerff61a782011-06-09 15:42:02 +0000221#endif /* POLARSSL_CIPHER_C */
222
Paul Bakker9d781402011-05-09 16:17:09 +0000223#if defined(POLARSSL_DHM_C)
224 if( use_ret == -(POLARSSL_ERR_DHM_BAD_INPUT_DATA) )
225 snprintf( buf, buflen, "DHM - Bad input parameters to function" );
226 if( use_ret == -(POLARSSL_ERR_DHM_READ_PARAMS_FAILED) )
227 snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
228 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PARAMS_FAILED) )
229 snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
230 if( use_ret == -(POLARSSL_ERR_DHM_READ_PUBLIC_FAILED) )
231 snprintf( buf, buflen, "DHM - Reading of the public values failed" );
232 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PUBLIC_FAILED) )
Paul Bakker05ef8352012-05-08 09:17:57 +0000233 snprintf( buf, buflen, "DHM - Making of the public value failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000234 if( use_ret == -(POLARSSL_ERR_DHM_CALC_SECRET_FAILED) )
235 snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
Paul Bakker40ce79f2013-09-15 17:43:54 +0200236 if( use_ret == -(POLARSSL_ERR_DHM_INVALID_FORMAT) )
237 snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
238 if( use_ret == -(POLARSSL_ERR_DHM_MALLOC_FAILED) )
239 snprintf( buf, buflen, "DHM - Allocation of memory failed" );
240 if( use_ret == -(POLARSSL_ERR_DHM_FILE_IO_ERROR) )
241 snprintf( buf, buflen, "DHM - Read/write of file failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000242#endif /* POLARSSL_DHM_C */
243
Paul Bakkercf4365f2013-01-16 17:00:43 +0100244#if defined(POLARSSL_ECP_C)
245 if( use_ret == -(POLARSSL_ERR_ECP_BAD_INPUT_DATA) )
246 snprintf( buf, buflen, "ECP - Bad input parameters to function" );
Paul Bakker41c83d32013-03-20 14:39:14 +0100247 if( use_ret == -(POLARSSL_ERR_ECP_BUFFER_TOO_SMALL) )
248 snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
Paul Bakkerfd3eac52013-06-29 23:31:33 +0200249 if( use_ret == -(POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE) )
250 snprintf( buf, buflen, "ECP - Requested curve not available" );
Paul Bakker1a7550a2013-09-15 13:01:22 +0200251 if( use_ret == -(POLARSSL_ERR_ECP_VERIFY_FAILED) )
252 snprintf( buf, buflen, "ECP - The signature is not valid" );
Manuel Pégourié-Gonnard456d3b92013-09-16 18:04:38 +0200253 if( use_ret == -(POLARSSL_ERR_ECP_MALLOC_FAILED) )
254 snprintf( buf, buflen, "ECP - Memory allocation failed" );
255 if( use_ret == -(POLARSSL_ERR_ECP_RANDOM_FAILED) )
256 snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
257 if( use_ret == -(POLARSSL_ERR_ECP_INVALID_KEY) )
258 snprintf( buf, buflen, "ECP - Invalid private or public key" );
Manuel Pégourié-Gonnard35e95dd2014-04-08 12:17:41 +0200259 if( use_ret == -(POLARSSL_ERR_ECP_SIG_LEN_MISMATCH) )
260 snprintf( buf, buflen, "ECP - Signature is valid but shorter than the user-supplied length" );
Paul Bakkercf4365f2013-01-16 17:00:43 +0100261#endif /* POLARSSL_ECP_C */
262
Paul Bakker9d781402011-05-09 16:17:09 +0000263#if defined(POLARSSL_MD_C)
264 if( use_ret == -(POLARSSL_ERR_MD_FEATURE_UNAVAILABLE) )
265 snprintf( buf, buflen, "MD - The selected feature is not available" );
Paul Bakker9c021ad2011-06-09 15:55:11 +0000266 if( use_ret == -(POLARSSL_ERR_MD_BAD_INPUT_DATA) )
267 snprintf( buf, buflen, "MD - Bad input parameters to function" );
268 if( use_ret == -(POLARSSL_ERR_MD_ALLOC_FAILED) )
269 snprintf( buf, buflen, "MD - Failed to allocate memory" );
Paul Bakker8913f822012-01-14 18:07:41 +0000270 if( use_ret == -(POLARSSL_ERR_MD_FILE_IO_ERROR) )
271 snprintf( buf, buflen, "MD - Opening or reading of file failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000272#endif /* POLARSSL_MD_C */
273
Paul Bakkercff68422013-09-15 20:43:33 +0200274#if defined(POLARSSL_PEM_PARSE_C) || defined(POLARSSL_PEM_WRITE_C)
Paul Bakker00b28602013-06-24 13:02:41 +0200275 if( use_ret == -(POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
276 snprintf( buf, buflen, "PEM - No PEM header or footer found" );
Paul Bakker9d781402011-05-09 16:17:09 +0000277 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_DATA) )
278 snprintf( buf, buflen, "PEM - PEM string is not as expected" );
279 if( use_ret == -(POLARSSL_ERR_PEM_MALLOC_FAILED) )
280 snprintf( buf, buflen, "PEM - Failed to allocate memory" );
281 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_ENC_IV) )
282 snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
283 if( use_ret == -(POLARSSL_ERR_PEM_UNKNOWN_ENC_ALG) )
284 snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
285 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_REQUIRED) )
286 snprintf( buf, buflen, "PEM - Private key password can't be empty" );
287 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_MISMATCH) )
288 snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
289 if( use_ret == -(POLARSSL_ERR_PEM_FEATURE_UNAVAILABLE) )
290 snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
Paul Bakker00b28602013-06-24 13:02:41 +0200291 if( use_ret == -(POLARSSL_ERR_PEM_BAD_INPUT_DATA) )
292 snprintf( buf, buflen, "PEM - Bad input parameters to function" );
Paul Bakkercff68422013-09-15 20:43:33 +0200293#endif /* POLARSSL_PEM_PARSE_C || POLARSSL_PEM_WRITE_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000294
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200295#if defined(POLARSSL_PK_C)
296 if( use_ret == -(POLARSSL_ERR_PK_MALLOC_FAILED) )
297 snprintf( buf, buflen, "PK - Memory alloation failed" );
Manuel Pégourié-Gonnard374e4b82013-07-09 10:21:34 +0200298 if( use_ret == -(POLARSSL_ERR_PK_TYPE_MISMATCH) )
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200299 snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
Manuel Pégourié-Gonnard15699382013-08-14 19:22:48 +0200300 if( use_ret == -(POLARSSL_ERR_PK_BAD_INPUT_DATA) )
301 snprintf( buf, buflen, "PK - Bad input parameters to function" );
Paul Bakker1a7550a2013-09-15 13:01:22 +0200302 if( use_ret == -(POLARSSL_ERR_PK_FILE_IO_ERROR) )
303 snprintf( buf, buflen, "PK - Read/write of file failed" );
304 if( use_ret == -(POLARSSL_ERR_PK_KEY_INVALID_VERSION) )
305 snprintf( buf, buflen, "PK - Unsupported key version" );
306 if( use_ret == -(POLARSSL_ERR_PK_KEY_INVALID_FORMAT) )
307 snprintf( buf, buflen, "PK - Invalid key tag or value" );
308 if( use_ret == -(POLARSSL_ERR_PK_UNKNOWN_PK_ALG) )
309 snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
310 if( use_ret == -(POLARSSL_ERR_PK_PASSWORD_REQUIRED) )
311 snprintf( buf, buflen, "PK - Private key password can't be empty" );
312 if( use_ret == -(POLARSSL_ERR_PK_PASSWORD_MISMATCH) )
313 snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
314 if( use_ret == -(POLARSSL_ERR_PK_INVALID_PUBKEY) )
315 snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
316 if( use_ret == -(POLARSSL_ERR_PK_INVALID_ALG) )
317 snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
318 if( use_ret == -(POLARSSL_ERR_PK_UNKNOWN_NAMED_CURVE) )
319 snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
320 if( use_ret == -(POLARSSL_ERR_PK_FEATURE_UNAVAILABLE) )
321 snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
Manuel Pégourié-Gonnard2abed842014-04-08 12:40:15 +0200322 if( use_ret == -(POLARSSL_ERR_PK_SIG_LEN_MISMATCH) )
323 snprintf( buf, buflen, "PK - The signature is valid but its length is less than expected" );
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200324#endif /* POLARSSL_PK_C */
325
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200326#if defined(POLARSSL_PKCS12_C)
327 if( use_ret == -(POLARSSL_ERR_PKCS12_BAD_INPUT_DATA) )
328 snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
329 if( use_ret == -(POLARSSL_ERR_PKCS12_FEATURE_UNAVAILABLE) )
330 snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
331 if( use_ret == -(POLARSSL_ERR_PKCS12_PBE_INVALID_FORMAT) )
332 snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
Paul Bakker38b50d72013-06-24 19:33:27 +0200333 if( use_ret == -(POLARSSL_ERR_PKCS12_PASSWORD_MISMATCH) )
334 snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200335#endif /* POLARSSL_PKCS12_C */
336
Paul Bakker28144de2013-06-24 19:28:55 +0200337#if defined(POLARSSL_PKCS5_C)
338 if( use_ret == -(POLARSSL_ERR_PKCS5_BAD_INPUT_DATA) )
339 snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
340 if( use_ret == -(POLARSSL_ERR_PKCS5_INVALID_FORMAT) )
341 snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
342 if( use_ret == -(POLARSSL_ERR_PKCS5_FEATURE_UNAVAILABLE) )
343 snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
344 if( use_ret == -(POLARSSL_ERR_PKCS5_PASSWORD_MISMATCH) )
345 snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
346#endif /* POLARSSL_PKCS5_C */
347
Paul Bakker9d781402011-05-09 16:17:09 +0000348#if defined(POLARSSL_RSA_C)
349 if( use_ret == -(POLARSSL_ERR_RSA_BAD_INPUT_DATA) )
350 snprintf( buf, buflen, "RSA - Bad input parameters to function" );
351 if( use_ret == -(POLARSSL_ERR_RSA_INVALID_PADDING) )
352 snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
353 if( use_ret == -(POLARSSL_ERR_RSA_KEY_GEN_FAILED) )
354 snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
355 if( use_ret == -(POLARSSL_ERR_RSA_KEY_CHECK_FAILED) )
356 snprintf( buf, buflen, "RSA - Key failed to pass the libraries validity check" );
357 if( use_ret == -(POLARSSL_ERR_RSA_PUBLIC_FAILED) )
358 snprintf( buf, buflen, "RSA - The public key operation failed" );
359 if( use_ret == -(POLARSSL_ERR_RSA_PRIVATE_FAILED) )
360 snprintf( buf, buflen, "RSA - The private key operation failed" );
361 if( use_ret == -(POLARSSL_ERR_RSA_VERIFY_FAILED) )
362 snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
363 if( use_ret == -(POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE) )
364 snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
365 if( use_ret == -(POLARSSL_ERR_RSA_RNG_FAILED) )
366 snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
367#endif /* POLARSSL_RSA_C */
368
Paul Bakker831a7552011-05-18 13:32:51 +0000369#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000370 if( use_ret == -(POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE) )
371 snprintf( buf, buflen, "SSL - The requested feature is not available" );
372 if( use_ret == -(POLARSSL_ERR_SSL_BAD_INPUT_DATA) )
373 snprintf( buf, buflen, "SSL - Bad input parameters to function" );
374 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_MAC) )
375 snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
376 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_RECORD) )
377 snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
Paul Bakker831a7552011-05-18 13:32:51 +0000378 if( use_ret == -(POLARSSL_ERR_SSL_CONN_EOF) )
379 snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
Paul Bakker9d781402011-05-09 16:17:09 +0000380 if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_CIPHER) )
381 snprintf( buf, buflen, "SSL - An unknown cipher was received" );
382 if( use_ret == -(POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN) )
383 snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
Paul Bakkera9a028e2013-11-21 17:31:06 +0100384 if( use_ret == -(POLARSSL_ERR_SSL_NO_RNG) )
385 snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
Paul Bakker9d781402011-05-09 16:17:09 +0000386 if( use_ret == -(POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE) )
387 snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
388 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE) )
Manuel Pégourié-Gonnard11c91922015-01-22 13:21:29 +0000389 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 +0000390 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED) )
391 snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
392 if( use_ret == -(POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED) )
Paul Bakker73a899a2013-04-17 19:11:36 +0200393 snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000394 if( use_ret == -(POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED) )
395 snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
396 if( use_ret == -(POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE) )
397 snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
398 if( use_ret == -(POLARSSL_ERR_SSL_FATAL_ALERT_MESSAGE) )
Paul Bakker3aac1da2012-05-08 13:12:27 +0000399 {
Paul Bakker9d781402011-05-09 16:17:09 +0000400 snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
Paul Bakker3aac1da2012-05-08 13:12:27 +0000401 return;
402 }
Paul Bakker9d781402011-05-09 16:17:09 +0000403 if( use_ret == -(POLARSSL_ERR_SSL_PEER_VERIFY_FAILED) )
404 snprintf( buf, buflen, "SSL - Verification of our peer failed" );
405 if( use_ret == -(POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) )
406 snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
407 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO) )
408 snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
409 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO) )
410 snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
411 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE) )
412 snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
413 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
414 snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
415 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
416 snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
417 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
418 snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
419 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
420 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
Paul Bakker41c83d32013-03-20 14:39:14 +0100421 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
422 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
423 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
424 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
Paul Bakker9d781402011-05-09 16:17:09 +0000425 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
426 snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
427 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
428 snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
429 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_FINISHED) )
430 snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000431 if( use_ret == -(POLARSSL_ERR_SSL_MALLOC_FAILED) )
432 snprintf( buf, buflen, "SSL - Memory allocation failed" );
Paul Bakker05ef8352012-05-08 09:17:57 +0000433 if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FAILED) )
434 snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
435 if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
436 snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
Paul Bakker83f00bb2012-07-04 11:08:50 +0000437 if( use_ret == -(POLARSSL_ERR_SSL_COMPRESSION_FAILED) )
438 snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
Paul Bakker1d29fb52012-09-28 13:28:45 +0000439 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
440 snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
Manuel Pégourié-Gonnarda5cc6022013-07-31 12:58:16 +0200441 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
442 snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
Paul Bakker606b4ba2013-08-14 16:52:14 +0200443 if( use_ret == -(POLARSSL_ERR_SSL_SESSION_TICKET_EXPIRED) )
444 snprintf( buf, buflen, "SSL - Session ticket has expired" );
Manuel Pégourié-Gonnardb3d91872013-08-14 15:56:19 +0200445 if( use_ret == -(POLARSSL_ERR_SSL_PK_TYPE_MISMATCH) )
446 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 +0200447 if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_IDENTITY) )
Paul Bakker75342a62014-04-08 17:35:40 +0200448 snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
Manuel Pégourié-Gonnarda8a25ae2013-10-27 13:48:15 +0100449 if( use_ret == -(POLARSSL_ERR_SSL_INTERNAL_ERROR) )
450 snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
Manuel Pégourié-Gonnard83cdffc2014-03-10 21:20:29 +0100451 if( use_ret == -(POLARSSL_ERR_SSL_COUNTER_WRAPPING) )
452 snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
Manuel Pégourié-Gonnard65919622014-08-19 12:50:30 +0200453 if( use_ret == -(POLARSSL_ERR_SSL_WAITING_SERVER_HELLO_RENEGO) )
454 snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" );
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +0100455 if( use_ret == -(POLARSSL_ERR_SSL_NO_USABLE_CIPHERSUITE) )
456 snprintf( buf, buflen, "SSL - None of the common ciphersuites is usable (eg, no suitable certificate)" );
Paul Bakker831a7552011-05-18 13:32:51 +0000457#endif /* POLARSSL_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000458
Paul Bakker36713e82013-09-17 13:25:29 +0200459#if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000460 if( use_ret == -(POLARSSL_ERR_X509_FEATURE_UNAVAILABLE) )
461 snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
Paul Bakker51876562013-09-17 14:36:05 +0200462 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_OID) )
463 snprintf( buf, buflen, "X509 - Requested OID is unknown" );
464 if( use_ret == -(POLARSSL_ERR_X509_INVALID_FORMAT) )
465 snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
466 if( use_ret == -(POLARSSL_ERR_X509_INVALID_VERSION) )
467 snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
468 if( use_ret == -(POLARSSL_ERR_X509_INVALID_SERIAL) )
Paul Bakker9d781402011-05-09 16:17:09 +0000469 snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200470 if( use_ret == -(POLARSSL_ERR_X509_INVALID_ALG) )
Paul Bakker9d781402011-05-09 16:17:09 +0000471 snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200472 if( use_ret == -(POLARSSL_ERR_X509_INVALID_NAME) )
Paul Bakker9d781402011-05-09 16:17:09 +0000473 snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200474 if( use_ret == -(POLARSSL_ERR_X509_INVALID_DATE) )
Paul Bakker9d781402011-05-09 16:17:09 +0000475 snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200476 if( use_ret == -(POLARSSL_ERR_X509_INVALID_SIGNATURE) )
Paul Bakker9d781402011-05-09 16:17:09 +0000477 snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200478 if( use_ret == -(POLARSSL_ERR_X509_INVALID_EXTENSIONS) )
Paul Bakker9d781402011-05-09 16:17:09 +0000479 snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200480 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_VERSION) )
481 snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
482 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_SIG_ALG) )
Paul Bakker9d781402011-05-09 16:17:09 +0000483 snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
Paul Bakker51876562013-09-17 14:36:05 +0200484 if( use_ret == -(POLARSSL_ERR_X509_SIG_MISMATCH) )
Paul Bakker6db455e2013-09-18 17:29:31 +0200485 snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::x509_crt sig_oid)" );
Paul Bakker9d781402011-05-09 16:17:09 +0000486 if( use_ret == -(POLARSSL_ERR_X509_CERT_VERIFY_FAILED) )
487 snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
Paul Bakker6c0ceb32011-12-04 12:24:18 +0000488 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT) )
489 snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
Paul Bakker51876562013-09-17 14:36:05 +0200490 if( use_ret == -(POLARSSL_ERR_X509_BAD_INPUT_DATA) )
Paul Bakker69e095c2011-12-10 21:55:01 +0000491 snprintf( buf, buflen, "X509 - Input invalid" );
492 if( use_ret == -(POLARSSL_ERR_X509_MALLOC_FAILED) )
493 snprintf( buf, buflen, "X509 - Allocation of memory failed" );
494 if( use_ret == -(POLARSSL_ERR_X509_FILE_IO_ERROR) )
495 snprintf( buf, buflen, "X509 - Read/write of file failed" );
Paul Bakker36713e82013-09-17 13:25:29 +0200496#endif /* POLARSSL_X509_USE,X509_CREATE_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200497 // END generated code
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200498
Paul Bakker9d781402011-05-09 16:17:09 +0000499 if( strlen( buf ) == 0 )
500 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
501 }
502
503 use_ret = ret & ~0xFF80;
504
505 if( use_ret == 0 )
506 return;
507
508 // If high level code is present, make a concatenation between both
509 // error strings.
510 //
511 len = strlen( buf );
512
513 if( len > 0 )
514 {
515 if( buflen - len < 5 )
516 return;
517
518 snprintf( buf + len, buflen - len, " : " );
519
520 buf += len + 3;
521 buflen -= len + 3;
522 }
523
524 // Low level error codes
525 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200526 // BEGIN generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000527#if defined(POLARSSL_AES_C)
528 if( use_ret == -(POLARSSL_ERR_AES_INVALID_KEY_LENGTH) )
529 snprintf( buf, buflen, "AES - Invalid key length" );
530 if( use_ret == -(POLARSSL_ERR_AES_INVALID_INPUT_LENGTH) )
531 snprintf( buf, buflen, "AES - Invalid data input length" );
532#endif /* POLARSSL_AES_C */
533
Paul Bakkerdceecd82011-11-15 16:38:34 +0000534#if defined(POLARSSL_ASN1_PARSE_C)
535 if( use_ret == -(POLARSSL_ERR_ASN1_OUT_OF_DATA) )
536 snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
537 if( use_ret == -(POLARSSL_ERR_ASN1_UNEXPECTED_TAG) )
538 snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
539 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_LENGTH) )
540 snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
541 if( use_ret == -(POLARSSL_ERR_ASN1_LENGTH_MISMATCH) )
542 snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
543 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_DATA) )
544 snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000545 if( use_ret == -(POLARSSL_ERR_ASN1_MALLOC_FAILED) )
546 snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000547 if( use_ret == -(POLARSSL_ERR_ASN1_BUF_TOO_SMALL) )
548 snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
Paul Bakkerdceecd82011-11-15 16:38:34 +0000549#endif /* POLARSSL_ASN1_PARSE_C */
550
Paul Bakker9d781402011-05-09 16:17:09 +0000551#if defined(POLARSSL_BASE64_C)
552 if( use_ret == -(POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) )
553 snprintf( buf, buflen, "BASE64 - Output buffer too small" );
554 if( use_ret == -(POLARSSL_ERR_BASE64_INVALID_CHARACTER) )
555 snprintf( buf, buflen, "BASE64 - Invalid character in input" );
556#endif /* POLARSSL_BASE64_C */
557
558#if defined(POLARSSL_BIGNUM_C)
559 if( use_ret == -(POLARSSL_ERR_MPI_FILE_IO_ERROR) )
560 snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
561 if( use_ret == -(POLARSSL_ERR_MPI_BAD_INPUT_DATA) )
562 snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
563 if( use_ret == -(POLARSSL_ERR_MPI_INVALID_CHARACTER) )
564 snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
565 if( use_ret == -(POLARSSL_ERR_MPI_BUFFER_TOO_SMALL) )
Paul Bakker69e095c2011-12-10 21:55:01 +0000566 snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
Paul Bakker9d781402011-05-09 16:17:09 +0000567 if( use_ret == -(POLARSSL_ERR_MPI_NEGATIVE_VALUE) )
568 snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
569 if( use_ret == -(POLARSSL_ERR_MPI_DIVISION_BY_ZERO) )
570 snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
571 if( use_ret == -(POLARSSL_ERR_MPI_NOT_ACCEPTABLE) )
572 snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000573 if( use_ret == -(POLARSSL_ERR_MPI_MALLOC_FAILED) )
574 snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000575#endif /* POLARSSL_BIGNUM_C */
576
Paul Bakker83f00bb2012-07-04 11:08:50 +0000577#if defined(POLARSSL_BLOWFISH_C)
578 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
579 snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
580 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
581 snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
582#endif /* POLARSSL_BLOWFISH_C */
583
Paul Bakker9d781402011-05-09 16:17:09 +0000584#if defined(POLARSSL_CAMELLIA_C)
585 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
586 snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
587 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
588 snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
589#endif /* POLARSSL_CAMELLIA_C */
590
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200591#if defined(POLARSSL_CCM_C)
592 if( use_ret == -(POLARSSL_ERR_CCM_BAD_INPUT) )
593 snprintf( buf, buflen, "CCM - Bad input parameters to function" );
594 if( use_ret == -(POLARSSL_ERR_CCM_AUTH_FAILED) )
595 snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
596#endif /* POLARSSL_CCM_C */
597
Paul Bakker880ac7e2011-11-27 14:50:49 +0000598#if defined(POLARSSL_CTR_DRBG_C)
599 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
600 snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
601 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
602 snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
603 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG) )
604 snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000605 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR) )
606 snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
Paul Bakker880ac7e2011-11-27 14:50:49 +0000607#endif /* POLARSSL_CTR_DRBG_C */
608
Paul Bakker9d781402011-05-09 16:17:09 +0000609#if defined(POLARSSL_DES_C)
610 if( use_ret == -(POLARSSL_ERR_DES_INVALID_INPUT_LENGTH) )
611 snprintf( buf, buflen, "DES - The data input has an invalid length" );
612#endif /* POLARSSL_DES_C */
613
Paul Bakker6083fd22011-12-03 21:45:14 +0000614#if defined(POLARSSL_ENTROPY_C)
615 if( use_ret == -(POLARSSL_ERR_ENTROPY_SOURCE_FAILED) )
616 snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
617 if( use_ret == -(POLARSSL_ERR_ENTROPY_MAX_SOURCES) )
618 snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
Paul Bakker43655f42011-12-15 20:11:16 +0000619 if( use_ret == -(POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED) )
620 snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
Paul Bakker66ff70d2014-03-26 11:54:05 +0100621 if( use_ret == -(POLARSSL_ERR_ENTROPY_FILE_IO_ERROR) )
622 snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
Paul Bakker6083fd22011-12-03 21:45:14 +0000623#endif /* POLARSSL_ENTROPY_C */
624
Paul Bakker030277a2012-04-17 12:24:26 +0000625#if defined(POLARSSL_GCM_C)
626 if( use_ret == -(POLARSSL_ERR_GCM_AUTH_FAILED) )
627 snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
Paul Bakkerd8ef1672012-04-18 14:17:32 +0000628 if( use_ret == -(POLARSSL_ERR_GCM_BAD_INPUT) )
629 snprintf( buf, buflen, "GCM - Bad input parameters to function" );
Paul Bakker030277a2012-04-17 12:24:26 +0000630#endif /* POLARSSL_GCM_C */
631
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100632#if defined(POLARSSL_HMAC_DRBG_C)
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100633 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
634 snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
635 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
636 snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
637 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_FILE_IO_ERROR) )
638 snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
Manuel Pégourié-Gonnard9a6e93e2014-03-11 09:34:02 +0100639 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
640 snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100641#endif /* POLARSSL_HMAC_DRBG_C */
642
Paul Bakker69e095c2011-12-10 21:55:01 +0000643#if defined(POLARSSL_MD2_C)
644 if( use_ret == -(POLARSSL_ERR_MD2_FILE_IO_ERROR) )
645 snprintf( buf, buflen, "MD2 - Read/write error in file" );
646#endif /* POLARSSL_MD2_C */
647
648#if defined(POLARSSL_MD4_C)
649 if( use_ret == -(POLARSSL_ERR_MD4_FILE_IO_ERROR) )
650 snprintf( buf, buflen, "MD4 - Read/write error in file" );
651#endif /* POLARSSL_MD4_C */
652
653#if defined(POLARSSL_MD5_C)
654 if( use_ret == -(POLARSSL_ERR_MD5_FILE_IO_ERROR) )
655 snprintf( buf, buflen, "MD5 - Read/write error in file" );
656#endif /* POLARSSL_MD5_C */
657
Paul Bakker9d781402011-05-09 16:17:09 +0000658#if defined(POLARSSL_NET_C)
659 if( use_ret == -(POLARSSL_ERR_NET_UNKNOWN_HOST) )
660 snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
661 if( use_ret == -(POLARSSL_ERR_NET_SOCKET_FAILED) )
662 snprintf( buf, buflen, "NET - Failed to open a socket" );
663 if( use_ret == -(POLARSSL_ERR_NET_CONNECT_FAILED) )
664 snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
665 if( use_ret == -(POLARSSL_ERR_NET_BIND_FAILED) )
666 snprintf( buf, buflen, "NET - Binding of the socket failed" );
667 if( use_ret == -(POLARSSL_ERR_NET_LISTEN_FAILED) )
668 snprintf( buf, buflen, "NET - Could not listen on the socket" );
669 if( use_ret == -(POLARSSL_ERR_NET_ACCEPT_FAILED) )
670 snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
671 if( use_ret == -(POLARSSL_ERR_NET_RECV_FAILED) )
672 snprintf( buf, buflen, "NET - Reading information from the socket failed" );
673 if( use_ret == -(POLARSSL_ERR_NET_SEND_FAILED) )
674 snprintf( buf, buflen, "NET - Sending information through the socket failed" );
675 if( use_ret == -(POLARSSL_ERR_NET_CONN_RESET) )
676 snprintf( buf, buflen, "NET - Connection was reset by peer" );
Paul Bakker831a7552011-05-18 13:32:51 +0000677 if( use_ret == -(POLARSSL_ERR_NET_WANT_READ) )
678 snprintf( buf, buflen, "NET - Connection requires a read call" );
679 if( use_ret == -(POLARSSL_ERR_NET_WANT_WRITE) )
680 snprintf( buf, buflen, "NET - Connection requires a write call" );
Paul Bakker9d781402011-05-09 16:17:09 +0000681#endif /* POLARSSL_NET_C */
682
Paul Bakkerc70b9822013-04-07 22:00:46 +0200683#if defined(POLARSSL_OID_C)
684 if( use_ret == -(POLARSSL_ERR_OID_NOT_FOUND) )
685 snprintf( buf, buflen, "OID - OID is not found" );
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100686 if( use_ret == -(POLARSSL_ERR_OID_BUF_TOO_SMALL) )
687 snprintf( buf, buflen, "OID - output buffer is too small" );
Paul Bakkerc70b9822013-04-07 22:00:46 +0200688#endif /* POLARSSL_OID_C */
689
Paul Bakker9d781402011-05-09 16:17:09 +0000690#if defined(POLARSSL_PADLOCK_C)
691 if( use_ret == -(POLARSSL_ERR_PADLOCK_DATA_MISALIGNED) )
692 snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
693#endif /* POLARSSL_PADLOCK_C */
694
Paul Bakkerd14277d2012-09-26 15:19:05 +0000695#if defined(POLARSSL_PBKDF2_C)
696 if( use_ret == -(POLARSSL_ERR_PBKDF2_BAD_INPUT_DATA) )
697 snprintf( buf, buflen, "PBKDF2 - Bad input parameters to function" );
698#endif /* POLARSSL_PBKDF2_C */
699
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100700#if defined(POLARSSL_RIPEMD160_C)
701 if( use_ret == -(POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR) )
702 snprintf( buf, buflen, "RIPEMD160 - Read/write error in file" );
703#endif /* POLARSSL_RIPEMD160_C */
704
Paul Bakker69e095c2011-12-10 21:55:01 +0000705#if defined(POLARSSL_SHA1_C)
706 if( use_ret == -(POLARSSL_ERR_SHA1_FILE_IO_ERROR) )
707 snprintf( buf, buflen, "SHA1 - Read/write error in file" );
708#endif /* POLARSSL_SHA1_C */
709
Paul Bakker9e36f042013-06-30 14:34:05 +0200710#if defined(POLARSSL_SHA256_C)
711 if( use_ret == -(POLARSSL_ERR_SHA256_FILE_IO_ERROR) )
712 snprintf( buf, buflen, "SHA256 - Read/write error in file" );
713#endif /* POLARSSL_SHA256_C */
Paul Bakker69e095c2011-12-10 21:55:01 +0000714
Paul Bakker9e36f042013-06-30 14:34:05 +0200715#if defined(POLARSSL_SHA512_C)
716 if( use_ret == -(POLARSSL_ERR_SHA512_FILE_IO_ERROR) )
717 snprintf( buf, buflen, "SHA512 - Read/write error in file" );
718#endif /* POLARSSL_SHA512_C */
Paul Bakker69e095c2011-12-10 21:55:01 +0000719
Paul Bakker2466d932013-09-28 14:40:38 +0200720#if defined(POLARSSL_THREADING_C)
721 if( use_ret == -(POLARSSL_ERR_THREADING_FEATURE_UNAVAILABLE) )
722 snprintf( buf, buflen, "THREADING - The selected feature is not available" );
723 if( use_ret == -(POLARSSL_ERR_THREADING_BAD_INPUT_DATA) )
724 snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
725 if( use_ret == -(POLARSSL_ERR_THREADING_MUTEX_ERROR) )
726 snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
727#endif /* POLARSSL_THREADING_C */
728
Paul Bakker9d781402011-05-09 16:17:09 +0000729#if defined(POLARSSL_XTEA_C)
730 if( use_ret == -(POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH) )
731 snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
732#endif /* POLARSSL_XTEA_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200733 // END generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000734
735 if( strlen( buf ) != 0 )
736 return;
737
738 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
739}
740
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200741#if defined(POLARSSL_ERROR_STRERROR_BC)
742void error_strerror( int ret, char *buf, size_t buflen )
743{
Paul Bakkerb887f112013-10-11 15:09:40 +0200744 polarssl_strerror( ret, buf, buflen );
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200745}
746#endif /* POLARSSL_ERROR_STRERROR_BC */
747
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100748#else /* POLARSSL_ERROR_C */
749
750#if defined(POLARSSL_ERROR_STRERROR_DUMMY)
751
752#include <string.h>
753
754/*
755 * Provide an non-function in case POLARSSL_ERROR_C is not defined
756 */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200757void polarssl_strerror( int ret, char *buf, size_t buflen )
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100758{
759 ((void) ret);
760
761 if( buflen > 0 )
762 buf[0] = '\0';
763}
764
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200765#if defined(POLARSSL_ERROR_STRERROR_BC)
766void error_strerror( int ret, char *buf, size_t buflen )
767{
Paul Bakkerb887f112013-10-11 15:09:40 +0200768 polarssl_strerror( ret, buf, buflen );
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200769}
770#endif /* POLARSSL_ERROR_STRERROR_BC */
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100771#endif /* POLARSSL_ERROR_STRERROR_DUMMY */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200772
Paul Bakker9a736322012-11-14 12:39:52 +0000773#endif /* POLARSSL_ERROR_C */