@@ -4605,6 +4605,8 @@ static int wc_ecc_shared_secret_gen_async(ecc_key* private_key,
46054605 ecc_point * point , byte * out , word32 * outlen )
46064606{
46074607 int err = 0 ;
4608+
4609+ #if defined(HAVE_CAVIUM_V ) || defined(HAVE_INTEL_QA )
46084610 DECLARE_CURVE_SPECS (3 );
46094611
46104612 /* load curve info */
@@ -4620,7 +4622,6 @@ static int wc_ecc_shared_secret_gen_async(ecc_key* private_key,
46204622 return err ;
46214623 }
46224624
4623- #if defined(HAVE_CAVIUM_V ) || defined(HAVE_INTEL_QA )
46244625 if (private_key -> dp
46254626 #ifdef WOLFSSL_CUSTOM_CURVES
46264627 && private_key -> dp -> id != ECC_CURVE_CUSTOM
@@ -4660,57 +4661,37 @@ static int wc_ecc_shared_secret_gen_async(ecc_key* private_key,
46604661 & curve -> Af -> raw , & curve -> Bf -> raw , & curve -> prime -> raw ,
46614662 private_key -> dp -> cofactor );
46624663 #endif
4663- wc_ecc_curve_free (curve );
4664- FREE_CURVE_SPECS ();
4665- return err ;
4664+
4665+ if (err == WC_PENDING_E ) {
4666+ /* advance state, next call will handle return code processing */
4667+ private_key -> state ++ ;
4668+ }
46664669 }
4670+ else
46674671#elif defined(WOLFSSL_ASYNC_CRYPT_SW )
46684672 if (wc_AsyncSwInit (& private_key -> asyncDev , ASYNC_SW_ECC_SHARED_SEC )) {
46694673 WC_ASYNC_SW * sw = & private_key -> asyncDev .sw ;
46704674 sw -> eccSharedSec .private_key = private_key ;
46714675 sw -> eccSharedSec .public_point = point ;
46724676 sw -> eccSharedSec .out = out ;
46734677 sw -> eccSharedSec .outLen = outlen ;
4674- wc_ecc_curve_free (curve );
4675- FREE_CURVE_SPECS ();
4676- return WC_PENDING_E ;
4678+ err = WC_PENDING_E ;
46774679 }
4680+ else
46784681#endif
4682+ {
4683+ /* use sync in other cases */
4684+ err = wc_ecc_shared_secret_gen_sync (private_key , point , out , outlen );
4685+ }
46794686
4680- /* use sync in other cases */
4681- err = wc_ecc_shared_secret_gen_sync (private_key , point , out , outlen );
4682-
4687+ #if defined(HAVE_CAVIUM_V ) || defined(HAVE_INTEL_QA )
46834688 wc_ecc_curve_free (curve );
46844689 FREE_CURVE_SPECS ();
4685-
4686- return err ;
4687- }
4688- #endif /* WOLFSSL_ASYNC_CRYPT && WC_ASYNC_ENABLE_ECC */
4689-
4690- int wc_ecc_shared_secret_gen (ecc_key * private_key , ecc_point * point ,
4691- byte * out , word32 * outlen )
4692- {
4693- int err = MP_OKAY ;
4694-
4695- if (private_key == NULL || point == NULL || out == NULL ||
4696- outlen == NULL ) {
4697- return BAD_FUNC_ARG ;
4698- }
4699-
4700- #if defined(WOLFSSL_ASYNC_CRYPT ) && defined(WC_ASYNC_ENABLE_ECC )
4701- if (private_key -> asyncDev .marker == WOLFSSL_ASYNC_MARKER_ECC ) {
4702- err = wc_ecc_shared_secret_gen_async (private_key , point ,
4703- out , outlen );
4704- }
4705- else
47064690#endif
4707- {
4708- err = wc_ecc_shared_secret_gen_sync (private_key , point ,
4709- out , outlen );
4710- }
47114691
47124692 return err ;
47134693}
4694+ #endif /* WOLFSSL_ASYNC_CRYPT && WC_ASYNC_ENABLE_ECC */
47144695
47154696#ifndef WOLF_CRYPTO_CB_ONLY_ECC
47164697/**
@@ -4752,7 +4733,23 @@ int wc_ecc_shared_secret_ex(ecc_key* private_key, ecc_point* point,
47524733 case ECC_STATE_SHARED_SEC_GEN :
47534734 private_key -> state = ECC_STATE_SHARED_SEC_GEN ;
47544735
4755- err = wc_ecc_shared_secret_gen (private_key , point , out , outlen );
4736+ #if defined(WOLFSSL_ASYNC_CRYPT ) && defined(WC_ASYNC_ENABLE_ECC )
4737+ if (private_key -> asyncDev .marker == WOLFSSL_ASYNC_MARKER_ECC ) {
4738+ err = wc_ecc_shared_secret_gen_async (private_key , point ,
4739+ out , outlen );
4740+ if (err == 0 ) {
4741+ /* advance state and exit early */
4742+ private_key -> state ++ ;
4743+ RESTORE_VECTOR_REGISTERS ();
4744+ return err ;
4745+ }
4746+ }
4747+ else
4748+ #endif
4749+ {
4750+ err = wc_ecc_shared_secret_gen_sync (private_key , point ,
4751+ out , outlen );
4752+ }
47564753 if (err < 0 ) {
47574754 break ;
47584755 }
@@ -4783,7 +4780,6 @@ int wc_ecc_shared_secret_ex(ecc_key* private_key, ecc_point* point,
47834780
47844781 /* if async pending then return and skip done cleanup below */
47854782 if (err == WC_PENDING_E ) {
4786- private_key -> state ++ ;
47874783 return err ;
47884784 }
47894785
@@ -5029,7 +5025,7 @@ static int ecc_make_pub_ex(ecc_key* key, ecc_curve_spec* curveIn,
50295025 #endif
50305026 }
50315027
5032- #if defined(WOLFSSL_ASYNC_CRYPT ) && defined(WC_ASYNC_ENABLE_ECC ) && \
5028+ #if defined(WOLFSSL_ASYNC_CRYPT ) && defined(WC_ASYNC_ENABLE_ECC_KEYGEN ) && \
50335029 defined(HAVE_INTEL_QA )
50345030 if (err == MP_OKAY && key -> asyncDev .marker == WOLFSSL_ASYNC_MARKER_ECC ) {
50355031 word32 keySz = key -> dp -> size ;
0 commit comments