Skip to content

Commit e6bc7d2

Browse files
Register QAT SW GCM only on supported platform.
Changes to QAT SW GCM to not throw error when platform doesnt support, instead not register the implementation and use OpenSSL implemenation. Signed-off-by: Yogaraj Alamenda <yogarajx.alamenda@intel.com>
1 parent fb93dc6 commit e6bc7d2

File tree

3 files changed

+55
-33
lines changed

3 files changed

+55
-33
lines changed

e_qat.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ sigset_t set = {{0}};
180180
pthread_t qat_timer_poll_func_thread = 0;
181181
pthread_t multibuff_timer_poll_func_thread = 0;
182182
int cleared_to_start = 0;
183+
int qat_sw_ipsec = 0;
183184

184185
#ifdef QAT_HW
185186
# define QAT_CONFIG_SECTION_NAME_SIZE 64
@@ -423,19 +424,20 @@ static int hw_support(void) {
423424
unsigned int vpclmulqdq = 0;
424425

425426
if (*ebx & (0x1 << AVX512F_BIT))
426-
avx512f = 1;
427+
avx512f = 1;
427428

428429
if (*ecx & (0x1 << VAES_BIT))
429-
vaes = 1;
430+
vaes = 1;
430431

431432
if (*ecx & (0x1 << VPCLMULQDQ_BIT))
432-
vpclmulqdq = 1;
433+
vpclmulqdq = 1;
433434

434435
DEBUG("Processor Support - AVX512F = %u, VAES = %u, VPCLMULQDQ = %u\n",
435436
avx512f, vaes, vpclmulqdq);
436437

437438
if (avx512f && vaes && vpclmulqdq) {
438-
return 1;
439+
qat_sw_ipsec = 1;
440+
return 1;
439441
} else {
440442
WARN("Processor unsupported - AVX512F = %u, VAES = %u, VPCLMULQDQ = %u\n",
441443
avx512f, vaes, vpclmulqdq);
@@ -959,16 +961,14 @@ static int bind_qat(ENGINE *e, const char *id)
959961
#endif
960962

961963
#ifdef QAT_SW_IPSEC
962-
if (!hw_support()) {
963-
WARN("The Processor does not support the features needed for VAES.\n");
964-
goto end;
965-
}
964+
if (hw_support()) {
966965
# ifndef DISABLE_QAT_SW_GCM
967-
if (!vaesgcm_init_ipsec_mb_mgr()) {
968-
WARN("IPSec Multi-Buffer Manager Initialization failed\n");
969-
goto end;
970-
}
966+
if (!vaesgcm_init_ipsec_mb_mgr()) {
967+
WARN("IPSec Multi-Buffer Manager Initialization failed\n");
968+
goto end;
969+
}
971970
# endif
971+
}
972972
#endif
973973

974974
#if defined(QAT_HW) || defined(QAT_SW_IPSEC)

e_qat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ extern sigset_t set;
313313
extern pthread_t qat_timer_poll_func_thread;
314314
extern pthread_t multibuff_timer_poll_func_thread;
315315
extern int cleared_to_start;
316+
extern int qat_sw_ipsec;
316317

317318
# ifdef QAT_HW
318319
extern char qat_config_section_name[QAT_CONFIG_SECTION_NAME_SIZE];

qat_evp.c

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -198,31 +198,42 @@ void qat_create_ciphers(void)
198198

199199
for (i = 0; i < num_cc; i++) {
200200
if (info[i].cipher == NULL) {
201+
switch (info[i].nid) {
202+
case NID_aes_128_gcm:
203+
case NID_aes_192_gcm:
204+
case NID_aes_256_gcm:
201205
#ifdef QAT_SW_IPSEC
202-
if (info[i].nid == NID_aes_128_gcm ||
203-
info[i].nid == NID_aes_192_gcm ||
204-
info[i].nid == NID_aes_256_gcm) {
205-
info[i].cipher = (EVP_CIPHER *)
206-
vaesgcm_create_cipher_meth(info[i].nid, info[i].keylen);
207-
}
206+
if(qat_sw_ipsec)
207+
info[i].cipher = (EVP_CIPHER *)
208+
vaesgcm_create_cipher_meth(info[i].nid, info[i].keylen);
209+
#else
210+
# ifdef ENABLE_QAT_HW_GCM
211+
if (qat_offload) {
212+
if (info[i].nid != NID_aes_192_gcm)
213+
info[i].cipher = (EVP_CIPHER *)
214+
qat_create_gcm_cipher_meth(info[i].nid, info[i].keylen);
215+
}
216+
# endif
208217
#endif
218+
break;
209219

210220
#ifdef QAT_HW
211-
if (qat_offload) {
212-
if (info[i].nid == NID_aes_128_gcm ||
213-
info[i].nid == NID_aes_256_gcm) {
214-
# ifdef ENABLE_QAT_HW_GCM
215-
info[i].cipher = (EVP_CIPHER *)
216-
qat_create_gcm_cipher_meth(info[i].nid, info[i].keylen);
217-
# endif
218-
} else {
221+
case NID_aes_128_cbc_hmac_sha1:
222+
case NID_aes_128_cbc_hmac_sha256:
223+
case NID_aes_256_cbc_hmac_sha1:
224+
case NID_aes_256_cbc_hmac_sha256:
225+
if (qat_offload)
219226
info[i].cipher = (EVP_CIPHER *)
220227
qat_create_cipher_meth(info[i].nid, info[i].keylen);
221-
}
222-
}
228+
break;
223229
#endif
230+
default:
231+
/* Do nothing */
232+
break;
233+
}
224234
}
225235
}
236+
226237
}
227238

228239
void qat_free_ciphers(void)
@@ -231,16 +242,26 @@ void qat_free_ciphers(void)
231242

232243
for (i = 0; i < num_cc; i++) {
233244
if (info[i].cipher != NULL) {
234-
if (info[i].nid == NID_aes_128_gcm ||
235-
info[i].nid == NID_aes_192_gcm ||
236-
info[i].nid == NID_aes_256_gcm) {
245+
switch (info[i].nid) {
246+
case NID_aes_128_gcm:
247+
case NID_aes_192_gcm:
248+
case NID_aes_256_gcm:
237249
#ifndef DISABLE_QAT_SW_GCM
238250
EVP_CIPHER_meth_free(info[i].cipher);
239251
#endif
240-
} else {
241-
#if !defined(DISABLE_QAT_HW_CIPHERS) || !defined(DISABLE_QAT_HW_GCM)
252+
#ifndef DISABLE_QAT_HW_GCM
253+
if (info[i].nid != NID_aes_192_gcm)
254+
EVP_CIPHER_meth_free(info[i].cipher);
255+
#endif
256+
break;
257+
case NID_aes_128_cbc_hmac_sha1:
258+
case NID_aes_128_cbc_hmac_sha256:
259+
case NID_aes_256_cbc_hmac_sha1:
260+
case NID_aes_256_cbc_hmac_sha256:
261+
#ifndef DISABLE_QAT_HW_CIPHERS
242262
EVP_CIPHER_meth_free(info[i].cipher);
243263
#endif
264+
break;
244265
}
245266
info[i].cipher = NULL;
246267
}

0 commit comments

Comments
 (0)