6464# else
6565# error "No memory driver type defined"
6666# endif
67+ # ifdef QAT_HW_INTREE
68+ # define ENABLE_QAT_HW_SHA3
69+ # define ENABLE_QAT_HW_CHACHAPOLY
70+ # endif
6771#endif
6872
6973/* Standard Includes */
9599# include "qat_hw_rsa.h"
96100# include "qat_hw_dsa.h"
97101# include "qat_hw_dh.h"
98- # include "qat_hw_ec.h"
99102# include "qat_hw_gcm.h"
100103
101104/* QAT includes */
149152
150153/* Qat engine id declaration */
151154const char * engine_qat_id = STR (QAT_ENGINE_ID );
152- #ifdef QAT_HW
155+ #if defined(QAT_HW ) && defined(QAT_SW )
156+ const char * engine_qat_name =
157+ "Reference implementation of QAT crypto engine(qat_hw & qat_sw) v0.6.8" ;
158+ #elif QAT_HW
153159const char * engine_qat_name =
154160 "Reference implementation of QAT crypto engine(qat_hw) v0.6.8" ;
155161#else
@@ -162,7 +168,8 @@ int qat_hw_offload = 0;
162168int qat_sw_offload = 0 ;
163169int qat_hw_rsa_offload = 0 ;
164170int qat_hw_ecx_offload = 0 ;
165- int qat_hw_ec_offload = 0 ;
171+ int qat_hw_ecdh_offload = 0 ;
172+ int qat_hw_ecdsa_offload = 0 ;
166173int qat_keep_polling = 1 ;
167174int multibuff_keep_polling = 1 ;
168175int enable_external_polling = 0 ;
@@ -344,15 +351,17 @@ static int qat_engine_destroy(ENGINE *e)
344351{
345352 DEBUG ("---- Destroying Engine...\n\n" );
346353#ifdef QAT_HW
347- qat_free_EC_methods ();
348354 qat_free_DH_methods ();
349355 qat_free_DSA_methods ();
350356 qat_free_RSA_methods ();
351357#endif
352358
353359#ifdef QAT_SW
354360 multibuff_free_RSA_methods ();
355- mb_free_EC_methods ();
361+ #endif
362+
363+ #if defined(QAT_SW ) || defined(QAT_HW )
364+ qat_free_EC_methods ();
356365#endif
357366
358367#if defined(QAT_SW_IPSEC ) || defined(QAT_HW )
@@ -365,8 +374,6 @@ static int qat_engine_destroy(ENGINE *e)
365374# endif
366375#endif
367376
368- qat_hw_offload = 0 ;
369- qat_sw_offload = 0 ;
370377 QAT_DEBUG_LOG_CLOSE ();
371378 ERR_unload_QAT_strings ();
372379 return 1 ;
@@ -495,6 +502,12 @@ int qat_engine_finish_int(ENGINE *e, int reset_globals)
495502 if (reset_globals == QAT_RESET_GLOBALS ) {
496503 enable_external_polling = 0 ;
497504 enable_heuristic_polling = 0 ;
505+ qat_hw_offload = 0 ;
506+ qat_sw_offload = 0 ;
507+ qat_hw_rsa_offload = 0 ;
508+ qat_hw_ecx_offload = 0 ;
509+ qat_hw_ecdh_offload = 0 ;
510+ qat_hw_ecdsa_offload = 0 ;
498511 }
499512 qat_pthread_mutex_unlock ();
500513 CRYPTO_CLOSE_QAT_LOG ();
@@ -556,9 +569,10 @@ int qat_engine_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void))
556569 BREAK_IF (!enable_external_polling , "POLL failed as external polling is not enabled\n" );
557570 BREAK_IF (p == NULL , "POLL failed as the input parameter was NULL\n" );
558571#ifdef QAT_HW
559- BREAK_IF (qat_instance_handles == NULL , "POLL failed as no instances are available\n" );
560-
561- * (int * )p = (int )poll_instances ();
572+ if (qat_hw_offload ) {
573+ BREAK_IF (qat_instance_handles == NULL , "POLL failed as no instances are available\n" );
574+ * (int * )p = (int )poll_instances ();
575+ }
562576#endif
563577
564578#ifdef QAT_SW
@@ -833,12 +847,16 @@ static int bind_qat(ENGINE *e, const char *id)
833847 WARN ("%s - %s \n" , id , engine_qat_name );
834848
835849#ifdef QAT_HW
836- #ifdef QAT_HW_INTREE
850+ # ifdef QAT_HW_INTREE
837851 if (icp_sal_userIsQatAvailable () == CPA_TRUE ) {
838852 qat_hw_offload = 1 ;
839853 } else {
840854 WARN ("Qat Intree device not available\n" );
841- #else
855+ # ifndef QAT_SW
856+ goto end ;
857+ # endif
858+ }
859+ # else
842860 if (access (QAT_DEV , F_OK ) == 0 ) {
843861 qat_hw_offload = 1 ;
844862 if (access (QAT_MEM_DEV , F_OK ) != 0 ) {
@@ -847,8 +865,11 @@ static int bind_qat(ENGINE *e, const char *id)
847865 }
848866 } else {
849867 WARN ("Qat device not available\n" );
868+ # ifndef QAT_SW
869+ goto end ;
870+ # endif
850871 }
851- #endif
872+ # endif
852873#endif
853874
854875 if (id && (strcmp (id , engine_qat_id ) != 0 )) {
@@ -898,13 +919,6 @@ static int bind_qat(ENGINE *e, const char *id)
898919 }
899920# endif
900921
901- # if defined(ENABLE_QAT_HW_ECDH ) || defined(ENABLE_QAT_HW_ECDSA )
902- if (!ENGINE_set_EC (e , qat_get_EC_methods ())) {
903- WARN ("ENGINE_set_EC QAT HW failed\n" );
904- goto end ;
905- }
906- # endif
907-
908922# ifdef ENABLE_QAT_HW_SHA3
909923 if (!ENGINE_set_digests (e , qat_digest_methods )) {
910924 WARN ("ENGINE_set_digests failed\n" );
@@ -931,20 +945,6 @@ static int bind_qat(ENGINE *e, const char *id)
931945 }
932946# endif
933947
934- # if defined(ENABLE_QAT_SW_ECDH ) || defined(ENABLE_QAT_SW_ECDSA )
935- if (!qat_hw_ec_offload &&
936- mbx_get_algo_info (MBX_ALGO_ECDHE_NIST_P256 ) &&
937- mbx_get_algo_info (MBX_ALGO_ECDHE_NIST_P384 ) &&
938- mbx_get_algo_info (MBX_ALGO_ECDSA_NIST_P256 ) &&
939- mbx_get_algo_info (MBX_ALGO_ECDSA_NIST_P384 )) {
940- DEBUG ("QAT SW ECDSA p256/p384 & ECDH p256/p384 Supported\n" );
941- qat_sw_offload = 1 ;
942- if (!ENGINE_set_EC (e , mb_get_EC_methods ())) {
943- WARN ("ENGINE_set_EC QAT SW failed\n" );
944- goto end ;
945- }
946- }
947- # endif
948948#endif
949949
950950#ifdef QAT_SW_IPSEC
@@ -959,6 +959,20 @@ static int bind_qat(ENGINE *e, const char *id)
959959#endif
960960
961961#if defined(QAT_HW ) || defined(QAT_SW )
962+ if (!ENGINE_set_EC (e , qat_get_EC_methods ())) {
963+ WARN ("ENGINE_set_EC failed\n" );
964+ goto end ;
965+ }
966+ # if defined(ENABLE_QAT_SW_ECDH ) || defined(ENABLE_QAT_SW_ECDSA )
967+ if (mbx_get_algo_info (MBX_ALGO_ECDHE_NIST_P256 ) &&
968+ mbx_get_algo_info (MBX_ALGO_ECDHE_NIST_P384 ) &&
969+ mbx_get_algo_info (MBX_ALGO_ECDSA_NIST_P256 ) &&
970+ mbx_get_algo_info (MBX_ALGO_ECDSA_NIST_P384 )) {
971+ DEBUG ("QAT SW ECDSA p256/p384 & ECDH p256/p384 Supported\n" );
972+ qat_sw_offload = 1 ;
973+ }
974+ # endif
975+
962976# ifndef QAT_OPENSSL_3
963977 if (!ENGINE_set_pkey_meths (e , qat_pkey_methods )) {
964978 WARN ("ENGINE_set_pkey_meths failed\n" );
0 commit comments