blob: 85beaeeacc4122f06697d645f8f189c641640165 [file] [log] [blame]
Paul Bakker9d781402011-05-09 16:17:09 +00001/*
2 * Error message information
3 *
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02004 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02005 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
Paul Bakker9d781402011-05-09 16:17:09 +000018 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000019 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker9d781402011-05-09 16:17:09 +000020 */
21
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020022#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000023#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020024#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020025#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020026#endif
Paul Bakker9d781402011-05-09 16:17:09 +000027
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028#if defined(MBEDTLS_ERROR_C) || defined(MBEDTLS_ERROR_STRERROR_DUMMY)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000029#include "mbedtls/error.h"
Rich Evans00ab4702015-02-06 13:43:58 +000030#include <string.h>
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020031#endif
32
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020033#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000034#include "mbedtls/platform.h"
Manuel Pégourié-Gonnard09286402015-02-13 15:18:33 +000035#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020036#define mbedtls_snprintf snprintf
-~- redtangent ~-~9fa2e862016-05-26 10:07:49 +010037#define mbedtls_time_t time_t
Manuel Pégourié-Gonnardbee8ded2014-06-25 12:22:59 +020038#endif
39
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020040#if defined(MBEDTLS_ERROR_C)
Paul Bakker3c2122f2013-06-24 19:03:14 +020041
Rich Evans00ab4702015-02-06 13:43:58 +000042#include <stdio.h>
43
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020044#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000045#include "mbedtls/aes.h"
Paul Bakker9d781402011-05-09 16:17:09 +000046#endif
47
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010048#if defined(MBEDTLS_ARC4_C)
49#include "mbedtls/arc4.h"
50#endif
51
Markku-Juhani O. Saarinen07478d62017-12-01 16:20:15 +000052#if defined(MBEDTLS_ARIA_C)
53#include "mbedtls/aria.h"
54#endif
55
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056#if defined(MBEDTLS_BASE64_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000057#include "mbedtls/base64.h"
Paul Bakker9d781402011-05-09 16:17:09 +000058#endif
59
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060#if defined(MBEDTLS_BIGNUM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000061#include "mbedtls/bignum.h"
Paul Bakker9d781402011-05-09 16:17:09 +000062#endif
63
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000065#include "mbedtls/blowfish.h"
Paul Bakker83f00bb2012-07-04 11:08:50 +000066#endif
67
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000069#include "mbedtls/camellia.h"
Paul Bakker9d781402011-05-09 16:17:09 +000070#endif
71
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020072#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000073#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +020074#endif
75
Daniel King34b822c2016-05-15 17:28:08 -030076#if defined(MBEDTLS_CHACHA20_C)
77#include "mbedtls/chacha20.h"
78#endif
79
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020080#if defined(MBEDTLS_CHACHAPOLY_C)
81#include "mbedtls/chachapoly.h"
82#endif
83
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020084#if defined(MBEDTLS_CIPHER_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000085#include "mbedtls/cipher.h"
Paul Bakkerff61a782011-06-09 15:42:02 +000086#endif
87
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010088#if defined(MBEDTLS_CMAC_C)
89#include "mbedtls/cmac.h"
90#endif
91
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092#if defined(MBEDTLS_CTR_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000093#include "mbedtls/ctr_drbg.h"
Paul Bakker880ac7e2011-11-27 14:50:49 +000094#endif
95
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000097#include "mbedtls/des.h"
Paul Bakker9d781402011-05-09 16:17:09 +000098#endif
99
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200100#if defined(MBEDTLS_DHM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000101#include "mbedtls/dhm.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000102#endif
103
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200104#if defined(MBEDTLS_ECP_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000105#include "mbedtls/ecp.h"
Paul Bakkercf4365f2013-01-16 17:00:43 +0100106#endif
107
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200108#if defined(MBEDTLS_ENTROPY_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000109#include "mbedtls/entropy.h"
Paul Bakker6083fd22011-12-03 21:45:14 +0000110#endif
111
Janos Follath60f6b642019-12-03 15:55:56 +0000112#if defined(MBEDTLS_ERROR_C)
113#include "mbedtls/error.h"
114#endif
115
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200116#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000117#include "mbedtls/gcm.h"
Paul Bakker030277a2012-04-17 12:24:26 +0000118#endif
119
Thomas Fossati656864b2016-07-17 08:51:22 +0100120#if defined(MBEDTLS_HKDF_C)
121#include "mbedtls/hkdf.h"
122#endif
123
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124#if defined(MBEDTLS_HMAC_DRBG_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000125#include "mbedtls/hmac_drbg.h"
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100126#endif
127
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128#if defined(MBEDTLS_MD_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000129#include "mbedtls/md.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000130#endif
131
Gilles Peskinea381fe82018-01-23 18:16:11 +0100132#if defined(MBEDTLS_MD2_C)
133#include "mbedtls/md2.h"
134#endif
135
136#if defined(MBEDTLS_MD4_C)
137#include "mbedtls/md4.h"
138#endif
139
140#if defined(MBEDTLS_MD5_C)
141#include "mbedtls/md5.h"
142#endif
143
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200144#if defined(MBEDTLS_OID_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000145#include "mbedtls/oid.h"
Paul Bakkerc70b9822013-04-07 22:00:46 +0200146#endif
147
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200148#if defined(MBEDTLS_PADLOCK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000149#include "mbedtls/padlock.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000150#endif
151
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200152#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000153#include "mbedtls/pem.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000154#endif
155
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200156#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000157#include "mbedtls/pk.h"
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200158#endif
159
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200160#if defined(MBEDTLS_PKCS12_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000161#include "mbedtls/pkcs12.h"
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200162#endif
163
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200164#if defined(MBEDTLS_PKCS5_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000165#include "mbedtls/pkcs5.h"
Paul Bakkerb0c19a42013-06-24 19:26:38 +0200166#endif
167
Ron Eldor0ff4e0b2018-08-29 18:53:20 +0300168#if defined(MBEDTLS_PLATFORM_C)
169#include "mbedtls/platform.h"
170#endif
171
Daniel Kingadc32c02016-05-16 18:25:45 -0300172#if defined(MBEDTLS_POLY1305_C)
173#include "mbedtls/poly1305.h"
174#endif
175
Gilles Peskinea381fe82018-01-23 18:16:11 +0100176#if defined(MBEDTLS_RIPEMD160_C)
177#include "mbedtls/ripemd160.h"
178#endif
179
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200180#if defined(MBEDTLS_RSA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000181#include "mbedtls/rsa.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000182#endif
183
Gilles Peskinea381fe82018-01-23 18:16:11 +0100184#if defined(MBEDTLS_SHA1_C)
185#include "mbedtls/sha1.h"
186#endif
187
188#if defined(MBEDTLS_SHA256_C)
189#include "mbedtls/sha256.h"
190#endif
191
192#if defined(MBEDTLS_SHA512_C)
193#include "mbedtls/sha512.h"
194#endif
195
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200196#if defined(MBEDTLS_THREADING_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000197#include "mbedtls/threading.h"
Paul Bakker2466d932013-09-28 14:40:38 +0200198#endif
199
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200200#if defined(MBEDTLS_XTEA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000201#include "mbedtls/xtea.h"
Paul Bakker9d781402011-05-09 16:17:09 +0000202#endif
203
Paul Bakkerdceecd82011-11-15 16:38:34 +0000204
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200205void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker9d781402011-05-09 16:17:09 +0000206{
207 size_t len;
208 int use_ret;
209
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200210 if( buflen == 0 )
211 return;
212
Paul Bakker9d781402011-05-09 16:17:09 +0000213 memset( buf, 0x00, buflen );
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200214
Paul Bakker9d781402011-05-09 16:17:09 +0000215 if( ret < 0 )
216 ret = -ret;
217
218 if( ret & 0xFF80 )
219 {
220 use_ret = ret & 0xFF80;
221
222 // High level error codes
223 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200224 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200225#if defined(MBEDTLS_CIPHER_C)
226 if( use_ret == -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE) )
227 mbedtls_snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
228 if( use_ret == -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA) )
Rose Zadik9ba6b622018-01-24 12:59:19 +0000229 mbedtls_snprintf( buf, buflen, "CIPHER - Bad input parameters" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200230 if( use_ret == -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED) )
231 mbedtls_snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
232 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_PADDING) )
233 mbedtls_snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
234 if( use_ret == -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
235 mbedtls_snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
236 if( use_ret == -(MBEDTLS_ERR_CIPHER_AUTH_FAILED) )
237 mbedtls_snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
Janos Follath98e28a72016-05-31 14:03:54 +0100238 if( use_ret == -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT) )
Rose Zadik9ba6b622018-01-24 12:59:19 +0000239 mbedtls_snprintf( buf, buflen, "CIPHER - The context is invalid. For example, because it was freed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100240 if( use_ret == -(MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED) )
241 mbedtls_snprintf( buf, buflen, "CIPHER - Cipher hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200242#endif /* MBEDTLS_CIPHER_C */
Paul Bakkerff61a782011-06-09 15:42:02 +0000243
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200244#if defined(MBEDTLS_DHM_C)
245 if( use_ret == -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA) )
Rose Zadik41ad0822018-01-26 10:54:57 +0000246 mbedtls_snprintf( buf, buflen, "DHM - Bad input parameters" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200247 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED) )
248 mbedtls_snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
249 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED) )
250 mbedtls_snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
251 if( use_ret == -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED) )
252 mbedtls_snprintf( buf, buflen, "DHM - Reading of the public values failed" );
253 if( use_ret == -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED) )
254 mbedtls_snprintf( buf, buflen, "DHM - Making of the public value failed" );
255 if( use_ret == -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED) )
256 mbedtls_snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
257 if( use_ret == -(MBEDTLS_ERR_DHM_INVALID_FORMAT) )
258 mbedtls_snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200259 if( use_ret == -(MBEDTLS_ERR_DHM_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200260 mbedtls_snprintf( buf, buflen, "DHM - Allocation of memory failed" );
261 if( use_ret == -(MBEDTLS_ERR_DHM_FILE_IO_ERROR) )
Rose Zadik41ad0822018-01-26 10:54:57 +0000262 mbedtls_snprintf( buf, buflen, "DHM - Read or write of file failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100263 if( use_ret == -(MBEDTLS_ERR_DHM_HW_ACCEL_FAILED) )
264 mbedtls_snprintf( buf, buflen, "DHM - DHM hardware accelerator failed" );
Hanno Beckera6dd90d2017-10-04 13:15:54 +0100265 if( use_ret == -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED) )
Jaeden Amero784de592018-01-26 17:52:01 +0000266 mbedtls_snprintf( buf, buflen, "DHM - Setting the modulus and generator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200267#endif /* MBEDTLS_DHM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000268
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200269#if defined(MBEDTLS_ECP_C)
270 if( use_ret == -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA) )
271 mbedtls_snprintf( buf, buflen, "ECP - Bad input parameters to function" );
272 if( use_ret == -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL) )
273 mbedtls_snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
274 if( use_ret == -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) )
Jaeden Amero3dd8abd2018-04-24 10:56:55 +0100275 mbedtls_snprintf( buf, buflen, "ECP - The requested feature is not available, for example, the requested curve is not supported" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200276 if( use_ret == -(MBEDTLS_ERR_ECP_VERIFY_FAILED) )
277 mbedtls_snprintf( buf, buflen, "ECP - The signature is not valid" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200278 if( use_ret == -(MBEDTLS_ERR_ECP_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200279 mbedtls_snprintf( buf, buflen, "ECP - Memory allocation failed" );
280 if( use_ret == -(MBEDTLS_ERR_ECP_RANDOM_FAILED) )
Jaeden Amero3dd8abd2018-04-24 10:56:55 +0100281 mbedtls_snprintf( buf, buflen, "ECP - Generation of random value, such as ephemeral key, failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200282 if( use_ret == -(MBEDTLS_ERR_ECP_INVALID_KEY) )
283 mbedtls_snprintf( buf, buflen, "ECP - Invalid private or public key" );
284 if( use_ret == -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) )
Gilles Peskinecc78ac42018-03-30 18:52:10 +0200285 mbedtls_snprintf( buf, buflen, "ECP - The buffer contains a valid signature followed by more data" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100286 if( use_ret == -(MBEDTLS_ERR_ECP_HW_ACCEL_FAILED) )
Jaeden Amero3dd8abd2018-04-24 10:56:55 +0100287 mbedtls_snprintf( buf, buflen, "ECP - The ECP hardware accelerator failed" );
Manuel Pégourié-Gonnard5e3c62f2017-03-08 10:14:11 +0100288 if( use_ret == -(MBEDTLS_ERR_ECP_IN_PROGRESS) )
Manuel Pégourié-Gonnardf0bbd7e2018-10-15 13:22:41 +0200289 mbedtls_snprintf( buf, buflen, "ECP - Operation in progress, call again with the same parameters to continue" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200290#endif /* MBEDTLS_ECP_C */
Paul Bakkercf4365f2013-01-16 17:00:43 +0100291
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200292#if defined(MBEDTLS_MD_C)
293 if( use_ret == -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE) )
294 mbedtls_snprintf( buf, buflen, "MD - The selected feature is not available" );
295 if( use_ret == -(MBEDTLS_ERR_MD_BAD_INPUT_DATA) )
296 mbedtls_snprintf( buf, buflen, "MD - Bad input parameters to function" );
297 if( use_ret == -(MBEDTLS_ERR_MD_ALLOC_FAILED) )
298 mbedtls_snprintf( buf, buflen, "MD - Failed to allocate memory" );
299 if( use_ret == -(MBEDTLS_ERR_MD_FILE_IO_ERROR) )
300 mbedtls_snprintf( buf, buflen, "MD - Opening or reading of file failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100301 if( use_ret == -(MBEDTLS_ERR_MD_HW_ACCEL_FAILED) )
302 mbedtls_snprintf( buf, buflen, "MD - MD hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200303#endif /* MBEDTLS_MD_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000304
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200305#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
306 if( use_ret == -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
307 mbedtls_snprintf( buf, buflen, "PEM - No PEM header or footer found" );
308 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_DATA) )
309 mbedtls_snprintf( buf, buflen, "PEM - PEM string is not as expected" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200310 if( use_ret == -(MBEDTLS_ERR_PEM_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200311 mbedtls_snprintf( buf, buflen, "PEM - Failed to allocate memory" );
312 if( use_ret == -(MBEDTLS_ERR_PEM_INVALID_ENC_IV) )
313 mbedtls_snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
314 if( use_ret == -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG) )
315 mbedtls_snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
316 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) )
317 mbedtls_snprintf( buf, buflen, "PEM - Private key password can't be empty" );
318 if( use_ret == -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) )
319 mbedtls_snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
320 if( use_ret == -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE) )
321 mbedtls_snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
322 if( use_ret == -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA) )
323 mbedtls_snprintf( buf, buflen, "PEM - Bad input parameters to function" );
324#endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000325
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200326#if defined(MBEDTLS_PK_C)
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200327 if( use_ret == -(MBEDTLS_ERR_PK_ALLOC_FAILED) )
Manuel Pégourié-Gonnard41b9c2b2015-05-28 14:56:20 +0200328 mbedtls_snprintf( buf, buflen, "PK - Memory allocation failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200329 if( use_ret == -(MBEDTLS_ERR_PK_TYPE_MISMATCH) )
330 mbedtls_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
331 if( use_ret == -(MBEDTLS_ERR_PK_BAD_INPUT_DATA) )
332 mbedtls_snprintf( buf, buflen, "PK - Bad input parameters to function" );
333 if( use_ret == -(MBEDTLS_ERR_PK_FILE_IO_ERROR) )
334 mbedtls_snprintf( buf, buflen, "PK - Read/write of file failed" );
335 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION) )
336 mbedtls_snprintf( buf, buflen, "PK - Unsupported key version" );
337 if( use_ret == -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT) )
338 mbedtls_snprintf( buf, buflen, "PK - Invalid key tag or value" );
339 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG) )
340 mbedtls_snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
341 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED) )
342 mbedtls_snprintf( buf, buflen, "PK - Private key password can't be empty" );
343 if( use_ret == -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH) )
344 mbedtls_snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
345 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_PUBKEY) )
346 mbedtls_snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
347 if( use_ret == -(MBEDTLS_ERR_PK_INVALID_ALG) )
348 mbedtls_snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
349 if( use_ret == -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE) )
350 mbedtls_snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
351 if( use_ret == -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) )
352 mbedtls_snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
353 if( use_ret == -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH) )
Gilles Peskinecc78ac42018-03-30 18:52:10 +0200354 mbedtls_snprintf( buf, buflen, "PK - The buffer contains a valid signature followed by more data" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100355 if( use_ret == -(MBEDTLS_ERR_PK_HW_ACCEL_FAILED) )
356 mbedtls_snprintf( buf, buflen, "PK - PK hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200357#endif /* MBEDTLS_PK_C */
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +0200358
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200359#if defined(MBEDTLS_PKCS12_C)
360 if( use_ret == -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA) )
361 mbedtls_snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
362 if( use_ret == -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE) )
363 mbedtls_snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
364 if( use_ret == -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT) )
365 mbedtls_snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
366 if( use_ret == -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) )
367 mbedtls_snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
368#endif /* MBEDTLS_PKCS12_C */
Paul Bakkerf1f21fe2013-06-24 19:17:19 +0200369
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200370#if defined(MBEDTLS_PKCS5_C)
371 if( use_ret == -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA) )
372 mbedtls_snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
373 if( use_ret == -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT) )
374 mbedtls_snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
375 if( use_ret == -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE) )
376 mbedtls_snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
377 if( use_ret == -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) )
378 mbedtls_snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
379#endif /* MBEDTLS_PKCS5_C */
Paul Bakker28144de2013-06-24 19:28:55 +0200380
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200381#if defined(MBEDTLS_RSA_C)
382 if( use_ret == -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA) )
383 mbedtls_snprintf( buf, buflen, "RSA - Bad input parameters to function" );
384 if( use_ret == -(MBEDTLS_ERR_RSA_INVALID_PADDING) )
385 mbedtls_snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
386 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED) )
387 mbedtls_snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
388 if( use_ret == -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED) )
Rose Zadik042e97f2018-01-26 16:35:10 +0000389 mbedtls_snprintf( buf, buflen, "RSA - Key failed to pass the validity check of the library" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200390 if( use_ret == -(MBEDTLS_ERR_RSA_PUBLIC_FAILED) )
391 mbedtls_snprintf( buf, buflen, "RSA - The public key operation failed" );
392 if( use_ret == -(MBEDTLS_ERR_RSA_PRIVATE_FAILED) )
393 mbedtls_snprintf( buf, buflen, "RSA - The private key operation failed" );
394 if( use_ret == -(MBEDTLS_ERR_RSA_VERIFY_FAILED) )
395 mbedtls_snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
396 if( use_ret == -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE) )
397 mbedtls_snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
398 if( use_ret == -(MBEDTLS_ERR_RSA_RNG_FAILED) )
399 mbedtls_snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
Hanno Becker3cdc7112017-10-05 10:09:31 +0100400 if( use_ret == -(MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION) )
Rose Zadik042e97f2018-01-26 16:35:10 +0000401 mbedtls_snprintf( buf, buflen, "RSA - The implementation does not offer the requested operation, for example, because of security violations or lack of functionality" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100402 if( use_ret == -(MBEDTLS_ERR_RSA_HW_ACCEL_FAILED) )
403 mbedtls_snprintf( buf, buflen, "RSA - RSA hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200404#endif /* MBEDTLS_RSA_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200405 // END generated code
Paul Bakker0e06c0f2013-08-25 11:21:30 +0200406
Paul Bakker9d781402011-05-09 16:17:09 +0000407 if( strlen( buf ) == 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200408 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000409 }
410
411 use_ret = ret & ~0xFF80;
412
413 if( use_ret == 0 )
414 return;
415
416 // If high level code is present, make a concatenation between both
417 // error strings.
418 //
419 len = strlen( buf );
420
421 if( len > 0 )
422 {
423 if( buflen - len < 5 )
424 return;
425
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200426 mbedtls_snprintf( buf + len, buflen - len, " : " );
Paul Bakker9d781402011-05-09 16:17:09 +0000427
428 buf += len + 3;
429 buflen -= len + 3;
430 }
431
432 // Low level error codes
433 //
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200434 // BEGIN generated code
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200435#if defined(MBEDTLS_AES_C)
436 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH) )
437 mbedtls_snprintf( buf, buflen, "AES - Invalid key length" );
438 if( use_ret == -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH) )
439 mbedtls_snprintf( buf, buflen, "AES - Invalid data input length" );
Mohammad Azim Khane5b5bd72017-11-24 10:52:51 +0000440 if( use_ret == -(MBEDTLS_ERR_AES_BAD_INPUT_DATA) )
441 mbedtls_snprintf( buf, buflen, "AES - Invalid input data" );
Andres Amaya Garciafd487392017-06-14 16:19:12 +0100442 if( use_ret == -(MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE) )
Rose Zadik7f441272018-01-22 11:48:23 +0000443 mbedtls_snprintf( buf, buflen, "AES - Feature not available. For example, an unsupported AES key size" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100444 if( use_ret == -(MBEDTLS_ERR_AES_HW_ACCEL_FAILED) )
445 mbedtls_snprintf( buf, buflen, "AES - AES hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200446#endif /* MBEDTLS_AES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000447
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100448#if defined(MBEDTLS_ARC4_C)
449 if( use_ret == -(MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED) )
450 mbedtls_snprintf( buf, buflen, "ARC4 - ARC4 hardware accelerator failed" );
451#endif /* MBEDTLS_ARC4_C */
452
Markku-Juhani O. Saarinen07478d62017-12-01 16:20:15 +0000453#if defined(MBEDTLS_ARIA_C)
Hanno Becker32142152018-12-17 13:25:58 +0000454 if( use_ret == -(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA) )
455 mbedtls_snprintf( buf, buflen, "ARIA - Bad input data" );
Hanno Beckera0343692018-12-18 09:42:58 +0000456 if( use_ret == -(MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH) )
457 mbedtls_snprintf( buf, buflen, "ARIA - Invalid data input length" );
Manuel Pégourié-Gonnard3c800092018-03-01 09:02:16 +0100458 if( use_ret == -(MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE) )
459 mbedtls_snprintf( buf, buflen, "ARIA - Feature not available. For example, an unsupported ARIA key size" );
460 if( use_ret == -(MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED) )
461 mbedtls_snprintf( buf, buflen, "ARIA - ARIA hardware accelerator failed" );
Markku-Juhani O. Saarinen07478d62017-12-01 16:20:15 +0000462#endif /* MBEDTLS_ARIA_C */
463
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200464#if defined(MBEDTLS_ASN1_PARSE_C)
465 if( use_ret == -(MBEDTLS_ERR_ASN1_OUT_OF_DATA) )
466 mbedtls_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
467 if( use_ret == -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) )
468 mbedtls_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
469 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_LENGTH) )
470 mbedtls_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
471 if( use_ret == -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH) )
472 mbedtls_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
473 if( use_ret == -(MBEDTLS_ERR_ASN1_INVALID_DATA) )
Gilles Peskineaac38532019-09-11 16:52:01 +0200474 mbedtls_snprintf( buf, buflen, "ASN1 - Data is invalid" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200475 if( use_ret == -(MBEDTLS_ERR_ASN1_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200476 mbedtls_snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
477 if( use_ret == -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL) )
478 mbedtls_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
479#endif /* MBEDTLS_ASN1_PARSE_C */
Paul Bakkerdceecd82011-11-15 16:38:34 +0000480
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200481#if defined(MBEDTLS_BASE64_C)
482 if( use_ret == -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) )
483 mbedtls_snprintf( buf, buflen, "BASE64 - Output buffer too small" );
484 if( use_ret == -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER) )
485 mbedtls_snprintf( buf, buflen, "BASE64 - Invalid character in input" );
486#endif /* MBEDTLS_BASE64_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000487
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200488#if defined(MBEDTLS_BIGNUM_C)
489 if( use_ret == -(MBEDTLS_ERR_MPI_FILE_IO_ERROR) )
490 mbedtls_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
491 if( use_ret == -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA) )
492 mbedtls_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
493 if( use_ret == -(MBEDTLS_ERR_MPI_INVALID_CHARACTER) )
494 mbedtls_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
495 if( use_ret == -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL) )
496 mbedtls_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
497 if( use_ret == -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE) )
498 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
499 if( use_ret == -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO) )
500 mbedtls_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
501 if( use_ret == -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) )
502 mbedtls_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
Manuel Pégourié-Gonnard6a8ca332015-05-28 09:33:39 +0200503 if( use_ret == -(MBEDTLS_ERR_MPI_ALLOC_FAILED) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200504 mbedtls_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
505#endif /* MBEDTLS_BIGNUM_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000506
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200507#if defined(MBEDTLS_BLOWFISH_C)
Hanno Becker32142152018-12-17 13:25:58 +0000508 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA) )
509 mbedtls_snprintf( buf, buflen, "BLOWFISH - Bad input data" );
Hanno Becker6640b0d2018-12-18 09:45:17 +0000510 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
511 mbedtls_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100512 if( use_ret == -(MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED) )
513 mbedtls_snprintf( buf, buflen, "BLOWFISH - Blowfish hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200514#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker83f00bb2012-07-04 11:08:50 +0000515
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200516#if defined(MBEDTLS_CAMELLIA_C)
Hanno Becker32142152018-12-17 13:25:58 +0000517 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA) )
518 mbedtls_snprintf( buf, buflen, "CAMELLIA - Bad input data" );
Hanno Becker938f9e92018-12-18 09:40:25 +0000519 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
520 mbedtls_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100521 if( use_ret == -(MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED) )
522 mbedtls_snprintf( buf, buflen, "CAMELLIA - Camellia hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200523#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000524
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200525#if defined(MBEDTLS_CCM_C)
526 if( use_ret == -(MBEDTLS_ERR_CCM_BAD_INPUT) )
Rose Zadikeecdbea2018-01-24 12:56:53 +0000527 mbedtls_snprintf( buf, buflen, "CCM - Bad input parameters to the function" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200528 if( use_ret == -(MBEDTLS_ERR_CCM_AUTH_FAILED) )
529 mbedtls_snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100530 if( use_ret == -(MBEDTLS_ERR_CCM_HW_ACCEL_FAILED) )
531 mbedtls_snprintf( buf, buflen, "CCM - CCM hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200532#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnarda6916fa2014-05-02 15:17:29 +0200533
Daniel King34b822c2016-05-15 17:28:08 -0300534#if defined(MBEDTLS_CHACHA20_C)
535 if( use_ret == -(MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA) )
536 mbedtls_snprintf( buf, buflen, "CHACHA20 - Invalid input parameter(s)" );
Manuel Pégourié-Gonnardb8bd80a2018-05-09 09:54:51 +0200537 if( use_ret == -(MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE) )
538 mbedtls_snprintf( buf, buflen, "CHACHA20 - Feature not available. For example, s part of the API is not implemented" );
Manuel Pégourié-Gonnard3798b6b2018-05-24 13:27:45 +0200539 if( use_ret == -(MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED) )
540 mbedtls_snprintf( buf, buflen, "CHACHA20 - Chacha20 hardware accelerator failed" );
Daniel King34b822c2016-05-15 17:28:08 -0300541#endif /* MBEDTLS_CHACHA20_C */
542
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200543#if defined(MBEDTLS_CHACHAPOLY_C)
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200544 if( use_ret == -(MBEDTLS_ERR_CHACHAPOLY_BAD_STATE) )
545 mbedtls_snprintf( buf, buflen, "CHACHAPOLY - The requested operation is not permitted in the current state" );
Manuel Pégourié-Gonnardb8bd80a2018-05-09 09:54:51 +0200546 if( use_ret == -(MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED) )
547 mbedtls_snprintf( buf, buflen, "CHACHAPOLY - Authenticated decryption failed: data was not authentic" );
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200548#endif /* MBEDTLS_CHACHAPOLY_C */
549
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100550#if defined(MBEDTLS_CMAC_C)
551 if( use_ret == -(MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED) )
552 mbedtls_snprintf( buf, buflen, "CMAC - CMAC hardware accelerator failed" );
553#endif /* MBEDTLS_CMAC_C */
554
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200555#if defined(MBEDTLS_CTR_DRBG_C)
556 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
557 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
558 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000559 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The requested random buffer length is too big" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200560 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000561 mbedtls_snprintf( buf, buflen, "CTR_DRBG - The input (entropy + additional data) is too large" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200562 if( use_ret == -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR) )
Rose Zadik2f8163d2018-01-25 21:55:14 +0000563 mbedtls_snprintf( buf, buflen, "CTR_DRBG - Read or write error in file" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200564#endif /* MBEDTLS_CTR_DRBG_C */
Paul Bakker880ac7e2011-11-27 14:50:49 +0000565
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200566#if defined(MBEDTLS_DES_C)
567 if( use_ret == -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH) )
568 mbedtls_snprintf( buf, buflen, "DES - The data input has an invalid length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100569 if( use_ret == -(MBEDTLS_ERR_DES_HW_ACCEL_FAILED) )
570 mbedtls_snprintf( buf, buflen, "DES - DES hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200571#endif /* MBEDTLS_DES_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000572
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200573#if defined(MBEDTLS_ENTROPY_C)
574 if( use_ret == -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED) )
575 mbedtls_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
576 if( use_ret == -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES) )
577 mbedtls_snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
578 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED) )
579 mbedtls_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
Manuel Pégourié-Gonnardf9cbd732015-06-22 12:06:50 +0200580 if( use_ret == -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE) )
581 mbedtls_snprintf( buf, buflen, "ENTROPY - No strong sources have been added to poll" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200582 if( use_ret == -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR) )
583 mbedtls_snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
584#endif /* MBEDTLS_ENTROPY_C */
Paul Bakker6083fd22011-12-03 21:45:14 +0000585
Janos Follath60f6b642019-12-03 15:55:56 +0000586#if defined(MBEDTLS_ERROR_C)
587 if( use_ret == -(MBEDTLS_ERR_ERROR_GENERIC_ERROR) )
588 mbedtls_snprintf( buf, buflen, "ERROR - Generic error" );
589 if( use_ret == -(MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED) )
590 mbedtls_snprintf( buf, buflen, "ERROR - This is a bug in the library" );
591#endif /* MBEDTLS_ERROR_C */
592
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200593#if defined(MBEDTLS_GCM_C)
594 if( use_ret == -(MBEDTLS_ERR_GCM_AUTH_FAILED) )
595 mbedtls_snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100596 if( use_ret == -(MBEDTLS_ERR_GCM_HW_ACCEL_FAILED) )
597 mbedtls_snprintf( buf, buflen, "GCM - GCM hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200598 if( use_ret == -(MBEDTLS_ERR_GCM_BAD_INPUT) )
599 mbedtls_snprintf( buf, buflen, "GCM - Bad input parameters to function" );
600#endif /* MBEDTLS_GCM_C */
Paul Bakker030277a2012-04-17 12:24:26 +0000601
Thomas Fossati656864b2016-07-17 08:51:22 +0100602#if defined(MBEDTLS_HKDF_C)
603 if( use_ret == -(MBEDTLS_ERR_HKDF_BAD_INPUT_DATA) )
604 mbedtls_snprintf( buf, buflen, "HKDF - Bad input parameters to function" );
605#endif /* MBEDTLS_HKDF_C */
606
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200607#if defined(MBEDTLS_HMAC_DRBG_C)
608 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
609 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
610 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
611 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
612 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR) )
613 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
614 if( use_ret == -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
615 mbedtls_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
616#endif /* MBEDTLS_HMAC_DRBG_C */
Manuel Pégourié-Gonnardcf383672014-02-01 10:22:21 +0100617
Gilles Peskinea381fe82018-01-23 18:16:11 +0100618#if defined(MBEDTLS_MD2_C)
619 if( use_ret == -(MBEDTLS_ERR_MD2_HW_ACCEL_FAILED) )
620 mbedtls_snprintf( buf, buflen, "MD2 - MD2 hardware accelerator failed" );
621#endif /* MBEDTLS_MD2_C */
622
623#if defined(MBEDTLS_MD4_C)
624 if( use_ret == -(MBEDTLS_ERR_MD4_HW_ACCEL_FAILED) )
625 mbedtls_snprintf( buf, buflen, "MD4 - MD4 hardware accelerator failed" );
626#endif /* MBEDTLS_MD4_C */
627
628#if defined(MBEDTLS_MD5_C)
629 if( use_ret == -(MBEDTLS_ERR_MD5_HW_ACCEL_FAILED) )
630 mbedtls_snprintf( buf, buflen, "MD5 - MD5 hardware accelerator failed" );
631#endif /* MBEDTLS_MD5_C */
632
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200633#if defined(MBEDTLS_OID_C)
634 if( use_ret == -(MBEDTLS_ERR_OID_NOT_FOUND) )
635 mbedtls_snprintf( buf, buflen, "OID - OID is not found" );
636 if( use_ret == -(MBEDTLS_ERR_OID_BUF_TOO_SMALL) )
637 mbedtls_snprintf( buf, buflen, "OID - output buffer is too small" );
638#endif /* MBEDTLS_OID_C */
Paul Bakkerc70b9822013-04-07 22:00:46 +0200639
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200640#if defined(MBEDTLS_PADLOCK_C)
641 if( use_ret == -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED) )
642 mbedtls_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
643#endif /* MBEDTLS_PADLOCK_C */
Paul Bakker9d781402011-05-09 16:17:09 +0000644
Ron Eldor0ff4e0b2018-08-29 18:53:20 +0300645#if defined(MBEDTLS_PLATFORM_C)
Ron Eldora27190b2018-10-15 16:33:43 +0300646 if( use_ret == -(MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED) )
Ron Eldor5267b622018-10-15 18:44:42 +0300647 mbedtls_snprintf( buf, buflen, "PLATFORM - Hardware accelerator failed" );
Ron Eldorbcca58c2018-10-03 16:33:21 +0300648 if( use_ret == -(MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED) )
649 mbedtls_snprintf( buf, buflen, "PLATFORM - The requested feature is not supported by the platform" );
Ron Eldor0ff4e0b2018-08-29 18:53:20 +0300650#endif /* MBEDTLS_PLATFORM_C */
651
Daniel Kingadc32c02016-05-16 18:25:45 -0300652#if defined(MBEDTLS_POLY1305_C)
653 if( use_ret == -(MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA) )
654 mbedtls_snprintf( buf, buflen, "POLY1305 - Invalid input parameter(s)" );
Manuel Pégourié-Gonnardb8bd80a2018-05-09 09:54:51 +0200655 if( use_ret == -(MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE) )
656 mbedtls_snprintf( buf, buflen, "POLY1305 - Feature not available. For example, s part of the API is not implemented" );
Manuel Pégourié-Gonnard3798b6b2018-05-24 13:27:45 +0200657 if( use_ret == -(MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED) )
658 mbedtls_snprintf( buf, buflen, "POLY1305 - Poly1305 hardware accelerator failed" );
Daniel Kingadc32c02016-05-16 18:25:45 -0300659#endif /* MBEDTLS_POLY1305_C */
660
Gilles Peskinea381fe82018-01-23 18:16:11 +0100661#if defined(MBEDTLS_RIPEMD160_C)
662 if( use_ret == -(MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED) )
663 mbedtls_snprintf( buf, buflen, "RIPEMD160 - RIPEMD160 hardware accelerator failed" );
664#endif /* MBEDTLS_RIPEMD160_C */
665
666#if defined(MBEDTLS_SHA1_C)
667 if( use_ret == -(MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED) )
668 mbedtls_snprintf( buf, buflen, "SHA1 - SHA-1 hardware accelerator failed" );
Andres Amaya Garciaa685d4f2018-12-09 19:13:01 +0000669 if( use_ret == -(MBEDTLS_ERR_SHA1_BAD_INPUT_DATA) )
Hanno Becker859522a2018-12-19 09:54:14 +0000670 mbedtls_snprintf( buf, buflen, "SHA1 - SHA-1 input data was malformed" );
Gilles Peskinea381fe82018-01-23 18:16:11 +0100671#endif /* MBEDTLS_SHA1_C */
672
673#if defined(MBEDTLS_SHA256_C)
674 if( use_ret == -(MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED) )
675 mbedtls_snprintf( buf, buflen, "SHA256 - SHA-256 hardware accelerator failed" );
Andres Amaya Garcia9e76c0e2018-12-09 20:42:05 +0000676 if( use_ret == -(MBEDTLS_ERR_SHA256_BAD_INPUT_DATA) )
Hanno Beckerd8e4f4a2018-12-19 09:54:55 +0000677 mbedtls_snprintf( buf, buflen, "SHA256 - SHA-256 input data was malformed" );
Gilles Peskinea381fe82018-01-23 18:16:11 +0100678#endif /* MBEDTLS_SHA256_C */
679
680#if defined(MBEDTLS_SHA512_C)
681 if( use_ret == -(MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED) )
682 mbedtls_snprintf( buf, buflen, "SHA512 - SHA-512 hardware accelerator failed" );
Andres Amaya Garcia863d4832018-12-09 20:58:52 +0000683 if( use_ret == -(MBEDTLS_ERR_SHA512_BAD_INPUT_DATA) )
Hanno Becker9994e0d2018-12-19 09:55:40 +0000684 mbedtls_snprintf( buf, buflen, "SHA512 - SHA-512 input data was malformed" );
Gilles Peskinea381fe82018-01-23 18:16:11 +0100685#endif /* MBEDTLS_SHA512_C */
686
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200687#if defined(MBEDTLS_THREADING_C)
688 if( use_ret == -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE) )
689 mbedtls_snprintf( buf, buflen, "THREADING - The selected feature is not available" );
690 if( use_ret == -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA) )
691 mbedtls_snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
692 if( use_ret == -(MBEDTLS_ERR_THREADING_MUTEX_ERROR) )
693 mbedtls_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
694#endif /* MBEDTLS_THREADING_C */
Paul Bakker2466d932013-09-28 14:40:38 +0200695
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200696#if defined(MBEDTLS_XTEA_C)
697 if( use_ret == -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH) )
698 mbedtls_snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
Gilles Peskine7ecab3d2018-01-26 17:56:38 +0100699 if( use_ret == -(MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED) )
700 mbedtls_snprintf( buf, buflen, "XTEA - XTEA hardware accelerator failed" );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200701#endif /* MBEDTLS_XTEA_C */
Manuel Pégourié-Gonnardfe671f42014-04-11 18:06:44 +0200702 // END generated code
Paul Bakker9d781402011-05-09 16:17:09 +0000703
704 if( strlen( buf ) != 0 )
705 return;
706
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200707 mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
Paul Bakker9d781402011-05-09 16:17:09 +0000708}
709
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200710#else /* MBEDTLS_ERROR_C */
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100711
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200712#if defined(MBEDTLS_ERROR_STRERROR_DUMMY)
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100713
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100714/*
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200715 * Provide an non-function in case MBEDTLS_ERROR_C is not defined
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100716 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200717void mbedtls_strerror( int ret, char *buf, size_t buflen )
Paul Bakker8fe40dc2013-02-02 12:43:08 +0100718{
719 ((void) ret);
720
721 if( buflen > 0 )
722 buf[0] = '\0';
723}
724
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200725#endif /* MBEDTLS_ERROR_STRERROR_DUMMY */
Paul Bakkere2ab84f2013-06-29 18:24:32 +0200726
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200727#endif /* MBEDTLS_ERROR_C */