Skip to content

Commit b2f2d91

Browse files
PremkumarxYogaraj-Alamenda
authored andcommitted
Bug fixes on GCM cleanup and disable flags in provider.
Signed-off-by: Premkumar Shanmugam <premkumarx.shanmugam@intel.com>
1 parent 7a74199 commit b2f2d91

File tree

4 files changed

+41
-34
lines changed

4 files changed

+41
-34
lines changed

qat_hw_gcm.c

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ int qat_aes_gcm_cleanup(EVP_CIPHER_CTX *ctx)
741741
#endif
742742
CpaStatus sts = 0;
743743
CpaCySymSessionSetupData* session_data = NULL;
744+
CpaBoolean sessionInUse = CPA_FALSE;
744745
int ret_val = 1;
745746

746747
DEBUG("- Entering\n");
@@ -764,48 +765,53 @@ int qat_aes_gcm_cleanup(EVP_CIPHER_CTX *ctx)
764765
return 0;
765766
}
766767

768+
/* Wait for in-flight requests before removing session */
769+
do {
770+
cpaCySymSessionInUse(qctx->qat_ctx, &sessionInUse);
771+
} while (sessionInUse);
772+
767773
session_data = qctx->session_data;
768774
if (session_data) {
769775
/* Remove the session */
770776
if (qctx->qat_ctx) {
771777
if ((sts = cpaCySymRemoveSession(qat_instance_handles[qctx->inst_num], qctx->qat_ctx))
772-
!= CPA_STATUS_SUCCESS) {
778+
!= CPA_STATUS_SUCCESS) {
773779
WARN("cpaCySymRemoveSession FAILED, sts = %d.!\n", sts);
774780
ret_val = 0;
775781
/* Lets not return yet and instead make a best effort to
776782
* cleanup the rest to avoid memory leaks
777783
*/
778784
}
779-
qaeCryptoMemFreeNonZero(qctx->qat_ctx);
785+
qaeCryptoMemFreeNonZero(qctx->qat_ctx);
780786
qctx->qat_ctx = NULL;
781787
}
782-
/* Cleanup the memory */
783-
if (qctx->aad) {
784-
qaeCryptoMemFreeNonZero(qctx->aad);
785-
qctx->aad = NULL;
786-
}
787-
if (qctx->srcBufferList.pPrivateMetaData) {
788-
qaeCryptoMemFreeNonZero(qctx->srcBufferList.pPrivateMetaData);
789-
qctx->srcBufferList.pPrivateMetaData = NULL;
790-
}
791-
if (qctx->dstBufferList.pPrivateMetaData) {
792-
qaeCryptoMemFreeNonZero(qctx->dstBufferList.pPrivateMetaData);
793-
qctx->dstBufferList.pPrivateMetaData = NULL;
794-
}
795-
if (qctx->iv) {
796-
qaeCryptoMemFree(qctx->iv);
797-
qctx->iv = NULL;
798-
}
799-
if (qctx->cipher_key) {
800-
qaeCryptoMemFree(qctx->cipher_key);
801-
qctx->cipher_key = NULL;
802-
}
803-
if (qctx->OpData.pDigestResult) {
804-
qaeCryptoMemFree(qctx->OpData.pDigestResult);
805-
qctx->OpData.pDigestResult = NULL;
806-
}
807-
session_data->cipherSetupData.pCipherKey = NULL;
808-
OPENSSL_clear_free(session_data, sizeof(CpaCySymSessionSetupData));
788+
/* Cleanup the memory */
789+
if (qctx->aad) {
790+
qaeCryptoMemFreeNonZero(qctx->aad);
791+
qctx->aad = NULL;
792+
}
793+
if (qctx->srcBufferList.pPrivateMetaData) {
794+
qaeCryptoMemFreeNonZero(qctx->srcBufferList.pPrivateMetaData);
795+
qctx->srcBufferList.pPrivateMetaData = NULL;
796+
}
797+
if (qctx->dstBufferList.pPrivateMetaData) {
798+
qaeCryptoMemFreeNonZero(qctx->dstBufferList.pPrivateMetaData);
799+
qctx->dstBufferList.pPrivateMetaData = NULL;
800+
}
801+
if (qctx->iv) {
802+
qaeCryptoMemFree(qctx->iv);
803+
qctx->iv = NULL;
804+
}
805+
if (qctx->cipher_key) {
806+
qaeCryptoMemFree(qctx->cipher_key);
807+
qctx->cipher_key = NULL;
808+
}
809+
if (qctx->OpData.pDigestResult) {
810+
qaeCryptoMemFree(qctx->OpData.pDigestResult);
811+
qctx->OpData.pDigestResult = NULL;
812+
}
813+
session_data->cipherSetupData.pCipherKey = NULL;
814+
OPENSSL_clear_free(session_data, sizeof(CpaCySymSessionSetupData));
809815
}
810816
qctx->is_session_init = 0;
811817

