blob: d9c3971cddff7122f30fa7dd93408cdaec43ae9c [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
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020048#if defined(MBEDTLS_BASE64_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000049#include "mbedtls/base64.h"
Paul Bakker9d781402011-05-09 16:17:09 +000050#endif
51
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052#if defined(MBEDTLS_BIGNUM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000053#include "mbedtls/bignum.h"
Paul Bakker9d781402011-05-09 16:17:09 +000054#endif
55
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000057#include "mbedtls/blowfish.h"
Paul Bakker83f00bb2012-07-04 11:08:50 +000058#endif
59
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000061#include "mbedtls/camellia.h"
Paul Bakker9d781402011-05-09 16:17:09 +000062#endif
63
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000065#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +020066#endif
67
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068#if defined(MBEDTLS_CIPHER_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000069#include "mbedtls/cipher.h"
Paul Bakkerff61a782011-06-09 15:42:02 +000070#endif
71
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020072#if defined(MBEDTLS_CTR_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000073#include "mbedtls/ctr_drbg.h"
Paul Bakker880ac7e2011-11-27 14:50:49 +000074#endif
75
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020076#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000077#include "mbedtls/des.h"
Paul Bakker9d781402011-05-09 16:17:09 +000078#endif
79
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020080#if defined(MBEDTLS_DHM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000081#include "mbedtls/dhm.h"
Paul Bakker9d781402011-05-09 16:17:09 +000082#endif
83
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020084#if defined(MBEDTLS_ECP_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000085#include "mbedtls/ecp.h"
Paul Bakkercf4365f2013-01-16 17:00:43 +010086#endif
87
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020088#if defined(MBEDTLS_ENTROPY_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000089#include "mbedtls/entropy.h"
Paul Bakker6083fd22011-12-03 21:45:14 +000090#endif
91
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000093#include "mbedtls/gcm.h"
Paul Bakker030277a2012-04-17 12:24:26 +000094#endif
95
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096#if defined(MBEDTLS_HMAC_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000097#include "mbedtls/hmac_drbg.h"
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010098#endif
99
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200100#if defined(MBEDTLS_MD_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000101#include "mbedtls/md.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000102#endif
103
Gilles Peskinea381fe82018-01-23 18:16:11 +0100104#if defined(MBEDTLS_MD2_C)
105#include "mbedtls/md2.h"
106#endif
107
108#if defined(MBEDTLS_MD4_C)
109#include "mbedtls/md4.h"
110#endif
111
112#if defined(MBEDTLS_MD5_C)
113#include "mbedtls/md5.h"
114#endif
115
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200116#if defined(MBEDTLS_NET_C)
Andres AG3616f6f2016-09-14 14:32:09 +0100117#include "mbedtls/net_sockets.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000118#endif
119
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200120#if defined(MBEDTLS_OID_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000121#include "mbedtls/oid.h"
Paul Bakkerc70b9822013-04-07 22:00:46 +0200122#endif
123
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124#if defined(MBEDTLS_PADLOCK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000125#include "mbedtls/padlock.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000126#endif
127
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000129#include "mbedtls/pem.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000130#endif
131
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200132#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000133#include "mbedtls/pk.h"
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200134#endif
135
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200136#if defined(MBEDTLS_PKCS12_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000137#include "mbedtls/pkcs12.h"
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200138#endif
139
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140#if defined(MBEDTLS_PKCS5_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000141#include "mbedtls/pkcs5.h"
Paul Bakkerb0c19a42013-06-24 19:26:38 +0200142#endif
143
Gilles Peskinea381fe82018-01-23 18:16:11 +0100144#if defined(MBEDTLS_RIPEMD160_C)
145#include "mbedtls/ripemd160.h"
146#endif
147
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200148#if defined(MBEDTLS_RSA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000149#include "mbedtls/rsa.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000150#endif
151
Gilles Peskinea381fe82018-01-23 18:16:11 +0100152#if defined(MBEDTLS_SHA1_C)
153#include "mbedtls/sha1.h"
154#endif
155
156#if defined(MBEDTLS_SHA256_C)
157#include "mbedtls/sha256.h"
158#endif
159
160#if defined(MBEDTLS_SHA512_C)
161#include "mbedtls/sha512.h"
162#endif
163
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200164#if defined(MBEDTLS_SSL_TLS_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000165#include "mbedtls/ssl.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000166#endif
167
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200168#if defined(MBEDTLS_THREADING_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000169#include "mbedtls/threading.h"
Paul Bakker2466d932013-09-28 14:40:38 +0200170#endif
171
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200172#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000173#include "mbedtls/x509.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000174#endif
175
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200176#if defined(MBEDTLS_XTEA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000177#include "mbedtls/xtea.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000178#endif
179
Paul Bakkerdceecd82011-11-15 16:38:34 +0000180
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200181void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker9d781402011-05-09 16:17:09 +0000182{
183 size_t len;
184 int use_ret;
185
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200186 if( buflen == 0 )
187 return;
188
Paul Bakker9d781402011-05-09 16:17:09 +0000189 memset( buf, 0x00, buflen );
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200190
Paul Bakker9d781402011-05-09 16:17:09 +0000191 if( ret < 0 )
192 ret = -ret;
193
194 if( ret & 0xFF80 )
195 {
196 use_ret = ret & 0xFF80;
197
198 // High level error codes
199 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200200 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200201#if defined(MBEDTLS_CIPHER_C)
202 if( use_ret == -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE) )
203 mbedtls_snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
204 if( use_ret == -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA) )
205 mbedtls_snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
206 if( use_ret == -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED) )
207 mbedtls_snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
208 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_PADDING) )
209 mbedtls_snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
210 if( use_ret == -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
211 mbedtls_snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
212 if( use_ret == -(MBEDTLS_ERR_CIPHER_AUTH_FAILED) )
213 mbedtls_snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
Janos Follath98e28a72016-05-31 14:03:54 +0100214 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT) )
215 mbedtls_snprintf( buf, buflen, "CIPHER - The context is invalid, eg because it was free()ed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200216#endif /* MBEDTLS_CIPHER_C */
Paul Bakkerff61a782011-06-09 15:42:02 +0000217
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200218#if defined(MBEDTLS_DHM_C)
219 if( use_ret == -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA) )
220 mbedtls_snprintf( buf, buflen, "DHM - Bad input parameters to function" );
221 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED) )
222 mbedtls_snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
223 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED) )
224 mbedtls_snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
225 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED) )
226 mbedtls_snprintf( buf, buflen, "DHM - Reading of the public values failed" );
227 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED) )
228 mbedtls_snprintf( buf, buflen, "DHM - Making of the public value failed" );
229 if( use_ret == -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED) )
230 mbedtls_snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
231 if( use_ret == -(MBEDTLS_ERR_DHM_INVALID_FORMAT) )
232 mbedtls_snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200233 if( use_ret == -(MBEDTLS_ERR_DHM_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200234 mbedtls_snprintf( buf, buflen, "DHM - Allocation of memory failed" );
235 if( use_ret == -(MBEDTLS_ERR_DHM_FILE_IO_ERROR) )
236 mbedtls_snprintf( buf, buflen, "DHM - Read/write of file failed" );
Hanno Beckera6dd90d2017-10-04 13:15:54 +0100237 if( use_ret == -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED) )
Jaeden Amero784de592018-01-26 17:52:01 +0000238 mbedtls_snprintf( buf, buflen, "DHM - Setting the modulus and generator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200239#endif /* MBEDTLS_DHM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000240
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200241#if defined(MBEDTLS_ECP_C)
242 if( use_ret == -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA) )
243 mbedtls_snprintf( buf, buflen, "ECP - Bad input parameters to function" );
244 if( use_ret == -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL) )
245 mbedtls_snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
246 if( use_ret == -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) )
247 mbedtls_snprintf( buf, buflen, "ECP - Requested curve not available" );
248 if( use_ret == -(MBEDTLS_ERR_ECP_VERIFY_FAILED) )
249 mbedtls_snprintf( buf, buflen, "ECP - The signature is not valid" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200250 if( use_ret == -(MBEDTLS_ERR_ECP_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200251 mbedtls_snprintf( buf, buflen, "ECP - Memory allocation failed" );
252 if( use_ret == -(MBEDTLS_ERR_ECP_RANDOM_FAILED) )
253 mbedtls_snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
254 if( use_ret == -(MBEDTLS_ERR_ECP_INVALID_KEY) )
255 mbedtls_snprintf( buf, buflen, "ECP - Invalid private or public key" );
256 if( use_ret == -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) )
257 mbedtls_snprintf( buf, buflen, "ECP - Signature is valid but shorter than the user-supplied length" );
258#endif /* MBEDTLS_ECP_C */
Paul Bakkercf4365f2013-01-16 17:00:43 +0100259
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200260#if defined(MBEDTLS_MD_C)
261 if( use_ret == -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE) )
262 mbedtls_snprintf( buf, buflen, "MD - The selected feature is not available" );
263 if( use_ret == -(MBEDTLS_ERR_MD_BAD_INPUT_DATA) )
264 mbedtls_snprintf( buf, buflen, "MD - Bad input parameters to function" );
265 if( use_ret == -(MBEDTLS_ERR_MD_ALLOC_FAILED) )
266 mbedtls_snprintf( buf, buflen, "MD - Failed to allocate memory" );
267 if( use_ret == -(MBEDTLS_ERR_MD_FILE_IO_ERROR) )
268 mbedtls_snprintf( buf, buflen, "MD - Opening or reading of file failed" );
269#endif /* MBEDTLS_MD_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000270
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200271#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
272 if( use_ret == -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
273 mbedtls_snprintf( buf, buflen, "PEM - No PEM header or footer found" );
274 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_DATA) )
275 mbedtls_snprintf( buf, buflen, "PEM - PEM string is not as expected" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200276 if( use_ret == -(MBEDTLS_ERR_PEM_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200277 mbedtls_snprintf( buf, buflen, "PEM - Failed to allocate memory" );
278 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_ENC_IV) )
279 mbedtls_snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
280 if( use_ret == -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG) )
281 mbedtls_snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
282 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) )
283 mbedtls_snprintf( buf, buflen, "PEM - Private key password can't be empty" );
284 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) )
285 mbedtls_snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
286 if( use_ret == -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE) )
287 mbedtls_snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
288 if( use_ret == -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA) )
289 mbedtls_snprintf( buf, buflen, "PEM - Bad input parameters to function" );
290#endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000291
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200292#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200293 if( use_ret == -(MBEDTLS_ERR_PK_ALLOC_FAILED) )
Manuel Pégourié-Gonnard41b9c2b2015-05-28 14:56:20 +0200294 mbedtls_snprintf( buf, buflen, "PK - Memory allocation failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200295 if( use_ret == -(MBEDTLS_ERR_PK_TYPE_MISMATCH) )
296 mbedtls_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
297 if( use_ret == -(MBEDTLS_ERR_PK_BAD_INPUT_DATA) )
298 mbedtls_snprintf( buf, buflen, "PK - Bad input parameters to function" );
299 if( use_ret == -(MBEDTLS_ERR_PK_FILE_IO_ERROR) )
300 mbedtls_snprintf( buf, buflen, "PK - Read/write of file failed" );
301 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION) )
302 mbedtls_snprintf( buf, buflen, "PK - Unsupported key version" );
303 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT) )
304 mbedtls_snprintf( buf, buflen, "PK - Invalid key tag or value" );
305 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG) )
306 mbedtls_snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
307 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED) )
308 mbedtls_snprintf( buf, buflen, "PK - Private key password can't be empty" );
309 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH) )
310 mbedtls_snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
311 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_PUBKEY) )
312 mbedtls_snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
313 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_ALG) )
314 mbedtls_snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
315 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE) )
316 mbedtls_snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
317 if( use_ret == -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) )
318 mbedtls_snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
319 if( use_ret == -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH) )
320 mbedtls_snprintf( buf, buflen, "PK - The signature is valid but its length is less than expected" );
321#endif /* MBEDTLS_PK_C */
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200322
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200323#if defined(MBEDTLS_PKCS12_C)
324 if( use_ret == -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA) )
325 mbedtls_snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
326 if( use_ret == -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE) )
327 mbedtls_snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
328 if( use_ret == -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT) )
329 mbedtls_snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
330 if( use_ret == -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) )
331 mbedtls_snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
332#endif /* MBEDTLS_PKCS12_C */
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200333
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200334#if defined(MBEDTLS_PKCS5_C)
335 if( use_ret == -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA) )
336 mbedtls_snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
337 if( use_ret == -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT) )
338 mbedtls_snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
339 if( use_ret == -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE) )
340 mbedtls_snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
341 if( use_ret == -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) )
342 mbedtls_snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
343#endif /* MBEDTLS_PKCS5_C */
Paul Bakker28144de2013-06-24 19:28:55 +0200344
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200345#if defined(MBEDTLS_RSA_C)
346 if( use_ret == -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA) )
347 mbedtls_snprintf( buf, buflen, "RSA - Bad input parameters to function" );
348 if( use_ret == -(MBEDTLS_ERR_RSA_INVALID_PADDING) )
349 mbedtls_snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
350 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED) )
351 mbedtls_snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
352 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED) )
Manuel Pégourié-Gonnardeecb43c2015-05-12 12:56:41 +0200353 mbedtls_snprintf( buf, buflen, "RSA - Key failed to pass the library's validity check" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200354 if( use_ret == -(MBEDTLS_ERR_RSA_PUBLIC_FAILED) )
355 mbedtls_snprintf( buf, buflen, "RSA - The public key operation failed" );
356 if( use_ret == -(MBEDTLS_ERR_RSA_PRIVATE_FAILED) )
357 mbedtls_snprintf( buf, buflen, "RSA - The private key operation failed" );
358 if( use_ret == -(MBEDTLS_ERR_RSA_VERIFY_FAILED) )
359 mbedtls_snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
360 if( use_ret == -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE) )
361 mbedtls_snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
362 if( use_ret == -(MBEDTLS_ERR_RSA_RNG_FAILED) )
363 mbedtls_snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
Hanno Becker3cdc7112017-10-05 10:09:31 +0100364 if( use_ret == -(MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION) )
Hanno Becker1434a362017-12-13 11:24:49 +0000365 mbedtls_snprintf( buf, buflen, "RSA - The implementation doesn't offer the requested operation, e.g. because of security violations or lack of functionality" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200366#endif /* MBEDTLS_RSA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000367
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200368#if defined(MBEDTLS_SSL_TLS_C)
369 if( use_ret == -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE) )
370 mbedtls_snprintf( buf, buflen, "SSL - The requested feature is not available" );
371 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA) )
372 mbedtls_snprintf( buf, buflen, "SSL - Bad input parameters to function" );
373 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_MAC) )
374 mbedtls_snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
375 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_RECORD) )
376 mbedtls_snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
377 if( use_ret == -(MBEDTLS_ERR_SSL_CONN_EOF) )
378 mbedtls_snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
379 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER) )
380 mbedtls_snprintf( buf, buflen, "SSL - An unknown cipher was received" );
381 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN) )
382 mbedtls_snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
383 if( use_ret == -(MBEDTLS_ERR_SSL_NO_RNG) )
384 mbedtls_snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
385 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE) )
386 mbedtls_snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
387 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE) )
388 mbedtls_snprintf( buf, buflen, "SSL - Our own certificate(s) is/are too large to send in an SSL message" );
389 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED) )
390 mbedtls_snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
391 if( use_ret == -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED) )
392 mbedtls_snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
393 if( use_ret == -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED) )
394 mbedtls_snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
395 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE) )
396 mbedtls_snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
397 if( use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE) )
Paul Bakker3aac1da2012-05-08 13:12:27 +0000398 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200399 mbedtls_snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
Paul Bakker3aac1da2012-05-08 13:12:27 +0000400 return;
401 }
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200402 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED) )
403 mbedtls_snprintf( buf, buflen, "SSL - Verification of our peer failed" );
404 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) )
405 mbedtls_snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
406 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO) )
407 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
408 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO) )
409 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
410 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE) )
411 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
412 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
413 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
414 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
415 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
416 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
417 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
418 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
419 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
420 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
421 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
422 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
423 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
424 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
425 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
426 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
427 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
428 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED) )
429 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200430 if( use_ret == -(MBEDTLS_ERR_SSL_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200431 mbedtls_snprintf( buf, buflen, "SSL - Memory allocation failed" );
432 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED) )
433 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
434 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
435 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
436 if( use_ret == -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED) )
437 mbedtls_snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
438 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
439 mbedtls_snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
440 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
441 mbedtls_snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
442 if( use_ret == -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED) )
443 mbedtls_snprintf( buf, buflen, "SSL - Session ticket has expired" );
444 if( use_ret == -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH) )
445 mbedtls_snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
446 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY) )
447 mbedtls_snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
448 if( use_ret == -(MBEDTLS_ERR_SSL_INTERNAL_ERROR) )
449 mbedtls_snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
450 if( use_ret == -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING) )
451 mbedtls_snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
452 if( use_ret == -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO) )
453 mbedtls_snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" );
454 if( use_ret == -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED) )
455 mbedtls_snprintf( buf, buflen, "SSL - DTLS client must retry for hello verification" );
456 if( use_ret == -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL) )
457 mbedtls_snprintf( buf, buflen, "SSL - A buffer is too small to receive or write a message" );
458 if( use_ret == -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE) )
459 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 +0100460 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_READ) )
461 mbedtls_snprintf( buf, buflen, "SSL - Connection requires a read call" );
462 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_WRITE) )
463 mbedtls_snprintf( buf, buflen, "SSL - Connection requires a write call" );
464 if( use_ret == -(MBEDTLS_ERR_SSL_TIMEOUT) )
465 mbedtls_snprintf( buf, buflen, "SSL - The operation timed out" );
Manuel Pégourié-Gonnardbe619c12015-09-08 11:21:21 +0200466 if( use_ret == -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT) )
467 mbedtls_snprintf( buf, buflen, "SSL - The client initiated a reconnect from the same port" );
Manuel Pégourié-Gonnarde2e25e72015-12-03 16:13:17 +0100468 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD) )
469 mbedtls_snprintf( buf, buflen, "SSL - Record header looks valid but is not expected" );
Simon Butcher99000142016-10-13 17:21:01 +0100470 if( use_ret == -(MBEDTLS_ERR_SSL_NON_FATAL) )
471 mbedtls_snprintf( buf, buflen, "SSL - The alert message received indicates a non-fatal error" );
472 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH) )
473 mbedtls_snprintf( buf, buflen, "SSL - Couldn't set the hash for verifying CertificateVerify" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200474#endif /* MBEDTLS_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000475
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200476#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
477 if( use_ret == -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) )
478 mbedtls_snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
479 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_OID) )
480 mbedtls_snprintf( buf, buflen, "X509 - Requested OID is unknown" );
481 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_FORMAT) )
482 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
483 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_VERSION) )
484 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
485 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SERIAL) )
486 mbedtls_snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
487 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_ALG) )
488 mbedtls_snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
489 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_NAME) )
490 mbedtls_snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
491 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_DATE) )
492 mbedtls_snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
493 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SIGNATURE) )
494 mbedtls_snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
495 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS) )
496 mbedtls_snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
497 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_VERSION) )
498 mbedtls_snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
499 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG) )
500 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
501 if( use_ret == -(MBEDTLS_ERR_X509_SIG_MISMATCH) )
502 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" );
503 if( use_ret == -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) )
504 mbedtls_snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
505 if( use_ret == -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT) )
506 mbedtls_snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
507 if( use_ret == -(MBEDTLS_ERR_X509_BAD_INPUT_DATA) )
508 mbedtls_snprintf( buf, buflen, "X509 - Input invalid" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200509 if( use_ret == -(MBEDTLS_ERR_X509_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200510 mbedtls_snprintf( buf, buflen, "X509 - Allocation of memory failed" );
511 if( use_ret == -(MBEDTLS_ERR_X509_FILE_IO_ERROR) )
512 mbedtls_snprintf( buf, buflen, "X509 - Read/write of file failed" );
Manuel Pégourié-Gonnard9dbaf402015-06-22 11:50:58 +0200513 if( use_ret == -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL) )
514 mbedtls_snprintf( buf, buflen, "X509 - Destination buffer is too small" );
Manuel Pégourié-Gonnard31458a12017-06-26 10:11:49 +0200515 if( use_ret == -(MBEDTLS_ERR_X509_FATAL_ERROR) )
516 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 +0200517#endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200518 // END generated code
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200519
Paul Bakker9d781402011-05-09 16:17:09 +0000520 if( strlen( buf ) == 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200521 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000522 }
523
524 use_ret = ret & ~0xFF80;
525
526 if( use_ret == 0 )
527 return;
528
529 // If high level code is present, make a concatenation between both
530 // error strings.
531 //
532 len = strlen( buf );
533
534 if( len > 0 )
535 {
536 if( buflen - len < 5 )
537 return;
538
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200539 mbedtls_snprintf( buf + len, buflen - len, " : " );
Paul Bakker9d781402011-05-09 16:17:09 +0000540
541 buf += len + 3;
542 buflen -= len + 3;
543 }
544
545 // Low level error codes
546 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200547 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200548#if defined(MBEDTLS_AES_C)
549 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH) )
550 mbedtls_snprintf( buf, buflen, "AES - Invalid key length" );
551 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH) )
552 mbedtls_snprintf( buf, buflen, "AES - Invalid data input length" );
Andres Amaya Garciafd487392017-06-14 16:19:12 +0100553 if( use_ret == -(MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE) )
554 mbedtls_snprintf( buf, buflen, "AES - Feature not available, e.g. unsupported AES key size" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200555#endif /* MBEDTLS_AES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000556
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200557#if defined(MBEDTLS_ASN1_PARSE_C)
558 if( use_ret == -(MBEDTLS_ERR_ASN1_OUT_OF_DATA) )
559 mbedtls_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
560 if( use_ret == -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) )
561 mbedtls_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
562 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_LENGTH) )
563 mbedtls_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
564 if( use_ret == -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH) )
565 mbedtls_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
566 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_DATA) )
567 mbedtls_snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200568 if( use_ret == -(MBEDTLS_ERR_ASN1_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200569 mbedtls_snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
570 if( use_ret == -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL) )
571 mbedtls_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
572#endif /* MBEDTLS_ASN1_PARSE_C */
Paul Bakkerdceecd82011-11-15 16:38:34 +0000573
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200574#if defined(MBEDTLS_BASE64_C)
575 if( use_ret == -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) )
576 mbedtls_snprintf( buf, buflen, "BASE64 - Output buffer too small" );
577 if( use_ret == -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER) )
578 mbedtls_snprintf( buf, buflen, "BASE64 - Invalid character in input" );
579#endif /* MBEDTLS_BASE64_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000580
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200581#if defined(MBEDTLS_BIGNUM_C)
582 if( use_ret == -(MBEDTLS_ERR_MPI_FILE_IO_ERROR) )
583 mbedtls_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
584 if( use_ret == -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA) )
585 mbedtls_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
586 if( use_ret == -(MBEDTLS_ERR_MPI_INVALID_CHARACTER) )
587 mbedtls_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
588 if( use_ret == -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL) )
589 mbedtls_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
590 if( use_ret == -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE) )
591 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
592 if( use_ret == -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO) )
593 mbedtls_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
594 if( use_ret == -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) )
595 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200596 if( use_ret == -(MBEDTLS_ERR_MPI_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200597 mbedtls_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
598#endif /* MBEDTLS_BIGNUM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000599
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200600#if defined(MBEDTLS_BLOWFISH_C)
601 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
602 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
603 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
604 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
605#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker83f00bb2012-07-04 11:08:50 +0000606
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200607#if defined(MBEDTLS_CAMELLIA_C)
608 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
609 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
610 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
611 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
612#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000613
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200614#if defined(MBEDTLS_CCM_C)
615 if( use_ret == -(MBEDTLS_ERR_CCM_BAD_INPUT) )
616 mbedtls_snprintf( buf, buflen, "CCM - Bad input parameters to function" );
617 if( use_ret == -(MBEDTLS_ERR_CCM_AUTH_FAILED) )
618 mbedtls_snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
619#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200620
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200621#if defined(MBEDTLS_CTR_DRBG_C)
622 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
623 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
624 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
625 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
626 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG) )
627 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
628 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR) )
629 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
630#endif /* MBEDTLS_CTR_DRBG_C */
Paul Bakker880ac7e2011-11-27 14:50:49 +0000631
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200632#if defined(MBEDTLS_DES_C)
633 if( use_ret == -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH) )
634 mbedtls_snprintf( buf, buflen, "DES - The data input has an invalid length" );
635#endif /* MBEDTLS_DES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000636
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200637#if defined(MBEDTLS_ENTROPY_C)
638 if( use_ret == -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED) )
639 mbedtls_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
640 if( use_ret == -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES) )
641 mbedtls_snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
642 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED) )
643 mbedtls_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
Manuel Pégourié-Gonnardf9cbd732015-06-22 12:06:50 +0200644 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE) )
645 mbedtls_snprintf( buf, buflen, "ENTROPY - No strong sources have been added to poll" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200646 if( use_ret == -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR) )
647 mbedtls_snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
648#endif /* MBEDTLS_ENTROPY_C */
Paul Bakker6083fd22011-12-03 21:45:14 +0000649
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200650#if defined(MBEDTLS_GCM_C)
651 if( use_ret == -(MBEDTLS_ERR_GCM_AUTH_FAILED) )
652 mbedtls_snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
653 if( use_ret == -(MBEDTLS_ERR_GCM_BAD_INPUT) )
654 mbedtls_snprintf( buf, buflen, "GCM - Bad input parameters to function" );
655#endif /* MBEDTLS_GCM_C */
Paul Bakker030277a2012-04-17 12:24:26 +0000656
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200657#if defined(MBEDTLS_HMAC_DRBG_C)
658 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
659 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
660 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
661 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
662 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR) )
663 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
664 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
665 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
666#endif /* MBEDTLS_HMAC_DRBG_C */
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100667
Gilles Peskinea381fe82018-01-23 18:16:11 +0100668#if defined(MBEDTLS_MD2_C)
669 if( use_ret == -(MBEDTLS_ERR_MD2_HW_ACCEL_FAILED) )
670 mbedtls_snprintf( buf, buflen, "MD2 - MD2 hardware accelerator failed" );
671#endif /* MBEDTLS_MD2_C */
672
673#if defined(MBEDTLS_MD4_C)
674 if( use_ret == -(MBEDTLS_ERR_MD4_HW_ACCEL_FAILED) )
675 mbedtls_snprintf( buf, buflen, "MD4 - MD4 hardware accelerator failed" );
676#endif /* MBEDTLS_MD4_C */
677
678#if defined(MBEDTLS_MD5_C)
679 if( use_ret == -(MBEDTLS_ERR_MD5_HW_ACCEL_FAILED) )
680 mbedtls_snprintf( buf, buflen, "MD5 - MD5 hardware accelerator failed" );
681#endif /* MBEDTLS_MD5_C */
682
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200683#if defined(MBEDTLS_NET_C)
684 if( use_ret == -(MBEDTLS_ERR_NET_SOCKET_FAILED) )
685 mbedtls_snprintf( buf, buflen, "NET - Failed to open a socket" );
686 if( use_ret == -(MBEDTLS_ERR_NET_CONNECT_FAILED) )
687 mbedtls_snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
688 if( use_ret == -(MBEDTLS_ERR_NET_BIND_FAILED) )
689 mbedtls_snprintf( buf, buflen, "NET - Binding of the socket failed" );
690 if( use_ret == -(MBEDTLS_ERR_NET_LISTEN_FAILED) )
691 mbedtls_snprintf( buf, buflen, "NET - Could not listen on the socket" );
692 if( use_ret == -(MBEDTLS_ERR_NET_ACCEPT_FAILED) )
693 mbedtls_snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
694 if( use_ret == -(MBEDTLS_ERR_NET_RECV_FAILED) )
695 mbedtls_snprintf( buf, buflen, "NET - Reading information from the socket failed" );
696 if( use_ret == -(MBEDTLS_ERR_NET_SEND_FAILED) )
697 mbedtls_snprintf( buf, buflen, "NET - Sending information through the socket failed" );
698 if( use_ret == -(MBEDTLS_ERR_NET_CONN_RESET) )
699 mbedtls_snprintf( buf, buflen, "NET - Connection was reset by peer" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200700 if( use_ret == -(MBEDTLS_ERR_NET_UNKNOWN_HOST) )
701 mbedtls_snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
Manuel Pégourié-Gonnard0b104b02015-05-14 21:52:40 +0200702 if( use_ret == -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL) )
703 mbedtls_snprintf( buf, buflen, "NET - Buffer is too small to hold the data" );
Manuel Pégourié-Gonnard9bd0afd2015-07-01 19:03:27 +0200704 if( use_ret == -(MBEDTLS_ERR_NET_INVALID_CONTEXT) )
705 mbedtls_snprintf( buf, buflen, "NET - The context is invalid, eg because it was free()ed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200706#endif /* MBEDTLS_NET_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000707
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200708#if defined(MBEDTLS_OID_C)
709 if( use_ret == -(MBEDTLS_ERR_OID_NOT_FOUND) )
710 mbedtls_snprintf( buf, buflen, "OID - OID is not found" );
711 if( use_ret == -(MBEDTLS_ERR_OID_BUF_TOO_SMALL) )
712 mbedtls_snprintf( buf, buflen, "OID - output buffer is too small" );
713#endif /* MBEDTLS_OID_C */
Paul Bakkerc70b9822013-04-07 22:00:46 +0200714
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200715#if defined(MBEDTLS_PADLOCK_C)
716 if( use_ret == -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED) )
717 mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
718#endif /* MBEDTLS_PADLOCK_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000719
Gilles Peskinea381fe82018-01-23 18:16:11 +0100720#if defined(MBEDTLS_RIPEMD160_C)
721 if( use_ret == -(MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED) )
722 mbedtls_snprintf( buf, buflen, "RIPEMD160 - RIPEMD160 hardware accelerator failed" );
723#endif /* MBEDTLS_RIPEMD160_C */
724
725#if defined(MBEDTLS_SHA1_C)
726 if( use_ret == -(MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED) )
727 mbedtls_snprintf( buf, buflen, "SHA1 - SHA-1 hardware accelerator failed" );
728#endif /* MBEDTLS_SHA1_C */
729
730#if defined(MBEDTLS_SHA256_C)
731 if( use_ret == -(MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED) )
732 mbedtls_snprintf( buf, buflen, "SHA256 - SHA-256 hardware accelerator failed" );
733#endif /* MBEDTLS_SHA256_C */
734
735#if defined(MBEDTLS_SHA512_C)
736 if( use_ret == -(MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED) )
737 mbedtls_snprintf( buf, buflen, "SHA512 - SHA-512 hardware accelerator failed" );
738#endif /* MBEDTLS_SHA512_C */
739
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200740#if defined(MBEDTLS_THREADING_C)
741 if( use_ret == -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE) )
742 mbedtls_snprintf( buf, buflen, "THREADING - The selected feature is not available" );
743 if( use_ret == -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA) )
744 mbedtls_snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
745 if( use_ret == -(MBEDTLS_ERR_THREADING_MUTEX_ERROR) )
746 mbedtls_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
747#endif /* MBEDTLS_THREADING_C */
Paul Bakker2466d932013-09-28 14:40:38 +0200748
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200749#if defined(MBEDTLS_XTEA_C)
750 if( use_ret == -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH) )
751 mbedtls_snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
752#endif /* MBEDTLS_XTEA_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200753 // END generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000754
755 if( strlen( buf ) != 0 )
756 return;
757
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200758 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000759}
760
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200761#else /* MBEDTLS_ERROR_C */
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100762
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200763#if defined(MBEDTLS_ERROR_STRERROR_DUMMY)
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100764
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100765/*
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200766 * Provide an non-function in case MBEDTLS_ERROR_C is not defined
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100767 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200768void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100769{
770 ((void) ret);
771
772 if( buflen > 0 )
773 buf[0] = '\0';
774}
775
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200776#endif /* MBEDTLS_ERROR_STRERROR_DUMMY */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200777
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200778#endif /* MBEDTLS_ERROR_C */