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