qat_prov_kmgmt_ec.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@
7272
# include "qat_sw_ec.h"
7373
#endif
7474

75-
#if defined(ENABLE_QAT_HW_ECDSA) || defined(ENABLE_QAT_HW_ECDH) \
76-
|| defined(ENABLE_QAT_SW_ECDSA) || defined(ENABLE_QAT_SW_ECDH)
7775
typedef struct{
7876
int id; /* libcrypto internal */
7977
int name_id;
@@ -131,6 +129,8 @@ typedef struct {
131129
EC_GROUP *gen_group;
132130
}QAT_EC_GEN_CTX;
133131

132+
#if defined(ENABLE_QAT_HW_ECDSA) || defined(ENABLE_QAT_HW_ECDH) \
133+
|| defined(ENABLE_QAT_SW_ECDSA) || defined(ENABLE_QAT_SW_ECDH)
134134
static QAT_EC_KEYMGMT get_default_keymgmt()
135135
{
136136
static QAT_EC_KEYMGMT s_keymgmt;
@@ -424,6 +424,7 @@ const OSSL_DISPATCH qat_ecdh_keymgmt_functions[] = {
424424
(void (*)(void))qat_keymgmt_ec_query_operation_name },
425425
{0, NULL }
426426
};
427+
#endif /* defined(ENABLE_QAT_HW_ECDH) || defined(ENABLE_QAT_SW_ECDH) */
427428

428429
# ifdef ENABLE_QAT_SW_SM2
429430
static QAT_EC_KEYMGMT sm2_get_default_keymgmt()
@@ -673,4 +674,3 @@ const OSSL_DISPATCH qat_sm2_keymgmt_functions[] = {
673674
{0, NULL }
674675
};
675676
# endif /* ENABLE_QAT_SW_SM2 */
676-
#endif /* defined(ENABLE_QAT_HW_ECDH) || defined(ENABLE_QAT_SW_ECDH) */

qat_sw_ec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
#include "crypto_mb/ec_nistp384.h"
7676
#include "crypto_mb/ec_sm2.h"
7777

78-
#ifdef ENABLE_QAT_FIPS
78+
# if defined(ENABLE_QAT_FIPS) && defined(ENABLE_QAT_SW_ECDSA)
7979
extern int qat_fips_kat_test;
8080
static const unsigned char KINV_256[] = {
8181
0x62, 0x15, 0x9E, 0x5B, 0xA9, 0xE7, 0x12, 0xFB,

qat_sw_ecx.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ int x25519_nid[] = {
8383
EVP_PKEY_X25519
8484
};
8585

86-
86+
#ifdef ENABLE_QAT_SW_ECX
8787
void process_x25519_keygen_reqs(mb_thread_data *tlv)
8888
{
8989
x25519_keygen_op_data *x25519_keygen_req_array[MULTIBUFF_BATCH] = {0};
@@ -620,3 +620,4 @@ int multibuff_x25519_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
620620
return -2;
621621
}
622622
# endif
623+
#endif /*ENABLE_QAT_HW_ECX*/

0 commit comments

Comments
 (0)