add support for crypto cb only with ECC and CAAM

This commit is contained in:
JacobBarthelmeh
2024-02-23 08:09:19 -08:00
parent 8a68e6aaa1
commit 2364b699ff

View File

@ -245,15 +245,22 @@ ECC Curve Sizes:
#define HAVE_ECC_MAKE_PUB #define HAVE_ECC_MAKE_PUB
#endif #endif
/* macro guard for ecc_check_pubkey_order functionality */
#if !defined(WOLFSSL_SP_MATH) && \ #if !defined(WOLFSSL_SP_MATH) && \
!defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \ !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
!defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SILABS_SE_ACCEL) && \ !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SILABS_SE_ACCEL) && \
!defined(WOLFSSL_SE050) && !defined(WOLFSSL_STM32_PKA) && \ !defined(WOLFSSL_SE050) && !defined(WOLFSSL_STM32_PKA) && \
!defined(WOLF_CRYPTO_CB_ONLY_ECC) (!defined(WOLF_CRYPTO_CB_ONLY_ECC) || defined(WOLFSSL_IMXRT1170_CAAM) || \
defined(WOLFSSL_QNX_CAAM))
/* CAAM builds use public key validation as a means to check if an
* imported private key is an encrypted black key or not */
#undef HAVE_ECC_CHECK_PUBKEY_ORDER #undef HAVE_ECC_CHECK_PUBKEY_ORDER
#define HAVE_ECC_CHECK_PUBKEY_ORDER #define HAVE_ECC_CHECK_PUBKEY_ORDER
#endif #endif
#if defined(WOLFSSL_SP_MATH_ALL) && SP_INT_BITS < MAX_ECC_BITS_NEEDED #if defined(WOLFSSL_SP_MATH_ALL) && SP_INT_BITS < MAX_ECC_BITS_NEEDED
#define MAX_ECC_BITS_USE SP_INT_BITS #define MAX_ECC_BITS_USE SP_INT_BITS
#else #else
@ -1841,8 +1848,7 @@ static void alt_fp_init(mp_int* a)
#endif /* ALT_ECC_SIZE */ #endif /* ALT_ECC_SIZE */
#if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \ #ifdef HAVE_ECC_CHECK_PUBKEY_ORDER
!defined(WOLFSSL_CRYPTOCELL) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
#if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_PUBLIC_ECC_ADD_DBL) #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_PUBLIC_ECC_ADD_DBL)
static int _ecc_projective_dbl_point(ecc_point *P, ecc_point *R, mp_int* a, static int _ecc_projective_dbl_point(ecc_point *P, ecc_point *R, mp_int* a,
@ -5138,8 +5144,7 @@ int wc_ecc_point_is_on_curve(ecc_point *p, int curve_idx)
} }
#endif /* USE_ECC_B_PARAM */ #endif /* USE_ECC_B_PARAM */
#if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \ #ifdef HAVE_ECC_CHECK_PUBKEY_ORDER
!defined(WOLFSSL_CRYPTOCELL) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
/* return 1 if point is at infinity, 0 if not, < 0 on error */ /* return 1 if point is at infinity, 0 if not, < 0 on error */
int wc_ecc_point_is_at_infinity(ecc_point* p) int wc_ecc_point_is_at_infinity(ecc_point* p)
{ {
@ -5150,7 +5155,7 @@ int wc_ecc_point_is_at_infinity(ecc_point* p)
return 0; return 0;
} }
#endif /* !WOLFSSL_ATECC508A && !WOLFSSL_CRYPTOCELL */ #endif /* HAVE_ECC_CHECK_PUBKEY_ORDER */
/* generate random and ensure its greater than 0 and less than order */ /* generate random and ensure its greater than 0 and less than order */
int wc_ecc_gen_k(WC_RNG* rng, int size, mp_int* k, mp_int* order) int wc_ecc_gen_k(WC_RNG* rng, int size, mp_int* k, mp_int* order)
@ -7767,9 +7772,8 @@ int wc_ecc_free(ecc_key* key)
return 0; return 0;
} }
#if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \ #ifdef HAVE_ECC_CHECK_PUBKEY_ORDER
!defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SP_MATH) && \
!defined(WOLF_CRYPTO_CB_ONLY_ECC)
/* Handles add failure cases: /* Handles add failure cases:
* *
* Before add: * Before add:
@ -7883,8 +7887,7 @@ int ecc_projective_dbl_point_safe(ecc_point *P, ecc_point *R, mp_int* a,
return err; return err;
} }
#endif /* !WOLFSSL_ATECC508A && !WOLFSSL_ATECC608A #endif /* HAVE_ECC_CHECK_PUBKEY_ORDER */
&& !WOLFSSL_CRYPTOCELL && !WOLFSSL_SP_MATH */
#if !defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_ATECC508A) && \ #if !defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_ATECC508A) && \
!defined(WOLFSSL_ATECC608A) && !defined(WOLFSSL_CRYPTOCELL) && \ !defined(WOLFSSL_ATECC608A) && !defined(WOLFSSL_CRYPTOCELL) && \
@ -9606,9 +9609,7 @@ int wc_ecc_export_x963_ex(ecc_key* key, byte* out, word32* outLen,
#endif /* HAVE_ECC_KEY_EXPORT */ #endif /* HAVE_ECC_KEY_EXPORT */
#if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \ #ifdef HAVE_ECC_CHECK_PUBKEY_ORDER
!defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SE050) && \
!defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(WOLFSSL_STM32_PKA)
/* is ecc point on curve described by dp ? */ /* is ecc point on curve described by dp ? */
static int _ecc_is_point(ecc_point* ecp, mp_int* a, mp_int* b, mp_int* prime) static int _ecc_is_point(ecc_point* ecp, mp_int* a, mp_int* b, mp_int* prime)
@ -10107,7 +10108,7 @@ static int ecc_check_pubkey_order(ecc_key* key, ecc_point* pubkey, mp_int* a,
} }
#endif /* !WOLFSSL_SP_MATH */ #endif /* !WOLFSSL_SP_MATH */
#endif /* !WOLFSSL_ATECC508A && !WOLFSSL_CRYPTOCELL*/ #endif /* HAVE_ECC_CHECK_PUBKEY_ORDER */
#ifdef OPENSSL_EXTRA #ifdef OPENSSL_EXTRA
int wc_ecc_get_generator(ecc_point* ecp, int curve_idx) int wc_ecc_get_generator(ecc_point* ecp, int curve_idx)
@ -10148,10 +10149,7 @@ static int _ecc_validate_public_key(ecc_key* key, int partial, int priv)
{ {
int err = MP_OKAY; int err = MP_OKAY;
#ifndef WOLFSSL_SP_MATH #ifndef WOLFSSL_SP_MATH
#if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \ #ifdef HAVE_ECC_CHECK_PUBKEY_ORDER
!defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SILABS_SE_ACCEL) && \
!defined(WOLFSSL_SE050) && !defined(WOLF_CRYPTO_CB_ONLY_ECC) && \
!defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(WOLFSSL_STM32_PKA)
mp_int* b = NULL; mp_int* b = NULL;
#ifdef USE_ECC_B_PARAM #ifdef USE_ECC_B_PARAM
DECLARE_CURVE_SPECS(4); DECLARE_CURVE_SPECS(4);
@ -10161,8 +10159,7 @@ static int _ecc_validate_public_key(ecc_key* key, int partial, int priv)
#endif #endif
DECLARE_CURVE_SPECS(3); DECLARE_CURVE_SPECS(3);
#endif /* USE_ECC_B_PARAM */ #endif /* USE_ECC_B_PARAM */
#endif /* !WOLFSSL_ATECC508A && !WOLFSSL_ATECC608A && #endif /* HAVE_ECC_CHECK_PUBKEY_ORDER */
!WOLFSSL_CRYPTOCELL && !WOLFSSL_SILABS_SE_ACCEL && !WOLFSSL_SE050 */
#endif /* !WOLFSSL_SP_MATH */ #endif /* !WOLFSSL_SP_MATH */
ASSERT_SAVED_VECTOR_REGISTERS(); ASSERT_SAVED_VECTOR_REGISTERS();
@ -10208,7 +10205,7 @@ static int _ecc_validate_public_key(ecc_key* key, int partial, int priv)
/* consider key check success on HW crypto /* consider key check success on HW crypto
* ex: ATECC508/608A, CryptoCell and Silabs * ex: ATECC508/608A, CryptoCell and Silabs
* *
* consider key check success on Crypt Cb * consider key check success on most Crypt Cb only builds
*/ */
err = MP_OKAY; err = MP_OKAY;