blob: a86daac5925cf160389442c4dce9bb46263d6dd3 [file] [log] [blame]
Paul Bakker9d781402011-05-09 16:17:09 +00001/*
2 * Error message information
3 *
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02004 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02005 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
Paul Bakker9d781402011-05-09 16:17:09 +000018 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000019 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker9d781402011-05-09 16:17:09 +000020 */
21
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020022#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000023#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020024#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020025#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020026#endif
Paul Bakker9d781402011-05-09 16:17:09 +000027
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028#if defined(MBEDTLS_ERROR_C) || defined(MBEDTLS_ERROR_STRERROR_DUMMY)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000029#include "mbedtls/error.h"
Rich Evans00ab4702015-02-06 13:43:58 +000030#include <string.h>
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020031#endif
32
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020033#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000034#include "mbedtls/platform.h"
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +000035#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020036#define mbedtls_snprintf snprintf
-~- redtangent ~-~9fa2e862016-05-26 10:07:49 +010037#define mbedtls_time_t time_t
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020038#endif
39
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020040#if defined(MBEDTLS_ERROR_C)
Paul Bakker3c2122f2013-06-24 19:03:14 +020041
Rich Evans00ab4702015-02-06 13:43:58 +000042#include <stdio.h>
43
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020044#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000045#include "mbedtls/aes.h"
Paul Bakker9d781402011-05-09 16:17:09 +000046#endif
47
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010048#if defined(MBEDTLS_ARC4_C)
49#include "mbedtls/arc4.h"
50#endif
51
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052#if defined(MBEDTLS_BASE64_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000053#include "mbedtls/base64.h"
Paul Bakker9d781402011-05-09 16:17:09 +000054#endif
55
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056#if defined(MBEDTLS_BIGNUM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000057#include "mbedtls/bignum.h"
Paul Bakker9d781402011-05-09 16:17:09 +000058#endif
59
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000061#include "mbedtls/blowfish.h"
Paul Bakker83f00bb2012-07-04 11:08:50 +000062#endif
63
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000065#include "mbedtls/camellia.h"
Paul Bakker9d781402011-05-09 16:17:09 +000066#endif
67
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000069#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +020070#endif
71
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020072#if defined(MBEDTLS_CIPHER_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000073#include "mbedtls/cipher.h"
Paul Bakkerff61a782011-06-09 15:42:02 +000074#endif
75
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010076#if defined(MBEDTLS_CMAC_C)
77#include "mbedtls/cmac.h"
78#endif
79
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020080#if defined(MBEDTLS_CTR_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000081#include "mbedtls/ctr_drbg.h"
Paul Bakker880ac7e2011-11-27 14:50:49 +000082#endif
83
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020084#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000085#include "mbedtls/des.h"
Paul Bakker9d781402011-05-09 16:17:09 +000086#endif
87
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020088#if defined(MBEDTLS_DHM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000089#include "mbedtls/dhm.h"
Paul Bakker9d781402011-05-09 16:17:09 +000090#endif
91
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092#if defined(MBEDTLS_ECP_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000093#include "mbedtls/ecp.h"
Paul Bakkercf4365f2013-01-16 17:00:43 +010094#endif
95
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096#if defined(MBEDTLS_ENTROPY_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000097#include "mbedtls/entropy.h"
Paul Bakker6083fd22011-12-03 21:45:14 +000098#endif
99
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200100#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000101#include "mbedtls/gcm.h"
Paul Bakker030277a2012-04-17 12:24:26 +0000102#endif
103
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200104#if defined(MBEDTLS_HMAC_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000105#include "mbedtls/hmac_drbg.h"
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100106#endif
107
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200108#if defined(MBEDTLS_MD_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000109#include "mbedtls/md.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000110#endif
111
Gilles Peskinea381fe82018-01-23 18:16:11 +0100112#if defined(MBEDTLS_MD2_C)
113#include "mbedtls/md2.h"
114#endif
115
116#if defined(MBEDTLS_MD4_C)
117#include "mbedtls/md4.h"
118#endif
119
120#if defined(MBEDTLS_MD5_C)
121#include "mbedtls/md5.h"
122#endif
123
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124#if defined(MBEDTLS_NET_C)
Andres AG3616f6f2016-09-14 14:32:09 +0100125#include "mbedtls/net_sockets.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000126#endif
127
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128#if defined(MBEDTLS_OID_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000129#include "mbedtls/oid.h"
Paul Bakkerc70b9822013-04-07 22:00:46 +0200130#endif
131
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200132#if defined(MBEDTLS_PADLOCK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000133#include "mbedtls/padlock.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000134#endif
135
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200136#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000137#include "mbedtls/pem.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000138#endif
139
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000141#include "mbedtls/pk.h"
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200142#endif
143
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200144#if defined(MBEDTLS_PKCS12_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000145#include "mbedtls/pkcs12.h"
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200146#endif
147
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200148#if defined(MBEDTLS_PKCS5_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000149#include "mbedtls/pkcs5.h"
Paul Bakkerb0c19a42013-06-24 19:26:38 +0200150#endif
151
Gilles Peskinea381fe82018-01-23 18:16:11 +0100152#if defined(MBEDTLS_RIPEMD160_C)
153#include "mbedtls/ripemd160.h"
154#endif
155
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200156#if defined(MBEDTLS_RSA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000157#include "mbedtls/rsa.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000158#endif
159
Gilles Peskinea381fe82018-01-23 18:16:11 +0100160#if defined(MBEDTLS_SHA1_C)
161#include "mbedtls/sha1.h"
162#endif
163
164#if defined(MBEDTLS_SHA256_C)
165#include "mbedtls/sha256.h"
166#endif
167
168#if defined(MBEDTLS_SHA512_C)
169#include "mbedtls/sha512.h"
170#endif
171
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200172#if defined(MBEDTLS_SSL_TLS_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000173#include "mbedtls/ssl.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000174#endif
175
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200176#if defined(MBEDTLS_THREADING_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000177#include "mbedtls/threading.h"
Paul Bakker2466d932013-09-28 14:40:38 +0200178#endif
179
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200180#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000181#include "mbedtls/x509.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000182#endif
183
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200184#if defined(MBEDTLS_XTEA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000185#include "mbedtls/xtea.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000186#endif
187
Paul Bakkerdceecd82011-11-15 16:38:34 +0000188
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200189void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker9d781402011-05-09 16:17:09 +0000190{
191 size_t len;
192 int use_ret;
193
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200194 if( buflen == 0 )
195 return;
196
Paul Bakker9d781402011-05-09 16:17:09 +0000197 memset( buf, 0x00, buflen );
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200198
Paul Bakker9d781402011-05-09 16:17:09 +0000199 if( ret < 0 )
200 ret = -ret;
201
202 if( ret & 0xFF80 )
203 {
204 use_ret = ret & 0xFF80;
205
206 // High level error codes
207 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200208 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200209#if defined(MBEDTLS_CIPHER_C)
210 if( use_ret == -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE) )
211 mbedtls_snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
212 if( use_ret == -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA) )
Rose Zadik9ba6b622018-01-24 12:59:19 +0000213 mbedtls_snprintf( buf, buflen, "CIPHER - Bad input parameters" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200214 if( use_ret == -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED) )
215 mbedtls_snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
216 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_PADDING) )
217 mbedtls_snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
218 if( use_ret == -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
219 mbedtls_snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
220 if( use_ret == -(MBEDTLS_ERR_CIPHER_AUTH_FAILED) )
221 mbedtls_snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
Janos Follath98e28a72016-05-31 14:03:54 +0100222 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT) )
Rose Zadik9ba6b622018-01-24 12:59:19 +0000223 mbedtls_snprintf( buf, buflen, "CIPHER - The context is invalid. For example, because it was freed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100224 if( use_ret == -(MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED) )
225 mbedtls_snprintf( buf, buflen, "CIPHER - Cipher hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200226#endif /* MBEDTLS_CIPHER_C */
Paul Bakkerff61a782011-06-09 15:42:02 +0000227
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200228#if defined(MBEDTLS_DHM_C)
229 if( use_ret == -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA) )
Rose Zadik41ad0822018-01-26 10:54:57 +0000230 mbedtls_snprintf( buf, buflen, "DHM - Bad input parameters" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200231 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED) )
232 mbedtls_snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
233 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED) )
234 mbedtls_snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
235 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED) )
236 mbedtls_snprintf( buf, buflen, "DHM - Reading of the public values failed" );
237 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED) )
238 mbedtls_snprintf( buf, buflen, "DHM - Making of the public value failed" );
239 if( use_ret == -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED) )
240 mbedtls_snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
241 if( use_ret == -(MBEDTLS_ERR_DHM_INVALID_FORMAT) )
242 mbedtls_snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200243 if( use_ret == -(MBEDTLS_ERR_DHM_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200244 mbedtls_snprintf( buf, buflen, "DHM - Allocation of memory failed" );
245 if( use_ret == -(MBEDTLS_ERR_DHM_FILE_IO_ERROR) )
Rose Zadik41ad0822018-01-26 10:54:57 +0000246 mbedtls_snprintf( buf, buflen, "DHM - Read or write of file failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100247 if( use_ret == -(MBEDTLS_ERR_DHM_HW_ACCEL_FAILED) )
248 mbedtls_snprintf( buf, buflen, "DHM - DHM hardware accelerator failed" );
Hanno Beckera6dd90d2017-10-04 13:15:54 +0100249 if( use_ret == -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED) )
Jaeden Amero784de592018-01-26 17:52:01 +0000250 mbedtls_snprintf( buf, buflen, "DHM - Setting the modulus and generator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200251#endif /* MBEDTLS_DHM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000252
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200253#if defined(MBEDTLS_ECP_C)
254 if( use_ret == -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA) )
255 mbedtls_snprintf( buf, buflen, "ECP - Bad input parameters to function" );
256 if( use_ret == -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL) )
257 mbedtls_snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
258 if( use_ret == -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) )
259 mbedtls_snprintf( buf, buflen, "ECP - Requested curve not available" );
260 if( use_ret == -(MBEDTLS_ERR_ECP_VERIFY_FAILED) )
261 mbedtls_snprintf( buf, buflen, "ECP - The signature is not valid" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200262 if( use_ret == -(MBEDTLS_ERR_ECP_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200263 mbedtls_snprintf( buf, buflen, "ECP - Memory allocation failed" );
264 if( use_ret == -(MBEDTLS_ERR_ECP_RANDOM_FAILED) )
265 mbedtls_snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
266 if( use_ret == -(MBEDTLS_ERR_ECP_INVALID_KEY) )
267 mbedtls_snprintf( buf, buflen, "ECP - Invalid private or public key" );
268 if( use_ret == -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) )
269 mbedtls_snprintf( buf, buflen, "ECP - Signature is valid but shorter than the user-supplied length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100270 if( use_ret == -(MBEDTLS_ERR_ECP_HW_ACCEL_FAILED) )
271 mbedtls_snprintf( buf, buflen, "ECP - ECP hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200272#endif /* MBEDTLS_ECP_C */
Paul Bakkercf4365f2013-01-16 17:00:43 +0100273
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200274#if defined(MBEDTLS_MD_C)
275 if( use_ret == -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE) )
276 mbedtls_snprintf( buf, buflen, "MD - The selected feature is not available" );
277 if( use_ret == -(MBEDTLS_ERR_MD_BAD_INPUT_DATA) )
278 mbedtls_snprintf( buf, buflen, "MD - Bad input parameters to function" );
279 if( use_ret == -(MBEDTLS_ERR_MD_ALLOC_FAILED) )
280 mbedtls_snprintf( buf, buflen, "MD - Failed to allocate memory" );
281 if( use_ret == -(MBEDTLS_ERR_MD_FILE_IO_ERROR) )
282 mbedtls_snprintf( buf, buflen, "MD - Opening or reading of file failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100283 if( use_ret == -(MBEDTLS_ERR_MD_HW_ACCEL_FAILED) )
284 mbedtls_snprintf( buf, buflen, "MD - MD hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200285#endif /* MBEDTLS_MD_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000286
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200287#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
288 if( use_ret == -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
289 mbedtls_snprintf( buf, buflen, "PEM - No PEM header or footer found" );
290 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_DATA) )
291 mbedtls_snprintf( buf, buflen, "PEM - PEM string is not as expected" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200292 if( use_ret == -(MBEDTLS_ERR_PEM_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200293 mbedtls_snprintf( buf, buflen, "PEM - Failed to allocate memory" );
294 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_ENC_IV) )
295 mbedtls_snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
296 if( use_ret == -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG) )
297 mbedtls_snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
298 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) )
299 mbedtls_snprintf( buf, buflen, "PEM - Private key password can't be empty" );
300 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) )
301 mbedtls_snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
302 if( use_ret == -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE) )
303 mbedtls_snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
304 if( use_ret == -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA) )
305 mbedtls_snprintf( buf, buflen, "PEM - Bad input parameters to function" );
306#endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000307
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200308#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200309 if( use_ret == -(MBEDTLS_ERR_PK_ALLOC_FAILED) )
Manuel Pégourié-Gonnard41b9c2b2015-05-28 14:56:20 +0200310 mbedtls_snprintf( buf, buflen, "PK - Memory allocation failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200311 if( use_ret == -(MBEDTLS_ERR_PK_TYPE_MISMATCH) )
312 mbedtls_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
313 if( use_ret == -(MBEDTLS_ERR_PK_BAD_INPUT_DATA) )
314 mbedtls_snprintf( buf, buflen, "PK - Bad input parameters to function" );
315 if( use_ret == -(MBEDTLS_ERR_PK_FILE_IO_ERROR) )
316 mbedtls_snprintf( buf, buflen, "PK - Read/write of file failed" );
317 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION) )
318 mbedtls_snprintf( buf, buflen, "PK - Unsupported key version" );
319 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT) )
320 mbedtls_snprintf( buf, buflen, "PK - Invalid key tag or value" );
321 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG) )
322 mbedtls_snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
323 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED) )
324 mbedtls_snprintf( buf, buflen, "PK - Private key password can't be empty" );
325 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH) )
326 mbedtls_snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
327 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_PUBKEY) )
328 mbedtls_snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
329 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_ALG) )
330 mbedtls_snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
331 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE) )
332 mbedtls_snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
333 if( use_ret == -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) )
334 mbedtls_snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
335 if( use_ret == -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH) )
336 mbedtls_snprintf( buf, buflen, "PK - The signature is valid but its length is less than expected" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100337 if( use_ret == -(MBEDTLS_ERR_PK_HW_ACCEL_FAILED) )
338 mbedtls_snprintf( buf, buflen, "PK - PK hardware accelerator failed" );
Gilles Peskine02768b42017-11-03 19:20:27 +0100339 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_SIGNATURE) )
340 mbedtls_snprintf( buf, buflen, "PK - Invalid signature" );
341 if( use_ret == -(MBEDTLS_ERR_PK_BUFFER_TOO_SMALL) )
342 mbedtls_snprintf( buf, buflen, "PK - Output buffer too small" );
343 if( use_ret == -(MBEDTLS_ERR_PK_NOT_PERMITTED) )
344 mbedtls_snprintf( buf, buflen, "PK - Operation not permitted" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200345#endif /* MBEDTLS_PK_C */
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200346
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200347#if defined(MBEDTLS_PKCS12_C)
348 if( use_ret == -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA) )
349 mbedtls_snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
350 if( use_ret == -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE) )
351 mbedtls_snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
352 if( use_ret == -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT) )
353 mbedtls_snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
354 if( use_ret == -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) )
355 mbedtls_snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
356#endif /* MBEDTLS_PKCS12_C */
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200357
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200358#if defined(MBEDTLS_PKCS5_C)
359 if( use_ret == -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA) )
360 mbedtls_snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
361 if( use_ret == -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT) )
362 mbedtls_snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
363 if( use_ret == -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE) )
364 mbedtls_snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
365 if( use_ret == -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) )
366 mbedtls_snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
367#endif /* MBEDTLS_PKCS5_C */
Paul Bakker28144de2013-06-24 19:28:55 +0200368
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200369#if defined(MBEDTLS_RSA_C)
370 if( use_ret == -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA) )
371 mbedtls_snprintf( buf, buflen, "RSA - Bad input parameters to function" );
372 if( use_ret == -(MBEDTLS_ERR_RSA_INVALID_PADDING) )
373 mbedtls_snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
374 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED) )
375 mbedtls_snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
376 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED) )
Rose Zadik042e97f2018-01-26 16:35:10 +0000377 mbedtls_snprintf( buf, buflen, "RSA - Key failed to pass the validity check of the library" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200378 if( use_ret == -(MBEDTLS_ERR_RSA_PUBLIC_FAILED) )
379 mbedtls_snprintf( buf, buflen, "RSA - The public key operation failed" );
380 if( use_ret == -(MBEDTLS_ERR_RSA_PRIVATE_FAILED) )
381 mbedtls_snprintf( buf, buflen, "RSA - The private key operation failed" );
382 if( use_ret == -(MBEDTLS_ERR_RSA_VERIFY_FAILED) )
383 mbedtls_snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
384 if( use_ret == -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE) )
385 mbedtls_snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
386 if( use_ret == -(MBEDTLS_ERR_RSA_RNG_FAILED) )
387 mbedtls_snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
Hanno Becker3cdc7112017-10-05 10:09:31 +0100388 if( use_ret == -(MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION) )
Rose Zadik042e97f2018-01-26 16:35:10 +0000389 mbedtls_snprintf( buf, buflen, "RSA - The implementation does not offer the requested operation, for example, because of security violations or lack of functionality" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100390 if( use_ret == -(MBEDTLS_ERR_RSA_HW_ACCEL_FAILED) )
391 mbedtls_snprintf( buf, buflen, "RSA - RSA hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200392#endif /* MBEDTLS_RSA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000393
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200394#if defined(MBEDTLS_SSL_TLS_C)
395 if( use_ret == -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE) )
396 mbedtls_snprintf( buf, buflen, "SSL - The requested feature is not available" );
397 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA) )
398 mbedtls_snprintf( buf, buflen, "SSL - Bad input parameters to function" );
399 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_MAC) )
400 mbedtls_snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
401 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_RECORD) )
402 mbedtls_snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
403 if( use_ret == -(MBEDTLS_ERR_SSL_CONN_EOF) )
404 mbedtls_snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
405 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER) )
406 mbedtls_snprintf( buf, buflen, "SSL - An unknown cipher was received" );
407 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN) )
408 mbedtls_snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
409 if( use_ret == -(MBEDTLS_ERR_SSL_NO_RNG) )
410 mbedtls_snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
411 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE) )
412 mbedtls_snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
413 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE) )
414 mbedtls_snprintf( buf, buflen, "SSL - Our own certificate(s) is/are too large to send in an SSL message" );
415 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED) )
416 mbedtls_snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
417 if( use_ret == -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED) )
418 mbedtls_snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
419 if( use_ret == -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED) )
420 mbedtls_snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
421 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE) )
422 mbedtls_snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
423 if( use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE) )
Paul Bakker3aac1da2012-05-08 13:12:27 +0000424 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200425 mbedtls_snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
Paul Bakker3aac1da2012-05-08 13:12:27 +0000426 return;
427 }
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200428 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED) )
429 mbedtls_snprintf( buf, buflen, "SSL - Verification of our peer failed" );
430 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) )
431 mbedtls_snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
432 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO) )
433 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
434 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO) )
435 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
436 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE) )
437 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
438 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
439 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
440 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
441 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
442 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
443 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
444 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
445 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
446 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
447 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
448 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
449 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
450 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
451 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
452 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
453 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
454 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED) )
455 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200456 if( use_ret == -(MBEDTLS_ERR_SSL_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200457 mbedtls_snprintf( buf, buflen, "SSL - Memory allocation failed" );
458 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED) )
459 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
460 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
461 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
462 if( use_ret == -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED) )
463 mbedtls_snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
464 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
465 mbedtls_snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
466 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
467 mbedtls_snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
468 if( use_ret == -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED) )
469 mbedtls_snprintf( buf, buflen, "SSL - Session ticket has expired" );
470 if( use_ret == -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH) )
471 mbedtls_snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
472 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY) )
473 mbedtls_snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
474 if( use_ret == -(MBEDTLS_ERR_SSL_INTERNAL_ERROR) )
475 mbedtls_snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
476 if( use_ret == -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING) )
477 mbedtls_snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
478 if( use_ret == -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO) )
479 mbedtls_snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" );
480 if( use_ret == -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED) )
481 mbedtls_snprintf( buf, buflen, "SSL - DTLS client must retry for hello verification" );
482 if( use_ret == -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL) )
483 mbedtls_snprintf( buf, buflen, "SSL - A buffer is too small to receive or write a message" );
484 if( use_ret == -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE) )
485 mbedtls_snprintf( buf, buflen, "SSL - None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages)" );
Manuel Pégourié-Gonnard88369942015-05-06 16:19:31 +0100486 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_READ) )
487 mbedtls_snprintf( buf, buflen, "SSL - Connection requires a read call" );
488 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_WRITE) )
489 mbedtls_snprintf( buf, buflen, "SSL - Connection requires a write call" );
490 if( use_ret == -(MBEDTLS_ERR_SSL_TIMEOUT) )
491 mbedtls_snprintf( buf, buflen, "SSL - The operation timed out" );
Manuel Pégourié-Gonnardbe619c12015-09-08 11:21:21 +0200492 if( use_ret == -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT) )
493 mbedtls_snprintf( buf, buflen, "SSL - The client initiated a reconnect from the same port" );
Manuel Pégourié-Gonnarde2e25e72015-12-03 16:13:17 +0100494 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD) )
495 mbedtls_snprintf( buf, buflen, "SSL - Record header looks valid but is not expected" );
Simon Butcher99000142016-10-13 17:21:01 +0100496 if( use_ret == -(MBEDTLS_ERR_SSL_NON_FATAL) )
497 mbedtls_snprintf( buf, buflen, "SSL - The alert message received indicates a non-fatal error" );
498 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH) )
499 mbedtls_snprintf( buf, buflen, "SSL - Couldn't set the hash for verifying CertificateVerify" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200500#endif /* MBEDTLS_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000501
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200502#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
503 if( use_ret == -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) )
504 mbedtls_snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
505 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_OID) )
506 mbedtls_snprintf( buf, buflen, "X509 - Requested OID is unknown" );
507 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_FORMAT) )
508 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
509 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_VERSION) )
510 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
511 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SERIAL) )
512 mbedtls_snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
513 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_ALG) )
514 mbedtls_snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
515 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_NAME) )
516 mbedtls_snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
517 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_DATE) )
518 mbedtls_snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
519 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SIGNATURE) )
520 mbedtls_snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
521 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS) )
522 mbedtls_snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
523 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_VERSION) )
524 mbedtls_snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
525 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG) )
526 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
527 if( use_ret == -(MBEDTLS_ERR_X509_SIG_MISMATCH) )
528 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" );
529 if( use_ret == -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) )
530 mbedtls_snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
531 if( use_ret == -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT) )
532 mbedtls_snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
533 if( use_ret == -(MBEDTLS_ERR_X509_BAD_INPUT_DATA) )
534 mbedtls_snprintf( buf, buflen, "X509 - Input invalid" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200535 if( use_ret == -(MBEDTLS_ERR_X509_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200536 mbedtls_snprintf( buf, buflen, "X509 - Allocation of memory failed" );
537 if( use_ret == -(MBEDTLS_ERR_X509_FILE_IO_ERROR) )
538 mbedtls_snprintf( buf, buflen, "X509 - Read/write of file failed" );
Manuel Pégourié-Gonnard9dbaf402015-06-22 11:50:58 +0200539 if( use_ret == -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL) )
540 mbedtls_snprintf( buf, buflen, "X509 - Destination buffer is too small" );
Manuel Pégourié-Gonnard31458a12017-06-26 10:11:49 +0200541 if( use_ret == -(MBEDTLS_ERR_X509_FATAL_ERROR) )
542 mbedtls_snprintf( buf, buflen, "X509 - A fatal error occured, eg the chain is too long or the vrfy callback failed" );
Manuel Pégourié-Gonnarde546ad42015-04-08 20:27:02 +0200543#endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200544 // END generated code
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200545
Paul Bakker9d781402011-05-09 16:17:09 +0000546 if( strlen( buf ) == 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200547 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000548 }
549
550 use_ret = ret & ~0xFF80;
551
552 if( use_ret == 0 )
553 return;
554
555 // If high level code is present, make a concatenation between both
556 // error strings.
557 //
558 len = strlen( buf );
559
560 if( len > 0 )
561 {
562 if( buflen - len < 5 )
563 return;
564
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200565 mbedtls_snprintf( buf + len, buflen - len, " : " );
Paul Bakker9d781402011-05-09 16:17:09 +0000566
567 buf += len + 3;
568 buflen -= len + 3;
569 }
570
571 // Low level error codes
572 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200573 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200574#if defined(MBEDTLS_AES_C)
575 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH) )
576 mbedtls_snprintf( buf, buflen, "AES - Invalid key length" );
577 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH) )
578 mbedtls_snprintf( buf, buflen, "AES - Invalid data input length" );
Andres Amaya Garciafd487392017-06-14 16:19:12 +0100579 if( use_ret == -(MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE) )
Rose Zadik7f441272018-01-22 11:48:23 +0000580 mbedtls_snprintf( buf, buflen, "AES - Feature not available. For example, an unsupported AES key size" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100581 if( use_ret == -(MBEDTLS_ERR_AES_HW_ACCEL_FAILED) )
582 mbedtls_snprintf( buf, buflen, "AES - AES hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200583#endif /* MBEDTLS_AES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000584
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100585#if defined(MBEDTLS_ARC4_C)
586 if( use_ret == -(MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED) )
587 mbedtls_snprintf( buf, buflen, "ARC4 - ARC4 hardware accelerator failed" );
588#endif /* MBEDTLS_ARC4_C */
589
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200590#if defined(MBEDTLS_ASN1_PARSE_C)
591 if( use_ret == -(MBEDTLS_ERR_ASN1_OUT_OF_DATA) )
592 mbedtls_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
593 if( use_ret == -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) )
594 mbedtls_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
595 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_LENGTH) )
596 mbedtls_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
597 if( use_ret == -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH) )
598 mbedtls_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
599 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_DATA) )
600 mbedtls_snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200601 if( use_ret == -(MBEDTLS_ERR_ASN1_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200602 mbedtls_snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
603 if( use_ret == -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL) )
604 mbedtls_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
605#endif /* MBEDTLS_ASN1_PARSE_C */
Paul Bakkerdceecd82011-11-15 16:38:34 +0000606
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200607#if defined(MBEDTLS_BASE64_C)
608 if( use_ret == -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) )
609 mbedtls_snprintf( buf, buflen, "BASE64 - Output buffer too small" );
610 if( use_ret == -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER) )
611 mbedtls_snprintf( buf, buflen, "BASE64 - Invalid character in input" );
612#endif /* MBEDTLS_BASE64_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000613
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200614#if defined(MBEDTLS_BIGNUM_C)
615 if( use_ret == -(MBEDTLS_ERR_MPI_FILE_IO_ERROR) )
616 mbedtls_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
617 if( use_ret == -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA) )
618 mbedtls_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
619 if( use_ret == -(MBEDTLS_ERR_MPI_INVALID_CHARACTER) )
620 mbedtls_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
621 if( use_ret == -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL) )
622 mbedtls_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
623 if( use_ret == -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE) )
624 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
625 if( use_ret == -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO) )
626 mbedtls_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
627 if( use_ret == -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) )
628 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200629 if( use_ret == -(MBEDTLS_ERR_MPI_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200630 mbedtls_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
631#endif /* MBEDTLS_BIGNUM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000632
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200633#if defined(MBEDTLS_BLOWFISH_C)
634 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
635 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100636 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED) )
637 mbedtls_snprintf( buf, buflen, "BLOWFISH - Blowfish hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200638 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
639 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
640#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker83f00bb2012-07-04 11:08:50 +0000641
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200642#if defined(MBEDTLS_CAMELLIA_C)
643 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
644 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
645 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
646 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100647 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED) )
648 mbedtls_snprintf( buf, buflen, "CAMELLIA - Camellia hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200649#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000650
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200651#if defined(MBEDTLS_CCM_C)
652 if( use_ret == -(MBEDTLS_ERR_CCM_BAD_INPUT) )
Rose Zadikeecdbea2018-01-24 12:56:53 +0000653 mbedtls_snprintf( buf, buflen, "CCM - Bad input parameters to the function" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200654 if( use_ret == -(MBEDTLS_ERR_CCM_AUTH_FAILED) )
655 mbedtls_snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100656 if( use_ret == -(MBEDTLS_ERR_CCM_HW_ACCEL_FAILED) )
657 mbedtls_snprintf( buf, buflen, "CCM - CCM hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200658#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200659
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100660#if defined(MBEDTLS_CMAC_C)
661 if( use_ret == -(MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED) )
662 mbedtls_snprintf( buf, buflen, "CMAC - CMAC hardware accelerator failed" );
663#endif /* MBEDTLS_CMAC_C */
664
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200665#if defined(MBEDTLS_CTR_DRBG_C)
666 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
667 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
668 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000669 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The requested random buffer length is too big" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200670 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000671 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The input (entropy + additional data) is too large" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200672 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000673 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Read or write error in file" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200674#endif /* MBEDTLS_CTR_DRBG_C */
Paul Bakker880ac7e2011-11-27 14:50:49 +0000675
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200676#if defined(MBEDTLS_DES_C)
677 if( use_ret == -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH) )
678 mbedtls_snprintf( buf, buflen, "DES - The data input has an invalid length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100679 if( use_ret == -(MBEDTLS_ERR_DES_HW_ACCEL_FAILED) )
680 mbedtls_snprintf( buf, buflen, "DES - DES hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200681#endif /* MBEDTLS_DES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000682
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200683#if defined(MBEDTLS_ENTROPY_C)
684 if( use_ret == -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED) )
685 mbedtls_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
686 if( use_ret == -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES) )
687 mbedtls_snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
688 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED) )
689 mbedtls_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
Manuel Pégourié-Gonnardf9cbd732015-06-22 12:06:50 +0200690 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE) )
691 mbedtls_snprintf( buf, buflen, "ENTROPY - No strong sources have been added to poll" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200692 if( use_ret == -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR) )
693 mbedtls_snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
694#endif /* MBEDTLS_ENTROPY_C */
Paul Bakker6083fd22011-12-03 21:45:14 +0000695
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200696#if defined(MBEDTLS_GCM_C)
697 if( use_ret == -(MBEDTLS_ERR_GCM_AUTH_FAILED) )
698 mbedtls_snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100699 if( use_ret == -(MBEDTLS_ERR_GCM_HW_ACCEL_FAILED) )
700 mbedtls_snprintf( buf, buflen, "GCM - GCM hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200701 if( use_ret == -(MBEDTLS_ERR_GCM_BAD_INPUT) )
702 mbedtls_snprintf( buf, buflen, "GCM - Bad input parameters to function" );
703#endif /* MBEDTLS_GCM_C */
Paul Bakker030277a2012-04-17 12:24:26 +0000704
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200705#if defined(MBEDTLS_HMAC_DRBG_C)
706 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
707 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
708 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
709 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
710 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR) )
711 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
712 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
713 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
714#endif /* MBEDTLS_HMAC_DRBG_C */
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100715
Gilles Peskinea381fe82018-01-23 18:16:11 +0100716#if defined(MBEDTLS_MD2_C)
717 if( use_ret == -(MBEDTLS_ERR_MD2_HW_ACCEL_FAILED) )
718 mbedtls_snprintf( buf, buflen, "MD2 - MD2 hardware accelerator failed" );
719#endif /* MBEDTLS_MD2_C */
720
721#if defined(MBEDTLS_MD4_C)
722 if( use_ret == -(MBEDTLS_ERR_MD4_HW_ACCEL_FAILED) )
723 mbedtls_snprintf( buf, buflen, "MD4 - MD4 hardware accelerator failed" );
724#endif /* MBEDTLS_MD4_C */
725
726#if defined(MBEDTLS_MD5_C)
727 if( use_ret == -(MBEDTLS_ERR_MD5_HW_ACCEL_FAILED) )
728 mbedtls_snprintf( buf, buflen, "MD5 - MD5 hardware accelerator failed" );
729#endif /* MBEDTLS_MD5_C */
730
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200731#if defined(MBEDTLS_NET_C)
732 if( use_ret == -(MBEDTLS_ERR_NET_SOCKET_FAILED) )
733 mbedtls_snprintf( buf, buflen, "NET - Failed to open a socket" );
734 if( use_ret == -(MBEDTLS_ERR_NET_CONNECT_FAILED) )
735 mbedtls_snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
736 if( use_ret == -(MBEDTLS_ERR_NET_BIND_FAILED) )
737 mbedtls_snprintf( buf, buflen, "NET - Binding of the socket failed" );
738 if( use_ret == -(MBEDTLS_ERR_NET_LISTEN_FAILED) )
739 mbedtls_snprintf( buf, buflen, "NET - Could not listen on the socket" );
740 if( use_ret == -(MBEDTLS_ERR_NET_ACCEPT_FAILED) )
741 mbedtls_snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
742 if( use_ret == -(MBEDTLS_ERR_NET_RECV_FAILED) )
743 mbedtls_snprintf( buf, buflen, "NET - Reading information from the socket failed" );
744 if( use_ret == -(MBEDTLS_ERR_NET_SEND_FAILED) )
745 mbedtls_snprintf( buf, buflen, "NET - Sending information through the socket failed" );
746 if( use_ret == -(MBEDTLS_ERR_NET_CONN_RESET) )
747 mbedtls_snprintf( buf, buflen, "NET - Connection was reset by peer" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200748 if( use_ret == -(MBEDTLS_ERR_NET_UNKNOWN_HOST) )
749 mbedtls_snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
Manuel Pégourié-Gonnard0b104b02015-05-14 21:52:40 +0200750 if( use_ret == -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL) )
751 mbedtls_snprintf( buf, buflen, "NET - Buffer is too small to hold the data" );
Manuel Pégourié-Gonnard9bd0afd2015-07-01 19:03:27 +0200752 if( use_ret == -(MBEDTLS_ERR_NET_INVALID_CONTEXT) )
753 mbedtls_snprintf( buf, buflen, "NET - The context is invalid, eg because it was free()ed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200754#endif /* MBEDTLS_NET_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000755
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200756#if defined(MBEDTLS_OID_C)
757 if( use_ret == -(MBEDTLS_ERR_OID_NOT_FOUND) )
758 mbedtls_snprintf( buf, buflen, "OID - OID is not found" );
759 if( use_ret == -(MBEDTLS_ERR_OID_BUF_TOO_SMALL) )
760 mbedtls_snprintf( buf, buflen, "OID - output buffer is too small" );
761#endif /* MBEDTLS_OID_C */
Paul Bakkerc70b9822013-04-07 22:00:46 +0200762
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200763#if defined(MBEDTLS_PADLOCK_C)
764 if( use_ret == -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED) )
765 mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
766#endif /* MBEDTLS_PADLOCK_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000767
Gilles Peskinea381fe82018-01-23 18:16:11 +0100768#if defined(MBEDTLS_RIPEMD160_C)
769 if( use_ret == -(MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED) )
770 mbedtls_snprintf( buf, buflen, "RIPEMD160 - RIPEMD160 hardware accelerator failed" );
771#endif /* MBEDTLS_RIPEMD160_C */
772
773#if defined(MBEDTLS_SHA1_C)
774 if( use_ret == -(MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED) )
775 mbedtls_snprintf( buf, buflen, "SHA1 - SHA-1 hardware accelerator failed" );
776#endif /* MBEDTLS_SHA1_C */
777
778#if defined(MBEDTLS_SHA256_C)
779 if( use_ret == -(MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED) )
780 mbedtls_snprintf( buf, buflen, "SHA256 - SHA-256 hardware accelerator failed" );
781#endif /* MBEDTLS_SHA256_C */
782
783#if defined(MBEDTLS_SHA512_C)
784 if( use_ret == -(MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED) )
785 mbedtls_snprintf( buf, buflen, "SHA512 - SHA-512 hardware accelerator failed" );
786#endif /* MBEDTLS_SHA512_C */
787
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200788#if defined(MBEDTLS_THREADING_C)
789 if( use_ret == -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE) )
790 mbedtls_snprintf( buf, buflen, "THREADING - The selected feature is not available" );
791 if( use_ret == -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA) )
792 mbedtls_snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
793 if( use_ret == -(MBEDTLS_ERR_THREADING_MUTEX_ERROR) )
794 mbedtls_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
795#endif /* MBEDTLS_THREADING_C */
Paul Bakker2466d932013-09-28 14:40:38 +0200796
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200797#if defined(MBEDTLS_XTEA_C)
798 if( use_ret == -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH) )
799 mbedtls_snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100800 if( use_ret == -(MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED) )
801 mbedtls_snprintf( buf, buflen, "XTEA - XTEA hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200802#endif /* MBEDTLS_XTEA_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200803 // END generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000804
805 if( strlen( buf ) != 0 )
806 return;
807
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200808 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000809}
810
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200811#else /* MBEDTLS_ERROR_C */
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100812
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200813#if defined(MBEDTLS_ERROR_STRERROR_DUMMY)
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100814
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100815/*
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200816 * Provide an non-function in case MBEDTLS_ERROR_C is not defined
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100817 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200818void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100819{
820 ((void) ret);
821
822 if( buflen > 0 )
823 buf[0] = '\0';
824}
825
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200826#endif /* MBEDTLS_ERROR_STRERROR_DUMMY */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200827
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200828#endif /* MBEDTLS_ERROR_C */