Skip to content

Commit 51b85ee

Browse files
authored
Merge pull request #7490 from dgarske/ecc_curvecache_nomalloc
Support for ECC_CACHE_CURVE with no malloc
2 parents 75b178f + 3afa420 commit 51b85ee

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

wolfcrypt/src/ecc.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,11 @@ static int xil_mpi_import(mp_int *mpi,
14951495

14961496
#ifdef ECC_CACHE_CURVE
14971497
/* cache (mp_int) of the curve parameters */
1498+
#ifdef WOLFSSL_NO_MALLOC
1499+
static ecc_curve_spec ecc_curve_spec_cache[ECC_SET_COUNT];
1500+
#else
14981501
static ecc_curve_spec* ecc_curve_spec_cache[ECC_SET_COUNT];
1502+
#endif
14991503
#ifndef SINGLE_THREADED
15001504
static wolfSSL_Mutex ecc_curve_cache_mutex WOLFSSL_MUTEX_INITIALIZER_CLAUSE(ecc_curve_cache_mutex);
15011505
#endif
@@ -1675,6 +1679,9 @@ static int wc_ecc_curve_load(const ecc_set_type* dp, ecc_curve_spec** pCurve,
16751679
}
16761680
#endif
16771681

1682+
#ifdef WOLFSSL_NO_MALLOC
1683+
curve = &ecc_curve_spec_cache[x];
1684+
#else
16781685
/* make sure cache has been allocated */
16791686
if (ecc_curve_spec_cache[x] == NULL
16801687
#ifdef WOLFSSL_CUSTOM_CURVES
@@ -1701,6 +1708,8 @@ static int wc_ecc_curve_load(const ecc_set_type* dp, ecc_curve_spec** pCurve,
17011708
else {
17021709
curve = ecc_curve_spec_cache[x];
17031710
}
1711+
#endif /* WOLFSSL_NO_MALLOC */
1712+
17041713
/* return new or cached curve */
17051714
*pCurve = curve;
17061715
#else
@@ -1780,11 +1789,16 @@ void wc_ecc_curve_cache_free(void)
17801789

17811790
/* free all ECC curve caches */
17821791
for (x = 0; x < (int)ECC_SET_COUNT; x++) {
1792+
#ifdef WOLFSSL_NO_MALLOC
1793+
wc_ecc_curve_cache_free_spec(&ecc_curve_spec_cache[x]);
1794+
XMEMSET(&ecc_curve_spec_cache[x], 0, sizeof(ecc_curve_spec_cache[x]));
1795+
#else
17831796
if (ecc_curve_spec_cache[x]) {
17841797
wc_ecc_curve_cache_free_spec(ecc_curve_spec_cache[x]);
17851798
XFREE(ecc_curve_spec_cache[x], NULL, DYNAMIC_TYPE_ECC);
17861799
ecc_curve_spec_cache[x] = NULL;
17871800
}
1801+
#endif /* WOLFSSL_NO_MALLOC */
17881802
}
17891803

17901804
#if defined(ECC_CACHE_CURVE) && !defined(SINGLE_THREADED) && \

wolfssl/wolfcrypt/settings.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2755,7 +2755,9 @@ extern void uITRON4_free(void *p) ;
27552755
#endif
27562756

27572757
/* Enable ECC_CACHE_CURVE for ASYNC */
2758-
#if !defined(ECC_CACHE_CURVE)
2758+
#if !defined(ECC_CACHE_CURVE) && !defined(NO_ECC_CACHE_CURVE)
2759+
/* Enabled by default for increased async performance,
2760+
* but not required */
27592761
#define ECC_CACHE_CURVE
27602762
#endif
27612763
#endif /* WOLFSSL_ASYNC_CRYPT */

0 commit comments

Comments
 (0)