blob: c6c9838e20754c156dce303b05a21267f8ea4a18 [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
32#if defined(POLARSSL_ERROR_C)
33
Paul Bakker3c2122f2013-06-24 19:03:14 +020034#include "polarssl/error.h"
35
Paul Bakker9d781402011-05-09 16:17:09 +000036#if defined(POLARSSL_AES_C)
37#include "polarssl/aes.h"
38#endif
39
40#if defined(POLARSSL_BASE64_C)
41#include "polarssl/base64.h"
42#endif
43
44#if defined(POLARSSL_BIGNUM_C)
45#include "polarssl/bignum.h"
46#endif
47
Paul Bakker83f00bb2012-07-04 11:08:50 +000048#if defined(POLARSSL_BLOWFISH_C)
49#include "polarssl/blowfish.h"
50#endif
51
Paul Bakker9d781402011-05-09 16:17:09 +000052#if defined(POLARSSL_CAMELLIA_C)
53#include "polarssl/camellia.h"
54#endif
55
Paul Bakkerff61a782011-06-09 15:42:02 +000056#if defined(POLARSSL_CIPHER_C)
57#include "polarssl/cipher.h"
58#endif
59
Paul Bakker880ac7e2011-11-27 14:50:49 +000060#if defined(POLARSSL_CTR_DRBG_C)
61#include "polarssl/ctr_drbg.h"
62#endif
63
Paul Bakker9d781402011-05-09 16:17:09 +000064#if defined(POLARSSL_DES_C)
65#include "polarssl/des.h"
66#endif
67
68#if defined(POLARSSL_DHM_C)
69#include "polarssl/dhm.h"
70#endif
71
Paul Bakkercf4365f2013-01-16 17:00:43 +010072#if defined(POLARSSL_ECP_C)
73#include "polarssl/ecp.h"
74#endif
75
Paul Bakker6083fd22011-12-03 21:45:14 +000076#if defined(POLARSSL_ENTROPY_C)
77#include "polarssl/entropy.h"
78#endif
79
Paul Bakker030277a2012-04-17 12:24:26 +000080#if defined(POLARSSL_GCM_C)
81#include "polarssl/gcm.h"
82#endif
83
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010084#if defined(POLARSSL_HMAC_DRBG_C)
85#include "polarssl/hmac_drbg.h"
86#endif
87
Paul Bakker9d781402011-05-09 16:17:09 +000088#if defined(POLARSSL_MD_C)
89#include "polarssl/md.h"
90#endif
91
Paul Bakker69e095c2011-12-10 21:55:01 +000092#if defined(POLARSSL_MD2_C)
93#include "polarssl/md2.h"
94#endif
95
96#if defined(POLARSSL_MD4_C)
97#include "polarssl/md4.h"
98#endif
99
100#if defined(POLARSSL_MD5_C)
101#include "polarssl/md5.h"
102#endif
103
Paul Bakker9d781402011-05-09 16:17:09 +0000104#if defined(POLARSSL_NET_C)
105#include "polarssl/net.h"
106#endif
107
Paul Bakkerc70b9822013-04-07 22:00:46 +0200108#if defined(POLARSSL_OID_C)
109#include "polarssl/oid.h"
110#endif
111
Paul Bakker9d781402011-05-09 16:17:09 +0000112#if defined(POLARSSL_PADLOCK_C)
113#include "polarssl/padlock.h"
114#endif
115
Paul Bakkerd14277d2012-09-26 15:19:05 +0000116#if defined(POLARSSL_PBKDF2_C)
117#include "polarssl/pbkdf2.h"
118#endif
119
Paul Bakkercff68422013-09-15 20:43:33 +0200120#if defined(POLARSSL_PEM_PARSE_C) || defined(POLARSSL_PEM_WRITE_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000121#include "polarssl/pem.h"
122#endif
123
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200124#if defined(POLARSSL_PK_C)
125#include "polarssl/pk.h"
126#endif
127
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200128#if defined(POLARSSL_PKCS12_C)
129#include "polarssl/pkcs12.h"
130#endif
131
Paul Bakkerb0c19a42013-06-24 19:26:38 +0200132#if defined(POLARSSL_PKCS5_C)
133#include "polarssl/pkcs5.h"
134#endif
135
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100136#if defined(POLARSSL_RIPEMD160_C)
137#include "polarssl/ripemd160.h"
138#endif
139
Paul Bakker9d781402011-05-09 16:17:09 +0000140#if defined(POLARSSL_RSA_C)
141#include "polarssl/rsa.h"
142#endif
143
Paul Bakker69e095c2011-12-10 21:55:01 +0000144#if defined(POLARSSL_SHA1_C)
145#include "polarssl/sha1.h"
146#endif
147
Paul Bakker9e36f042013-06-30 14:34:05 +0200148#if defined(POLARSSL_SHA256_C)
Paul Bakkerd2681d82013-06-30 14:49:12 +0200149#include "polarssl/sha256.h"
Paul Bakker69e095c2011-12-10 21:55:01 +0000150#endif
151
Paul Bakker9e36f042013-06-30 14:34:05 +0200152#if defined(POLARSSL_SHA512_C)
Paul Bakkerd2681d82013-06-30 14:49:12 +0200153#include "polarssl/sha512.h"
Paul Bakker69e095c2011-12-10 21:55:01 +0000154#endif
155
Paul Bakker831a7552011-05-18 13:32:51 +0000156#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000157#include "polarssl/ssl.h"
158#endif
159
Paul Bakker2466d932013-09-28 14:40:38 +0200160#if defined(POLARSSL_THREADING_C)
161#include "polarssl/threading.h"
162#endif
163
Paul Bakker36713e82013-09-17 13:25:29 +0200164#if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000165#include "polarssl/x509.h"
166#endif
167
168#if defined(POLARSSL_XTEA_C)
169#include "polarssl/xtea.h"
170#endif
171
172
173#include <string.h>
174
Paul Bakker6edcd412013-10-29 15:22:54 +0100175#if defined(_MSC_VER) && !defined snprintf && !defined(EFIX64) && \
176 !defined(EFI32)
Paul Bakkerdceecd82011-11-15 16:38:34 +0000177#define snprintf _snprintf
178#endif
179
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200180void polarssl_strerror( int ret, char *buf, size_t buflen )
Paul Bakker9d781402011-05-09 16:17:09 +0000181{
182 size_t len;
183 int use_ret;
184
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200185 if( buflen == 0 )
186 return;
187
Paul Bakker9d781402011-05-09 16:17:09 +0000188 memset( buf, 0x00, buflen );
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200189 /* Reduce buflen to make sure MSVC _snprintf() ends with \0 as well */
190 buflen -= 1;
191
Paul Bakker9d781402011-05-09 16:17:09 +0000192 if( ret < 0 )
193 ret = -ret;
194
195 if( ret & 0xFF80 )
196 {
197 use_ret = ret & 0xFF80;
198
199 // High level error codes
200 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200201 // BEGIN generated code
Paul Bakkerff61a782011-06-09 15:42:02 +0000202#if defined(POLARSSL_CIPHER_C)
203 if( use_ret == -(POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE) )
204 snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
205 if( use_ret == -(POLARSSL_ERR_CIPHER_BAD_INPUT_DATA) )
206 snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
207 if( use_ret == -(POLARSSL_ERR_CIPHER_ALLOC_FAILED) )
208 snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
209 if( use_ret == -(POLARSSL_ERR_CIPHER_INVALID_PADDING) )
210 snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
211 if( use_ret == -(POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
212 snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
Manuel Pégourié-Gonnard4fee79b2013-09-19 18:09:14 +0200213 if( use_ret == -(POLARSSL_ERR_CIPHER_AUTH_FAILED) )
214 snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
Paul Bakkerff61a782011-06-09 15:42:02 +0000215#endif /* POLARSSL_CIPHER_C */
216
Paul Bakker9d781402011-05-09 16:17:09 +0000217#if defined(POLARSSL_DHM_C)
218 if( use_ret == -(POLARSSL_ERR_DHM_BAD_INPUT_DATA) )
219 snprintf( buf, buflen, "DHM - Bad input parameters to function" );
220 if( use_ret == -(POLARSSL_ERR_DHM_READ_PARAMS_FAILED) )
221 snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
222 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PARAMS_FAILED) )
223 snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
224 if( use_ret == -(POLARSSL_ERR_DHM_READ_PUBLIC_FAILED) )
225 snprintf( buf, buflen, "DHM - Reading of the public values failed" );
226 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PUBLIC_FAILED) )
Paul Bakker05ef8352012-05-08 09:17:57 +0000227 snprintf( buf, buflen, "DHM - Making of the public value failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000228 if( use_ret == -(POLARSSL_ERR_DHM_CALC_SECRET_FAILED) )
229 snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
Paul Bakker40ce79f2013-09-15 17:43:54 +0200230 if( use_ret == -(POLARSSL_ERR_DHM_INVALID_FORMAT) )
231 snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
232 if( use_ret == -(POLARSSL_ERR_DHM_MALLOC_FAILED) )
233 snprintf( buf, buflen, "DHM - Allocation of memory failed" );
234 if( use_ret == -(POLARSSL_ERR_DHM_FILE_IO_ERROR) )
235 snprintf( buf, buflen, "DHM - Read/write of file failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000236#endif /* POLARSSL_DHM_C */
237
Paul Bakkercf4365f2013-01-16 17:00:43 +0100238#if defined(POLARSSL_ECP_C)
239 if( use_ret == -(POLARSSL_ERR_ECP_BAD_INPUT_DATA) )
240 snprintf( buf, buflen, "ECP - Bad input parameters to function" );
Paul Bakker41c83d32013-03-20 14:39:14 +0100241 if( use_ret == -(POLARSSL_ERR_ECP_BUFFER_TOO_SMALL) )
242 snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
Paul Bakkerfd3eac52013-06-29 23:31:33 +0200243 if( use_ret == -(POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE) )
244 snprintf( buf, buflen, "ECP - Requested curve not available" );
Paul Bakker1a7550a2013-09-15 13:01:22 +0200245 if( use_ret == -(POLARSSL_ERR_ECP_VERIFY_FAILED) )
246 snprintf( buf, buflen, "ECP - The signature is not valid" );
Manuel Pégourié-Gonnard456d3b92013-09-16 18:04:38 +0200247 if( use_ret == -(POLARSSL_ERR_ECP_MALLOC_FAILED) )
248 snprintf( buf, buflen, "ECP - Memory allocation failed" );
249 if( use_ret == -(POLARSSL_ERR_ECP_RANDOM_FAILED) )
250 snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
251 if( use_ret == -(POLARSSL_ERR_ECP_INVALID_KEY) )
252 snprintf( buf, buflen, "ECP - Invalid private or public key" );
Manuel Pégourié-Gonnard35e95dd2014-04-08 12:17:41 +0200253 if( use_ret == -(POLARSSL_ERR_ECP_SIG_LEN_MISMATCH) )
254 snprintf( buf, buflen, "ECP - Signature is valid but shorter than the user-supplied length" );
Paul Bakkercf4365f2013-01-16 17:00:43 +0100255#endif /* POLARSSL_ECP_C */
256
Paul Bakker9d781402011-05-09 16:17:09 +0000257#if defined(POLARSSL_MD_C)
258 if( use_ret == -(POLARSSL_ERR_MD_FEATURE_UNAVAILABLE) )
259 snprintf( buf, buflen, "MD - The selected feature is not available" );
Paul Bakker9c021ad2011-06-09 15:55:11 +0000260 if( use_ret == -(POLARSSL_ERR_MD_BAD_INPUT_DATA) )
261 snprintf( buf, buflen, "MD - Bad input parameters to function" );
262 if( use_ret == -(POLARSSL_ERR_MD_ALLOC_FAILED) )
263 snprintf( buf, buflen, "MD - Failed to allocate memory" );
Paul Bakker8913f822012-01-14 18:07:41 +0000264 if( use_ret == -(POLARSSL_ERR_MD_FILE_IO_ERROR) )
265 snprintf( buf, buflen, "MD - Opening or reading of file failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000266#endif /* POLARSSL_MD_C */
267
Paul Bakkercff68422013-09-15 20:43:33 +0200268#if defined(POLARSSL_PEM_PARSE_C) || defined(POLARSSL_PEM_WRITE_C)
Paul Bakker00b28602013-06-24 13:02:41 +0200269 if( use_ret == -(POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
270 snprintf( buf, buflen, "PEM - No PEM header or footer found" );
Paul Bakker9d781402011-05-09 16:17:09 +0000271 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_DATA) )
272 snprintf( buf, buflen, "PEM - PEM string is not as expected" );
273 if( use_ret == -(POLARSSL_ERR_PEM_MALLOC_FAILED) )
274 snprintf( buf, buflen, "PEM - Failed to allocate memory" );
275 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_ENC_IV) )
276 snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
277 if( use_ret == -(POLARSSL_ERR_PEM_UNKNOWN_ENC_ALG) )
278 snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
279 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_REQUIRED) )
280 snprintf( buf, buflen, "PEM - Private key password can't be empty" );
281 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_MISMATCH) )
282 snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
283 if( use_ret == -(POLARSSL_ERR_PEM_FEATURE_UNAVAILABLE) )
284 snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
Paul Bakker00b28602013-06-24 13:02:41 +0200285 if( use_ret == -(POLARSSL_ERR_PEM_BAD_INPUT_DATA) )
286 snprintf( buf, buflen, "PEM - Bad input parameters to function" );
Paul Bakkercff68422013-09-15 20:43:33 +0200287#endif /* POLARSSL_PEM_PARSE_C || POLARSSL_PEM_WRITE_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000288
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200289#if defined(POLARSSL_PK_C)
290 if( use_ret == -(POLARSSL_ERR_PK_MALLOC_FAILED) )
291 snprintf( buf, buflen, "PK - Memory alloation failed" );
Manuel Pégourié-Gonnard374e4b82013-07-09 10:21:34 +0200292 if( use_ret == -(POLARSSL_ERR_PK_TYPE_MISMATCH) )
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200293 snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
Manuel Pégourié-Gonnard15699382013-08-14 19:22:48 +0200294 if( use_ret == -(POLARSSL_ERR_PK_BAD_INPUT_DATA) )
295 snprintf( buf, buflen, "PK - Bad input parameters to function" );
Paul Bakker1a7550a2013-09-15 13:01:22 +0200296 if( use_ret == -(POLARSSL_ERR_PK_FILE_IO_ERROR) )
297 snprintf( buf, buflen, "PK - Read/write of file failed" );
298 if( use_ret == -(POLARSSL_ERR_PK_KEY_INVALID_VERSION) )
299 snprintf( buf, buflen, "PK - Unsupported key version" );
300 if( use_ret == -(POLARSSL_ERR_PK_KEY_INVALID_FORMAT) )
301 snprintf( buf, buflen, "PK - Invalid key tag or value" );
302 if( use_ret == -(POLARSSL_ERR_PK_UNKNOWN_PK_ALG) )
303 snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
304 if( use_ret == -(POLARSSL_ERR_PK_PASSWORD_REQUIRED) )
305 snprintf( buf, buflen, "PK - Private key password can't be empty" );
306 if( use_ret == -(POLARSSL_ERR_PK_PASSWORD_MISMATCH) )
307 snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
308 if( use_ret == -(POLARSSL_ERR_PK_INVALID_PUBKEY) )
309 snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
310 if( use_ret == -(POLARSSL_ERR_PK_INVALID_ALG) )
311 snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
312 if( use_ret == -(POLARSSL_ERR_PK_UNKNOWN_NAMED_CURVE) )
313 snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
314 if( use_ret == -(POLARSSL_ERR_PK_FEATURE_UNAVAILABLE) )
315 snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
Manuel Pégourié-Gonnard2abed842014-04-08 12:40:15 +0200316 if( use_ret == -(POLARSSL_ERR_PK_SIG_LEN_MISMATCH) )
317 snprintf( buf, buflen, "PK - The signature is valid but its length is less than expected" );
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200318#endif /* POLARSSL_PK_C */
319
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200320#if defined(POLARSSL_PKCS12_C)
321 if( use_ret == -(POLARSSL_ERR_PKCS12_BAD_INPUT_DATA) )
322 snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
323 if( use_ret == -(POLARSSL_ERR_PKCS12_FEATURE_UNAVAILABLE) )
324 snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
325 if( use_ret == -(POLARSSL_ERR_PKCS12_PBE_INVALID_FORMAT) )
326 snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
Paul Bakker38b50d72013-06-24 19:33:27 +0200327 if( use_ret == -(POLARSSL_ERR_PKCS12_PASSWORD_MISMATCH) )
328 snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200329#endif /* POLARSSL_PKCS12_C */
330
Paul Bakker28144de2013-06-24 19:28:55 +0200331#if defined(POLARSSL_PKCS5_C)
332 if( use_ret == -(POLARSSL_ERR_PKCS5_BAD_INPUT_DATA) )
333 snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
334 if( use_ret == -(POLARSSL_ERR_PKCS5_INVALID_FORMAT) )
335 snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
336 if( use_ret == -(POLARSSL_ERR_PKCS5_FEATURE_UNAVAILABLE) )
337 snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
338 if( use_ret == -(POLARSSL_ERR_PKCS5_PASSWORD_MISMATCH) )
339 snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
340#endif /* POLARSSL_PKCS5_C */
341
Paul Bakker9d781402011-05-09 16:17:09 +0000342#if defined(POLARSSL_RSA_C)
343 if( use_ret == -(POLARSSL_ERR_RSA_BAD_INPUT_DATA) )
344 snprintf( buf, buflen, "RSA - Bad input parameters to function" );
345 if( use_ret == -(POLARSSL_ERR_RSA_INVALID_PADDING) )
346 snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
347 if( use_ret == -(POLARSSL_ERR_RSA_KEY_GEN_FAILED) )
348 snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
349 if( use_ret == -(POLARSSL_ERR_RSA_KEY_CHECK_FAILED) )
350 snprintf( buf, buflen, "RSA - Key failed to pass the libraries validity check" );
351 if( use_ret == -(POLARSSL_ERR_RSA_PUBLIC_FAILED) )
352 snprintf( buf, buflen, "RSA - The public key operation failed" );
353 if( use_ret == -(POLARSSL_ERR_RSA_PRIVATE_FAILED) )
354 snprintf( buf, buflen, "RSA - The private key operation failed" );
355 if( use_ret == -(POLARSSL_ERR_RSA_VERIFY_FAILED) )
356 snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
357 if( use_ret == -(POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE) )
358 snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
359 if( use_ret == -(POLARSSL_ERR_RSA_RNG_FAILED) )
360 snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
361#endif /* POLARSSL_RSA_C */
362
Paul Bakker831a7552011-05-18 13:32:51 +0000363#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000364 if( use_ret == -(POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE) )
365 snprintf( buf, buflen, "SSL - The requested feature is not available" );
366 if( use_ret == -(POLARSSL_ERR_SSL_BAD_INPUT_DATA) )
367 snprintf( buf, buflen, "SSL - Bad input parameters to function" );
368 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_MAC) )
369 snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
370 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_RECORD) )
371 snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
Paul Bakker831a7552011-05-18 13:32:51 +0000372 if( use_ret == -(POLARSSL_ERR_SSL_CONN_EOF) )
373 snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
Paul Bakker9d781402011-05-09 16:17:09 +0000374 if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_CIPHER) )
375 snprintf( buf, buflen, "SSL - An unknown cipher was received" );
376 if( use_ret == -(POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN) )
377 snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
Paul Bakkera9a028e2013-11-21 17:31:06 +0100378 if( use_ret == -(POLARSSL_ERR_SSL_NO_RNG) )
379 snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
Paul Bakker9d781402011-05-09 16:17:09 +0000380 if( use_ret == -(POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE) )
381 snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
382 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE) )
383 snprintf( buf, buflen, "SSL - DESCRIPTION MISSING" );
384 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED) )
385 snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
386 if( use_ret == -(POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED) )
Paul Bakker73a899a2013-04-17 19:11:36 +0200387 snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000388 if( use_ret == -(POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED) )
389 snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
390 if( use_ret == -(POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE) )
391 snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
392 if( use_ret == -(POLARSSL_ERR_SSL_FATAL_ALERT_MESSAGE) )
Paul Bakker3aac1da2012-05-08 13:12:27 +0000393 {
Paul Bakker9d781402011-05-09 16:17:09 +0000394 snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
Paul Bakker3aac1da2012-05-08 13:12:27 +0000395 return;
396 }
Paul Bakker9d781402011-05-09 16:17:09 +0000397 if( use_ret == -(POLARSSL_ERR_SSL_PEER_VERIFY_FAILED) )
398 snprintf( buf, buflen, "SSL - Verification of our peer failed" );
399 if( use_ret == -(POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) )
400 snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
401 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO) )
402 snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
403 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO) )
404 snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
405 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE) )
406 snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
407 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
408 snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
409 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
410 snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
411 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
412 snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
413 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
414 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
Paul Bakker41c83d32013-03-20 14:39:14 +0100415 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
416 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
417 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
418 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
Paul Bakker9d781402011-05-09 16:17:09 +0000419 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
420 snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
421 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
422 snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
423 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_FINISHED) )
424 snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000425 if( use_ret == -(POLARSSL_ERR_SSL_MALLOC_FAILED) )
426 snprintf( buf, buflen, "SSL - Memory allocation failed" );
Paul Bakker05ef8352012-05-08 09:17:57 +0000427 if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FAILED) )
428 snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
429 if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
430 snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
Paul Bakker83f00bb2012-07-04 11:08:50 +0000431 if( use_ret == -(POLARSSL_ERR_SSL_COMPRESSION_FAILED) )
432 snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
Paul Bakker1d29fb52012-09-28 13:28:45 +0000433 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
434 snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
Manuel Pégourié-Gonnarda5cc6022013-07-31 12:58:16 +0200435 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
436 snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
Paul Bakker606b4ba2013-08-14 16:52:14 +0200437 if( use_ret == -(POLARSSL_ERR_SSL_SESSION_TICKET_EXPIRED) )
438 snprintf( buf, buflen, "SSL - Session ticket has expired" );
Manuel Pégourié-Gonnardb3d91872013-08-14 15:56:19 +0200439 if( use_ret == -(POLARSSL_ERR_SSL_PK_TYPE_MISMATCH) )
440 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 +0200441 if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_IDENTITY) )
Paul Bakker75342a62014-04-08 17:35:40 +0200442 snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
Manuel Pégourié-Gonnarda8a25ae2013-10-27 13:48:15 +0100443 if( use_ret == -(POLARSSL_ERR_SSL_INTERNAL_ERROR) )
444 snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
Manuel Pégourié-Gonnard83cdffc2014-03-10 21:20:29 +0100445 if( use_ret == -(POLARSSL_ERR_SSL_COUNTER_WRAPPING) )
446 snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
Paul Bakker831a7552011-05-18 13:32:51 +0000447#endif /* POLARSSL_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000448
Paul Bakker36713e82013-09-17 13:25:29 +0200449#if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000450 if( use_ret == -(POLARSSL_ERR_X509_FEATURE_UNAVAILABLE) )
451 snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
Paul Bakker51876562013-09-17 14:36:05 +0200452 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_OID) )
453 snprintf( buf, buflen, "X509 - Requested OID is unknown" );
454 if( use_ret == -(POLARSSL_ERR_X509_INVALID_FORMAT) )
455 snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
456 if( use_ret == -(POLARSSL_ERR_X509_INVALID_VERSION) )
457 snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
458 if( use_ret == -(POLARSSL_ERR_X509_INVALID_SERIAL) )
Paul Bakker9d781402011-05-09 16:17:09 +0000459 snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200460 if( use_ret == -(POLARSSL_ERR_X509_INVALID_ALG) )
Paul Bakker9d781402011-05-09 16:17:09 +0000461 snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200462 if( use_ret == -(POLARSSL_ERR_X509_INVALID_NAME) )
Paul Bakker9d781402011-05-09 16:17:09 +0000463 snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200464 if( use_ret == -(POLARSSL_ERR_X509_INVALID_DATE) )
Paul Bakker9d781402011-05-09 16:17:09 +0000465 snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200466 if( use_ret == -(POLARSSL_ERR_X509_INVALID_SIGNATURE) )
Paul Bakker9d781402011-05-09 16:17:09 +0000467 snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200468 if( use_ret == -(POLARSSL_ERR_X509_INVALID_EXTENSIONS) )
Paul Bakker9d781402011-05-09 16:17:09 +0000469 snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200470 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_VERSION) )
471 snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
472 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_SIG_ALG) )
Paul Bakker9d781402011-05-09 16:17:09 +0000473 snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
Paul Bakker51876562013-09-17 14:36:05 +0200474 if( use_ret == -(POLARSSL_ERR_X509_SIG_MISMATCH) )
Paul Bakker6db455e2013-09-18 17:29:31 +0200475 snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::x509_crt sig_oid)" );
Paul Bakker9d781402011-05-09 16:17:09 +0000476 if( use_ret == -(POLARSSL_ERR_X509_CERT_VERIFY_FAILED) )
477 snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
Paul Bakker6c0ceb32011-12-04 12:24:18 +0000478 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT) )
479 snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
Paul Bakker51876562013-09-17 14:36:05 +0200480 if( use_ret == -(POLARSSL_ERR_X509_BAD_INPUT_DATA) )
Paul Bakker69e095c2011-12-10 21:55:01 +0000481 snprintf( buf, buflen, "X509 - Input invalid" );
482 if( use_ret == -(POLARSSL_ERR_X509_MALLOC_FAILED) )
483 snprintf( buf, buflen, "X509 - Allocation of memory failed" );
484 if( use_ret == -(POLARSSL_ERR_X509_FILE_IO_ERROR) )
485 snprintf( buf, buflen, "X509 - Read/write of file failed" );
Paul Bakker36713e82013-09-17 13:25:29 +0200486#endif /* POLARSSL_X509_USE,X509_CREATE_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200487 // END generated code
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200488
Paul Bakker9d781402011-05-09 16:17:09 +0000489 if( strlen( buf ) == 0 )
490 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
491 }
492
493 use_ret = ret & ~0xFF80;
494
495 if( use_ret == 0 )
496 return;
497
498 // If high level code is present, make a concatenation between both
499 // error strings.
500 //
501 len = strlen( buf );
502
503 if( len > 0 )
504 {
505 if( buflen - len < 5 )
506 return;
507
508 snprintf( buf + len, buflen - len, " : " );
509
510 buf += len + 3;
511 buflen -= len + 3;
512 }
513
514 // Low level error codes
515 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200516 // BEGIN generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000517#if defined(POLARSSL_AES_C)
518 if( use_ret == -(POLARSSL_ERR_AES_INVALID_KEY_LENGTH) )
519 snprintf( buf, buflen, "AES - Invalid key length" );
520 if( use_ret == -(POLARSSL_ERR_AES_INVALID_INPUT_LENGTH) )
521 snprintf( buf, buflen, "AES - Invalid data input length" );
522#endif /* POLARSSL_AES_C */
523
Paul Bakkerdceecd82011-11-15 16:38:34 +0000524#if defined(POLARSSL_ASN1_PARSE_C)
525 if( use_ret == -(POLARSSL_ERR_ASN1_OUT_OF_DATA) )
526 snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
527 if( use_ret == -(POLARSSL_ERR_ASN1_UNEXPECTED_TAG) )
528 snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
529 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_LENGTH) )
530 snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
531 if( use_ret == -(POLARSSL_ERR_ASN1_LENGTH_MISMATCH) )
532 snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
533 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_DATA) )
534 snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000535 if( use_ret == -(POLARSSL_ERR_ASN1_MALLOC_FAILED) )
536 snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000537 if( use_ret == -(POLARSSL_ERR_ASN1_BUF_TOO_SMALL) )
538 snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
Paul Bakkerdceecd82011-11-15 16:38:34 +0000539#endif /* POLARSSL_ASN1_PARSE_C */
540
Paul Bakker9d781402011-05-09 16:17:09 +0000541#if defined(POLARSSL_BASE64_C)
542 if( use_ret == -(POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) )
543 snprintf( buf, buflen, "BASE64 - Output buffer too small" );
544 if( use_ret == -(POLARSSL_ERR_BASE64_INVALID_CHARACTER) )
545 snprintf( buf, buflen, "BASE64 - Invalid character in input" );
546#endif /* POLARSSL_BASE64_C */
547
548#if defined(POLARSSL_BIGNUM_C)
549 if( use_ret == -(POLARSSL_ERR_MPI_FILE_IO_ERROR) )
550 snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
551 if( use_ret == -(POLARSSL_ERR_MPI_BAD_INPUT_DATA) )
552 snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
553 if( use_ret == -(POLARSSL_ERR_MPI_INVALID_CHARACTER) )
554 snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
555 if( use_ret == -(POLARSSL_ERR_MPI_BUFFER_TOO_SMALL) )
Paul Bakker69e095c2011-12-10 21:55:01 +0000556 snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
Paul Bakker9d781402011-05-09 16:17:09 +0000557 if( use_ret == -(POLARSSL_ERR_MPI_NEGATIVE_VALUE) )
558 snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
559 if( use_ret == -(POLARSSL_ERR_MPI_DIVISION_BY_ZERO) )
560 snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
561 if( use_ret == -(POLARSSL_ERR_MPI_NOT_ACCEPTABLE) )
562 snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000563 if( use_ret == -(POLARSSL_ERR_MPI_MALLOC_FAILED) )
564 snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000565#endif /* POLARSSL_BIGNUM_C */
566
Paul Bakker83f00bb2012-07-04 11:08:50 +0000567#if defined(POLARSSL_BLOWFISH_C)
568 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
569 snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
570 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
571 snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
572#endif /* POLARSSL_BLOWFISH_C */
573
Paul Bakker9d781402011-05-09 16:17:09 +0000574#if defined(POLARSSL_CAMELLIA_C)
575 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
576 snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
577 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
578 snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
579#endif /* POLARSSL_CAMELLIA_C */
580
Paul Bakker880ac7e2011-11-27 14:50:49 +0000581#if defined(POLARSSL_CTR_DRBG_C)
582 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
583 snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
584 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
585 snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
586 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG) )
587 snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000588 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR) )
589 snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
Paul Bakker880ac7e2011-11-27 14:50:49 +0000590#endif /* POLARSSL_CTR_DRBG_C */
591
Paul Bakker9d781402011-05-09 16:17:09 +0000592#if defined(POLARSSL_DES_C)
593 if( use_ret == -(POLARSSL_ERR_DES_INVALID_INPUT_LENGTH) )
594 snprintf( buf, buflen, "DES - The data input has an invalid length" );
595#endif /* POLARSSL_DES_C */
596
Paul Bakker6083fd22011-12-03 21:45:14 +0000597#if defined(POLARSSL_ENTROPY_C)
598 if( use_ret == -(POLARSSL_ERR_ENTROPY_SOURCE_FAILED) )
599 snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
600 if( use_ret == -(POLARSSL_ERR_ENTROPY_MAX_SOURCES) )
601 snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
Paul Bakker43655f42011-12-15 20:11:16 +0000602 if( use_ret == -(POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED) )
603 snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
Paul Bakker66ff70d2014-03-26 11:54:05 +0100604 if( use_ret == -(POLARSSL_ERR_ENTROPY_FILE_IO_ERROR) )
605 snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
Paul Bakker6083fd22011-12-03 21:45:14 +0000606#endif /* POLARSSL_ENTROPY_C */
607
Paul Bakker030277a2012-04-17 12:24:26 +0000608#if defined(POLARSSL_GCM_C)
609 if( use_ret == -(POLARSSL_ERR_GCM_AUTH_FAILED) )
610 snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
Paul Bakkerd8ef1672012-04-18 14:17:32 +0000611 if( use_ret == -(POLARSSL_ERR_GCM_BAD_INPUT) )
612 snprintf( buf, buflen, "GCM - Bad input parameters to function" );
Paul Bakker030277a2012-04-17 12:24:26 +0000613#endif /* POLARSSL_GCM_C */
614
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100615#if defined(POLARSSL_HMAC_DRBG_C)
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100616 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
617 snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
618 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
619 snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
620 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_FILE_IO_ERROR) )
621 snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
Manuel Pégourié-Gonnard9a6e93e2014-03-11 09:34:02 +0100622 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
623 snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100624#endif /* POLARSSL_HMAC_DRBG_C */
625
Paul Bakker69e095c2011-12-10 21:55:01 +0000626#if defined(POLARSSL_MD2_C)
627 if( use_ret == -(POLARSSL_ERR_MD2_FILE_IO_ERROR) )
628 snprintf( buf, buflen, "MD2 - Read/write error in file" );
629#endif /* POLARSSL_MD2_C */
630
631#if defined(POLARSSL_MD4_C)
632 if( use_ret == -(POLARSSL_ERR_MD4_FILE_IO_ERROR) )
633 snprintf( buf, buflen, "MD4 - Read/write error in file" );
634#endif /* POLARSSL_MD4_C */
635
636#if defined(POLARSSL_MD5_C)
637 if( use_ret == -(POLARSSL_ERR_MD5_FILE_IO_ERROR) )
638 snprintf( buf, buflen, "MD5 - Read/write error in file" );
639#endif /* POLARSSL_MD5_C */
640
Paul Bakker9d781402011-05-09 16:17:09 +0000641#if defined(POLARSSL_NET_C)
642 if( use_ret == -(POLARSSL_ERR_NET_UNKNOWN_HOST) )
643 snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
644 if( use_ret == -(POLARSSL_ERR_NET_SOCKET_FAILED) )
645 snprintf( buf, buflen, "NET - Failed to open a socket" );
646 if( use_ret == -(POLARSSL_ERR_NET_CONNECT_FAILED) )
647 snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
648 if( use_ret == -(POLARSSL_ERR_NET_BIND_FAILED) )
649 snprintf( buf, buflen, "NET - Binding of the socket failed" );
650 if( use_ret == -(POLARSSL_ERR_NET_LISTEN_FAILED) )
651 snprintf( buf, buflen, "NET - Could not listen on the socket" );
652 if( use_ret == -(POLARSSL_ERR_NET_ACCEPT_FAILED) )
653 snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
654 if( use_ret == -(POLARSSL_ERR_NET_RECV_FAILED) )
655 snprintf( buf, buflen, "NET - Reading information from the socket failed" );
656 if( use_ret == -(POLARSSL_ERR_NET_SEND_FAILED) )
657 snprintf( buf, buflen, "NET - Sending information through the socket failed" );
658 if( use_ret == -(POLARSSL_ERR_NET_CONN_RESET) )
659 snprintf( buf, buflen, "NET - Connection was reset by peer" );
Paul Bakker831a7552011-05-18 13:32:51 +0000660 if( use_ret == -(POLARSSL_ERR_NET_WANT_READ) )
661 snprintf( buf, buflen, "NET - Connection requires a read call" );
662 if( use_ret == -(POLARSSL_ERR_NET_WANT_WRITE) )
663 snprintf( buf, buflen, "NET - Connection requires a write call" );
Paul Bakker9d781402011-05-09 16:17:09 +0000664#endif /* POLARSSL_NET_C */
665
Paul Bakkerc70b9822013-04-07 22:00:46 +0200666#if defined(POLARSSL_OID_C)
667 if( use_ret == -(POLARSSL_ERR_OID_NOT_FOUND) )
668 snprintf( buf, buflen, "OID - OID is not found" );
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100669 if( use_ret == -(POLARSSL_ERR_OID_BUF_TOO_SMALL) )
670 snprintf( buf, buflen, "OID - output buffer is too small" );
Paul Bakkerc70b9822013-04-07 22:00:46 +0200671#endif /* POLARSSL_OID_C */
672
Paul Bakker9d781402011-05-09 16:17:09 +0000673#if defined(POLARSSL_PADLOCK_C)
674 if( use_ret == -(POLARSSL_ERR_PADLOCK_DATA_MISALIGNED) )
675 snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
676#endif /* POLARSSL_PADLOCK_C */
677
Paul Bakkerd14277d2012-09-26 15:19:05 +0000678#if defined(POLARSSL_PBKDF2_C)
679 if( use_ret == -(POLARSSL_ERR_PBKDF2_BAD_INPUT_DATA) )
680 snprintf( buf, buflen, "PBKDF2 - Bad input parameters to function" );
681#endif /* POLARSSL_PBKDF2_C */
682
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100683#if defined(POLARSSL_RIPEMD160_C)
684 if( use_ret == -(POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR) )
685 snprintf( buf, buflen, "RIPEMD160 - Read/write error in file" );
686#endif /* POLARSSL_RIPEMD160_C */
687
Paul Bakker69e095c2011-12-10 21:55:01 +0000688#if defined(POLARSSL_SHA1_C)
689 if( use_ret == -(POLARSSL_ERR_SHA1_FILE_IO_ERROR) )
690 snprintf( buf, buflen, "SHA1 - Read/write error in file" );
691#endif /* POLARSSL_SHA1_C */
692
Paul Bakker9e36f042013-06-30 14:34:05 +0200693#if defined(POLARSSL_SHA256_C)
694 if( use_ret == -(POLARSSL_ERR_SHA256_FILE_IO_ERROR) )
695 snprintf( buf, buflen, "SHA256 - Read/write error in file" );
696#endif /* POLARSSL_SHA256_C */
Paul Bakker69e095c2011-12-10 21:55:01 +0000697
Paul Bakker9e36f042013-06-30 14:34:05 +0200698#if defined(POLARSSL_SHA512_C)
699 if( use_ret == -(POLARSSL_ERR_SHA512_FILE_IO_ERROR) )
700 snprintf( buf, buflen, "SHA512 - Read/write error in file" );
701#endif /* POLARSSL_SHA512_C */
Paul Bakker69e095c2011-12-10 21:55:01 +0000702
Paul Bakker2466d932013-09-28 14:40:38 +0200703#if defined(POLARSSL_THREADING_C)
704 if( use_ret == -(POLARSSL_ERR_THREADING_FEATURE_UNAVAILABLE) )
705 snprintf( buf, buflen, "THREADING - The selected feature is not available" );
706 if( use_ret == -(POLARSSL_ERR_THREADING_BAD_INPUT_DATA) )
707 snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
708 if( use_ret == -(POLARSSL_ERR_THREADING_MUTEX_ERROR) )
709 snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
710#endif /* POLARSSL_THREADING_C */
711
Paul Bakker9d781402011-05-09 16:17:09 +0000712#if defined(POLARSSL_XTEA_C)
713 if( use_ret == -(POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH) )
714 snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
715#endif /* POLARSSL_XTEA_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200716 // END generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000717
718 if( strlen( buf ) != 0 )
719 return;
720
721 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
722}
723
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200724#if defined(POLARSSL_ERROR_STRERROR_BC)
725void error_strerror( int ret, char *buf, size_t buflen )
726{
Paul Bakkerb887f112013-10-11 15:09:40 +0200727 polarssl_strerror( ret, buf, buflen );
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200728}
729#endif /* POLARSSL_ERROR_STRERROR_BC */
730
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100731#else /* POLARSSL_ERROR_C */
732
733#if defined(POLARSSL_ERROR_STRERROR_DUMMY)
734
735#include <string.h>
736
737/*
738 * Provide an non-function in case POLARSSL_ERROR_C is not defined
739 */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200740void polarssl_strerror( int ret, char *buf, size_t buflen )
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100741{
742 ((void) ret);
743
744 if( buflen > 0 )
745 buf[0] = '\0';
746}
747
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200748#if defined(POLARSSL_ERROR_STRERROR_BC)
749void error_strerror( int ret, char *buf, size_t buflen )
750{
Paul Bakkerb887f112013-10-11 15:09:40 +0200751 polarssl_strerror( ret, buf, buflen );
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200752}
753#endif /* POLARSSL_ERROR_STRERROR_BC */
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100754#endif /* POLARSSL_ERROR_STRERROR_DUMMY */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200755
Paul Bakker9a736322012-11-14 12:39:52 +0000756#endif /* POLARSSL_ERROR_C */