1817466cbSJens Wiklander /* 2817466cbSJens Wiklander * Error message information 3817466cbSJens Wiklander * 47901324dSJerome Forissier * Copyright The Mbed TLS Contributors 57901324dSJerome 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 207901324dSJerome Forissier #include "common.h" 21817466cbSJens Wiklander 227901324dSJerome Forissier #include "mbedtls/error.h" 237901324dSJerome Forissier 247901324dSJerome Forissier #if defined(MBEDTLS_ERROR_C) || defined(MBEDTLS_ERROR_STRERROR_DUMMY) 257901324dSJerome Forissier 267901324dSJerome Forissier #if defined(MBEDTLS_ERROR_C) 27817466cbSJens Wiklander 28817466cbSJens Wiklander #include "mbedtls/platform.h" 29817466cbSJens Wiklander 30817466cbSJens Wiklander #include <stdio.h> 317901324dSJerome Forissier #include <string.h> 32817466cbSJens Wiklander 33817466cbSJens Wiklander #if defined(MBEDTLS_AES_C) 34817466cbSJens Wiklander #include "mbedtls/aes.h" 35817466cbSJens Wiklander #endif 36817466cbSJens Wiklander 373d3b0591SJens Wiklander #if defined(MBEDTLS_ARIA_C) 383d3b0591SJens Wiklander #include "mbedtls/aria.h" 393d3b0591SJens Wiklander #endif 403d3b0591SJens Wiklander 417901324dSJerome Forissier #if defined(MBEDTLS_ASN1_PARSE_C) 427901324dSJerome Forissier #include "mbedtls/asn1.h" 437901324dSJerome Forissier #endif 447901324dSJerome Forissier 45817466cbSJens Wiklander #if defined(MBEDTLS_BASE64_C) 46817466cbSJens Wiklander #include "mbedtls/base64.h" 47817466cbSJens Wiklander #endif 48817466cbSJens Wiklander 49817466cbSJens Wiklander #if defined(MBEDTLS_BIGNUM_C) 50817466cbSJens Wiklander #include "mbedtls/bignum.h" 51817466cbSJens Wiklander #endif 52817466cbSJens Wiklander 53817466cbSJens Wiklander #if defined(MBEDTLS_CAMELLIA_C) 54817466cbSJens Wiklander #include "mbedtls/camellia.h" 55817466cbSJens Wiklander #endif 56817466cbSJens Wiklander 57817466cbSJens Wiklander #if defined(MBEDTLS_CCM_C) 58817466cbSJens Wiklander #include "mbedtls/ccm.h" 59817466cbSJens Wiklander #endif 60817466cbSJens Wiklander 613d3b0591SJens Wiklander #if defined(MBEDTLS_CHACHA20_C) 623d3b0591SJens Wiklander #include "mbedtls/chacha20.h" 633d3b0591SJens Wiklander #endif 643d3b0591SJens Wiklander 653d3b0591SJens Wiklander #if defined(MBEDTLS_CHACHAPOLY_C) 663d3b0591SJens Wiklander #include "mbedtls/chachapoly.h" 673d3b0591SJens Wiklander #endif 683d3b0591SJens Wiklander 69817466cbSJens Wiklander #if defined(MBEDTLS_CIPHER_C) 70817466cbSJens Wiklander #include "mbedtls/cipher.h" 71817466cbSJens Wiklander #endif 72817466cbSJens Wiklander 73817466cbSJens Wiklander #if defined(MBEDTLS_CTR_DRBG_C) 74817466cbSJens Wiklander #include "mbedtls/ctr_drbg.h" 75817466cbSJens Wiklander #endif 76817466cbSJens Wiklander 77817466cbSJens Wiklander #if defined(MBEDTLS_DES_C) 78817466cbSJens Wiklander #include "mbedtls/des.h" 79817466cbSJens Wiklander #endif 80817466cbSJens Wiklander 81817466cbSJens Wiklander #if defined(MBEDTLS_DHM_C) 82817466cbSJens Wiklander #include "mbedtls/dhm.h" 83817466cbSJens Wiklander #endif 84817466cbSJens Wiklander 85817466cbSJens Wiklander #if defined(MBEDTLS_ECP_C) 86817466cbSJens Wiklander #include "mbedtls/ecp.h" 87817466cbSJens Wiklander #endif 88817466cbSJens Wiklander 89817466cbSJens Wiklander #if defined(MBEDTLS_ENTROPY_C) 90817466cbSJens Wiklander #include "mbedtls/entropy.h" 91817466cbSJens Wiklander #endif 92817466cbSJens Wiklander 9311fa71b9SJerome Forissier #if defined(MBEDTLS_ERROR_C) 9411fa71b9SJerome Forissier #include "mbedtls/error.h" 9511fa71b9SJerome Forissier #endif 9611fa71b9SJerome Forissier 97*32b31808SJens Wiklander #if defined(MBEDTLS_PLATFORM_C) 98*32b31808SJens Wiklander #include "mbedtls/platform.h" 99*32b31808SJens Wiklander #endif 100*32b31808SJens Wiklander 101817466cbSJens Wiklander #if defined(MBEDTLS_GCM_C) 102817466cbSJens Wiklander #include "mbedtls/gcm.h" 103817466cbSJens Wiklander #endif 104817466cbSJens Wiklander 1053d3b0591SJens Wiklander #if defined(MBEDTLS_HKDF_C) 1063d3b0591SJens Wiklander #include "mbedtls/hkdf.h" 1073d3b0591SJens Wiklander #endif 1083d3b0591SJens Wiklander 109817466cbSJens Wiklander #if defined(MBEDTLS_HMAC_DRBG_C) 110817466cbSJens Wiklander #include "mbedtls/hmac_drbg.h" 111817466cbSJens Wiklander #endif 112817466cbSJens Wiklander 113*32b31808SJens Wiklander #if defined(MBEDTLS_LMS_C) 114*32b31808SJens Wiklander #include "mbedtls/lms.h" 115*32b31808SJens Wiklander #endif 116*32b31808SJens Wiklander 117817466cbSJens Wiklander #if defined(MBEDTLS_MD_C) 118817466cbSJens Wiklander #include "mbedtls/md.h" 119817466cbSJens Wiklander #endif 120817466cbSJens Wiklander 121817466cbSJens Wiklander #if defined(MBEDTLS_NET_C) 122817466cbSJens Wiklander #include "mbedtls/net_sockets.h" 123817466cbSJens Wiklander #endif 124817466cbSJens Wiklander 125817466cbSJens Wiklander #if defined(MBEDTLS_OID_C) 126817466cbSJens Wiklander #include "mbedtls/oid.h" 127817466cbSJens Wiklander #endif 128817466cbSJens Wiklander 129817466cbSJens Wiklander #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C) 130817466cbSJens Wiklander #include "mbedtls/pem.h" 131817466cbSJens Wiklander #endif 132817466cbSJens Wiklander 133817466cbSJens Wiklander #if defined(MBEDTLS_PK_C) 134817466cbSJens Wiklander #include "mbedtls/pk.h" 135817466cbSJens Wiklander #endif 136817466cbSJens Wiklander 137817466cbSJens Wiklander #if defined(MBEDTLS_PKCS12_C) 138817466cbSJens Wiklander #include "mbedtls/pkcs12.h" 139817466cbSJens Wiklander #endif 140817466cbSJens Wiklander 141817466cbSJens Wiklander #if defined(MBEDTLS_PKCS5_C) 142817466cbSJens Wiklander #include "mbedtls/pkcs5.h" 143817466cbSJens Wiklander #endif 144817466cbSJens Wiklander 145*32b31808SJens Wiklander #if defined(MBEDTLS_PKCS7_C) 146*32b31808SJens Wiklander #include "mbedtls/pkcs7.h" 1473d3b0591SJens Wiklander #endif 1483d3b0591SJens Wiklander 1493d3b0591SJens Wiklander #if defined(MBEDTLS_POLY1305_C) 1503d3b0591SJens Wiklander #include "mbedtls/poly1305.h" 1513d3b0591SJens Wiklander #endif 1523d3b0591SJens Wiklander 153817466cbSJens Wiklander #if defined(MBEDTLS_RSA_C) 154817466cbSJens Wiklander #include "mbedtls/rsa.h" 155817466cbSJens Wiklander #endif 156817466cbSJens Wiklander 1573d3b0591SJens Wiklander #if defined(MBEDTLS_SHA1_C) 1583d3b0591SJens Wiklander #include "mbedtls/sha1.h" 1593d3b0591SJens Wiklander #endif 1603d3b0591SJens Wiklander 1613d3b0591SJens Wiklander #if defined(MBEDTLS_SHA256_C) 1623d3b0591SJens Wiklander #include "mbedtls/sha256.h" 1633d3b0591SJens Wiklander #endif 1643d3b0591SJens Wiklander 1653d3b0591SJens Wiklander #if defined(MBEDTLS_SHA512_C) 1663d3b0591SJens Wiklander #include "mbedtls/sha512.h" 1673d3b0591SJens Wiklander #endif 1683d3b0591SJens Wiklander 169817466cbSJens Wiklander #if defined(MBEDTLS_SSL_TLS_C) 170817466cbSJens Wiklander #include "mbedtls/ssl.h" 171817466cbSJens Wiklander #endif 172817466cbSJens Wiklander 173817466cbSJens Wiklander #if defined(MBEDTLS_THREADING_C) 174817466cbSJens Wiklander #include "mbedtls/threading.h" 175817466cbSJens Wiklander #endif 176817466cbSJens Wiklander 177817466cbSJens Wiklander #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C) 178817466cbSJens Wiklander #include "mbedtls/x509.h" 179817466cbSJens Wiklander #endif 180817466cbSJens Wiklander 181817466cbSJens Wiklander 1827901324dSJerome Forissier const char *mbedtls_high_level_strerr(int error_code) 1837901324dSJerome Forissier { 1847901324dSJerome Forissier int high_level_error_code; 1857901324dSJerome Forissier 186*32b31808SJens Wiklander if (error_code < 0) { 1877901324dSJerome Forissier error_code = -error_code; 188*32b31808SJens Wiklander } 1897901324dSJerome Forissier 1907901324dSJerome Forissier /* Extract the high-level part from the error code. */ 1917901324dSJerome Forissier high_level_error_code = error_code & 0xFF80; 1927901324dSJerome Forissier 193*32b31808SJens Wiklander switch (high_level_error_code) { 1947901324dSJerome Forissier /* Begin Auto-Generated Code. */ 1957901324dSJerome Forissier #if defined(MBEDTLS_CIPHER_C) 1967901324dSJerome Forissier case -(MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE): 1977901324dSJerome Forissier return( "CIPHER - The selected feature is not available" ); 1987901324dSJerome Forissier case -(MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA): 1997901324dSJerome Forissier return( "CIPHER - Bad input parameters" ); 2007901324dSJerome Forissier case -(MBEDTLS_ERR_CIPHER_ALLOC_FAILED): 2017901324dSJerome Forissier return( "CIPHER - Failed to allocate memory" ); 2027901324dSJerome Forissier case -(MBEDTLS_ERR_CIPHER_INVALID_PADDING): 2037901324dSJerome Forissier return( "CIPHER - Input data contains invalid padding and is rejected" ); 2047901324dSJerome Forissier case -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED): 2057901324dSJerome Forissier return( "CIPHER - Decryption of block requires a full block" ); 2067901324dSJerome Forissier case -(MBEDTLS_ERR_CIPHER_AUTH_FAILED): 2077901324dSJerome Forissier return( "CIPHER - Authentication failed (for AEAD modes)" ); 2087901324dSJerome Forissier case -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT): 2097901324dSJerome Forissier return( "CIPHER - The context is invalid. For example, because it was freed" ); 2107901324dSJerome Forissier #endif /* MBEDTLS_CIPHER_C */ 2117901324dSJerome Forissier 2127901324dSJerome Forissier #if defined(MBEDTLS_DHM_C) 2137901324dSJerome Forissier case -(MBEDTLS_ERR_DHM_BAD_INPUT_DATA): 2147901324dSJerome Forissier return( "DHM - Bad input parameters" ); 2157901324dSJerome Forissier case -(MBEDTLS_ERR_DHM_READ_PARAMS_FAILED): 2167901324dSJerome Forissier return( "DHM - Reading of the DHM parameters failed" ); 2177901324dSJerome Forissier case -(MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED): 2187901324dSJerome Forissier return( "DHM - Making of the DHM parameters failed" ); 2197901324dSJerome Forissier case -(MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED): 2207901324dSJerome Forissier return( "DHM - Reading of the public values failed" ); 2217901324dSJerome Forissier case -(MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED): 2227901324dSJerome Forissier return( "DHM - Making of the public value failed" ); 2237901324dSJerome Forissier case -(MBEDTLS_ERR_DHM_CALC_SECRET_FAILED): 2247901324dSJerome Forissier return( "DHM - Calculation of the DHM secret failed" ); 2257901324dSJerome Forissier case -(MBEDTLS_ERR_DHM_INVALID_FORMAT): 2267901324dSJerome Forissier return( "DHM - The ASN.1 data is not formatted correctly" ); 2277901324dSJerome Forissier case -(MBEDTLS_ERR_DHM_ALLOC_FAILED): 2287901324dSJerome Forissier return( "DHM - Allocation of memory failed" ); 2297901324dSJerome Forissier case -(MBEDTLS_ERR_DHM_FILE_IO_ERROR): 2307901324dSJerome Forissier return( "DHM - Read or write of file failed" ); 2317901324dSJerome Forissier case -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED): 2327901324dSJerome Forissier return( "DHM - Setting the modulus and generator failed" ); 2337901324dSJerome Forissier #endif /* MBEDTLS_DHM_C */ 2347901324dSJerome Forissier 2357901324dSJerome Forissier #if defined(MBEDTLS_ECP_C) 2367901324dSJerome Forissier case -(MBEDTLS_ERR_ECP_BAD_INPUT_DATA): 2377901324dSJerome Forissier return( "ECP - Bad input parameters to function" ); 2387901324dSJerome Forissier case -(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL): 2397901324dSJerome Forissier return( "ECP - The buffer is too small to write to" ); 2407901324dSJerome Forissier case -(MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE): 2417901324dSJerome Forissier return( "ECP - The requested feature is not available, for example, the requested curve is not supported" ); 2427901324dSJerome Forissier case -(MBEDTLS_ERR_ECP_VERIFY_FAILED): 2437901324dSJerome Forissier return( "ECP - The signature is not valid" ); 2447901324dSJerome Forissier case -(MBEDTLS_ERR_ECP_ALLOC_FAILED): 2457901324dSJerome Forissier return( "ECP - Memory allocation failed" ); 2467901324dSJerome Forissier case -(MBEDTLS_ERR_ECP_RANDOM_FAILED): 2477901324dSJerome Forissier return( "ECP - Generation of random value, such as ephemeral key, failed" ); 2487901324dSJerome Forissier case -(MBEDTLS_ERR_ECP_INVALID_KEY): 2497901324dSJerome Forissier return( "ECP - Invalid private or public key" ); 2507901324dSJerome Forissier case -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH): 2517901324dSJerome Forissier return( "ECP - The buffer contains a valid signature followed by more data" ); 2527901324dSJerome Forissier case -(MBEDTLS_ERR_ECP_IN_PROGRESS): 2537901324dSJerome Forissier return( "ECP - Operation in progress, call again with the same parameters to continue" ); 2547901324dSJerome Forissier #endif /* MBEDTLS_ECP_C */ 2557901324dSJerome Forissier 2567901324dSJerome Forissier #if defined(MBEDTLS_MD_C) 2577901324dSJerome Forissier case -(MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE): 2587901324dSJerome Forissier return( "MD - The selected feature is not available" ); 2597901324dSJerome Forissier case -(MBEDTLS_ERR_MD_BAD_INPUT_DATA): 2607901324dSJerome Forissier return( "MD - Bad input parameters to function" ); 2617901324dSJerome Forissier case -(MBEDTLS_ERR_MD_ALLOC_FAILED): 2627901324dSJerome Forissier return( "MD - Failed to allocate memory" ); 2637901324dSJerome Forissier case -(MBEDTLS_ERR_MD_FILE_IO_ERROR): 2647901324dSJerome Forissier return( "MD - Opening or reading of file failed" ); 2657901324dSJerome Forissier #endif /* MBEDTLS_MD_C */ 2667901324dSJerome Forissier 2677901324dSJerome Forissier #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C) 2687901324dSJerome Forissier case -(MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT): 2697901324dSJerome Forissier return( "PEM - No PEM header or footer found" ); 2707901324dSJerome Forissier case -(MBEDTLS_ERR_PEM_INVALID_DATA): 2717901324dSJerome Forissier return( "PEM - PEM string is not as expected" ); 2727901324dSJerome Forissier case -(MBEDTLS_ERR_PEM_ALLOC_FAILED): 2737901324dSJerome Forissier return( "PEM - Failed to allocate memory" ); 2747901324dSJerome Forissier case -(MBEDTLS_ERR_PEM_INVALID_ENC_IV): 2757901324dSJerome Forissier return( "PEM - RSA IV is not in hex-format" ); 2767901324dSJerome Forissier case -(MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG): 2777901324dSJerome Forissier return( "PEM - Unsupported key encryption algorithm" ); 2787901324dSJerome Forissier case -(MBEDTLS_ERR_PEM_PASSWORD_REQUIRED): 2797901324dSJerome Forissier return( "PEM - Private key password can't be empty" ); 2807901324dSJerome Forissier case -(MBEDTLS_ERR_PEM_PASSWORD_MISMATCH): 2817901324dSJerome Forissier return( "PEM - Given private key password does not allow for correct decryption" ); 2827901324dSJerome Forissier case -(MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE): 2837901324dSJerome Forissier return( "PEM - Unavailable feature, e.g. hashing/encryption combination" ); 2847901324dSJerome Forissier case -(MBEDTLS_ERR_PEM_BAD_INPUT_DATA): 2857901324dSJerome Forissier return( "PEM - Bad input parameters to function" ); 2867901324dSJerome Forissier #endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */ 2877901324dSJerome Forissier 2887901324dSJerome Forissier #if defined(MBEDTLS_PK_C) 2897901324dSJerome Forissier case -(MBEDTLS_ERR_PK_ALLOC_FAILED): 2907901324dSJerome Forissier return( "PK - Memory allocation failed" ); 2917901324dSJerome Forissier case -(MBEDTLS_ERR_PK_TYPE_MISMATCH): 2927901324dSJerome Forissier return( "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" ); 2937901324dSJerome Forissier case -(MBEDTLS_ERR_PK_BAD_INPUT_DATA): 2947901324dSJerome Forissier return( "PK - Bad input parameters to function" ); 2957901324dSJerome Forissier case -(MBEDTLS_ERR_PK_FILE_IO_ERROR): 2967901324dSJerome Forissier return( "PK - Read/write of file failed" ); 2977901324dSJerome Forissier case -(MBEDTLS_ERR_PK_KEY_INVALID_VERSION): 2987901324dSJerome Forissier return( "PK - Unsupported key version" ); 2997901324dSJerome Forissier case -(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT): 3007901324dSJerome Forissier return( "PK - Invalid key tag or value" ); 3017901324dSJerome Forissier case -(MBEDTLS_ERR_PK_UNKNOWN_PK_ALG): 3027901324dSJerome Forissier return( "PK - Key algorithm is unsupported (only RSA and EC are supported)" ); 3037901324dSJerome Forissier case -(MBEDTLS_ERR_PK_PASSWORD_REQUIRED): 3047901324dSJerome Forissier return( "PK - Private key password can't be empty" ); 3057901324dSJerome Forissier case -(MBEDTLS_ERR_PK_PASSWORD_MISMATCH): 3067901324dSJerome Forissier return( "PK - Given private key password does not allow for correct decryption" ); 3077901324dSJerome Forissier case -(MBEDTLS_ERR_PK_INVALID_PUBKEY): 3087901324dSJerome Forissier return( "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" ); 3097901324dSJerome Forissier case -(MBEDTLS_ERR_PK_INVALID_ALG): 3107901324dSJerome Forissier return( "PK - The algorithm tag or value is invalid" ); 3117901324dSJerome Forissier case -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE): 3127901324dSJerome Forissier return( "PK - Elliptic curve is unsupported (only NIST curves are supported)" ); 3137901324dSJerome Forissier case -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE): 3147901324dSJerome Forissier return( "PK - Unavailable feature, e.g. RSA disabled for RSA key" ); 3157901324dSJerome Forissier case -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH): 3167901324dSJerome Forissier return( "PK - The buffer contains a valid signature followed by more data" ); 317*32b31808SJens Wiklander case -(MBEDTLS_ERR_PK_BUFFER_TOO_SMALL): 318*32b31808SJens Wiklander return( "PK - The output buffer is too small" ); 3197901324dSJerome Forissier #endif /* MBEDTLS_PK_C */ 3207901324dSJerome Forissier 3217901324dSJerome Forissier #if defined(MBEDTLS_PKCS12_C) 3227901324dSJerome Forissier case -(MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA): 3237901324dSJerome Forissier return( "PKCS12 - Bad input parameters to function" ); 3247901324dSJerome Forissier case -(MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE): 3257901324dSJerome Forissier return( "PKCS12 - Feature not available, e.g. unsupported encryption scheme" ); 3267901324dSJerome Forissier case -(MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT): 3277901324dSJerome Forissier return( "PKCS12 - PBE ASN.1 data not as expected" ); 3287901324dSJerome Forissier case -(MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH): 3297901324dSJerome Forissier return( "PKCS12 - Given private key password does not allow for correct decryption" ); 3307901324dSJerome Forissier #endif /* MBEDTLS_PKCS12_C */ 3317901324dSJerome Forissier 3327901324dSJerome Forissier #if defined(MBEDTLS_PKCS5_C) 3337901324dSJerome Forissier case -(MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA): 3347901324dSJerome Forissier return( "PKCS5 - Bad input parameters to function" ); 3357901324dSJerome Forissier case -(MBEDTLS_ERR_PKCS5_INVALID_FORMAT): 3367901324dSJerome Forissier return( "PKCS5 - Unexpected ASN.1 data" ); 3377901324dSJerome Forissier case -(MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE): 3387901324dSJerome Forissier return( "PKCS5 - Requested encryption or digest alg not available" ); 3397901324dSJerome Forissier case -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH): 3407901324dSJerome Forissier return( "PKCS5 - Given private key password does not allow for correct decryption" ); 3417901324dSJerome Forissier #endif /* MBEDTLS_PKCS5_C */ 3427901324dSJerome Forissier 343*32b31808SJens Wiklander #if defined(MBEDTLS_PKCS7_C) 344*32b31808SJens Wiklander case -(MBEDTLS_ERR_PKCS7_INVALID_FORMAT): 345*32b31808SJens Wiklander return( "PKCS7 - The format is invalid, e.g. different type expected" ); 346*32b31808SJens Wiklander case -(MBEDTLS_ERR_PKCS7_FEATURE_UNAVAILABLE): 347*32b31808SJens Wiklander return( "PKCS7 - Unavailable feature, e.g. anything other than signed data" ); 348*32b31808SJens Wiklander case -(MBEDTLS_ERR_PKCS7_INVALID_VERSION): 349*32b31808SJens Wiklander return( "PKCS7 - The PKCS #7 version element is invalid or cannot be parsed" ); 350*32b31808SJens Wiklander case -(MBEDTLS_ERR_PKCS7_INVALID_CONTENT_INFO): 351*32b31808SJens Wiklander return( "PKCS7 - The PKCS #7 content info is invalid or cannot be parsed" ); 352*32b31808SJens Wiklander case -(MBEDTLS_ERR_PKCS7_INVALID_ALG): 353*32b31808SJens Wiklander return( "PKCS7 - The algorithm tag or value is invalid or cannot be parsed" ); 354*32b31808SJens Wiklander case -(MBEDTLS_ERR_PKCS7_INVALID_CERT): 355*32b31808SJens Wiklander return( "PKCS7 - The certificate tag or value is invalid or cannot be parsed" ); 356*32b31808SJens Wiklander case -(MBEDTLS_ERR_PKCS7_INVALID_SIGNATURE): 357*32b31808SJens Wiklander return( "PKCS7 - Error parsing the signature" ); 358*32b31808SJens Wiklander case -(MBEDTLS_ERR_PKCS7_INVALID_SIGNER_INFO): 359*32b31808SJens Wiklander return( "PKCS7 - Error parsing the signer's info" ); 360*32b31808SJens Wiklander case -(MBEDTLS_ERR_PKCS7_BAD_INPUT_DATA): 361*32b31808SJens Wiklander return( "PKCS7 - Input invalid" ); 362*32b31808SJens Wiklander case -(MBEDTLS_ERR_PKCS7_ALLOC_FAILED): 363*32b31808SJens Wiklander return( "PKCS7 - Allocation of memory failed" ); 364*32b31808SJens Wiklander case -(MBEDTLS_ERR_PKCS7_VERIFY_FAIL): 365*32b31808SJens Wiklander return( "PKCS7 - Verification Failed" ); 366*32b31808SJens Wiklander case -(MBEDTLS_ERR_PKCS7_CERT_DATE_INVALID): 367*32b31808SJens Wiklander return( "PKCS7 - The PKCS #7 date issued/expired dates are invalid" ); 368*32b31808SJens Wiklander #endif /* MBEDTLS_PKCS7_C */ 369*32b31808SJens Wiklander 3707901324dSJerome Forissier #if defined(MBEDTLS_RSA_C) 3717901324dSJerome Forissier case -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA): 3727901324dSJerome Forissier return( "RSA - Bad input parameters to function" ); 3737901324dSJerome Forissier case -(MBEDTLS_ERR_RSA_INVALID_PADDING): 3747901324dSJerome Forissier return( "RSA - Input data contains invalid padding and is rejected" ); 3757901324dSJerome Forissier case -(MBEDTLS_ERR_RSA_KEY_GEN_FAILED): 3767901324dSJerome Forissier return( "RSA - Something failed during generation of a key" ); 3777901324dSJerome Forissier case -(MBEDTLS_ERR_RSA_KEY_CHECK_FAILED): 3787901324dSJerome Forissier return( "RSA - Key failed to pass the validity check of the library" ); 3797901324dSJerome Forissier case -(MBEDTLS_ERR_RSA_PUBLIC_FAILED): 3807901324dSJerome Forissier return( "RSA - The public key operation failed" ); 3817901324dSJerome Forissier case -(MBEDTLS_ERR_RSA_PRIVATE_FAILED): 3827901324dSJerome Forissier return( "RSA - The private key operation failed" ); 3837901324dSJerome Forissier case -(MBEDTLS_ERR_RSA_VERIFY_FAILED): 3847901324dSJerome Forissier return( "RSA - The PKCS#1 verification failed" ); 3857901324dSJerome Forissier case -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE): 3867901324dSJerome Forissier return( "RSA - The output buffer for decryption is not large enough" ); 3877901324dSJerome Forissier case -(MBEDTLS_ERR_RSA_RNG_FAILED): 3887901324dSJerome Forissier return( "RSA - The random generator failed to generate non-zeros" ); 3897901324dSJerome Forissier #endif /* MBEDTLS_RSA_C */ 3907901324dSJerome Forissier 3917901324dSJerome Forissier #if defined(MBEDTLS_SSL_TLS_C) 392*32b31808SJens Wiklander case -(MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS): 393*32b31808SJens Wiklander return( "SSL - A cryptographic operation is in progress. Try again later" ); 3947901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE): 3957901324dSJerome Forissier return( "SSL - The requested feature is not available" ); 3967901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA): 3977901324dSJerome Forissier return( "SSL - Bad input parameters to function" ); 3987901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_INVALID_MAC): 3997901324dSJerome Forissier return( "SSL - Verification of the message MAC failed" ); 4007901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_INVALID_RECORD): 4017901324dSJerome Forissier return( "SSL - An invalid SSL record was received" ); 4027901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_CONN_EOF): 4037901324dSJerome Forissier return( "SSL - The connection indicated an EOF" ); 404*32b31808SJens Wiklander case -(MBEDTLS_ERR_SSL_DECODE_ERROR): 405*32b31808SJens Wiklander return( "SSL - A message could not be parsed due to a syntactic error" ); 4067901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_NO_RNG): 4077901324dSJerome Forissier return( "SSL - No RNG was provided to the SSL module" ); 4087901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE): 4097901324dSJerome Forissier return( "SSL - No client certification received from the client, but required by the authentication mode" ); 410*32b31808SJens Wiklander case -(MBEDTLS_ERR_SSL_UNSUPPORTED_EXTENSION): 411*32b31808SJens Wiklander return( "SSL - Client received an extended server hello containing an unsupported extension" ); 412*32b31808SJens Wiklander case -(MBEDTLS_ERR_SSL_NO_APPLICATION_PROTOCOL): 413*32b31808SJens Wiklander return( "SSL - No ALPN protocols supported that the client advertises" ); 4147901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED): 4157901324dSJerome Forissier return( "SSL - The own private key or pre-shared key is not set, but needed" ); 4167901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED): 4177901324dSJerome Forissier return( "SSL - No CA Chain is set, but required to operate" ); 4187901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE): 4197901324dSJerome Forissier return( "SSL - An unexpected message was received from our peer" ); 4207901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE): 4217901324dSJerome Forissier return( "SSL - A fatal alert message was received from our peer" ); 422*32b31808SJens Wiklander case -(MBEDTLS_ERR_SSL_UNRECOGNIZED_NAME): 423*32b31808SJens Wiklander return( "SSL - No server could be identified matching the client's SNI" ); 4247901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY): 4257901324dSJerome Forissier return( "SSL - The peer notified us that the connection is going to be closed" ); 426*32b31808SJens Wiklander case -(MBEDTLS_ERR_SSL_BAD_CERTIFICATE): 4277901324dSJerome Forissier return( "SSL - Processing of the Certificate handshake message failed" ); 428*32b31808SJens Wiklander case -(MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET): 429*32b31808SJens Wiklander return( "SSL - * Received NewSessionTicket Post Handshake Message. This error code is experimental and may be changed or removed without notice" ); 430*32b31808SJens Wiklander case -(MBEDTLS_ERR_SSL_CANNOT_READ_EARLY_DATA): 431*32b31808SJens Wiklander return( "SSL - Not possible to read early data" ); 432*32b31808SJens Wiklander case -(MBEDTLS_ERR_SSL_CANNOT_WRITE_EARLY_DATA): 433*32b31808SJens Wiklander return( "SSL - Not possible to write early data" ); 4347901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_ALLOC_FAILED): 4357901324dSJerome Forissier return( "SSL - Memory allocation failed" ); 4367901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED): 4377901324dSJerome Forissier return( "SSL - Hardware acceleration function returned with error" ); 4387901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH): 4397901324dSJerome Forissier return( "SSL - Hardware acceleration function skipped / left alone data" ); 440*32b31808SJens Wiklander case -(MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION): 4417901324dSJerome Forissier return( "SSL - Handshake protocol not within min/max boundaries" ); 442*32b31808SJens Wiklander case -(MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE): 443*32b31808SJens Wiklander return( "SSL - The handshake negotiation failed" ); 4447901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED): 4457901324dSJerome Forissier return( "SSL - Session ticket has expired" ); 4467901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH): 4477901324dSJerome Forissier return( "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" ); 4487901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY): 4497901324dSJerome Forissier return( "SSL - Unknown identity received (eg, PSK identity)" ); 4507901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_INTERNAL_ERROR): 4517901324dSJerome Forissier return( "SSL - Internal error (eg, unexpected failure in lower-level module)" ); 4527901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_COUNTER_WRAPPING): 4537901324dSJerome Forissier return( "SSL - A counter would wrap (eg, too many messages exchanged)" ); 4547901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO): 4557901324dSJerome Forissier return( "SSL - Unexpected message at ServerHello in renegotiation" ); 4567901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED): 4577901324dSJerome Forissier return( "SSL - DTLS client must retry for hello verification" ); 4587901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL): 4597901324dSJerome Forissier return( "SSL - A buffer is too small to receive or write a message" ); 4607901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_WANT_READ): 4617901324dSJerome Forissier return( "SSL - No data of requested type currently available on underlying transport" ); 4627901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_WANT_WRITE): 4637901324dSJerome Forissier return( "SSL - Connection requires a write call" ); 4647901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_TIMEOUT): 4657901324dSJerome Forissier return( "SSL - The operation timed out" ); 4667901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT): 4677901324dSJerome Forissier return( "SSL - The client initiated a reconnect from the same port" ); 4687901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD): 4697901324dSJerome Forissier return( "SSL - Record header looks valid but is not expected" ); 4707901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_NON_FATAL): 4717901324dSJerome Forissier return( "SSL - The alert message received indicates a non-fatal error" ); 472*32b31808SJens Wiklander case -(MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER): 473*32b31808SJens Wiklander return( "SSL - A field in a message was incorrect or inconsistent with other fields" ); 4747901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_CONTINUE_PROCESSING): 4757901324dSJerome Forissier return( "SSL - Internal-only message signaling that further message-processing should be done" ); 4767901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS): 4777901324dSJerome Forissier return( "SSL - The asynchronous operation is not completed yet" ); 4787901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_EARLY_MESSAGE): 4797901324dSJerome Forissier return( "SSL - Internal-only message signaling that a message arrived early" ); 4807901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_UNEXPECTED_CID): 4817901324dSJerome Forissier return( "SSL - An encrypted DTLS-frame with an unexpected CID was received" ); 4827901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_VERSION_MISMATCH): 4837901324dSJerome Forissier return( "SSL - An operation failed due to an unexpected version or configuration" ); 4847901324dSJerome Forissier case -(MBEDTLS_ERR_SSL_BAD_CONFIG): 4857901324dSJerome Forissier return( "SSL - Invalid value in SSL config" ); 4867901324dSJerome Forissier #endif /* MBEDTLS_SSL_TLS_C */ 4877901324dSJerome Forissier 4887901324dSJerome Forissier #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C) 4897901324dSJerome Forissier case -(MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE): 4907901324dSJerome Forissier return( "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" ); 4917901324dSJerome Forissier case -(MBEDTLS_ERR_X509_UNKNOWN_OID): 4927901324dSJerome Forissier return( "X509 - Requested OID is unknown" ); 4937901324dSJerome Forissier case -(MBEDTLS_ERR_X509_INVALID_FORMAT): 4947901324dSJerome Forissier return( "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" ); 4957901324dSJerome Forissier case -(MBEDTLS_ERR_X509_INVALID_VERSION): 4967901324dSJerome Forissier return( "X509 - The CRT/CRL/CSR version element is invalid" ); 4977901324dSJerome Forissier case -(MBEDTLS_ERR_X509_INVALID_SERIAL): 4987901324dSJerome Forissier return( "X509 - The serial tag or value is invalid" ); 4997901324dSJerome Forissier case -(MBEDTLS_ERR_X509_INVALID_ALG): 5007901324dSJerome Forissier return( "X509 - The algorithm tag or value is invalid" ); 5017901324dSJerome Forissier case -(MBEDTLS_ERR_X509_INVALID_NAME): 5027901324dSJerome Forissier return( "X509 - The name tag or value is invalid" ); 5037901324dSJerome Forissier case -(MBEDTLS_ERR_X509_INVALID_DATE): 5047901324dSJerome Forissier return( "X509 - The date tag or value is invalid" ); 5057901324dSJerome Forissier case -(MBEDTLS_ERR_X509_INVALID_SIGNATURE): 5067901324dSJerome Forissier return( "X509 - The signature tag or value invalid" ); 5077901324dSJerome Forissier case -(MBEDTLS_ERR_X509_INVALID_EXTENSIONS): 5087901324dSJerome Forissier return( "X509 - The extension tag or value is invalid" ); 5097901324dSJerome Forissier case -(MBEDTLS_ERR_X509_UNKNOWN_VERSION): 5107901324dSJerome Forissier return( "X509 - CRT/CRL/CSR has an unsupported version number" ); 5117901324dSJerome Forissier case -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG): 5127901324dSJerome Forissier return( "X509 - Signature algorithm (oid) is unsupported" ); 5137901324dSJerome Forissier case -(MBEDTLS_ERR_X509_SIG_MISMATCH): 5147901324dSJerome Forissier return( "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)" ); 5157901324dSJerome Forissier case -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED): 5167901324dSJerome Forissier return( "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" ); 5177901324dSJerome Forissier case -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT): 5187901324dSJerome Forissier return( "X509 - Format not recognized as DER or PEM" ); 5197901324dSJerome Forissier case -(MBEDTLS_ERR_X509_BAD_INPUT_DATA): 5207901324dSJerome Forissier return( "X509 - Input invalid" ); 5217901324dSJerome Forissier case -(MBEDTLS_ERR_X509_ALLOC_FAILED): 5227901324dSJerome Forissier return( "X509 - Allocation of memory failed" ); 5237901324dSJerome Forissier case -(MBEDTLS_ERR_X509_FILE_IO_ERROR): 5247901324dSJerome Forissier return( "X509 - Read/write of file failed" ); 5257901324dSJerome Forissier case -(MBEDTLS_ERR_X509_BUFFER_TOO_SMALL): 5267901324dSJerome Forissier return( "X509 - Destination buffer is too small" ); 5277901324dSJerome Forissier case -(MBEDTLS_ERR_X509_FATAL_ERROR): 5287901324dSJerome Forissier return( "X509 - A fatal error occurred, eg the chain is too long or the vrfy callback failed" ); 5297901324dSJerome Forissier #endif /* MBEDTLS_X509_USE_C || MBEDTLS_X509_CREATE_C */ 5307901324dSJerome Forissier /* End Auto-Generated Code. */ 5317901324dSJerome Forissier 5327901324dSJerome Forissier default: 5337901324dSJerome Forissier break; 5347901324dSJerome Forissier } 5357901324dSJerome Forissier 536*32b31808SJens Wiklander return NULL; 5377901324dSJerome Forissier } 5387901324dSJerome Forissier 5397901324dSJerome Forissier const char *mbedtls_low_level_strerr(int error_code) 5407901324dSJerome Forissier { 5417901324dSJerome Forissier int low_level_error_code; 5427901324dSJerome Forissier 543*32b31808SJens Wiklander if (error_code < 0) { 5447901324dSJerome Forissier error_code = -error_code; 545*32b31808SJens Wiklander } 5467901324dSJerome Forissier 5477901324dSJerome Forissier /* Extract the low-level part from the error code. */ 5487901324dSJerome Forissier low_level_error_code = error_code & ~0xFF80; 5497901324dSJerome Forissier 550*32b31808SJens Wiklander switch (low_level_error_code) { 5517901324dSJerome Forissier /* Begin Auto-Generated Code. */ 5527901324dSJerome Forissier #if defined(MBEDTLS_AES_C) 5537901324dSJerome Forissier case -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH): 5547901324dSJerome Forissier return( "AES - Invalid key length" ); 5557901324dSJerome Forissier case -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH): 5567901324dSJerome Forissier return( "AES - Invalid data input length" ); 5577901324dSJerome Forissier case -(MBEDTLS_ERR_AES_BAD_INPUT_DATA): 5587901324dSJerome Forissier return( "AES - Invalid input data" ); 5597901324dSJerome Forissier #endif /* MBEDTLS_AES_C */ 5607901324dSJerome Forissier 5617901324dSJerome Forissier #if defined(MBEDTLS_ARIA_C) 5627901324dSJerome Forissier case -(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA): 5637901324dSJerome Forissier return( "ARIA - Bad input data" ); 5647901324dSJerome Forissier case -(MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH): 5657901324dSJerome Forissier return( "ARIA - Invalid data input length" ); 5667901324dSJerome Forissier #endif /* MBEDTLS_ARIA_C */ 5677901324dSJerome Forissier 5687901324dSJerome Forissier #if defined(MBEDTLS_ASN1_PARSE_C) 5697901324dSJerome Forissier case -(MBEDTLS_ERR_ASN1_OUT_OF_DATA): 5707901324dSJerome Forissier return( "ASN1 - Out of data when parsing an ASN1 data structure" ); 5717901324dSJerome Forissier case -(MBEDTLS_ERR_ASN1_UNEXPECTED_TAG): 5727901324dSJerome Forissier return( "ASN1 - ASN1 tag was of an unexpected value" ); 5737901324dSJerome Forissier case -(MBEDTLS_ERR_ASN1_INVALID_LENGTH): 5747901324dSJerome Forissier return( "ASN1 - Error when trying to determine the length or invalid length" ); 5757901324dSJerome Forissier case -(MBEDTLS_ERR_ASN1_LENGTH_MISMATCH): 5767901324dSJerome Forissier return( "ASN1 - Actual length differs from expected length" ); 5777901324dSJerome Forissier case -(MBEDTLS_ERR_ASN1_INVALID_DATA): 5787901324dSJerome Forissier return( "ASN1 - Data is invalid" ); 5797901324dSJerome Forissier case -(MBEDTLS_ERR_ASN1_ALLOC_FAILED): 5807901324dSJerome Forissier return( "ASN1 - Memory allocation failed" ); 5817901324dSJerome Forissier case -(MBEDTLS_ERR_ASN1_BUF_TOO_SMALL): 5827901324dSJerome Forissier return( "ASN1 - Buffer too small when writing ASN.1 data structure" ); 5837901324dSJerome Forissier #endif /* MBEDTLS_ASN1_PARSE_C */ 5847901324dSJerome Forissier 5857901324dSJerome Forissier #if defined(MBEDTLS_BASE64_C) 5867901324dSJerome Forissier case -(MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL): 5877901324dSJerome Forissier return( "BASE64 - Output buffer too small" ); 5887901324dSJerome Forissier case -(MBEDTLS_ERR_BASE64_INVALID_CHARACTER): 5897901324dSJerome Forissier return( "BASE64 - Invalid character in input" ); 5907901324dSJerome Forissier #endif /* MBEDTLS_BASE64_C */ 5917901324dSJerome Forissier 5927901324dSJerome Forissier #if defined(MBEDTLS_BIGNUM_C) 5937901324dSJerome Forissier case -(MBEDTLS_ERR_MPI_FILE_IO_ERROR): 5947901324dSJerome Forissier return( "BIGNUM - An error occurred while reading from or writing to a file" ); 5957901324dSJerome Forissier case -(MBEDTLS_ERR_MPI_BAD_INPUT_DATA): 5967901324dSJerome Forissier return( "BIGNUM - Bad input parameters to function" ); 5977901324dSJerome Forissier case -(MBEDTLS_ERR_MPI_INVALID_CHARACTER): 5987901324dSJerome Forissier return( "BIGNUM - There is an invalid character in the digit string" ); 5997901324dSJerome Forissier case -(MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL): 6007901324dSJerome Forissier return( "BIGNUM - The buffer is too small to write to" ); 6017901324dSJerome Forissier case -(MBEDTLS_ERR_MPI_NEGATIVE_VALUE): 6027901324dSJerome Forissier return( "BIGNUM - The input arguments are negative or result in illegal output" ); 6037901324dSJerome Forissier case -(MBEDTLS_ERR_MPI_DIVISION_BY_ZERO): 6047901324dSJerome Forissier return( "BIGNUM - The input argument for division is zero, which is not allowed" ); 6057901324dSJerome Forissier case -(MBEDTLS_ERR_MPI_NOT_ACCEPTABLE): 6067901324dSJerome Forissier return( "BIGNUM - The input arguments are not acceptable" ); 6077901324dSJerome Forissier case -(MBEDTLS_ERR_MPI_ALLOC_FAILED): 6087901324dSJerome Forissier return( "BIGNUM - Memory allocation failed" ); 6097901324dSJerome Forissier #endif /* MBEDTLS_BIGNUM_C */ 6107901324dSJerome Forissier 6117901324dSJerome Forissier #if defined(MBEDTLS_CAMELLIA_C) 6127901324dSJerome Forissier case -(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA): 6137901324dSJerome Forissier return( "CAMELLIA - Bad input data" ); 6147901324dSJerome Forissier case -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH): 6157901324dSJerome Forissier return( "CAMELLIA - Invalid data input length" ); 6167901324dSJerome Forissier #endif /* MBEDTLS_CAMELLIA_C */ 6177901324dSJerome Forissier 6187901324dSJerome Forissier #if defined(MBEDTLS_CCM_C) 6197901324dSJerome Forissier case -(MBEDTLS_ERR_CCM_BAD_INPUT): 6207901324dSJerome Forissier return( "CCM - Bad input parameters to the function" ); 6217901324dSJerome Forissier case -(MBEDTLS_ERR_CCM_AUTH_FAILED): 6227901324dSJerome Forissier return( "CCM - Authenticated decryption failed" ); 6237901324dSJerome Forissier #endif /* MBEDTLS_CCM_C */ 6247901324dSJerome Forissier 6257901324dSJerome Forissier #if defined(MBEDTLS_CHACHA20_C) 6267901324dSJerome Forissier case -(MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA): 6277901324dSJerome Forissier return( "CHACHA20 - Invalid input parameter(s)" ); 6287901324dSJerome Forissier #endif /* MBEDTLS_CHACHA20_C */ 6297901324dSJerome Forissier 6307901324dSJerome Forissier #if defined(MBEDTLS_CHACHAPOLY_C) 6317901324dSJerome Forissier case -(MBEDTLS_ERR_CHACHAPOLY_BAD_STATE): 6327901324dSJerome Forissier return( "CHACHAPOLY - The requested operation is not permitted in the current state" ); 6337901324dSJerome Forissier case -(MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED): 6347901324dSJerome Forissier return( "CHACHAPOLY - Authenticated decryption failed: data was not authentic" ); 6357901324dSJerome Forissier #endif /* MBEDTLS_CHACHAPOLY_C */ 6367901324dSJerome Forissier 6377901324dSJerome Forissier #if defined(MBEDTLS_CTR_DRBG_C) 6387901324dSJerome Forissier case -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED): 6397901324dSJerome Forissier return( "CTR_DRBG - The entropy source failed" ); 6407901324dSJerome Forissier case -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG): 6417901324dSJerome Forissier return( "CTR_DRBG - The requested random buffer length is too big" ); 6427901324dSJerome Forissier case -(MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG): 6437901324dSJerome Forissier return( "CTR_DRBG - The input (entropy + additional data) is too large" ); 6447901324dSJerome Forissier case -(MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR): 6457901324dSJerome Forissier return( "CTR_DRBG - Read or write error in file" ); 6467901324dSJerome Forissier #endif /* MBEDTLS_CTR_DRBG_C */ 6477901324dSJerome Forissier 6487901324dSJerome Forissier #if defined(MBEDTLS_DES_C) 6497901324dSJerome Forissier case -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH): 6507901324dSJerome Forissier return( "DES - The data input has an invalid length" ); 6517901324dSJerome Forissier #endif /* MBEDTLS_DES_C */ 6527901324dSJerome Forissier 6537901324dSJerome Forissier #if defined(MBEDTLS_ENTROPY_C) 6547901324dSJerome Forissier case -(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED): 6557901324dSJerome Forissier return( "ENTROPY - Critical entropy source failure" ); 6567901324dSJerome Forissier case -(MBEDTLS_ERR_ENTROPY_MAX_SOURCES): 6577901324dSJerome Forissier return( "ENTROPY - No more sources can be added" ); 6587901324dSJerome Forissier case -(MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED): 6597901324dSJerome Forissier return( "ENTROPY - No sources have been added to poll" ); 6607901324dSJerome Forissier case -(MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE): 6617901324dSJerome Forissier return( "ENTROPY - No strong sources have been added to poll" ); 6627901324dSJerome Forissier case -(MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR): 6637901324dSJerome Forissier return( "ENTROPY - Read/write error in file" ); 6647901324dSJerome Forissier #endif /* MBEDTLS_ENTROPY_C */ 6657901324dSJerome Forissier 6667901324dSJerome Forissier #if defined(MBEDTLS_ERROR_C) 6677901324dSJerome Forissier case -(MBEDTLS_ERR_ERROR_GENERIC_ERROR): 6687901324dSJerome Forissier return( "ERROR - Generic error" ); 6697901324dSJerome Forissier case -(MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED): 6707901324dSJerome Forissier return( "ERROR - This is a bug in the library" ); 6717901324dSJerome Forissier #endif /* MBEDTLS_ERROR_C */ 6727901324dSJerome Forissier 673*32b31808SJens Wiklander #if defined(MBEDTLS_PLATFORM_C) 674*32b31808SJens Wiklander case -(MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED): 675*32b31808SJens Wiklander return( "PLATFORM - Hardware accelerator failed" ); 676*32b31808SJens Wiklander case -(MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED): 677*32b31808SJens Wiklander return( "PLATFORM - The requested feature is not supported by the platform" ); 678*32b31808SJens Wiklander #endif /* MBEDTLS_PLATFORM_C */ 679*32b31808SJens Wiklander 6807901324dSJerome Forissier #if defined(MBEDTLS_GCM_C) 6817901324dSJerome Forissier case -(MBEDTLS_ERR_GCM_AUTH_FAILED): 6827901324dSJerome Forissier return( "GCM - Authenticated decryption failed" ); 6837901324dSJerome Forissier case -(MBEDTLS_ERR_GCM_BAD_INPUT): 6847901324dSJerome Forissier return( "GCM - Bad input parameters to function" ); 685*32b31808SJens Wiklander case -(MBEDTLS_ERR_GCM_BUFFER_TOO_SMALL): 686*32b31808SJens Wiklander return( "GCM - An output buffer is too small" ); 6877901324dSJerome Forissier #endif /* MBEDTLS_GCM_C */ 6887901324dSJerome Forissier 6897901324dSJerome Forissier #if defined(MBEDTLS_HKDF_C) 6907901324dSJerome Forissier case -(MBEDTLS_ERR_HKDF_BAD_INPUT_DATA): 6917901324dSJerome Forissier return( "HKDF - Bad input parameters to function" ); 6927901324dSJerome Forissier #endif /* MBEDTLS_HKDF_C */ 6937901324dSJerome Forissier 6947901324dSJerome Forissier #if defined(MBEDTLS_HMAC_DRBG_C) 6957901324dSJerome Forissier case -(MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG): 6967901324dSJerome Forissier return( "HMAC_DRBG - Too many random requested in single call" ); 6977901324dSJerome Forissier case -(MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG): 6987901324dSJerome Forissier return( "HMAC_DRBG - Input too large (Entropy + additional)" ); 6997901324dSJerome Forissier case -(MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR): 7007901324dSJerome Forissier return( "HMAC_DRBG - Read/write error in file" ); 7017901324dSJerome Forissier case -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED): 7027901324dSJerome Forissier return( "HMAC_DRBG - The entropy source failed" ); 7037901324dSJerome Forissier #endif /* MBEDTLS_HMAC_DRBG_C */ 7047901324dSJerome Forissier 705*32b31808SJens Wiklander #if defined(MBEDTLS_LMS_C) 706*32b31808SJens Wiklander case -(MBEDTLS_ERR_LMS_BAD_INPUT_DATA): 707*32b31808SJens Wiklander return( "LMS - Bad data has been input to an LMS function" ); 708*32b31808SJens Wiklander case -(MBEDTLS_ERR_LMS_OUT_OF_PRIVATE_KEYS): 709*32b31808SJens Wiklander return( "LMS - Specified LMS key has utilised all of its private keys" ); 710*32b31808SJens Wiklander case -(MBEDTLS_ERR_LMS_VERIFY_FAILED): 711*32b31808SJens Wiklander return( "LMS - LMS signature verification failed" ); 712*32b31808SJens Wiklander case -(MBEDTLS_ERR_LMS_ALLOC_FAILED): 713*32b31808SJens Wiklander return( "LMS - LMS failed to allocate space for a private key" ); 714*32b31808SJens Wiklander case -(MBEDTLS_ERR_LMS_BUFFER_TOO_SMALL): 715*32b31808SJens Wiklander return( "LMS - Input/output buffer is too small to contain requited data" ); 716*32b31808SJens Wiklander #endif /* MBEDTLS_LMS_C */ 7177901324dSJerome Forissier 7187901324dSJerome Forissier #if defined(MBEDTLS_NET_C) 7197901324dSJerome Forissier case -(MBEDTLS_ERR_NET_SOCKET_FAILED): 7207901324dSJerome Forissier return( "NET - Failed to open a socket" ); 7217901324dSJerome Forissier case -(MBEDTLS_ERR_NET_CONNECT_FAILED): 7227901324dSJerome Forissier return( "NET - The connection to the given server / port failed" ); 7237901324dSJerome Forissier case -(MBEDTLS_ERR_NET_BIND_FAILED): 7247901324dSJerome Forissier return( "NET - Binding of the socket failed" ); 7257901324dSJerome Forissier case -(MBEDTLS_ERR_NET_LISTEN_FAILED): 7267901324dSJerome Forissier return( "NET - Could not listen on the socket" ); 7277901324dSJerome Forissier case -(MBEDTLS_ERR_NET_ACCEPT_FAILED): 7287901324dSJerome Forissier return( "NET - Could not accept the incoming connection" ); 7297901324dSJerome Forissier case -(MBEDTLS_ERR_NET_RECV_FAILED): 7307901324dSJerome Forissier return( "NET - Reading information from the socket failed" ); 7317901324dSJerome Forissier case -(MBEDTLS_ERR_NET_SEND_FAILED): 7327901324dSJerome Forissier return( "NET - Sending information through the socket failed" ); 7337901324dSJerome Forissier case -(MBEDTLS_ERR_NET_CONN_RESET): 7347901324dSJerome Forissier return( "NET - Connection was reset by peer" ); 7357901324dSJerome Forissier case -(MBEDTLS_ERR_NET_UNKNOWN_HOST): 7367901324dSJerome Forissier return( "NET - Failed to get an IP address for the given hostname" ); 7377901324dSJerome Forissier case -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL): 7387901324dSJerome Forissier return( "NET - Buffer is too small to hold the data" ); 7397901324dSJerome Forissier case -(MBEDTLS_ERR_NET_INVALID_CONTEXT): 7407901324dSJerome Forissier return( "NET - The context is invalid, eg because it was free()ed" ); 7417901324dSJerome Forissier case -(MBEDTLS_ERR_NET_POLL_FAILED): 7427901324dSJerome Forissier return( "NET - Polling the net context failed" ); 7437901324dSJerome Forissier case -(MBEDTLS_ERR_NET_BAD_INPUT_DATA): 7447901324dSJerome Forissier return( "NET - Input invalid" ); 7457901324dSJerome Forissier #endif /* MBEDTLS_NET_C */ 7467901324dSJerome Forissier 7477901324dSJerome Forissier #if defined(MBEDTLS_OID_C) 7487901324dSJerome Forissier case -(MBEDTLS_ERR_OID_NOT_FOUND): 7497901324dSJerome Forissier return( "OID - OID is not found" ); 7507901324dSJerome Forissier case -(MBEDTLS_ERR_OID_BUF_TOO_SMALL): 7517901324dSJerome Forissier return( "OID - output buffer is too small" ); 7527901324dSJerome Forissier #endif /* MBEDTLS_OID_C */ 7537901324dSJerome Forissier 7547901324dSJerome Forissier #if defined(MBEDTLS_POLY1305_C) 7557901324dSJerome Forissier case -(MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA): 7567901324dSJerome Forissier return( "POLY1305 - Invalid input parameter(s)" ); 7577901324dSJerome Forissier #endif /* MBEDTLS_POLY1305_C */ 7587901324dSJerome Forissier 7597901324dSJerome Forissier #if defined(MBEDTLS_SHA1_C) 7607901324dSJerome Forissier case -(MBEDTLS_ERR_SHA1_BAD_INPUT_DATA): 7617901324dSJerome Forissier return( "SHA1 - SHA-1 input data was malformed" ); 7627901324dSJerome Forissier #endif /* MBEDTLS_SHA1_C */ 7637901324dSJerome Forissier 7647901324dSJerome Forissier #if defined(MBEDTLS_SHA256_C) 7657901324dSJerome Forissier case -(MBEDTLS_ERR_SHA256_BAD_INPUT_DATA): 7667901324dSJerome Forissier return( "SHA256 - SHA-256 input data was malformed" ); 7677901324dSJerome Forissier #endif /* MBEDTLS_SHA256_C */ 7687901324dSJerome Forissier 7697901324dSJerome Forissier #if defined(MBEDTLS_SHA512_C) 7707901324dSJerome Forissier case -(MBEDTLS_ERR_SHA512_BAD_INPUT_DATA): 7717901324dSJerome Forissier return( "SHA512 - SHA-512 input data was malformed" ); 7727901324dSJerome Forissier #endif /* MBEDTLS_SHA512_C */ 7737901324dSJerome Forissier 7747901324dSJerome Forissier #if defined(MBEDTLS_THREADING_C) 7757901324dSJerome Forissier case -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA): 7767901324dSJerome Forissier return( "THREADING - Bad input parameters to function" ); 7777901324dSJerome Forissier case -(MBEDTLS_ERR_THREADING_MUTEX_ERROR): 7787901324dSJerome Forissier return( "THREADING - Locking / unlocking / free failed with error code" ); 7797901324dSJerome Forissier #endif /* MBEDTLS_THREADING_C */ 7807901324dSJerome Forissier /* End Auto-Generated Code. */ 7817901324dSJerome Forissier 7827901324dSJerome Forissier default: 7837901324dSJerome Forissier break; 7847901324dSJerome Forissier } 7857901324dSJerome Forissier 786*32b31808SJens Wiklander return NULL; 7877901324dSJerome Forissier } 7887901324dSJerome Forissier 789817466cbSJens Wiklander void mbedtls_strerror(int ret, char *buf, size_t buflen) 790817466cbSJens Wiklander { 791817466cbSJens Wiklander size_t len; 792817466cbSJens Wiklander int use_ret; 7937901324dSJerome Forissier const char *high_level_error_description = NULL; 7947901324dSJerome Forissier const char *low_level_error_description = NULL; 795817466cbSJens Wiklander 796*32b31808SJens Wiklander if (buflen == 0) { 797817466cbSJens Wiklander return; 798*32b31808SJens Wiklander } 799817466cbSJens Wiklander 800817466cbSJens Wiklander memset(buf, 0x00, buflen); 801817466cbSJens Wiklander 802*32b31808SJens Wiklander if (ret < 0) { 803817466cbSJens Wiklander ret = -ret; 804*32b31808SJens Wiklander } 805817466cbSJens Wiklander 806*32b31808SJens Wiklander if (ret & 0xFF80) { 807817466cbSJens Wiklander use_ret = ret & 0xFF80; 808817466cbSJens Wiklander 8097901324dSJerome Forissier // Translate high level error code. 8107901324dSJerome Forissier high_level_error_description = mbedtls_high_level_strerr(ret); 811817466cbSJens Wiklander 812*32b31808SJens Wiklander if (high_level_error_description == NULL) { 8137901324dSJerome Forissier mbedtls_snprintf(buf, buflen, "UNKNOWN ERROR CODE (%04X)", (unsigned int) use_ret); 814*32b31808SJens Wiklander } else { 8157901324dSJerome Forissier mbedtls_snprintf(buf, buflen, "%s", high_level_error_description); 816*32b31808SJens Wiklander } 817817466cbSJens Wiklander 818817466cbSJens Wiklander #if defined(MBEDTLS_SSL_TLS_C) 8197901324dSJerome Forissier // Early return in case of a fatal error - do not try to translate low 8207901324dSJerome Forissier // level code. 821*32b31808SJens Wiklander if (use_ret == -(MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE)) { 822817466cbSJens Wiklander return; 823*32b31808SJens Wiklander } 824817466cbSJens Wiklander #endif /* MBEDTLS_SSL_TLS_C */ 825817466cbSJens Wiklander } 826817466cbSJens Wiklander 827817466cbSJens Wiklander use_ret = ret & ~0xFF80; 828817466cbSJens Wiklander 829*32b31808SJens Wiklander if (use_ret == 0) { 830817466cbSJens Wiklander return; 831*32b31808SJens Wiklander } 832817466cbSJens Wiklander 833817466cbSJens Wiklander // If high level code is present, make a concatenation between both 834817466cbSJens Wiklander // error strings. 835817466cbSJens Wiklander // 836817466cbSJens Wiklander len = strlen(buf); 837817466cbSJens Wiklander 838*32b31808SJens Wiklander if (len > 0) { 839*32b31808SJens Wiklander if (buflen - len < 5) { 840817466cbSJens Wiklander return; 841*32b31808SJens Wiklander } 842817466cbSJens Wiklander 843817466cbSJens Wiklander mbedtls_snprintf(buf + len, buflen - len, " : "); 844817466cbSJens Wiklander 845817466cbSJens Wiklander buf += len + 3; 846817466cbSJens Wiklander buflen -= len + 3; 847817466cbSJens Wiklander } 848817466cbSJens Wiklander 8497901324dSJerome Forissier // Translate low level error code. 8507901324dSJerome Forissier low_level_error_description = mbedtls_low_level_strerr(ret); 851817466cbSJens Wiklander 852*32b31808SJens Wiklander if (low_level_error_description == NULL) { 8537901324dSJerome Forissier mbedtls_snprintf(buf, buflen, "UNKNOWN ERROR CODE (%04X)", (unsigned int) use_ret); 854*32b31808SJens Wiklander } else { 8557901324dSJerome Forissier mbedtls_snprintf(buf, buflen, "%s", low_level_error_description); 856817466cbSJens Wiklander } 857*32b31808SJens Wiklander } 858817466cbSJens Wiklander 859817466cbSJens Wiklander #else /* MBEDTLS_ERROR_C */ 860817466cbSJens Wiklander 861817466cbSJens Wiklander /* 862*32b31808SJens Wiklander * Provide a dummy implementation when MBEDTLS_ERROR_C is not defined 863817466cbSJens Wiklander */ 864817466cbSJens Wiklander void mbedtls_strerror(int ret, char *buf, size_t buflen) 865817466cbSJens Wiklander { 866817466cbSJens Wiklander ((void) ret); 867817466cbSJens Wiklander 868*32b31808SJens Wiklander if (buflen > 0) { 869817466cbSJens Wiklander buf[0] = '\0'; 870817466cbSJens Wiklander } 871*32b31808SJens Wiklander } 872817466cbSJens Wiklander 873817466cbSJens Wiklander #endif /* MBEDTLS_ERROR_C */ 8747901324dSJerome Forissier 8757901324dSJerome Forissier #if defined(MBEDTLS_TEST_HOOKS) 8767901324dSJerome Forissier void (*mbedtls_test_hook_error_add)(int, int, const char *, int); 8777901324dSJerome Forissier #endif 8787901324dSJerome Forissier 8797901324dSJerome Forissier #endif /* MBEDTLS_ERROR_C || MBEDTLS_ERROR_STRERROR_DUMMY */ 880