Merge pull request #4982 from SparkiDev/sp_x64_improvements

SP ASM improvements
This commit is contained in:
David Garske
2022-03-25 13:04:01 -07:00
committed by GitHub
11 changed files with 52668 additions and 17870 deletions

View File

@@ -5837,12 +5837,12 @@ void bench_eccMakeKey(int doAsync, int curveId)
bench_stats_start(&count, &start); bench_stats_start(&count, &start);
do { do {
/* while free pending slots in queue, submit ops */ /* while free pending slots in queue, submit ops */
for (times = 0; times < genTimes || pending > 0; ) { for (times = 0; times < agreeTimes || pending > 0; ) {
bench_async_poll(&pending); bench_async_poll(&pending);
for (i = 0; i < BENCH_MAX_PENDING; i++) { for (i = 0; i < BENCH_MAX_PENDING; i++) {
if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&genKey[i]), 0, if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&genKey[i]), 0,
&times, genTimes, &pending)) { &times, agreeTimes, &pending)) {
wc_ecc_free(&genKey[i]); wc_ecc_free(&genKey[i]);
ret = wc_ecc_init_ex(&genKey[i], HEAP_HINT, deviceID); ret = wc_ecc_init_ex(&genKey[i], HEAP_HINT, deviceID);

View File

@@ -4260,16 +4260,9 @@ int wc_ecc_shared_secret(ecc_key* private_key, ecc_key* public_key, byte* out,
!defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_KCAPI_ECC) !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_KCAPI_ECC)
static int wc_ecc_shared_secret_gen_sync(ecc_key* private_key, ecc_point* point, static int wc_ecc_shared_secret_gen_sync(ecc_key* private_key, ecc_point* point,
byte* out, word32* outlen, ecc_curve_spec* curve) byte* out, word32* outlen)
{ {
int err = MP_OKAY; int err = MP_OKAY;
#if !defined(WOLFSSL_SP_MATH)
ecc_point* result = NULL;
#ifdef WOLFSSL_NO_MALLOC
ecc_point lcl_result;
#endif
word32 x = 0;
#endif
mp_int* k = &private_key->k; mp_int* k = &private_key->k;
#ifdef HAVE_ECC_CDH #ifdef HAVE_ECC_CDH
#ifdef WOLFSSL_SMALL_STACK #ifdef WOLFSSL_SMALL_STACK
@@ -4335,20 +4328,41 @@ static int wc_ecc_shared_secret_gen_sync(ecc_key* private_key, ecc_point* point,
#if defined(WOLFSSL_SP_MATH) #if defined(WOLFSSL_SP_MATH)
{ {
err = WC_KEY_SIZE_E; err = WC_KEY_SIZE_E;
(void)curve;
goto errout; goto errout;
} }
#else #else
{ {
ecc_point* result = NULL;
#ifdef WOLFSSL_NO_MALLOC
ecc_point lcl_result;
#endif
word32 x = 0;
mp_digit mp = 0; mp_digit mp = 0;
DECLARE_CURVE_SPECS(3);
/* load curve info */
ALLOC_CURVE_SPECS(3, err);
if (err == MP_OKAY) {
err = wc_ecc_curve_load(private_key->dp, &curve,
(ECC_CURVE_FIELD_PRIME | ECC_CURVE_FIELD_AF |
ECC_CURVE_FIELD_ORDER));
}
if (err != MP_OKAY) {
FREE_CURVE_SPECS();
goto errout;
}
/* make new point */ /* make new point */
#ifdef WOLFSSL_NO_MALLOC #ifdef WOLFSSL_NO_MALLOC
result = &lcl_result; result = &lcl_result;
#endif #endif
err = wc_ecc_new_point_ex(&result, private_key->heap); err = wc_ecc_new_point_ex(&result, private_key->heap);
if (err != MP_OKAY) if (err != MP_OKAY) {
wc_ecc_curve_free(curve);
FREE_CURVE_SPECS();
goto errout; goto errout;
}
#ifdef ECC_TIMING_RESISTANT #ifdef ECC_TIMING_RESISTANT
if (private_key->rng == NULL) { if (private_key->rng == NULL) {
@@ -4389,6 +4403,9 @@ static int wc_ecc_shared_secret_gen_sync(ecc_key* private_key, ecc_point* point,
*outlen = x; *outlen = x;
wc_ecc_del_point_ex(result, private_key->heap); wc_ecc_del_point_ex(result, private_key->heap);
wc_ecc_curve_free(curve);
FREE_CURVE_SPECS();
} }
#endif #endif
@@ -4410,10 +4427,23 @@ static int wc_ecc_shared_secret_gen_sync(ecc_key* private_key, ecc_point* point,
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC)
static int wc_ecc_shared_secret_gen_async(ecc_key* private_key, static int wc_ecc_shared_secret_gen_async(ecc_key* private_key,
ecc_point* point, byte* out, word32 *outlen, ecc_point* point, byte* out, word32 *outlen)
ecc_curve_spec* curve)
{ {
int err; int err;
DECLARE_CURVE_SPECS(3);
/* load curve info */
ALLOC_CURVE_SPECS(3, err);
if (err == MP_OKAY) {
err = wc_ecc_curve_load(private_key->dp, &curve,
(ECC_CURVE_FIELD_PRIME | ECC_CURVE_FIELD_AF |
ECC_CURVE_FIELD_ORDER));
}
if (err != MP_OKAY) {
FREE_CURVE_SPECS();
return err;
}
#if defined(HAVE_CAVIUM_V) || defined(HAVE_INTEL_QA) #if defined(HAVE_CAVIUM_V) || defined(HAVE_INTEL_QA)
if (private_key->dp if (private_key->dp
@@ -4455,6 +4485,8 @@ static int wc_ecc_shared_secret_gen_async(ecc_key* private_key,
&curve->Af->raw, &curve->Bf->raw, &curve->prime->raw, &curve->Af->raw, &curve->Bf->raw, &curve->prime->raw,
private_key->dp->cofactor); private_key->dp->cofactor);
#endif #endif
wc_ecc_curve_free(curve);
FREE_CURVE_SPECS();
return err; return err;
} }
#elif defined(WOLFSSL_ASYNC_CRYPT_TEST) #elif defined(WOLFSSL_ASYNC_CRYPT_TEST)
@@ -4464,6 +4496,8 @@ static int wc_ecc_shared_secret_gen_async(ecc_key* private_key,
testDev->eccSharedSec.public_point = point; testDev->eccSharedSec.public_point = point;
testDev->eccSharedSec.out = out; testDev->eccSharedSec.out = out;
testDev->eccSharedSec.outLen = outlen; testDev->eccSharedSec.outLen = outlen;
wc_ecc_curve_free(curve);
FREE_CURVE_SPECS();
return WC_PENDING_E; return WC_PENDING_E;
} }
#endif #endif
@@ -4471,6 +4505,9 @@ static int wc_ecc_shared_secret_gen_async(ecc_key* private_key,
/* use sync in other cases */ /* use sync in other cases */
err = wc_ecc_shared_secret_gen_sync(private_key, point, out, outlen, curve); err = wc_ecc_shared_secret_gen_sync(private_key, point, out, outlen, curve);
wc_ecc_curve_free(curve);
FREE_CURVE_SPECS();
return err; return err;
} }
#endif /* WOLFSSL_ASYNC_CRYPT && WC_ASYNC_ENABLE_ECC */ #endif /* WOLFSSL_ASYNC_CRYPT && WC_ASYNC_ENABLE_ECC */
@@ -4479,40 +4516,24 @@ int wc_ecc_shared_secret_gen(ecc_key* private_key, ecc_point* point,
byte* out, word32 *outlen) byte* out, word32 *outlen)
{ {
int err = MP_OKAY; int err = MP_OKAY;
DECLARE_CURVE_SPECS(3);
if (private_key == NULL || point == NULL || out == NULL || if (private_key == NULL || point == NULL || out == NULL ||
outlen == NULL) { outlen == NULL) {
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
} }
/* load curve info */
ALLOC_CURVE_SPECS(3, err);
if (err == MP_OKAY) {
err = wc_ecc_curve_load(private_key->dp, &curve,
(ECC_CURVE_FIELD_PRIME | ECC_CURVE_FIELD_AF | ECC_CURVE_FIELD_ORDER));
}
if (err != MP_OKAY) {
FREE_CURVE_SPECS();
return err;
}
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC)
if (private_key->asyncDev.marker == WOLFSSL_ASYNC_MARKER_ECC) { if (private_key->asyncDev.marker == WOLFSSL_ASYNC_MARKER_ECC) {
err = wc_ecc_shared_secret_gen_async(private_key, point, err = wc_ecc_shared_secret_gen_async(private_key, point,
out, outlen, curve); out, outlen);
} }
else else
#endif #endif
{ {
err = wc_ecc_shared_secret_gen_sync(private_key, point, err = wc_ecc_shared_secret_gen_sync(private_key, point,
out, outlen, curve); out, outlen);
} }
wc_ecc_curve_free(curve);
FREE_CURVE_SPECS();
return err; return err;
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff