blob: a1cf83aed44d931f3d9982402423188e7bf22f30 [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
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020037#endif
38
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020039#if defined(MBEDTLS_ERROR_C)
Paul Bakker3c2122f2013-06-24 19:03:14 +020040
Rich Evans00ab4702015-02-06 13:43:58 +000041#include <stdio.h>
42
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020043#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000044#include "mbedtls/aes.h"
Paul Bakker9d781402011-05-09 16:17:09 +000045#endif
46
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020047#if defined(MBEDTLS_BASE64_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000048#include "mbedtls/base64.h"
Paul Bakker9d781402011-05-09 16:17:09 +000049#endif
50
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020051#if defined(MBEDTLS_BIGNUM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000052#include "mbedtls/bignum.h"
Paul Bakker9d781402011-05-09 16:17:09 +000053#endif
54
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000056#include "mbedtls/blowfish.h"
Paul Bakker83f00bb2012-07-04 11:08:50 +000057#endif
58
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000060#include "mbedtls/camellia.h"
Paul Bakker9d781402011-05-09 16:17:09 +000061#endif
62
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000064#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +020065#endif
66
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020067#if defined(MBEDTLS_CIPHER_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000068#include "mbedtls/cipher.h"
Paul Bakkerff61a782011-06-09 15:42:02 +000069#endif
70
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020071#if defined(MBEDTLS_CTR_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000072#include "mbedtls/ctr_drbg.h"
Paul Bakker880ac7e2011-11-27 14:50:49 +000073#endif
74
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000076#include "mbedtls/des.h"
Paul Bakker9d781402011-05-09 16:17:09 +000077#endif
78
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020079#if defined(MBEDTLS_DHM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000080#include "mbedtls/dhm.h"
Paul Bakker9d781402011-05-09 16:17:09 +000081#endif
82
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083#if defined(MBEDTLS_ECP_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000084#include "mbedtls/ecp.h"
Paul Bakkercf4365f2013-01-16 17:00:43 +010085#endif
86
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020087#if defined(MBEDTLS_ENTROPY_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000088#include "mbedtls/entropy.h"
Paul Bakker6083fd22011-12-03 21:45:14 +000089#endif
90
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020091#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000092#include "mbedtls/gcm.h"
Paul Bakker030277a2012-04-17 12:24:26 +000093#endif
94
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020095#if defined(MBEDTLS_HMAC_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000096#include "mbedtls/hmac_drbg.h"
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +010097#endif
98
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020099#if defined(MBEDTLS_MD_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000100#include "mbedtls/md.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000101#endif
102
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200103#if defined(MBEDTLS_NET_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000104#include "mbedtls/net.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000105#endif
106
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200107#if defined(MBEDTLS_OID_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000108#include "mbedtls/oid.h"
Paul Bakkerc70b9822013-04-07 22:00:46 +0200109#endif
110
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200111#if defined(MBEDTLS_PADLOCK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000112#include "mbedtls/padlock.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000113#endif
114
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200115#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000116#include "mbedtls/pem.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000117#endif
118
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200119#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000120#include "mbedtls/pk.h"
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200121#endif
122
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200123#if defined(MBEDTLS_PKCS12_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000124#include "mbedtls/pkcs12.h"
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200125#endif
126
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127#if defined(MBEDTLS_PKCS5_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000128#include "mbedtls/pkcs5.h"
Paul Bakkerb0c19a42013-06-24 19:26:38 +0200129#endif
130
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131#if defined(MBEDTLS_RSA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000132#include "mbedtls/rsa.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000133#endif
134
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200135#if defined(MBEDTLS_SSL_TLS_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000136#include "mbedtls/ssl.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000137#endif
138
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200139#if defined(MBEDTLS_THREADING_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000140#include "mbedtls/threading.h"
Paul Bakker2466d932013-09-28 14:40:38 +0200141#endif
142
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200143#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000144#include "mbedtls/x509.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000145#endif
146
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200147#if defined(MBEDTLS_XTEA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000148#include "mbedtls/xtea.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000149#endif
150
Paul Bakkerdceecd82011-11-15 16:38:34 +0000151
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200152void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker9d781402011-05-09 16:17:09 +0000153{
154 size_t len;
155 int use_ret;
156
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200157 if( buflen == 0 )
158 return;
159
Paul Bakker9d781402011-05-09 16:17:09 +0000160 memset( buf, 0x00, buflen );
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200161
Paul Bakker9d781402011-05-09 16:17:09 +0000162 if( ret < 0 )
163 ret = -ret;
164
165 if( ret & 0xFF80 )
166 {
167 use_ret = ret & 0xFF80;
168
169 // High level error codes
170 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200171 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200172#if defined(MBEDTLS_CIPHER_C)
173 if( use_ret == -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE) )
174 mbedtls_snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
175 if( use_ret == -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA) )
176 mbedtls_snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
177 if( use_ret == -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED) )
178 mbedtls_snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
179 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_PADDING) )
180 mbedtls_snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
181 if( use_ret == -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
182 mbedtls_snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
183 if( use_ret == -(MBEDTLS_ERR_CIPHER_AUTH_FAILED) )
184 mbedtls_snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
185#endif /* MBEDTLS_CIPHER_C */
Paul Bakkerff61a782011-06-09 15:42:02 +0000186
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200187#if defined(MBEDTLS_DHM_C)
188 if( use_ret == -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA) )
189 mbedtls_snprintf( buf, buflen, "DHM - Bad input parameters to function" );
190 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED) )
191 mbedtls_snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
192 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED) )
193 mbedtls_snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
194 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED) )
195 mbedtls_snprintf( buf, buflen, "DHM - Reading of the public values failed" );
196 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED) )
197 mbedtls_snprintf( buf, buflen, "DHM - Making of the public value failed" );
198 if( use_ret == -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED) )
199 mbedtls_snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
200 if( use_ret == -(MBEDTLS_ERR_DHM_INVALID_FORMAT) )
201 mbedtls_snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200202 if( use_ret == -(MBEDTLS_ERR_DHM_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200203 mbedtls_snprintf( buf, buflen, "DHM - Allocation of memory failed" );
204 if( use_ret == -(MBEDTLS_ERR_DHM_FILE_IO_ERROR) )
205 mbedtls_snprintf( buf, buflen, "DHM - Read/write of file failed" );
206#endif /* MBEDTLS_DHM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000207
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200208#if defined(MBEDTLS_ECP_C)
209 if( use_ret == -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA) )
210 mbedtls_snprintf( buf, buflen, "ECP - Bad input parameters to function" );
211 if( use_ret == -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL) )
212 mbedtls_snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
213 if( use_ret == -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) )
214 mbedtls_snprintf( buf, buflen, "ECP - Requested curve not available" );
215 if( use_ret == -(MBEDTLS_ERR_ECP_VERIFY_FAILED) )
216 mbedtls_snprintf( buf, buflen, "ECP - The signature is not valid" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200217 if( use_ret == -(MBEDTLS_ERR_ECP_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200218 mbedtls_snprintf( buf, buflen, "ECP - Memory allocation failed" );
219 if( use_ret == -(MBEDTLS_ERR_ECP_RANDOM_FAILED) )
220 mbedtls_snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
221 if( use_ret == -(MBEDTLS_ERR_ECP_INVALID_KEY) )
222 mbedtls_snprintf( buf, buflen, "ECP - Invalid private or public key" );
223 if( use_ret == -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) )
224 mbedtls_snprintf( buf, buflen, "ECP - Signature is valid but shorter than the user-supplied length" );
225#endif /* MBEDTLS_ECP_C */
Paul Bakkercf4365f2013-01-16 17:00:43 +0100226
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200227#if defined(MBEDTLS_MD_C)
228 if( use_ret == -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE) )
229 mbedtls_snprintf( buf, buflen, "MD - The selected feature is not available" );
230 if( use_ret == -(MBEDTLS_ERR_MD_BAD_INPUT_DATA) )
231 mbedtls_snprintf( buf, buflen, "MD - Bad input parameters to function" );
232 if( use_ret == -(MBEDTLS_ERR_MD_ALLOC_FAILED) )
233 mbedtls_snprintf( buf, buflen, "MD - Failed to allocate memory" );
234 if( use_ret == -(MBEDTLS_ERR_MD_FILE_IO_ERROR) )
235 mbedtls_snprintf( buf, buflen, "MD - Opening or reading of file failed" );
236#endif /* MBEDTLS_MD_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000237
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200238#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
239 if( use_ret == -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
240 mbedtls_snprintf( buf, buflen, "PEM - No PEM header or footer found" );
241 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_DATA) )
242 mbedtls_snprintf( buf, buflen, "PEM - PEM string is not as expected" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200243 if( use_ret == -(MBEDTLS_ERR_PEM_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200244 mbedtls_snprintf( buf, buflen, "PEM - Failed to allocate memory" );
245 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_ENC_IV) )
246 mbedtls_snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
247 if( use_ret == -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG) )
248 mbedtls_snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
249 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) )
250 mbedtls_snprintf( buf, buflen, "PEM - Private key password can't be empty" );
251 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) )
252 mbedtls_snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
253 if( use_ret == -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE) )
254 mbedtls_snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
255 if( use_ret == -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA) )
256 mbedtls_snprintf( buf, buflen, "PEM - Bad input parameters to function" );
257#endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000258
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200259#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200260 if( use_ret == -(MBEDTLS_ERR_PK_ALLOC_FAILED) )
Manuel Pégourié-Gonnard41b9c2b2015-05-28 14:56:20 +0200261 mbedtls_snprintf( buf, buflen, "PK - Memory allocation failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200262 if( use_ret == -(MBEDTLS_ERR_PK_TYPE_MISMATCH) )
263 mbedtls_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
264 if( use_ret == -(MBEDTLS_ERR_PK_BAD_INPUT_DATA) )
265 mbedtls_snprintf( buf, buflen, "PK - Bad input parameters to function" );
266 if( use_ret == -(MBEDTLS_ERR_PK_FILE_IO_ERROR) )
267 mbedtls_snprintf( buf, buflen, "PK - Read/write of file failed" );
268 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION) )
269 mbedtls_snprintf( buf, buflen, "PK - Unsupported key version" );
270 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT) )
271 mbedtls_snprintf( buf, buflen, "PK - Invalid key tag or value" );
272 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG) )
273 mbedtls_snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
274 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED) )
275 mbedtls_snprintf( buf, buflen, "PK - Private key password can't be empty" );
276 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH) )
277 mbedtls_snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
278 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_PUBKEY) )
279 mbedtls_snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
280 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_ALG) )
281 mbedtls_snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
282 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE) )
283 mbedtls_snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
284 if( use_ret == -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) )
285 mbedtls_snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
286 if( use_ret == -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH) )
287 mbedtls_snprintf( buf, buflen, "PK - The signature is valid but its length is less than expected" );
288#endif /* MBEDTLS_PK_C */
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200289
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200290#if defined(MBEDTLS_PKCS12_C)
291 if( use_ret == -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA) )
292 mbedtls_snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
293 if( use_ret == -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE) )
294 mbedtls_snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
295 if( use_ret == -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT) )
296 mbedtls_snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
297 if( use_ret == -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) )
298 mbedtls_snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
299#endif /* MBEDTLS_PKCS12_C */
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200300
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200301#if defined(MBEDTLS_PKCS5_C)
302 if( use_ret == -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA) )
303 mbedtls_snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
304 if( use_ret == -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT) )
305 mbedtls_snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
306 if( use_ret == -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE) )
307 mbedtls_snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
308 if( use_ret == -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) )
309 mbedtls_snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
310#endif /* MBEDTLS_PKCS5_C */
Paul Bakker28144de2013-06-24 19:28:55 +0200311
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200312#if defined(MBEDTLS_RSA_C)
313 if( use_ret == -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA) )
314 mbedtls_snprintf( buf, buflen, "RSA - Bad input parameters to function" );
315 if( use_ret == -(MBEDTLS_ERR_RSA_INVALID_PADDING) )
316 mbedtls_snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
317 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED) )
318 mbedtls_snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
319 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED) )
Manuel Pégourié-Gonnardeecb43c2015-05-12 12:56:41 +0200320 mbedtls_snprintf( buf, buflen, "RSA - Key failed to pass the library's validity check" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200321 if( use_ret == -(MBEDTLS_ERR_RSA_PUBLIC_FAILED) )
322 mbedtls_snprintf( buf, buflen, "RSA - The public key operation failed" );
323 if( use_ret == -(MBEDTLS_ERR_RSA_PRIVATE_FAILED) )
324 mbedtls_snprintf( buf, buflen, "RSA - The private key operation failed" );
325 if( use_ret == -(MBEDTLS_ERR_RSA_VERIFY_FAILED) )
326 mbedtls_snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
327 if( use_ret == -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE) )
328 mbedtls_snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
329 if( use_ret == -(MBEDTLS_ERR_RSA_RNG_FAILED) )
330 mbedtls_snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
331#endif /* MBEDTLS_RSA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000332
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200333#if defined(MBEDTLS_SSL_TLS_C)
334 if( use_ret == -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE) )
335 mbedtls_snprintf( buf, buflen, "SSL - The requested feature is not available" );
336 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA) )
337 mbedtls_snprintf( buf, buflen, "SSL - Bad input parameters to function" );
338 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_MAC) )
339 mbedtls_snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
340 if( use_ret == -(MBEDTLS_ERR_SSL_INVALID_RECORD) )
341 mbedtls_snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
342 if( use_ret == -(MBEDTLS_ERR_SSL_CONN_EOF) )
343 mbedtls_snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
344 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER) )
345 mbedtls_snprintf( buf, buflen, "SSL - An unknown cipher was received" );
346 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN) )
347 mbedtls_snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
348 if( use_ret == -(MBEDTLS_ERR_SSL_NO_RNG) )
349 mbedtls_snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
350 if( use_ret == -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE) )
351 mbedtls_snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
352 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE) )
353 mbedtls_snprintf( buf, buflen, "SSL - Our own certificate(s) is/are too large to send in an SSL message" );
354 if( use_ret == -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED) )
355 mbedtls_snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
356 if( use_ret == -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED) )
357 mbedtls_snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
358 if( use_ret == -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED) )
359 mbedtls_snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
360 if( use_ret == -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE) )
361 mbedtls_snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
362 if( use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE) )
Paul Bakker3aac1da2012-05-08 13:12:27 +0000363 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200364 mbedtls_snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
Paul Bakker3aac1da2012-05-08 13:12:27 +0000365 return;
366 }
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200367 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED) )
368 mbedtls_snprintf( buf, buflen, "SSL - Verification of our peer failed" );
369 if( use_ret == -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) )
370 mbedtls_snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
371 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO) )
372 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
373 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO) )
374 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
375 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE) )
376 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
377 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
378 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
379 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
380 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
381 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
382 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
383 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
384 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
385 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
386 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
387 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
388 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
389 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
390 mbedtls_snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
391 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
392 mbedtls_snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
393 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED) )
394 mbedtls_snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200395 if( use_ret == -(MBEDTLS_ERR_SSL_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200396 mbedtls_snprintf( buf, buflen, "SSL - Memory allocation failed" );
397 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED) )
398 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
399 if( use_ret == -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
400 mbedtls_snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
401 if( use_ret == -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED) )
402 mbedtls_snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
403 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
404 mbedtls_snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
405 if( use_ret == -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
406 mbedtls_snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
407 if( use_ret == -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED) )
408 mbedtls_snprintf( buf, buflen, "SSL - Session ticket has expired" );
409 if( use_ret == -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH) )
410 mbedtls_snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
411 if( use_ret == -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY) )
412 mbedtls_snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
413 if( use_ret == -(MBEDTLS_ERR_SSL_INTERNAL_ERROR) )
414 mbedtls_snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
415 if( use_ret == -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING) )
416 mbedtls_snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
417 if( use_ret == -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO) )
418 mbedtls_snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" );
419 if( use_ret == -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED) )
420 mbedtls_snprintf( buf, buflen, "SSL - DTLS client must retry for hello verification" );
421 if( use_ret == -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL) )
422 mbedtls_snprintf( buf, buflen, "SSL - A buffer is too small to receive or write a message" );
423 if( use_ret == -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE) )
424 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 +0100425 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_READ) )
426 mbedtls_snprintf( buf, buflen, "SSL - Connection requires a read call" );
427 if( use_ret == -(MBEDTLS_ERR_SSL_WANT_WRITE) )
428 mbedtls_snprintf( buf, buflen, "SSL - Connection requires a write call" );
429 if( use_ret == -(MBEDTLS_ERR_SSL_TIMEOUT) )
430 mbedtls_snprintf( buf, buflen, "SSL - The operation timed out" );
Manuel Pégourié-Gonnardbe619c12015-09-08 11:21:21 +0200431 if( use_ret == -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT) )
432 mbedtls_snprintf( buf, buflen, "SSL - The client initiated a reconnect from the same port" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200433#endif /* MBEDTLS_SSL_TLS_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000434
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200435#if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
436 if( use_ret == -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE) )
437 mbedtls_snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
438 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_OID) )
439 mbedtls_snprintf( buf, buflen, "X509 - Requested OID is unknown" );
440 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_FORMAT) )
441 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
442 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_VERSION) )
443 mbedtls_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
444 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SERIAL) )
445 mbedtls_snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
446 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_ALG) )
447 mbedtls_snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
448 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_NAME) )
449 mbedtls_snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
450 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_DATE) )
451 mbedtls_snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
452 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_SIGNATURE) )
453 mbedtls_snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
454 if( use_ret == -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS) )
455 mbedtls_snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
456 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_VERSION) )
457 mbedtls_snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
458 if( use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG) )
459 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
460 if( use_ret == -(MBEDTLS_ERR_X509_SIG_MISMATCH) )
461 mbedtls_snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" );
462 if( use_ret == -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) )
463 mbedtls_snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
464 if( use_ret == -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT) )
465 mbedtls_snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
466 if( use_ret == -(MBEDTLS_ERR_X509_BAD_INPUT_DATA) )
467 mbedtls_snprintf( buf, buflen, "X509 - Input invalid" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200468 if( use_ret == -(MBEDTLS_ERR_X509_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200469 mbedtls_snprintf( buf, buflen, "X509 - Allocation of memory failed" );
470 if( use_ret == -(MBEDTLS_ERR_X509_FILE_IO_ERROR) )
471 mbedtls_snprintf( buf, buflen, "X509 - Read/write of file failed" );
Manuel Pégourié-Gonnard9dbaf402015-06-22 11:50:58 +0200472 if( use_ret == -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL) )
473 mbedtls_snprintf( buf, buflen, "X509 - Destination buffer is too small" );
Manuel Pégourié-Gonnarde546ad42015-04-08 20:27:02 +0200474#endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200475 // END generated code
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200476
Paul Bakker9d781402011-05-09 16:17:09 +0000477 if( strlen( buf ) == 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200478 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000479 }
480
481 use_ret = ret & ~0xFF80;
482
483 if( use_ret == 0 )
484 return;
485
486 // If high level code is present, make a concatenation between both
487 // error strings.
488 //
489 len = strlen( buf );
490
491 if( len > 0 )
492 {
493 if( buflen - len < 5 )
494 return;
495
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200496 mbedtls_snprintf( buf + len, buflen - len, " : " );
Paul Bakker9d781402011-05-09 16:17:09 +0000497
498 buf += len + 3;
499 buflen -= len + 3;
500 }
501
502 // Low level error codes
503 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200504 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200505#if defined(MBEDTLS_AES_C)
506 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH) )
507 mbedtls_snprintf( buf, buflen, "AES - Invalid key length" );
508 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH) )
509 mbedtls_snprintf( buf, buflen, "AES - Invalid data input length" );
510#endif /* MBEDTLS_AES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000511
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200512#if defined(MBEDTLS_ASN1_PARSE_C)
513 if( use_ret == -(MBEDTLS_ERR_ASN1_OUT_OF_DATA) )
514 mbedtls_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
515 if( use_ret == -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) )
516 mbedtls_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
517 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_LENGTH) )
518 mbedtls_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
519 if( use_ret == -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH) )
520 mbedtls_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
521 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_DATA) )
522 mbedtls_snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200523 if( use_ret == -(MBEDTLS_ERR_ASN1_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200524 mbedtls_snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
525 if( use_ret == -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL) )
526 mbedtls_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
527#endif /* MBEDTLS_ASN1_PARSE_C */
Paul Bakkerdceecd82011-11-15 16:38:34 +0000528
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200529#if defined(MBEDTLS_BASE64_C)
530 if( use_ret == -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) )
531 mbedtls_snprintf( buf, buflen, "BASE64 - Output buffer too small" );
532 if( use_ret == -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER) )
533 mbedtls_snprintf( buf, buflen, "BASE64 - Invalid character in input" );
534#endif /* MBEDTLS_BASE64_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000535
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200536#if defined(MBEDTLS_BIGNUM_C)
537 if( use_ret == -(MBEDTLS_ERR_MPI_FILE_IO_ERROR) )
538 mbedtls_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
539 if( use_ret == -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA) )
540 mbedtls_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
541 if( use_ret == -(MBEDTLS_ERR_MPI_INVALID_CHARACTER) )
542 mbedtls_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
543 if( use_ret == -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL) )
544 mbedtls_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
545 if( use_ret == -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE) )
546 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
547 if( use_ret == -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO) )
548 mbedtls_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
549 if( use_ret == -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) )
550 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200551 if( use_ret == -(MBEDTLS_ERR_MPI_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200552 mbedtls_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
553#endif /* MBEDTLS_BIGNUM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000554
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200555#if defined(MBEDTLS_BLOWFISH_C)
556 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
557 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
558 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
559 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
560#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker83f00bb2012-07-04 11:08:50 +0000561
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200562#if defined(MBEDTLS_CAMELLIA_C)
563 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
564 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
565 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
566 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
567#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000568
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200569#if defined(MBEDTLS_CCM_C)
570 if( use_ret == -(MBEDTLS_ERR_CCM_BAD_INPUT) )
571 mbedtls_snprintf( buf, buflen, "CCM - Bad input parameters to function" );
572 if( use_ret == -(MBEDTLS_ERR_CCM_AUTH_FAILED) )
573 mbedtls_snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
574#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200575
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200576#if defined(MBEDTLS_CTR_DRBG_C)
577 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
578 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
579 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
580 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
581 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG) )
582 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
583 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR) )
584 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
585#endif /* MBEDTLS_CTR_DRBG_C */
Paul Bakker880ac7e2011-11-27 14:50:49 +0000586
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200587#if defined(MBEDTLS_DES_C)
588 if( use_ret == -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH) )
589 mbedtls_snprintf( buf, buflen, "DES - The data input has an invalid length" );
590#endif /* MBEDTLS_DES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000591
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200592#if defined(MBEDTLS_ENTROPY_C)
593 if( use_ret == -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED) )
594 mbedtls_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
595 if( use_ret == -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES) )
596 mbedtls_snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
597 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED) )
598 mbedtls_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
Manuel Pégourié-Gonnardf9cbd732015-06-22 12:06:50 +0200599 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE) )
600 mbedtls_snprintf( buf, buflen, "ENTROPY - No strong sources have been added to poll" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200601 if( use_ret == -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR) )
602 mbedtls_snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
603#endif /* MBEDTLS_ENTROPY_C */
Paul Bakker6083fd22011-12-03 21:45:14 +0000604
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200605#if defined(MBEDTLS_GCM_C)
606 if( use_ret == -(MBEDTLS_ERR_GCM_AUTH_FAILED) )
607 mbedtls_snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
608 if( use_ret == -(MBEDTLS_ERR_GCM_BAD_INPUT) )
609 mbedtls_snprintf( buf, buflen, "GCM - Bad input parameters to function" );
610#endif /* MBEDTLS_GCM_C */
Paul Bakker030277a2012-04-17 12:24:26 +0000611
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200612#if defined(MBEDTLS_HMAC_DRBG_C)
613 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
614 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
615 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
616 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
617 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR) )
618 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
619 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
620 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
621#endif /* MBEDTLS_HMAC_DRBG_C */
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100622
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200623#if defined(MBEDTLS_NET_C)
624 if( use_ret == -(MBEDTLS_ERR_NET_SOCKET_FAILED) )
625 mbedtls_snprintf( buf, buflen, "NET - Failed to open a socket" );
626 if( use_ret == -(MBEDTLS_ERR_NET_CONNECT_FAILED) )
627 mbedtls_snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
628 if( use_ret == -(MBEDTLS_ERR_NET_BIND_FAILED) )
629 mbedtls_snprintf( buf, buflen, "NET - Binding of the socket failed" );
630 if( use_ret == -(MBEDTLS_ERR_NET_LISTEN_FAILED) )
631 mbedtls_snprintf( buf, buflen, "NET - Could not listen on the socket" );
632 if( use_ret == -(MBEDTLS_ERR_NET_ACCEPT_FAILED) )
633 mbedtls_snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
634 if( use_ret == -(MBEDTLS_ERR_NET_RECV_FAILED) )
635 mbedtls_snprintf( buf, buflen, "NET - Reading information from the socket failed" );
636 if( use_ret == -(MBEDTLS_ERR_NET_SEND_FAILED) )
637 mbedtls_snprintf( buf, buflen, "NET - Sending information through the socket failed" );
638 if( use_ret == -(MBEDTLS_ERR_NET_CONN_RESET) )
639 mbedtls_snprintf( buf, buflen, "NET - Connection was reset by peer" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200640 if( use_ret == -(MBEDTLS_ERR_NET_UNKNOWN_HOST) )
641 mbedtls_snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
Manuel Pégourié-Gonnard0b104b02015-05-14 21:52:40 +0200642 if( use_ret == -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL) )
643 mbedtls_snprintf( buf, buflen, "NET - Buffer is too small to hold the data" );
Manuel Pégourié-Gonnard9bd0afd2015-07-01 19:03:27 +0200644 if( use_ret == -(MBEDTLS_ERR_NET_INVALID_CONTEXT) )
645 mbedtls_snprintf( buf, buflen, "NET - The context is invalid, eg because it was free()ed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200646#endif /* MBEDTLS_NET_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000647
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200648#if defined(MBEDTLS_OID_C)
649 if( use_ret == -(MBEDTLS_ERR_OID_NOT_FOUND) )
650 mbedtls_snprintf( buf, buflen, "OID - OID is not found" );
651 if( use_ret == -(MBEDTLS_ERR_OID_BUF_TOO_SMALL) )
652 mbedtls_snprintf( buf, buflen, "OID - output buffer is too small" );
653#endif /* MBEDTLS_OID_C */
Paul Bakkerc70b9822013-04-07 22:00:46 +0200654
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200655#if defined(MBEDTLS_PADLOCK_C)
656 if( use_ret == -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED) )
657 mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
658#endif /* MBEDTLS_PADLOCK_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000659
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200660#if defined(MBEDTLS_THREADING_C)
661 if( use_ret == -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE) )
662 mbedtls_snprintf( buf, buflen, "THREADING - The selected feature is not available" );
663 if( use_ret == -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA) )
664 mbedtls_snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
665 if( use_ret == -(MBEDTLS_ERR_THREADING_MUTEX_ERROR) )
666 mbedtls_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
667#endif /* MBEDTLS_THREADING_C */
Paul Bakker2466d932013-09-28 14:40:38 +0200668
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200669#if defined(MBEDTLS_XTEA_C)
670 if( use_ret == -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH) )
671 mbedtls_snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
672#endif /* MBEDTLS_XTEA_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200673 // END generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000674
675 if( strlen( buf ) != 0 )
676 return;
677
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200678 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000679}
680
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200681#else /* MBEDTLS_ERROR_C */
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100682
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200683#if defined(MBEDTLS_ERROR_STRERROR_DUMMY)
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100684
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100685/*
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200686 * Provide an non-function in case MBEDTLS_ERROR_C is not defined
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100687 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200688void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100689{
690 ((void) ret);
691
692 if( buflen > 0 )
693 buf[0] = '\0';
694}
695
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200696#endif /* MBEDTLS_ERROR_STRERROR_DUMMY */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200697
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200698#endif /* MBEDTLS_ERROR_C */