PolarSSL v1.2.12
error.c
Go to the documentation of this file.
1 /*
2  * Error message information
3  *
4  * Copyright (C) 2006-2012, Brainspark B.V.
5  *
6  * This file is part of PolarSSL (http://www.polarssl.org)
7  * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
8  *
9  * All rights reserved.
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25 
26 #include "polarssl/config.h"
27 
28 #if defined(POLARSSL_ERROR_C)
29 
30 #include "polarssl/error.h"
31 
32 #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 
44 #if defined(POLARSSL_BLOWFISH_C)
45 #include "polarssl/blowfish.h"
46 #endif
47 
48 #if defined(POLARSSL_CAMELLIA_C)
49 #include "polarssl/camellia.h"
50 #endif
51 
52 #if defined(POLARSSL_CIPHER_C)
53 #include "polarssl/cipher.h"
54 #endif
55 
56 #if defined(POLARSSL_CTR_DRBG_C)
57 #include "polarssl/ctr_drbg.h"
58 #endif
59 
60 #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 
68 #if defined(POLARSSL_ENTROPY_C)
69 #include "polarssl/entropy.h"
70 #endif
71 
72 #if defined(POLARSSL_GCM_C)
73 #include "polarssl/gcm.h"
74 #endif
75 
76 #if defined(POLARSSL_MD_C)
77 #include "polarssl/md.h"
78 #endif
79 
80 #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 
92 #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 
100 #if defined(POLARSSL_PBKDF2_C)
101 #include "polarssl/pbkdf2.h"
102 #endif
103 
104 #if defined(POLARSSL_PEM_C)
105 #include "polarssl/pem.h"
106 #endif
107 
108 #if defined(POLARSSL_PKCS12_C)
109 #include "polarssl/pkcs12.h"
110 #endif
111 
112 #if defined(POLARSSL_PKCS5_C)
113 #include "polarssl/pkcs5.h"
114 #endif
115 
116 #if defined(POLARSSL_RSA_C)
117 #include "polarssl/rsa.h"
118 #endif
119 
120 #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 
132 #if defined(POLARSSL_SSL_TLS_C)
133 #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 
147 #if defined _MSC_VER && !defined snprintf
148 #define snprintf _snprintf
149 #endif
150 
151 void 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  //
167 #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 
180 #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) )
190  snprintf( buf, buflen, "DHM - Making of the public value failed" );
191  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" );
198  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" );
202  if( use_ret == -(POLARSSL_ERR_MD_FILE_IO_ERROR) )
203  snprintf( buf, buflen, "MD - Opening or reading of file failed" );
204 #endif /* POLARSSL_MD_C */
205 
206 #if defined(POLARSSL_PEM_C)
208  snprintf( buf, buflen, "PEM - No PEM header or footer found" );
209  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" );
223  if( use_ret == -(POLARSSL_ERR_PEM_BAD_INPUT_DATA) )
224  snprintf( buf, buflen, "PEM - Bad input parameters to function" );
225 #endif /* POLARSSL_PEM_C */
226 
227 #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" );
234  if( use_ret == -(POLARSSL_ERR_PKCS12_PASSWORD_MISMATCH) )
235  snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
236 #endif /* POLARSSL_PKCS12_C */
237 
238 #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 
249 #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 
270 #if defined(POLARSSL_SSL_TLS_C)
271  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" );
279  if( use_ret == -(POLARSSL_ERR_SSL_CONN_EOF) )
280  snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
281  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" );
285  if( use_ret == -(POLARSSL_ERR_SSL_NO_RNG) )
286  snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
287  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) )
300  {
301  snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
302  return;
303  }
304  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" );
315  snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
317  snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
319  snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
321  snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
323  snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM Read Public" );
325  snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM Calculate Secret" );
327  snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
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" );
332  if( use_ret == -(POLARSSL_ERR_SSL_MALLOC_FAILED) )
333  snprintf( buf, buflen, "SSL - Memory allocation failed" );
334  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" );
338  if( use_ret == -(POLARSSL_ERR_SSL_COMPRESSION_FAILED) )
339  snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
340  if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
341  snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
342  if( use_ret == -(POLARSSL_ERR_SSL_COUNTER_WRAPPING) )
343  snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
344 #endif /* POLARSSL_SSL_TLS_C */
345 
346 #if defined(POLARSSL_X509_PARSE_C)
347  if( use_ret == -(POLARSSL_ERR_X509_FEATURE_UNAVAILABLE) )
348  snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
349  if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_PEM) )
350  snprintf( buf, buflen, "X509 - The PEM-encoded certificate contains invalid elements, e.g. invalid character" );
351  if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_FORMAT) )
352  snprintf( buf, buflen, "X509 - The certificate format is invalid, e.g. different type expected" );
353  if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_VERSION) )
354  snprintf( buf, buflen, "X509 - The certificate version element is invalid" );
355  if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_SERIAL) )
356  snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
357  if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_ALG) )
358  snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
359  if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_NAME) )
360  snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
361  if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_DATE) )
362  snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
363  if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_PUBKEY) )
364  snprintf( buf, buflen, "X509 - The pubkey tag or value is invalid (only RSA is supported)" );
365  if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE) )
366  snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
368  snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
369  if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION) )
370  snprintf( buf, buflen, "X509 - Certificate or CRL has an unsupported version number" );
371  if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG) )
372  snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
373  if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_PK_ALG) )
374  snprintf( buf, buflen, "X509 - Key algorithm is unsupported (only RSA is supported)" );
375  if( use_ret == -(POLARSSL_ERR_X509_CERT_SIG_MISMATCH) )
376  snprintf( buf, buflen, "X509 - Certificate signature algorithms do not match. (see \\c ::x509_cert sig_oid)" );
377  if( use_ret == -(POLARSSL_ERR_X509_CERT_VERIFY_FAILED) )
378  snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
379  if( use_ret == -(POLARSSL_ERR_X509_KEY_INVALID_VERSION) )
380  snprintf( buf, buflen, "X509 - Unsupported RSA key version" );
381  if( use_ret == -(POLARSSL_ERR_X509_KEY_INVALID_FORMAT) )
382  snprintf( buf, buflen, "X509 - Invalid RSA key tag or value" );
383  if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT) )
384  snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
385  if( use_ret == -(POLARSSL_ERR_X509_INVALID_INPUT) )
386  snprintf( buf, buflen, "X509 - Input invalid" );
387  if( use_ret == -(POLARSSL_ERR_X509_MALLOC_FAILED) )
388  snprintf( buf, buflen, "X509 - Allocation of memory failed" );
389  if( use_ret == -(POLARSSL_ERR_X509_FILE_IO_ERROR) )
390  snprintf( buf, buflen, "X509 - Read/write of file failed" );
391  if( use_ret == -(POLARSSL_ERR_X509_PASSWORD_REQUIRED) )
392  snprintf( buf, buflen, "X509 - Private key password can't be empty" );
393  if( use_ret == -(POLARSSL_ERR_X509_PASSWORD_MISMATCH) )
394  snprintf( buf, buflen, "X509 - Given private key password does not allow for correct decryption" );
395 #endif /* POLARSSL_X509_PARSE_C */
396 
397  if( strlen( buf ) == 0 )
398  snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
399  }
400 
401  use_ret = ret & ~0xFF80;
402 
403  if( use_ret == 0 )
404  return;
405 
406  // If high level code is present, make a concatenation between both
407  // error strings.
408  //
409  len = strlen( buf );
410 
411  if( len > 0 )
412  {
413  if( buflen - len < 5 )
414  return;
415 
416  snprintf( buf + len, buflen - len, " : " );
417 
418  buf += len + 3;
419  buflen -= len + 3;
420  }
421 
422  // Low level error codes
423  //
424 #if defined(POLARSSL_AES_C)
425  if( use_ret == -(POLARSSL_ERR_AES_INVALID_KEY_LENGTH) )
426  snprintf( buf, buflen, "AES - Invalid key length" );
427  if( use_ret == -(POLARSSL_ERR_AES_INVALID_INPUT_LENGTH) )
428  snprintf( buf, buflen, "AES - Invalid data input length" );
429 #endif /* POLARSSL_AES_C */
430 
431 #if defined(POLARSSL_ASN1_PARSE_C)
432  if( use_ret == -(POLARSSL_ERR_ASN1_OUT_OF_DATA) )
433  snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
434  if( use_ret == -(POLARSSL_ERR_ASN1_UNEXPECTED_TAG) )
435  snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
436  if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_LENGTH) )
437  snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
438  if( use_ret == -(POLARSSL_ERR_ASN1_LENGTH_MISMATCH) )
439  snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
440  if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_DATA) )
441  snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
442  if( use_ret == -(POLARSSL_ERR_ASN1_MALLOC_FAILED) )
443  snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
444  if( use_ret == -(POLARSSL_ERR_ASN1_BUF_TOO_SMALL) )
445  snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
446 #endif /* POLARSSL_ASN1_PARSE_C */
447 
448 #if defined(POLARSSL_BASE64_C)
449  if( use_ret == -(POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) )
450  snprintf( buf, buflen, "BASE64 - Output buffer too small" );
451  if( use_ret == -(POLARSSL_ERR_BASE64_INVALID_CHARACTER) )
452  snprintf( buf, buflen, "BASE64 - Invalid character in input" );
453 #endif /* POLARSSL_BASE64_C */
454 
455 #if defined(POLARSSL_BIGNUM_C)
456  if( use_ret == -(POLARSSL_ERR_MPI_FILE_IO_ERROR) )
457  snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
458  if( use_ret == -(POLARSSL_ERR_MPI_BAD_INPUT_DATA) )
459  snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
460  if( use_ret == -(POLARSSL_ERR_MPI_INVALID_CHARACTER) )
461  snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
462  if( use_ret == -(POLARSSL_ERR_MPI_BUFFER_TOO_SMALL) )
463  snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
464  if( use_ret == -(POLARSSL_ERR_MPI_NEGATIVE_VALUE) )
465  snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
466  if( use_ret == -(POLARSSL_ERR_MPI_DIVISION_BY_ZERO) )
467  snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
468  if( use_ret == -(POLARSSL_ERR_MPI_NOT_ACCEPTABLE) )
469  snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
470  if( use_ret == -(POLARSSL_ERR_MPI_MALLOC_FAILED) )
471  snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
472 #endif /* POLARSSL_BIGNUM_C */
473 
474 #if defined(POLARSSL_BLOWFISH_C)
475  if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
476  snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
478  snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
479 #endif /* POLARSSL_BLOWFISH_C */
480 
481 #if defined(POLARSSL_CAMELLIA_C)
482  if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
483  snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
485  snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
486 #endif /* POLARSSL_CAMELLIA_C */
487 
488 #if defined(POLARSSL_CTR_DRBG_C)
490  snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
491  if( use_ret == -(POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
492  snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
493  if( use_ret == -(POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG) )
494  snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
495  if( use_ret == -(POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR) )
496  snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
497 #endif /* POLARSSL_CTR_DRBG_C */
498 
499 #if defined(POLARSSL_DES_C)
500  if( use_ret == -(POLARSSL_ERR_DES_INVALID_INPUT_LENGTH) )
501  snprintf( buf, buflen, "DES - The data input has an invalid length" );
502 #endif /* POLARSSL_DES_C */
503 
504 #if defined(POLARSSL_ENTROPY_C)
505  if( use_ret == -(POLARSSL_ERR_ENTROPY_SOURCE_FAILED) )
506  snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
507  if( use_ret == -(POLARSSL_ERR_ENTROPY_MAX_SOURCES) )
508  snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
509  if( use_ret == -(POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED) )
510  snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
511  if( use_ret == -(POLARSSL_ERR_ENTROPY_FILE_IO_ERROR) )
512  snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
513 #endif /* POLARSSL_ENTROPY_C */
514 
515 #if defined(POLARSSL_GCM_C)
516  if( use_ret == -(POLARSSL_ERR_GCM_AUTH_FAILED) )
517  snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
518  if( use_ret == -(POLARSSL_ERR_GCM_BAD_INPUT) )
519  snprintf( buf, buflen, "GCM - Bad input parameters to function" );
520 #endif /* POLARSSL_GCM_C */
521 
522 #if defined(POLARSSL_MD2_C)
523  if( use_ret == -(POLARSSL_ERR_MD2_FILE_IO_ERROR) )
524  snprintf( buf, buflen, "MD2 - Read/write error in file" );
525 #endif /* POLARSSL_MD2_C */
526 
527 #if defined(POLARSSL_MD4_C)
528  if( use_ret == -(POLARSSL_ERR_MD4_FILE_IO_ERROR) )
529  snprintf( buf, buflen, "MD4 - Read/write error in file" );
530 #endif /* POLARSSL_MD4_C */
531 
532 #if defined(POLARSSL_MD5_C)
533  if( use_ret == -(POLARSSL_ERR_MD5_FILE_IO_ERROR) )
534  snprintf( buf, buflen, "MD5 - Read/write error in file" );
535 #endif /* POLARSSL_MD5_C */
536 
537 #if defined(POLARSSL_NET_C)
538  if( use_ret == -(POLARSSL_ERR_NET_UNKNOWN_HOST) )
539  snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
540  if( use_ret == -(POLARSSL_ERR_NET_SOCKET_FAILED) )
541  snprintf( buf, buflen, "NET - Failed to open a socket" );
542  if( use_ret == -(POLARSSL_ERR_NET_CONNECT_FAILED) )
543  snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
544  if( use_ret == -(POLARSSL_ERR_NET_BIND_FAILED) )
545  snprintf( buf, buflen, "NET - Binding of the socket failed" );
546  if( use_ret == -(POLARSSL_ERR_NET_LISTEN_FAILED) )
547  snprintf( buf, buflen, "NET - Could not listen on the socket" );
548  if( use_ret == -(POLARSSL_ERR_NET_ACCEPT_FAILED) )
549  snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
550  if( use_ret == -(POLARSSL_ERR_NET_RECV_FAILED) )
551  snprintf( buf, buflen, "NET - Reading information from the socket failed" );
552  if( use_ret == -(POLARSSL_ERR_NET_SEND_FAILED) )
553  snprintf( buf, buflen, "NET - Sending information through the socket failed" );
554  if( use_ret == -(POLARSSL_ERR_NET_CONN_RESET) )
555  snprintf( buf, buflen, "NET - Connection was reset by peer" );
556  if( use_ret == -(POLARSSL_ERR_NET_WANT_READ) )
557  snprintf( buf, buflen, "NET - Connection requires a read call" );
558  if( use_ret == -(POLARSSL_ERR_NET_WANT_WRITE) )
559  snprintf( buf, buflen, "NET - Connection requires a write call" );
560 #endif /* POLARSSL_NET_C */
561 
562 #if defined(POLARSSL_PADLOCK_C)
563  if( use_ret == -(POLARSSL_ERR_PADLOCK_DATA_MISALIGNED) )
564  snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
565 #endif /* POLARSSL_PADLOCK_C */
566 
567 #if defined(POLARSSL_PBKDF2_C)
568  if( use_ret == -(POLARSSL_ERR_PBKDF2_BAD_INPUT_DATA) )
569  snprintf( buf, buflen, "PBKDF2 - Bad input parameters to function" );
570 #endif /* POLARSSL_PBKDF2_C */
571 
572 #if defined(POLARSSL_SHA1_C)
573  if( use_ret == -(POLARSSL_ERR_SHA1_FILE_IO_ERROR) )
574  snprintf( buf, buflen, "SHA1 - Read/write error in file" );
575 #endif /* POLARSSL_SHA1_C */
576 
577 #if defined(POLARSSL_SHA2_C)
578  if( use_ret == -(POLARSSL_ERR_SHA2_FILE_IO_ERROR) )
579  snprintf( buf, buflen, "SHA2 - Read/write error in file" );
580 #endif /* POLARSSL_SHA2_C */
581 
582 #if defined(POLARSSL_SHA4_C)
583  if( use_ret == -(POLARSSL_ERR_SHA4_FILE_IO_ERROR) )
584  snprintf( buf, buflen, "SHA4 - Read/write error in file" );
585 #endif /* POLARSSL_SHA4_C */
586 
587 #if defined(POLARSSL_XTEA_C)
588  if( use_ret == -(POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH) )
589  snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
590 #endif /* POLARSSL_XTEA_C */
591 
592  if( strlen( buf ) != 0 )
593  return;
594 
595  snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
596 }
597 
598 #else /* POLARSSL_ERROR_C */
599 
600 #if defined(POLARSSL_ERROR_STRERROR_DUMMY)
601 
602 #include <string.h>
603 
604 /*
605  * Provide an non-function in case POLARSSL_ERROR_C is not defined
606  */
607 void error_strerror( int ret, char *buf, size_t buflen )
608 {
609  ((void) ret);
610 
611  if( buflen > 0 )
612  buf[0] = '\0';
613 }
614 
615 #endif /* POLARSSL_ERROR_STRERROR_DUMMY */
616 #endif /* POLARSSL_ERROR_C */