blob: d5ad61754318e0e056e3a321bbe1793a3166647f [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
70#if defined(POLARSSL_NET_C)
71#include "polarssl/net.h"
72#endif
73
74#if defined(POLARSSL_PADLOCK_C)
75#include "polarssl/padlock.h"
76#endif
77
78#if defined(POLARSSL_PEM_C)
79#include "polarssl/pem.h"
80#endif
81
82#if defined(POLARSSL_RSA_C)
83#include "polarssl/rsa.h"
84#endif
85
Paul Bakker831a7552011-05-18 13:32:51 +000086#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +000087#include "polarssl/ssl.h"
88#endif
89
90#if defined(POLARSSL_X509_PARSE_C)
91#include "polarssl/x509.h"
92#endif
93
94#if defined(POLARSSL_XTEA_C)
95#include "polarssl/xtea.h"
96#endif
97
98
99#include <string.h>
100
Paul Bakkerdceecd82011-11-15 16:38:34 +0000101#if defined _MSC_VER && !defined snprintf
102#define snprintf _snprintf
103#endif
104
Paul Bakker9d781402011-05-09 16:17:09 +0000105void error_strerror( int ret, char *buf, size_t buflen )
106{
107 size_t len;
108 int use_ret;
109
110 memset( buf, 0x00, buflen );
111
112 if( ret < 0 )
113 ret = -ret;
114
115 if( ret & 0xFF80 )
116 {
117 use_ret = ret & 0xFF80;
118
119 // High level error codes
120 //
Paul Bakkerff61a782011-06-09 15:42:02 +0000121#if defined(POLARSSL_CIPHER_C)
122 if( use_ret == -(POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE) )
123 snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
124 if( use_ret == -(POLARSSL_ERR_CIPHER_BAD_INPUT_DATA) )
125 snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
126 if( use_ret == -(POLARSSL_ERR_CIPHER_ALLOC_FAILED) )
127 snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
128 if( use_ret == -(POLARSSL_ERR_CIPHER_INVALID_PADDING) )
129 snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
130 if( use_ret == -(POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
131 snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
132#endif /* POLARSSL_CIPHER_C */
133
Paul Bakker9d781402011-05-09 16:17:09 +0000134#if defined(POLARSSL_DHM_C)
135 if( use_ret == -(POLARSSL_ERR_DHM_BAD_INPUT_DATA) )
136 snprintf( buf, buflen, "DHM - Bad input parameters to function" );
137 if( use_ret == -(POLARSSL_ERR_DHM_READ_PARAMS_FAILED) )
138 snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
139 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PARAMS_FAILED) )
140 snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
141 if( use_ret == -(POLARSSL_ERR_DHM_READ_PUBLIC_FAILED) )
142 snprintf( buf, buflen, "DHM - Reading of the public values failed" );
143 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PUBLIC_FAILED) )
144 snprintf( buf, buflen, "DHM - Makeing of the public value failed" );
145 if( use_ret == -(POLARSSL_ERR_DHM_CALC_SECRET_FAILED) )
146 snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
147#endif /* POLARSSL_DHM_C */
148
149#if defined(POLARSSL_MD_C)
150 if( use_ret == -(POLARSSL_ERR_MD_FEATURE_UNAVAILABLE) )
151 snprintf( buf, buflen, "MD - The selected feature is not available" );
Paul Bakker9c021ad2011-06-09 15:55:11 +0000152 if( use_ret == -(POLARSSL_ERR_MD_BAD_INPUT_DATA) )
153 snprintf( buf, buflen, "MD - Bad input parameters to function" );
154 if( use_ret == -(POLARSSL_ERR_MD_ALLOC_FAILED) )
155 snprintf( buf, buflen, "MD - Failed to allocate memory" );
156 if( use_ret == -(POLARSSL_ERR_MD_FILE_OPEN_FAILED) )
157 snprintf( buf, buflen, "MD - Opening of file failed" );
158 if( use_ret == -(POLARSSL_ERR_MD_FILE_READ_FAILED) )
159 snprintf( buf, buflen, "MD - Failure when reading from file" );
Paul Bakker9d781402011-05-09 16:17:09 +0000160#endif /* POLARSSL_MD_C */
161
162#if defined(POLARSSL_PEM_C)
163 if( use_ret == -(POLARSSL_ERR_PEM_NO_HEADER_PRESENT) )
164 snprintf( buf, buflen, "PEM - No PEM header found" );
165 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_DATA) )
166 snprintf( buf, buflen, "PEM - PEM string is not as expected" );
167 if( use_ret == -(POLARSSL_ERR_PEM_MALLOC_FAILED) )
168 snprintf( buf, buflen, "PEM - Failed to allocate memory" );
169 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_ENC_IV) )
170 snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
171 if( use_ret == -(POLARSSL_ERR_PEM_UNKNOWN_ENC_ALG) )
172 snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
173 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_REQUIRED) )
174 snprintf( buf, buflen, "PEM - Private key password can't be empty" );
175 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_MISMATCH) )
176 snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
177 if( use_ret == -(POLARSSL_ERR_PEM_FEATURE_UNAVAILABLE) )
178 snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
179#endif /* POLARSSL_PEM_C */
180
181#if defined(POLARSSL_RSA_C)
182 if( use_ret == -(POLARSSL_ERR_RSA_BAD_INPUT_DATA) )
183 snprintf( buf, buflen, "RSA - Bad input parameters to function" );
184 if( use_ret == -(POLARSSL_ERR_RSA_INVALID_PADDING) )
185 snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
186 if( use_ret == -(POLARSSL_ERR_RSA_KEY_GEN_FAILED) )
187 snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
188 if( use_ret == -(POLARSSL_ERR_RSA_KEY_CHECK_FAILED) )
189 snprintf( buf, buflen, "RSA - Key failed to pass the libraries validity check" );
190 if( use_ret == -(POLARSSL_ERR_RSA_PUBLIC_FAILED) )
191 snprintf( buf, buflen, "RSA - The public key operation failed" );
192 if( use_ret == -(POLARSSL_ERR_RSA_PRIVATE_FAILED) )
193 snprintf( buf, buflen, "RSA - The private key operation failed" );
194 if( use_ret == -(POLARSSL_ERR_RSA_VERIFY_FAILED) )
195 snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
196 if( use_ret == -(POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE) )
197 snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
198 if( use_ret == -(POLARSSL_ERR_RSA_RNG_FAILED) )
199 snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
200#endif /* POLARSSL_RSA_C */
201
Paul Bakker831a7552011-05-18 13:32:51 +0000202#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000203 if( use_ret == -(POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE) )
204 snprintf( buf, buflen, "SSL - The requested feature is not available" );
205 if( use_ret == -(POLARSSL_ERR_SSL_BAD_INPUT_DATA) )
206 snprintf( buf, buflen, "SSL - Bad input parameters to function" );
207 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_MAC) )
208 snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
209 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_RECORD) )
210 snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
Paul Bakker831a7552011-05-18 13:32:51 +0000211 if( use_ret == -(POLARSSL_ERR_SSL_CONN_EOF) )
212 snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
Paul Bakker9d781402011-05-09 16:17:09 +0000213 if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_CIPHER) )
214 snprintf( buf, buflen, "SSL - An unknown cipher was received" );
215 if( use_ret == -(POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN) )
216 snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
217 if( use_ret == -(POLARSSL_ERR_SSL_NO_SESSION_FOUND) )
218 snprintf( buf, buflen, "SSL - No session to recover was found" );
219 if( use_ret == -(POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE) )
220 snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
221 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE) )
222 snprintf( buf, buflen, "SSL - DESCRIPTION MISSING" );
223 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED) )
224 snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
225 if( use_ret == -(POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED) )
226 snprintf( buf, buflen, "SSL - The own private key is not set, but needed" );
227 if( use_ret == -(POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED) )
228 snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
229 if( use_ret == -(POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE) )
230 snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
231 if( use_ret == -(POLARSSL_ERR_SSL_FATAL_ALERT_MESSAGE) )
232 snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
233 if( use_ret == -(POLARSSL_ERR_SSL_PEER_VERIFY_FAILED) )
234 snprintf( buf, buflen, "SSL - Verification of our peer failed" );
235 if( use_ret == -(POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) )
236 snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
237 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO) )
238 snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
239 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO) )
240 snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
241 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE) )
242 snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
243 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
244 snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
245 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
246 snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
247 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
248 snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
249 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
250 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
251 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_RP) )
252 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM Read Public" );
253 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_CS) )
254 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM Calculate Secret" );
255 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
256 snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
257 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
258 snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
259 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_FINISHED) )
260 snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
Paul Bakker831a7552011-05-18 13:32:51 +0000261#endif /* POLARSSL_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000262
263#if defined(POLARSSL_X509_PARSE_C)
264 if( use_ret == -(POLARSSL_ERR_X509_FEATURE_UNAVAILABLE) )
265 snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
266 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_PEM) )
267 snprintf( buf, buflen, "X509 - The PEM-encoded certificate contains invalid elements, e.g. invalid character" );
268 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_FORMAT) )
269 snprintf( buf, buflen, "X509 - The certificate format is invalid, e.g. different type expected" );
270 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_VERSION) )
271 snprintf( buf, buflen, "X509 - The certificate version element is invalid" );
272 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_SERIAL) )
273 snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
274 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_ALG) )
275 snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
276 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_NAME) )
277 snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
278 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_DATE) )
279 snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
280 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_PUBKEY) )
281 snprintf( buf, buflen, "X509 - The pubkey tag or value is invalid (only RSA is supported)" );
282 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE) )
283 snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
284 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS) )
285 snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
286 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION) )
287 snprintf( buf, buflen, "X509 - Certificate or CRL has an unsupported version number" );
288 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG) )
289 snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
Paul Bakker9db77422011-07-13 11:47:32 +0000290 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_PK_ALG) )
291 snprintf( buf, buflen, "X509 - Key algorithm is unsupported (only RSA is supported)" );
Paul Bakker9d781402011-05-09 16:17:09 +0000292 if( use_ret == -(POLARSSL_ERR_X509_CERT_SIG_MISMATCH) )
293 snprintf( buf, buflen, "X509 - Certificate signature algorithms do not match. (see \\c ::x509_cert sig_oid)" );
294 if( use_ret == -(POLARSSL_ERR_X509_CERT_VERIFY_FAILED) )
295 snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
296 if( use_ret == -(POLARSSL_ERR_X509_KEY_INVALID_VERSION) )
297 snprintf( buf, buflen, "X509 - Unsupported RSA key version" );
298 if( use_ret == -(POLARSSL_ERR_X509_KEY_INVALID_FORMAT) )
299 snprintf( buf, buflen, "X509 - Invalid RSA key tag or value" );
300 if( use_ret == -(POLARSSL_ERR_X509_POINT_ERROR) )
301 snprintf( buf, buflen, "X509 - Not used" );
302 if( use_ret == -(POLARSSL_ERR_X509_VALUE_TO_LENGTH) )
303 snprintf( buf, buflen, "X509 - Not used" );
304#endif /* POLARSSL_X509_PARSE_C */
305
306 if( strlen( buf ) == 0 )
307 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
308 }
309
310 use_ret = ret & ~0xFF80;
311
312 if( use_ret == 0 )
313 return;
314
315 // If high level code is present, make a concatenation between both
316 // error strings.
317 //
318 len = strlen( buf );
319
320 if( len > 0 )
321 {
322 if( buflen - len < 5 )
323 return;
324
325 snprintf( buf + len, buflen - len, " : " );
326
327 buf += len + 3;
328 buflen -= len + 3;
329 }
330
331 // Low level error codes
332 //
333#if defined(POLARSSL_AES_C)
334 if( use_ret == -(POLARSSL_ERR_AES_INVALID_KEY_LENGTH) )
335 snprintf( buf, buflen, "AES - Invalid key length" );
336 if( use_ret == -(POLARSSL_ERR_AES_INVALID_INPUT_LENGTH) )
337 snprintf( buf, buflen, "AES - Invalid data input length" );
338#endif /* POLARSSL_AES_C */
339
Paul Bakkerdceecd82011-11-15 16:38:34 +0000340#if defined(POLARSSL_ASN1_PARSE_C)
341 if( use_ret == -(POLARSSL_ERR_ASN1_OUT_OF_DATA) )
342 snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
343 if( use_ret == -(POLARSSL_ERR_ASN1_UNEXPECTED_TAG) )
344 snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
345 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_LENGTH) )
346 snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
347 if( use_ret == -(POLARSSL_ERR_ASN1_LENGTH_MISMATCH) )
348 snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
349 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_DATA) )
350 snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
351#endif /* POLARSSL_ASN1_PARSE_C */
352
Paul Bakker9d781402011-05-09 16:17:09 +0000353#if defined(POLARSSL_BASE64_C)
354 if( use_ret == -(POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) )
355 snprintf( buf, buflen, "BASE64 - Output buffer too small" );
356 if( use_ret == -(POLARSSL_ERR_BASE64_INVALID_CHARACTER) )
357 snprintf( buf, buflen, "BASE64 - Invalid character in input" );
358#endif /* POLARSSL_BASE64_C */
359
360#if defined(POLARSSL_BIGNUM_C)
361 if( use_ret == -(POLARSSL_ERR_MPI_FILE_IO_ERROR) )
362 snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
363 if( use_ret == -(POLARSSL_ERR_MPI_BAD_INPUT_DATA) )
364 snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
365 if( use_ret == -(POLARSSL_ERR_MPI_INVALID_CHARACTER) )
366 snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
367 if( use_ret == -(POLARSSL_ERR_MPI_BUFFER_TOO_SMALL) )
368 snprintf( buf, buflen, "BIGNUM - The output buffer is too small to write too" );
369 if( use_ret == -(POLARSSL_ERR_MPI_NEGATIVE_VALUE) )
370 snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
371 if( use_ret == -(POLARSSL_ERR_MPI_DIVISION_BY_ZERO) )
372 snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
373 if( use_ret == -(POLARSSL_ERR_MPI_NOT_ACCEPTABLE) )
374 snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
375#endif /* POLARSSL_BIGNUM_C */
376
377#if defined(POLARSSL_CAMELLIA_C)
378 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
379 snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
380 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
381 snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
382#endif /* POLARSSL_CAMELLIA_C */
383
Paul Bakker880ac7e2011-11-27 14:50:49 +0000384#if defined(POLARSSL_CTR_DRBG_C)
385 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
386 snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
387 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
388 snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
389 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG) )
390 snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
391#endif /* POLARSSL_CTR_DRBG_C */
392
Paul Bakker9d781402011-05-09 16:17:09 +0000393#if defined(POLARSSL_DES_C)
394 if( use_ret == -(POLARSSL_ERR_DES_INVALID_INPUT_LENGTH) )
395 snprintf( buf, buflen, "DES - The data input has an invalid length" );
396#endif /* POLARSSL_DES_C */
397
Paul Bakker6083fd22011-12-03 21:45:14 +0000398#if defined(POLARSSL_ENTROPY_C)
399 if( use_ret == -(POLARSSL_ERR_ENTROPY_SOURCE_FAILED) )
400 snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
401 if( use_ret == -(POLARSSL_ERR_ENTROPY_MAX_SOURCES) )
402 snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
403#endif /* POLARSSL_ENTROPY_C */
404
Paul Bakker9d781402011-05-09 16:17:09 +0000405#if defined(POLARSSL_NET_C)
406 if( use_ret == -(POLARSSL_ERR_NET_UNKNOWN_HOST) )
407 snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
408 if( use_ret == -(POLARSSL_ERR_NET_SOCKET_FAILED) )
409 snprintf( buf, buflen, "NET - Failed to open a socket" );
410 if( use_ret == -(POLARSSL_ERR_NET_CONNECT_FAILED) )
411 snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
412 if( use_ret == -(POLARSSL_ERR_NET_BIND_FAILED) )
413 snprintf( buf, buflen, "NET - Binding of the socket failed" );
414 if( use_ret == -(POLARSSL_ERR_NET_LISTEN_FAILED) )
415 snprintf( buf, buflen, "NET - Could not listen on the socket" );
416 if( use_ret == -(POLARSSL_ERR_NET_ACCEPT_FAILED) )
417 snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
418 if( use_ret == -(POLARSSL_ERR_NET_RECV_FAILED) )
419 snprintf( buf, buflen, "NET - Reading information from the socket failed" );
420 if( use_ret == -(POLARSSL_ERR_NET_SEND_FAILED) )
421 snprintf( buf, buflen, "NET - Sending information through the socket failed" );
422 if( use_ret == -(POLARSSL_ERR_NET_CONN_RESET) )
423 snprintf( buf, buflen, "NET - Connection was reset by peer" );
Paul Bakker831a7552011-05-18 13:32:51 +0000424 if( use_ret == -(POLARSSL_ERR_NET_WANT_READ) )
425 snprintf( buf, buflen, "NET - Connection requires a read call" );
426 if( use_ret == -(POLARSSL_ERR_NET_WANT_WRITE) )
427 snprintf( buf, buflen, "NET - Connection requires a write call" );
Paul Bakker9d781402011-05-09 16:17:09 +0000428#endif /* POLARSSL_NET_C */
429
430#if defined(POLARSSL_PADLOCK_C)
431 if( use_ret == -(POLARSSL_ERR_PADLOCK_DATA_MISALIGNED) )
432 snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
433#endif /* POLARSSL_PADLOCK_C */
434
Paul Bakker9d781402011-05-09 16:17:09 +0000435#if defined(POLARSSL_XTEA_C)
436 if( use_ret == -(POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH) )
437 snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
438#endif /* POLARSSL_XTEA_C */
439
440 if( strlen( buf ) != 0 )
441 return;
442
443 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
444}
445
446#endif /* POLARSSL_VERBOSE_ERROR */