mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-29 18:27:29 +02:00
Merge pull request #7490 from dgarske/ecc_curvecache_nomalloc
Support for ECC_CACHE_CURVE with no malloc
This commit is contained in:
@ -1495,7 +1495,11 @@ static int xil_mpi_import(mp_int *mpi,
|
||||
|
||||
#ifdef ECC_CACHE_CURVE
|
||||
/* cache (mp_int) of the curve parameters */
|
||||
#ifdef WOLFSSL_NO_MALLOC
|
||||
static ecc_curve_spec ecc_curve_spec_cache[ECC_SET_COUNT];
|
||||
#else
|
||||
static ecc_curve_spec* ecc_curve_spec_cache[ECC_SET_COUNT];
|
||||
#endif
|
||||
#ifndef SINGLE_THREADED
|
||||
static wolfSSL_Mutex ecc_curve_cache_mutex WOLFSSL_MUTEX_INITIALIZER_CLAUSE(ecc_curve_cache_mutex);
|
||||
#endif
|
||||
@ -1675,6 +1679,9 @@ static int wc_ecc_curve_load(const ecc_set_type* dp, ecc_curve_spec** pCurve,
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_NO_MALLOC
|
||||
curve = &ecc_curve_spec_cache[x];
|
||||
#else
|
||||
/* make sure cache has been allocated */
|
||||
if (ecc_curve_spec_cache[x] == NULL
|
||||
#ifdef WOLFSSL_CUSTOM_CURVES
|
||||
@ -1701,6 +1708,8 @@ static int wc_ecc_curve_load(const ecc_set_type* dp, ecc_curve_spec** pCurve,
|
||||
else {
|
||||
curve = ecc_curve_spec_cache[x];
|
||||
}
|
||||
#endif /* WOLFSSL_NO_MALLOC */
|
||||
|
||||
/* return new or cached curve */
|
||||
*pCurve = curve;
|
||||
#else
|
||||
@ -1780,11 +1789,16 @@ void wc_ecc_curve_cache_free(void)
|
||||
|
||||
/* free all ECC curve caches */
|
||||
for (x = 0; x < (int)ECC_SET_COUNT; x++) {
|
||||
#ifdef WOLFSSL_NO_MALLOC
|
||||
wc_ecc_curve_cache_free_spec(&ecc_curve_spec_cache[x]);
|
||||
XMEMSET(&ecc_curve_spec_cache[x], 0, sizeof(ecc_curve_spec_cache[x]));
|
||||
#else
|
||||
if (ecc_curve_spec_cache[x]) {
|
||||
wc_ecc_curve_cache_free_spec(ecc_curve_spec_cache[x]);
|
||||
XFREE(ecc_curve_spec_cache[x], NULL, DYNAMIC_TYPE_ECC);
|
||||
ecc_curve_spec_cache[x] = NULL;
|
||||
}
|
||||
#endif /* WOLFSSL_NO_MALLOC */
|
||||
}
|
||||
|
||||
#if defined(ECC_CACHE_CURVE) && !defined(SINGLE_THREADED) && \
|
||||
|
@ -2755,7 +2755,9 @@ extern void uITRON4_free(void *p) ;
|
||||
#endif
|
||||
|
||||
/* Enable ECC_CACHE_CURVE for ASYNC */
|
||||
#if !defined(ECC_CACHE_CURVE)
|
||||
#if !defined(ECC_CACHE_CURVE) && !defined(NO_ECC_CACHE_CURVE)
|
||||
/* Enabled by default for increased async performance,
|
||||
* but not required */
|
||||
#define ECC_CACHE_CURVE
|
||||
#endif
|
||||
#endif /* WOLFSSL_ASYNC_CRYPT */
|
||||
|
Reference in New Issue
Block a user