Skip to content

Commit

Permalink
Register QAT SW GCM only on supported platform.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Yogaraj-Alamenda committed Mar 25, 2021
1 parent fb93dc6 commit e6bc7d2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 33 deletions.
24 changes: 12 additions & 12 deletions e_qat.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ sigset_t set = {{0}};
pthread_t qat_timer_poll_func_thread = 0;
pthread_t multibuff_timer_poll_func_thread = 0;
int cleared_to_start = 0;
int qat_sw_ipsec = 0;

#ifdef QAT_HW
# define QAT_CONFIG_SECTION_NAME_SIZE 64
Expand Down Expand Up @@ -423,19 +424,20 @@ static int hw_support(void) {
unsigned int vpclmulqdq = 0;

if (*ebx & (0x1 << AVX512F_BIT))
avx512f = 1;
avx512f = 1;

if (*ecx & (0x1 << VAES_BIT))
vaes = 1;
vaes = 1;

if (*ecx & (0x1 << VPCLMULQDQ_BIT))
vpclmulqdq = 1;
vpclmulqdq = 1;

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

if (avx512f && vaes && vpclmulqdq) {
return 1;
qat_sw_ipsec = 1;
return 1;
} else {
WARN("Processor unsupported - AVX512F = %u, VAES = %u, VPCLMULQDQ = %u\n",
avx512f, vaes, vpclmulqdq);
Expand Down Expand Up @@ -959,16 +961,14 @@ static int bind_qat(ENGINE *e, const char *id)
#endif

#ifdef QAT_SW_IPSEC
if (!hw_support()) {
WARN("The Processor does not support the features needed for VAES.\n");
goto end;
}
if (hw_support()) {
# ifndef DISABLE_QAT_SW_GCM
if (!vaesgcm_init_ipsec_mb_mgr()) {
WARN("IPSec Multi-Buffer Manager Initialization failed\n");
goto end;
}
if (!vaesgcm_init_ipsec_mb_mgr()) {
WARN("IPSec Multi-Buffer Manager Initialization failed\n");
goto end;
}
# endif
}
#endif

#if defined(QAT_HW) || defined(QAT_SW_IPSEC)
Expand Down
1 change: 1 addition & 0 deletions e_qat.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ extern sigset_t set;
extern pthread_t qat_timer_poll_func_thread;
extern pthread_t multibuff_timer_poll_func_thread;
extern int cleared_to_start;
extern int qat_sw_ipsec;

# ifdef QAT_HW
extern char qat_config_section_name[QAT_CONFIG_SECTION_NAME_SIZE];
Expand Down
63 changes: 42 additions & 21 deletions qat_evp.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,31 +198,42 @@ void qat_create_ciphers(void)

for (i = 0; i < num_cc; i++) {
if (info[i].cipher == NULL) {
switch (info[i].nid) {
case NID_aes_128_gcm:
case NID_aes_192_gcm:
case NID_aes_256_gcm:
#ifdef QAT_SW_IPSEC
if (info[i].nid == NID_aes_128_gcm ||
info[i].nid == NID_aes_192_gcm ||
info[i].nid == NID_aes_256_gcm) {
info[i].cipher = (EVP_CIPHER *)
vaesgcm_create_cipher_meth(info[i].nid, info[i].keylen);
}
if(qat_sw_ipsec)
info[i].cipher = (EVP_CIPHER *)
vaesgcm_create_cipher_meth(info[i].nid, info[i].keylen);
#else
# ifdef ENABLE_QAT_HW_GCM
if (qat_offload) {
if (info[i].nid != NID_aes_192_gcm)
info[i].cipher = (EVP_CIPHER *)
qat_create_gcm_cipher_meth(info[i].nid, info[i].keylen);
}
# endif
#endif
break;

#ifdef QAT_HW
if (qat_offload) {
if (info[i].nid == NID_aes_128_gcm ||
info[i].nid == NID_aes_256_gcm) {
# ifdef ENABLE_QAT_HW_GCM
info[i].cipher = (EVP_CIPHER *)
qat_create_gcm_cipher_meth(info[i].nid, info[i].keylen);
# endif
} else {
case NID_aes_128_cbc_hmac_sha1:
case NID_aes_128_cbc_hmac_sha256:
case NID_aes_256_cbc_hmac_sha1:
case NID_aes_256_cbc_hmac_sha256:
if (qat_offload)
info[i].cipher = (EVP_CIPHER *)
qat_create_cipher_meth(info[i].nid, info[i].keylen);
}
}
break;
#endif
default:
/* Do nothing */
break;
}
}
}

}

void qat_free_ciphers(void)
Expand All @@ -231,16 +242,26 @@ void qat_free_ciphers(void)

for (i = 0; i < num_cc; i++) {
if (info[i].cipher != NULL) {
if (info[i].nid == NID_aes_128_gcm ||
info[i].nid == NID_aes_192_gcm ||
info[i].nid == NID_aes_256_gcm) {
switch (info[i].nid) {
case NID_aes_128_gcm:
case NID_aes_192_gcm:
case NID_aes_256_gcm:
#ifndef DISABLE_QAT_SW_GCM
EVP_CIPHER_meth_free(info[i].cipher);
#endif
} else {
#if !defined(DISABLE_QAT_HW_CIPHERS) || !defined(DISABLE_QAT_HW_GCM)
#ifndef DISABLE_QAT_HW_GCM
if (info[i].nid != NID_aes_192_gcm)
EVP_CIPHER_meth_free(info[i].cipher);
#endif
break;
case NID_aes_128_cbc_hmac_sha1:
case NID_aes_128_cbc_hmac_sha256:
case NID_aes_256_cbc_hmac_sha1:
case NID_aes_256_cbc_hmac_sha256:
#ifndef DISABLE_QAT_HW_CIPHERS
EVP_CIPHER_meth_free(info[i].cipher);
#endif
break;
}
info[i].cipher = NULL;
}
Expand Down

0 comments on commit e6bc7d2

Please sign in to comment.