gnunet-android

GNUnet for Android
Log | Files | Refs | README

error-crypt.h (18726B)


      1 /* error-crypt.h
      2  *
      3  * Copyright (C) 2006-2025 wolfSSL Inc.
      4  *
      5  * This file is part of wolfSSL.
      6  *
      7  * wolfSSL is free software; you can redistribute it and/or modify
      8  * it under the terms of the GNU General Public License as published by
      9  * the Free Software Foundation; either version 3 of the License, or
     10  * (at your option) any later version.
     11  *
     12  * wolfSSL is distributed in the hope that it will be useful,
     13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15  * GNU General Public License for more details.
     16  *
     17  * You should have received a copy of the GNU General Public License
     18  * along with this program; if not, write to the Free Software
     19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
     20  */
     21 
     22 /*!
     23     \file wolfssl/wolfcrypt/error-crypt.h
     24 */
     25 /*
     26 DESCRIPTION
     27 This library defines error codes and contains routines for setting and examining
     28 the error status.
     29 */
     30 
     31 #ifndef WOLF_CRYPT_ERROR_H
     32 #define WOLF_CRYPT_ERROR_H
     33 
     34 #include <wolfssl/wolfcrypt/types.h>
     35 
     36 #ifdef __cplusplus
     37     extern "C" {
     38 #endif
     39 
     40 #ifdef WOLFSSL_DEBUG_TRACE_ERROR_CODES_H
     41 #include <wolfssl/debug-untrace-error-codes.h>
     42 #endif
     43 
     44 /* error codes, add string for new errors !!! */
     45 enum wolfCrypt_ErrorCodes {
     46     /* note that WOLFSSL_FATAL_ERROR is defined as -1 in error-ssl.h, for
     47      * reasons of backward compatibility.
     48      */
     49     WC_FAILURE         =   -1,  /* Generic but traceable back compat errcode.
     50                                  * Note, not reflected in MAX_CODE_E or
     51                                  * WC_FIRST_E.
     52                                  */
     53 
     54     MAX_CODE_E         =  -96,  /* WC_FIRST_E + 1, for backward compat. */
     55     WC_FIRST_E         =  -97,  /* First code used for wolfCrypt */
     56 
     57     WC_SPAN1_FIRST_E   =  -97,  /* errors -97 - -300 */
     58 
     59     MP_MEM             =  -97,  /* MP dynamic memory allocation failed. */
     60     MP_VAL             =  -98,  /* MP value passed is not able to be used. */
     61     MP_WOULDBLOCK      =  -99,  /* MP non-blocking operation is returning after
     62                                  * partial completion. */
     63     MP_NOT_INF         = -100,  /* MP point not at infinity */
     64 
     65     OPEN_RAN_E         = -101,  /* opening random device error */
     66     READ_RAN_E         = -102,  /* reading random device error */
     67     WINCRYPT_E         = -103,  /* windows crypt init error */
     68     CRYPTGEN_E         = -104,  /* windows crypt generation error */
     69     RAN_BLOCK_E        = -105,  /* reading random device would block */
     70     BAD_MUTEX_E        = -106,  /* Bad mutex operation */
     71     WC_TIMEOUT_E       = -107,  /* timeout error */
     72     WC_PENDING_E       = -108,  /* wolfCrypt operation pending (would block) */
     73     WC_NO_PENDING_E    = -109,  /* no asynchronous operation pending */
     74 
     75     MP_INIT_E          = -110,  /* mp_init error state */
     76     MP_READ_E          = -111,  /* mp_read error state */
     77     MP_EXPTMOD_E       = -112,  /* mp_exptmod error state */
     78     MP_TO_E            = -113,  /* mp_to_xxx error state, can't convert */
     79     MP_SUB_E           = -114,  /* mp_sub error state, can't subtract */
     80     MP_ADD_E           = -115,  /* mp_add error state, can't add */
     81     MP_MUL_E           = -116,  /* mp_mul error state, can't multiply */
     82     MP_MULMOD_E        = -117,  /* mp_mulmod error state, can't multiply mod */
     83     MP_MOD_E           = -118,  /* mp_mod error state, can't mod */
     84     MP_INVMOD_E        = -119,  /* mp_invmod error state, can't inv mod */
     85     MP_CMP_E           = -120,  /* mp_cmp error state */
     86     MP_ZERO_E          = -121,  /* got a mp zero result, not expected */
     87 
     88     AES_EAX_AUTH_E     = -122, /* AES-EAX Authentication check failure */
     89     KEY_EXHAUSTED_E    = -123, /* No longer usable for operation. */
     90 
     91     /* -124 unused. */
     92 
     93     MEMORY_E           = -125,  /* out of memory error */
     94     VAR_STATE_CHANGE_E = -126,  /* var state modified by different thread */
     95     FIPS_DEGRADED_E    = -127,  /* FIPS Module in degraded mode */
     96 
     97     FIPS_CODE_SZ_E     = -128,  /* Module CODE too big */
     98     FIPS_DATA_SZ_E     = -129,  /* Module DATA too big */
     99 
    100     RSA_WRONG_TYPE_E   = -130,  /* RSA wrong block type for RSA function */
    101     RSA_BUFFER_E       = -131,  /* RSA buffer error, output too small or
    102                                    input too large */
    103     BUFFER_E           = -132,  /* output buffer too small or input too large */
    104     ALGO_ID_E          = -133,  /* setting algo id error */
    105     PUBLIC_KEY_E       = -134,  /* setting public key error */
    106     DATE_E             = -135,  /* setting date validity error */
    107     SUBJECT_E          = -136,  /* setting subject name error */
    108     ISSUER_E           = -137,  /* setting issuer  name error */
    109     CA_TRUE_E          = -138,  /* setting CA basic constraint true error */
    110     EXTENSIONS_E       = -139,  /* setting extensions error */
    111 
    112     ASN_PARSE_E        = -140,  /* ASN parsing error, invalid input */
    113     ASN_VERSION_E      = -141,  /* ASN version error, invalid number */
    114     ASN_GETINT_E       = -142,  /* ASN get big int error, invalid data */
    115     ASN_RSA_KEY_E      = -143,  /* ASN key init error, invalid input */
    116     ASN_OBJECT_ID_E    = -144,  /* ASN object id error, invalid id */
    117     ASN_TAG_NULL_E     = -145,  /* ASN tag error, not null */
    118     ASN_EXPECT_0_E     = -146,  /* ASN expect error, not zero */
    119     ASN_BITSTR_E       = -147,  /* ASN bit string error, wrong id */
    120     ASN_UNKNOWN_OID_E  = -148,  /* ASN oid error, unknown sum id */
    121     ASN_DATE_SZ_E      = -149,  /* ASN date error, bad size */
    122     ASN_BEFORE_DATE_E  = -150,  /* ASN date error, current date before */
    123     ASN_AFTER_DATE_E   = -151,  /* ASN date error, current date after */
    124     ASN_SIG_OID_E      = -152,  /* ASN signature error, mismatched oid */
    125     ASN_TIME_E         = -153,  /* ASN time error, unknown time type */
    126     ASN_INPUT_E        = -154,  /* ASN input error, not enough data */
    127     ASN_SIG_CONFIRM_E  = -155,  /* ASN sig error, confirm failure */
    128     ASN_SIG_HASH_E     = -156,  /* ASN sig error, unsupported hash type */
    129     ASN_SIG_KEY_E      = -157,  /* ASN sig error, unsupported key type */
    130     ASN_DH_KEY_E       = -158,  /* ASN key init error, invalid input */
    131     KDF_SRTP_KAT_FIPS_E = -159, /* SRTP-KDF Known Answer Test Failure */
    132     ASN_CRIT_EXT_E     = -160,  /* ASN unsupported critical extension */
    133     ASN_ALT_NAME_E     = -161,  /* ASN alternate name error */
    134     ASN_NO_PEM_HEADER  = -162,  /* ASN no PEM header found */
    135     ED25519_KAT_FIPS_E = -163,  /* Ed25519 Known answer test failure */
    136     ED448_KAT_FIPS_E   = -164,  /* Ed448 Known answer test failure */
    137     PBKDF2_KAT_FIPS_E  = -165,  /* PBKDF2 Known answer test failure */
    138     WC_KEY_MISMATCH_E  = -166,  /* Error for private/public key mismatch */
    139     /* -167..-169 unused. */
    140 
    141     ECC_BAD_ARG_E      = -170,  /* ECC input argument of wrong type */
    142     ASN_ECC_KEY_E      = -171,  /* ASN ECC bad input */
    143     ECC_CURVE_OID_E    = -172,  /* Unsupported ECC OID curve type */
    144     BAD_FUNC_ARG       = -173,  /* Bad function argument provided */
    145     NOT_COMPILED_IN    = -174,  /* Feature not compiled in */
    146     UNICODE_SIZE_E     = -175,  /* Unicode password too big */
    147     NO_PASSWORD        = -176,  /* no password provided by user */
    148     ALT_NAME_E         = -177,  /* alt name size problem, too big */
    149     BAD_OCSP_RESPONDER = -178,  /* missing key usage extensions */
    150     CRL_CERT_DATE_ERR  = -179,   /* CRL date error */
    151 
    152     AES_GCM_AUTH_E     = -180,  /* AES-GCM Authentication check failure */
    153     AES_CCM_AUTH_E     = -181,  /* AES-CCM Authentication check failure */
    154 
    155     ASYNC_INIT_E       = -182,  /* Async Init type error */
    156 
    157     COMPRESS_INIT_E    = -183,  /* Compress init error */
    158     COMPRESS_E         = -184,  /* Compress error */
    159     DECOMPRESS_INIT_E  = -185,  /* DeCompress init error */
    160     DECOMPRESS_E       = -186,  /* DeCompress error */
    161 
    162     BAD_ALIGN_E         = -187,  /* Bad alignment for operation, no alloc */
    163     ASN_NO_SIGNER_E     = -188,  /* ASN no signer to confirm failure */
    164     ASN_CRL_CONFIRM_E   = -189,  /* ASN CRL signature confirm failure */
    165     ASN_CRL_NO_SIGNER_E = -190,  /* ASN CRL no signer to confirm failure */
    166     ASN_OCSP_CONFIRM_E  = -191,  /* ASN OCSP signature confirm failure */
    167 
    168     BAD_STATE_E         = -192,  /* Bad state operation */
    169     BAD_PADDING_E       = -193,  /* Bad padding, msg not correct length  */
    170 
    171     REQ_ATTRIBUTE_E     = -194,  /* setting cert request attributes error */
    172 
    173     PKCS7_OID_E         = -195,  /* PKCS#7, mismatched OID error */
    174     PKCS7_RECIP_E       = -196,  /* PKCS#7, recipient error */
    175     FIPS_NOT_ALLOWED_E  = -197,  /* FIPS not allowed error */
    176     ASN_NAME_INVALID_E  = -198,  /* ASN name constraint error */
    177 
    178     RNG_FAILURE_E       = -199,  /* RNG Failed, Reinitialize */
    179     HMAC_MIN_KEYLEN_E   = -200,  /* FIPS Mode HMAC Minimum Key Length error */
    180     RSA_PAD_E           = -201,  /* RSA Padding Error */
    181     LENGTH_ONLY_E       = -202,  /* Returning output length only */
    182 
    183     IN_CORE_FIPS_E      = -203,  /* In Core Integrity check failure */
    184     AES_KAT_FIPS_E      = -204,  /* AES KAT failure */
    185     DES3_KAT_FIPS_E     = -205,  /* DES3 KAT failure */
    186     HMAC_KAT_FIPS_E     = -206,  /* HMAC KAT failure */
    187     RSA_KAT_FIPS_E      = -207,  /* RSA KAT failure */
    188     DRBG_KAT_FIPS_E     = -208,  /* HASH DRBG KAT failure */
    189     DRBG_CONT_FIPS_E    = -209,  /* HASH DRBG Continuous test failure */
    190     AESGCM_KAT_FIPS_E   = -210,  /* AESGCM KAT failure */
    191     THREAD_STORE_KEY_E  = -211,  /* Thread local storage key create failure */
    192     THREAD_STORE_SET_E  = -212,  /* Thread local storage key set failure */
    193 
    194     MAC_CMP_FAILED_E    = -213,  /* MAC comparison failed */
    195     IS_POINT_E          = -214,  /* ECC is point on curve failed */
    196     ECC_INF_E           = -215,  /* ECC point infinity error */
    197     ECC_PRIV_KEY_E      = -216,  /* ECC private key not valid error */
    198     ECC_OUT_OF_RANGE_E  = -217,  /* ECC key component out of range */
    199 
    200     SRP_CALL_ORDER_E    = -218,  /* SRP function called in the wrong order. */
    201     SRP_VERIFY_E        = -219,  /* SRP proof verification failed. */
    202     SRP_BAD_KEY_E       = -220,  /* SRP bad ephemeral values. */
    203 
    204     ASN_NO_SKID         = -221,  /* ASN no Subject Key Identifier found */
    205     ASN_NO_AKID         = -222,  /* ASN no Authority Key Identifier found */
    206     ASN_NO_KEYUSAGE     = -223,  /* ASN no Key Usage found */
    207     SKID_E              = -224,  /* setting Subject Key Identifier error */
    208     AKID_E              = -225,  /* setting Authority Key Identifier error */
    209     KEYUSAGE_E          = -226,  /* Bad Key Usage value */
    210     CERTPOLICIES_E      = -227,  /* setting Certificate Policies error */
    211 
    212     WC_INIT_E           = -228,  /* wolfcrypt failed to initialize */
    213     SIG_VERIFY_E        = -229,  /* wolfcrypt signature verify error */
    214     BAD_COND_E          = -230,  /* Bad condition variable operation */
    215     SIG_TYPE_E          = -231,  /* Signature Type not enabled/available
    216                                   * NOTE: 1024-bit sign disabled in FIPS mode */
    217     HASH_TYPE_E         = -232,  /* Hash Type not enabled/available */
    218 
    219     FIPS_INVALID_VER_E  = -233,  /* Invalid FIPS Version defined */
    220 
    221     WC_KEY_SIZE_E       = -234,  /* Key size error, either too small or large */
    222     ASN_COUNTRY_SIZE_E  = -235,  /* ASN Cert Gen, invalid country code size */
    223     MISSING_RNG_E       = -236,  /* RNG required but not provided */
    224     ASN_PATHLEN_SIZE_E  = -237,  /* ASN CA path length too large error */
    225     ASN_PATHLEN_INV_E   = -238,  /* ASN CA path length inversion error */
    226 
    227     BAD_KEYWRAP_ALG_E   = -239,
    228     BAD_KEYWRAP_IV_E    = -240,  /* Decrypted AES key wrap IV incorrect */
    229     WC_CLEANUP_E        = -241,  /* wolfcrypt cleanup failed */
    230     ECC_CDH_KAT_FIPS_E  = -242,  /* ECC CDH Known Answer Test failure */
    231     DH_CHECK_PUB_E      = -243,  /* DH Check Pub Key error */
    232     BAD_PATH_ERROR      = -244,  /* Bad path for opendir */
    233 
    234     ASYNC_OP_E          = -245,  /* Async operation error */
    235 
    236     ECC_PRIVATEONLY_E   = -246,  /* Invalid use of private only ECC key*/
    237     EXTKEYUSAGE_E       = -247,  /* Bad Extended Key Usage value */
    238     WC_HW_E             = -248,  /* Error with hardware crypto use */
    239     WC_HW_WAIT_E        = -249,  /* Hardware waiting on resource */
    240 
    241     PSS_SALTLEN_E       = -250,  /* PSS length of salt is too long for hash */
    242     PRIME_GEN_E         = -251,  /* Failure finding a prime. */
    243     BER_INDEF_E         = -252,  /* Cannot decode indefinite length BER. */
    244     RSA_OUT_OF_RANGE_E  = -253,  /* Ciphertext to decrypt out of range. */
    245     RSAPSS_PAT_FIPS_E   = -254,  /* RSA-PSS PAT failure */
    246     ECDSA_PAT_FIPS_E    = -255,  /* ECDSA PAT failure */
    247     DH_KAT_FIPS_E       = -256,  /* DH KAT failure */
    248     AESCCM_KAT_FIPS_E   = -257,  /* AESCCM KAT failure */
    249     SHA3_KAT_FIPS_E     = -258,  /* SHA-3 KAT failure */
    250     ECDHE_KAT_FIPS_E    = -259,  /* ECDHE KAT failure */
    251     AES_GCM_OVERFLOW_E  = -260,  /* AES-GCM invocation counter overflow. */
    252     AES_CCM_OVERFLOW_E  = -261,  /* AES-CCM invocation counter overflow. */
    253     RSA_KEY_PAIR_E      = -262,  /* RSA Key Pair-Wise Consistency check fail. */
    254     DH_CHECK_PRIV_E     = -263,  /* DH Check Priv Key error */
    255 
    256     WC_AFALG_SOCK_E     = -264,  /* AF_ALG socket error */
    257     WC_DEVCRYPTO_E      = -265,  /* /dev/crypto error */
    258 
    259     ZLIB_INIT_ERROR     = -266,   /* zlib init error  */
    260     ZLIB_COMPRESS_ERROR = -267,   /* zlib compression error  */
    261     ZLIB_DECOMPRESS_ERROR = -268,  /* zlib decompression error  */
    262 
    263     PKCS7_NO_SIGNER_E   = -269,  /* No signer in PKCS#7 signed data msg */
    264     WC_PKCS7_WANT_READ_E= -270,  /* PKCS7 operations wants more input */
    265 
    266     CRYPTOCB_UNAVAILABLE= -271,  /* Crypto callback unavailable */
    267     PKCS7_SIGNEEDS_CHECK= -272,  /* signature needs verified by caller */
    268     PSS_SALTLEN_RECOVER_E=-273,  /* PSS slat length not recoverable */
    269     CHACHA_POLY_OVERFLOW =-274,  /* ChaCha20Poly1305 limit overflow */
    270     ASN_SELF_SIGNED_E   = -275,  /* ASN self-signed certificate error */
    271     SAKKE_VERIFY_FAIL_E = -276,  /* SAKKE derivation verification error */
    272     MISSING_IV          = -277,  /* IV was not set */
    273     MISSING_KEY         = -278,  /* Key was not set */
    274     BAD_LENGTH_E        = -279,  /* Value of length parameter is invalid. */
    275     ECDSA_KAT_FIPS_E    = -280,  /* ECDSA KAT failure */
    276     RSA_PAT_FIPS_E      = -281,  /* RSA Pairwise failure */
    277     KDF_TLS12_KAT_FIPS_E = -282, /* TLS12 KDF KAT failure */
    278     KDF_TLS13_KAT_FIPS_E = -283, /* TLS13 KDF KAT failure */
    279     KDF_SSH_KAT_FIPS_E  = -284,  /* SSH KDF KAT failure */
    280     DHE_PCT_E           = -285,  /* DHE Pairwise Consistency Test failure */
    281     ECC_PCT_E           = -286,  /* ECDHE Pairwise Consistency Test failure */
    282     FIPS_PRIVATE_KEY_LOCKED_E = -287, /* Cannot export private key. */
    283     PROTOCOLCB_UNAVAILABLE  = -288, /* Protocol callback unavailable */
    284     AES_SIV_AUTH_E      = -289,  /* AES-SIV authentication failed */
    285     NO_VALID_DEVID      = -290,  /* no valid device ID */
    286 
    287     IO_FAILED_E         = -291,  /* Input/output failure */
    288     SYSLIB_FAILED_E     = -292,  /* System/library call failed */
    289     USE_HW_PSK          = -293,  /* Callback return to indicate HW has PSK */
    290 
    291     ENTROPY_RT_E        = -294,  /* Entropy Repetition Test failed */
    292     ENTROPY_APT_E       = -295,  /* Entropy Adaptive Proportion Test failed */
    293 
    294     ASN_DEPTH_E         = -296,  /* Invalid ASN.1 - depth check */
    295     ASN_LEN_E           = -297,  /* ASN.1 length invalid */
    296 
    297     SM4_GCM_AUTH_E      = -298,  /* SM4-GCM Authentication check failure */
    298     SM4_CCM_AUTH_E      = -299,  /* SM4-CCM Authentication check failure */
    299 
    300     WC_SPAN1_LAST_E     = -299,  /* Last used code in span 1 */
    301     WC_SPAN1_MIN_CODE_E = -300,  /* Last usable code in span 1 */
    302 
    303     WC_SPAN2_FIRST_E    = -1000,
    304 
    305     DEADLOCK_AVERTED_E  = -1000, /* Deadlock averted -- retry the call */
    306     ASCON_AUTH_E        = -1001, /* ASCON Authentication check failure */
    307     WC_ACCEL_INHIBIT_E  = -1002, /* Crypto acceleration is currently inhibited */
    308 
    309     WC_SPAN2_LAST_E     = -1002, /* Update to indicate last used error code */
    310     WC_SPAN2_MIN_CODE_E = -1999, /* Last usable code in span 2 */
    311 
    312     WC_LAST_E           = -1002, /* the last code used either here or in
    313                                   * error-ssl.h
    314                                   */
    315 
    316     MIN_CODE_E          = -1999  /* the last code allocated either here or in
    317                                   * error-ssl.h
    318                                   */
    319 
    320     /* add new companion error id strings for any new error codes
    321        wolfcrypt/src/error.c !!! */
    322 };
    323 
    324 wc_static_assert((int)WC_LAST_E <= (int)WC_SPAN2_LAST_E);
    325 wc_static_assert((int)MIN_CODE_E <= (int)WC_LAST_E);
    326 wc_static_assert((int)MIN_CODE_E <= (int)WC_SPAN2_MIN_CODE_E);
    327 
    328 #ifdef NO_ERROR_STRINGS
    329     #define wc_GetErrorString(error) "no support for error strings built in"
    330     #define wc_ErrorString(err, buf) \
    331         (void)(err); XSTRNCPY((buf), wc_GetErrorString(err), \
    332         WOLFSSL_MAX_ERROR_SZ);
    333 
    334 #else
    335 WOLFSSL_API void wc_ErrorString(int err, char* buff);
    336 WOLFSSL_ABI WOLFSSL_API const char* wc_GetErrorString(int error);
    337 #endif
    338 
    339 #if defined(WOLFSSL_DEBUG_TRACE_ERROR_CODES) && \
    340         (defined(BUILDING_WOLFSSL) || \
    341          defined(WOLFSSL_DEBUG_TRACE_ERROR_CODES_ALWAYS))
    342     WOLFSSL_API extern void wc_backtrace_render(void);
    343     #define WC_NO_ERR_TRACE(label) (CONST_NUM_ERR_ ## label)
    344     #ifndef WOLFSSL_DEBUG_BACKTRACE_RENDER_CLAUSE
    345         #ifdef WOLFSSL_DEBUG_BACKTRACE_ERROR_CODES
    346             #define WOLFSSL_DEBUG_BACKTRACE_RENDER_CLAUSE wc_backtrace_render()
    347         #else
    348             #define WOLFSSL_DEBUG_BACKTRACE_RENDER_CLAUSE (void)0
    349         #endif
    350     #endif
    351     #ifndef WC_ERR_TRACE
    352         #ifdef NO_STDIO_FILESYSTEM
    353         #define WC_ERR_TRACE(label)                           \
    354             ( printf("ERR TRACE: %s L %d %s (%d)\n",          \
    355                       __FILE__, __LINE__, #label, label),     \
    356               WOLFSSL_DEBUG_BACKTRACE_RENDER_CLAUSE,          \
    357               label                                           \
    358             )
    359         #else
    360         #define WC_ERR_TRACE(label)                           \
    361             ( fprintf(stderr,                                 \
    362                       "ERR TRACE: %s L %d %s (%d)\n",         \
    363                       __FILE__, __LINE__, #label, label),     \
    364               WOLFSSL_DEBUG_BACKTRACE_RENDER_CLAUSE,          \
    365               label                                           \
    366             )
    367         #endif
    368     #endif
    369     #include <wolfssl/debug-trace-error-codes.h>
    370 #else
    371     #define WC_NO_ERR_TRACE(label) (label)
    372 #endif
    373 
    374 #ifdef __cplusplus
    375     } /* extern "C" */
    376 #endif
    377 #endif /* WOLF_CRYPT_ERROR_H */