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);
do {
/* 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);
for (i = 0; i < BENCH_MAX_PENDING; i++) {
if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(&genKey[i]), 0,
&times, genTimes, &pending)) {
&times, agreeTimes, &pending)) {
wc_ecc_free(&genKey[i]);
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)
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;
#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;
#ifdef HAVE_ECC_CDH
#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)
{
err = WC_KEY_SIZE_E;
(void)curve;
goto errout;
}
#else
{
ecc_point* result = NULL;
#ifdef WOLFSSL_NO_MALLOC
ecc_point lcl_result;
#endif
word32 x = 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 */
#ifdef WOLFSSL_NO_MALLOC
result = &lcl_result;
#endif
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;
}
#ifdef ECC_TIMING_RESISTANT
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;
wc_ecc_del_point_ex(result, private_key->heap);
wc_ecc_curve_free(curve);
FREE_CURVE_SPECS();
}
#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)
static int wc_ecc_shared_secret_gen_async(ecc_key* private_key,
ecc_point* point, byte* out, word32 *outlen,
ecc_curve_spec* curve)
ecc_point* point, byte* out, word32 *outlen)
{
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 (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,
private_key->dp->cofactor);
#endif
wc_ecc_curve_free(curve);
FREE_CURVE_SPECS();
return err;
}
#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.out = out;
testDev->eccSharedSec.outLen = outlen;
wc_ecc_curve_free(curve);
FREE_CURVE_SPECS();
return WC_PENDING_E;
}
#endif
@@ -4471,6 +4505,9 @@ static int wc_ecc_shared_secret_gen_async(ecc_key* private_key,
/* use sync in other cases */
err = wc_ecc_shared_secret_gen_sync(private_key, point, out, outlen, curve);
wc_ecc_curve_free(curve);
FREE_CURVE_SPECS();
return err;
}
#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)
{
int err = MP_OKAY;
DECLARE_CURVE_SPECS(3);
if (private_key == NULL || point == NULL || out == NULL ||
outlen == NULL) {
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 (private_key->asyncDev.marker == WOLFSSL_ASYNC_MARKER_ECC) {
err = wc_ecc_shared_secret_gen_async(private_key, point,
out, outlen, curve);
out, outlen);
}
else
#endif
{
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;
}

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