blob: 9980a9100f3c6e5fbda3dd51ecdca062ac69abf2 [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
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010080#if defined(POLARSSL_HMAC_DRBG_C)
81#include "polarssl/hmac_drbg.h"
82#endif
83
Paul Bakker9d781402011-05-09 16:17:09 +000084#if defined(POLARSSL_MD_C)
85#include "polarssl/md.h"
86#endif
87
Paul Bakker69e095c2011-12-10 21:55:01 +000088#if defined(POLARSSL_MD2_C)
89#include "polarssl/md2.h"
90#endif
91
92#if defined(POLARSSL_MD4_C)
93#include "polarssl/md4.h"
94#endif
95
96#if defined(POLARSSL_MD5_C)
97#include "polarssl/md5.h"
98#endif
99
Paul Bakker9d781402011-05-09 16:17:09 +0000100#if defined(POLARSSL_NET_C)
101#include "polarssl/net.h"
102#endif
103
Paul Bakkerc70b9822013-04-07 22:00:46 +0200104#if defined(POLARSSL_OID_C)
105#include "polarssl/oid.h"
106#endif
107
Paul Bakker9d781402011-05-09 16:17:09 +0000108#if defined(POLARSSL_PADLOCK_C)
109#include "polarssl/padlock.h"
110#endif
111
Paul Bakkerd14277d2012-09-26 15:19:05 +0000112#if defined(POLARSSL_PBKDF2_C)
113#include "polarssl/pbkdf2.h"
114#endif
115
Paul Bakkercff68422013-09-15 20:43:33 +0200116#if defined(POLARSSL_PEM_PARSE_C) || defined(POLARSSL_PEM_WRITE_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000117#include "polarssl/pem.h"
118#endif
119
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200120#if defined(POLARSSL_PK_C)
121#include "polarssl/pk.h"
122#endif
123
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200124#if defined(POLARSSL_PKCS12_C)
125#include "polarssl/pkcs12.h"
126#endif
127
Paul Bakkerb0c19a42013-06-24 19:26:38 +0200128#if defined(POLARSSL_PKCS5_C)
129#include "polarssl/pkcs5.h"
130#endif
131
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100132#if defined(POLARSSL_RIPEMD160_C)
133#include "polarssl/ripemd160.h"
134#endif
135
Paul Bakker9d781402011-05-09 16:17:09 +0000136#if defined(POLARSSL_RSA_C)
137#include "polarssl/rsa.h"
138#endif
139
Paul Bakker69e095c2011-12-10 21:55:01 +0000140#if defined(POLARSSL_SHA1_C)
141#include "polarssl/sha1.h"
142#endif
143
Paul Bakker9e36f042013-06-30 14:34:05 +0200144#if defined(POLARSSL_SHA256_C)
Paul Bakkerd2681d82013-06-30 14:49:12 +0200145#include "polarssl/sha256.h"
Paul Bakker69e095c2011-12-10 21:55:01 +0000146#endif
147
Paul Bakker9e36f042013-06-30 14:34:05 +0200148#if defined(POLARSSL_SHA512_C)
Paul Bakkerd2681d82013-06-30 14:49:12 +0200149#include "polarssl/sha512.h"
Paul Bakker69e095c2011-12-10 21:55:01 +0000150#endif
151
Paul Bakker831a7552011-05-18 13:32:51 +0000152#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000153#include "polarssl/ssl.h"
154#endif
155
Paul Bakker2466d932013-09-28 14:40:38 +0200156#if defined(POLARSSL_THREADING_C)
157#include "polarssl/threading.h"
158#endif
159
Paul Bakker36713e82013-09-17 13:25:29 +0200160#if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000161#include "polarssl/x509.h"
162#endif
163
164#if defined(POLARSSL_XTEA_C)
165#include "polarssl/xtea.h"
166#endif
167
168
169#include <string.h>
170
Paul Bakker6edcd412013-10-29 15:22:54 +0100171#if defined(_MSC_VER) && !defined snprintf && !defined(EFIX64) && \
172 !defined(EFI32)
Paul Bakkerdceecd82011-11-15 16:38:34 +0000173#define snprintf _snprintf
174#endif
175
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200176void polarssl_strerror( int ret, char *buf, size_t buflen )
Paul Bakker9d781402011-05-09 16:17:09 +0000177{
178 size_t len;
179 int use_ret;
180
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200181 if( buflen == 0 )
182 return;
183
Paul Bakker9d781402011-05-09 16:17:09 +0000184 memset( buf, 0x00, buflen );
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200185 /* Reduce buflen to make sure MSVC _snprintf() ends with \0 as well */
186 buflen -= 1;
187
Paul Bakker9d781402011-05-09 16:17:09 +0000188 if( ret < 0 )
189 ret = -ret;
190
191 if( ret & 0xFF80 )
192 {
193 use_ret = ret & 0xFF80;
194
195 // High level error codes
196 //
Paul Bakkerff61a782011-06-09 15:42:02 +0000197#if defined(POLARSSL_CIPHER_C)
198 if( use_ret == -(POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE) )
199 snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
200 if( use_ret == -(POLARSSL_ERR_CIPHER_BAD_INPUT_DATA) )
201 snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
202 if( use_ret == -(POLARSSL_ERR_CIPHER_ALLOC_FAILED) )
203 snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
204 if( use_ret == -(POLARSSL_ERR_CIPHER_INVALID_PADDING) )
205 snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
206 if( use_ret == -(POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
207 snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
Manuel Pégourié-Gonnard4fee79b2013-09-19 18:09:14 +0200208 if( use_ret == -(POLARSSL_ERR_CIPHER_AUTH_FAILED) )
209 snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
Paul Bakkerff61a782011-06-09 15:42:02 +0000210#endif /* POLARSSL_CIPHER_C */
211
Paul Bakker9d781402011-05-09 16:17:09 +0000212#if defined(POLARSSL_DHM_C)
213 if( use_ret == -(POLARSSL_ERR_DHM_BAD_INPUT_DATA) )
214 snprintf( buf, buflen, "DHM - Bad input parameters to function" );
215 if( use_ret == -(POLARSSL_ERR_DHM_READ_PARAMS_FAILED) )
216 snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
217 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PARAMS_FAILED) )
218 snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
219 if( use_ret == -(POLARSSL_ERR_DHM_READ_PUBLIC_FAILED) )
220 snprintf( buf, buflen, "DHM - Reading of the public values failed" );
221 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PUBLIC_FAILED) )
Paul Bakker05ef8352012-05-08 09:17:57 +0000222 snprintf( buf, buflen, "DHM - Making of the public value failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000223 if( use_ret == -(POLARSSL_ERR_DHM_CALC_SECRET_FAILED) )
224 snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
Paul Bakker40ce79f2013-09-15 17:43:54 +0200225 if( use_ret == -(POLARSSL_ERR_DHM_INVALID_FORMAT) )
226 snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
227 if( use_ret == -(POLARSSL_ERR_DHM_MALLOC_FAILED) )
228 snprintf( buf, buflen, "DHM - Allocation of memory failed" );
229 if( use_ret == -(POLARSSL_ERR_DHM_FILE_IO_ERROR) )
230 snprintf( buf, buflen, "DHM - Read/write of file failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000231#endif /* POLARSSL_DHM_C */
232
Paul Bakkercf4365f2013-01-16 17:00:43 +0100233#if defined(POLARSSL_ECP_C)
234 if( use_ret == -(POLARSSL_ERR_ECP_BAD_INPUT_DATA) )
235 snprintf( buf, buflen, "ECP - Bad input parameters to function" );
Paul Bakker41c83d32013-03-20 14:39:14 +0100236 if( use_ret == -(POLARSSL_ERR_ECP_BUFFER_TOO_SMALL) )
237 snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
Paul Bakkerfd3eac52013-06-29 23:31:33 +0200238 if( use_ret == -(POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE) )
239 snprintf( buf, buflen, "ECP - Requested curve not available" );
Paul Bakker1a7550a2013-09-15 13:01:22 +0200240 if( use_ret == -(POLARSSL_ERR_ECP_VERIFY_FAILED) )
241 snprintf( buf, buflen, "ECP - The signature is not valid" );
Manuel Pégourié-Gonnard456d3b92013-09-16 18:04:38 +0200242 if( use_ret == -(POLARSSL_ERR_ECP_MALLOC_FAILED) )
243 snprintf( buf, buflen, "ECP - Memory allocation failed" );
244 if( use_ret == -(POLARSSL_ERR_ECP_RANDOM_FAILED) )
245 snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
246 if( use_ret == -(POLARSSL_ERR_ECP_INVALID_KEY) )
247 snprintf( buf, buflen, "ECP - Invalid private or public key" );
Paul Bakkercf4365f2013-01-16 17:00:43 +0100248#endif /* POLARSSL_ECP_C */
249
Paul Bakker9d781402011-05-09 16:17:09 +0000250#if defined(POLARSSL_MD_C)
251 if( use_ret == -(POLARSSL_ERR_MD_FEATURE_UNAVAILABLE) )
252 snprintf( buf, buflen, "MD - The selected feature is not available" );
Paul Bakker9c021ad2011-06-09 15:55:11 +0000253 if( use_ret == -(POLARSSL_ERR_MD_BAD_INPUT_DATA) )
254 snprintf( buf, buflen, "MD - Bad input parameters to function" );
255 if( use_ret == -(POLARSSL_ERR_MD_ALLOC_FAILED) )
256 snprintf( buf, buflen, "MD - Failed to allocate memory" );
Paul Bakker8913f822012-01-14 18:07:41 +0000257 if( use_ret == -(POLARSSL_ERR_MD_FILE_IO_ERROR) )
258 snprintf( buf, buflen, "MD - Opening or reading of file failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000259#endif /* POLARSSL_MD_C */
260
Paul Bakkercff68422013-09-15 20:43:33 +0200261#if defined(POLARSSL_PEM_PARSE_C) || defined(POLARSSL_PEM_WRITE_C)
Paul Bakker00b28602013-06-24 13:02:41 +0200262 if( use_ret == -(POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
263 snprintf( buf, buflen, "PEM - No PEM header or footer found" );
Paul Bakker9d781402011-05-09 16:17:09 +0000264 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_DATA) )
265 snprintf( buf, buflen, "PEM - PEM string is not as expected" );
266 if( use_ret == -(POLARSSL_ERR_PEM_MALLOC_FAILED) )
267 snprintf( buf, buflen, "PEM - Failed to allocate memory" );
268 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_ENC_IV) )
269 snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
270 if( use_ret == -(POLARSSL_ERR_PEM_UNKNOWN_ENC_ALG) )
271 snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
272 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_REQUIRED) )
273 snprintf( buf, buflen, "PEM - Private key password can't be empty" );
274 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_MISMATCH) )
275 snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
276 if( use_ret == -(POLARSSL_ERR_PEM_FEATURE_UNAVAILABLE) )
277 snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
Paul Bakker00b28602013-06-24 13:02:41 +0200278 if( use_ret == -(POLARSSL_ERR_PEM_BAD_INPUT_DATA) )
279 snprintf( buf, buflen, "PEM - Bad input parameters to function" );
Paul Bakkercff68422013-09-15 20:43:33 +0200280#endif /* POLARSSL_PEM_PARSE_C || POLARSSL_PEM_WRITE_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000281
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200282#if defined(POLARSSL_PK_C)
283 if( use_ret == -(POLARSSL_ERR_PK_MALLOC_FAILED) )
284 snprintf( buf, buflen, "PK - Memory alloation failed" );
Manuel Pégourié-Gonnard374e4b82013-07-09 10:21:34 +0200285 if( use_ret == -(POLARSSL_ERR_PK_TYPE_MISMATCH) )
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200286 snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
Manuel Pégourié-Gonnard15699382013-08-14 19:22:48 +0200287 if( use_ret == -(POLARSSL_ERR_PK_BAD_INPUT_DATA) )
288 snprintf( buf, buflen, "PK - Bad input parameters to function" );
Paul Bakker1a7550a2013-09-15 13:01:22 +0200289 if( use_ret == -(POLARSSL_ERR_PK_FILE_IO_ERROR) )
290 snprintf( buf, buflen, "PK - Read/write of file failed" );
291 if( use_ret == -(POLARSSL_ERR_PK_KEY_INVALID_VERSION) )
292 snprintf( buf, buflen, "PK - Unsupported key version" );
293 if( use_ret == -(POLARSSL_ERR_PK_KEY_INVALID_FORMAT) )
294 snprintf( buf, buflen, "PK - Invalid key tag or value" );
295 if( use_ret == -(POLARSSL_ERR_PK_UNKNOWN_PK_ALG) )
296 snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
297 if( use_ret == -(POLARSSL_ERR_PK_PASSWORD_REQUIRED) )
298 snprintf( buf, buflen, "PK - Private key password can't be empty" );
299 if( use_ret == -(POLARSSL_ERR_PK_PASSWORD_MISMATCH) )
300 snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
301 if( use_ret == -(POLARSSL_ERR_PK_INVALID_PUBKEY) )
302 snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
303 if( use_ret == -(POLARSSL_ERR_PK_INVALID_ALG) )
304 snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
305 if( use_ret == -(POLARSSL_ERR_PK_UNKNOWN_NAMED_CURVE) )
306 snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
307 if( use_ret == -(POLARSSL_ERR_PK_FEATURE_UNAVAILABLE) )
308 snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200309#endif /* POLARSSL_PK_C */
310
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200311#if defined(POLARSSL_PKCS12_C)
312 if( use_ret == -(POLARSSL_ERR_PKCS12_BAD_INPUT_DATA) )
313 snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
314 if( use_ret == -(POLARSSL_ERR_PKCS12_FEATURE_UNAVAILABLE) )
315 snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
316 if( use_ret == -(POLARSSL_ERR_PKCS12_PBE_INVALID_FORMAT) )
317 snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
Paul Bakker38b50d72013-06-24 19:33:27 +0200318 if( use_ret == -(POLARSSL_ERR_PKCS12_PASSWORD_MISMATCH) )
319 snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200320#endif /* POLARSSL_PKCS12_C */
321
Paul Bakker28144de2013-06-24 19:28:55 +0200322#if defined(POLARSSL_PKCS5_C)
323 if( use_ret == -(POLARSSL_ERR_PKCS5_BAD_INPUT_DATA) )
324 snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
325 if( use_ret == -(POLARSSL_ERR_PKCS5_INVALID_FORMAT) )
326 snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
327 if( use_ret == -(POLARSSL_ERR_PKCS5_FEATURE_UNAVAILABLE) )
328 snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
329 if( use_ret == -(POLARSSL_ERR_PKCS5_PASSWORD_MISMATCH) )
330 snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
331#endif /* POLARSSL_PKCS5_C */
332
Paul Bakker9d781402011-05-09 16:17:09 +0000333#if defined(POLARSSL_RSA_C)
334 if( use_ret == -(POLARSSL_ERR_RSA_BAD_INPUT_DATA) )
335 snprintf( buf, buflen, "RSA - Bad input parameters to function" );
336 if( use_ret == -(POLARSSL_ERR_RSA_INVALID_PADDING) )
337 snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
338 if( use_ret == -(POLARSSL_ERR_RSA_KEY_GEN_FAILED) )
339 snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
340 if( use_ret == -(POLARSSL_ERR_RSA_KEY_CHECK_FAILED) )
341 snprintf( buf, buflen, "RSA - Key failed to pass the libraries validity check" );
342 if( use_ret == -(POLARSSL_ERR_RSA_PUBLIC_FAILED) )
343 snprintf( buf, buflen, "RSA - The public key operation failed" );
344 if( use_ret == -(POLARSSL_ERR_RSA_PRIVATE_FAILED) )
345 snprintf( buf, buflen, "RSA - The private key operation failed" );
346 if( use_ret == -(POLARSSL_ERR_RSA_VERIFY_FAILED) )
347 snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
348 if( use_ret == -(POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE) )
349 snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
350 if( use_ret == -(POLARSSL_ERR_RSA_RNG_FAILED) )
351 snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
352#endif /* POLARSSL_RSA_C */
353
Paul Bakker831a7552011-05-18 13:32:51 +0000354#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000355 if( use_ret == -(POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE) )
356 snprintf( buf, buflen, "SSL - The requested feature is not available" );
357 if( use_ret == -(POLARSSL_ERR_SSL_BAD_INPUT_DATA) )
358 snprintf( buf, buflen, "SSL - Bad input parameters to function" );
359 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_MAC) )
360 snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
361 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_RECORD) )
362 snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
Paul Bakker831a7552011-05-18 13:32:51 +0000363 if( use_ret == -(POLARSSL_ERR_SSL_CONN_EOF) )
364 snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
Paul Bakker9d781402011-05-09 16:17:09 +0000365 if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_CIPHER) )
366 snprintf( buf, buflen, "SSL - An unknown cipher was received" );
367 if( use_ret == -(POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN) )
368 snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
Paul Bakkera9a028e2013-11-21 17:31:06 +0100369 if( use_ret == -(POLARSSL_ERR_SSL_NO_RNG) )
370 snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
Paul Bakker9d781402011-05-09 16:17:09 +0000371 if( use_ret == -(POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE) )
372 snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
373 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE) )
374 snprintf( buf, buflen, "SSL - DESCRIPTION MISSING" );
375 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED) )
376 snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
377 if( use_ret == -(POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED) )
Paul Bakker73a899a2013-04-17 19:11:36 +0200378 snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000379 if( use_ret == -(POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED) )
380 snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
381 if( use_ret == -(POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE) )
382 snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
383 if( use_ret == -(POLARSSL_ERR_SSL_FATAL_ALERT_MESSAGE) )
Paul Bakker3aac1da2012-05-08 13:12:27 +0000384 {
Paul Bakker9d781402011-05-09 16:17:09 +0000385 snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
Paul Bakker3aac1da2012-05-08 13:12:27 +0000386 return;
387 }
Paul Bakker9d781402011-05-09 16:17:09 +0000388 if( use_ret == -(POLARSSL_ERR_SSL_PEER_VERIFY_FAILED) )
389 snprintf( buf, buflen, "SSL - Verification of our peer failed" );
390 if( use_ret == -(POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) )
391 snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
392 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO) )
393 snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
394 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO) )
395 snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
396 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE) )
397 snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
398 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
399 snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
400 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
401 snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
402 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
403 snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
404 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
405 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
Paul Bakker41c83d32013-03-20 14:39:14 +0100406 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
407 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
408 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
409 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
Paul Bakker9d781402011-05-09 16:17:09 +0000410 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
411 snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
412 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
413 snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
414 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_FINISHED) )
415 snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000416 if( use_ret == -(POLARSSL_ERR_SSL_MALLOC_FAILED) )
417 snprintf( buf, buflen, "SSL - Memory allocation failed" );
Paul Bakker05ef8352012-05-08 09:17:57 +0000418 if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FAILED) )
419 snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
420 if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
421 snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
Paul Bakker83f00bb2012-07-04 11:08:50 +0000422 if( use_ret == -(POLARSSL_ERR_SSL_COMPRESSION_FAILED) )
423 snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
Paul Bakker1d29fb52012-09-28 13:28:45 +0000424 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
425 snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
Manuel Pégourié-Gonnarda5cc6022013-07-31 12:58:16 +0200426 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
427 snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
Paul Bakker606b4ba2013-08-14 16:52:14 +0200428 if( use_ret == -(POLARSSL_ERR_SSL_SESSION_TICKET_EXPIRED) )
429 snprintf( buf, buflen, "SSL - Session ticket has expired" );
Manuel Pégourié-Gonnardb3d91872013-08-14 15:56:19 +0200430 if( use_ret == -(POLARSSL_ERR_SSL_PK_TYPE_MISMATCH) )
431 snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
Paul Bakker6db455e2013-09-18 17:29:31 +0200432 if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_IDENTITY) )
433 snprintf( buf, buflen, "SSL - Unkown identity received (eg, PSK identity)" );
Manuel Pégourié-Gonnarda8a25ae2013-10-27 13:48:15 +0100434 if( use_ret == -(POLARSSL_ERR_SSL_INTERNAL_ERROR) )
435 snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
Manuel Pégourié-Gonnard83cdffc2014-03-10 21:20:29 +0100436 if( use_ret == -(POLARSSL_ERR_SSL_COUNTER_WRAPPING) )
437 snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
Paul Bakker831a7552011-05-18 13:32:51 +0000438#endif /* POLARSSL_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000439
Paul Bakker36713e82013-09-17 13:25:29 +0200440#if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000441 if( use_ret == -(POLARSSL_ERR_X509_FEATURE_UNAVAILABLE) )
442 snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
Paul Bakker51876562013-09-17 14:36:05 +0200443 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_OID) )
444 snprintf( buf, buflen, "X509 - Requested OID is unknown" );
445 if( use_ret == -(POLARSSL_ERR_X509_INVALID_FORMAT) )
446 snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
447 if( use_ret == -(POLARSSL_ERR_X509_INVALID_VERSION) )
448 snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
449 if( use_ret == -(POLARSSL_ERR_X509_INVALID_SERIAL) )
Paul Bakker9d781402011-05-09 16:17:09 +0000450 snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200451 if( use_ret == -(POLARSSL_ERR_X509_INVALID_ALG) )
Paul Bakker9d781402011-05-09 16:17:09 +0000452 snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200453 if( use_ret == -(POLARSSL_ERR_X509_INVALID_NAME) )
Paul Bakker9d781402011-05-09 16:17:09 +0000454 snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200455 if( use_ret == -(POLARSSL_ERR_X509_INVALID_DATE) )
Paul Bakker9d781402011-05-09 16:17:09 +0000456 snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200457 if( use_ret == -(POLARSSL_ERR_X509_INVALID_SIGNATURE) )
Paul Bakker9d781402011-05-09 16:17:09 +0000458 snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200459 if( use_ret == -(POLARSSL_ERR_X509_INVALID_EXTENSIONS) )
Paul Bakker9d781402011-05-09 16:17:09 +0000460 snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200461 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_VERSION) )
462 snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
463 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_SIG_ALG) )
Paul Bakker9d781402011-05-09 16:17:09 +0000464 snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
Paul Bakker51876562013-09-17 14:36:05 +0200465 if( use_ret == -(POLARSSL_ERR_X509_SIG_MISMATCH) )
Paul Bakker6db455e2013-09-18 17:29:31 +0200466 snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::x509_crt sig_oid)" );
Paul Bakker9d781402011-05-09 16:17:09 +0000467 if( use_ret == -(POLARSSL_ERR_X509_CERT_VERIFY_FAILED) )
468 snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
Paul Bakker6c0ceb32011-12-04 12:24:18 +0000469 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT) )
470 snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
Paul Bakker51876562013-09-17 14:36:05 +0200471 if( use_ret == -(POLARSSL_ERR_X509_BAD_INPUT_DATA) )
Paul Bakker69e095c2011-12-10 21:55:01 +0000472 snprintf( buf, buflen, "X509 - Input invalid" );
473 if( use_ret == -(POLARSSL_ERR_X509_MALLOC_FAILED) )
474 snprintf( buf, buflen, "X509 - Allocation of memory failed" );
475 if( use_ret == -(POLARSSL_ERR_X509_FILE_IO_ERROR) )
476 snprintf( buf, buflen, "X509 - Read/write of file failed" );
Paul Bakker36713e82013-09-17 13:25:29 +0200477#endif /* POLARSSL_X509_USE,X509_CREATE_C */
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200478
Paul Bakker9d781402011-05-09 16:17:09 +0000479 if( strlen( buf ) == 0 )
480 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
481 }
482
483 use_ret = ret & ~0xFF80;
484
485 if( use_ret == 0 )
486 return;
487
488 // If high level code is present, make a concatenation between both
489 // error strings.
490 //
491 len = strlen( buf );
492
493 if( len > 0 )
494 {
495 if( buflen - len < 5 )
496 return;
497
498 snprintf( buf + len, buflen - len, " : " );
499
500 buf += len + 3;
501 buflen -= len + 3;
502 }
503
504 // Low level error codes
505 //
506#if defined(POLARSSL_AES_C)
507 if( use_ret == -(POLARSSL_ERR_AES_INVALID_KEY_LENGTH) )
508 snprintf( buf, buflen, "AES - Invalid key length" );
509 if( use_ret == -(POLARSSL_ERR_AES_INVALID_INPUT_LENGTH) )
510 snprintf( buf, buflen, "AES - Invalid data input length" );
511#endif /* POLARSSL_AES_C */
512
Paul Bakkerdceecd82011-11-15 16:38:34 +0000513#if defined(POLARSSL_ASN1_PARSE_C)
514 if( use_ret == -(POLARSSL_ERR_ASN1_OUT_OF_DATA) )
515 snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
516 if( use_ret == -(POLARSSL_ERR_ASN1_UNEXPECTED_TAG) )
517 snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
518 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_LENGTH) )
519 snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
520 if( use_ret == -(POLARSSL_ERR_ASN1_LENGTH_MISMATCH) )
521 snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
522 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_DATA) )
523 snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000524 if( use_ret == -(POLARSSL_ERR_ASN1_MALLOC_FAILED) )
525 snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000526 if( use_ret == -(POLARSSL_ERR_ASN1_BUF_TOO_SMALL) )
527 snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
Paul Bakkerdceecd82011-11-15 16:38:34 +0000528#endif /* POLARSSL_ASN1_PARSE_C */
529
Paul Bakker9d781402011-05-09 16:17:09 +0000530#if defined(POLARSSL_BASE64_C)
531 if( use_ret == -(POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) )
532 snprintf( buf, buflen, "BASE64 - Output buffer too small" );
533 if( use_ret == -(POLARSSL_ERR_BASE64_INVALID_CHARACTER) )
534 snprintf( buf, buflen, "BASE64 - Invalid character in input" );
535#endif /* POLARSSL_BASE64_C */
536
537#if defined(POLARSSL_BIGNUM_C)
538 if( use_ret == -(POLARSSL_ERR_MPI_FILE_IO_ERROR) )
539 snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
540 if( use_ret == -(POLARSSL_ERR_MPI_BAD_INPUT_DATA) )
541 snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
542 if( use_ret == -(POLARSSL_ERR_MPI_INVALID_CHARACTER) )
543 snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
544 if( use_ret == -(POLARSSL_ERR_MPI_BUFFER_TOO_SMALL) )
Paul Bakker69e095c2011-12-10 21:55:01 +0000545 snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
Paul Bakker9d781402011-05-09 16:17:09 +0000546 if( use_ret == -(POLARSSL_ERR_MPI_NEGATIVE_VALUE) )
547 snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
548 if( use_ret == -(POLARSSL_ERR_MPI_DIVISION_BY_ZERO) )
549 snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
550 if( use_ret == -(POLARSSL_ERR_MPI_NOT_ACCEPTABLE) )
551 snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000552 if( use_ret == -(POLARSSL_ERR_MPI_MALLOC_FAILED) )
553 snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000554#endif /* POLARSSL_BIGNUM_C */
555
Paul Bakker83f00bb2012-07-04 11:08:50 +0000556#if defined(POLARSSL_BLOWFISH_C)
557 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
558 snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
559 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
560 snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
561#endif /* POLARSSL_BLOWFISH_C */
562
Paul Bakker9d781402011-05-09 16:17:09 +0000563#if defined(POLARSSL_CAMELLIA_C)
564 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
565 snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
566 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
567 snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
568#endif /* POLARSSL_CAMELLIA_C */
569
Paul Bakker880ac7e2011-11-27 14:50:49 +0000570#if defined(POLARSSL_CTR_DRBG_C)
571 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
572 snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
573 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
574 snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
575 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG) )
576 snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000577 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR) )
578 snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
Paul Bakker880ac7e2011-11-27 14:50:49 +0000579#endif /* POLARSSL_CTR_DRBG_C */
580
Paul Bakker9d781402011-05-09 16:17:09 +0000581#if defined(POLARSSL_DES_C)
582 if( use_ret == -(POLARSSL_ERR_DES_INVALID_INPUT_LENGTH) )
583 snprintf( buf, buflen, "DES - The data input has an invalid length" );
584#endif /* POLARSSL_DES_C */
585
Paul Bakker6083fd22011-12-03 21:45:14 +0000586#if defined(POLARSSL_ENTROPY_C)
587 if( use_ret == -(POLARSSL_ERR_ENTROPY_SOURCE_FAILED) )
588 snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
589 if( use_ret == -(POLARSSL_ERR_ENTROPY_MAX_SOURCES) )
590 snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
Paul Bakker43655f42011-12-15 20:11:16 +0000591 if( use_ret == -(POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED) )
592 snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
Paul Bakker66ff70d2014-03-26 11:54:05 +0100593 if( use_ret == -(POLARSSL_ERR_ENTROPY_FILE_IO_ERROR) )
594 snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
Paul Bakker6083fd22011-12-03 21:45:14 +0000595#endif /* POLARSSL_ENTROPY_C */
596
Paul Bakker030277a2012-04-17 12:24:26 +0000597#if defined(POLARSSL_GCM_C)
598 if( use_ret == -(POLARSSL_ERR_GCM_AUTH_FAILED) )
599 snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
Paul Bakkerd8ef1672012-04-18 14:17:32 +0000600 if( use_ret == -(POLARSSL_ERR_GCM_BAD_INPUT) )
601 snprintf( buf, buflen, "GCM - Bad input parameters to function" );
Paul Bakker030277a2012-04-17 12:24:26 +0000602#endif /* POLARSSL_GCM_C */
603
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100604#if defined(POLARSSL_HMAC_DRBG_C)
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100605 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
606 snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
607 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
608 snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
609 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_FILE_IO_ERROR) )
610 snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
Manuel Pégourié-Gonnard9a6e93e2014-03-11 09:34:02 +0100611 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
612 snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100613#endif /* POLARSSL_HMAC_DRBG_C */
614
Paul Bakker69e095c2011-12-10 21:55:01 +0000615#if defined(POLARSSL_MD2_C)
616 if( use_ret == -(POLARSSL_ERR_MD2_FILE_IO_ERROR) )
617 snprintf( buf, buflen, "MD2 - Read/write error in file" );
618#endif /* POLARSSL_MD2_C */
619
620#if defined(POLARSSL_MD4_C)
621 if( use_ret == -(POLARSSL_ERR_MD4_FILE_IO_ERROR) )
622 snprintf( buf, buflen, "MD4 - Read/write error in file" );
623#endif /* POLARSSL_MD4_C */
624
625#if defined(POLARSSL_MD5_C)
626 if( use_ret == -(POLARSSL_ERR_MD5_FILE_IO_ERROR) )
627 snprintf( buf, buflen, "MD5 - Read/write error in file" );
628#endif /* POLARSSL_MD5_C */
629
Paul Bakker9d781402011-05-09 16:17:09 +0000630#if defined(POLARSSL_NET_C)
631 if( use_ret == -(POLARSSL_ERR_NET_UNKNOWN_HOST) )
632 snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
633 if( use_ret == -(POLARSSL_ERR_NET_SOCKET_FAILED) )
634 snprintf( buf, buflen, "NET - Failed to open a socket" );
635 if( use_ret == -(POLARSSL_ERR_NET_CONNECT_FAILED) )
636 snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
637 if( use_ret == -(POLARSSL_ERR_NET_BIND_FAILED) )
638 snprintf( buf, buflen, "NET - Binding of the socket failed" );
639 if( use_ret == -(POLARSSL_ERR_NET_LISTEN_FAILED) )
640 snprintf( buf, buflen, "NET - Could not listen on the socket" );
641 if( use_ret == -(POLARSSL_ERR_NET_ACCEPT_FAILED) )
642 snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
643 if( use_ret == -(POLARSSL_ERR_NET_RECV_FAILED) )
644 snprintf( buf, buflen, "NET - Reading information from the socket failed" );
645 if( use_ret == -(POLARSSL_ERR_NET_SEND_FAILED) )
646 snprintf( buf, buflen, "NET - Sending information through the socket failed" );
647 if( use_ret == -(POLARSSL_ERR_NET_CONN_RESET) )
648 snprintf( buf, buflen, "NET - Connection was reset by peer" );
Paul Bakker831a7552011-05-18 13:32:51 +0000649 if( use_ret == -(POLARSSL_ERR_NET_WANT_READ) )
650 snprintf( buf, buflen, "NET - Connection requires a read call" );
651 if( use_ret == -(POLARSSL_ERR_NET_WANT_WRITE) )
652 snprintf( buf, buflen, "NET - Connection requires a write call" );
Paul Bakker9d781402011-05-09 16:17:09 +0000653#endif /* POLARSSL_NET_C */
654
Paul Bakkerc70b9822013-04-07 22:00:46 +0200655#if defined(POLARSSL_OID_C)
656 if( use_ret == -(POLARSSL_ERR_OID_NOT_FOUND) )
657 snprintf( buf, buflen, "OID - OID is not found" );
658#endif /* POLARSSL_OID_C */
659
Paul Bakker9d781402011-05-09 16:17:09 +0000660#if defined(POLARSSL_PADLOCK_C)
661 if( use_ret == -(POLARSSL_ERR_PADLOCK_DATA_MISALIGNED) )
662 snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
663#endif /* POLARSSL_PADLOCK_C */
664
Paul Bakkerd14277d2012-09-26 15:19:05 +0000665#if defined(POLARSSL_PBKDF2_C)
666 if( use_ret == -(POLARSSL_ERR_PBKDF2_BAD_INPUT_DATA) )
667 snprintf( buf, buflen, "PBKDF2 - Bad input parameters to function" );
668#endif /* POLARSSL_PBKDF2_C */
669
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100670#if defined(POLARSSL_RIPEMD160_C)
671 if( use_ret == -(POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR) )
672 snprintf( buf, buflen, "RIPEMD160 - Read/write error in file" );
673#endif /* POLARSSL_RIPEMD160_C */
674
Paul Bakker69e095c2011-12-10 21:55:01 +0000675#if defined(POLARSSL_SHA1_C)
676 if( use_ret == -(POLARSSL_ERR_SHA1_FILE_IO_ERROR) )
677 snprintf( buf, buflen, "SHA1 - Read/write error in file" );
678#endif /* POLARSSL_SHA1_C */
679
Paul Bakker9e36f042013-06-30 14:34:05 +0200680#if defined(POLARSSL_SHA256_C)
681 if( use_ret == -(POLARSSL_ERR_SHA256_FILE_IO_ERROR) )
682 snprintf( buf, buflen, "SHA256 - Read/write error in file" );
683#endif /* POLARSSL_SHA256_C */
Paul Bakker69e095c2011-12-10 21:55:01 +0000684
Paul Bakker9e36f042013-06-30 14:34:05 +0200685#if defined(POLARSSL_SHA512_C)
686 if( use_ret == -(POLARSSL_ERR_SHA512_FILE_IO_ERROR) )
687 snprintf( buf, buflen, "SHA512 - Read/write error in file" );
688#endif /* POLARSSL_SHA512_C */
Paul Bakker69e095c2011-12-10 21:55:01 +0000689
Paul Bakker2466d932013-09-28 14:40:38 +0200690#if defined(POLARSSL_THREADING_C)
691 if( use_ret == -(POLARSSL_ERR_THREADING_FEATURE_UNAVAILABLE) )
692 snprintf( buf, buflen, "THREADING - The selected feature is not available" );
693 if( use_ret == -(POLARSSL_ERR_THREADING_BAD_INPUT_DATA) )
694 snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
695 if( use_ret == -(POLARSSL_ERR_THREADING_MUTEX_ERROR) )
696 snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
697#endif /* POLARSSL_THREADING_C */
698
Paul Bakker9d781402011-05-09 16:17:09 +0000699#if defined(POLARSSL_XTEA_C)
700 if( use_ret == -(POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH) )
701 snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
702#endif /* POLARSSL_XTEA_C */
703
704 if( strlen( buf ) != 0 )
705 return;
706
707 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
708}
709
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200710#if defined(POLARSSL_ERROR_STRERROR_BC)
711void error_strerror( int ret, char *buf, size_t buflen )
712{
Paul Bakkerb887f112013-10-11 15:09:40 +0200713 polarssl_strerror( ret, buf, buflen );
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200714}
715#endif /* POLARSSL_ERROR_STRERROR_BC */
716
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100717#else /* POLARSSL_ERROR_C */
718
719#if defined(POLARSSL_ERROR_STRERROR_DUMMY)
720
721#include <string.h>
722
723/*
724 * Provide an non-function in case POLARSSL_ERROR_C is not defined
725 */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200726void polarssl_strerror( int ret, char *buf, size_t buflen )
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100727{
728 ((void) ret);
729
730 if( buflen > 0 )
731 buf[0] = '\0';
732}
733
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200734#if defined(POLARSSL_ERROR_STRERROR_BC)
735void error_strerror( int ret, char *buf, size_t buflen )
736{
Paul Bakkerb887f112013-10-11 15:09:40 +0200737 polarssl_strerror( ret, buf, buflen );
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200738}
739#endif /* POLARSSL_ERROR_STRERROR_BC */
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100740#endif /* POLARSSL_ERROR_STRERROR_DUMMY */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200741
Paul Bakker9a736322012-11-14 12:39:52 +0000742#endif /* POLARSSL_ERROR_C */