blob: 9c89658545ebcbd6481ae8a55dfa332f7407a732 [file] [log] [blame]
Paul Bakker9d781402011-05-09 16:17:09 +00001/*
2 * Error message information
3 *
Paul Bakker530927b2015-02-13 14:24:10 +01004 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Paul Bakker9d781402011-05-09 16:17:09 +00005 *
Manuel Pégourié-Gonnarde12abf92015-01-28 17:13:45 +00006 * This file is part of mbed TLS (https://polarssl.org)
Paul Bakker9d781402011-05-09 16:17:09 +00007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23#include "polarssl/config.h"
24
25#if defined(POLARSSL_ERROR_C)
26
Paul Bakkereae09db2013-06-06 12:35:54 +020027#include "polarssl/error.h"
28
Paul Bakker9d781402011-05-09 16:17:09 +000029#if defined(POLARSSL_AES_C)
30#include "polarssl/aes.h"
31#endif
32
33#if defined(POLARSSL_BASE64_C)
34#include "polarssl/base64.h"
35#endif
36
37#if defined(POLARSSL_BIGNUM_C)
38#include "polarssl/bignum.h"
39#endif
40
Paul Bakker83f00bb2012-07-04 11:08:50 +000041#if defined(POLARSSL_BLOWFISH_C)
42#include "polarssl/blowfish.h"
43#endif
44
Paul Bakker9d781402011-05-09 16:17:09 +000045#if defined(POLARSSL_CAMELLIA_C)
46#include "polarssl/camellia.h"
47#endif
48
Paul Bakkerff61a782011-06-09 15:42:02 +000049#if defined(POLARSSL_CIPHER_C)
50#include "polarssl/cipher.h"
51#endif
52
Paul Bakker880ac7e2011-11-27 14:50:49 +000053#if defined(POLARSSL_CTR_DRBG_C)
54#include "polarssl/ctr_drbg.h"
55#endif
56
Paul Bakker9d781402011-05-09 16:17:09 +000057#if defined(POLARSSL_DES_C)
58#include "polarssl/des.h"
59#endif
60
61#if defined(POLARSSL_DHM_C)
62#include "polarssl/dhm.h"
63#endif
64
Paul Bakker6083fd22011-12-03 21:45:14 +000065#if defined(POLARSSL_ENTROPY_C)
66#include "polarssl/entropy.h"
67#endif
68
Paul Bakker030277a2012-04-17 12:24:26 +000069#if defined(POLARSSL_GCM_C)
70#include "polarssl/gcm.h"
71#endif
72
Paul Bakker9d781402011-05-09 16:17:09 +000073#if defined(POLARSSL_MD_C)
74#include "polarssl/md.h"
75#endif
76
Paul Bakker69e095c2011-12-10 21:55:01 +000077#if defined(POLARSSL_MD2_C)
78#include "polarssl/md2.h"
79#endif
80
81#if defined(POLARSSL_MD4_C)
82#include "polarssl/md4.h"
83#endif
84
85#if defined(POLARSSL_MD5_C)
86#include "polarssl/md5.h"
87#endif
88
Paul Bakker9d781402011-05-09 16:17:09 +000089#if defined(POLARSSL_NET_C)
90#include "polarssl/net.h"
91#endif
92
93#if defined(POLARSSL_PADLOCK_C)
94#include "polarssl/padlock.h"
95#endif
96
Paul Bakkerd14277d2012-09-26 15:19:05 +000097#if defined(POLARSSL_PBKDF2_C)
98#include "polarssl/pbkdf2.h"
99#endif
100
Paul Bakker9d781402011-05-09 16:17:09 +0000101#if defined(POLARSSL_PEM_C)
102#include "polarssl/pem.h"
103#endif
104
Paul Bakkercf6e95d2013-06-12 13:18:15 +0200105#if defined(POLARSSL_PKCS12_C)
106#include "polarssl/pkcs12.h"
107#endif
108
Paul Bakker19bd2972013-06-14 12:06:45 +0200109#if defined(POLARSSL_PKCS5_C)
110#include "polarssl/pkcs5.h"
111#endif
112
Paul Bakker9d781402011-05-09 16:17:09 +0000113#if defined(POLARSSL_RSA_C)
114#include "polarssl/rsa.h"
115#endif
116
Paul Bakker69e095c2011-12-10 21:55:01 +0000117#if defined(POLARSSL_SHA1_C)
118#include "polarssl/sha1.h"
119#endif
120
121#if defined(POLARSSL_SHA2_C)
122#include "polarssl/sha2.h"
123#endif
124
125#if defined(POLARSSL_SHA4_C)
126#include "polarssl/sha4.h"
127#endif
128
Paul Bakker831a7552011-05-18 13:32:51 +0000129#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000130#include "polarssl/ssl.h"
131#endif
132
133#if defined(POLARSSL_X509_PARSE_C)
134#include "polarssl/x509.h"
135#endif
136
137#if defined(POLARSSL_XTEA_C)
138#include "polarssl/xtea.h"
139#endif
140
141
142#include <string.h>
143
Paul Bakkerdceecd82011-11-15 16:38:34 +0000144#if defined _MSC_VER && !defined snprintf
145#define snprintf _snprintf
146#endif
147
Paul Bakker9d781402011-05-09 16:17:09 +0000148void error_strerror( int ret, char *buf, size_t buflen )
149{
150 size_t len;
151 int use_ret;
152
153 memset( buf, 0x00, buflen );
154
155 if( ret < 0 )
156 ret = -ret;
157
158 if( ret & 0xFF80 )
159 {
160 use_ret = ret & 0xFF80;
161
162 // High level error codes
163 //
Paul Bakkerff61a782011-06-09 15:42:02 +0000164#if defined(POLARSSL_CIPHER_C)
165 if( use_ret == -(POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE) )
166 snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
167 if( use_ret == -(POLARSSL_ERR_CIPHER_BAD_INPUT_DATA) )
168 snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
169 if( use_ret == -(POLARSSL_ERR_CIPHER_ALLOC_FAILED) )
170 snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
171 if( use_ret == -(POLARSSL_ERR_CIPHER_INVALID_PADDING) )
172 snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
173 if( use_ret == -(POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
174 snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
175#endif /* POLARSSL_CIPHER_C */
176
Paul Bakker9d781402011-05-09 16:17:09 +0000177#if defined(POLARSSL_DHM_C)
178 if( use_ret == -(POLARSSL_ERR_DHM_BAD_INPUT_DATA) )
179 snprintf( buf, buflen, "DHM - Bad input parameters to function" );
180 if( use_ret == -(POLARSSL_ERR_DHM_READ_PARAMS_FAILED) )
181 snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
182 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PARAMS_FAILED) )
183 snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
184 if( use_ret == -(POLARSSL_ERR_DHM_READ_PUBLIC_FAILED) )
185 snprintf( buf, buflen, "DHM - Reading of the public values failed" );
186 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PUBLIC_FAILED) )
Paul Bakker05ef8352012-05-08 09:17:57 +0000187 snprintf( buf, buflen, "DHM - Making of the public value failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000188 if( use_ret == -(POLARSSL_ERR_DHM_CALC_SECRET_FAILED) )
189 snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
190#endif /* POLARSSL_DHM_C */
191
192#if defined(POLARSSL_MD_C)
193 if( use_ret == -(POLARSSL_ERR_MD_FEATURE_UNAVAILABLE) )
194 snprintf( buf, buflen, "MD - The selected feature is not available" );
Paul Bakker9c021ad2011-06-09 15:55:11 +0000195 if( use_ret == -(POLARSSL_ERR_MD_BAD_INPUT_DATA) )
196 snprintf( buf, buflen, "MD - Bad input parameters to function" );
197 if( use_ret == -(POLARSSL_ERR_MD_ALLOC_FAILED) )
198 snprintf( buf, buflen, "MD - Failed to allocate memory" );
Paul Bakker8913f822012-01-14 18:07:41 +0000199 if( use_ret == -(POLARSSL_ERR_MD_FILE_IO_ERROR) )
200 snprintf( buf, buflen, "MD - Opening or reading of file failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000201#endif /* POLARSSL_MD_C */
202
203#if defined(POLARSSL_PEM_C)
Paul Bakker9255e832013-06-06 14:58:28 +0200204 if( use_ret == -(POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
205 snprintf( buf, buflen, "PEM - No PEM header or footer found" );
Paul Bakker9d781402011-05-09 16:17:09 +0000206 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_DATA) )
207 snprintf( buf, buflen, "PEM - PEM string is not as expected" );
208 if( use_ret == -(POLARSSL_ERR_PEM_MALLOC_FAILED) )
209 snprintf( buf, buflen, "PEM - Failed to allocate memory" );
210 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_ENC_IV) )
211 snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
212 if( use_ret == -(POLARSSL_ERR_PEM_UNKNOWN_ENC_ALG) )
213 snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
214 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_REQUIRED) )
215 snprintf( buf, buflen, "PEM - Private key password can't be empty" );
216 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_MISMATCH) )
217 snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
218 if( use_ret == -(POLARSSL_ERR_PEM_FEATURE_UNAVAILABLE) )
219 snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
Paul Bakker9255e832013-06-06 14:58:28 +0200220 if( use_ret == -(POLARSSL_ERR_PEM_BAD_INPUT_DATA) )
221 snprintf( buf, buflen, "PEM - Bad input parameters to function" );
Paul Bakker9d781402011-05-09 16:17:09 +0000222#endif /* POLARSSL_PEM_C */
223
Paul Bakkercf6e95d2013-06-12 13:18:15 +0200224#if defined(POLARSSL_PKCS12_C)
225 if( use_ret == -(POLARSSL_ERR_PKCS12_BAD_INPUT_DATA) )
226 snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
227 if( use_ret == -(POLARSSL_ERR_PKCS12_FEATURE_UNAVAILABLE) )
228 snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
229 if( use_ret == -(POLARSSL_ERR_PKCS12_PBE_INVALID_FORMAT) )
230 snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
Paul Bakker14a222c2013-06-18 16:35:48 +0200231 if( use_ret == -(POLARSSL_ERR_PKCS12_PASSWORD_MISMATCH) )
232 snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
Paul Bakkercf6e95d2013-06-12 13:18:15 +0200233#endif /* POLARSSL_PKCS12_C */
234
Paul Bakker1fd43212013-06-17 15:14:42 +0200235#if defined(POLARSSL_PKCS5_C)
236 if( use_ret == -(POLARSSL_ERR_PKCS5_BAD_INPUT_DATA) )
237 snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
238 if( use_ret == -(POLARSSL_ERR_PKCS5_INVALID_FORMAT) )
239 snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
240 if( use_ret == -(POLARSSL_ERR_PKCS5_FEATURE_UNAVAILABLE) )
241 snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
242 if( use_ret == -(POLARSSL_ERR_PKCS5_PASSWORD_MISMATCH) )
243 snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
244#endif /* POLARSSL_PKCS5_C */
245
Paul Bakker9d781402011-05-09 16:17:09 +0000246#if defined(POLARSSL_RSA_C)
247 if( use_ret == -(POLARSSL_ERR_RSA_BAD_INPUT_DATA) )
248 snprintf( buf, buflen, "RSA - Bad input parameters to function" );
249 if( use_ret == -(POLARSSL_ERR_RSA_INVALID_PADDING) )
250 snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
251 if( use_ret == -(POLARSSL_ERR_RSA_KEY_GEN_FAILED) )
252 snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
253 if( use_ret == -(POLARSSL_ERR_RSA_KEY_CHECK_FAILED) )
254 snprintf( buf, buflen, "RSA - Key failed to pass the libraries validity check" );
255 if( use_ret == -(POLARSSL_ERR_RSA_PUBLIC_FAILED) )
256 snprintf( buf, buflen, "RSA - The public key operation failed" );
257 if( use_ret == -(POLARSSL_ERR_RSA_PRIVATE_FAILED) )
258 snprintf( buf, buflen, "RSA - The private key operation failed" );
259 if( use_ret == -(POLARSSL_ERR_RSA_VERIFY_FAILED) )
260 snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
261 if( use_ret == -(POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE) )
262 snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
263 if( use_ret == -(POLARSSL_ERR_RSA_RNG_FAILED) )
264 snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
265#endif /* POLARSSL_RSA_C */
266
Paul Bakker831a7552011-05-18 13:32:51 +0000267#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000268 if( use_ret == -(POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE) )
269 snprintf( buf, buflen, "SSL - The requested feature is not available" );
270 if( use_ret == -(POLARSSL_ERR_SSL_BAD_INPUT_DATA) )
271 snprintf( buf, buflen, "SSL - Bad input parameters to function" );
272 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_MAC) )
273 snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
274 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_RECORD) )
275 snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
Paul Bakker831a7552011-05-18 13:32:51 +0000276 if( use_ret == -(POLARSSL_ERR_SSL_CONN_EOF) )
277 snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
Paul Bakker9d781402011-05-09 16:17:09 +0000278 if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_CIPHER) )
279 snprintf( buf, buflen, "SSL - An unknown cipher was received" );
280 if( use_ret == -(POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN) )
281 snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
Paul Bakkera1caf6e2013-11-21 17:31:06 +0100282 if( use_ret == -(POLARSSL_ERR_SSL_NO_RNG) )
283 snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
Paul Bakker9d781402011-05-09 16:17:09 +0000284 if( use_ret == -(POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE) )
285 snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
286 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE) )
287 snprintf( buf, buflen, "SSL - DESCRIPTION MISSING" );
288 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED) )
289 snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
290 if( use_ret == -(POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED) )
291 snprintf( buf, buflen, "SSL - The own private key is not set, but needed" );
292 if( use_ret == -(POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED) )
293 snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
294 if( use_ret == -(POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE) )
295 snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
296 if( use_ret == -(POLARSSL_ERR_SSL_FATAL_ALERT_MESSAGE) )
Paul Bakker3aac1da2012-05-08 13:12:27 +0000297 {
Paul Bakker9d781402011-05-09 16:17:09 +0000298 snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
Paul Bakker3aac1da2012-05-08 13:12:27 +0000299 return;
300 }
Paul Bakker9d781402011-05-09 16:17:09 +0000301 if( use_ret == -(POLARSSL_ERR_SSL_PEER_VERIFY_FAILED) )
302 snprintf( buf, buflen, "SSL - Verification of our peer failed" );
303 if( use_ret == -(POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) )
304 snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
305 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO) )
306 snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
307 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO) )
308 snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
309 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE) )
310 snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
311 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
312 snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
313 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
314 snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
315 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
316 snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
317 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
318 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
319 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_RP) )
320 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM Read Public" );
321 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_CS) )
322 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM Calculate Secret" );
323 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
324 snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
325 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
326 snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
327 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_FINISHED) )
328 snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000329 if( use_ret == -(POLARSSL_ERR_SSL_MALLOC_FAILED) )
330 snprintf( buf, buflen, "SSL - Memory allocation failed" );
Paul Bakker05ef8352012-05-08 09:17:57 +0000331 if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FAILED) )
332 snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
333 if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
334 snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
Paul Bakker83f00bb2012-07-04 11:08:50 +0000335 if( use_ret == -(POLARSSL_ERR_SSL_COMPRESSION_FAILED) )
336 snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
Paul Bakker1d29fb52012-09-28 13:28:45 +0000337 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
338 snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
Manuel Pégourié-Gonnardbe046732014-03-10 21:20:29 +0100339 if( use_ret == -(POLARSSL_ERR_SSL_COUNTER_WRAPPING) )
340 snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
Paul Bakker831a7552011-05-18 13:32:51 +0000341#endif /* POLARSSL_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000342
343#if defined(POLARSSL_X509_PARSE_C)
344 if( use_ret == -(POLARSSL_ERR_X509_FEATURE_UNAVAILABLE) )
345 snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
346 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_PEM) )
347 snprintf( buf, buflen, "X509 - The PEM-encoded certificate contains invalid elements, e.g. invalid character" );
348 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_FORMAT) )
349 snprintf( buf, buflen, "X509 - The certificate format is invalid, e.g. different type expected" );
350 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_VERSION) )
351 snprintf( buf, buflen, "X509 - The certificate version element is invalid" );
352 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_SERIAL) )
353 snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
354 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_ALG) )
355 snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
356 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_NAME) )
357 snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
358 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_DATE) )
359 snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
360 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_PUBKEY) )
361 snprintf( buf, buflen, "X509 - The pubkey tag or value is invalid (only RSA is supported)" );
362 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE) )
363 snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
364 if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS) )
365 snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
366 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION) )
367 snprintf( buf, buflen, "X509 - Certificate or CRL has an unsupported version number" );
368 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG) )
369 snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
Paul Bakker9db77422011-07-13 11:47:32 +0000370 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_PK_ALG) )
371 snprintf( buf, buflen, "X509 - Key algorithm is unsupported (only RSA is supported)" );
Paul Bakker9d781402011-05-09 16:17:09 +0000372 if( use_ret == -(POLARSSL_ERR_X509_CERT_SIG_MISMATCH) )
373 snprintf( buf, buflen, "X509 - Certificate signature algorithms do not match. (see \\c ::x509_cert sig_oid)" );
374 if( use_ret == -(POLARSSL_ERR_X509_CERT_VERIFY_FAILED) )
375 snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
376 if( use_ret == -(POLARSSL_ERR_X509_KEY_INVALID_VERSION) )
377 snprintf( buf, buflen, "X509 - Unsupported RSA key version" );
378 if( use_ret == -(POLARSSL_ERR_X509_KEY_INVALID_FORMAT) )
379 snprintf( buf, buflen, "X509 - Invalid RSA key tag or value" );
Paul Bakker6c0ceb32011-12-04 12:24:18 +0000380 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT) )
381 snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000382 if( use_ret == -(POLARSSL_ERR_X509_INVALID_INPUT) )
383 snprintf( buf, buflen, "X509 - Input invalid" );
384 if( use_ret == -(POLARSSL_ERR_X509_MALLOC_FAILED) )
385 snprintf( buf, buflen, "X509 - Allocation of memory failed" );
386 if( use_ret == -(POLARSSL_ERR_X509_FILE_IO_ERROR) )
387 snprintf( buf, buflen, "X509 - Read/write of file failed" );
Paul Bakker1fd43212013-06-17 15:14:42 +0200388 if( use_ret == -(POLARSSL_ERR_X509_PASSWORD_REQUIRED) )
389 snprintf( buf, buflen, "X509 - Private key password can't be empty" );
390 if( use_ret == -(POLARSSL_ERR_X509_PASSWORD_MISMATCH) )
391 snprintf( buf, buflen, "X509 - Given private key password does not allow for correct decryption" );
Paul Bakker9d781402011-05-09 16:17:09 +0000392#endif /* POLARSSL_X509_PARSE_C */
393
394 if( strlen( buf ) == 0 )
395 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
396 }
397
398 use_ret = ret & ~0xFF80;
399
400 if( use_ret == 0 )
401 return;
402
403 // If high level code is present, make a concatenation between both
404 // error strings.
405 //
406 len = strlen( buf );
407
408 if( len > 0 )
409 {
410 if( buflen - len < 5 )
411 return;
412
413 snprintf( buf + len, buflen - len, " : " );
414
415 buf += len + 3;
416 buflen -= len + 3;
417 }
418
419 // Low level error codes
420 //
421#if defined(POLARSSL_AES_C)
422 if( use_ret == -(POLARSSL_ERR_AES_INVALID_KEY_LENGTH) )
423 snprintf( buf, buflen, "AES - Invalid key length" );
424 if( use_ret == -(POLARSSL_ERR_AES_INVALID_INPUT_LENGTH) )
425 snprintf( buf, buflen, "AES - Invalid data input length" );
426#endif /* POLARSSL_AES_C */
427
Paul Bakkerdceecd82011-11-15 16:38:34 +0000428#if defined(POLARSSL_ASN1_PARSE_C)
429 if( use_ret == -(POLARSSL_ERR_ASN1_OUT_OF_DATA) )
430 snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
431 if( use_ret == -(POLARSSL_ERR_ASN1_UNEXPECTED_TAG) )
432 snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
433 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_LENGTH) )
434 snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
435 if( use_ret == -(POLARSSL_ERR_ASN1_LENGTH_MISMATCH) )
436 snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
437 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_DATA) )
438 snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000439 if( use_ret == -(POLARSSL_ERR_ASN1_MALLOC_FAILED) )
440 snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000441 if( use_ret == -(POLARSSL_ERR_ASN1_BUF_TOO_SMALL) )
442 snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
Paul Bakkerdceecd82011-11-15 16:38:34 +0000443#endif /* POLARSSL_ASN1_PARSE_C */
444
Paul Bakker9d781402011-05-09 16:17:09 +0000445#if defined(POLARSSL_BASE64_C)
446 if( use_ret == -(POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) )
447 snprintf( buf, buflen, "BASE64 - Output buffer too small" );
448 if( use_ret == -(POLARSSL_ERR_BASE64_INVALID_CHARACTER) )
449 snprintf( buf, buflen, "BASE64 - Invalid character in input" );
450#endif /* POLARSSL_BASE64_C */
451
452#if defined(POLARSSL_BIGNUM_C)
453 if( use_ret == -(POLARSSL_ERR_MPI_FILE_IO_ERROR) )
454 snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
455 if( use_ret == -(POLARSSL_ERR_MPI_BAD_INPUT_DATA) )
456 snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
457 if( use_ret == -(POLARSSL_ERR_MPI_INVALID_CHARACTER) )
458 snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
459 if( use_ret == -(POLARSSL_ERR_MPI_BUFFER_TOO_SMALL) )
Paul Bakker69e095c2011-12-10 21:55:01 +0000460 snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
Paul Bakker9d781402011-05-09 16:17:09 +0000461 if( use_ret == -(POLARSSL_ERR_MPI_NEGATIVE_VALUE) )
462 snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
463 if( use_ret == -(POLARSSL_ERR_MPI_DIVISION_BY_ZERO) )
464 snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
465 if( use_ret == -(POLARSSL_ERR_MPI_NOT_ACCEPTABLE) )
466 snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000467 if( use_ret == -(POLARSSL_ERR_MPI_MALLOC_FAILED) )
468 snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000469#endif /* POLARSSL_BIGNUM_C */
470
Paul Bakker83f00bb2012-07-04 11:08:50 +0000471#if defined(POLARSSL_BLOWFISH_C)
472 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
473 snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
474 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
475 snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
476#endif /* POLARSSL_BLOWFISH_C */
477
Paul Bakker9d781402011-05-09 16:17:09 +0000478#if defined(POLARSSL_CAMELLIA_C)
479 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
480 snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
481 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
482 snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
483#endif /* POLARSSL_CAMELLIA_C */
484
Paul Bakker880ac7e2011-11-27 14:50:49 +0000485#if defined(POLARSSL_CTR_DRBG_C)
486 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
487 snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
488 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
489 snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
490 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG) )
491 snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000492 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR) )
493 snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
Paul Bakker880ac7e2011-11-27 14:50:49 +0000494#endif /* POLARSSL_CTR_DRBG_C */
495
Paul Bakker9d781402011-05-09 16:17:09 +0000496#if defined(POLARSSL_DES_C)
497 if( use_ret == -(POLARSSL_ERR_DES_INVALID_INPUT_LENGTH) )
498 snprintf( buf, buflen, "DES - The data input has an invalid length" );
499#endif /* POLARSSL_DES_C */
500
Paul Bakker6083fd22011-12-03 21:45:14 +0000501#if defined(POLARSSL_ENTROPY_C)
502 if( use_ret == -(POLARSSL_ERR_ENTROPY_SOURCE_FAILED) )
503 snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
504 if( use_ret == -(POLARSSL_ERR_ENTROPY_MAX_SOURCES) )
505 snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
Paul Bakker43655f42011-12-15 20:11:16 +0000506 if( use_ret == -(POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED) )
507 snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
Paul Bakker1e942372014-03-26 11:54:05 +0100508 if( use_ret == -(POLARSSL_ERR_ENTROPY_FILE_IO_ERROR) )
509 snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
Paul Bakker6083fd22011-12-03 21:45:14 +0000510#endif /* POLARSSL_ENTROPY_C */
511
Paul Bakker030277a2012-04-17 12:24:26 +0000512#if defined(POLARSSL_GCM_C)
513 if( use_ret == -(POLARSSL_ERR_GCM_AUTH_FAILED) )
514 snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
Paul Bakkerd8ef1672012-04-18 14:17:32 +0000515 if( use_ret == -(POLARSSL_ERR_GCM_BAD_INPUT) )
516 snprintf( buf, buflen, "GCM - Bad input parameters to function" );
Paul Bakker030277a2012-04-17 12:24:26 +0000517#endif /* POLARSSL_GCM_C */
518
Paul Bakker69e095c2011-12-10 21:55:01 +0000519#if defined(POLARSSL_MD2_C)
520 if( use_ret == -(POLARSSL_ERR_MD2_FILE_IO_ERROR) )
521 snprintf( buf, buflen, "MD2 - Read/write error in file" );
522#endif /* POLARSSL_MD2_C */
523
524#if defined(POLARSSL_MD4_C)
525 if( use_ret == -(POLARSSL_ERR_MD4_FILE_IO_ERROR) )
526 snprintf( buf, buflen, "MD4 - Read/write error in file" );
527#endif /* POLARSSL_MD4_C */
528
529#if defined(POLARSSL_MD5_C)
530 if( use_ret == -(POLARSSL_ERR_MD5_FILE_IO_ERROR) )
531 snprintf( buf, buflen, "MD5 - Read/write error in file" );
532#endif /* POLARSSL_MD5_C */
533
Paul Bakker9d781402011-05-09 16:17:09 +0000534#if defined(POLARSSL_NET_C)
535 if( use_ret == -(POLARSSL_ERR_NET_UNKNOWN_HOST) )
536 snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
537 if( use_ret == -(POLARSSL_ERR_NET_SOCKET_FAILED) )
538 snprintf( buf, buflen, "NET - Failed to open a socket" );
539 if( use_ret == -(POLARSSL_ERR_NET_CONNECT_FAILED) )
540 snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
541 if( use_ret == -(POLARSSL_ERR_NET_BIND_FAILED) )
542 snprintf( buf, buflen, "NET - Binding of the socket failed" );
543 if( use_ret == -(POLARSSL_ERR_NET_LISTEN_FAILED) )
544 snprintf( buf, buflen, "NET - Could not listen on the socket" );
545 if( use_ret == -(POLARSSL_ERR_NET_ACCEPT_FAILED) )
546 snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
547 if( use_ret == -(POLARSSL_ERR_NET_RECV_FAILED) )
548 snprintf( buf, buflen, "NET - Reading information from the socket failed" );
549 if( use_ret == -(POLARSSL_ERR_NET_SEND_FAILED) )
550 snprintf( buf, buflen, "NET - Sending information through the socket failed" );
551 if( use_ret == -(POLARSSL_ERR_NET_CONN_RESET) )
552 snprintf( buf, buflen, "NET - Connection was reset by peer" );
Paul Bakker831a7552011-05-18 13:32:51 +0000553 if( use_ret == -(POLARSSL_ERR_NET_WANT_READ) )
554 snprintf( buf, buflen, "NET - Connection requires a read call" );
555 if( use_ret == -(POLARSSL_ERR_NET_WANT_WRITE) )
556 snprintf( buf, buflen, "NET - Connection requires a write call" );
Paul Bakker9d781402011-05-09 16:17:09 +0000557#endif /* POLARSSL_NET_C */
558
559#if defined(POLARSSL_PADLOCK_C)
560 if( use_ret == -(POLARSSL_ERR_PADLOCK_DATA_MISALIGNED) )
561 snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
562#endif /* POLARSSL_PADLOCK_C */
563
Paul Bakkerd14277d2012-09-26 15:19:05 +0000564#if defined(POLARSSL_PBKDF2_C)
565 if( use_ret == -(POLARSSL_ERR_PBKDF2_BAD_INPUT_DATA) )
566 snprintf( buf, buflen, "PBKDF2 - Bad input parameters to function" );
567#endif /* POLARSSL_PBKDF2_C */
568
Paul Bakker69e095c2011-12-10 21:55:01 +0000569#if defined(POLARSSL_SHA1_C)
570 if( use_ret == -(POLARSSL_ERR_SHA1_FILE_IO_ERROR) )
571 snprintf( buf, buflen, "SHA1 - Read/write error in file" );
572#endif /* POLARSSL_SHA1_C */
573
574#if defined(POLARSSL_SHA2_C)
575 if( use_ret == -(POLARSSL_ERR_SHA2_FILE_IO_ERROR) )
576 snprintf( buf, buflen, "SHA2 - Read/write error in file" );
577#endif /* POLARSSL_SHA2_C */
578
579#if defined(POLARSSL_SHA4_C)
580 if( use_ret == -(POLARSSL_ERR_SHA4_FILE_IO_ERROR) )
581 snprintf( buf, buflen, "SHA4 - Read/write error in file" );
582#endif /* POLARSSL_SHA4_C */
583
Paul Bakker9d781402011-05-09 16:17:09 +0000584#if defined(POLARSSL_XTEA_C)
585 if( use_ret == -(POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH) )
586 snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
587#endif /* POLARSSL_XTEA_C */
588
589 if( strlen( buf ) != 0 )
590 return;
591
592 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
593}
594
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100595#else /* POLARSSL_ERROR_C */
596
597#if defined(POLARSSL_ERROR_STRERROR_DUMMY)
598
599#include <string.h>
600
601/*
602 * Provide an non-function in case POLARSSL_ERROR_C is not defined
603 */
604void error_strerror( int ret, char *buf, size_t buflen )
605{
606 ((void) ret);
607
608 if( buflen > 0 )
609 buf[0] = '\0';
610}
611
612#endif /* POLARSSL_ERROR_STRERROR_DUMMY */
Paul Bakker9a736322012-11-14 12:39:52 +0000613#endif /* POLARSSL_ERROR_C */