Skip to content

Commit 2364b69

Browse files
add support for crypto cb only with ECC and CAAM
1 parent 8a68e6a commit 2364b69

1 file changed

Lines changed: 19 additions & 22 deletions

File tree

wolfcrypt/src/ecc.c

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,22 @@ ECC Curve Sizes:
245245
#define HAVE_ECC_MAKE_PUB
246246
#endif
247247

248+
249+
/* macro guard for ecc_check_pubkey_order functionality */
248250
#if !defined(WOLFSSL_SP_MATH) && \
249251
!defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
250252
!defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SILABS_SE_ACCEL) && \
251253
!defined(WOLFSSL_SE050) && !defined(WOLFSSL_STM32_PKA) && \
252-
!defined(WOLF_CRYPTO_CB_ONLY_ECC)
254+
(!defined(WOLF_CRYPTO_CB_ONLY_ECC) || defined(WOLFSSL_IMXRT1170_CAAM) || \
255+
defined(WOLFSSL_QNX_CAAM))
256+
257+
/* CAAM builds use public key validation as a means to check if an
258+
* imported private key is an encrypted black key or not */
253259
#undef HAVE_ECC_CHECK_PUBKEY_ORDER
254260
#define HAVE_ECC_CHECK_PUBKEY_ORDER
255261
#endif
256262

263+
257264
#if defined(WOLFSSL_SP_MATH_ALL) && SP_INT_BITS < MAX_ECC_BITS_NEEDED
258265
#define MAX_ECC_BITS_USE SP_INT_BITS
259266
#else
@@ -1841,8 +1848,7 @@ static void alt_fp_init(mp_int* a)
18411848
#endif /* ALT_ECC_SIZE */
18421849

18431850

1844-
#if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
1845-
!defined(WOLFSSL_CRYPTOCELL) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
1851+
#ifdef HAVE_ECC_CHECK_PUBKEY_ORDER
18461852

18471853
#if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_PUBLIC_ECC_ADD_DBL)
18481854
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)
51385144
}
51395145
#endif /* USE_ECC_B_PARAM */
51405146

5141-
#if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
5142-
!defined(WOLFSSL_CRYPTOCELL) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
5147+
#ifdef HAVE_ECC_CHECK_PUBKEY_ORDER
51435148
/* return 1 if point is at infinity, 0 if not, < 0 on error */
51445149
int wc_ecc_point_is_at_infinity(ecc_point* p)
51455150
{
@@ -5150,7 +5155,7 @@ int wc_ecc_point_is_at_infinity(ecc_point* p)
51505155

51515156
return 0;
51525157
}
5153-
#endif /* !WOLFSSL_ATECC508A && !WOLFSSL_CRYPTOCELL */
5158+
#endif /* HAVE_ECC_CHECK_PUBKEY_ORDER */
51545159

51555160
/* generate random and ensure its greater than 0 and less than order */
51565161
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)
77677772
return 0;
77687773
}
77697774

7770-
#if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
7771-
!defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SP_MATH) && \
7772-
!defined(WOLF_CRYPTO_CB_ONLY_ECC)
7775+
#ifdef HAVE_ECC_CHECK_PUBKEY_ORDER
7776+
77737777
/* Handles add failure cases:
77747778
*
77757779
* Before add:
@@ -7883,8 +7887,7 @@ int ecc_projective_dbl_point_safe(ecc_point *P, ecc_point *R, mp_int* a,
78837887

78847888
return err;
78857889
}
7886-
#endif /* !WOLFSSL_ATECC508A && !WOLFSSL_ATECC608A
7887-
&& !WOLFSSL_CRYPTOCELL && !WOLFSSL_SP_MATH */
7890+
#endif /* HAVE_ECC_CHECK_PUBKEY_ORDER */
78887891

78897892
#if !defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_ATECC508A) && \
78907893
!defined(WOLFSSL_ATECC608A) && !defined(WOLFSSL_CRYPTOCELL) && \
@@ -9606,9 +9609,7 @@ int wc_ecc_export_x963_ex(ecc_key* key, byte* out, word32* outLen,
96069609
#endif /* HAVE_ECC_KEY_EXPORT */
96079610

96089611

9609-
#if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
9610-
!defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SE050) && \
9611-
!defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(WOLFSSL_STM32_PKA)
9612+
#ifdef HAVE_ECC_CHECK_PUBKEY_ORDER
96129613

96139614
/* is ecc point on curve described by dp ? */
96149615
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,
1010710108
}
1010810109
#endif /* !WOLFSSL_SP_MATH */
1010910110

10110-
#endif /* !WOLFSSL_ATECC508A && !WOLFSSL_CRYPTOCELL*/
10111+
#endif /* HAVE_ECC_CHECK_PUBKEY_ORDER */
1011110112

1011210113
#ifdef OPENSSL_EXTRA
1011310114
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)
1014810149
{
1014910150
int err = MP_OKAY;
1015010151
#ifndef WOLFSSL_SP_MATH
10151-
#if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
10152-
!defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SILABS_SE_ACCEL) && \
10153-
!defined(WOLFSSL_SE050) && !defined(WOLF_CRYPTO_CB_ONLY_ECC) && \
10154-
!defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(WOLFSSL_STM32_PKA)
10152+
#ifdef HAVE_ECC_CHECK_PUBKEY_ORDER
1015510153
mp_int* b = NULL;
1015610154
#ifdef USE_ECC_B_PARAM
1015710155
DECLARE_CURVE_SPECS(4);
@@ -10161,8 +10159,7 @@ static int _ecc_validate_public_key(ecc_key* key, int partial, int priv)
1016110159
#endif
1016210160
DECLARE_CURVE_SPECS(3);
1016310161
#endif /* USE_ECC_B_PARAM */
10164-
#endif /* !WOLFSSL_ATECC508A && !WOLFSSL_ATECC608A &&
10165-
!WOLFSSL_CRYPTOCELL && !WOLFSSL_SILABS_SE_ACCEL && !WOLFSSL_SE050 */
10162+
#endif /* HAVE_ECC_CHECK_PUBKEY_ORDER */
1016610163
#endif /* !WOLFSSL_SP_MATH */
1016710164

1016810165
ASSERT_SAVED_VECTOR_REGISTERS();
@@ -10208,7 +10205,7 @@ static int _ecc_validate_public_key(ecc_key* key, int partial, int priv)
1020810205
/* consider key check success on HW crypto
1020910206
* ex: ATECC508/608A, CryptoCell and Silabs
1021010207
*
10211-
* consider key check success on Crypt Cb
10208+
* consider key check success on most Crypt Cb only builds
1021210209
*/
1021310210
err = MP_OKAY;
1021410211

0 commit comments

Comments
 (0)