xref: /optee_os/lib/libmbedtls/mbedtls/library/error.c (revision 7901324d9530594155991c8b283023d567741cc7)
1817466cbSJens Wiklander /*
2817466cbSJens Wiklander  *  Error message information
3817466cbSJens Wiklander  *
4*7901324dSJerome Forissier  *  Copyright The Mbed TLS Contributors
5*7901324dSJerome Forissier  *  SPDX-License-Identifier: Apache-2.0
6817466cbSJens Wiklander  *
7817466cbSJens Wiklander  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
8817466cbSJens Wiklander  *  not use this file except in compliance with the License.
9817466cbSJens Wiklander  *  You may obtain a copy of the License at
10817466cbSJens Wiklander  *
11817466cbSJens Wiklander  *  http://www.apache.org/licenses/LICENSE-2.0
12817466cbSJens Wiklander  *
13817466cbSJens Wiklander  *  Unless required by applicable law or agreed to in writing, software
14817466cbSJens Wiklander  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15817466cbSJens Wiklander  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16817466cbSJens Wiklander  *  See the License for the specific language governing permissions and
17817466cbSJens Wiklander  *  limitations under the License.
18817466cbSJens Wiklander  */
19817466cbSJens Wiklander 
20*7901324dSJerome Forissier #include "common.h"
21817466cbSJens Wiklander 
22*7901324dSJerome Forissier #include "mbedtls/error.h"
23*7901324dSJerome Forissier 
24*7901324dSJerome Forissier #if defined(MBEDTLS_ERROR_C) || defined(MBEDTLS_ERROR_STRERROR_DUMMY)
25*7901324dSJerome Forissier 
26*7901324dSJerome Forissier #if defined(MBEDTLS_ERROR_C)
27817466cbSJens Wiklander 
28817466cbSJens Wiklander #if defined(MBEDTLS_PLATFORM_C)
29817466cbSJens Wiklander #include "mbedtls/platform.h"
30817466cbSJens Wiklander #else
31817466cbSJens Wiklander #define mbedtls_snprintf snprintf
32817466cbSJens Wiklander #endif
33817466cbSJens Wiklander 
34817466cbSJens Wiklander #include <stdio.h>
35*7901324dSJerome Forissier #include <string.h>
36817466cbSJens Wiklander 
37817466cbSJens Wiklander #if defined(MBEDTLS_AES_C)
38817466cbSJens Wiklander #include "mbedtls/aes.h"
39817466cbSJens Wiklander #endif
40817466cbSJens Wiklander 
413d3b0591SJens Wiklander #if defined(MBEDTLS_ARC4_C)
423d3b0591SJens Wiklander #include "mbedtls/arc4.h"
433d3b0591SJens Wiklander #endif
443d3b0591SJens Wiklander 
453d3b0591SJens Wiklander #if defined(MBEDTLS_ARIA_C)
463d3b0591SJens Wiklander #include "mbedtls/aria.h"
473d3b0591SJens Wiklander #endif
483d3b0591SJens Wiklander 
49*7901324dSJerome Forissier #if defined(MBEDTLS_ASN1_PARSE_C)
50*7901324dSJerome Forissier #include "mbedtls/asn1.h"
51*7901324dSJerome Forissier #endif
52*7901324dSJerome Forissier 
53817466cbSJens Wiklander #if defined(MBEDTLS_BASE64_C)
54817466cbSJens Wiklander #include "mbedtls/base64.h"
55817466cbSJens Wiklander #endif
56817466cbSJens Wiklander 
57817466cbSJens Wiklander #if defined(MBEDTLS_BIGNUM_C)
58817466cbSJens Wiklander #include "mbedtls/bignum.h"
59817466cbSJens Wiklander #endif
60817466cbSJens Wiklander 
61817466cbSJens Wiklander #if defined(MBEDTLS_BLOWFISH_C)
62817466cbSJens Wiklander #include "mbedtls/blowfish.h"
63817466cbSJens Wiklander #endif
64817466cbSJens Wiklander 
65817466cbSJens Wiklander #if defined(MBEDTLS_CAMELLIA_C)
66817466cbSJens Wiklander #include "mbedtls/camellia.h"
67817466cbSJens Wiklander #endif
68817466cbSJens Wiklander 
69817466cbSJens Wiklander #if defined(MBEDTLS_CCM_C)
70817466cbSJens Wiklander #include "mbedtls/ccm.h"
71817466cbSJens Wiklander #endif
72817466cbSJens Wiklander 
733d3b0591SJens Wiklander #if defined(MBEDTLS_CHACHA20_C)
743d3b0591SJens Wiklander #include "mbedtls/chacha20.h"
753d3b0591SJens Wiklander #endif
763d3b0591SJens Wiklander 
773d3b0591SJens Wiklander #if defined(MBEDTLS_CHACHAPOLY_C)
783d3b0591SJens Wiklander #include "mbedtls/chachapoly.h"
793d3b0591SJens Wiklander #endif
803d3b0591SJens Wiklander 
81817466cbSJens Wiklander #if defined(MBEDTLS_CIPHER_C)
82817466cbSJens Wiklander #include "mbedtls/cipher.h"
83817466cbSJens Wiklander #endif
84817466cbSJens Wiklander 
853d3b0591SJens Wiklander #if defined(MBEDTLS_CMAC_C)
863d3b0591SJens Wiklander #include "mbedtls/cmac.h"
873d3b0591SJens Wiklander #endif
883d3b0591SJens Wiklander 
89817466cbSJens Wiklander #if defined(MBEDTLS_CTR_DRBG_C)
90817466cbSJens Wiklander #include "mbedtls/ctr_drbg.h"
91817466cbSJens Wiklander #endif
92817466cbSJens Wiklander 
93817466cbSJens Wiklander #if defined(MBEDTLS_DES_C)
94817466cbSJens Wiklander #include "mbedtls/des.h"
95817466cbSJens Wiklander #endif
96817466cbSJens Wiklander 
97817466cbSJens Wiklander #if defined(MBEDTLS_DHM_C)
98817466cbSJens Wiklander #include "mbedtls/dhm.h"
99817466cbSJens Wiklander #endif
100817466cbSJens Wiklander 
101817466cbSJens Wiklander #if defined(MBEDTLS_ECP_C)
102817466cbSJens Wiklander #include "mbedtls/ecp.h"
103817466cbSJens Wiklander #endif
104817466cbSJens Wiklander 
105817466cbSJens Wiklander #if defined(MBEDTLS_ENTROPY_C)
106817466cbSJens Wiklander #include "mbedtls/entropy.h"
107817466cbSJens Wiklander #endif
108817466cbSJens Wiklander 
10911fa71b9SJerome Forissier #if defined(MBEDTLS_ERROR_C)
11011fa71b9SJerome Forissier #include "mbedtls/error.h"
11111fa71b9SJerome Forissier #endif
11211fa71b9SJerome Forissier 
113817466cbSJens Wiklander #if defined(MBEDTLS_GCM_C)
114817466cbSJens Wiklander #include "mbedtls/gcm.h"
115817466cbSJens Wiklander #endif
116817466cbSJens Wiklander 
1173d3b0591SJens Wiklander #if defined(MBEDTLS_HKDF_C)
1183d3b0591SJens Wiklander #include "mbedtls/hkdf.h"
1193d3b0591SJens Wiklander #endif
1203d3b0591SJens Wiklander 
121817466cbSJens Wiklander #if defined(MBEDTLS_HMAC_DRBG_C)
122817466cbSJens Wiklander #include "mbedtls/hmac_drbg.h"
123817466cbSJens Wiklander #endif
124817466cbSJens Wiklander 
125817466cbSJens Wiklander #if defined(MBEDTLS_MD_C)
126817466cbSJens Wiklander #include "mbedtls/md.h"
127817466cbSJens Wiklander #endif
128817466cbSJens Wiklander 
1293d3b0591SJens Wiklander #if defined(MBEDTLS_MD2_C)
1303d3b0591SJens Wiklander #include "mbedtls/md2.h"
1313d3b0591SJens Wiklander #endif
1323d3b0591SJens Wiklander 
1333d3b0591SJens Wiklander #if defined(MBEDTLS_MD4_C)
1343d3b0591SJens Wiklander #include "mbedtls/md4.h"
1353d3b0591SJens Wiklander #endif
1363d3b0591SJens Wiklander 
1373d3b0591SJens Wiklander #if defined(MBEDTLS_MD5_C)
1383d3b0591SJens Wiklander #include "mbedtls/md5.h"
1393d3b0591SJens Wiklander #endif
1403d3b0591SJens Wiklander 
141817466cbSJens Wiklander #if defined(MBEDTLS_NET_C)
142817466cbSJens Wiklander #include "mbedtls/net_sockets.h"
143817466cbSJens Wiklander #endif
144817466cbSJens Wiklander 
145817466cbSJens Wiklander #if defined(MBEDTLS_OID_C)
146817466cbSJens Wiklander #include "mbedtls/oid.h"
147817466cbSJens Wiklander #endif
148817466cbSJens Wiklander 
149817466cbSJens Wiklander #if defined(MBEDTLS_PADLOCK_C)
150817466cbSJens Wiklander #include "mbedtls/padlock.h"
151817466cbSJens Wiklander #endif
152817466cbSJens Wiklander 
153817466cbSJens Wiklander #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
154817466cbSJens Wiklander #include "mbedtls/pem.h"
155817466cbSJens Wiklander #endif
156817466cbSJens Wiklander 
157817466cbSJens Wiklander #if defined(MBEDTLS_PK_C)
158817466cbSJens Wiklander #include "mbedtls/pk.h"
159817466cbSJens Wiklander #endif
160817466cbSJens Wiklander 
161817466cbSJens Wiklander #if defined(MBEDTLS_PKCS12_C)
162817466cbSJens Wiklander #include "mbedtls/pkcs12.h"
163817466cbSJens Wiklander #endif
164817466cbSJens Wiklander 
165817466cbSJens Wiklander #if defined(MBEDTLS_PKCS5_C)
166817466cbSJens Wiklander #include "mbedtls/pkcs5.h"
167817466cbSJens Wiklander #endif
168817466cbSJens Wiklander 
1693d3b0591SJens Wiklander #if defined(MBEDTLS_PLATFORM_C)
1703d3b0591SJens Wiklander #include "mbedtls/platform.h"
1713d3b0591SJens Wiklander #endif
1723d3b0591SJens Wiklander 
1733d3b0591SJens Wiklander #if defined(MBEDTLS_POLY1305_C)
1743d3b0591SJens Wiklander #include "mbedtls/poly1305.h"
1753d3b0591SJens Wiklander #endif
1763d3b0591SJens Wiklander 
1773d3b0591SJens Wiklander #if defined(MBEDTLS_RIPEMD160_C)
1783d3b0591SJens Wiklander #include "mbedtls/ripemd160.h"
1793d3b0591SJens Wiklander #endif
1803d3b0591SJens Wiklander 
181817466cbSJens Wiklander #if defined(MBEDTLS_RSA_C)
182817466cbSJens Wiklander #include "mbedtls/rsa.h"
183817466cbSJens Wiklander #endif
184817466cbSJens Wiklander 
1853d3b0591SJens Wiklander #if defined(MBEDTLS_SHA1_C)
1863d3b0591SJens Wiklander #include "mbedtls/sha1.h"
1873d3b0591SJens Wiklander #endif
1883d3b0591SJens Wiklander 
1893d3b0591SJens Wiklander #if defined(MBEDTLS_SHA256_C)
1903d3b0591SJens Wiklander #include "mbedtls/sha256.h"
1913d3b0591SJens Wiklander #endif
1923d3b0591SJens Wiklander 
1933d3b0591SJens Wiklander #if defined(MBEDTLS_SHA512_C)
1943d3b0591SJens Wiklander #include "mbedtls/sha512.h"
1953d3b0591SJens Wiklander #endif
1963d3b0591SJens Wiklander 
197817466cbSJens Wiklander #if defined(MBEDTLS_SSL_TLS_C)
198817466cbSJens Wiklander #include "mbedtls/ssl.h"
199817466cbSJens Wiklander #endif
200817466cbSJens Wiklander 
201817466cbSJens Wiklander #if defined(MBEDTLS_THREADING_C)
202817466cbSJens Wiklander #include "mbedtls/threading.h"
203817466cbSJens Wiklander #endif
204817466cbSJens Wiklander 
205817466cbSJens Wiklander #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
206817466cbSJens Wiklander #include "mbedtls/x509.h"
207817466cbSJens Wiklander #endif
208817466cbSJens Wiklander 
209817466cbSJens Wiklander #if defined(MBEDTLS_XTEA_C)
210817466cbSJens Wiklander #include "mbedtls/xtea.h"
211817466cbSJens Wiklander #endif
212817466cbSJens Wiklander 
213817466cbSJens Wiklander 
214*7901324dSJerome Forissier const char * mbedtls_high_level_strerr( int error_code )
215*7901324dSJerome Forissier {
216*7901324dSJerome Forissier     int high_level_error_code;
217*7901324dSJerome Forissier 
218*7901324dSJerome Forissier     if( error_code < 0 )
219*7901324dSJerome Forissier         error_code = -error_code;
220*7901324dSJerome Forissier 
221*7901324dSJerome Forissier     /* Extract the high-level part from the error code. */
222*7901324dSJerome Forissier     high_level_error_code = error_code & 0xFF80;
223*7901324dSJerome Forissier 
224*7901324dSJerome Forissier     switch( high_level_error_code )
225*7901324dSJerome Forissier     {
226*7901324dSJerome Forissier         /* Begin Auto-Generated Code. */
227*7901324dSJerome Forissier #if defined(MBEDTLS_CIPHER_C)
228*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE):
229*7901324dSJerome Forissier             return( "CIPHER - The selected feature is not available" );
230*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA):
231*7901324dSJerome Forissier             return( "CIPHER - Bad input parameters" );
232*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED):
233*7901324dSJerome Forissier             return( "CIPHER - Failed to allocate memory" );
234*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CIPHER_INVALID_PADDING):
235*7901324dSJerome Forissier             return( "CIPHER - Input data contains invalid padding and is rejected" );
236*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED):
237*7901324dSJerome Forissier             return( "CIPHER - Decryption of block requires a full block" );
238*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CIPHER_AUTH_FAILED):
239*7901324dSJerome Forissier             return( "CIPHER - Authentication failed (for AEAD modes)" );
240*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT):
241*7901324dSJerome Forissier             return( "CIPHER - The context is invalid. For example, because it was freed" );
242*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED):
243*7901324dSJerome Forissier             return( "CIPHER - Cipher hardware accelerator failed" );
244*7901324dSJerome Forissier #endif /* MBEDTLS_CIPHER_C */
245*7901324dSJerome Forissier 
246*7901324dSJerome Forissier #if defined(MBEDTLS_DHM_C)
247*7901324dSJerome Forissier         case -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA):
248*7901324dSJerome Forissier             return( "DHM - Bad input parameters" );
249*7901324dSJerome Forissier         case -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED):
250*7901324dSJerome Forissier             return( "DHM - Reading of the DHM parameters failed" );
251*7901324dSJerome Forissier         case -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED):
252*7901324dSJerome Forissier             return( "DHM - Making of the DHM parameters failed" );
253*7901324dSJerome Forissier         case -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED):
254*7901324dSJerome Forissier             return( "DHM - Reading of the public values failed" );
255*7901324dSJerome Forissier         case -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED):
256*7901324dSJerome Forissier             return( "DHM - Making of the public value failed" );
257*7901324dSJerome Forissier         case -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED):
258*7901324dSJerome Forissier             return( "DHM - Calculation of the DHM secret failed" );
259*7901324dSJerome Forissier         case -(MBEDTLS_ERR_DHM_INVALID_FORMAT):
260*7901324dSJerome Forissier             return( "DHM - The ASN.1 data is not formatted correctly" );
261*7901324dSJerome Forissier         case -(MBEDTLS_ERR_DHM_ALLOC_FAILED):
262*7901324dSJerome Forissier             return( "DHM - Allocation of memory failed" );
263*7901324dSJerome Forissier         case -(MBEDTLS_ERR_DHM_FILE_IO_ERROR):
264*7901324dSJerome Forissier             return( "DHM - Read or write of file failed" );
265*7901324dSJerome Forissier         case -(MBEDTLS_ERR_DHM_HW_ACCEL_FAILED):
266*7901324dSJerome Forissier             return( "DHM - DHM hardware accelerator failed" );
267*7901324dSJerome Forissier         case -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED):
268*7901324dSJerome Forissier             return( "DHM - Setting the modulus and generator failed" );
269*7901324dSJerome Forissier #endif /* MBEDTLS_DHM_C */
270*7901324dSJerome Forissier 
271*7901324dSJerome Forissier #if defined(MBEDTLS_ECP_C)
272*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA):
273*7901324dSJerome Forissier             return( "ECP - Bad input parameters to function" );
274*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL):
275*7901324dSJerome Forissier             return( "ECP - The buffer is too small to write to" );
276*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE):
277*7901324dSJerome Forissier             return( "ECP - The requested feature is not available, for example, the requested curve is not supported" );
278*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ECP_VERIFY_FAILED):
279*7901324dSJerome Forissier             return( "ECP - The signature is not valid" );
280*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ECP_ALLOC_FAILED):
281*7901324dSJerome Forissier             return( "ECP - Memory allocation failed" );
282*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ECP_RANDOM_FAILED):
283*7901324dSJerome Forissier             return( "ECP - Generation of random value, such as ephemeral key, failed" );
284*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ECP_INVALID_KEY):
285*7901324dSJerome Forissier             return( "ECP - Invalid private or public key" );
286*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH):
287*7901324dSJerome Forissier             return( "ECP - The buffer contains a valid signature followed by more data" );
288*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ECP_HW_ACCEL_FAILED):
289*7901324dSJerome Forissier             return( "ECP - The ECP hardware accelerator failed" );
290*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ECP_IN_PROGRESS):
291*7901324dSJerome Forissier             return( "ECP - Operation in progress, call again with the same parameters to continue" );
292*7901324dSJerome Forissier #endif /* MBEDTLS_ECP_C */
293*7901324dSJerome Forissier 
294*7901324dSJerome Forissier #if defined(MBEDTLS_MD_C)
295*7901324dSJerome Forissier         case -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE):
296*7901324dSJerome Forissier             return( "MD - The selected feature is not available" );
297*7901324dSJerome Forissier         case -(MBEDTLS_ERR_MD_BAD_INPUT_DATA):
298*7901324dSJerome Forissier             return( "MD - Bad input parameters to function" );
299*7901324dSJerome Forissier         case -(MBEDTLS_ERR_MD_ALLOC_FAILED):
300*7901324dSJerome Forissier             return( "MD - Failed to allocate memory" );
301*7901324dSJerome Forissier         case -(MBEDTLS_ERR_MD_FILE_IO_ERROR):
302*7901324dSJerome Forissier             return( "MD - Opening or reading of file failed" );
303*7901324dSJerome Forissier         case -(MBEDTLS_ERR_MD_HW_ACCEL_FAILED):
304*7901324dSJerome Forissier             return( "MD - MD hardware accelerator failed" );
305*7901324dSJerome Forissier #endif /* MBEDTLS_MD_C */
306*7901324dSJerome Forissier 
307*7901324dSJerome Forissier #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
308*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT):
309*7901324dSJerome Forissier             return( "PEM - No PEM header or footer found" );
310*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PEM_INVALID_DATA):
311*7901324dSJerome Forissier             return( "PEM - PEM string is not as expected" );
312*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PEM_ALLOC_FAILED):
313*7901324dSJerome Forissier             return( "PEM - Failed to allocate memory" );
314*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PEM_INVALID_ENC_IV):
315*7901324dSJerome Forissier             return( "PEM - RSA IV is not in hex-format" );
316*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG):
317*7901324dSJerome Forissier             return( "PEM - Unsupported key encryption algorithm" );
318*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED):
319*7901324dSJerome Forissier             return( "PEM - Private key password can't be empty" );
320*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH):
321*7901324dSJerome Forissier             return( "PEM - Given private key password does not allow for correct decryption" );
322*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE):
323*7901324dSJerome Forissier             return( "PEM - Unavailable feature, e.g. hashing/encryption combination" );
324*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA):
325*7901324dSJerome Forissier             return( "PEM - Bad input parameters to function" );
326*7901324dSJerome Forissier #endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */
327*7901324dSJerome Forissier 
328*7901324dSJerome Forissier #if defined(MBEDTLS_PK_C)
329*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PK_ALLOC_FAILED):
330*7901324dSJerome Forissier             return( "PK - Memory allocation failed" );
331*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PK_TYPE_MISMATCH):
332*7901324dSJerome Forissier             return( "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
333*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PK_BAD_INPUT_DATA):
334*7901324dSJerome Forissier             return( "PK - Bad input parameters to function" );
335*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PK_FILE_IO_ERROR):
336*7901324dSJerome Forissier             return( "PK - Read/write of file failed" );
337*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION):
338*7901324dSJerome Forissier             return( "PK - Unsupported key version" );
339*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT):
340*7901324dSJerome Forissier             return( "PK - Invalid key tag or value" );
341*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG):
342*7901324dSJerome Forissier             return( "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
343*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED):
344*7901324dSJerome Forissier             return( "PK - Private key password can't be empty" );
345*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH):
346*7901324dSJerome Forissier             return( "PK - Given private key password does not allow for correct decryption" );
347*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PK_INVALID_PUBKEY):
348*7901324dSJerome Forissier             return( "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
349*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PK_INVALID_ALG):
350*7901324dSJerome Forissier             return( "PK - The algorithm tag or value is invalid" );
351*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE):
352*7901324dSJerome Forissier             return( "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
353*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE):
354*7901324dSJerome Forissier             return( "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
355*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH):
356*7901324dSJerome Forissier             return( "PK - The buffer contains a valid signature followed by more data" );
357*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PK_HW_ACCEL_FAILED):
358*7901324dSJerome Forissier             return( "PK - PK hardware accelerator failed" );
359*7901324dSJerome Forissier #endif /* MBEDTLS_PK_C */
360*7901324dSJerome Forissier 
361*7901324dSJerome Forissier #if defined(MBEDTLS_PKCS12_C)
362*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA):
363*7901324dSJerome Forissier             return( "PKCS12 - Bad input parameters to function" );
364*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE):
365*7901324dSJerome Forissier             return( "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
366*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT):
367*7901324dSJerome Forissier             return( "PKCS12 - PBE ASN.1 data not as expected" );
368*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH):
369*7901324dSJerome Forissier             return( "PKCS12 - Given private key password does not allow for correct decryption" );
370*7901324dSJerome Forissier #endif /* MBEDTLS_PKCS12_C */
371*7901324dSJerome Forissier 
372*7901324dSJerome Forissier #if defined(MBEDTLS_PKCS5_C)
373*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA):
374*7901324dSJerome Forissier             return( "PKCS5 - Bad input parameters to function" );
375*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT):
376*7901324dSJerome Forissier             return( "PKCS5 - Unexpected ASN.1 data" );
377*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE):
378*7901324dSJerome Forissier             return( "PKCS5 - Requested encryption or digest alg not available" );
379*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH):
380*7901324dSJerome Forissier             return( "PKCS5 - Given private key password does not allow for correct decryption" );
381*7901324dSJerome Forissier #endif /* MBEDTLS_PKCS5_C */
382*7901324dSJerome Forissier 
383*7901324dSJerome Forissier #if defined(MBEDTLS_RSA_C)
384*7901324dSJerome Forissier         case -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA):
385*7901324dSJerome Forissier             return( "RSA - Bad input parameters to function" );
386*7901324dSJerome Forissier         case -(MBEDTLS_ERR_RSA_INVALID_PADDING):
387*7901324dSJerome Forissier             return( "RSA - Input data contains invalid padding and is rejected" );
388*7901324dSJerome Forissier         case -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED):
389*7901324dSJerome Forissier             return( "RSA - Something failed during generation of a key" );
390*7901324dSJerome Forissier         case -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED):
391*7901324dSJerome Forissier             return( "RSA - Key failed to pass the validity check of the library" );
392*7901324dSJerome Forissier         case -(MBEDTLS_ERR_RSA_PUBLIC_FAILED):
393*7901324dSJerome Forissier             return( "RSA - The public key operation failed" );
394*7901324dSJerome Forissier         case -(MBEDTLS_ERR_RSA_PRIVATE_FAILED):
395*7901324dSJerome Forissier             return( "RSA - The private key operation failed" );
396*7901324dSJerome Forissier         case -(MBEDTLS_ERR_RSA_VERIFY_FAILED):
397*7901324dSJerome Forissier             return( "RSA - The PKCS#1 verification failed" );
398*7901324dSJerome Forissier         case -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE):
399*7901324dSJerome Forissier             return( "RSA - The output buffer for decryption is not large enough" );
400*7901324dSJerome Forissier         case -(MBEDTLS_ERR_RSA_RNG_FAILED):
401*7901324dSJerome Forissier             return( "RSA - The random generator failed to generate non-zeros" );
402*7901324dSJerome Forissier         case -(MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION):
403*7901324dSJerome Forissier             return( "RSA - The implementation does not offer the requested operation, for example, because of security violations or lack of functionality" );
404*7901324dSJerome Forissier         case -(MBEDTLS_ERR_RSA_HW_ACCEL_FAILED):
405*7901324dSJerome Forissier             return( "RSA - RSA hardware accelerator failed" );
406*7901324dSJerome Forissier #endif /* MBEDTLS_RSA_C */
407*7901324dSJerome Forissier 
408*7901324dSJerome Forissier #if defined(MBEDTLS_SSL_TLS_C)
409*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE):
410*7901324dSJerome Forissier             return( "SSL - The requested feature is not available" );
411*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA):
412*7901324dSJerome Forissier             return( "SSL - Bad input parameters to function" );
413*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_INVALID_MAC):
414*7901324dSJerome Forissier             return( "SSL - Verification of the message MAC failed" );
415*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_INVALID_RECORD):
416*7901324dSJerome Forissier             return( "SSL - An invalid SSL record was received" );
417*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_CONN_EOF):
418*7901324dSJerome Forissier             return( "SSL - The connection indicated an EOF" );
419*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER):
420*7901324dSJerome Forissier             return( "SSL - An unknown cipher was received" );
421*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN):
422*7901324dSJerome Forissier             return( "SSL - The server has no ciphersuites in common with the client" );
423*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_NO_RNG):
424*7901324dSJerome Forissier             return( "SSL - No RNG was provided to the SSL module" );
425*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE):
426*7901324dSJerome Forissier             return( "SSL - No client certification received from the client, but required by the authentication mode" );
427*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE):
428*7901324dSJerome Forissier             return( "SSL - Our own certificate(s) is/are too large to send in an SSL message" );
429*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED):
430*7901324dSJerome Forissier             return( "SSL - The own certificate is not set, but needed by the server" );
431*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED):
432*7901324dSJerome Forissier             return( "SSL - The own private key or pre-shared key is not set, but needed" );
433*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED):
434*7901324dSJerome Forissier             return( "SSL - No CA Chain is set, but required to operate" );
435*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE):
436*7901324dSJerome Forissier             return( "SSL - An unexpected message was received from our peer" );
437*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE):
438*7901324dSJerome Forissier             return( "SSL - A fatal alert message was received from our peer" );
439*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED):
440*7901324dSJerome Forissier             return( "SSL - Verification of our peer failed" );
441*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY):
442*7901324dSJerome Forissier             return( "SSL - The peer notified us that the connection is going to be closed" );
443*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO):
444*7901324dSJerome Forissier             return( "SSL - Processing of the ClientHello handshake message failed" );
445*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO):
446*7901324dSJerome Forissier             return( "SSL - Processing of the ServerHello handshake message failed" );
447*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE):
448*7901324dSJerome Forissier             return( "SSL - Processing of the Certificate handshake message failed" );
449*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST):
450*7901324dSJerome Forissier             return( "SSL - Processing of the CertificateRequest handshake message failed" );
451*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE):
452*7901324dSJerome Forissier             return( "SSL - Processing of the ServerKeyExchange handshake message failed" );
453*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE):
454*7901324dSJerome Forissier             return( "SSL - Processing of the ServerHelloDone handshake message failed" );
455*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE):
456*7901324dSJerome Forissier             return( "SSL - Processing of the ClientKeyExchange handshake message failed" );
457*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP):
458*7901324dSJerome Forissier             return( "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
459*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS):
460*7901324dSJerome Forissier             return( "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
461*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY):
462*7901324dSJerome Forissier             return( "SSL - Processing of the CertificateVerify handshake message failed" );
463*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC):
464*7901324dSJerome Forissier             return( "SSL - Processing of the ChangeCipherSpec handshake message failed" );
465*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED):
466*7901324dSJerome Forissier             return( "SSL - Processing of the Finished handshake message failed" );
467*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_ALLOC_FAILED):
468*7901324dSJerome Forissier             return( "SSL - Memory allocation failed" );
469*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED):
470*7901324dSJerome Forissier             return( "SSL - Hardware acceleration function returned with error" );
471*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH):
472*7901324dSJerome Forissier             return( "SSL - Hardware acceleration function skipped / left alone data" );
473*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED):
474*7901324dSJerome Forissier             return( "SSL - Processing of the compression / decompression failed" );
475*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION):
476*7901324dSJerome Forissier             return( "SSL - Handshake protocol not within min/max boundaries" );
477*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET):
478*7901324dSJerome Forissier             return( "SSL - Processing of the NewSessionTicket handshake message failed" );
479*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED):
480*7901324dSJerome Forissier             return( "SSL - Session ticket has expired" );
481*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH):
482*7901324dSJerome Forissier             return( "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
483*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY):
484*7901324dSJerome Forissier             return( "SSL - Unknown identity received (eg, PSK identity)" );
485*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_INTERNAL_ERROR):
486*7901324dSJerome Forissier             return( "SSL - Internal error (eg, unexpected failure in lower-level module)" );
487*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING):
488*7901324dSJerome Forissier             return( "SSL - A counter would wrap (eg, too many messages exchanged)" );
489*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO):
490*7901324dSJerome Forissier             return( "SSL - Unexpected message at ServerHello in renegotiation" );
491*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED):
492*7901324dSJerome Forissier             return( "SSL - DTLS client must retry for hello verification" );
493*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL):
494*7901324dSJerome Forissier             return( "SSL - A buffer is too small to receive or write a message" );
495*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE):
496*7901324dSJerome Forissier             return( "SSL - None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages)" );
497*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_WANT_READ):
498*7901324dSJerome Forissier             return( "SSL - No data of requested type currently available on underlying transport" );
499*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_WANT_WRITE):
500*7901324dSJerome Forissier             return( "SSL - Connection requires a write call" );
501*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_TIMEOUT):
502*7901324dSJerome Forissier             return( "SSL - The operation timed out" );
503*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT):
504*7901324dSJerome Forissier             return( "SSL - The client initiated a reconnect from the same port" );
505*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD):
506*7901324dSJerome Forissier             return( "SSL - Record header looks valid but is not expected" );
507*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_NON_FATAL):
508*7901324dSJerome Forissier             return( "SSL - The alert message received indicates a non-fatal error" );
509*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH):
510*7901324dSJerome Forissier             return( "SSL - Couldn't set the hash for verifying CertificateVerify" );
511*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_CONTINUE_PROCESSING):
512*7901324dSJerome Forissier             return( "SSL - Internal-only message signaling that further message-processing should be done" );
513*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS):
514*7901324dSJerome Forissier             return( "SSL - The asynchronous operation is not completed yet" );
515*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_EARLY_MESSAGE):
516*7901324dSJerome Forissier             return( "SSL - Internal-only message signaling that a message arrived early" );
517*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_UNEXPECTED_CID):
518*7901324dSJerome Forissier             return( "SSL - An encrypted DTLS-frame with an unexpected CID was received" );
519*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_VERSION_MISMATCH):
520*7901324dSJerome Forissier             return( "SSL - An operation failed due to an unexpected version or configuration" );
521*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS):
522*7901324dSJerome Forissier             return( "SSL - A cryptographic operation is in progress. Try again later" );
523*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SSL_BAD_CONFIG):
524*7901324dSJerome Forissier             return( "SSL - Invalid value in SSL config" );
525*7901324dSJerome Forissier #endif /* MBEDTLS_SSL_TLS_C */
526*7901324dSJerome Forissier 
527*7901324dSJerome Forissier #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
528*7901324dSJerome Forissier         case -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE):
529*7901324dSJerome Forissier             return( "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
530*7901324dSJerome Forissier         case -(MBEDTLS_ERR_X509_UNKNOWN_OID):
531*7901324dSJerome Forissier             return( "X509 - Requested OID is unknown" );
532*7901324dSJerome Forissier         case -(MBEDTLS_ERR_X509_INVALID_FORMAT):
533*7901324dSJerome Forissier             return( "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
534*7901324dSJerome Forissier         case -(MBEDTLS_ERR_X509_INVALID_VERSION):
535*7901324dSJerome Forissier             return( "X509 - The CRT/CRL/CSR version element is invalid" );
536*7901324dSJerome Forissier         case -(MBEDTLS_ERR_X509_INVALID_SERIAL):
537*7901324dSJerome Forissier             return( "X509 - The serial tag or value is invalid" );
538*7901324dSJerome Forissier         case -(MBEDTLS_ERR_X509_INVALID_ALG):
539*7901324dSJerome Forissier             return( "X509 - The algorithm tag or value is invalid" );
540*7901324dSJerome Forissier         case -(MBEDTLS_ERR_X509_INVALID_NAME):
541*7901324dSJerome Forissier             return( "X509 - The name tag or value is invalid" );
542*7901324dSJerome Forissier         case -(MBEDTLS_ERR_X509_INVALID_DATE):
543*7901324dSJerome Forissier             return( "X509 - The date tag or value is invalid" );
544*7901324dSJerome Forissier         case -(MBEDTLS_ERR_X509_INVALID_SIGNATURE):
545*7901324dSJerome Forissier             return( "X509 - The signature tag or value invalid" );
546*7901324dSJerome Forissier         case -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS):
547*7901324dSJerome Forissier             return( "X509 - The extension tag or value is invalid" );
548*7901324dSJerome Forissier         case -(MBEDTLS_ERR_X509_UNKNOWN_VERSION):
549*7901324dSJerome Forissier             return( "X509 - CRT/CRL/CSR has an unsupported version number" );
550*7901324dSJerome Forissier         case -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG):
551*7901324dSJerome Forissier             return( "X509 - Signature algorithm (oid) is unsupported" );
552*7901324dSJerome Forissier         case -(MBEDTLS_ERR_X509_SIG_MISMATCH):
553*7901324dSJerome Forissier             return( "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" );
554*7901324dSJerome Forissier         case -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED):
555*7901324dSJerome Forissier             return( "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
556*7901324dSJerome Forissier         case -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT):
557*7901324dSJerome Forissier             return( "X509 - Format not recognized as DER or PEM" );
558*7901324dSJerome Forissier         case -(MBEDTLS_ERR_X509_BAD_INPUT_DATA):
559*7901324dSJerome Forissier             return( "X509 - Input invalid" );
560*7901324dSJerome Forissier         case -(MBEDTLS_ERR_X509_ALLOC_FAILED):
561*7901324dSJerome Forissier             return( "X509 - Allocation of memory failed" );
562*7901324dSJerome Forissier         case -(MBEDTLS_ERR_X509_FILE_IO_ERROR):
563*7901324dSJerome Forissier             return( "X509 - Read/write of file failed" );
564*7901324dSJerome Forissier         case -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL):
565*7901324dSJerome Forissier             return( "X509 - Destination buffer is too small" );
566*7901324dSJerome Forissier         case -(MBEDTLS_ERR_X509_FATAL_ERROR):
567*7901324dSJerome Forissier             return( "X509 - A fatal error occurred, eg the chain is too long or the vrfy callback failed" );
568*7901324dSJerome Forissier #endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */
569*7901324dSJerome Forissier         /* End Auto-Generated Code. */
570*7901324dSJerome Forissier 
571*7901324dSJerome Forissier         default:
572*7901324dSJerome Forissier             break;
573*7901324dSJerome Forissier     }
574*7901324dSJerome Forissier 
575*7901324dSJerome Forissier     return( NULL );
576*7901324dSJerome Forissier }
577*7901324dSJerome Forissier 
578*7901324dSJerome Forissier const char * mbedtls_low_level_strerr( int error_code )
579*7901324dSJerome Forissier {
580*7901324dSJerome Forissier     int low_level_error_code;
581*7901324dSJerome Forissier 
582*7901324dSJerome Forissier     if( error_code < 0 )
583*7901324dSJerome Forissier         error_code = -error_code;
584*7901324dSJerome Forissier 
585*7901324dSJerome Forissier     /* Extract the low-level part from the error code. */
586*7901324dSJerome Forissier     low_level_error_code = error_code & ~0xFF80;
587*7901324dSJerome Forissier 
588*7901324dSJerome Forissier     switch( low_level_error_code )
589*7901324dSJerome Forissier     {
590*7901324dSJerome Forissier         /* Begin Auto-Generated Code. */
591*7901324dSJerome Forissier #if defined(MBEDTLS_AES_C)
592*7901324dSJerome Forissier         case -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH):
593*7901324dSJerome Forissier             return( "AES - Invalid key length" );
594*7901324dSJerome Forissier         case -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH):
595*7901324dSJerome Forissier             return( "AES - Invalid data input length" );
596*7901324dSJerome Forissier         case -(MBEDTLS_ERR_AES_BAD_INPUT_DATA):
597*7901324dSJerome Forissier             return( "AES - Invalid input data" );
598*7901324dSJerome Forissier         case -(MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE):
599*7901324dSJerome Forissier             return( "AES - Feature not available. For example, an unsupported AES key size" );
600*7901324dSJerome Forissier         case -(MBEDTLS_ERR_AES_HW_ACCEL_FAILED):
601*7901324dSJerome Forissier             return( "AES - AES hardware accelerator failed" );
602*7901324dSJerome Forissier #endif /* MBEDTLS_AES_C */
603*7901324dSJerome Forissier 
604*7901324dSJerome Forissier #if defined(MBEDTLS_ARC4_C)
605*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED):
606*7901324dSJerome Forissier             return( "ARC4 - ARC4 hardware accelerator failed" );
607*7901324dSJerome Forissier #endif /* MBEDTLS_ARC4_C */
608*7901324dSJerome Forissier 
609*7901324dSJerome Forissier #if defined(MBEDTLS_ARIA_C)
610*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA):
611*7901324dSJerome Forissier             return( "ARIA - Bad input data" );
612*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH):
613*7901324dSJerome Forissier             return( "ARIA - Invalid data input length" );
614*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE):
615*7901324dSJerome Forissier             return( "ARIA - Feature not available. For example, an unsupported ARIA key size" );
616*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED):
617*7901324dSJerome Forissier             return( "ARIA - ARIA hardware accelerator failed" );
618*7901324dSJerome Forissier #endif /* MBEDTLS_ARIA_C */
619*7901324dSJerome Forissier 
620*7901324dSJerome Forissier #if defined(MBEDTLS_ASN1_PARSE_C)
621*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ASN1_OUT_OF_DATA):
622*7901324dSJerome Forissier             return( "ASN1 - Out of data when parsing an ASN1 data structure" );
623*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG):
624*7901324dSJerome Forissier             return( "ASN1 - ASN1 tag was of an unexpected value" );
625*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ASN1_INVALID_LENGTH):
626*7901324dSJerome Forissier             return( "ASN1 - Error when trying to determine the length or invalid length" );
627*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH):
628*7901324dSJerome Forissier             return( "ASN1 - Actual length differs from expected length" );
629*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ASN1_INVALID_DATA):
630*7901324dSJerome Forissier             return( "ASN1 - Data is invalid" );
631*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ASN1_ALLOC_FAILED):
632*7901324dSJerome Forissier             return( "ASN1 - Memory allocation failed" );
633*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL):
634*7901324dSJerome Forissier             return( "ASN1 - Buffer too small when writing ASN.1 data structure" );
635*7901324dSJerome Forissier #endif /* MBEDTLS_ASN1_PARSE_C */
636*7901324dSJerome Forissier 
637*7901324dSJerome Forissier #if defined(MBEDTLS_BASE64_C)
638*7901324dSJerome Forissier         case -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL):
639*7901324dSJerome Forissier             return( "BASE64 - Output buffer too small" );
640*7901324dSJerome Forissier         case -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER):
641*7901324dSJerome Forissier             return( "BASE64 - Invalid character in input" );
642*7901324dSJerome Forissier #endif /* MBEDTLS_BASE64_C */
643*7901324dSJerome Forissier 
644*7901324dSJerome Forissier #if defined(MBEDTLS_BIGNUM_C)
645*7901324dSJerome Forissier         case -(MBEDTLS_ERR_MPI_FILE_IO_ERROR):
646*7901324dSJerome Forissier             return( "BIGNUM - An error occurred while reading from or writing to a file" );
647*7901324dSJerome Forissier         case -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA):
648*7901324dSJerome Forissier             return( "BIGNUM - Bad input parameters to function" );
649*7901324dSJerome Forissier         case -(MBEDTLS_ERR_MPI_INVALID_CHARACTER):
650*7901324dSJerome Forissier             return( "BIGNUM - There is an invalid character in the digit string" );
651*7901324dSJerome Forissier         case -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL):
652*7901324dSJerome Forissier             return( "BIGNUM - The buffer is too small to write to" );
653*7901324dSJerome Forissier         case -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE):
654*7901324dSJerome Forissier             return( "BIGNUM - The input arguments are negative or result in illegal output" );
655*7901324dSJerome Forissier         case -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO):
656*7901324dSJerome Forissier             return( "BIGNUM - The input argument for division is zero, which is not allowed" );
657*7901324dSJerome Forissier         case -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE):
658*7901324dSJerome Forissier             return( "BIGNUM - The input arguments are not acceptable" );
659*7901324dSJerome Forissier         case -(MBEDTLS_ERR_MPI_ALLOC_FAILED):
660*7901324dSJerome Forissier             return( "BIGNUM - Memory allocation failed" );
661*7901324dSJerome Forissier #endif /* MBEDTLS_BIGNUM_C */
662*7901324dSJerome Forissier 
663*7901324dSJerome Forissier #if defined(MBEDTLS_BLOWFISH_C)
664*7901324dSJerome Forissier         case -(MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA):
665*7901324dSJerome Forissier             return( "BLOWFISH - Bad input data" );
666*7901324dSJerome Forissier         case -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH):
667*7901324dSJerome Forissier             return( "BLOWFISH - Invalid data input length" );
668*7901324dSJerome Forissier         case -(MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED):
669*7901324dSJerome Forissier             return( "BLOWFISH - Blowfish hardware accelerator failed" );
670*7901324dSJerome Forissier #endif /* MBEDTLS_BLOWFISH_C */
671*7901324dSJerome Forissier 
672*7901324dSJerome Forissier #if defined(MBEDTLS_CAMELLIA_C)
673*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA):
674*7901324dSJerome Forissier             return( "CAMELLIA - Bad input data" );
675*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH):
676*7901324dSJerome Forissier             return( "CAMELLIA - Invalid data input length" );
677*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED):
678*7901324dSJerome Forissier             return( "CAMELLIA - Camellia hardware accelerator failed" );
679*7901324dSJerome Forissier #endif /* MBEDTLS_CAMELLIA_C */
680*7901324dSJerome Forissier 
681*7901324dSJerome Forissier #if defined(MBEDTLS_CCM_C)
682*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CCM_BAD_INPUT):
683*7901324dSJerome Forissier             return( "CCM - Bad input parameters to the function" );
684*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CCM_AUTH_FAILED):
685*7901324dSJerome Forissier             return( "CCM - Authenticated decryption failed" );
686*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CCM_HW_ACCEL_FAILED):
687*7901324dSJerome Forissier             return( "CCM - CCM hardware accelerator failed" );
688*7901324dSJerome Forissier #endif /* MBEDTLS_CCM_C */
689*7901324dSJerome Forissier 
690*7901324dSJerome Forissier #if defined(MBEDTLS_CHACHA20_C)
691*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA):
692*7901324dSJerome Forissier             return( "CHACHA20 - Invalid input parameter(s)" );
693*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE):
694*7901324dSJerome Forissier             return( "CHACHA20 - Feature not available. For example, s part of the API is not implemented" );
695*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED):
696*7901324dSJerome Forissier             return( "CHACHA20 - Chacha20 hardware accelerator failed" );
697*7901324dSJerome Forissier #endif /* MBEDTLS_CHACHA20_C */
698*7901324dSJerome Forissier 
699*7901324dSJerome Forissier #if defined(MBEDTLS_CHACHAPOLY_C)
700*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CHACHAPOLY_BAD_STATE):
701*7901324dSJerome Forissier             return( "CHACHAPOLY - The requested operation is not permitted in the current state" );
702*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED):
703*7901324dSJerome Forissier             return( "CHACHAPOLY - Authenticated decryption failed: data was not authentic" );
704*7901324dSJerome Forissier #endif /* MBEDTLS_CHACHAPOLY_C */
705*7901324dSJerome Forissier 
706*7901324dSJerome Forissier #if defined(MBEDTLS_CMAC_C)
707*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED):
708*7901324dSJerome Forissier             return( "CMAC - CMAC hardware accelerator failed" );
709*7901324dSJerome Forissier #endif /* MBEDTLS_CMAC_C */
710*7901324dSJerome Forissier 
711*7901324dSJerome Forissier #if defined(MBEDTLS_CTR_DRBG_C)
712*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED):
713*7901324dSJerome Forissier             return( "CTR_DRBG - The entropy source failed" );
714*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG):
715*7901324dSJerome Forissier             return( "CTR_DRBG - The requested random buffer length is too big" );
716*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG):
717*7901324dSJerome Forissier             return( "CTR_DRBG - The input (entropy + additional data) is too large" );
718*7901324dSJerome Forissier         case -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR):
719*7901324dSJerome Forissier             return( "CTR_DRBG - Read or write error in file" );
720*7901324dSJerome Forissier #endif /* MBEDTLS_CTR_DRBG_C */
721*7901324dSJerome Forissier 
722*7901324dSJerome Forissier #if defined(MBEDTLS_DES_C)
723*7901324dSJerome Forissier         case -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH):
724*7901324dSJerome Forissier             return( "DES - The data input has an invalid length" );
725*7901324dSJerome Forissier         case -(MBEDTLS_ERR_DES_HW_ACCEL_FAILED):
726*7901324dSJerome Forissier             return( "DES - DES hardware accelerator failed" );
727*7901324dSJerome Forissier #endif /* MBEDTLS_DES_C */
728*7901324dSJerome Forissier 
729*7901324dSJerome Forissier #if defined(MBEDTLS_ENTROPY_C)
730*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED):
731*7901324dSJerome Forissier             return( "ENTROPY - Critical entropy source failure" );
732*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES):
733*7901324dSJerome Forissier             return( "ENTROPY - No more sources can be added" );
734*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED):
735*7901324dSJerome Forissier             return( "ENTROPY - No sources have been added to poll" );
736*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE):
737*7901324dSJerome Forissier             return( "ENTROPY - No strong sources have been added to poll" );
738*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR):
739*7901324dSJerome Forissier             return( "ENTROPY - Read/write error in file" );
740*7901324dSJerome Forissier #endif /* MBEDTLS_ENTROPY_C */
741*7901324dSJerome Forissier 
742*7901324dSJerome Forissier #if defined(MBEDTLS_ERROR_C)
743*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ERROR_GENERIC_ERROR):
744*7901324dSJerome Forissier             return( "ERROR - Generic error" );
745*7901324dSJerome Forissier         case -(MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED):
746*7901324dSJerome Forissier             return( "ERROR - This is a bug in the library" );
747*7901324dSJerome Forissier #endif /* MBEDTLS_ERROR_C */
748*7901324dSJerome Forissier 
749*7901324dSJerome Forissier #if defined(MBEDTLS_GCM_C)
750*7901324dSJerome Forissier         case -(MBEDTLS_ERR_GCM_AUTH_FAILED):
751*7901324dSJerome Forissier             return( "GCM - Authenticated decryption failed" );
752*7901324dSJerome Forissier         case -(MBEDTLS_ERR_GCM_HW_ACCEL_FAILED):
753*7901324dSJerome Forissier             return( "GCM - GCM hardware accelerator failed" );
754*7901324dSJerome Forissier         case -(MBEDTLS_ERR_GCM_BAD_INPUT):
755*7901324dSJerome Forissier             return( "GCM - Bad input parameters to function" );
756*7901324dSJerome Forissier #endif /* MBEDTLS_GCM_C */
757*7901324dSJerome Forissier 
758*7901324dSJerome Forissier #if defined(MBEDTLS_HKDF_C)
759*7901324dSJerome Forissier         case -(MBEDTLS_ERR_HKDF_BAD_INPUT_DATA):
760*7901324dSJerome Forissier             return( "HKDF - Bad input parameters to function" );
761*7901324dSJerome Forissier #endif /* MBEDTLS_HKDF_C */
762*7901324dSJerome Forissier 
763*7901324dSJerome Forissier #if defined(MBEDTLS_HMAC_DRBG_C)
764*7901324dSJerome Forissier         case -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG):
765*7901324dSJerome Forissier             return( "HMAC_DRBG - Too many random requested in single call" );
766*7901324dSJerome Forissier         case -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG):
767*7901324dSJerome Forissier             return( "HMAC_DRBG - Input too large (Entropy + additional)" );
768*7901324dSJerome Forissier         case -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR):
769*7901324dSJerome Forissier             return( "HMAC_DRBG - Read/write error in file" );
770*7901324dSJerome Forissier         case -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED):
771*7901324dSJerome Forissier             return( "HMAC_DRBG - The entropy source failed" );
772*7901324dSJerome Forissier #endif /* MBEDTLS_HMAC_DRBG_C */
773*7901324dSJerome Forissier 
774*7901324dSJerome Forissier #if defined(MBEDTLS_MD2_C)
775*7901324dSJerome Forissier         case -(MBEDTLS_ERR_MD2_HW_ACCEL_FAILED):
776*7901324dSJerome Forissier             return( "MD2 - MD2 hardware accelerator failed" );
777*7901324dSJerome Forissier #endif /* MBEDTLS_MD2_C */
778*7901324dSJerome Forissier 
779*7901324dSJerome Forissier #if defined(MBEDTLS_MD4_C)
780*7901324dSJerome Forissier         case -(MBEDTLS_ERR_MD4_HW_ACCEL_FAILED):
781*7901324dSJerome Forissier             return( "MD4 - MD4 hardware accelerator failed" );
782*7901324dSJerome Forissier #endif /* MBEDTLS_MD4_C */
783*7901324dSJerome Forissier 
784*7901324dSJerome Forissier #if defined(MBEDTLS_MD5_C)
785*7901324dSJerome Forissier         case -(MBEDTLS_ERR_MD5_HW_ACCEL_FAILED):
786*7901324dSJerome Forissier             return( "MD5 - MD5 hardware accelerator failed" );
787*7901324dSJerome Forissier #endif /* MBEDTLS_MD5_C */
788*7901324dSJerome Forissier 
789*7901324dSJerome Forissier #if defined(MBEDTLS_NET_C)
790*7901324dSJerome Forissier         case -(MBEDTLS_ERR_NET_SOCKET_FAILED):
791*7901324dSJerome Forissier             return( "NET - Failed to open a socket" );
792*7901324dSJerome Forissier         case -(MBEDTLS_ERR_NET_CONNECT_FAILED):
793*7901324dSJerome Forissier             return( "NET - The connection to the given server / port failed" );
794*7901324dSJerome Forissier         case -(MBEDTLS_ERR_NET_BIND_FAILED):
795*7901324dSJerome Forissier             return( "NET - Binding of the socket failed" );
796*7901324dSJerome Forissier         case -(MBEDTLS_ERR_NET_LISTEN_FAILED):
797*7901324dSJerome Forissier             return( "NET - Could not listen on the socket" );
798*7901324dSJerome Forissier         case -(MBEDTLS_ERR_NET_ACCEPT_FAILED):
799*7901324dSJerome Forissier             return( "NET - Could not accept the incoming connection" );
800*7901324dSJerome Forissier         case -(MBEDTLS_ERR_NET_RECV_FAILED):
801*7901324dSJerome Forissier             return( "NET - Reading information from the socket failed" );
802*7901324dSJerome Forissier         case -(MBEDTLS_ERR_NET_SEND_FAILED):
803*7901324dSJerome Forissier             return( "NET - Sending information through the socket failed" );
804*7901324dSJerome Forissier         case -(MBEDTLS_ERR_NET_CONN_RESET):
805*7901324dSJerome Forissier             return( "NET - Connection was reset by peer" );
806*7901324dSJerome Forissier         case -(MBEDTLS_ERR_NET_UNKNOWN_HOST):
807*7901324dSJerome Forissier             return( "NET - Failed to get an IP address for the given hostname" );
808*7901324dSJerome Forissier         case -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL):
809*7901324dSJerome Forissier             return( "NET - Buffer is too small to hold the data" );
810*7901324dSJerome Forissier         case -(MBEDTLS_ERR_NET_INVALID_CONTEXT):
811*7901324dSJerome Forissier             return( "NET - The context is invalid, eg because it was free()ed" );
812*7901324dSJerome Forissier         case -(MBEDTLS_ERR_NET_POLL_FAILED):
813*7901324dSJerome Forissier             return( "NET - Polling the net context failed" );
814*7901324dSJerome Forissier         case -(MBEDTLS_ERR_NET_BAD_INPUT_DATA):
815*7901324dSJerome Forissier             return( "NET - Input invalid" );
816*7901324dSJerome Forissier #endif /* MBEDTLS_NET_C */
817*7901324dSJerome Forissier 
818*7901324dSJerome Forissier #if defined(MBEDTLS_OID_C)
819*7901324dSJerome Forissier         case -(MBEDTLS_ERR_OID_NOT_FOUND):
820*7901324dSJerome Forissier             return( "OID - OID is not found" );
821*7901324dSJerome Forissier         case -(MBEDTLS_ERR_OID_BUF_TOO_SMALL):
822*7901324dSJerome Forissier             return( "OID - output buffer is too small" );
823*7901324dSJerome Forissier #endif /* MBEDTLS_OID_C */
824*7901324dSJerome Forissier 
825*7901324dSJerome Forissier #if defined(MBEDTLS_PADLOCK_C)
826*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED):
827*7901324dSJerome Forissier             return( "PADLOCK - Input data should be aligned" );
828*7901324dSJerome Forissier #endif /* MBEDTLS_PADLOCK_C */
829*7901324dSJerome Forissier 
830*7901324dSJerome Forissier #if defined(MBEDTLS_PLATFORM_C)
831*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED):
832*7901324dSJerome Forissier             return( "PLATFORM - Hardware accelerator failed" );
833*7901324dSJerome Forissier         case -(MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED):
834*7901324dSJerome Forissier             return( "PLATFORM - The requested feature is not supported by the platform" );
835*7901324dSJerome Forissier #endif /* MBEDTLS_PLATFORM_C */
836*7901324dSJerome Forissier 
837*7901324dSJerome Forissier #if defined(MBEDTLS_POLY1305_C)
838*7901324dSJerome Forissier         case -(MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA):
839*7901324dSJerome Forissier             return( "POLY1305 - Invalid input parameter(s)" );
840*7901324dSJerome Forissier         case -(MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE):
841*7901324dSJerome Forissier             return( "POLY1305 - Feature not available. For example, s part of the API is not implemented" );
842*7901324dSJerome Forissier         case -(MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED):
843*7901324dSJerome Forissier             return( "POLY1305 - Poly1305 hardware accelerator failed" );
844*7901324dSJerome Forissier #endif /* MBEDTLS_POLY1305_C */
845*7901324dSJerome Forissier 
846*7901324dSJerome Forissier #if defined(MBEDTLS_RIPEMD160_C)
847*7901324dSJerome Forissier         case -(MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED):
848*7901324dSJerome Forissier             return( "RIPEMD160 - RIPEMD160 hardware accelerator failed" );
849*7901324dSJerome Forissier #endif /* MBEDTLS_RIPEMD160_C */
850*7901324dSJerome Forissier 
851*7901324dSJerome Forissier #if defined(MBEDTLS_SHA1_C)
852*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED):
853*7901324dSJerome Forissier             return( "SHA1 - SHA-1 hardware accelerator failed" );
854*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SHA1_BAD_INPUT_DATA):
855*7901324dSJerome Forissier             return( "SHA1 - SHA-1 input data was malformed" );
856*7901324dSJerome Forissier #endif /* MBEDTLS_SHA1_C */
857*7901324dSJerome Forissier 
858*7901324dSJerome Forissier #if defined(MBEDTLS_SHA256_C)
859*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED):
860*7901324dSJerome Forissier             return( "SHA256 - SHA-256 hardware accelerator failed" );
861*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SHA256_BAD_INPUT_DATA):
862*7901324dSJerome Forissier             return( "SHA256 - SHA-256 input data was malformed" );
863*7901324dSJerome Forissier #endif /* MBEDTLS_SHA256_C */
864*7901324dSJerome Forissier 
865*7901324dSJerome Forissier #if defined(MBEDTLS_SHA512_C)
866*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED):
867*7901324dSJerome Forissier             return( "SHA512 - SHA-512 hardware accelerator failed" );
868*7901324dSJerome Forissier         case -(MBEDTLS_ERR_SHA512_BAD_INPUT_DATA):
869*7901324dSJerome Forissier             return( "SHA512 - SHA-512 input data was malformed" );
870*7901324dSJerome Forissier #endif /* MBEDTLS_SHA512_C */
871*7901324dSJerome Forissier 
872*7901324dSJerome Forissier #if defined(MBEDTLS_THREADING_C)
873*7901324dSJerome Forissier         case -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE):
874*7901324dSJerome Forissier             return( "THREADING - The selected feature is not available" );
875*7901324dSJerome Forissier         case -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA):
876*7901324dSJerome Forissier             return( "THREADING - Bad input parameters to function" );
877*7901324dSJerome Forissier         case -(MBEDTLS_ERR_THREADING_MUTEX_ERROR):
878*7901324dSJerome Forissier             return( "THREADING - Locking / unlocking / free failed with error code" );
879*7901324dSJerome Forissier #endif /* MBEDTLS_THREADING_C */
880*7901324dSJerome Forissier 
881*7901324dSJerome Forissier #if defined(MBEDTLS_XTEA_C)
882*7901324dSJerome Forissier         case -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH):
883*7901324dSJerome Forissier             return( "XTEA - The data input has an invalid length" );
884*7901324dSJerome Forissier         case -(MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED):
885*7901324dSJerome Forissier             return( "XTEA - XTEA hardware accelerator failed" );
886*7901324dSJerome Forissier #endif /* MBEDTLS_XTEA_C */
887*7901324dSJerome Forissier         /* End Auto-Generated Code. */
888*7901324dSJerome Forissier 
889*7901324dSJerome Forissier         default:
890*7901324dSJerome Forissier             break;
891*7901324dSJerome Forissier     }
892*7901324dSJerome Forissier 
893*7901324dSJerome Forissier     return( NULL );
894*7901324dSJerome Forissier }
895*7901324dSJerome Forissier 
896817466cbSJens Wiklander void mbedtls_strerror( int ret, char *buf, size_t buflen )
897817466cbSJens Wiklander {
898817466cbSJens Wiklander     size_t len;
899817466cbSJens Wiklander     int use_ret;
900*7901324dSJerome Forissier     const char * high_level_error_description = NULL;
901*7901324dSJerome Forissier     const char * low_level_error_description = NULL;
902817466cbSJens Wiklander 
903817466cbSJens Wiklander     if( buflen == 0 )
904817466cbSJens Wiklander         return;
905817466cbSJens Wiklander 
906817466cbSJens Wiklander     memset( buf, 0x00, buflen );
907817466cbSJens Wiklander 
908817466cbSJens Wiklander     if( ret < 0 )
909817466cbSJens Wiklander         ret = -ret;
910817466cbSJens Wiklander 
911817466cbSJens Wiklander     if( ret & 0xFF80 )
912817466cbSJens Wiklander     {
913817466cbSJens Wiklander         use_ret = ret & 0xFF80;
914817466cbSJens Wiklander 
915*7901324dSJerome Forissier         // Translate high level error code.
916*7901324dSJerome Forissier         high_level_error_description = mbedtls_high_level_strerr( ret );
917817466cbSJens Wiklander 
918*7901324dSJerome Forissier         if( high_level_error_description == NULL )
919*7901324dSJerome Forissier             mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", (unsigned int) use_ret );
920*7901324dSJerome Forissier         else
921*7901324dSJerome Forissier             mbedtls_snprintf( buf, buflen, "%s", high_level_error_description );
922817466cbSJens Wiklander 
923817466cbSJens Wiklander #if defined(MBEDTLS_SSL_TLS_C)
924*7901324dSJerome Forissier         // Early return in case of a fatal error - do not try to translate low
925*7901324dSJerome Forissier         // level code.
926817466cbSJens Wiklander         if(use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE))
927817466cbSJens Wiklander             return;
928817466cbSJens Wiklander #endif /* MBEDTLS_SSL_TLS_C */
929817466cbSJens Wiklander     }
930817466cbSJens Wiklander 
931817466cbSJens Wiklander     use_ret = ret & ~0xFF80;
932817466cbSJens Wiklander 
933817466cbSJens Wiklander     if( use_ret == 0 )
934817466cbSJens Wiklander         return;
935817466cbSJens Wiklander 
936817466cbSJens Wiklander     // If high level code is present, make a concatenation between both
937817466cbSJens Wiklander     // error strings.
938817466cbSJens Wiklander     //
939817466cbSJens Wiklander     len = strlen( buf );
940817466cbSJens Wiklander 
941817466cbSJens Wiklander     if( len > 0 )
942817466cbSJens Wiklander     {
943817466cbSJens Wiklander         if( buflen - len < 5 )
944817466cbSJens Wiklander             return;
945817466cbSJens Wiklander 
946817466cbSJens Wiklander         mbedtls_snprintf( buf + len, buflen - len, " : " );
947817466cbSJens Wiklander 
948817466cbSJens Wiklander         buf += len + 3;
949817466cbSJens Wiklander         buflen -= len + 3;
950817466cbSJens Wiklander     }
951817466cbSJens Wiklander 
952*7901324dSJerome Forissier     // Translate low level error code.
953*7901324dSJerome Forissier     low_level_error_description = mbedtls_low_level_strerr( ret );
954817466cbSJens Wiklander 
955*7901324dSJerome Forissier     if( low_level_error_description == NULL )
956*7901324dSJerome Forissier         mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", (unsigned int) use_ret );
957*7901324dSJerome Forissier     else
958*7901324dSJerome Forissier         mbedtls_snprintf( buf, buflen, "%s", low_level_error_description );
959817466cbSJens Wiklander }
960817466cbSJens Wiklander 
961817466cbSJens Wiklander #else /* MBEDTLS_ERROR_C */
962817466cbSJens Wiklander 
963817466cbSJens Wiklander /*
964817466cbSJens Wiklander  * Provide an non-function in case MBEDTLS_ERROR_C is not defined
965817466cbSJens Wiklander  */
966817466cbSJens Wiklander void mbedtls_strerror( int ret, char *buf, size_t buflen )
967817466cbSJens Wiklander {
968817466cbSJens Wiklander     ((void) ret);
969817466cbSJens Wiklander 
970817466cbSJens Wiklander     if( buflen > 0 )
971817466cbSJens Wiklander         buf[0] = '\0';
972817466cbSJens Wiklander }
973817466cbSJens Wiklander 
974817466cbSJens Wiklander #endif /* MBEDTLS_ERROR_C */
975*7901324dSJerome Forissier 
976*7901324dSJerome Forissier #if defined(MBEDTLS_TEST_HOOKS)
977*7901324dSJerome Forissier void (*mbedtls_test_hook_error_add)( int, int, const char *, int );
978*7901324dSJerome Forissier #endif
979*7901324dSJerome Forissier 
980*7901324dSJerome Forissier #endif /* MBEDTLS_ERROR_C || MBEDTLS_ERROR_STRERROR_DUMMY */
981