blob: 3f717481a0207f1d8ecbdb70878e4ebb5beaca77 [file] [log] [blame]
Paul Bakker9d781402011-05-09 16:17:09 +00001/*
2 * Error message information
3 *
Paul Bakker9a736322012-11-14 12:39:52 +00004 * Copyright (C) 2006-2012, Brainspark B.V.
Paul Bakker9d781402011-05-09 16:17:09 +00005 *
6 * This file is part of PolarSSL (http://www.polarssl.org)
7 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
8 *
9 * All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 */
25
26#include "polarssl/config.h"
27
28#if defined(POLARSSL_ERROR_C)
29
Paul Bakkereae09db2013-06-06 12:35:54 +020030#include "polarssl/error.h"
31
Paul Bakker9d781402011-05-09 16:17:09 +000032#if defined(POLARSSL_AES_C)
33#include "polarssl/aes.h"
34#endif
35
36#if defined(POLARSSL_BASE64_C)
37#include "polarssl/base64.h"
38#endif
39
40#if defined(POLARSSL_BIGNUM_C)
41#include "polarssl/bignum.h"
42#endif
43
Paul Bakker83f00bb2012-07-04 11:08:50 +000044#if defined(POLARSSL_BLOWFISH_C)
45#include "polarssl/blowfish.h"
46#endif
47
Paul Bakker9d781402011-05-09 16:17:09 +000048#if defined(POLARSSL_CAMELLIA_C)
49#include "polarssl/camellia.h"
50#endif
51
Paul Bakkerff61a782011-06-09 15:42:02 +000052#if defined(POLARSSL_CIPHER_C)
53#include "polarssl/cipher.h"
54#endif
55
Paul Bakker880ac7e2011-11-27 14:50:49 +000056#if defined(POLARSSL_CTR_DRBG_C)
57#include "polarssl/ctr_drbg.h"
58#endif
59
Paul Bakker9d781402011-05-09 16:17:09 +000060#if defined(POLARSSL_DES_C)
61#include "polarssl/des.h"
62#endif
63
64#if defined(POLARSSL_DHM_C)
65#include "polarssl/dhm.h"
66#endif
67
Paul Bakker6083fd22011-12-03 21:45:14 +000068#if defined(POLARSSL_ENTROPY_C)
69#include "polarssl/entropy.h"
70#endif
71
Paul Bakker030277a2012-04-17 12:24:26 +000072#if defined(POLARSSL_GCM_C)
73#include "polarssl/gcm.h"
74#endif
75
Paul Bakker9d781402011-05-09 16:17:09 +000076#if defined(POLARSSL_MD_C)
77#include "polarssl/md.h"
78#endif
79
Paul Bakker69e095c2011-12-10 21:55:01 +000080#if defined(POLARSSL_MD2_C)
81#include "polarssl/md2.h"
82#endif
83
84#if defined(POLARSSL_MD4_C)
85#include "polarssl/md4.h"
86#endif
87
88#if defined(POLARSSL_MD5_C)
89#include "polarssl/md5.h"
90#endif
91
Paul Bakker9d781402011-05-09 16:17:09 +000092#if defined(POLARSSL_NET_C)
93#include "polarssl/net.h"
94#endif
95
96#if defined(POLARSSL_PADLOCK_C)
97#include "polarssl/padlock.h"
98#endif
99
Paul Bakkerd14277d2012-09-26 15:19:05 +0000100#if defined(POLARSSL_PBKDF2_C)
101#include "polarssl/pbkdf2.h"
102#endif
103
Paul Bakker9d781402011-05-09 16:17:09 +0000104#if defined(POLARSSL_PEM_C)
105#include "polarssl/pem.h"
106#endif
107
108#if defined(POLARSSL_RSA_C)
109#include "polarssl/rsa.h"
110#endif
111
Paul Bakker69e095c2011-12-10 21:55:01 +0000112#if defined(POLARSSL_SHA1_C)
113#include "polarssl/sha1.h"
114#endif
115
116#if defined(POLARSSL_SHA2_C)
117#include "polarssl/sha2.h"
118#endif
119
120#if defined(POLARSSL_SHA4_C)
121#include "polarssl/sha4.h"
122#endif
123
Paul Bakker831a7552011-05-18 13:32:51 +0000124#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000125#include "polarssl/ssl.h"
126#endif
127
128#if defined(POLARSSL_X509_PARSE_C)
129#include "polarssl/x509.h"
130#endif
131
132#if defined(POLARSSL_XTEA_C)
133#include "polarssl/xtea.h"
134#endif
135
136
137#include <string.h>
138
Paul Bakkerdceecd82011-11-15 16:38:34 +0000139#if defined _MSC_VER && !defined snprintf
140#define snprintf _snprintf
141#endif
142
Paul Bakker9d781402011-05-09 16:17:09 +0000143void error_strerror( int ret, char *buf, size_t buflen )
144{
145 size_t len;
146 int use_ret;
147
148 memset( buf, 0x00, buflen );
149
150 if( ret < 0 )
151 ret = -ret;
152
153 if( ret & 0xFF80 )
154 {
155 use_ret = ret & 0xFF80;
156
157 // High level error codes
158 //
Paul Bakkerff61a782011-06-09 15:42:02 +0000159#if defined(POLARSSL_CIPHER_C)
160 if( use_ret == -(POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE) )
161 snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
162 if( use_ret == -(POLARSSL_ERR_CIPHER_BAD_INPUT_DATA) )
163 snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
164 if( use_ret == -(POLARSSL_ERR_CIPHER_ALLOC_FAILED) )
165 snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
166 if( use_ret == -(POLARSSL_ERR_CIPHER_INVALID_PADDING) )
167 snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
168 if( use_ret == -(POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
169 snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
170#endif /* POLARSSL_CIPHER_C */
171
Paul Bakker9d781402011-05-09 16:17:09 +0000172#if defined(POLARSSL_DHM_C)
173 if( use_ret == -(POLARSSL_ERR_DHM_BAD_INPUT_DATA) )
174 snprintf( buf, buflen, "DHM - Bad input parameters to function" );
175 if( use_ret == -(POLARSSL_ERR_DHM_READ_PARAMS_FAILED) )
176 snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
177 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PARAMS_FAILED) )
178 snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
179 if( use_ret == -(POLARSSL_ERR_DHM_READ_PUBLIC_FAILED) )
180 snprintf( buf, buflen, "DHM - Reading of the public values failed" );
181 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PUBLIC_FAILED) )
Paul Bakker05ef8352012-05-08 09:17:57 +0000182 snprintf( buf, buflen, "DHM - Making of the public value failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000183 if( use_ret == -(POLARSSL_ERR_DHM_CALC_SECRET_FAILED) )
184 snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
185#endif /* POLARSSL_DHM_C */
186
187#if defined(POLARSSL_MD_C)
188 if( use_ret == -(POLARSSL_ERR_MD_FEATURE_UNAVAILABLE) )
189 snprintf( buf, buflen, "MD - The selected feature is not available" );
Paul Bakker9c021ad2011-06-09 15:55:11 +0000190 if( use_ret == -(POLARSSL_ERR_MD_BAD_INPUT_DATA) )
191 snprintf( buf, buflen, "MD - Bad input parameters to function" );
192 if( use_ret == -(POLARSSL_ERR_MD_ALLOC_FAILED) )
193 snprintf( buf, buflen, "MD - Failed to allocate memory" );
Paul Bakker8913f822012-01-14 18:07:41 +0000194 if( use_ret == -(POLARSSL_ERR_MD_FILE_IO_ERROR) )
195 snprintf( buf, buflen, "MD - Opening or reading of file failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000196#endif /* POLARSSL_MD_C */
197
198#if defined(POLARSSL_PEM_C)
199 if( use_ret == -(POLARSSL_ERR_PEM_NO_HEADER_PRESENT) )
200 snprintf( buf, buflen, "PEM - No PEM header found" );
201 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_DATA) )
202 snprintf( buf, buflen, "PEM - PEM string is not as expected" );
203 if( use_ret == -(POLARSSL_ERR_PEM_MALLOC_FAILED) )
204 snprintf( buf, buflen, "PEM - Failed to allocate memory" );
205 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_ENC_IV) )
206 snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
207 if( use_ret == -(POLARSSL_ERR_PEM_UNKNOWN_ENC_ALG) )
208 snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
209 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_REQUIRED) )
210 snprintf( buf, buflen, "PEM - Private key password can't be empty" );
211 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_MISMATCH) )
212 snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
213 if( use_ret == -(POLARSSL_ERR_PEM_FEATURE_UNAVAILABLE) )
214 snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
215#endif /* POLARSSL_PEM_C */
216
217#if defined(POLARSSL_RSA_C)
218 if( use_ret == -(POLARSSL_ERR_RSA_BAD_INPUT_DATA) )
219 snprintf( buf, buflen, "RSA - Bad input parameters to function" );
220 if( use_ret == -(POLARSSL_ERR_RSA_INVALID_PADDING) )
221 snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
222 if( use_ret == -(POLARSSL_ERR_RSA_KEY_GEN_FAILED) )
223 snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
224 if( use_ret == -(POLARSSL_ERR_RSA_KEY_CHECK_FAILED) )
225 snprintf( buf, buflen, "RSA - Key failed to pass the libraries validity check" );
226 if( use_ret == -(POLARSSL_ERR_RSA_PUBLIC_FAILED) )
227 snprintf( buf, buflen, "RSA - The public key operation failed" );
228 if( use_ret == -(POLARSSL_ERR_RSA_PRIVATE_FAILED) )
229 snprintf( buf, buflen, "RSA - The private key operation failed" );
230 if( use_ret == -(POLARSSL_ERR_RSA_VERIFY_FAILED) )
231 snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
232 if( use_ret == -(POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE) )
233 snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
234 if( use_ret == -(POLARSSL_ERR_RSA_RNG_FAILED) )
235 snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
236#endif /* POLARSSL_RSA_C */
237
Paul Bakker831a7552011-05-18 13:32:51 +0000238#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000239 if( use_ret == -(POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE) )
240 snprintf( buf, buflen, "SSL - The requested feature is not available" );
241 if( use_ret == -(POLARSSL_ERR_SSL_BAD_INPUT_DATA) )
242 snprintf( buf, buflen, "SSL - Bad input parameters to function" );
243 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_MAC) )
244 snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
245 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_RECORD) )
246 snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
Paul Bakker831a7552011-05-18 13:32:51 +0000247 if( use_ret == -(POLARSSL_ERR_SSL_CONN_EOF) )
248 snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
Paul Bakker9d781402011-05-09 16:17:09 +0000249 if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_CIPHER) )
250 snprintf( buf, buflen, "SSL - An unknown cipher was received" );
251 if( use_ret == -(POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN) )
252 snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
253 if( use_ret == -(POLARSSL_ERR_SSL_NO_SESSION_FOUND) )
254 snprintf( buf, buflen, "SSL - No session to recover was found" );
255 if( use_ret == -(POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE) )
256 snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
257 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE) )
258 snprintf( buf, buflen, "SSL - DESCRIPTION MISSING" );
259 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED) )
260 snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
261 if( use_ret == -(POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED) )
262 snprintf( buf, buflen, "SSL - The own private key is not set, but needed" );
263 if( use_ret == -(POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED) )
264 snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
265 if( use_ret == -(POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE) )
266 snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
267 if( use_ret == -(POLARSSL_ERR_SSL_FATAL_ALERT_MESSAGE) )
Paul Bakker3aac1da2012-05-08 13:12:27 +0000268 {
Paul Bakker9d781402011-05-09 16:17:09 +0000269 snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
Paul Bakker3aac1da2012-05-08 13:12:27 +0000270 return;
271 }
Paul Bakker9d781402011-05-09 16:17:09 +0000272 if( use_ret == -(POLARSSL_ERR_SSL_PEER_VERIFY_FAILED) )
273 snprintf( buf, buflen, "SSL - Verification of our peer failed" );
274 if( use_ret == -(POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) )
275 snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
276 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO) )
277 snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
278 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO) )
279 snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
280 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE) )
281 snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
282 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
283 snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
284 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
285 snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
286 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
287 snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
288 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
289 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
290 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_RP) )
291 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM Read Public" );
292 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_CS) )
293 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM Calculate Secret" );
294 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
295 snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
296 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
297 snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
298 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_FINISHED) )
299 snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000300 if( use_ret == -(POLARSSL_ERR_SSL_MALLOC_FAILED) )
301 snprintf( buf, buflen, "SSL - Memory allocation failed" );
Paul Bakker05ef8352012-05-08 09:17:57 +0000302 if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FAILED) )
303 snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
304 if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
305 snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
Paul Bakker83f00bb2012-07-04 11:08:50 +0000306 if( use_ret == -(POLARSSL_ERR_SSL_COMPRESSION_FAILED) )
307 snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
Paul Bakker1d29fb52012-09-28 13:28:45 +0000308 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
309 snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
Paul Bakker831a7552011-05-18 13:32:51 +0000310#endif /* POLARSSL_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000311
312#if defined(POLARSSL_X509_PARSE_C)
313 if( use_ret == -(POLARSSL_ERR_X509_FEATURE_UNAVAILABLE) )
314 snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
315 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_PEM) )
316 snprintf( buf, buflen, "X509 - The PEM-encoded certificate contains invalid elements, e.g. invalid character" );
317 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_FORMAT) )
318 snprintf( buf, buflen, "X509 - The certificate format is invalid, e.g. different type expected" );
319 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_VERSION) )
320 snprintf( buf, buflen, "X509 - The certificate version element is invalid" );
321 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_SERIAL) )
322 snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
323 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_ALG) )
324 snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
325 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_NAME) )
326 snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
327 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_DATE) )
328 snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
329 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_PUBKEY) )
330 snprintf( buf, buflen, "X509 - The pubkey tag or value is invalid (only RSA is supported)" );
331 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE) )
332 snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
333 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS) )
334 snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
335 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION) )
336 snprintf( buf, buflen, "X509 - Certificate or CRL has an unsupported version number" );
337 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG) )
338 snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
Paul Bakker9db77422011-07-13 11:47:32 +0000339 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_PK_ALG) )
340 snprintf( buf, buflen, "X509 - Key algorithm is unsupported (only RSA is supported)" );
Paul Bakker9d781402011-05-09 16:17:09 +0000341 if( use_ret == -(POLARSSL_ERR_X509_CERT_SIG_MISMATCH) )
342 snprintf( buf, buflen, "X509 - Certificate signature algorithms do not match. (see \\c ::x509_cert sig_oid)" );
343 if( use_ret == -(POLARSSL_ERR_X509_CERT_VERIFY_FAILED) )
344 snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
345 if( use_ret == -(POLARSSL_ERR_X509_KEY_INVALID_VERSION) )
346 snprintf( buf, buflen, "X509 - Unsupported RSA key version" );
347 if( use_ret == -(POLARSSL_ERR_X509_KEY_INVALID_FORMAT) )
348 snprintf( buf, buflen, "X509 - Invalid RSA key tag or value" );
Paul Bakker6c0ceb32011-12-04 12:24:18 +0000349 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT) )
350 snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000351 if( use_ret == -(POLARSSL_ERR_X509_INVALID_INPUT) )
352 snprintf( buf, buflen, "X509 - Input invalid" );
353 if( use_ret == -(POLARSSL_ERR_X509_MALLOC_FAILED) )
354 snprintf( buf, buflen, "X509 - Allocation of memory failed" );
355 if( use_ret == -(POLARSSL_ERR_X509_FILE_IO_ERROR) )
356 snprintf( buf, buflen, "X509 - Read/write of file failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000357#endif /* POLARSSL_X509_PARSE_C */
358
359 if( strlen( buf ) == 0 )
360 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
361 }
362
363 use_ret = ret & ~0xFF80;
364
365 if( use_ret == 0 )
366 return;
367
368 // If high level code is present, make a concatenation between both
369 // error strings.
370 //
371 len = strlen( buf );
372
373 if( len > 0 )
374 {
375 if( buflen - len < 5 )
376 return;
377
378 snprintf( buf + len, buflen - len, " : " );
379
380 buf += len + 3;
381 buflen -= len + 3;
382 }
383
384 // Low level error codes
385 //
386#if defined(POLARSSL_AES_C)
387 if( use_ret == -(POLARSSL_ERR_AES_INVALID_KEY_LENGTH) )
388 snprintf( buf, buflen, "AES - Invalid key length" );
389 if( use_ret == -(POLARSSL_ERR_AES_INVALID_INPUT_LENGTH) )
390 snprintf( buf, buflen, "AES - Invalid data input length" );
391#endif /* POLARSSL_AES_C */
392
Paul Bakkerdceecd82011-11-15 16:38:34 +0000393#if defined(POLARSSL_ASN1_PARSE_C)
394 if( use_ret == -(POLARSSL_ERR_ASN1_OUT_OF_DATA) )
395 snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
396 if( use_ret == -(POLARSSL_ERR_ASN1_UNEXPECTED_TAG) )
397 snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
398 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_LENGTH) )
399 snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
400 if( use_ret == -(POLARSSL_ERR_ASN1_LENGTH_MISMATCH) )
401 snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
402 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_DATA) )
403 snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000404 if( use_ret == -(POLARSSL_ERR_ASN1_MALLOC_FAILED) )
405 snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000406 if( use_ret == -(POLARSSL_ERR_ASN1_BUF_TOO_SMALL) )
407 snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
Paul Bakkerdceecd82011-11-15 16:38:34 +0000408#endif /* POLARSSL_ASN1_PARSE_C */
409
Paul Bakker9d781402011-05-09 16:17:09 +0000410#if defined(POLARSSL_BASE64_C)
411 if( use_ret == -(POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) )
412 snprintf( buf, buflen, "BASE64 - Output buffer too small" );
413 if( use_ret == -(POLARSSL_ERR_BASE64_INVALID_CHARACTER) )
414 snprintf( buf, buflen, "BASE64 - Invalid character in input" );
415#endif /* POLARSSL_BASE64_C */
416
417#if defined(POLARSSL_BIGNUM_C)
418 if( use_ret == -(POLARSSL_ERR_MPI_FILE_IO_ERROR) )
419 snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
420 if( use_ret == -(POLARSSL_ERR_MPI_BAD_INPUT_DATA) )
421 snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
422 if( use_ret == -(POLARSSL_ERR_MPI_INVALID_CHARACTER) )
423 snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
424 if( use_ret == -(POLARSSL_ERR_MPI_BUFFER_TOO_SMALL) )
Paul Bakker69e095c2011-12-10 21:55:01 +0000425 snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
Paul Bakker9d781402011-05-09 16:17:09 +0000426 if( use_ret == -(POLARSSL_ERR_MPI_NEGATIVE_VALUE) )
427 snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
428 if( use_ret == -(POLARSSL_ERR_MPI_DIVISION_BY_ZERO) )
429 snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
430 if( use_ret == -(POLARSSL_ERR_MPI_NOT_ACCEPTABLE) )
431 snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000432 if( use_ret == -(POLARSSL_ERR_MPI_MALLOC_FAILED) )
433 snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000434#endif /* POLARSSL_BIGNUM_C */
435
Paul Bakker83f00bb2012-07-04 11:08:50 +0000436#if defined(POLARSSL_BLOWFISH_C)
437 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
438 snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
439 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
440 snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
441#endif /* POLARSSL_BLOWFISH_C */
442
Paul Bakker9d781402011-05-09 16:17:09 +0000443#if defined(POLARSSL_CAMELLIA_C)
444 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
445 snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
446 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
447 snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
448#endif /* POLARSSL_CAMELLIA_C */
449
Paul Bakker880ac7e2011-11-27 14:50:49 +0000450#if defined(POLARSSL_CTR_DRBG_C)
451 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
452 snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
453 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
454 snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
455 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG) )
456 snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000457 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR) )
458 snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
Paul Bakker880ac7e2011-11-27 14:50:49 +0000459#endif /* POLARSSL_CTR_DRBG_C */
460
Paul Bakker9d781402011-05-09 16:17:09 +0000461#if defined(POLARSSL_DES_C)
462 if( use_ret == -(POLARSSL_ERR_DES_INVALID_INPUT_LENGTH) )
463 snprintf( buf, buflen, "DES - The data input has an invalid length" );
464#endif /* POLARSSL_DES_C */
465
Paul Bakker6083fd22011-12-03 21:45:14 +0000466#if defined(POLARSSL_ENTROPY_C)
467 if( use_ret == -(POLARSSL_ERR_ENTROPY_SOURCE_FAILED) )
468 snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
469 if( use_ret == -(POLARSSL_ERR_ENTROPY_MAX_SOURCES) )
470 snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
Paul Bakker43655f42011-12-15 20:11:16 +0000471 if( use_ret == -(POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED) )
472 snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
Paul Bakker6083fd22011-12-03 21:45:14 +0000473#endif /* POLARSSL_ENTROPY_C */
474
Paul Bakker030277a2012-04-17 12:24:26 +0000475#if defined(POLARSSL_GCM_C)
476 if( use_ret == -(POLARSSL_ERR_GCM_AUTH_FAILED) )
477 snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
Paul Bakkerd8ef1672012-04-18 14:17:32 +0000478 if( use_ret == -(POLARSSL_ERR_GCM_BAD_INPUT) )
479 snprintf( buf, buflen, "GCM - Bad input parameters to function" );
Paul Bakker030277a2012-04-17 12:24:26 +0000480#endif /* POLARSSL_GCM_C */
481
Paul Bakker69e095c2011-12-10 21:55:01 +0000482#if defined(POLARSSL_MD2_C)
483 if( use_ret == -(POLARSSL_ERR_MD2_FILE_IO_ERROR) )
484 snprintf( buf, buflen, "MD2 - Read/write error in file" );
485#endif /* POLARSSL_MD2_C */
486
487#if defined(POLARSSL_MD4_C)
488 if( use_ret == -(POLARSSL_ERR_MD4_FILE_IO_ERROR) )
489 snprintf( buf, buflen, "MD4 - Read/write error in file" );
490#endif /* POLARSSL_MD4_C */
491
492#if defined(POLARSSL_MD5_C)
493 if( use_ret == -(POLARSSL_ERR_MD5_FILE_IO_ERROR) )
494 snprintf( buf, buflen, "MD5 - Read/write error in file" );
495#endif /* POLARSSL_MD5_C */
496
Paul Bakker9d781402011-05-09 16:17:09 +0000497#if defined(POLARSSL_NET_C)
498 if( use_ret == -(POLARSSL_ERR_NET_UNKNOWN_HOST) )
499 snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
500 if( use_ret == -(POLARSSL_ERR_NET_SOCKET_FAILED) )
501 snprintf( buf, buflen, "NET - Failed to open a socket" );
502 if( use_ret == -(POLARSSL_ERR_NET_CONNECT_FAILED) )
503 snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
504 if( use_ret == -(POLARSSL_ERR_NET_BIND_FAILED) )
505 snprintf( buf, buflen, "NET - Binding of the socket failed" );
506 if( use_ret == -(POLARSSL_ERR_NET_LISTEN_FAILED) )
507 snprintf( buf, buflen, "NET - Could not listen on the socket" );
508 if( use_ret == -(POLARSSL_ERR_NET_ACCEPT_FAILED) )
509 snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
510 if( use_ret == -(POLARSSL_ERR_NET_RECV_FAILED) )
511 snprintf( buf, buflen, "NET - Reading information from the socket failed" );
512 if( use_ret == -(POLARSSL_ERR_NET_SEND_FAILED) )
513 snprintf( buf, buflen, "NET - Sending information through the socket failed" );
514 if( use_ret == -(POLARSSL_ERR_NET_CONN_RESET) )
515 snprintf( buf, buflen, "NET - Connection was reset by peer" );
Paul Bakker831a7552011-05-18 13:32:51 +0000516 if( use_ret == -(POLARSSL_ERR_NET_WANT_READ) )
517 snprintf( buf, buflen, "NET - Connection requires a read call" );
518 if( use_ret == -(POLARSSL_ERR_NET_WANT_WRITE) )
519 snprintf( buf, buflen, "NET - Connection requires a write call" );
Paul Bakker9d781402011-05-09 16:17:09 +0000520#endif /* POLARSSL_NET_C */
521
522#if defined(POLARSSL_PADLOCK_C)
523 if( use_ret == -(POLARSSL_ERR_PADLOCK_DATA_MISALIGNED) )
524 snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
525#endif /* POLARSSL_PADLOCK_C */
526
Paul Bakkerd14277d2012-09-26 15:19:05 +0000527#if defined(POLARSSL_PBKDF2_C)
528 if( use_ret == -(POLARSSL_ERR_PBKDF2_BAD_INPUT_DATA) )
529 snprintf( buf, buflen, "PBKDF2 - Bad input parameters to function" );
530#endif /* POLARSSL_PBKDF2_C */
531
Paul Bakker69e095c2011-12-10 21:55:01 +0000532#if defined(POLARSSL_SHA1_C)
533 if( use_ret == -(POLARSSL_ERR_SHA1_FILE_IO_ERROR) )
534 snprintf( buf, buflen, "SHA1 - Read/write error in file" );
535#endif /* POLARSSL_SHA1_C */
536
537#if defined(POLARSSL_SHA2_C)
538 if( use_ret == -(POLARSSL_ERR_SHA2_FILE_IO_ERROR) )
539 snprintf( buf, buflen, "SHA2 - Read/write error in file" );
540#endif /* POLARSSL_SHA2_C */
541
542#if defined(POLARSSL_SHA4_C)
543 if( use_ret == -(POLARSSL_ERR_SHA4_FILE_IO_ERROR) )
544 snprintf( buf, buflen, "SHA4 - Read/write error in file" );
545#endif /* POLARSSL_SHA4_C */
546
Paul Bakker9d781402011-05-09 16:17:09 +0000547#if defined(POLARSSL_XTEA_C)
548 if( use_ret == -(POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH) )
549 snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
550#endif /* POLARSSL_XTEA_C */
551
552 if( strlen( buf ) != 0 )
553 return;
554
555 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
556}
557
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100558#else /* POLARSSL_ERROR_C */
559
560#if defined(POLARSSL_ERROR_STRERROR_DUMMY)
561
562#include <string.h>
563
564/*
565 * Provide an non-function in case POLARSSL_ERROR_C is not defined
566 */
567void error_strerror( int ret, char *buf, size_t buflen )
568{
569 ((void) ret);
570
571 if( buflen > 0 )
572 buf[0] = '\0';
573}
574
575#endif /* POLARSSL_ERROR_STRERROR_DUMMY */
Paul Bakker9a736322012-11-14 12:39:52 +0000576#endif /* POLARSSL_ERROR_C */