source: trunk/library/error.c @ 1269

Revision 1269, 24.7 KB checked in by paul, 10 days ago (diff)
  • Added exception error parsing when FATAL ssl message is received
Line 
1/*
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
46#if defined(POLARSSL_CIPHER_C)
47#include "polarssl/cipher.h"
48#endif
49
50#if defined(POLARSSL_CTR_DRBG_C)
51#include "polarssl/ctr_drbg.h"
52#endif
53
54#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
62#if defined(POLARSSL_ENTROPY_C)
63#include "polarssl/entropy.h"
64#endif
65
66#if defined(POLARSSL_GCM_C)
67#include "polarssl/gcm.h"
68#endif
69
70#if defined(POLARSSL_MD_C)
71#include "polarssl/md.h"
72#endif
73
74#if defined(POLARSSL_MD2_C)
75#include "polarssl/md2.h"
76#endif
77
78#if defined(POLARSSL_MD4_C)
79#include "polarssl/md4.h"
80#endif
81
82#if defined(POLARSSL_MD5_C)
83#include "polarssl/md5.h"
84#endif
85
86#if defined(POLARSSL_NET_C)
87#include "polarssl/net.h"
88#endif
89
90#if defined(POLARSSL_PADLOCK_C)
91#include "polarssl/padlock.h"
92#endif
93
94#if defined(POLARSSL_PEM_C)
95#include "polarssl/pem.h"
96#endif
97
98#if defined(POLARSSL_RSA_C)
99#include "polarssl/rsa.h"
100#endif
101
102#if defined(POLARSSL_SHA1_C)
103#include "polarssl/sha1.h"
104#endif
105
106#if defined(POLARSSL_SHA2_C)
107#include "polarssl/sha2.h"
108#endif
109
110#if defined(POLARSSL_SHA4_C)
111#include "polarssl/sha4.h"
112#endif
113
114#if defined(POLARSSL_SSL_TLS_C)
115#include "polarssl/ssl.h"
116#endif
117
118#if defined(POLARSSL_X509_PARSE_C)
119#include "polarssl/x509.h"
120#endif
121
122#if defined(POLARSSL_XTEA_C)
123#include "polarssl/xtea.h"
124#endif
125
126
127#include <string.h>
128
129#if defined _MSC_VER && !defined  snprintf
130#define  snprintf  _snprintf
131#endif
132
133void error_strerror( int ret, char *buf, size_t buflen )
134{
135    size_t len;
136    int use_ret;
137
138    memset( buf, 0x00, buflen );
139     
140    if( ret < 0 )
141        ret = -ret;
142
143    if( ret & 0xFF80 )
144    {
145        use_ret = ret & 0xFF80;
146
147        // High level error codes
148        //
149#if defined(POLARSSL_CIPHER_C)
150        if( use_ret == -(POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE) )
151            snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
152        if( use_ret == -(POLARSSL_ERR_CIPHER_BAD_INPUT_DATA) )
153            snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
154        if( use_ret == -(POLARSSL_ERR_CIPHER_ALLOC_FAILED) )
155            snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
156        if( use_ret == -(POLARSSL_ERR_CIPHER_INVALID_PADDING) )
157            snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
158        if( use_ret == -(POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
159            snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
160#endif /* POLARSSL_CIPHER_C */
161
162#if defined(POLARSSL_DHM_C)
163        if( use_ret == -(POLARSSL_ERR_DHM_BAD_INPUT_DATA) )
164            snprintf( buf, buflen, "DHM - Bad input parameters to function" );
165        if( use_ret == -(POLARSSL_ERR_DHM_READ_PARAMS_FAILED) )
166            snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
167        if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PARAMS_FAILED) )
168            snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
169        if( use_ret == -(POLARSSL_ERR_DHM_READ_PUBLIC_FAILED) )
170            snprintf( buf, buflen, "DHM - Reading of the public values failed" );
171        if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PUBLIC_FAILED) )
172            snprintf( buf, buflen, "DHM - Making of the public value failed" );
173        if( use_ret == -(POLARSSL_ERR_DHM_CALC_SECRET_FAILED) )
174            snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
175#endif /* POLARSSL_DHM_C */
176
177#if defined(POLARSSL_MD_C)
178        if( use_ret == -(POLARSSL_ERR_MD_FEATURE_UNAVAILABLE) )
179            snprintf( buf, buflen, "MD - The selected feature is not available" );
180        if( use_ret == -(POLARSSL_ERR_MD_BAD_INPUT_DATA) )
181            snprintf( buf, buflen, "MD - Bad input parameters to function" );
182        if( use_ret == -(POLARSSL_ERR_MD_ALLOC_FAILED) )
183            snprintf( buf, buflen, "MD - Failed to allocate memory" );
184        if( use_ret == -(POLARSSL_ERR_MD_FILE_IO_ERROR) )
185            snprintf( buf, buflen, "MD - Opening or reading of file failed" );
186#endif /* POLARSSL_MD_C */
187
188#if defined(POLARSSL_PEM_C)
189        if( use_ret == -(POLARSSL_ERR_PEM_NO_HEADER_PRESENT) )
190            snprintf( buf, buflen, "PEM - No PEM header found" );
191        if( use_ret == -(POLARSSL_ERR_PEM_INVALID_DATA) )
192            snprintf( buf, buflen, "PEM - PEM string is not as expected" );
193        if( use_ret == -(POLARSSL_ERR_PEM_MALLOC_FAILED) )
194            snprintf( buf, buflen, "PEM - Failed to allocate memory" );
195        if( use_ret == -(POLARSSL_ERR_PEM_INVALID_ENC_IV) )
196            snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
197        if( use_ret == -(POLARSSL_ERR_PEM_UNKNOWN_ENC_ALG) )
198            snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
199        if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_REQUIRED) )
200            snprintf( buf, buflen, "PEM - Private key password can't be empty" );
201        if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_MISMATCH) )
202            snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
203        if( use_ret == -(POLARSSL_ERR_PEM_FEATURE_UNAVAILABLE) )
204            snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
205#endif /* POLARSSL_PEM_C */
206
207#if defined(POLARSSL_RSA_C)
208        if( use_ret == -(POLARSSL_ERR_RSA_BAD_INPUT_DATA) )
209            snprintf( buf, buflen, "RSA - Bad input parameters to function" );
210        if( use_ret == -(POLARSSL_ERR_RSA_INVALID_PADDING) )
211            snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
212        if( use_ret == -(POLARSSL_ERR_RSA_KEY_GEN_FAILED) )
213            snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
214        if( use_ret == -(POLARSSL_ERR_RSA_KEY_CHECK_FAILED) )
215            snprintf( buf, buflen, "RSA - Key failed to pass the libraries validity check" );
216        if( use_ret == -(POLARSSL_ERR_RSA_PUBLIC_FAILED) )
217            snprintf( buf, buflen, "RSA - The public key operation failed" );
218        if( use_ret == -(POLARSSL_ERR_RSA_PRIVATE_FAILED) )
219            snprintf( buf, buflen, "RSA - The private key operation failed" );
220        if( use_ret == -(POLARSSL_ERR_RSA_VERIFY_FAILED) )
221            snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
222        if( use_ret == -(POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE) )
223            snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
224        if( use_ret == -(POLARSSL_ERR_RSA_RNG_FAILED) )
225            snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
226#endif /* POLARSSL_RSA_C */
227
228#if defined(POLARSSL_SSL_TLS_C)
229        if( use_ret == -(POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE) )
230            snprintf( buf, buflen, "SSL - The requested feature is not available" );
231        if( use_ret == -(POLARSSL_ERR_SSL_BAD_INPUT_DATA) )
232            snprintf( buf, buflen, "SSL - Bad input parameters to function" );
233        if( use_ret == -(POLARSSL_ERR_SSL_INVALID_MAC) )
234            snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
235        if( use_ret == -(POLARSSL_ERR_SSL_INVALID_RECORD) )
236            snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
237        if( use_ret == -(POLARSSL_ERR_SSL_CONN_EOF) )
238            snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
239        if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_CIPHER) )
240            snprintf( buf, buflen, "SSL - An unknown cipher was received" );
241        if( use_ret == -(POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN) )
242            snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
243        if( use_ret == -(POLARSSL_ERR_SSL_NO_SESSION_FOUND) )
244            snprintf( buf, buflen, "SSL - No session to recover was found" );
245        if( use_ret == -(POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE) )
246            snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
247        if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE) )
248            snprintf( buf, buflen, "SSL - DESCRIPTION MISSING" );
249        if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED) )
250            snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
251        if( use_ret == -(POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED) )
252            snprintf( buf, buflen, "SSL - The own private key is not set, but needed" );
253        if( use_ret == -(POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED) )
254            snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
255        if( use_ret == -(POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE) )
256            snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
257        if( use_ret == -(POLARSSL_ERR_SSL_FATAL_ALERT_MESSAGE) )
258        {
259            snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
260            return;
261        }
262        if( use_ret == -(POLARSSL_ERR_SSL_PEER_VERIFY_FAILED) )
263            snprintf( buf, buflen, "SSL - Verification of our peer failed" );
264        if( use_ret == -(POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) )
265            snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
266        if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO) )
267            snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
268        if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO) )
269            snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
270        if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE) )
271            snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
272        if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
273            snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
274        if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
275            snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
276        if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
277            snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
278        if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
279            snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
280        if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_RP) )
281            snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM Read Public" );
282        if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_CS) )
283            snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM Calculate Secret" );
284        if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
285            snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
286        if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
287            snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
288        if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_FINISHED) )
289            snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
290        if( use_ret == -(POLARSSL_ERR_SSL_MALLOC_FAILED) )
291            snprintf( buf, buflen, "SSL - Memory allocation failed" );
292        if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FAILED) )
293            snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
294        if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
295            snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
296#endif /* POLARSSL_SSL_TLS_C */
297
298#if defined(POLARSSL_X509_PARSE_C)
299        if( use_ret == -(POLARSSL_ERR_X509_FEATURE_UNAVAILABLE) )
300            snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
301        if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_PEM) )
302            snprintf( buf, buflen, "X509 - The PEM-encoded certificate contains invalid elements, e.g. invalid character" );
303        if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_FORMAT) )
304            snprintf( buf, buflen, "X509 - The certificate format is invalid, e.g. different type expected" );
305        if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_VERSION) )
306            snprintf( buf, buflen, "X509 - The certificate version element is invalid" );
307        if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_SERIAL) )
308            snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
309        if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_ALG) )
310            snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
311        if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_NAME) )
312            snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
313        if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_DATE) )
314            snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
315        if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_PUBKEY) )
316            snprintf( buf, buflen, "X509 - The pubkey tag or value is invalid (only RSA is supported)" );
317        if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE) )
318            snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
319        if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS) )
320            snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
321        if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION) )
322            snprintf( buf, buflen, "X509 - Certificate or CRL has an unsupported version number" );
323        if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG) )
324            snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
325        if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_PK_ALG) )
326            snprintf( buf, buflen, "X509 - Key algorithm is unsupported (only RSA is supported)" );
327        if( use_ret == -(POLARSSL_ERR_X509_CERT_SIG_MISMATCH) )
328            snprintf( buf, buflen, "X509 - Certificate signature algorithms do not match. (see \\c ::x509_cert sig_oid)" );
329        if( use_ret == -(POLARSSL_ERR_X509_CERT_VERIFY_FAILED) )
330            snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
331        if( use_ret == -(POLARSSL_ERR_X509_KEY_INVALID_VERSION) )
332            snprintf( buf, buflen, "X509 - Unsupported RSA key version" );
333        if( use_ret == -(POLARSSL_ERR_X509_KEY_INVALID_FORMAT) )
334            snprintf( buf, buflen, "X509 - Invalid RSA key tag or value" );
335        if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT) )
336            snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
337        if( use_ret == -(POLARSSL_ERR_X509_INVALID_INPUT) )
338            snprintf( buf, buflen, "X509 - Input invalid" );
339        if( use_ret == -(POLARSSL_ERR_X509_MALLOC_FAILED) )
340            snprintf( buf, buflen, "X509 - Allocation of memory failed" );
341        if( use_ret == -(POLARSSL_ERR_X509_FILE_IO_ERROR) )
342            snprintf( buf, buflen, "X509 - Read/write of file failed" );
343#endif /* POLARSSL_X509_PARSE_C */
344
345        if( strlen( buf ) == 0 )
346            snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
347    }
348
349    use_ret = ret & ~0xFF80;
350
351    if( use_ret == 0 )
352        return;
353
354    // If high level code is present, make a concatenation between both
355    // error strings.
356    //
357    len = strlen( buf );
358
359    if( len > 0 )
360    {
361        if( buflen - len < 5 )
362            return;
363
364        snprintf( buf + len, buflen - len, " : " );
365
366        buf += len + 3;
367        buflen -= len + 3;
368    }
369
370    // Low level error codes
371    //
372#if defined(POLARSSL_AES_C)
373    if( use_ret == -(POLARSSL_ERR_AES_INVALID_KEY_LENGTH) )
374        snprintf( buf, buflen, "AES - Invalid key length" );
375    if( use_ret == -(POLARSSL_ERR_AES_INVALID_INPUT_LENGTH) )
376        snprintf( buf, buflen, "AES - Invalid data input length" );
377#endif /* POLARSSL_AES_C */
378
379#if defined(POLARSSL_ASN1_PARSE_C)
380    if( use_ret == -(POLARSSL_ERR_ASN1_OUT_OF_DATA) )
381        snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
382    if( use_ret == -(POLARSSL_ERR_ASN1_UNEXPECTED_TAG) )
383        snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
384    if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_LENGTH) )
385        snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
386    if( use_ret == -(POLARSSL_ERR_ASN1_LENGTH_MISMATCH) )
387        snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
388    if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_DATA) )
389        snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
390    if( use_ret == -(POLARSSL_ERR_ASN1_MALLOC_FAILED) )
391        snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
392    if( use_ret == -(POLARSSL_ERR_ASN1_BUF_TOO_SMALL) )
393        snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
394#endif /* POLARSSL_ASN1_PARSE_C */
395
396#if defined(POLARSSL_BASE64_C)
397    if( use_ret == -(POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) )
398        snprintf( buf, buflen, "BASE64 - Output buffer too small" );
399    if( use_ret == -(POLARSSL_ERR_BASE64_INVALID_CHARACTER) )
400        snprintf( buf, buflen, "BASE64 - Invalid character in input" );
401#endif /* POLARSSL_BASE64_C */
402
403#if defined(POLARSSL_BIGNUM_C)
404    if( use_ret == -(POLARSSL_ERR_MPI_FILE_IO_ERROR) )
405        snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
406    if( use_ret == -(POLARSSL_ERR_MPI_BAD_INPUT_DATA) )
407        snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
408    if( use_ret == -(POLARSSL_ERR_MPI_INVALID_CHARACTER) )
409        snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
410    if( use_ret == -(POLARSSL_ERR_MPI_BUFFER_TOO_SMALL) )
411        snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
412    if( use_ret == -(POLARSSL_ERR_MPI_NEGATIVE_VALUE) )
413        snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
414    if( use_ret == -(POLARSSL_ERR_MPI_DIVISION_BY_ZERO) )
415        snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
416    if( use_ret == -(POLARSSL_ERR_MPI_NOT_ACCEPTABLE) )
417        snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
418    if( use_ret == -(POLARSSL_ERR_MPI_MALLOC_FAILED) )
419        snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
420#endif /* POLARSSL_BIGNUM_C */
421
422#if defined(POLARSSL_CAMELLIA_C)
423    if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
424        snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
425    if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
426        snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
427#endif /* POLARSSL_CAMELLIA_C */
428
429#if defined(POLARSSL_CTR_DRBG_C)
430    if( use_ret == -(POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
431        snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
432    if( use_ret == -(POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
433        snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
434    if( use_ret == -(POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG) )
435        snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
436    if( use_ret == -(POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR) )
437        snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
438#endif /* POLARSSL_CTR_DRBG_C */
439
440#if defined(POLARSSL_DES_C)
441    if( use_ret == -(POLARSSL_ERR_DES_INVALID_INPUT_LENGTH) )
442        snprintf( buf, buflen, "DES - The data input has an invalid length" );
443#endif /* POLARSSL_DES_C */
444
445#if defined(POLARSSL_ENTROPY_C)
446    if( use_ret == -(POLARSSL_ERR_ENTROPY_SOURCE_FAILED) )
447        snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
448    if( use_ret == -(POLARSSL_ERR_ENTROPY_MAX_SOURCES) )
449        snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
450    if( use_ret == -(POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED) )
451        snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
452#endif /* POLARSSL_ENTROPY_C */
453
454#if defined(POLARSSL_GCM_C)
455    if( use_ret == -(POLARSSL_ERR_GCM_AUTH_FAILED) )
456        snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
457    if( use_ret == -(POLARSSL_ERR_GCM_BAD_INPUT) )
458        snprintf( buf, buflen, "GCM - Bad input parameters to function" );
459#endif /* POLARSSL_GCM_C */
460
461#if defined(POLARSSL_MD2_C)
462    if( use_ret == -(POLARSSL_ERR_MD2_FILE_IO_ERROR) )
463        snprintf( buf, buflen, "MD2 - Read/write error in file" );
464#endif /* POLARSSL_MD2_C */
465
466#if defined(POLARSSL_MD4_C)
467    if( use_ret == -(POLARSSL_ERR_MD4_FILE_IO_ERROR) )
468        snprintf( buf, buflen, "MD4 - Read/write error in file" );
469#endif /* POLARSSL_MD4_C */
470
471#if defined(POLARSSL_MD5_C)
472    if( use_ret == -(POLARSSL_ERR_MD5_FILE_IO_ERROR) )
473        snprintf( buf, buflen, "MD5 - Read/write error in file" );
474#endif /* POLARSSL_MD5_C */
475
476#if defined(POLARSSL_NET_C)
477    if( use_ret == -(POLARSSL_ERR_NET_UNKNOWN_HOST) )
478        snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
479    if( use_ret == -(POLARSSL_ERR_NET_SOCKET_FAILED) )
480        snprintf( buf, buflen, "NET - Failed to open a socket" );
481    if( use_ret == -(POLARSSL_ERR_NET_CONNECT_FAILED) )
482        snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
483    if( use_ret == -(POLARSSL_ERR_NET_BIND_FAILED) )
484        snprintf( buf, buflen, "NET - Binding of the socket failed" );
485    if( use_ret == -(POLARSSL_ERR_NET_LISTEN_FAILED) )
486        snprintf( buf, buflen, "NET - Could not listen on the socket" );
487    if( use_ret == -(POLARSSL_ERR_NET_ACCEPT_FAILED) )
488        snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
489    if( use_ret == -(POLARSSL_ERR_NET_RECV_FAILED) )
490        snprintf( buf, buflen, "NET - Reading information from the socket failed" );
491    if( use_ret == -(POLARSSL_ERR_NET_SEND_FAILED) )
492        snprintf( buf, buflen, "NET - Sending information through the socket failed" );
493    if( use_ret == -(POLARSSL_ERR_NET_CONN_RESET) )
494        snprintf( buf, buflen, "NET - Connection was reset by peer" );
495    if( use_ret == -(POLARSSL_ERR_NET_WANT_READ) )
496        snprintf( buf, buflen, "NET - Connection requires a read call" );
497    if( use_ret == -(POLARSSL_ERR_NET_WANT_WRITE) )
498        snprintf( buf, buflen, "NET - Connection requires a write call" );
499#endif /* POLARSSL_NET_C */
500
501#if defined(POLARSSL_PADLOCK_C)
502    if( use_ret == -(POLARSSL_ERR_PADLOCK_DATA_MISALIGNED) )
503        snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
504#endif /* POLARSSL_PADLOCK_C */
505
506#if defined(POLARSSL_SHA1_C)
507    if( use_ret == -(POLARSSL_ERR_SHA1_FILE_IO_ERROR) )
508        snprintf( buf, buflen, "SHA1 - Read/write error in file" );
509#endif /* POLARSSL_SHA1_C */
510
511#if defined(POLARSSL_SHA2_C)
512    if( use_ret == -(POLARSSL_ERR_SHA2_FILE_IO_ERROR) )
513        snprintf( buf, buflen, "SHA2 - Read/write error in file" );
514#endif /* POLARSSL_SHA2_C */
515
516#if defined(POLARSSL_SHA4_C)
517    if( use_ret == -(POLARSSL_ERR_SHA4_FILE_IO_ERROR) )
518        snprintf( buf, buflen, "SHA4 - Read/write error in file" );
519#endif /* POLARSSL_SHA4_C */
520
521#if defined(POLARSSL_XTEA_C)
522    if( use_ret == -(POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH) )
523        snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
524#endif /* POLARSSL_XTEA_C */
525
526    if( strlen( buf ) != 0 )
527        return;
528
529    snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
530}
531
532#endif /* POLARSSL_VERBOSE_ERROR */
Note: See TracBrowser for help on using the repository browser.

What are you looking for?