blob: 46adb274609534ad28a28092e7604521d441feec [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
Paul Bakkercf6e95d2013-06-12 13:18:15 +0200108#if defined(POLARSSL_PKCS12_C)
109#include "polarssl/pkcs12.h"
110#endif
111
Paul Bakker19bd2972013-06-14 12:06:45 +0200112#if defined(POLARSSL_PKCS5_C)
113#include "polarssl/pkcs5.h"
114#endif
115
Paul Bakker9d781402011-05-09 16:17:09 +0000116#if defined(POLARSSL_RSA_C)
117#include "polarssl/rsa.h"
118#endif
119
Paul Bakker69e095c2011-12-10 21:55:01 +0000120#if defined(POLARSSL_SHA1_C)
121#include "polarssl/sha1.h"
122#endif
123
124#if defined(POLARSSL_SHA2_C)
125#include "polarssl/sha2.h"
126#endif
127
128#if defined(POLARSSL_SHA4_C)
129#include "polarssl/sha4.h"
130#endif
131
Paul Bakker831a7552011-05-18 13:32:51 +0000132#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000133#include "polarssl/ssl.h"
134#endif
135
136#if defined(POLARSSL_X509_PARSE_C)
137#include "polarssl/x509.h"
138#endif
139
140#if defined(POLARSSL_XTEA_C)
141#include "polarssl/xtea.h"
142#endif
143
144
145#include <string.h>
146
Paul Bakkerdceecd82011-11-15 16:38:34 +0000147#if defined _MSC_VER && !defined snprintf
148#define snprintf _snprintf
149#endif
150
Paul Bakker9d781402011-05-09 16:17:09 +0000151void error_strerror( int ret, char *buf, size_t buflen )
152{
153 size_t len;
154 int use_ret;
155
156 memset( buf, 0x00, buflen );
157
158 if( ret < 0 )
159 ret = -ret;
160
161 if( ret & 0xFF80 )
162 {
163 use_ret = ret & 0xFF80;
164
165 // High level error codes
166 //
Paul Bakkerff61a782011-06-09 15:42:02 +0000167#if defined(POLARSSL_CIPHER_C)
168 if( use_ret == -(POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE) )
169 snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
170 if( use_ret == -(POLARSSL_ERR_CIPHER_BAD_INPUT_DATA) )
171 snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
172 if( use_ret == -(POLARSSL_ERR_CIPHER_ALLOC_FAILED) )
173 snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
174 if( use_ret == -(POLARSSL_ERR_CIPHER_INVALID_PADDING) )
175 snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
176 if( use_ret == -(POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
177 snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
178#endif /* POLARSSL_CIPHER_C */
179
Paul Bakker9d781402011-05-09 16:17:09 +0000180#if defined(POLARSSL_DHM_C)
181 if( use_ret == -(POLARSSL_ERR_DHM_BAD_INPUT_DATA) )
182 snprintf( buf, buflen, "DHM - Bad input parameters to function" );
183 if( use_ret == -(POLARSSL_ERR_DHM_READ_PARAMS_FAILED) )
184 snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
185 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PARAMS_FAILED) )
186 snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
187 if( use_ret == -(POLARSSL_ERR_DHM_READ_PUBLIC_FAILED) )
188 snprintf( buf, buflen, "DHM - Reading of the public values failed" );
189 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PUBLIC_FAILED) )
Paul Bakker05ef8352012-05-08 09:17:57 +0000190 snprintf( buf, buflen, "DHM - Making of the public value failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000191 if( use_ret == -(POLARSSL_ERR_DHM_CALC_SECRET_FAILED) )
192 snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
193#endif /* POLARSSL_DHM_C */
194
195#if defined(POLARSSL_MD_C)
196 if( use_ret == -(POLARSSL_ERR_MD_FEATURE_UNAVAILABLE) )
197 snprintf( buf, buflen, "MD - The selected feature is not available" );
Paul Bakker9c021ad2011-06-09 15:55:11 +0000198 if( use_ret == -(POLARSSL_ERR_MD_BAD_INPUT_DATA) )
199 snprintf( buf, buflen, "MD - Bad input parameters to function" );
200 if( use_ret == -(POLARSSL_ERR_MD_ALLOC_FAILED) )
201 snprintf( buf, buflen, "MD - Failed to allocate memory" );
Paul Bakker8913f822012-01-14 18:07:41 +0000202 if( use_ret == -(POLARSSL_ERR_MD_FILE_IO_ERROR) )
203 snprintf( buf, buflen, "MD - Opening or reading of file failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000204#endif /* POLARSSL_MD_C */
205
206#if defined(POLARSSL_PEM_C)
Paul Bakker9255e832013-06-06 14:58:28 +0200207 if( use_ret == -(POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
208 snprintf( buf, buflen, "PEM - No PEM header or footer found" );
Paul Bakker9d781402011-05-09 16:17:09 +0000209 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_DATA) )
210 snprintf( buf, buflen, "PEM - PEM string is not as expected" );
211 if( use_ret == -(POLARSSL_ERR_PEM_MALLOC_FAILED) )
212 snprintf( buf, buflen, "PEM - Failed to allocate memory" );
213 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_ENC_IV) )
214 snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
215 if( use_ret == -(POLARSSL_ERR_PEM_UNKNOWN_ENC_ALG) )
216 snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
217 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_REQUIRED) )
218 snprintf( buf, buflen, "PEM - Private key password can't be empty" );
219 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_MISMATCH) )
220 snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
221 if( use_ret == -(POLARSSL_ERR_PEM_FEATURE_UNAVAILABLE) )
222 snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
Paul Bakker9255e832013-06-06 14:58:28 +0200223 if( use_ret == -(POLARSSL_ERR_PEM_BAD_INPUT_DATA) )
224 snprintf( buf, buflen, "PEM - Bad input parameters to function" );
Paul Bakker9d781402011-05-09 16:17:09 +0000225#endif /* POLARSSL_PEM_C */
226
Paul Bakkercf6e95d2013-06-12 13:18:15 +0200227#if defined(POLARSSL_PKCS12_C)
228 if( use_ret == -(POLARSSL_ERR_PKCS12_BAD_INPUT_DATA) )
229 snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
230 if( use_ret == -(POLARSSL_ERR_PKCS12_FEATURE_UNAVAILABLE) )
231 snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
232 if( use_ret == -(POLARSSL_ERR_PKCS12_PBE_INVALID_FORMAT) )
233 snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
Paul Bakker14a222c2013-06-18 16:35:48 +0200234 if( use_ret == -(POLARSSL_ERR_PKCS12_PASSWORD_MISMATCH) )
235 snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
Paul Bakkercf6e95d2013-06-12 13:18:15 +0200236#endif /* POLARSSL_PKCS12_C */
237
Paul Bakker1fd43212013-06-17 15:14:42 +0200238#if defined(POLARSSL_PKCS5_C)
239 if( use_ret == -(POLARSSL_ERR_PKCS5_BAD_INPUT_DATA) )
240 snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
241 if( use_ret == -(POLARSSL_ERR_PKCS5_INVALID_FORMAT) )
242 snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
243 if( use_ret == -(POLARSSL_ERR_PKCS5_FEATURE_UNAVAILABLE) )
244 snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
245 if( use_ret == -(POLARSSL_ERR_PKCS5_PASSWORD_MISMATCH) )
246 snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
247#endif /* POLARSSL_PKCS5_C */
248
Paul Bakker9d781402011-05-09 16:17:09 +0000249#if defined(POLARSSL_RSA_C)
250 if( use_ret == -(POLARSSL_ERR_RSA_BAD_INPUT_DATA) )
251 snprintf( buf, buflen, "RSA - Bad input parameters to function" );
252 if( use_ret == -(POLARSSL_ERR_RSA_INVALID_PADDING) )
253 snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
254 if( use_ret == -(POLARSSL_ERR_RSA_KEY_GEN_FAILED) )
255 snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
256 if( use_ret == -(POLARSSL_ERR_RSA_KEY_CHECK_FAILED) )
257 snprintf( buf, buflen, "RSA - Key failed to pass the libraries validity check" );
258 if( use_ret == -(POLARSSL_ERR_RSA_PUBLIC_FAILED) )
259 snprintf( buf, buflen, "RSA - The public key operation failed" );
260 if( use_ret == -(POLARSSL_ERR_RSA_PRIVATE_FAILED) )
261 snprintf( buf, buflen, "RSA - The private key operation failed" );
262 if( use_ret == -(POLARSSL_ERR_RSA_VERIFY_FAILED) )
263 snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
264 if( use_ret == -(POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE) )
265 snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
266 if( use_ret == -(POLARSSL_ERR_RSA_RNG_FAILED) )
267 snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
268#endif /* POLARSSL_RSA_C */
269
Paul Bakker831a7552011-05-18 13:32:51 +0000270#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000271 if( use_ret == -(POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE) )
272 snprintf( buf, buflen, "SSL - The requested feature is not available" );
273 if( use_ret == -(POLARSSL_ERR_SSL_BAD_INPUT_DATA) )
274 snprintf( buf, buflen, "SSL - Bad input parameters to function" );
275 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_MAC) )
276 snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
277 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_RECORD) )
278 snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
Paul Bakker831a7552011-05-18 13:32:51 +0000279 if( use_ret == -(POLARSSL_ERR_SSL_CONN_EOF) )
280 snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
Paul Bakker9d781402011-05-09 16:17:09 +0000281 if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_CIPHER) )
282 snprintf( buf, buflen, "SSL - An unknown cipher was received" );
283 if( use_ret == -(POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN) )
284 snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
Paul Bakkera1caf6e2013-11-21 17:31:06 +0100285 if( use_ret == -(POLARSSL_ERR_SSL_NO_RNG) )
286 snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
Paul Bakker9d781402011-05-09 16:17:09 +0000287 if( use_ret == -(POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE) )
288 snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
289 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE) )
290 snprintf( buf, buflen, "SSL - DESCRIPTION MISSING" );
291 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED) )
292 snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
293 if( use_ret == -(POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED) )
294 snprintf( buf, buflen, "SSL - The own private key is not set, but needed" );
295 if( use_ret == -(POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED) )
296 snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
297 if( use_ret == -(POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE) )
298 snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
299 if( use_ret == -(POLARSSL_ERR_SSL_FATAL_ALERT_MESSAGE) )
Paul Bakker3aac1da2012-05-08 13:12:27 +0000300 {
Paul Bakker9d781402011-05-09 16:17:09 +0000301 snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
Paul Bakker3aac1da2012-05-08 13:12:27 +0000302 return;
303 }
Paul Bakker9d781402011-05-09 16:17:09 +0000304 if( use_ret == -(POLARSSL_ERR_SSL_PEER_VERIFY_FAILED) )
305 snprintf( buf, buflen, "SSL - Verification of our peer failed" );
306 if( use_ret == -(POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) )
307 snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
308 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO) )
309 snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
310 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO) )
311 snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
312 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE) )
313 snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
314 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
315 snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
316 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
317 snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
318 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
319 snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
320 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
321 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
322 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_RP) )
323 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM Read Public" );
324 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_CS) )
325 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM Calculate Secret" );
326 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
327 snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
328 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
329 snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
330 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_FINISHED) )
331 snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000332 if( use_ret == -(POLARSSL_ERR_SSL_MALLOC_FAILED) )
333 snprintf( buf, buflen, "SSL - Memory allocation failed" );
Paul Bakker05ef8352012-05-08 09:17:57 +0000334 if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FAILED) )
335 snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
336 if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
337 snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
Paul Bakker83f00bb2012-07-04 11:08:50 +0000338 if( use_ret == -(POLARSSL_ERR_SSL_COMPRESSION_FAILED) )
339 snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
Paul Bakker1d29fb52012-09-28 13:28:45 +0000340 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
341 snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
Paul Bakker831a7552011-05-18 13:32:51 +0000342#endif /* POLARSSL_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000343
344#if defined(POLARSSL_X509_PARSE_C)
345 if( use_ret == -(POLARSSL_ERR_X509_FEATURE_UNAVAILABLE) )
346 snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
347 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_PEM) )
348 snprintf( buf, buflen, "X509 - The PEM-encoded certificate contains invalid elements, e.g. invalid character" );
349 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_FORMAT) )
350 snprintf( buf, buflen, "X509 - The certificate format is invalid, e.g. different type expected" );
351 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_VERSION) )
352 snprintf( buf, buflen, "X509 - The certificate version element is invalid" );
353 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_SERIAL) )
354 snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
355 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_ALG) )
356 snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
357 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_NAME) )
358 snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
359 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_DATE) )
360 snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
361 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_PUBKEY) )
362 snprintf( buf, buflen, "X509 - The pubkey tag or value is invalid (only RSA is supported)" );
363 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE) )
364 snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
365 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS) )
366 snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
367 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION) )
368 snprintf( buf, buflen, "X509 - Certificate or CRL has an unsupported version number" );
369 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG) )
370 snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
Paul Bakker9db77422011-07-13 11:47:32 +0000371 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_PK_ALG) )
372 snprintf( buf, buflen, "X509 - Key algorithm is unsupported (only RSA is supported)" );
Paul Bakker9d781402011-05-09 16:17:09 +0000373 if( use_ret == -(POLARSSL_ERR_X509_CERT_SIG_MISMATCH) )
374 snprintf( buf, buflen, "X509 - Certificate signature algorithms do not match. (see \\c ::x509_cert sig_oid)" );
375 if( use_ret == -(POLARSSL_ERR_X509_CERT_VERIFY_FAILED) )
376 snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
377 if( use_ret == -(POLARSSL_ERR_X509_KEY_INVALID_VERSION) )
378 snprintf( buf, buflen, "X509 - Unsupported RSA key version" );
379 if( use_ret == -(POLARSSL_ERR_X509_KEY_INVALID_FORMAT) )
380 snprintf( buf, buflen, "X509 - Invalid RSA key tag or value" );
Paul Bakker6c0ceb32011-12-04 12:24:18 +0000381 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT) )
382 snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000383 if( use_ret == -(POLARSSL_ERR_X509_INVALID_INPUT) )
384 snprintf( buf, buflen, "X509 - Input invalid" );
385 if( use_ret == -(POLARSSL_ERR_X509_MALLOC_FAILED) )
386 snprintf( buf, buflen, "X509 - Allocation of memory failed" );
387 if( use_ret == -(POLARSSL_ERR_X509_FILE_IO_ERROR) )
388 snprintf( buf, buflen, "X509 - Read/write of file failed" );
Paul Bakker1fd43212013-06-17 15:14:42 +0200389 if( use_ret == -(POLARSSL_ERR_X509_PASSWORD_REQUIRED) )
390 snprintf( buf, buflen, "X509 - Private key password can't be empty" );
391 if( use_ret == -(POLARSSL_ERR_X509_PASSWORD_MISMATCH) )
392 snprintf( buf, buflen, "X509 - Given private key password does not allow for correct decryption" );
Paul Bakker9d781402011-05-09 16:17:09 +0000393#endif /* POLARSSL_X509_PARSE_C */
394
395 if( strlen( buf ) == 0 )
396 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
397 }
398
399 use_ret = ret & ~0xFF80;
400
401 if( use_ret == 0 )
402 return;
403
404 // If high level code is present, make a concatenation between both
405 // error strings.
406 //
407 len = strlen( buf );
408
409 if( len > 0 )
410 {
411 if( buflen - len < 5 )
412 return;
413
414 snprintf( buf + len, buflen - len, " : " );
415
416 buf += len + 3;
417 buflen -= len + 3;
418 }
419
420 // Low level error codes
421 //
422#if defined(POLARSSL_AES_C)
423 if( use_ret == -(POLARSSL_ERR_AES_INVALID_KEY_LENGTH) )
424 snprintf( buf, buflen, "AES - Invalid key length" );
425 if( use_ret == -(POLARSSL_ERR_AES_INVALID_INPUT_LENGTH) )
426 snprintf( buf, buflen, "AES - Invalid data input length" );
427#endif /* POLARSSL_AES_C */
428
Paul Bakkerdceecd82011-11-15 16:38:34 +0000429#if defined(POLARSSL_ASN1_PARSE_C)
430 if( use_ret == -(POLARSSL_ERR_ASN1_OUT_OF_DATA) )
431 snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
432 if( use_ret == -(POLARSSL_ERR_ASN1_UNEXPECTED_TAG) )
433 snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
434 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_LENGTH) )
435 snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
436 if( use_ret == -(POLARSSL_ERR_ASN1_LENGTH_MISMATCH) )
437 snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
438 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_DATA) )
439 snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000440 if( use_ret == -(POLARSSL_ERR_ASN1_MALLOC_FAILED) )
441 snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000442 if( use_ret == -(POLARSSL_ERR_ASN1_BUF_TOO_SMALL) )
443 snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
Paul Bakkerdceecd82011-11-15 16:38:34 +0000444#endif /* POLARSSL_ASN1_PARSE_C */
445
Paul Bakker9d781402011-05-09 16:17:09 +0000446#if defined(POLARSSL_BASE64_C)
447 if( use_ret == -(POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) )
448 snprintf( buf, buflen, "BASE64 - Output buffer too small" );
449 if( use_ret == -(POLARSSL_ERR_BASE64_INVALID_CHARACTER) )
450 snprintf( buf, buflen, "BASE64 - Invalid character in input" );
451#endif /* POLARSSL_BASE64_C */
452
453#if defined(POLARSSL_BIGNUM_C)
454 if( use_ret == -(POLARSSL_ERR_MPI_FILE_IO_ERROR) )
455 snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
456 if( use_ret == -(POLARSSL_ERR_MPI_BAD_INPUT_DATA) )
457 snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
458 if( use_ret == -(POLARSSL_ERR_MPI_INVALID_CHARACTER) )
459 snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
460 if( use_ret == -(POLARSSL_ERR_MPI_BUFFER_TOO_SMALL) )
Paul Bakker69e095c2011-12-10 21:55:01 +0000461 snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
Paul Bakker9d781402011-05-09 16:17:09 +0000462 if( use_ret == -(POLARSSL_ERR_MPI_NEGATIVE_VALUE) )
463 snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
464 if( use_ret == -(POLARSSL_ERR_MPI_DIVISION_BY_ZERO) )
465 snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
466 if( use_ret == -(POLARSSL_ERR_MPI_NOT_ACCEPTABLE) )
467 snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000468 if( use_ret == -(POLARSSL_ERR_MPI_MALLOC_FAILED) )
469 snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000470#endif /* POLARSSL_BIGNUM_C */
471
Paul Bakker83f00bb2012-07-04 11:08:50 +0000472#if defined(POLARSSL_BLOWFISH_C)
473 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
474 snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
475 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
476 snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
477#endif /* POLARSSL_BLOWFISH_C */
478
Paul Bakker9d781402011-05-09 16:17:09 +0000479#if defined(POLARSSL_CAMELLIA_C)
480 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
481 snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
482 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
483 snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
484#endif /* POLARSSL_CAMELLIA_C */
485
Paul Bakker880ac7e2011-11-27 14:50:49 +0000486#if defined(POLARSSL_CTR_DRBG_C)
487 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
488 snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
489 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
490 snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
491 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG) )
492 snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000493 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR) )
494 snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
Paul Bakker880ac7e2011-11-27 14:50:49 +0000495#endif /* POLARSSL_CTR_DRBG_C */
496
Paul Bakker9d781402011-05-09 16:17:09 +0000497#if defined(POLARSSL_DES_C)
498 if( use_ret == -(POLARSSL_ERR_DES_INVALID_INPUT_LENGTH) )
499 snprintf( buf, buflen, "DES - The data input has an invalid length" );
500#endif /* POLARSSL_DES_C */
501
Paul Bakker6083fd22011-12-03 21:45:14 +0000502#if defined(POLARSSL_ENTROPY_C)
503 if( use_ret == -(POLARSSL_ERR_ENTROPY_SOURCE_FAILED) )
504 snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
505 if( use_ret == -(POLARSSL_ERR_ENTROPY_MAX_SOURCES) )
506 snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
Paul Bakker43655f42011-12-15 20:11:16 +0000507 if( use_ret == -(POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED) )
508 snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
Paul Bakker6083fd22011-12-03 21:45:14 +0000509#endif /* POLARSSL_ENTROPY_C */
510
Paul Bakker030277a2012-04-17 12:24:26 +0000511#if defined(POLARSSL_GCM_C)
512 if( use_ret == -(POLARSSL_ERR_GCM_AUTH_FAILED) )
513 snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
Paul Bakkerd8ef1672012-04-18 14:17:32 +0000514 if( use_ret == -(POLARSSL_ERR_GCM_BAD_INPUT) )
515 snprintf( buf, buflen, "GCM - Bad input parameters to function" );
Paul Bakker030277a2012-04-17 12:24:26 +0000516#endif /* POLARSSL_GCM_C */
517
Paul Bakker69e095c2011-12-10 21:55:01 +0000518#if defined(POLARSSL_MD2_C)
519 if( use_ret == -(POLARSSL_ERR_MD2_FILE_IO_ERROR) )
520 snprintf( buf, buflen, "MD2 - Read/write error in file" );
521#endif /* POLARSSL_MD2_C */
522
523#if defined(POLARSSL_MD4_C)
524 if( use_ret == -(POLARSSL_ERR_MD4_FILE_IO_ERROR) )
525 snprintf( buf, buflen, "MD4 - Read/write error in file" );
526#endif /* POLARSSL_MD4_C */
527
528#if defined(POLARSSL_MD5_C)
529 if( use_ret == -(POLARSSL_ERR_MD5_FILE_IO_ERROR) )
530 snprintf( buf, buflen, "MD5 - Read/write error in file" );
531#endif /* POLARSSL_MD5_C */
532
Paul Bakker9d781402011-05-09 16:17:09 +0000533#if defined(POLARSSL_NET_C)
534 if( use_ret == -(POLARSSL_ERR_NET_UNKNOWN_HOST) )
535 snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
536 if( use_ret == -(POLARSSL_ERR_NET_SOCKET_FAILED) )
537 snprintf( buf, buflen, "NET - Failed to open a socket" );
538 if( use_ret == -(POLARSSL_ERR_NET_CONNECT_FAILED) )
539 snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
540 if( use_ret == -(POLARSSL_ERR_NET_BIND_FAILED) )
541 snprintf( buf, buflen, "NET - Binding of the socket failed" );
542 if( use_ret == -(POLARSSL_ERR_NET_LISTEN_FAILED) )
543 snprintf( buf, buflen, "NET - Could not listen on the socket" );
544 if( use_ret == -(POLARSSL_ERR_NET_ACCEPT_FAILED) )
545 snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
546 if( use_ret == -(POLARSSL_ERR_NET_RECV_FAILED) )
547 snprintf( buf, buflen, "NET - Reading information from the socket failed" );
548 if( use_ret == -(POLARSSL_ERR_NET_SEND_FAILED) )
549 snprintf( buf, buflen, "NET - Sending information through the socket failed" );
550 if( use_ret == -(POLARSSL_ERR_NET_CONN_RESET) )
551 snprintf( buf, buflen, "NET - Connection was reset by peer" );
Paul Bakker831a7552011-05-18 13:32:51 +0000552 if( use_ret == -(POLARSSL_ERR_NET_WANT_READ) )
553 snprintf( buf, buflen, "NET - Connection requires a read call" );
554 if( use_ret == -(POLARSSL_ERR_NET_WANT_WRITE) )
555 snprintf( buf, buflen, "NET - Connection requires a write call" );
Paul Bakker9d781402011-05-09 16:17:09 +0000556#endif /* POLARSSL_NET_C */
557
558#if defined(POLARSSL_PADLOCK_C)
559 if( use_ret == -(POLARSSL_ERR_PADLOCK_DATA_MISALIGNED) )
560 snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
561#endif /* POLARSSL_PADLOCK_C */
562
Paul Bakkerd14277d2012-09-26 15:19:05 +0000563#if defined(POLARSSL_PBKDF2_C)
564 if( use_ret == -(POLARSSL_ERR_PBKDF2_BAD_INPUT_DATA) )
565 snprintf( buf, buflen, "PBKDF2 - Bad input parameters to function" );
566#endif /* POLARSSL_PBKDF2_C */
567
Paul Bakker69e095c2011-12-10 21:55:01 +0000568#if defined(POLARSSL_SHA1_C)
569 if( use_ret == -(POLARSSL_ERR_SHA1_FILE_IO_ERROR) )
570 snprintf( buf, buflen, "SHA1 - Read/write error in file" );
571#endif /* POLARSSL_SHA1_C */
572
573#if defined(POLARSSL_SHA2_C)
574 if( use_ret == -(POLARSSL_ERR_SHA2_FILE_IO_ERROR) )
575 snprintf( buf, buflen, "SHA2 - Read/write error in file" );
576#endif /* POLARSSL_SHA2_C */
577
578#if defined(POLARSSL_SHA4_C)
579 if( use_ret == -(POLARSSL_ERR_SHA4_FILE_IO_ERROR) )
580 snprintf( buf, buflen, "SHA4 - Read/write error in file" );
581#endif /* POLARSSL_SHA4_C */
582
Paul Bakker9d781402011-05-09 16:17:09 +0000583#if defined(POLARSSL_XTEA_C)
584 if( use_ret == -(POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH) )
585 snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
586#endif /* POLARSSL_XTEA_C */
587
588 if( strlen( buf ) != 0 )
589 return;
590
591 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
592}
593
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100594#else /* POLARSSL_ERROR_C */
595
596#if defined(POLARSSL_ERROR_STRERROR_DUMMY)
597
598#include <string.h>
599
600/*
601 * Provide an non-function in case POLARSSL_ERROR_C is not defined
602 */
603void error_strerror( int ret, char *buf, size_t buflen )
604{
605 ((void) ret);
606
607 if( buflen > 0 )
608 buf[0] = '\0';
609}
610
611#endif /* POLARSSL_ERROR_STRERROR_DUMMY */
Paul Bakker9a736322012-11-14 12:39:52 +0000612#endif /* POLARSSL_ERROR_C */