mirror of https://github.com/wolfSSL/wolfssl.git
Merge pull request #5868 from dgarske/ecc_pub_math
Expose more ECC math functions and improve async shared secretpull/5872/head
commit
c959d22b98
|
@ -4605,6 +4605,8 @@ 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)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
|
#if defined(HAVE_CAVIUM_V) || defined(HAVE_INTEL_QA)
|
||||||
DECLARE_CURVE_SPECS(3);
|
DECLARE_CURVE_SPECS(3);
|
||||||
|
|
||||||
/* load curve info */
|
/* load curve info */
|
||||||
|
@ -4620,7 +4622,6 @@ static int wc_ecc_shared_secret_gen_async(ecc_key* private_key,
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HAVE_CAVIUM_V) || defined(HAVE_INTEL_QA)
|
|
||||||
if (private_key->dp
|
if (private_key->dp
|
||||||
#ifdef WOLFSSL_CUSTOM_CURVES
|
#ifdef WOLFSSL_CUSTOM_CURVES
|
||||||
&& private_key->dp->id != ECC_CURVE_CUSTOM
|
&& private_key->dp->id != ECC_CURVE_CUSTOM
|
||||||
|
@ -4660,10 +4661,13 @@ 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();
|
if (err == WC_PENDING_E) {
|
||||||
return err;
|
/* advance state, next call will handle return code processing */
|
||||||
|
private_key->state++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
#elif defined(WOLFSSL_ASYNC_CRYPT_SW)
|
#elif defined(WOLFSSL_ASYNC_CRYPT_SW)
|
||||||
if (wc_AsyncSwInit(&private_key->asyncDev, ASYNC_SW_ECC_SHARED_SEC)) {
|
if (wc_AsyncSwInit(&private_key->asyncDev, ASYNC_SW_ECC_SHARED_SEC)) {
|
||||||
WC_ASYNC_SW* sw = &private_key->asyncDev.sw;
|
WC_ASYNC_SW* sw = &private_key->asyncDev.sw;
|
||||||
|
@ -4671,46 +4675,23 @@ static int wc_ecc_shared_secret_gen_async(ecc_key* private_key,
|
||||||
sw->eccSharedSec.public_point = point;
|
sw->eccSharedSec.public_point = point;
|
||||||
sw->eccSharedSec.out = out;
|
sw->eccSharedSec.out = out;
|
||||||
sw->eccSharedSec.outLen = outlen;
|
sw->eccSharedSec.outLen = outlen;
|
||||||
wc_ecc_curve_free(curve);
|
err = WC_PENDING_E;
|
||||||
FREE_CURVE_SPECS();
|
|
||||||
return WC_PENDING_E;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* use sync in other cases */
|
|
||||||
err = wc_ecc_shared_secret_gen_sync(private_key, point, out, outlen);
|
|
||||||
|
|
||||||
wc_ecc_curve_free(curve);
|
|
||||||
FREE_CURVE_SPECS();
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
#endif /* WOLFSSL_ASYNC_CRYPT && WC_ASYNC_ENABLE_ECC */
|
|
||||||
|
|
||||||
int wc_ecc_shared_secret_gen(ecc_key* private_key, ecc_point* point,
|
|
||||||
byte* out, word32 *outlen)
|
|
||||||
{
|
|
||||||
int err = MP_OKAY;
|
|
||||||
|
|
||||||
if (private_key == NULL || point == NULL || out == NULL ||
|
|
||||||
outlen == NULL) {
|
|
||||||
return BAD_FUNC_ARG;
|
|
||||||
}
|
|
||||||
|
|
||||||
#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);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
err = wc_ecc_shared_secret_gen_sync(private_key, point,
|
/* use sync in other cases */
|
||||||
out, outlen);
|
err = wc_ecc_shared_secret_gen_sync(private_key, point, out, outlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(HAVE_CAVIUM_V) || defined(HAVE_INTEL_QA)
|
||||||
|
wc_ecc_curve_free(curve);
|
||||||
|
FREE_CURVE_SPECS();
|
||||||
|
#endif
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
#endif /* WOLFSSL_ASYNC_CRYPT && WC_ASYNC_ENABLE_ECC */
|
||||||
|
|
||||||
#ifndef WOLF_CRYPTO_CB_ONLY_ECC
|
#ifndef WOLF_CRYPTO_CB_ONLY_ECC
|
||||||
/**
|
/**
|
||||||
|
@ -4752,7 +4733,23 @@ int wc_ecc_shared_secret_ex(ecc_key* private_key, ecc_point* point,
|
||||||
case ECC_STATE_SHARED_SEC_GEN:
|
case ECC_STATE_SHARED_SEC_GEN:
|
||||||
private_key->state = ECC_STATE_SHARED_SEC_GEN;
|
private_key->state = ECC_STATE_SHARED_SEC_GEN;
|
||||||
|
|
||||||
err = wc_ecc_shared_secret_gen(private_key, point, out, outlen);
|
#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);
|
||||||
|
if (err == 0) {
|
||||||
|
/* advance state and exit early */
|
||||||
|
private_key->state++;
|
||||||
|
RESTORE_VECTOR_REGISTERS();
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
err = wc_ecc_shared_secret_gen_sync(private_key, point,
|
||||||
|
out, outlen);
|
||||||
|
}
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -4783,7 +4780,6 @@ int wc_ecc_shared_secret_ex(ecc_key* private_key, ecc_point* point,
|
||||||
|
|
||||||
/* if async pending then return and skip done cleanup below */
|
/* if async pending then return and skip done cleanup below */
|
||||||
if (err == WC_PENDING_E) {
|
if (err == WC_PENDING_E) {
|
||||||
private_key->state++;
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5029,7 +5025,7 @@ static int ecc_make_pub_ex(ecc_key* key, ecc_curve_spec* curveIn,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) && \
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC_KEYGEN) && \
|
||||||
defined(HAVE_INTEL_QA)
|
defined(HAVE_INTEL_QA)
|
||||||
if (err == MP_OKAY && key->asyncDev.marker == WOLFSSL_ASYNC_MARKER_ECC) {
|
if (err == MP_OKAY && key->asyncDev.marker == WOLFSSL_ASYNC_MARKER_ECC) {
|
||||||
word32 keySz = key->dp->size;
|
word32 keySz = key->dp->size;
|
||||||
|
|
|
@ -570,12 +570,10 @@ ECC_API int ecc_projective_add_point(ecc_point* P, ecc_point* Q, ecc_point* R,
|
||||||
ECC_API int ecc_projective_dbl_point(ecc_point* P, ecc_point* R, mp_int* a,
|
ECC_API int ecc_projective_dbl_point(ecc_point* P, ecc_point* R, mp_int* a,
|
||||||
mp_int* modulus, mp_digit mp);
|
mp_int* modulus, mp_digit mp);
|
||||||
|
|
||||||
WOLFSSL_LOCAL
|
ECC_API int ecc_projective_add_point_safe(ecc_point* A, ecc_point* B,
|
||||||
int ecc_projective_add_point_safe(ecc_point* A, ecc_point* B, ecc_point* R,
|
ecc_point* R, mp_int* a, mp_int* modulus, mp_digit mp, int* infinity);
|
||||||
mp_int* a, mp_int* modulus, mp_digit mp, int* infinity);
|
ECC_API int ecc_projective_dbl_point_safe(ecc_point* P, ecc_point* R, mp_int* a,
|
||||||
WOLFSSL_LOCAL
|
mp_int* modulus, mp_digit mp);
|
||||||
int ecc_projective_dbl_point_safe(ecc_point* P, ecc_point* R, mp_int* a,
|
|
||||||
mp_int* modulus, mp_digit mp);
|
|
||||||
|
|
||||||
WOLFSSL_ABI WOLFSSL_API
|
WOLFSSL_ABI WOLFSSL_API
|
||||||
int wc_ecc_make_key(WC_RNG* rng, int keysize, ecc_key* key);
|
int wc_ecc_make_key(WC_RNG* rng, int keysize, ecc_key* key);
|
||||||
|
@ -599,9 +597,7 @@ int wc_ecc_get_generator(ecc_point* ecp, int curve_idx);
|
||||||
WOLFSSL_ABI WOLFSSL_API
|
WOLFSSL_ABI WOLFSSL_API
|
||||||
int wc_ecc_shared_secret(ecc_key* private_key, ecc_key* public_key, byte* out,
|
int wc_ecc_shared_secret(ecc_key* private_key, ecc_key* public_key, byte* out,
|
||||||
word32* outlen);
|
word32* outlen);
|
||||||
WOLFSSL_LOCAL
|
|
||||||
int wc_ecc_shared_secret_gen(ecc_key* private_key, ecc_point* point,
|
|
||||||
byte* out, word32 *outlen);
|
|
||||||
WOLFSSL_API
|
WOLFSSL_API
|
||||||
int wc_ecc_shared_secret_ex(ecc_key* private_key, ecc_point* point,
|
int wc_ecc_shared_secret_ex(ecc_key* private_key, ecc_point* point,
|
||||||
byte* out, word32 *outlen);
|
byte* out, word32 *outlen);
|
||||||
|
@ -727,10 +723,10 @@ int wc_ecc_point_is_on_curve(ecc_point *p, int curve_idx);
|
||||||
WOLFSSL_API
|
WOLFSSL_API
|
||||||
int wc_ecc_mulmod(const mp_int* k, ecc_point *G, ecc_point *R,
|
int wc_ecc_mulmod(const mp_int* k, ecc_point *G, ecc_point *R,
|
||||||
mp_int* a, mp_int* modulus, int map);
|
mp_int* a, mp_int* modulus, int map);
|
||||||
WOLFSSL_LOCAL
|
ECC_API
|
||||||
int wc_ecc_mulmod_ex(const mp_int* k, ecc_point *G, ecc_point *R,
|
int wc_ecc_mulmod_ex(const mp_int* k, ecc_point *G, ecc_point *R,
|
||||||
mp_int* a, mp_int* modulus, int map, void* heap);
|
mp_int* a, mp_int* modulus, int map, void* heap);
|
||||||
WOLFSSL_LOCAL
|
ECC_API
|
||||||
int wc_ecc_mulmod_ex2(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
|
int wc_ecc_mulmod_ex2(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
|
||||||
mp_int* modulus, mp_int* order, WC_RNG* rng, int map,
|
mp_int* modulus, mp_int* order, WC_RNG* rng, int map,
|
||||||
void* heap);
|
void* heap);
|
||||||
|
|
Loading…
Reference in New Issue