124124#endif /* QAT_BORINGSSL */
125125#endif
126126
127+ #ifdef QAT_SW_IPSEC
128+ # if defined(ENABLE_QAT_FIPS ) && defined(ENABLE_QAT_SW_SHA2 )
129+ # include "qat_sw_sha2.h"
130+ # endif
131+ #endif
132+
127133/* OpenSSL Includes */
128134#include <openssl/err.h>
129135#include <openssl/objects.h>
137143# define Genu 0x756e6547
138144# define ineI 0x49656e69
139145# define ntel 0x6c65746e
140-
141146# define VAES_BIT 9
142147# define VPCLMULQDQ_BIT 10
143148# define AVX512F_BIT 16
149154# define QAT_ENGINE_ID qatengine
150155#endif
151156
157+ #ifdef ENABLE_QAT_FIPS
158+ int qat_fips_key_zeroize ;
159+ int qat_fips_kat_test ;
160+ #endif
161+
152162/* Qat engine id declaration */
153163const char * engine_qat_id = STR (QAT_ENGINE_ID );
154164#if defined(QAT_HW ) && defined(QAT_SW )
@@ -184,6 +194,14 @@ int qat_hw_sm4_cbc_offload = 0;
184194int qat_sw_sm2_offload = 0 ;
185195int qat_hw_sha_offload = 0 ;
186196int qat_hw_sm3_offload = 0 ;
197+ # ifdef ENABLE_QAT_FIPS
198+ int qat_sw_sha_offload = 0 ;
199+ # endif
200+ # ifdef QAT_OPENSSL_PROVIDER
201+ int qat_hw_dsa_offload = 0 ;
202+ int qat_hw_dh_offload = 0 ;
203+ int qat_hw_ecx_448_offload = 0 ;
204+ # endif
187205int qat_sw_sm3_offload = 0 ;
188206int qat_sw_sm4_cbc_offload = 0 ;
189207int qat_sw_sm4_gcm_offload = 0 ;
@@ -216,11 +234,13 @@ pthread_cond_t qat_poll_condition = PTHREAD_COND_INITIALIZER;
216234# define QAT_CONFIG_SECTION_NAME_SIZE 64
217235char qat_config_section_name [QAT_CONFIG_SECTION_NAME_SIZE ] = "SHIM" ;
218236char * ICPConfigSectionName_libcrypto = qat_config_section_name ;
219-
220237int enable_inline_polling = 0 ;
221238int enable_event_driven_polling = 0 ;
222239int enable_instance_for_thread = 0 ;
223240int disable_qat_offload = 0 ;
241+ /* By default Software fallback disabled in QAT FIPs mode.
242+ * Always enable_sw_fallback is zero in QAT FIPs mode.
243+ */
224244int enable_sw_fallback = 0 ;
225245CpaInstanceHandle * qat_instance_handles = NULL ;
226246Cpa16U qat_num_instances = 0 ;
@@ -565,13 +585,18 @@ int qat_engine_init(ENGINE *e)
565585#ifdef QAT_HW
566586 if (qat_hw_offload ) {
567587 if (!qat_hw_init (e )) {
568- # ifdef QAT_SW /* Co-Existence mode: Don't return failure when QAT HW initialization Failed. */
588+ # ifdef ENABLE_QAT_FIPS
589+ fprintf (stderr , "QAT_HW initialization Failed\n" );
590+ return 0 ;
591+ # else
592+ # ifdef QAT_SW /* Co-Existence mode: Don't return failure when QAT HW initialization Failed. */
569593 fallback_to_qat_sw = 1 ;
570594 WARN ("QAT HW initialization Failed, switching to QAT SW.\n" );
571- # else
595+ # else
572596 fprintf (stderr , "QAT HW initialization Failed.\n" );
573597 qat_pthread_mutex_unlock ();
574598 return 0 ;
599+ # endif
575600# endif
576601 }
577602 }
@@ -580,8 +605,13 @@ int qat_engine_init(ENGINE *e)
580605#ifdef QAT_SW
581606 if (qat_sw_offload ) {
582607 if (!qat_sw_init (e )) {
608+ # ifdef ENABLE_QAT_FIPS
609+ fprintf (stderr , "QAT_SW initialization Failed\n" );
610+ return 0 ;
611+ # else
583612 WARN ("QAT SW initialization Failed, switching to OpenSSL.\n" );
584613 fallback_to_openssl = 1 ;
614+ # endif
585615 }
586616 }
587617#endif
@@ -625,7 +655,6 @@ int qat_engine_finish_int(ENGINE *e, int reset_globals)
625655 if (qat_sw_offload )
626656 ret = qat_sw_finish_int (e , reset_globals );
627657#endif
628-
629658 engine_inited = 0 ;
630659
631660 if (reset_globals == QAT_RESET_GLOBALS ) {
@@ -1092,10 +1121,10 @@ int bind_qat(ENGINE *e, const char *id)
10921121 return ret ;
10931122 }
10941123
1095- if (!ENGINE_set_EC (e , qat_get_EC_methods ())) {
1096- WARN ("ENGINE_set_EC failed\n" );
1097- return ret ;
1098- }
1124+ if (!ENGINE_set_EC (e , qat_get_EC_methods ())) {
1125+ WARN ("ENGINE_set_EC failed\n" );
1126+ return ret ;
1127+ }
10991128
11001129 if (!ENGINE_set_pkey_meths (e , qat_pkey_methods )) {
11011130 WARN ("ENGINE_set_pkey_meths failed\n" );
@@ -1137,31 +1166,43 @@ int bind_qat(ENGINE *e, const char *id)
11371166 if (qat_hw_offload ) {
11381167# ifdef ENABLE_QAT_HW_RSA
11391168 qat_hw_rsa_offload = 1 ;
1140- DEBUG ("QAT_HW RSA for Provider Enabled\n" );
1169+ INFO ("QAT_HW RSA for Provider Enabled\n" );
11411170# endif
11421171# ifdef ENABLE_QAT_HW_ECDSA
11431172 qat_hw_ecdsa_offload = 1 ;
1144- DEBUG ("QAT_HW ECDSA for Provider Enabled\n" );
1173+ INFO ("QAT_HW ECDSA for Provider Enabled\n" );
11451174# endif
11461175# ifdef ENABLE_QAT_HW_ECDH
11471176 qat_hw_ecdh_offload = 1 ;
1148- DEBUG ("QAT_HW ECDH for Provider Enabled\n" );
1177+ INFO ("QAT_HW ECDH for Provider Enabled\n" );
1178+ # endif
1179+ # ifdef ENABLE_QAT_HW_DSA
1180+ qat_hw_dsa_offload = 1 ;
1181+ INFO ("QAT_HW DSA for Provider Enabled\n" );
1182+ # endif
1183+ # ifdef ENABLE_QAT_HW_DH
1184+ qat_hw_dh_offload = 1 ;
1185+ INFO ("QAT_HW DH for Provider Enabled\n" );
11491186# endif
11501187# ifdef ENABLE_QAT_HW_ECX
11511188 qat_hw_ecx_offload = 1 ;
1152- DEBUG ("QAT_HW ECX for Provider Enabled\n" );
1189+ INFO ("QAT_HW ECX25519 for Provider Enabled\n" );
1190+ # endif
1191+ # ifdef ENABLE_QAT_HW_ECX
1192+ qat_hw_ecx_448_offload = 1 ;
1193+ INFO ("QAT_HW ECX448 for Provider Enabled\n" );
11531194# endif
11541195# ifdef ENABLE_QAT_HW_PRF
11551196 qat_hw_prf_offload = 1 ;
1156- DEBUG ("QAT_HW PRF for Provider Enabled\n" );
1197+ INFO ("QAT_HW PRF for Provider Enabled\n" );
11571198# endif
11581199# ifdef ENABLE_QAT_HW_HKDF
11591200 qat_hw_hkdf_offload = 1 ;
1160- DEBUG ("QAT_HW HKDF for Provider Enabled\n" );
1201+ INFO ("QAT_HW HKDF for Provider Enabled\n" );
11611202# endif
11621203# ifdef ENABLE_QAT_HW_SHA3
11631204 qat_hw_sha_offload = 1 ;
1164- DEBUG ("QAT_HW SHA3 for Provider Enabled\n" );
1205+ INFO ("QAT_HW SHA3 for Provider Enabled\n" );
11651206# endif
11661207# ifdef ENABLE_QAT_HW_GCM
11671208 if (!qat_sw_gcm_offload ) {
@@ -1178,7 +1219,7 @@ int bind_qat(ENGINE *e, const char *id)
11781219 mbx_get_algo_info (MBX_ALGO_RSA_3K ) &&
11791220 mbx_get_algo_info (MBX_ALGO_RSA_4K )) {
11801221 qat_sw_rsa_offload = 1 ;
1181- DEBUG ("QAT_SW RSA for Provider Enabled\n" );
1222+ INFO ("QAT_SW RSA for Provider Enabled\n" );
11821223 }
11831224# endif
11841225
@@ -1187,7 +1228,7 @@ int bind_qat(ENGINE *e, const char *id)
11871228 mbx_get_algo_info (MBX_ALGO_ECDSA_NIST_P256 ) &&
11881229 mbx_get_algo_info (MBX_ALGO_ECDSA_NIST_P384 )) {
11891230 qat_sw_ecdsa_offload = 1 ;
1190- DEBUG ("QAT_SW ECDSA for Provider Enabled\n" );
1231+ INFO ("QAT_SW ECDSA for Provider Enabled\n" );
11911232 }
11921233# endif
11931234
@@ -1196,26 +1237,42 @@ int bind_qat(ENGINE *e, const char *id)
11961237 mbx_get_algo_info (MBX_ALGO_ECDHE_NIST_P256 ) &&
11971238 mbx_get_algo_info (MBX_ALGO_ECDHE_NIST_P384 )) {
11981239 qat_sw_ecdh_offload = 1 ;
1199- DEBUG ("QAT_SW ECDH for Provider Enabled\n" );
1240+ INFO ("QAT_SW ECDH for Provider Enabled\n" );
12001241 }
12011242# endif
12021243
12031244# ifdef ENABLE_QAT_SW_ECX
12041245 if (!qat_hw_ecx_offload &&
12051246 mbx_get_algo_info (MBX_ALGO_X25519 )) {
12061247 qat_sw_ecx_offload = 1 ;
1207- DEBUG ("QAT_SW X25519 for Provider Enabled\n" );
1248+ INFO ("QAT_SW X25519 for Provider Enabled\n" );
12081249 }
12091250# endif
12101251
12111252# ifdef ENABLE_QAT_SW_GCM
12121253 qat_sw_gcm_offload = 1 ;
12131254 DEBUG ("QAT_SW GCM for Provider Enabled\n" );
1255+ # endif
1256+ # if defined(ENABLE_QAT_FIPS ) && defined (ENABLE_QAT_SW_SHA2 )
1257+ qat_sw_sha_offload = 1 ;
1258+ INFO ("QAT_SW SHA2 for Provider Enabled\n" );
1259+
1260+ if (!sha_init_ipsec_mb_mgr ()) {
1261+ WARN ("SHA IPSec_Mb Manager Initialization failed\n" );
1262+ return 0 ;
1263+ }
12141264# endif
12151265 }
12161266 /* Create static structures for ciphers now
12171267 * as this function will be called by a single thread. */
12181268 qat_create_ciphers ();
1269+ # ifndef QAT_DEBUG
1270+ if (qat_sw_gcm_offload && !qat_hw_gcm_offload )
1271+ INFO ("QAT_SW GCM for Provider Enabled\n" );
1272+
1273+ if (qat_hw_gcm_offload && !qat_sw_gcm_offload )
1274+ INFO ("QAT_HW GCM for Provider Enabled\n" );
1275+ # endif
12191276#endif
12201277
12211278#ifndef QAT_BORINGSSL
@@ -1255,7 +1312,7 @@ int bind_qat(ENGINE *e, const char *id)
12551312
12561313#ifndef OPENSSL_NO_DYNAMIC_ENGINE
12571314IMPLEMENT_DYNAMIC_BIND_FN (bind_qat )
1258- IMPLEMENT_DYNAMIC_CHECK_FN ()
1315+ IMPLEMENT_DYNAMIC_CHECK_FN ()
12591316#endif /* ndef OPENSSL_NO_DYNAMIC_ENGINE */
12601317/* initialize Qat Engine if OPENSSL_NO_DYNAMIC_ENGINE*/
12611318#ifdef OPENSSL_NO_DYNAMIC_ENGINE
0 commit comments