blob: 44b11426b40e1644b840e91bf10309619f369b87 [file] [log] [blame]
Paul Bakker9d781402011-05-09 16:17:09 +00001/*
2 * Error message information
3 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00004 * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
Paul Bakker9d781402011-05-09 16:17:09 +00005 *
Manuel Pégourié-Gonnard085ab042015-01-23 11:06:27 +00006 * This file is part of mbed TLS (https://www.polarssl.org)
Paul Bakker9d781402011-05-09 16:17:09 +00007 *
Paul Bakker9d781402011-05-09 16:17:09 +00008 * 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
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020023#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker9d781402011-05-09 16:17:09 +000024#include "polarssl/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020025#else
26#include POLARSSL_CONFIG_FILE
27#endif
Paul Bakker9d781402011-05-09 16:17:09 +000028
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020029#if defined(POLARSSL_ERROR_C) || defined(POLARSSL_ERROR_STRERROR_DUMMY)
Paul Bakker3c2122f2013-06-24 19:03:14 +020030#include "polarssl/error.h"
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020031#endif
32
33#if defined(POLARSSL_ERROR_C)
Paul Bakker3c2122f2013-06-24 19:03:14 +020034
Paul Bakker9d781402011-05-09 16:17:09 +000035#if defined(POLARSSL_AES_C)
36#include "polarssl/aes.h"
37#endif
38
39#if defined(POLARSSL_BASE64_C)
40#include "polarssl/base64.h"
41#endif
42
43#if defined(POLARSSL_BIGNUM_C)
44#include "polarssl/bignum.h"
45#endif
46
Paul Bakker83f00bb2012-07-04 11:08:50 +000047#if defined(POLARSSL_BLOWFISH_C)
48#include "polarssl/blowfish.h"
49#endif
50
Paul Bakker9d781402011-05-09 16:17:09 +000051#if defined(POLARSSL_CAMELLIA_C)
52#include "polarssl/camellia.h"
53#endif
54
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +020055#if defined(POLARSSL_CCM_C)
56#include "polarssl/ccm.h"
57#endif
58
Paul Bakkerff61a782011-06-09 15:42:02 +000059#if defined(POLARSSL_CIPHER_C)
60#include "polarssl/cipher.h"
61#endif
62
Paul Bakker880ac7e2011-11-27 14:50:49 +000063#if defined(POLARSSL_CTR_DRBG_C)
64#include "polarssl/ctr_drbg.h"
65#endif
66
Paul Bakker9d781402011-05-09 16:17:09 +000067#if defined(POLARSSL_DES_C)
68#include "polarssl/des.h"
69#endif
70
71#if defined(POLARSSL_DHM_C)
72#include "polarssl/dhm.h"
73#endif
74
Paul Bakkercf4365f2013-01-16 17:00:43 +010075#if defined(POLARSSL_ECP_C)
76#include "polarssl/ecp.h"
77#endif
78
Paul Bakker6083fd22011-12-03 21:45:14 +000079#if defined(POLARSSL_ENTROPY_C)
80#include "polarssl/entropy.h"
81#endif
82
Paul Bakker030277a2012-04-17 12:24:26 +000083#if defined(POLARSSL_GCM_C)
84#include "polarssl/gcm.h"
85#endif
86
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010087#if defined(POLARSSL_HMAC_DRBG_C)
88#include "polarssl/hmac_drbg.h"
89#endif
90
Paul Bakker9d781402011-05-09 16:17:09 +000091#if defined(POLARSSL_MD_C)
92#include "polarssl/md.h"
93#endif
94
Paul Bakker69e095c2011-12-10 21:55:01 +000095#if defined(POLARSSL_MD2_C)
96#include "polarssl/md2.h"
97#endif
98
99#if defined(POLARSSL_MD4_C)
100#include "polarssl/md4.h"
101#endif
102
103#if defined(POLARSSL_MD5_C)
104#include "polarssl/md5.h"
105#endif
106
Paul Bakker9d781402011-05-09 16:17:09 +0000107#if defined(POLARSSL_NET_C)
108#include "polarssl/net.h"
109#endif
110
Paul Bakkerc70b9822013-04-07 22:00:46 +0200111#if defined(POLARSSL_OID_C)
112#include "polarssl/oid.h"
113#endif
114
Paul Bakker9d781402011-05-09 16:17:09 +0000115#if defined(POLARSSL_PADLOCK_C)
116#include "polarssl/padlock.h"
117#endif
118
Paul Bakkerd14277d2012-09-26 15:19:05 +0000119#if defined(POLARSSL_PBKDF2_C)
120#include "polarssl/pbkdf2.h"
121#endif
122
Paul Bakkercff68422013-09-15 20:43:33 +0200123#if defined(POLARSSL_PEM_PARSE_C) || defined(POLARSSL_PEM_WRITE_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000124#include "polarssl/pem.h"
125#endif
126
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200127#if defined(POLARSSL_PK_C)
128#include "polarssl/pk.h"
129#endif
130
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200131#if defined(POLARSSL_PKCS12_C)
132#include "polarssl/pkcs12.h"
133#endif
134
Paul Bakkerb0c19a42013-06-24 19:26:38 +0200135#if defined(POLARSSL_PKCS5_C)
136#include "polarssl/pkcs5.h"
137#endif
138
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100139#if defined(POLARSSL_RIPEMD160_C)
140#include "polarssl/ripemd160.h"
141#endif
142
Paul Bakker9d781402011-05-09 16:17:09 +0000143#if defined(POLARSSL_RSA_C)
144#include "polarssl/rsa.h"
145#endif
146
Paul Bakker69e095c2011-12-10 21:55:01 +0000147#if defined(POLARSSL_SHA1_C)
148#include "polarssl/sha1.h"
149#endif
150
Paul Bakker9e36f042013-06-30 14:34:05 +0200151#if defined(POLARSSL_SHA256_C)
Paul Bakkerd2681d82013-06-30 14:49:12 +0200152#include "polarssl/sha256.h"
Paul Bakker69e095c2011-12-10 21:55:01 +0000153#endif
154
Paul Bakker9e36f042013-06-30 14:34:05 +0200155#if defined(POLARSSL_SHA512_C)
Paul Bakkerd2681d82013-06-30 14:49:12 +0200156#include "polarssl/sha512.h"
Paul Bakker69e095c2011-12-10 21:55:01 +0000157#endif
158
Paul Bakker831a7552011-05-18 13:32:51 +0000159#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000160#include "polarssl/ssl.h"
161#endif
162
Paul Bakker2466d932013-09-28 14:40:38 +0200163#if defined(POLARSSL_THREADING_C)
164#include "polarssl/threading.h"
165#endif
166
Paul Bakker36713e82013-09-17 13:25:29 +0200167#if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000168#include "polarssl/x509.h"
169#endif
170
171#if defined(POLARSSL_XTEA_C)
172#include "polarssl/xtea.h"
173#endif
174
Manuel Pégourié-Gonnarde94e6e52015-01-19 15:01:53 +0000175#include <stdio.h>
Paul Bakker9d781402011-05-09 16:17:09 +0000176#include <string.h>
177
Paul Bakker6edcd412013-10-29 15:22:54 +0100178#if defined(_MSC_VER) && !defined snprintf && !defined(EFIX64) && \
179 !defined(EFI32)
Paul Bakkerdceecd82011-11-15 16:38:34 +0000180#define snprintf _snprintf
181#endif
182
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200183void polarssl_strerror( int ret, char *buf, size_t buflen )
Paul Bakker9d781402011-05-09 16:17:09 +0000184{
185 size_t len;
186 int use_ret;
187
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200188 if( buflen == 0 )
189 return;
190
Paul Bakker9d781402011-05-09 16:17:09 +0000191 memset( buf, 0x00, buflen );
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200192 /* Reduce buflen to make sure MSVC _snprintf() ends with \0 as well */
193 buflen -= 1;
194
Paul Bakker9d781402011-05-09 16:17:09 +0000195 if( ret < 0 )
196 ret = -ret;
197
198 if( ret & 0xFF80 )
199 {
200 use_ret = ret & 0xFF80;
201
202 // High level error codes
203 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200204 // BEGIN generated code
Paul Bakkerff61a782011-06-09 15:42:02 +0000205#if defined(POLARSSL_CIPHER_C)
206 if( use_ret == -(POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE) )
207 snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
208 if( use_ret == -(POLARSSL_ERR_CIPHER_BAD_INPUT_DATA) )
209 snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
210 if( use_ret == -(POLARSSL_ERR_CIPHER_ALLOC_FAILED) )
211 snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
212 if( use_ret == -(POLARSSL_ERR_CIPHER_INVALID_PADDING) )
213 snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
214 if( use_ret == -(POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
215 snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
Manuel Pégourié-Gonnard4fee79b2013-09-19 18:09:14 +0200216 if( use_ret == -(POLARSSL_ERR_CIPHER_AUTH_FAILED) )
217 snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
Paul Bakkerff61a782011-06-09 15:42:02 +0000218#endif /* POLARSSL_CIPHER_C */
219
Paul Bakker9d781402011-05-09 16:17:09 +0000220#if defined(POLARSSL_DHM_C)
221 if( use_ret == -(POLARSSL_ERR_DHM_BAD_INPUT_DATA) )
222 snprintf( buf, buflen, "DHM - Bad input parameters to function" );
223 if( use_ret == -(POLARSSL_ERR_DHM_READ_PARAMS_FAILED) )
224 snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
225 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PARAMS_FAILED) )
226 snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
227 if( use_ret == -(POLARSSL_ERR_DHM_READ_PUBLIC_FAILED) )
228 snprintf( buf, buflen, "DHM - Reading of the public values failed" );
229 if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PUBLIC_FAILED) )
Paul Bakker05ef8352012-05-08 09:17:57 +0000230 snprintf( buf, buflen, "DHM - Making of the public value failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000231 if( use_ret == -(POLARSSL_ERR_DHM_CALC_SECRET_FAILED) )
232 snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
Paul Bakker40ce79f2013-09-15 17:43:54 +0200233 if( use_ret == -(POLARSSL_ERR_DHM_INVALID_FORMAT) )
234 snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
235 if( use_ret == -(POLARSSL_ERR_DHM_MALLOC_FAILED) )
236 snprintf( buf, buflen, "DHM - Allocation of memory failed" );
237 if( use_ret == -(POLARSSL_ERR_DHM_FILE_IO_ERROR) )
238 snprintf( buf, buflen, "DHM - Read/write of file failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000239#endif /* POLARSSL_DHM_C */
240
Paul Bakkercf4365f2013-01-16 17:00:43 +0100241#if defined(POLARSSL_ECP_C)
242 if( use_ret == -(POLARSSL_ERR_ECP_BAD_INPUT_DATA) )
243 snprintf( buf, buflen, "ECP - Bad input parameters to function" );
Paul Bakker41c83d32013-03-20 14:39:14 +0100244 if( use_ret == -(POLARSSL_ERR_ECP_BUFFER_TOO_SMALL) )
245 snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
Paul Bakkerfd3eac52013-06-29 23:31:33 +0200246 if( use_ret == -(POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE) )
247 snprintf( buf, buflen, "ECP - Requested curve not available" );
Paul Bakker1a7550a2013-09-15 13:01:22 +0200248 if( use_ret == -(POLARSSL_ERR_ECP_VERIFY_FAILED) )
249 snprintf( buf, buflen, "ECP - The signature is not valid" );
Manuel Pégourié-Gonnard456d3b92013-09-16 18:04:38 +0200250 if( use_ret == -(POLARSSL_ERR_ECP_MALLOC_FAILED) )
251 snprintf( buf, buflen, "ECP - Memory allocation failed" );
252 if( use_ret == -(POLARSSL_ERR_ECP_RANDOM_FAILED) )
253 snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
254 if( use_ret == -(POLARSSL_ERR_ECP_INVALID_KEY) )
255 snprintf( buf, buflen, "ECP - Invalid private or public key" );
Manuel Pégourié-Gonnard35e95dd2014-04-08 12:17:41 +0200256 if( use_ret == -(POLARSSL_ERR_ECP_SIG_LEN_MISMATCH) )
257 snprintf( buf, buflen, "ECP - Signature is valid but shorter than the user-supplied length" );
Paul Bakkercf4365f2013-01-16 17:00:43 +0100258#endif /* POLARSSL_ECP_C */
259
Paul Bakker9d781402011-05-09 16:17:09 +0000260#if defined(POLARSSL_MD_C)
261 if( use_ret == -(POLARSSL_ERR_MD_FEATURE_UNAVAILABLE) )
262 snprintf( buf, buflen, "MD - The selected feature is not available" );
Paul Bakker9c021ad2011-06-09 15:55:11 +0000263 if( use_ret == -(POLARSSL_ERR_MD_BAD_INPUT_DATA) )
264 snprintf( buf, buflen, "MD - Bad input parameters to function" );
265 if( use_ret == -(POLARSSL_ERR_MD_ALLOC_FAILED) )
266 snprintf( buf, buflen, "MD - Failed to allocate memory" );
Paul Bakker8913f822012-01-14 18:07:41 +0000267 if( use_ret == -(POLARSSL_ERR_MD_FILE_IO_ERROR) )
268 snprintf( buf, buflen, "MD - Opening or reading of file failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000269#endif /* POLARSSL_MD_C */
270
Paul Bakkercff68422013-09-15 20:43:33 +0200271#if defined(POLARSSL_PEM_PARSE_C) || defined(POLARSSL_PEM_WRITE_C)
Paul Bakker00b28602013-06-24 13:02:41 +0200272 if( use_ret == -(POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
273 snprintf( buf, buflen, "PEM - No PEM header or footer found" );
Paul Bakker9d781402011-05-09 16:17:09 +0000274 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_DATA) )
275 snprintf( buf, buflen, "PEM - PEM string is not as expected" );
276 if( use_ret == -(POLARSSL_ERR_PEM_MALLOC_FAILED) )
277 snprintf( buf, buflen, "PEM - Failed to allocate memory" );
278 if( use_ret == -(POLARSSL_ERR_PEM_INVALID_ENC_IV) )
279 snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
280 if( use_ret == -(POLARSSL_ERR_PEM_UNKNOWN_ENC_ALG) )
281 snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
282 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_REQUIRED) )
283 snprintf( buf, buflen, "PEM - Private key password can't be empty" );
284 if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_MISMATCH) )
285 snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
286 if( use_ret == -(POLARSSL_ERR_PEM_FEATURE_UNAVAILABLE) )
287 snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
Paul Bakker00b28602013-06-24 13:02:41 +0200288 if( use_ret == -(POLARSSL_ERR_PEM_BAD_INPUT_DATA) )
289 snprintf( buf, buflen, "PEM - Bad input parameters to function" );
Paul Bakkercff68422013-09-15 20:43:33 +0200290#endif /* POLARSSL_PEM_PARSE_C || POLARSSL_PEM_WRITE_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000291
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200292#if defined(POLARSSL_PK_C)
293 if( use_ret == -(POLARSSL_ERR_PK_MALLOC_FAILED) )
294 snprintf( buf, buflen, "PK - Memory alloation failed" );
Manuel Pégourié-Gonnard374e4b82013-07-09 10:21:34 +0200295 if( use_ret == -(POLARSSL_ERR_PK_TYPE_MISMATCH) )
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200296 snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
Manuel Pégourié-Gonnard15699382013-08-14 19:22:48 +0200297 if( use_ret == -(POLARSSL_ERR_PK_BAD_INPUT_DATA) )
298 snprintf( buf, buflen, "PK - Bad input parameters to function" );
Paul Bakker1a7550a2013-09-15 13:01:22 +0200299 if( use_ret == -(POLARSSL_ERR_PK_FILE_IO_ERROR) )
300 snprintf( buf, buflen, "PK - Read/write of file failed" );
301 if( use_ret == -(POLARSSL_ERR_PK_KEY_INVALID_VERSION) )
302 snprintf( buf, buflen, "PK - Unsupported key version" );
303 if( use_ret == -(POLARSSL_ERR_PK_KEY_INVALID_FORMAT) )
304 snprintf( buf, buflen, "PK - Invalid key tag or value" );
305 if( use_ret == -(POLARSSL_ERR_PK_UNKNOWN_PK_ALG) )
306 snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
307 if( use_ret == -(POLARSSL_ERR_PK_PASSWORD_REQUIRED) )
308 snprintf( buf, buflen, "PK - Private key password can't be empty" );
309 if( use_ret == -(POLARSSL_ERR_PK_PASSWORD_MISMATCH) )
310 snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
311 if( use_ret == -(POLARSSL_ERR_PK_INVALID_PUBKEY) )
312 snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
313 if( use_ret == -(POLARSSL_ERR_PK_INVALID_ALG) )
314 snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
315 if( use_ret == -(POLARSSL_ERR_PK_UNKNOWN_NAMED_CURVE) )
316 snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
317 if( use_ret == -(POLARSSL_ERR_PK_FEATURE_UNAVAILABLE) )
318 snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
Manuel Pégourié-Gonnard2abed842014-04-08 12:40:15 +0200319 if( use_ret == -(POLARSSL_ERR_PK_SIG_LEN_MISMATCH) )
320 snprintf( buf, buflen, "PK - The signature is valid but its length is less than expected" );
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200321#endif /* POLARSSL_PK_C */
322
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200323#if defined(POLARSSL_PKCS12_C)
324 if( use_ret == -(POLARSSL_ERR_PKCS12_BAD_INPUT_DATA) )
325 snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
326 if( use_ret == -(POLARSSL_ERR_PKCS12_FEATURE_UNAVAILABLE) )
327 snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
328 if( use_ret == -(POLARSSL_ERR_PKCS12_PBE_INVALID_FORMAT) )
329 snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
Paul Bakker38b50d72013-06-24 19:33:27 +0200330 if( use_ret == -(POLARSSL_ERR_PKCS12_PASSWORD_MISMATCH) )
331 snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200332#endif /* POLARSSL_PKCS12_C */
333
Paul Bakker28144de2013-06-24 19:28:55 +0200334#if defined(POLARSSL_PKCS5_C)
335 if( use_ret == -(POLARSSL_ERR_PKCS5_BAD_INPUT_DATA) )
336 snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
337 if( use_ret == -(POLARSSL_ERR_PKCS5_INVALID_FORMAT) )
338 snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
339 if( use_ret == -(POLARSSL_ERR_PKCS5_FEATURE_UNAVAILABLE) )
340 snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
341 if( use_ret == -(POLARSSL_ERR_PKCS5_PASSWORD_MISMATCH) )
342 snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
343#endif /* POLARSSL_PKCS5_C */
344
Paul Bakker9d781402011-05-09 16:17:09 +0000345#if defined(POLARSSL_RSA_C)
346 if( use_ret == -(POLARSSL_ERR_RSA_BAD_INPUT_DATA) )
347 snprintf( buf, buflen, "RSA - Bad input parameters to function" );
348 if( use_ret == -(POLARSSL_ERR_RSA_INVALID_PADDING) )
349 snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
350 if( use_ret == -(POLARSSL_ERR_RSA_KEY_GEN_FAILED) )
351 snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
352 if( use_ret == -(POLARSSL_ERR_RSA_KEY_CHECK_FAILED) )
353 snprintf( buf, buflen, "RSA - Key failed to pass the libraries validity check" );
354 if( use_ret == -(POLARSSL_ERR_RSA_PUBLIC_FAILED) )
355 snprintf( buf, buflen, "RSA - The public key operation failed" );
356 if( use_ret == -(POLARSSL_ERR_RSA_PRIVATE_FAILED) )
357 snprintf( buf, buflen, "RSA - The private key operation failed" );
358 if( use_ret == -(POLARSSL_ERR_RSA_VERIFY_FAILED) )
359 snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
360 if( use_ret == -(POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE) )
361 snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
362 if( use_ret == -(POLARSSL_ERR_RSA_RNG_FAILED) )
363 snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
364#endif /* POLARSSL_RSA_C */
365
Paul Bakker831a7552011-05-18 13:32:51 +0000366#if defined(POLARSSL_SSL_TLS_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000367 if( use_ret == -(POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE) )
368 snprintf( buf, buflen, "SSL - The requested feature is not available" );
369 if( use_ret == -(POLARSSL_ERR_SSL_BAD_INPUT_DATA) )
370 snprintf( buf, buflen, "SSL - Bad input parameters to function" );
371 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_MAC) )
372 snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
373 if( use_ret == -(POLARSSL_ERR_SSL_INVALID_RECORD) )
374 snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
Paul Bakker831a7552011-05-18 13:32:51 +0000375 if( use_ret == -(POLARSSL_ERR_SSL_CONN_EOF) )
376 snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
Paul Bakker9d781402011-05-09 16:17:09 +0000377 if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_CIPHER) )
378 snprintf( buf, buflen, "SSL - An unknown cipher was received" );
379 if( use_ret == -(POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN) )
380 snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
Paul Bakkera9a028e2013-11-21 17:31:06 +0100381 if( use_ret == -(POLARSSL_ERR_SSL_NO_RNG) )
382 snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
Paul Bakker9d781402011-05-09 16:17:09 +0000383 if( use_ret == -(POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE) )
384 snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
385 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE) )
Manuel Pégourié-Gonnard11c91922015-01-22 13:21:29 +0000386 snprintf( buf, buflen, "SSL - Our own certificate(s) is/are too large to send in an SSL message" );
Paul Bakker9d781402011-05-09 16:17:09 +0000387 if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED) )
388 snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
389 if( use_ret == -(POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED) )
Paul Bakker73a899a2013-04-17 19:11:36 +0200390 snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000391 if( use_ret == -(POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED) )
392 snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
393 if( use_ret == -(POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE) )
394 snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
395 if( use_ret == -(POLARSSL_ERR_SSL_FATAL_ALERT_MESSAGE) )
Paul Bakker3aac1da2012-05-08 13:12:27 +0000396 {
Paul Bakker9d781402011-05-09 16:17:09 +0000397 snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
Paul Bakker3aac1da2012-05-08 13:12:27 +0000398 return;
399 }
Paul Bakker9d781402011-05-09 16:17:09 +0000400 if( use_ret == -(POLARSSL_ERR_SSL_PEER_VERIFY_FAILED) )
401 snprintf( buf, buflen, "SSL - Verification of our peer failed" );
402 if( use_ret == -(POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) )
403 snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
404 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO) )
405 snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
406 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO) )
407 snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
408 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE) )
409 snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
410 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
411 snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
412 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
413 snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
414 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
415 snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
416 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
417 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
Paul Bakker41c83d32013-03-20 14:39:14 +0100418 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
419 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
420 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
421 snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
Paul Bakker9d781402011-05-09 16:17:09 +0000422 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
423 snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
424 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
425 snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
426 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_FINISHED) )
427 snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000428 if( use_ret == -(POLARSSL_ERR_SSL_MALLOC_FAILED) )
429 snprintf( buf, buflen, "SSL - Memory allocation failed" );
Paul Bakker05ef8352012-05-08 09:17:57 +0000430 if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FAILED) )
431 snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
432 if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
433 snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
Paul Bakker83f00bb2012-07-04 11:08:50 +0000434 if( use_ret == -(POLARSSL_ERR_SSL_COMPRESSION_FAILED) )
435 snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
Paul Bakker1d29fb52012-09-28 13:28:45 +0000436 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
437 snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
Manuel Pégourié-Gonnarda5cc6022013-07-31 12:58:16 +0200438 if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
439 snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
Paul Bakker606b4ba2013-08-14 16:52:14 +0200440 if( use_ret == -(POLARSSL_ERR_SSL_SESSION_TICKET_EXPIRED) )
441 snprintf( buf, buflen, "SSL - Session ticket has expired" );
Manuel Pégourié-Gonnardb3d91872013-08-14 15:56:19 +0200442 if( use_ret == -(POLARSSL_ERR_SSL_PK_TYPE_MISMATCH) )
443 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 +0200444 if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_IDENTITY) )
Paul Bakker75342a62014-04-08 17:35:40 +0200445 snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
Manuel Pégourié-Gonnarda8a25ae2013-10-27 13:48:15 +0100446 if( use_ret == -(POLARSSL_ERR_SSL_INTERNAL_ERROR) )
447 snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
Manuel Pégourié-Gonnard83cdffc2014-03-10 21:20:29 +0100448 if( use_ret == -(POLARSSL_ERR_SSL_COUNTER_WRAPPING) )
449 snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
Manuel Pégourié-Gonnard65919622014-08-19 12:50:30 +0200450 if( use_ret == -(POLARSSL_ERR_SSL_WAITING_SERVER_HELLO_RENEGO) )
451 snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" );
Manuel Pégourié-Gonnardf01768c2015-01-08 17:06:16 +0100452 if( use_ret == -(POLARSSL_ERR_SSL_NO_USABLE_CIPHERSUITE) )
Manuel Pégourié-Gonnard607d6632015-01-26 11:17:20 +0000453 snprintf( buf, buflen, "SSL - None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages)" );
Paul Bakker831a7552011-05-18 13:32:51 +0000454#endif /* POLARSSL_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000455
Paul Bakker36713e82013-09-17 13:25:29 +0200456#if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
Paul Bakker9d781402011-05-09 16:17:09 +0000457 if( use_ret == -(POLARSSL_ERR_X509_FEATURE_UNAVAILABLE) )
458 snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
Paul Bakker51876562013-09-17 14:36:05 +0200459 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_OID) )
460 snprintf( buf, buflen, "X509 - Requested OID is unknown" );
461 if( use_ret == -(POLARSSL_ERR_X509_INVALID_FORMAT) )
462 snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
463 if( use_ret == -(POLARSSL_ERR_X509_INVALID_VERSION) )
464 snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
465 if( use_ret == -(POLARSSL_ERR_X509_INVALID_SERIAL) )
Paul Bakker9d781402011-05-09 16:17:09 +0000466 snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200467 if( use_ret == -(POLARSSL_ERR_X509_INVALID_ALG) )
Paul Bakker9d781402011-05-09 16:17:09 +0000468 snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200469 if( use_ret == -(POLARSSL_ERR_X509_INVALID_NAME) )
Paul Bakker9d781402011-05-09 16:17:09 +0000470 snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200471 if( use_ret == -(POLARSSL_ERR_X509_INVALID_DATE) )
Paul Bakker9d781402011-05-09 16:17:09 +0000472 snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200473 if( use_ret == -(POLARSSL_ERR_X509_INVALID_SIGNATURE) )
Paul Bakker9d781402011-05-09 16:17:09 +0000474 snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200475 if( use_ret == -(POLARSSL_ERR_X509_INVALID_EXTENSIONS) )
Paul Bakker9d781402011-05-09 16:17:09 +0000476 snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
Paul Bakker51876562013-09-17 14:36:05 +0200477 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_VERSION) )
478 snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
479 if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_SIG_ALG) )
Paul Bakker9d781402011-05-09 16:17:09 +0000480 snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
Paul Bakker51876562013-09-17 14:36:05 +0200481 if( use_ret == -(POLARSSL_ERR_X509_SIG_MISMATCH) )
Paul Bakker6db455e2013-09-18 17:29:31 +0200482 snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::x509_crt sig_oid)" );
Paul Bakker9d781402011-05-09 16:17:09 +0000483 if( use_ret == -(POLARSSL_ERR_X509_CERT_VERIFY_FAILED) )
484 snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
Paul Bakker6c0ceb32011-12-04 12:24:18 +0000485 if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT) )
486 snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
Paul Bakker51876562013-09-17 14:36:05 +0200487 if( use_ret == -(POLARSSL_ERR_X509_BAD_INPUT_DATA) )
Paul Bakker69e095c2011-12-10 21:55:01 +0000488 snprintf( buf, buflen, "X509 - Input invalid" );
489 if( use_ret == -(POLARSSL_ERR_X509_MALLOC_FAILED) )
490 snprintf( buf, buflen, "X509 - Allocation of memory failed" );
491 if( use_ret == -(POLARSSL_ERR_X509_FILE_IO_ERROR) )
492 snprintf( buf, buflen, "X509 - Read/write of file failed" );
Paul Bakker36713e82013-09-17 13:25:29 +0200493#endif /* POLARSSL_X509_USE,X509_CREATE_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200494 // END generated code
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200495
Paul Bakker9d781402011-05-09 16:17:09 +0000496 if( strlen( buf ) == 0 )
497 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
498 }
499
500 use_ret = ret & ~0xFF80;
501
502 if( use_ret == 0 )
503 return;
504
505 // If high level code is present, make a concatenation between both
506 // error strings.
507 //
508 len = strlen( buf );
509
510 if( len > 0 )
511 {
512 if( buflen - len < 5 )
513 return;
514
515 snprintf( buf + len, buflen - len, " : " );
516
517 buf += len + 3;
518 buflen -= len + 3;
519 }
520
521 // Low level error codes
522 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200523 // BEGIN generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000524#if defined(POLARSSL_AES_C)
525 if( use_ret == -(POLARSSL_ERR_AES_INVALID_KEY_LENGTH) )
526 snprintf( buf, buflen, "AES - Invalid key length" );
527 if( use_ret == -(POLARSSL_ERR_AES_INVALID_INPUT_LENGTH) )
528 snprintf( buf, buflen, "AES - Invalid data input length" );
529#endif /* POLARSSL_AES_C */
530
Paul Bakkerdceecd82011-11-15 16:38:34 +0000531#if defined(POLARSSL_ASN1_PARSE_C)
532 if( use_ret == -(POLARSSL_ERR_ASN1_OUT_OF_DATA) )
533 snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
534 if( use_ret == -(POLARSSL_ERR_ASN1_UNEXPECTED_TAG) )
535 snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
536 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_LENGTH) )
537 snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
538 if( use_ret == -(POLARSSL_ERR_ASN1_LENGTH_MISMATCH) )
539 snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
540 if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_DATA) )
541 snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000542 if( use_ret == -(POLARSSL_ERR_ASN1_MALLOC_FAILED) )
543 snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000544 if( use_ret == -(POLARSSL_ERR_ASN1_BUF_TOO_SMALL) )
545 snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
Paul Bakkerdceecd82011-11-15 16:38:34 +0000546#endif /* POLARSSL_ASN1_PARSE_C */
547
Paul Bakker9d781402011-05-09 16:17:09 +0000548#if defined(POLARSSL_BASE64_C)
549 if( use_ret == -(POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) )
550 snprintf( buf, buflen, "BASE64 - Output buffer too small" );
551 if( use_ret == -(POLARSSL_ERR_BASE64_INVALID_CHARACTER) )
552 snprintf( buf, buflen, "BASE64 - Invalid character in input" );
553#endif /* POLARSSL_BASE64_C */
554
555#if defined(POLARSSL_BIGNUM_C)
556 if( use_ret == -(POLARSSL_ERR_MPI_FILE_IO_ERROR) )
557 snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
558 if( use_ret == -(POLARSSL_ERR_MPI_BAD_INPUT_DATA) )
559 snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
560 if( use_ret == -(POLARSSL_ERR_MPI_INVALID_CHARACTER) )
561 snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
562 if( use_ret == -(POLARSSL_ERR_MPI_BUFFER_TOO_SMALL) )
Paul Bakker69e095c2011-12-10 21:55:01 +0000563 snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
Paul Bakker9d781402011-05-09 16:17:09 +0000564 if( use_ret == -(POLARSSL_ERR_MPI_NEGATIVE_VALUE) )
565 snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
566 if( use_ret == -(POLARSSL_ERR_MPI_DIVISION_BY_ZERO) )
567 snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
568 if( use_ret == -(POLARSSL_ERR_MPI_NOT_ACCEPTABLE) )
569 snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000570 if( use_ret == -(POLARSSL_ERR_MPI_MALLOC_FAILED) )
571 snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
Paul Bakker9d781402011-05-09 16:17:09 +0000572#endif /* POLARSSL_BIGNUM_C */
573
Paul Bakker83f00bb2012-07-04 11:08:50 +0000574#if defined(POLARSSL_BLOWFISH_C)
575 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
576 snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
577 if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
578 snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
579#endif /* POLARSSL_BLOWFISH_C */
580
Paul Bakker9d781402011-05-09 16:17:09 +0000581#if defined(POLARSSL_CAMELLIA_C)
582 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
583 snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
584 if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
585 snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
586#endif /* POLARSSL_CAMELLIA_C */
587
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200588#if defined(POLARSSL_CCM_C)
589 if( use_ret == -(POLARSSL_ERR_CCM_BAD_INPUT) )
590 snprintf( buf, buflen, "CCM - Bad input parameters to function" );
591 if( use_ret == -(POLARSSL_ERR_CCM_AUTH_FAILED) )
592 snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
593#endif /* POLARSSL_CCM_C */
594
Paul Bakker880ac7e2011-11-27 14:50:49 +0000595#if defined(POLARSSL_CTR_DRBG_C)
596 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
597 snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
598 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
599 snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
600 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG) )
601 snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
Paul Bakker69e095c2011-12-10 21:55:01 +0000602 if( use_ret == -(POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR) )
603 snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
Paul Bakker880ac7e2011-11-27 14:50:49 +0000604#endif /* POLARSSL_CTR_DRBG_C */
605
Paul Bakker9d781402011-05-09 16:17:09 +0000606#if defined(POLARSSL_DES_C)
607 if( use_ret == -(POLARSSL_ERR_DES_INVALID_INPUT_LENGTH) )
608 snprintf( buf, buflen, "DES - The data input has an invalid length" );
609#endif /* POLARSSL_DES_C */
610
Paul Bakker6083fd22011-12-03 21:45:14 +0000611#if defined(POLARSSL_ENTROPY_C)
612 if( use_ret == -(POLARSSL_ERR_ENTROPY_SOURCE_FAILED) )
613 snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
614 if( use_ret == -(POLARSSL_ERR_ENTROPY_MAX_SOURCES) )
615 snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
Paul Bakker43655f42011-12-15 20:11:16 +0000616 if( use_ret == -(POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED) )
617 snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
Paul Bakker66ff70d2014-03-26 11:54:05 +0100618 if( use_ret == -(POLARSSL_ERR_ENTROPY_FILE_IO_ERROR) )
619 snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
Paul Bakker6083fd22011-12-03 21:45:14 +0000620#endif /* POLARSSL_ENTROPY_C */
621
Paul Bakker030277a2012-04-17 12:24:26 +0000622#if defined(POLARSSL_GCM_C)
623 if( use_ret == -(POLARSSL_ERR_GCM_AUTH_FAILED) )
624 snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
Paul Bakkerd8ef1672012-04-18 14:17:32 +0000625 if( use_ret == -(POLARSSL_ERR_GCM_BAD_INPUT) )
626 snprintf( buf, buflen, "GCM - Bad input parameters to function" );
Paul Bakker030277a2012-04-17 12:24:26 +0000627#endif /* POLARSSL_GCM_C */
628
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100629#if defined(POLARSSL_HMAC_DRBG_C)
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100630 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
631 snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
632 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
633 snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
634 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_FILE_IO_ERROR) )
635 snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
Manuel Pégourié-Gonnard9a6e93e2014-03-11 09:34:02 +0100636 if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
637 snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100638#endif /* POLARSSL_HMAC_DRBG_C */
639
Paul Bakker69e095c2011-12-10 21:55:01 +0000640#if defined(POLARSSL_MD2_C)
641 if( use_ret == -(POLARSSL_ERR_MD2_FILE_IO_ERROR) )
642 snprintf( buf, buflen, "MD2 - Read/write error in file" );
643#endif /* POLARSSL_MD2_C */
644
645#if defined(POLARSSL_MD4_C)
646 if( use_ret == -(POLARSSL_ERR_MD4_FILE_IO_ERROR) )
647 snprintf( buf, buflen, "MD4 - Read/write error in file" );
648#endif /* POLARSSL_MD4_C */
649
650#if defined(POLARSSL_MD5_C)
651 if( use_ret == -(POLARSSL_ERR_MD5_FILE_IO_ERROR) )
652 snprintf( buf, buflen, "MD5 - Read/write error in file" );
653#endif /* POLARSSL_MD5_C */
654
Paul Bakker9d781402011-05-09 16:17:09 +0000655#if defined(POLARSSL_NET_C)
656 if( use_ret == -(POLARSSL_ERR_NET_UNKNOWN_HOST) )
657 snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
658 if( use_ret == -(POLARSSL_ERR_NET_SOCKET_FAILED) )
659 snprintf( buf, buflen, "NET - Failed to open a socket" );
660 if( use_ret == -(POLARSSL_ERR_NET_CONNECT_FAILED) )
661 snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
662 if( use_ret == -(POLARSSL_ERR_NET_BIND_FAILED) )
663 snprintf( buf, buflen, "NET - Binding of the socket failed" );
664 if( use_ret == -(POLARSSL_ERR_NET_LISTEN_FAILED) )
665 snprintf( buf, buflen, "NET - Could not listen on the socket" );
666 if( use_ret == -(POLARSSL_ERR_NET_ACCEPT_FAILED) )
667 snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
668 if( use_ret == -(POLARSSL_ERR_NET_RECV_FAILED) )
669 snprintf( buf, buflen, "NET - Reading information from the socket failed" );
670 if( use_ret == -(POLARSSL_ERR_NET_SEND_FAILED) )
671 snprintf( buf, buflen, "NET - Sending information through the socket failed" );
672 if( use_ret == -(POLARSSL_ERR_NET_CONN_RESET) )
673 snprintf( buf, buflen, "NET - Connection was reset by peer" );
Paul Bakker831a7552011-05-18 13:32:51 +0000674 if( use_ret == -(POLARSSL_ERR_NET_WANT_READ) )
675 snprintf( buf, buflen, "NET - Connection requires a read call" );
676 if( use_ret == -(POLARSSL_ERR_NET_WANT_WRITE) )
677 snprintf( buf, buflen, "NET - Connection requires a write call" );
Paul Bakker9d781402011-05-09 16:17:09 +0000678#endif /* POLARSSL_NET_C */
679
Paul Bakkerc70b9822013-04-07 22:00:46 +0200680#if defined(POLARSSL_OID_C)
681 if( use_ret == -(POLARSSL_ERR_OID_NOT_FOUND) )
682 snprintf( buf, buflen, "OID - OID is not found" );
Manuel Pégourié-Gonnard7afdb882014-03-28 16:06:35 +0100683 if( use_ret == -(POLARSSL_ERR_OID_BUF_TOO_SMALL) )
684 snprintf( buf, buflen, "OID - output buffer is too small" );
Paul Bakkerc70b9822013-04-07 22:00:46 +0200685#endif /* POLARSSL_OID_C */
686
Paul Bakker9d781402011-05-09 16:17:09 +0000687#if defined(POLARSSL_PADLOCK_C)
688 if( use_ret == -(POLARSSL_ERR_PADLOCK_DATA_MISALIGNED) )
689 snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
690#endif /* POLARSSL_PADLOCK_C */
691
Paul Bakkerd14277d2012-09-26 15:19:05 +0000692#if defined(POLARSSL_PBKDF2_C)
693 if( use_ret == -(POLARSSL_ERR_PBKDF2_BAD_INPUT_DATA) )
694 snprintf( buf, buflen, "PBKDF2 - Bad input parameters to function" );
695#endif /* POLARSSL_PBKDF2_C */
696
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100697#if defined(POLARSSL_RIPEMD160_C)
698 if( use_ret == -(POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR) )
699 snprintf( buf, buflen, "RIPEMD160 - Read/write error in file" );
700#endif /* POLARSSL_RIPEMD160_C */
701
Paul Bakker69e095c2011-12-10 21:55:01 +0000702#if defined(POLARSSL_SHA1_C)
703 if( use_ret == -(POLARSSL_ERR_SHA1_FILE_IO_ERROR) )
704 snprintf( buf, buflen, "SHA1 - Read/write error in file" );
705#endif /* POLARSSL_SHA1_C */
706
Paul Bakker9e36f042013-06-30 14:34:05 +0200707#if defined(POLARSSL_SHA256_C)
708 if( use_ret == -(POLARSSL_ERR_SHA256_FILE_IO_ERROR) )
709 snprintf( buf, buflen, "SHA256 - Read/write error in file" );
710#endif /* POLARSSL_SHA256_C */
Paul Bakker69e095c2011-12-10 21:55:01 +0000711
Paul Bakker9e36f042013-06-30 14:34:05 +0200712#if defined(POLARSSL_SHA512_C)
713 if( use_ret == -(POLARSSL_ERR_SHA512_FILE_IO_ERROR) )
714 snprintf( buf, buflen, "SHA512 - Read/write error in file" );
715#endif /* POLARSSL_SHA512_C */
Paul Bakker69e095c2011-12-10 21:55:01 +0000716
Paul Bakker2466d932013-09-28 14:40:38 +0200717#if defined(POLARSSL_THREADING_C)
718 if( use_ret == -(POLARSSL_ERR_THREADING_FEATURE_UNAVAILABLE) )
719 snprintf( buf, buflen, "THREADING - The selected feature is not available" );
720 if( use_ret == -(POLARSSL_ERR_THREADING_BAD_INPUT_DATA) )
721 snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
722 if( use_ret == -(POLARSSL_ERR_THREADING_MUTEX_ERROR) )
723 snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
724#endif /* POLARSSL_THREADING_C */
725
Paul Bakker9d781402011-05-09 16:17:09 +0000726#if defined(POLARSSL_XTEA_C)
727 if( use_ret == -(POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH) )
728 snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
729#endif /* POLARSSL_XTEA_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200730 // END generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000731
732 if( strlen( buf ) != 0 )
733 return;
734
735 snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
736}
737
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200738#if defined(POLARSSL_ERROR_STRERROR_BC)
739void error_strerror( int ret, char *buf, size_t buflen )
740{
Paul Bakkerb887f112013-10-11 15:09:40 +0200741 polarssl_strerror( ret, buf, buflen );
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200742}
743#endif /* POLARSSL_ERROR_STRERROR_BC */
744
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100745#else /* POLARSSL_ERROR_C */
746
747#if defined(POLARSSL_ERROR_STRERROR_DUMMY)
748
749#include <string.h>
750
751/*
752 * Provide an non-function in case POLARSSL_ERROR_C is not defined
753 */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200754void polarssl_strerror( int ret, char *buf, size_t buflen )
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100755{
756 ((void) ret);
757
758 if( buflen > 0 )
759 buf[0] = '\0';
760}
761
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200762#if defined(POLARSSL_ERROR_STRERROR_BC)
763void error_strerror( int ret, char *buf, size_t buflen )
764{
Paul Bakkerb887f112013-10-11 15:09:40 +0200765 polarssl_strerror( ret, buf, buflen );
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200766}
767#endif /* POLARSSL_ERROR_STRERROR_BC */
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100768#endif /* POLARSSL_ERROR_STRERROR_DUMMY */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200769
Paul Bakker9a736322012-11-14 12:39:52 +0000770#endif /* POLARSSL_ERROR_C */