blob: 9bc503429085a15969389677e9ea2c9558af4f96 [file] [log] [blame]
Paul Bakker9d781402011-05-09 16:17:09 +00001/*
2 * Error message information
3 *
4 * Copyright (C) 2006-2010, Brainspark B.V.
5 *
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
26#include "polarssl/config.h"
27
28#if defined(POLARSSL_ERROR_C)
29
30#if defined(POLARSSL_AES_C)
31#include "polarssl/aes.h"
32#endif
33
34#if defined(POLARSSL_BASE64_C)
35#include "polarssl/base64.h"
36#endif
37
38#if defined(POLARSSL_BIGNUM_C)
39#include "polarssl/bignum.h"
40#endif
41
42#if defined(POLARSSL_CAMELLIA_C)
43#include "polarssl/camellia.h"
44#endif
45
Paul Bakkerff61a782011-06-09 15:42:02 +000046#if defined(POLARSSL_CIPHER_C)
47#include "polarssl/cipher.h"
48#endif
49
Paul Bakker880ac7e2011-11-27 14:50:49 +000050#if defined(POLARSSL_CTR_DRBG_C)
51#include "polarssl/ctr_drbg.h"
52#endif
53
Paul Bakker9d781402011-05-09 16:17:09 +000054#if defined(POLARSSL_DES_C)
55#include "polarssl/des.h"
56#endif
57
58#if defined(POLARSSL_DHM_C)
59#include "polarssl/dhm.h"
60#endif
61
Paul Bakker6083fd22011-12-03 21:45:14 +000062#if defined(POLARSSL_ENTROPY_C)
63#include "polarssl/entropy.h"
64#endif
65
Paul Bakker9d781402011-05-09 16:17:09 +000066#if defined(POLARSSL_MD_C)
67#include "polarssl/md.h"
68#endif
69
Paul Bakker732e1a82011-12-11 16:35:09 +000070#if defined(POLARSSL_MD2_C)
71#include "polarssl/md2.h"
72#endif
73
74#if defined(POLARSSL_MD4_C)
75#include "polarssl/md4.h"
76#endif
77
78#if defined(POLARSSL_MD5_C)
79#include "polarssl/md5.h"
80#endif
81
Paul Bakker9d781402011-05-09 16:17:09 +000082#if defined(POLARSSL_NET_C)
83#include "polarssl/net.h"
84#endif
85
86#if defined(POLARSSL_PADLOCK_C)
87#include "polarssl/padlock.h"
88#endif
89
90#if defined(POLARSSL_PEM_C)
91#include "polarssl/pem.h"
92#endif
93
94#if defined(POLARSSL_RSA_C)
95#include "polarssl/rsa.h"
96#endif
97
Paul Bakker732e1a82011-12-11 16:35:09 +000098#if defined(POLARSSL_SHA1_C)
99#include "polarssl/sha1.h"
100#endif
101
102#if defined(POLARSSL_SHA2_C)
103#include "polarssl/sha2.h"
104#endif
105
106#if defined(POLARSSL_SHA4_C)
107#include "polarssl/sha4.h"
108#endif
109
Paul Bakker831a7552011-05-18 13:32:51 +0000110#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000111#include "polarssl/ssl.h"
112#endif
113
114#if defined(POLARSSL_X509_PARSE_C)
115#include "polarssl/x509.h"
116#endif
117
118#if defined(POLARSSL_XTEA_C)
119#include "polarssl/xtea.h"
120#endif
121
122
123#include <string.h>
124
Paul Bakkerdceecd82011-11-15 16:38:34 +0000125#if defined _MSC_VER && !defined snprintf
126#define snprintf _snprintf
127#endif
128
Paul Bakker9d781402011-05-09 16:17:09 +0000129void error_strerror( int ret, char *buf, size_t buflen )
130{
131 size_t len;
132 int use_ret;
133
134 memset( buf, 0x00, buflen );
135
136 if( ret < 0 )
137 ret = -ret;
138
139 if( ret & 0xFF80 )
140 {
141 use_ret = ret & 0xFF80;
142
143 // High level error codes
144 //
Paul Bakkerff61a782011-06-09 15:42:02 +0000145#if defined(POLARSSL_CIPHER_C)
146 if( use_ret == -(POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE) )
147 snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
148 if( use_ret == -(POLARSSL_ERR_CIPHER_BAD_INPUT_DATA) )
149 snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
150 if( use_ret == -(POLARSSL_ERR_CIPHER_ALLOC_FAILED) )
151 snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
152 if( use_ret == -(POLARSSL_ERR_CIPHER_INVALID_PADDING) )
153 snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
154 if( use_ret == -(POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
155 snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
156#endif /* POLARSSL_CIPHER_C */
157
Paul Bakker9d781402011-05-09 16:17:09 +0000158#if defined(POLARSSL_DHM_C)
159 if( use_ret == -(POLARSSL_ERR_DHM_BAD_INPUT_DATA) )
160 snprintf( buf, buflen, "DHM - Bad input parameters to function" );
161 if( use_ret == -(POLARSSL_ERR_DHM_READ_PARAMS_FAILED) )
162 snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
163 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PARAMS_FAILED) )
164 snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
165 if( use_ret == -(POLARSSL_ERR_DHM_READ_PUBLIC_FAILED) )
166 snprintf( buf, buflen, "DHM - Reading of the public values failed" );
167 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PUBLIC_FAILED) )
168 snprintf( buf, buflen, "DHM - Makeing of the public value failed" );
169 if( use_ret == -(POLARSSL_ERR_DHM_CALC_SECRET_FAILED) )
170 snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
171#endif /* POLARSSL_DHM_C */
172
173#if defined(POLARSSL_MD_C)
174 if( use_ret == -(POLARSSL_ERR_MD_FEATURE_UNAVAILABLE) )
175 snprintf( buf, buflen, "MD - The selected feature is not available" );
Paul Bakker9c021ad2011-06-09 15:55:11 +0000176 if( use_ret == -(POLARSSL_ERR_MD_BAD_INPUT_DATA) )
177 snprintf( buf, buflen, "MD - Bad input parameters to function" );
178 if( use_ret == -(POLARSSL_ERR_MD_ALLOC_FAILED) )
179 snprintf( buf, buflen, "MD - Failed to allocate memory" );
Paul Bakkere2e36d32012-01-23 09:56:51 +0000180 if( use_ret == -(POLARSSL_ERR_MD_FILE_IO_ERROR) )
181 snprintf( buf, buflen, "MD - Opening or reading of file failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000182#endif /* POLARSSL_MD_C */
183
184#if defined(POLARSSL_PEM_C)
185 if( use_ret == -(POLARSSL_ERR_PEM_NO_HEADER_PRESENT) )
186 snprintf( buf, buflen, "PEM - No PEM header found" );
187 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_DATA) )
188 snprintf( buf, buflen, "PEM - PEM string is not as expected" );
189 if( use_ret == -(POLARSSL_ERR_PEM_MALLOC_FAILED) )
190 snprintf( buf, buflen, "PEM - Failed to allocate memory" );
191 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_ENC_IV) )
192 snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
193 if( use_ret == -(POLARSSL_ERR_PEM_UNKNOWN_ENC_ALG) )
194 snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
195 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_REQUIRED) )
196 snprintf( buf, buflen, "PEM - Private key password can't be empty" );
197 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_MISMATCH) )
198 snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
199 if( use_ret == -(POLARSSL_ERR_PEM_FEATURE_UNAVAILABLE) )
200 snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
201#endif /* POLARSSL_PEM_C */
202
203#if defined(POLARSSL_RSA_C)
204 if( use_ret == -(POLARSSL_ERR_RSA_BAD_INPUT_DATA) )
205 snprintf( buf, buflen, "RSA - Bad input parameters to function" );
206 if( use_ret == -(POLARSSL_ERR_RSA_INVALID_PADDING) )
207 snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
208 if( use_ret == -(POLARSSL_ERR_RSA_KEY_GEN_FAILED) )
209 snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
210 if( use_ret == -(POLARSSL_ERR_RSA_KEY_CHECK_FAILED) )
211 snprintf( buf, buflen, "RSA - Key failed to pass the libraries validity check" );
212 if( use_ret == -(POLARSSL_ERR_RSA_PUBLIC_FAILED) )
213 snprintf( buf, buflen, "RSA - The public key operation failed" );
214 if( use_ret == -(POLARSSL_ERR_RSA_PRIVATE_FAILED) )
215 snprintf( buf, buflen, "RSA - The private key operation failed" );
216 if( use_ret == -(POLARSSL_ERR_RSA_VERIFY_FAILED) )
217 snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
218 if( use_ret == -(POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE) )
219 snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
220 if( use_ret == -(POLARSSL_ERR_RSA_RNG_FAILED) )
221 snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
222#endif /* POLARSSL_RSA_C */
223
Paul Bakker831a7552011-05-18 13:32:51 +0000224#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000225 if( use_ret == -(POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE) )
226 snprintf( buf, buflen, "SSL - The requested feature is not available" );
227 if( use_ret == -(POLARSSL_ERR_SSL_BAD_INPUT_DATA) )
228 snprintf( buf, buflen, "SSL - Bad input parameters to function" );
229 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_MAC) )
230 snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
231 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_RECORD) )
232 snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
Paul Bakker831a7552011-05-18 13:32:51 +0000233 if( use_ret == -(POLARSSL_ERR_SSL_CONN_EOF) )
234 snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
Paul Bakker9d781402011-05-09 16:17:09 +0000235 if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_CIPHER) )
236 snprintf( buf, buflen, "SSL - An unknown cipher was received" );
237 if( use_ret == -(POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN) )
238 snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
239 if( use_ret == -(POLARSSL_ERR_SSL_NO_SESSION_FOUND) )
240 snprintf( buf, buflen, "SSL - No session to recover was found" );
241 if( use_ret == -(POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE) )
242 snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
243 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE) )
244 snprintf( buf, buflen, "SSL - DESCRIPTION MISSING" );
245 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED) )
246 snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
247 if( use_ret == -(POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED) )
248 snprintf( buf, buflen, "SSL - The own private key is not set, but needed" );
249 if( use_ret == -(POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED) )
250 snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
251 if( use_ret == -(POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE) )
252 snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
253 if( use_ret == -(POLARSSL_ERR_SSL_FATAL_ALERT_MESSAGE) )
254 snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
255 if( use_ret == -(POLARSSL_ERR_SSL_PEER_VERIFY_FAILED) )
256 snprintf( buf, buflen, "SSL - Verification of our peer failed" );
257 if( use_ret == -(POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) )
258 snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
259 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO) )
260 snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
261 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO) )
262 snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
263 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE) )
264 snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
265 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
266 snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
267 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
268 snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
269 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
270 snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
271 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
272 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
273 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_RP) )
274 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM Read Public" );
275 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_CS) )
276 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM Calculate Secret" );
277 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
278 snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
279 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
280 snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
281 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_FINISHED) )
282 snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
Paul Bakker732e1a82011-12-11 16:35:09 +0000283 if( use_ret == -(POLARSSL_ERR_SSL_MALLOC_FAILED) )
284 snprintf( buf, buflen, "SSL - Memory allocation failed" );
Paul Bakker831a7552011-05-18 13:32:51 +0000285#endif /* POLARSSL_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000286
287#if defined(POLARSSL_X509_PARSE_C)
288 if( use_ret == -(POLARSSL_ERR_X509_FEATURE_UNAVAILABLE) )
289 snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
290 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_PEM) )
291 snprintf( buf, buflen, "X509 - The PEM-encoded certificate contains invalid elements, e.g. invalid character" );
292 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_FORMAT) )
293 snprintf( buf, buflen, "X509 - The certificate format is invalid, e.g. different type expected" );
294 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_VERSION) )
295 snprintf( buf, buflen, "X509 - The certificate version element is invalid" );
296 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_SERIAL) )
297 snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
298 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_ALG) )
299 snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
300 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_NAME) )
301 snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
302 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_DATE) )
303 snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
304 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_PUBKEY) )
305 snprintf( buf, buflen, "X509 - The pubkey tag or value is invalid (only RSA is supported)" );
306 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE) )
307 snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
308 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS) )
309 snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
310 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION) )
311 snprintf( buf, buflen, "X509 - Certificate or CRL has an unsupported version number" );
312 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG) )
313 snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
Paul Bakker9db77422011-07-13 11:47:32 +0000314 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_PK_ALG) )
315 snprintf( buf, buflen, "X509 - Key algorithm is unsupported (only RSA is supported)" );
Paul Bakker9d781402011-05-09 16:17:09 +0000316 if( use_ret == -(POLARSSL_ERR_X509_CERT_SIG_MISMATCH) )
317 snprintf( buf, buflen, "X509 - Certificate signature algorithms do not match. (see \\c ::x509_cert sig_oid)" );
318 if( use_ret == -(POLARSSL_ERR_X509_CERT_VERIFY_FAILED) )
319 snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
320 if( use_ret == -(POLARSSL_ERR_X509_KEY_INVALID_VERSION) )
321 snprintf( buf, buflen, "X509 - Unsupported RSA key version" );
322 if( use_ret == -(POLARSSL_ERR_X509_KEY_INVALID_FORMAT) )
323 snprintf( buf, buflen, "X509 - Invalid RSA key tag or value" );
Paul Bakker6c0ceb32011-12-04 12:24:18 +0000324 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT) )
325 snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
Paul Bakker732e1a82011-12-11 16:35:09 +0000326 if( use_ret == -(POLARSSL_ERR_X509_INVALID_INPUT) )
327 snprintf( buf, buflen, "X509 - Input invalid" );
328 if( use_ret == -(POLARSSL_ERR_X509_MALLOC_FAILED) )
329 snprintf( buf, buflen, "X509 - Allocation of memory failed" );
330 if( use_ret == -(POLARSSL_ERR_X509_FILE_IO_ERROR) )
331 snprintf( buf, buflen, "X509 - Read/write of file failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000332#endif /* POLARSSL_X509_PARSE_C */
333
334 if( strlen( buf ) == 0 )
335 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
336 }
337
338 use_ret = ret & ~0xFF80;
339
340 if( use_ret == 0 )
341 return;
342
343 // If high level code is present, make a concatenation between both
344 // error strings.
345 //
346 len = strlen( buf );
347
348 if( len > 0 )
349 {
350 if( buflen - len < 5 )
351 return;
352
353 snprintf( buf + len, buflen - len, " : " );
354
355 buf += len + 3;
356 buflen -= len + 3;
357 }
358
359 // Low level error codes
360 //
361#if defined(POLARSSL_AES_C)
362 if( use_ret == -(POLARSSL_ERR_AES_INVALID_KEY_LENGTH) )
363 snprintf( buf, buflen, "AES - Invalid key length" );
364 if( use_ret == -(POLARSSL_ERR_AES_INVALID_INPUT_LENGTH) )
365 snprintf( buf, buflen, "AES - Invalid data input length" );
366#endif /* POLARSSL_AES_C */
367
Paul Bakkerdceecd82011-11-15 16:38:34 +0000368#if defined(POLARSSL_ASN1_PARSE_C)
369 if( use_ret == -(POLARSSL_ERR_ASN1_OUT_OF_DATA) )
370 snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
371 if( use_ret == -(POLARSSL_ERR_ASN1_UNEXPECTED_TAG) )
372 snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
373 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_LENGTH) )
374 snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
375 if( use_ret == -(POLARSSL_ERR_ASN1_LENGTH_MISMATCH) )
376 snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
377 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_DATA) )
378 snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
Paul Bakker732e1a82011-12-11 16:35:09 +0000379 if( use_ret == -(POLARSSL_ERR_ASN1_MALLOC_FAILED) )
380 snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
Paul Bakkerdceecd82011-11-15 16:38:34 +0000381#endif /* POLARSSL_ASN1_PARSE_C */
382
Paul Bakker9d781402011-05-09 16:17:09 +0000383#if defined(POLARSSL_BASE64_C)
384 if( use_ret == -(POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) )
385 snprintf( buf, buflen, "BASE64 - Output buffer too small" );
386 if( use_ret == -(POLARSSL_ERR_BASE64_INVALID_CHARACTER) )
387 snprintf( buf, buflen, "BASE64 - Invalid character in input" );
388#endif /* POLARSSL_BASE64_C */
389
390#if defined(POLARSSL_BIGNUM_C)
391 if( use_ret == -(POLARSSL_ERR_MPI_FILE_IO_ERROR) )
392 snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
393 if( use_ret == -(POLARSSL_ERR_MPI_BAD_INPUT_DATA) )
394 snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
395 if( use_ret == -(POLARSSL_ERR_MPI_INVALID_CHARACTER) )
396 snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
397 if( use_ret == -(POLARSSL_ERR_MPI_BUFFER_TOO_SMALL) )
Paul Bakker732e1a82011-12-11 16:35:09 +0000398 snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
Paul Bakker9d781402011-05-09 16:17:09 +0000399 if( use_ret == -(POLARSSL_ERR_MPI_NEGATIVE_VALUE) )
400 snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
401 if( use_ret == -(POLARSSL_ERR_MPI_DIVISION_BY_ZERO) )
402 snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
403 if( use_ret == -(POLARSSL_ERR_MPI_NOT_ACCEPTABLE) )
404 snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Paul Bakker732e1a82011-12-11 16:35:09 +0000405 if( use_ret == -(POLARSSL_ERR_MPI_MALLOC_FAILED) )
406 snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000407#endif /* POLARSSL_BIGNUM_C */
408
409#if defined(POLARSSL_CAMELLIA_C)
410 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
411 snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
412 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
413 snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
414#endif /* POLARSSL_CAMELLIA_C */
415
Paul Bakker880ac7e2011-11-27 14:50:49 +0000416#if defined(POLARSSL_CTR_DRBG_C)
417 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
418 snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
419 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
420 snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
421 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG) )
422 snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
Paul Bakker732e1a82011-12-11 16:35:09 +0000423 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR) )
424 snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
Paul Bakker880ac7e2011-11-27 14:50:49 +0000425#endif /* POLARSSL_CTR_DRBG_C */
426
Paul Bakker9d781402011-05-09 16:17:09 +0000427#if defined(POLARSSL_DES_C)
428 if( use_ret == -(POLARSSL_ERR_DES_INVALID_INPUT_LENGTH) )
429 snprintf( buf, buflen, "DES - The data input has an invalid length" );
430#endif /* POLARSSL_DES_C */
431
Paul Bakker6083fd22011-12-03 21:45:14 +0000432#if defined(POLARSSL_ENTROPY_C)
433 if( use_ret == -(POLARSSL_ERR_ENTROPY_SOURCE_FAILED) )
434 snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
435 if( use_ret == -(POLARSSL_ERR_ENTROPY_MAX_SOURCES) )
436 snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
Paul Bakkerd567aa22011-12-22 10:06:27 +0000437 if( use_ret == -(POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED) )
438 snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
Paul Bakker6083fd22011-12-03 21:45:14 +0000439#endif /* POLARSSL_ENTROPY_C */
440
Paul Bakker732e1a82011-12-11 16:35:09 +0000441#if defined(POLARSSL_MD2_C)
442 if( use_ret == -(POLARSSL_ERR_MD2_FILE_IO_ERROR) )
443 snprintf( buf, buflen, "MD2 - Read/write error in file" );
444#endif /* POLARSSL_MD2_C */
445
446#if defined(POLARSSL_MD4_C)
447 if( use_ret == -(POLARSSL_ERR_MD4_FILE_IO_ERROR) )
448 snprintf( buf, buflen, "MD4 - Read/write error in file" );
449#endif /* POLARSSL_MD4_C */
450
451#if defined(POLARSSL_MD5_C)
452 if( use_ret == -(POLARSSL_ERR_MD5_FILE_IO_ERROR) )
453 snprintf( buf, buflen, "MD5 - Read/write error in file" );
454#endif /* POLARSSL_MD5_C */
455
Paul Bakker9d781402011-05-09 16:17:09 +0000456#if defined(POLARSSL_NET_C)
457 if( use_ret == -(POLARSSL_ERR_NET_UNKNOWN_HOST) )
458 snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
459 if( use_ret == -(POLARSSL_ERR_NET_SOCKET_FAILED) )
460 snprintf( buf, buflen, "NET - Failed to open a socket" );
461 if( use_ret == -(POLARSSL_ERR_NET_CONNECT_FAILED) )
462 snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
463 if( use_ret == -(POLARSSL_ERR_NET_BIND_FAILED) )
464 snprintf( buf, buflen, "NET - Binding of the socket failed" );
465 if( use_ret == -(POLARSSL_ERR_NET_LISTEN_FAILED) )
466 snprintf( buf, buflen, "NET - Could not listen on the socket" );
467 if( use_ret == -(POLARSSL_ERR_NET_ACCEPT_FAILED) )
468 snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
469 if( use_ret == -(POLARSSL_ERR_NET_RECV_FAILED) )
470 snprintf( buf, buflen, "NET - Reading information from the socket failed" );
471 if( use_ret == -(POLARSSL_ERR_NET_SEND_FAILED) )
472 snprintf( buf, buflen, "NET - Sending information through the socket failed" );
473 if( use_ret == -(POLARSSL_ERR_NET_CONN_RESET) )
474 snprintf( buf, buflen, "NET - Connection was reset by peer" );
Paul Bakker831a7552011-05-18 13:32:51 +0000475 if( use_ret == -(POLARSSL_ERR_NET_WANT_READ) )
476 snprintf( buf, buflen, "NET - Connection requires a read call" );
477 if( use_ret == -(POLARSSL_ERR_NET_WANT_WRITE) )
478 snprintf( buf, buflen, "NET - Connection requires a write call" );
Paul Bakker9d781402011-05-09 16:17:09 +0000479#endif /* POLARSSL_NET_C */
480
481#if defined(POLARSSL_PADLOCK_C)
482 if( use_ret == -(POLARSSL_ERR_PADLOCK_DATA_MISALIGNED) )
483 snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
484#endif /* POLARSSL_PADLOCK_C */
485
Paul Bakker732e1a82011-12-11 16:35:09 +0000486#if defined(POLARSSL_SHA1_C)
487 if( use_ret == -(POLARSSL_ERR_SHA1_FILE_IO_ERROR) )
488 snprintf( buf, buflen, "SHA1 - Read/write error in file" );
489#endif /* POLARSSL_SHA1_C */
490
491#if defined(POLARSSL_SHA2_C)
492 if( use_ret == -(POLARSSL_ERR_SHA2_FILE_IO_ERROR) )
493 snprintf( buf, buflen, "SHA2 - Read/write error in file" );
494#endif /* POLARSSL_SHA2_C */
495
496#if defined(POLARSSL_SHA4_C)
497 if( use_ret == -(POLARSSL_ERR_SHA4_FILE_IO_ERROR) )
498 snprintf( buf, buflen, "SHA4 - Read/write error in file" );
499#endif /* POLARSSL_SHA4_C */
500
Paul Bakker9d781402011-05-09 16:17:09 +0000501#if defined(POLARSSL_XTEA_C)
502 if( use_ret == -(POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH) )
503 snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
504#endif /* POLARSSL_XTEA_C */
505
506 if( strlen( buf ) != 0 )
507 return;
508
509 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
510}
511
512#endif /* POLARSSL_VERBOSE_ERROR */