blob: 94d8dc11d800605a7026451b2fbae21e5a12ef5f [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 Bakker3c2122f2013-06-24 19:03:14 +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 Bakkercf4365f2013-01-16 17:00:43 +010068#if defined(POLARSSL_ECP_C)
69#include "polarssl/ecp.h"
70#endif
71
Paul Bakker6083fd22011-12-03 21:45:14 +000072#if defined(POLARSSL_ENTROPY_C)
73#include "polarssl/entropy.h"
74#endif
75
Paul Bakker030277a2012-04-17 12:24:26 +000076#if defined(POLARSSL_GCM_C)
77#include "polarssl/gcm.h"
78#endif
79
Paul Bakker9d781402011-05-09 16:17:09 +000080#if defined(POLARSSL_MD_C)
81#include "polarssl/md.h"
82#endif
83
Paul Bakker69e095c2011-12-10 21:55:01 +000084#if defined(POLARSSL_MD2_C)
85#include "polarssl/md2.h"
86#endif
87
88#if defined(POLARSSL_MD4_C)
89#include "polarssl/md4.h"
90#endif
91
92#if defined(POLARSSL_MD5_C)
93#include "polarssl/md5.h"
94#endif
95
Paul Bakker9d781402011-05-09 16:17:09 +000096#if defined(POLARSSL_NET_C)
97#include "polarssl/net.h"
98#endif
99
Paul Bakkerc70b9822013-04-07 22:00:46 +0200100#if defined(POLARSSL_OID_C)
101#include "polarssl/oid.h"
102#endif
103
Paul Bakker9d781402011-05-09 16:17:09 +0000104#if defined(POLARSSL_PADLOCK_C)
105#include "polarssl/padlock.h"
106#endif
107
Paul Bakkerd14277d2012-09-26 15:19:05 +0000108#if defined(POLARSSL_PBKDF2_C)
109#include "polarssl/pbkdf2.h"
110#endif
111
Paul Bakker9d781402011-05-09 16:17:09 +0000112#if defined(POLARSSL_PEM_C)
113#include "polarssl/pem.h"
114#endif
115
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200116#if defined(POLARSSL_PK_C)
117#include "polarssl/pk.h"
118#endif
119
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200120#if defined(POLARSSL_PKCS12_C)
121#include "polarssl/pkcs12.h"
122#endif
123
Paul Bakkerb0c19a42013-06-24 19:26:38 +0200124#if defined(POLARSSL_PKCS5_C)
125#include "polarssl/pkcs5.h"
126#endif
127
Paul Bakker9d781402011-05-09 16:17:09 +0000128#if defined(POLARSSL_RSA_C)
129#include "polarssl/rsa.h"
130#endif
131
Paul Bakker69e095c2011-12-10 21:55:01 +0000132#if defined(POLARSSL_SHA1_C)
133#include "polarssl/sha1.h"
134#endif
135
Paul Bakker9e36f042013-06-30 14:34:05 +0200136#if defined(POLARSSL_SHA256_C)
Paul Bakkerd2681d82013-06-30 14:49:12 +0200137#include "polarssl/sha256.h"
Paul Bakker69e095c2011-12-10 21:55:01 +0000138#endif
139
Paul Bakker9e36f042013-06-30 14:34:05 +0200140#if defined(POLARSSL_SHA512_C)
Paul Bakkerd2681d82013-06-30 14:49:12 +0200141#include "polarssl/sha512.h"
Paul Bakker69e095c2011-12-10 21:55:01 +0000142#endif
143
Paul Bakker831a7552011-05-18 13:32:51 +0000144#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000145#include "polarssl/ssl.h"
146#endif
147
148#if defined(POLARSSL_X509_PARSE_C)
149#include "polarssl/x509.h"
150#endif
151
152#if defined(POLARSSL_XTEA_C)
153#include "polarssl/xtea.h"
154#endif
155
156
157#include <string.h>
158
Paul Bakkerdceecd82011-11-15 16:38:34 +0000159#if defined _MSC_VER && !defined snprintf
160#define snprintf _snprintf
161#endif
162
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200163void polarssl_strerror( int ret, char *buf, size_t buflen )
Paul Bakker9d781402011-05-09 16:17:09 +0000164{
165 size_t len;
166 int use_ret;
167
168 memset( buf, 0x00, buflen );
169
170 if( ret < 0 )
171 ret = -ret;
172
173 if( ret & 0xFF80 )
174 {
175 use_ret = ret & 0xFF80;
176
177 // High level error codes
178 //
Paul Bakkerff61a782011-06-09 15:42:02 +0000179#if defined(POLARSSL_CIPHER_C)
180 if( use_ret == -(POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE) )
181 snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
182 if( use_ret == -(POLARSSL_ERR_CIPHER_BAD_INPUT_DATA) )
183 snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
184 if( use_ret == -(POLARSSL_ERR_CIPHER_ALLOC_FAILED) )
185 snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
186 if( use_ret == -(POLARSSL_ERR_CIPHER_INVALID_PADDING) )
187 snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
188 if( use_ret == -(POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
189 snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
190#endif /* POLARSSL_CIPHER_C */
191
Paul Bakker9d781402011-05-09 16:17:09 +0000192#if defined(POLARSSL_DHM_C)
193 if( use_ret == -(POLARSSL_ERR_DHM_BAD_INPUT_DATA) )
194 snprintf( buf, buflen, "DHM - Bad input parameters to function" );
195 if( use_ret == -(POLARSSL_ERR_DHM_READ_PARAMS_FAILED) )
196 snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
197 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PARAMS_FAILED) )
198 snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
199 if( use_ret == -(POLARSSL_ERR_DHM_READ_PUBLIC_FAILED) )
200 snprintf( buf, buflen, "DHM - Reading of the public values failed" );
201 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PUBLIC_FAILED) )
Paul Bakker05ef8352012-05-08 09:17:57 +0000202 snprintf( buf, buflen, "DHM - Making of the public value failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000203 if( use_ret == -(POLARSSL_ERR_DHM_CALC_SECRET_FAILED) )
204 snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
205#endif /* POLARSSL_DHM_C */
206
Paul Bakkercf4365f2013-01-16 17:00:43 +0100207#if defined(POLARSSL_ECP_C)
208 if( use_ret == -(POLARSSL_ERR_ECP_BAD_INPUT_DATA) )
209 snprintf( buf, buflen, "ECP - Bad input parameters to function" );
Paul Bakker41c83d32013-03-20 14:39:14 +0100210 if( use_ret == -(POLARSSL_ERR_ECP_BUFFER_TOO_SMALL) )
211 snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
Paul Bakkercf4365f2013-01-16 17:00:43 +0100212 if( use_ret == -(POLARSSL_ERR_ECP_GENERIC) )
213 snprintf( buf, buflen, "ECP - Generic ECP error" );
Paul Bakkerfd3eac52013-06-29 23:31:33 +0200214 if( use_ret == -(POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE) )
215 snprintf( buf, buflen, "ECP - Requested curve not available" );
Paul Bakkercf4365f2013-01-16 17:00:43 +0100216#endif /* POLARSSL_ECP_C */
217
Paul Bakker9d781402011-05-09 16:17:09 +0000218#if defined(POLARSSL_MD_C)
219 if( use_ret == -(POLARSSL_ERR_MD_FEATURE_UNAVAILABLE) )
220 snprintf( buf, buflen, "MD - The selected feature is not available" );
Paul Bakker9c021ad2011-06-09 15:55:11 +0000221 if( use_ret == -(POLARSSL_ERR_MD_BAD_INPUT_DATA) )
222 snprintf( buf, buflen, "MD - Bad input parameters to function" );
223 if( use_ret == -(POLARSSL_ERR_MD_ALLOC_FAILED) )
224 snprintf( buf, buflen, "MD - Failed to allocate memory" );
Paul Bakker8913f822012-01-14 18:07:41 +0000225 if( use_ret == -(POLARSSL_ERR_MD_FILE_IO_ERROR) )
226 snprintf( buf, buflen, "MD - Opening or reading of file failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000227#endif /* POLARSSL_MD_C */
228
229#if defined(POLARSSL_PEM_C)
Paul Bakker00b28602013-06-24 13:02:41 +0200230 if( use_ret == -(POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
231 snprintf( buf, buflen, "PEM - No PEM header or footer found" );
Paul Bakker9d781402011-05-09 16:17:09 +0000232 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_DATA) )
233 snprintf( buf, buflen, "PEM - PEM string is not as expected" );
234 if( use_ret == -(POLARSSL_ERR_PEM_MALLOC_FAILED) )
235 snprintf( buf, buflen, "PEM - Failed to allocate memory" );
236 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_ENC_IV) )
237 snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
238 if( use_ret == -(POLARSSL_ERR_PEM_UNKNOWN_ENC_ALG) )
239 snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
240 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_REQUIRED) )
241 snprintf( buf, buflen, "PEM - Private key password can't be empty" );
242 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_MISMATCH) )
243 snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
244 if( use_ret == -(POLARSSL_ERR_PEM_FEATURE_UNAVAILABLE) )
245 snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
Paul Bakker00b28602013-06-24 13:02:41 +0200246 if( use_ret == -(POLARSSL_ERR_PEM_BAD_INPUT_DATA) )
247 snprintf( buf, buflen, "PEM - Bad input parameters to function" );
Paul Bakker9d781402011-05-09 16:17:09 +0000248#endif /* POLARSSL_PEM_C */
249
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200250#if defined(POLARSSL_PK_C)
251 if( use_ret == -(POLARSSL_ERR_PK_MALLOC_FAILED) )
252 snprintf( buf, buflen, "PK - Memory alloation failed" );
Manuel Pégourié-Gonnard374e4b82013-07-09 10:21:34 +0200253 if( use_ret == -(POLARSSL_ERR_PK_TYPE_MISMATCH) )
254 snprintf( buf, buflen, "PK - Type mismatch, eg attempt to use a RSA key as EC, or to modify key type" );
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200255#endif /* POLARSSL_PK_C */
256
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200257#if defined(POLARSSL_PKCS12_C)
258 if( use_ret == -(POLARSSL_ERR_PKCS12_BAD_INPUT_DATA) )
259 snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
260 if( use_ret == -(POLARSSL_ERR_PKCS12_FEATURE_UNAVAILABLE) )
261 snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
262 if( use_ret == -(POLARSSL_ERR_PKCS12_PBE_INVALID_FORMAT) )
263 snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
Paul Bakker38b50d72013-06-24 19:33:27 +0200264 if( use_ret == -(POLARSSL_ERR_PKCS12_PASSWORD_MISMATCH) )
265 snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200266#endif /* POLARSSL_PKCS12_C */
267
Paul Bakker28144de2013-06-24 19:28:55 +0200268#if defined(POLARSSL_PKCS5_C)
269 if( use_ret == -(POLARSSL_ERR_PKCS5_BAD_INPUT_DATA) )
270 snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
271 if( use_ret == -(POLARSSL_ERR_PKCS5_INVALID_FORMAT) )
272 snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
273 if( use_ret == -(POLARSSL_ERR_PKCS5_FEATURE_UNAVAILABLE) )
274 snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
275 if( use_ret == -(POLARSSL_ERR_PKCS5_PASSWORD_MISMATCH) )
276 snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
277#endif /* POLARSSL_PKCS5_C */
278
Paul Bakker9d781402011-05-09 16:17:09 +0000279#if defined(POLARSSL_RSA_C)
280 if( use_ret == -(POLARSSL_ERR_RSA_BAD_INPUT_DATA) )
281 snprintf( buf, buflen, "RSA - Bad input parameters to function" );
282 if( use_ret == -(POLARSSL_ERR_RSA_INVALID_PADDING) )
283 snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
284 if( use_ret == -(POLARSSL_ERR_RSA_KEY_GEN_FAILED) )
285 snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
286 if( use_ret == -(POLARSSL_ERR_RSA_KEY_CHECK_FAILED) )
287 snprintf( buf, buflen, "RSA - Key failed to pass the libraries validity check" );
288 if( use_ret == -(POLARSSL_ERR_RSA_PUBLIC_FAILED) )
289 snprintf( buf, buflen, "RSA - The public key operation failed" );
290 if( use_ret == -(POLARSSL_ERR_RSA_PRIVATE_FAILED) )
291 snprintf( buf, buflen, "RSA - The private key operation failed" );
292 if( use_ret == -(POLARSSL_ERR_RSA_VERIFY_FAILED) )
293 snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
294 if( use_ret == -(POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE) )
295 snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
296 if( use_ret == -(POLARSSL_ERR_RSA_RNG_FAILED) )
297 snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
298#endif /* POLARSSL_RSA_C */
299
Paul Bakker831a7552011-05-18 13:32:51 +0000300#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000301 if( use_ret == -(POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE) )
302 snprintf( buf, buflen, "SSL - The requested feature is not available" );
303 if( use_ret == -(POLARSSL_ERR_SSL_BAD_INPUT_DATA) )
304 snprintf( buf, buflen, "SSL - Bad input parameters to function" );
305 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_MAC) )
306 snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
307 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_RECORD) )
308 snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
Paul Bakker831a7552011-05-18 13:32:51 +0000309 if( use_ret == -(POLARSSL_ERR_SSL_CONN_EOF) )
310 snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
Paul Bakker9d781402011-05-09 16:17:09 +0000311 if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_CIPHER) )
312 snprintf( buf, buflen, "SSL - An unknown cipher was received" );
313 if( use_ret == -(POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN) )
314 snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
315 if( use_ret == -(POLARSSL_ERR_SSL_NO_SESSION_FOUND) )
316 snprintf( buf, buflen, "SSL - No session to recover was found" );
317 if( use_ret == -(POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE) )
318 snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
319 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE) )
320 snprintf( buf, buflen, "SSL - DESCRIPTION MISSING" );
321 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED) )
322 snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
323 if( use_ret == -(POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED) )
Paul Bakker73a899a2013-04-17 19:11:36 +0200324 snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000325 if( use_ret == -(POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED) )
326 snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
327 if( use_ret == -(POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE) )
328 snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
329 if( use_ret == -(POLARSSL_ERR_SSL_FATAL_ALERT_MESSAGE) )
Paul Bakker3aac1da2012-05-08 13:12:27 +0000330 {
Paul Bakker9d781402011-05-09 16:17:09 +0000331 snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
Paul Bakker3aac1da2012-05-08 13:12:27 +0000332 return;
333 }
Paul Bakker9d781402011-05-09 16:17:09 +0000334 if( use_ret == -(POLARSSL_ERR_SSL_PEER_VERIFY_FAILED) )
335 snprintf( buf, buflen, "SSL - Verification of our peer failed" );
336 if( use_ret == -(POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) )
337 snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
338 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO) )
339 snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
340 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO) )
341 snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
342 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE) )
343 snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
344 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
345 snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
346 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
347 snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
348 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
349 snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
350 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
351 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
Paul Bakker41c83d32013-03-20 14:39:14 +0100352 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
353 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
354 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
355 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
Paul Bakker9d781402011-05-09 16:17:09 +0000356 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
357 snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
358 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
359 snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
360 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_FINISHED) )
361 snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000362 if( use_ret == -(POLARSSL_ERR_SSL_MALLOC_FAILED) )
363 snprintf( buf, buflen, "SSL - Memory allocation failed" );
Paul Bakker05ef8352012-05-08 09:17:57 +0000364 if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FAILED) )
365 snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
366 if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
367 snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
Paul Bakker83f00bb2012-07-04 11:08:50 +0000368 if( use_ret == -(POLARSSL_ERR_SSL_COMPRESSION_FAILED) )
369 snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
Paul Bakker1d29fb52012-09-28 13:28:45 +0000370 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
371 snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
Manuel Pégourié-Gonnarda5cc6022013-07-31 12:58:16 +0200372 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
373 snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
Paul Bakker831a7552011-05-18 13:32:51 +0000374#endif /* POLARSSL_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000375
376#if defined(POLARSSL_X509_PARSE_C)
377 if( use_ret == -(POLARSSL_ERR_X509_FEATURE_UNAVAILABLE) )
378 snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
379 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_PEM) )
380 snprintf( buf, buflen, "X509 - The PEM-encoded certificate contains invalid elements, e.g. invalid character" );
381 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_FORMAT) )
382 snprintf( buf, buflen, "X509 - The certificate format is invalid, e.g. different type expected" );
383 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_VERSION) )
384 snprintf( buf, buflen, "X509 - The certificate version element is invalid" );
385 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_SERIAL) )
386 snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
387 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_ALG) )
388 snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
389 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_NAME) )
390 snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
391 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_DATE) )
392 snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
393 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_PUBKEY) )
394 snprintf( buf, buflen, "X509 - The pubkey tag or value is invalid (only RSA is supported)" );
395 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE) )
396 snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
397 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS) )
398 snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
399 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION) )
400 snprintf( buf, buflen, "X509 - Certificate or CRL has an unsupported version number" );
401 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG) )
402 snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
Paul Bakker9db77422011-07-13 11:47:32 +0000403 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_PK_ALG) )
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200404 snprintf( buf, buflen, "X509 - Key algorithm is unsupported (only RSA and EC are supported)" );
Paul Bakker9d781402011-05-09 16:17:09 +0000405 if( use_ret == -(POLARSSL_ERR_X509_CERT_SIG_MISMATCH) )
406 snprintf( buf, buflen, "X509 - Certificate signature algorithms do not match. (see \\c ::x509_cert sig_oid)" );
407 if( use_ret == -(POLARSSL_ERR_X509_CERT_VERIFY_FAILED) )
408 snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
409 if( use_ret == -(POLARSSL_ERR_X509_KEY_INVALID_VERSION) )
410 snprintf( buf, buflen, "X509 - Unsupported RSA key version" );
411 if( use_ret == -(POLARSSL_ERR_X509_KEY_INVALID_FORMAT) )
412 snprintf( buf, buflen, "X509 - Invalid RSA key tag or value" );
Paul Bakker6c0ceb32011-12-04 12:24:18 +0000413 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT) )
414 snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000415 if( use_ret == -(POLARSSL_ERR_X509_INVALID_INPUT) )
416 snprintf( buf, buflen, "X509 - Input invalid" );
417 if( use_ret == -(POLARSSL_ERR_X509_MALLOC_FAILED) )
418 snprintf( buf, buflen, "X509 - Allocation of memory failed" );
419 if( use_ret == -(POLARSSL_ERR_X509_FILE_IO_ERROR) )
420 snprintf( buf, buflen, "X509 - Read/write of file failed" );
Paul Bakker28144de2013-06-24 19:28:55 +0200421 if( use_ret == -(POLARSSL_ERR_X509_PASSWORD_REQUIRED) )
422 snprintf( buf, buflen, "X509 - Private key password can't be empty" );
423 if( use_ret == -(POLARSSL_ERR_X509_PASSWORD_MISMATCH) )
424 snprintf( buf, buflen, "X509 - Given private key password does not allow for correct decryption" );
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200425 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_NAMED_CURVE) )
426 snprintf( buf, buflen, "X509 - Elliptic curve is unsupported (only NIST curves are supported)" );
Paul Bakker9d781402011-05-09 16:17:09 +0000427#endif /* POLARSSL_X509_PARSE_C */
428
429 if( strlen( buf ) == 0 )
430 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
431 }
432
433 use_ret = ret & ~0xFF80;
434
435 if( use_ret == 0 )
436 return;
437
438 // If high level code is present, make a concatenation between both
439 // error strings.
440 //
441 len = strlen( buf );
442
443 if( len > 0 )
444 {
445 if( buflen - len < 5 )
446 return;
447
448 snprintf( buf + len, buflen - len, " : " );
449
450 buf += len + 3;
451 buflen -= len + 3;
452 }
453
454 // Low level error codes
455 //
456#if defined(POLARSSL_AES_C)
457 if( use_ret == -(POLARSSL_ERR_AES_INVALID_KEY_LENGTH) )
458 snprintf( buf, buflen, "AES - Invalid key length" );
459 if( use_ret == -(POLARSSL_ERR_AES_INVALID_INPUT_LENGTH) )
460 snprintf( buf, buflen, "AES - Invalid data input length" );
461#endif /* POLARSSL_AES_C */
462
Paul Bakkerdceecd82011-11-15 16:38:34 +0000463#if defined(POLARSSL_ASN1_PARSE_C)
464 if( use_ret == -(POLARSSL_ERR_ASN1_OUT_OF_DATA) )
465 snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
466 if( use_ret == -(POLARSSL_ERR_ASN1_UNEXPECTED_TAG) )
467 snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
468 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_LENGTH) )
469 snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
470 if( use_ret == -(POLARSSL_ERR_ASN1_LENGTH_MISMATCH) )
471 snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
472 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_DATA) )
473 snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000474 if( use_ret == -(POLARSSL_ERR_ASN1_MALLOC_FAILED) )
475 snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000476 if( use_ret == -(POLARSSL_ERR_ASN1_BUF_TOO_SMALL) )
477 snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
Paul Bakkerdceecd82011-11-15 16:38:34 +0000478#endif /* POLARSSL_ASN1_PARSE_C */
479
Paul Bakker9d781402011-05-09 16:17:09 +0000480#if defined(POLARSSL_BASE64_C)
481 if( use_ret == -(POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) )
482 snprintf( buf, buflen, "BASE64 - Output buffer too small" );
483 if( use_ret == -(POLARSSL_ERR_BASE64_INVALID_CHARACTER) )
484 snprintf( buf, buflen, "BASE64 - Invalid character in input" );
485#endif /* POLARSSL_BASE64_C */
486
487#if defined(POLARSSL_BIGNUM_C)
488 if( use_ret == -(POLARSSL_ERR_MPI_FILE_IO_ERROR) )
489 snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
490 if( use_ret == -(POLARSSL_ERR_MPI_BAD_INPUT_DATA) )
491 snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
492 if( use_ret == -(POLARSSL_ERR_MPI_INVALID_CHARACTER) )
493 snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
494 if( use_ret == -(POLARSSL_ERR_MPI_BUFFER_TOO_SMALL) )
Paul Bakker69e095c2011-12-10 21:55:01 +0000495 snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
Paul Bakker9d781402011-05-09 16:17:09 +0000496 if( use_ret == -(POLARSSL_ERR_MPI_NEGATIVE_VALUE) )
497 snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
498 if( use_ret == -(POLARSSL_ERR_MPI_DIVISION_BY_ZERO) )
499 snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
500 if( use_ret == -(POLARSSL_ERR_MPI_NOT_ACCEPTABLE) )
501 snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000502 if( use_ret == -(POLARSSL_ERR_MPI_MALLOC_FAILED) )
503 snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000504#endif /* POLARSSL_BIGNUM_C */
505
Paul Bakker83f00bb2012-07-04 11:08:50 +0000506#if defined(POLARSSL_BLOWFISH_C)
507 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
508 snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
509 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
510 snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
511#endif /* POLARSSL_BLOWFISH_C */
512
Paul Bakker9d781402011-05-09 16:17:09 +0000513#if defined(POLARSSL_CAMELLIA_C)
514 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
515 snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
516 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
517 snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
518#endif /* POLARSSL_CAMELLIA_C */
519
Paul Bakker880ac7e2011-11-27 14:50:49 +0000520#if defined(POLARSSL_CTR_DRBG_C)
521 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
522 snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
523 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
524 snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
525 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG) )
526 snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000527 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR) )
528 snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
Paul Bakker880ac7e2011-11-27 14:50:49 +0000529#endif /* POLARSSL_CTR_DRBG_C */
530
Paul Bakker9d781402011-05-09 16:17:09 +0000531#if defined(POLARSSL_DES_C)
532 if( use_ret == -(POLARSSL_ERR_DES_INVALID_INPUT_LENGTH) )
533 snprintf( buf, buflen, "DES - The data input has an invalid length" );
534#endif /* POLARSSL_DES_C */
535
Paul Bakker6083fd22011-12-03 21:45:14 +0000536#if defined(POLARSSL_ENTROPY_C)
537 if( use_ret == -(POLARSSL_ERR_ENTROPY_SOURCE_FAILED) )
538 snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
539 if( use_ret == -(POLARSSL_ERR_ENTROPY_MAX_SOURCES) )
540 snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
Paul Bakker43655f42011-12-15 20:11:16 +0000541 if( use_ret == -(POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED) )
542 snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
Paul Bakker6083fd22011-12-03 21:45:14 +0000543#endif /* POLARSSL_ENTROPY_C */
544
Paul Bakker030277a2012-04-17 12:24:26 +0000545#if defined(POLARSSL_GCM_C)
546 if( use_ret == -(POLARSSL_ERR_GCM_AUTH_FAILED) )
547 snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
Paul Bakkerd8ef1672012-04-18 14:17:32 +0000548 if( use_ret == -(POLARSSL_ERR_GCM_BAD_INPUT) )
549 snprintf( buf, buflen, "GCM - Bad input parameters to function" );
Paul Bakker030277a2012-04-17 12:24:26 +0000550#endif /* POLARSSL_GCM_C */
551
Paul Bakker69e095c2011-12-10 21:55:01 +0000552#if defined(POLARSSL_MD2_C)
553 if( use_ret == -(POLARSSL_ERR_MD2_FILE_IO_ERROR) )
554 snprintf( buf, buflen, "MD2 - Read/write error in file" );
555#endif /* POLARSSL_MD2_C */
556
557#if defined(POLARSSL_MD4_C)
558 if( use_ret == -(POLARSSL_ERR_MD4_FILE_IO_ERROR) )
559 snprintf( buf, buflen, "MD4 - Read/write error in file" );
560#endif /* POLARSSL_MD4_C */
561
562#if defined(POLARSSL_MD5_C)
563 if( use_ret == -(POLARSSL_ERR_MD5_FILE_IO_ERROR) )
564 snprintf( buf, buflen, "MD5 - Read/write error in file" );
565#endif /* POLARSSL_MD5_C */
566
Paul Bakker9d781402011-05-09 16:17:09 +0000567#if defined(POLARSSL_NET_C)
568 if( use_ret == -(POLARSSL_ERR_NET_UNKNOWN_HOST) )
569 snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
570 if( use_ret == -(POLARSSL_ERR_NET_SOCKET_FAILED) )
571 snprintf( buf, buflen, "NET - Failed to open a socket" );
572 if( use_ret == -(POLARSSL_ERR_NET_CONNECT_FAILED) )
573 snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
574 if( use_ret == -(POLARSSL_ERR_NET_BIND_FAILED) )
575 snprintf( buf, buflen, "NET - Binding of the socket failed" );
576 if( use_ret == -(POLARSSL_ERR_NET_LISTEN_FAILED) )
577 snprintf( buf, buflen, "NET - Could not listen on the socket" );
578 if( use_ret == -(POLARSSL_ERR_NET_ACCEPT_FAILED) )
579 snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
580 if( use_ret == -(POLARSSL_ERR_NET_RECV_FAILED) )
581 snprintf( buf, buflen, "NET - Reading information from the socket failed" );
582 if( use_ret == -(POLARSSL_ERR_NET_SEND_FAILED) )
583 snprintf( buf, buflen, "NET - Sending information through the socket failed" );
584 if( use_ret == -(POLARSSL_ERR_NET_CONN_RESET) )
585 snprintf( buf, buflen, "NET - Connection was reset by peer" );
Paul Bakker831a7552011-05-18 13:32:51 +0000586 if( use_ret == -(POLARSSL_ERR_NET_WANT_READ) )
587 snprintf( buf, buflen, "NET - Connection requires a read call" );
588 if( use_ret == -(POLARSSL_ERR_NET_WANT_WRITE) )
589 snprintf( buf, buflen, "NET - Connection requires a write call" );
Paul Bakker9d781402011-05-09 16:17:09 +0000590#endif /* POLARSSL_NET_C */
591
Paul Bakkerc70b9822013-04-07 22:00:46 +0200592#if defined(POLARSSL_OID_C)
593 if( use_ret == -(POLARSSL_ERR_OID_NOT_FOUND) )
594 snprintf( buf, buflen, "OID - OID is not found" );
595#endif /* POLARSSL_OID_C */
596
Paul Bakker9d781402011-05-09 16:17:09 +0000597#if defined(POLARSSL_PADLOCK_C)
598 if( use_ret == -(POLARSSL_ERR_PADLOCK_DATA_MISALIGNED) )
599 snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
600#endif /* POLARSSL_PADLOCK_C */
601
Paul Bakkerd14277d2012-09-26 15:19:05 +0000602#if defined(POLARSSL_PBKDF2_C)
603 if( use_ret == -(POLARSSL_ERR_PBKDF2_BAD_INPUT_DATA) )
604 snprintf( buf, buflen, "PBKDF2 - Bad input parameters to function" );
605#endif /* POLARSSL_PBKDF2_C */
606
Paul Bakker69e095c2011-12-10 21:55:01 +0000607#if defined(POLARSSL_SHA1_C)
608 if( use_ret == -(POLARSSL_ERR_SHA1_FILE_IO_ERROR) )
609 snprintf( buf, buflen, "SHA1 - Read/write error in file" );
610#endif /* POLARSSL_SHA1_C */
611
Paul Bakker9e36f042013-06-30 14:34:05 +0200612#if defined(POLARSSL_SHA256_C)
613 if( use_ret == -(POLARSSL_ERR_SHA256_FILE_IO_ERROR) )
614 snprintf( buf, buflen, "SHA256 - Read/write error in file" );
615#endif /* POLARSSL_SHA256_C */
Paul Bakker69e095c2011-12-10 21:55:01 +0000616
Paul Bakker9e36f042013-06-30 14:34:05 +0200617#if defined(POLARSSL_SHA512_C)
618 if( use_ret == -(POLARSSL_ERR_SHA512_FILE_IO_ERROR) )
619 snprintf( buf, buflen, "SHA512 - Read/write error in file" );
620#endif /* POLARSSL_SHA512_C */
Paul Bakker69e095c2011-12-10 21:55:01 +0000621
Paul Bakker9d781402011-05-09 16:17:09 +0000622#if defined(POLARSSL_XTEA_C)
623 if( use_ret == -(POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH) )
624 snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
625#endif /* POLARSSL_XTEA_C */
626
627 if( strlen( buf ) != 0 )
628 return;
629
630 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
631}
632
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200633#if defined(POLARSSL_ERROR_STRERROR_BC)
634void error_strerror( int ret, char *buf, size_t buflen )
635{
636 return polarssl_strerror( ret, buf, buflen );
637}
638#endif /* POLARSSL_ERROR_STRERROR_BC */
639
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100640#else /* POLARSSL_ERROR_C */
641
642#if defined(POLARSSL_ERROR_STRERROR_DUMMY)
643
644#include <string.h>
645
646/*
647 * Provide an non-function in case POLARSSL_ERROR_C is not defined
648 */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200649void polarssl_strerror( int ret, char *buf, size_t buflen )
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100650{
651 ((void) ret);
652
653 if( buflen > 0 )
654 buf[0] = '\0';
655}
656
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200657#if defined(POLARSSL_ERROR_STRERROR_BC)
658void error_strerror( int ret, char *buf, size_t buflen )
659{
660 return polarssl_strerror( ret, buf, buflen );
661}
662#endif /* POLARSSL_ERROR_STRERROR_BC */
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100663#endif /* POLARSSL_ERROR_STRERROR_DUMMY */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200664
Paul Bakker9a736322012-11-14 12:39:52 +0000665#endif /* POLARSSL_ERROR_C */