Skip to content

Commit 804c1cc

Browse files
Fix API version for QAT_HW 2.0 driver & bug fixes.
Co-authored-by: Nagha Abirami <[email protected]> Signed-off-by: Yogaraj Alamenda <[email protected]>
1 parent 8042faa commit 804c1cc

13 files changed

+45
-22
lines changed

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ AM_CFLAGS = $(cflags_cc_opt) $(cflags_qat_hw_intree) \
149149
$(cflags_mem_driver) $(cflags_openssl_3) \
150150
$(cflags_boringssl) $(cflags_qat_hw) \
151151
$(cflags_qat_sw) $(cflags_qat_sw_ipsec) \
152-
$(cflags_common)
152+
$(cflags_common) $(cflags_qat_debug)
153153

154154
if QAT_BORINGSSL
155155
bin_PROGRAMS = qatengine_test

configure.ac

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ then
405405
if test "x$enable_qat_hw" != "xno"
406406
then
407407
AC_SUBST([cflags_qat_hw], ["-DQAT_HW"])
408+
AC_CHECK_FILE(${with_qat_hw_dir}/quickassist/lookaside/access_layer/src/common/crypto/kpt/crypto/lac_kpt_crypto_qat_comms.c,
409+
[cflags_qat_hw="${cflags_qat_hw} -DQAT20_OOT"], [])
408410
AC_MSG_NOTICE([QAT_HW acceleration enabled])
409411
else
410412
AC_MSG_NOTICE([QAT_HW acceleration disabled])
@@ -608,9 +610,6 @@ AM_CONDITIONAL([QAT_PLOCK], [test "x$enable_qat_plock" != "x"])
608610
AS_IF([test "x$enable_qat_sw_heuristic_timeout" = "xyes" -a "x$cflags_qat_sw" != "x"],
609611
[cflags_common="${cflags_common} -DQAT_SW_HEURISTIC_TIMEOUT"; AC_MSG_NOTICE([QAT_SW Heuristic Timeout enabled])])
610612

611-
AS_IF([test "x$with_qat_debug_file" != "x"],
612-
[cflags_common="${cflags_common} -DQAT_DEBUG_FILE_PATH=\$(with_qat_debug_file)"; AC_MSG_NOTICE([Debugs to file enabled])])
613-
614613
AS_IF([test "x$with_qat_engine_id" != "x"],
615614
[cflags_common="${cflags_common} -DQAT_ENGINE_ID=\$(with_qat_engine_id)"; AC_MSG_NOTICE([Using engine id other than default])])
616615

@@ -640,6 +639,13 @@ then
640639
AC_SUBST([QAT_LD_LIB], ["\$(with_ld_opt)"])
641640
fi
642641

642+
# Write logs to a debug file
643+
if test "x$with_qat_debug_file" != "x"
644+
then
645+
AC_SUBST([cflags_qat_debug], ["-DQAT_DEBUG_FILE_PATH=\$(with_qat_debug_file)"])
646+
AC_MSG_NOTICE([Debugs to file enabled])
647+
fi
648+
643649
#QAT_HW Memory Driver
644650
if test "x$cflags_qat_hw" != "x"
645651
then

qat_evp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ const EVP_CIPHER *qat_create_gcm_cipher_meth(int nid, int keylen)
748748

749749
if (!qat_sw_gcm_offload && !qat_hw_gcm_offload) {
750750
DEBUG("OpenSSL SW AES_GCM_%d registration succeeded\n", keylen*8);
751+
EVP_CIPHER_meth_free(c);
751752
return qat_gcm_cipher_sw_impl(nid);
752753
}
753754

qat_hw_chachapoly.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ const EVP_CIPHER *chachapoly_cipher_meth(int nid, int keylen)
164164
} else {
165165
qat_hw_chacha_poly_offload = 0;
166166
DEBUG("QAT HW CHACHA POLY is disabled, using OpenSSL SW\n");
167+
EVP_CIPHER_meth_free(c);
167168
return EVP_chacha20_poly1305();
168169
}
169170
# else

qat_hw_ciphers.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ const EVP_CIPHER *qat_create_cipher_meth(int nid, int keylen)
275275
} else {
276276
qat_hw_aes_cbc_hmac_sha_offload = 0;
277277
DEBUG("QAT HW AES_CBC_%d_HMAC_SHA is disabled, using OpenSSL SW\n", keylen*8);
278+
EVP_CIPHER_meth_free(c);
278279
return qat_chained_cipher_sw_impl(nid);
279280
}
280281
}

qat_hw_ec.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ CpaCyEcFieldType qat_get_field_type(const EC_GROUP *group)
101101
return CPA_CY_EC_FIELD_TYPE_BINARY;
102102
}
103103

104-
#if CPA_CY_API_VERSION_NUM_MAJOR >= 3
104+
#if defined(QAT20_OOT) || defined(QAT_HW_INTREE)
105105
int qat_get_curve(CpaCyEcFieldType fieldType)
106106
{
107107
if (fieldType == CPA_CY_EC_FIELD_TYPE_PRIME)
@@ -140,7 +140,7 @@ int qat_ecdh_compute_key(unsigned char **outX, size_t *outlenX,
140140

141141
int inst_num = QAT_INVALID_INSTANCE;
142142
BIGNUM *xP = NULL, *yP = NULL;
143-
# if CPA_CY_API_VERSION_NUM_MAJOR >= 3
143+
# if defined(QAT20_OOT) || defined(QAT_HW_INTREE)
144144
CpaCyEcGenericPointMultiplyOpData *pOpData = NULL;
145145
# else
146146
CpaCyEcPointMultiplyOpData *opData = NULL;
@@ -184,7 +184,7 @@ int qat_ecdh_compute_key(unsigned char **outX, size_t *outlenX,
184184
return ret;
185185
}
186186

187-
# if CPA_CY_API_VERSION_NUM_MAJOR >= 3
187+
# if defined(QAT20_OOT) || defined(QAT_HW_INTREE)
188188
pOpData = (CpaCyEcGenericPointMultiplyOpData *)
189189
OPENSSL_zalloc(sizeof(CpaCyEcGenericPointMultiplyOpData));
190190
if (pOpData == NULL) {
@@ -300,7 +300,7 @@ int qat_ecdh_compute_key(unsigned char **outX, size_t *outlenX,
300300
goto err;
301301
}
302302

303-
# if CPA_CY_API_VERSION_NUM_MAJOR >= 3
303+
# if defined(QAT20_OOT) || defined(QAT_HW_INTREE)
304304
pOpData->pCurve->parameters.weierstrassParameters.fieldType = qat_get_field_type(group);
305305
pOpData->pCurve->curveType = qat_get_curve(pOpData->pCurve->parameters.weierstrassParameters.fieldType);
306306

@@ -423,7 +423,7 @@ int qat_ecdh_compute_key(unsigned char **outX, size_t *outlenX,
423423
}
424424

425425
CRYPTO_QAT_LOG("KX - %s\n", __func__);
426-
# if CPA_CY_API_VERSION_NUM_MAJOR >= 3
426+
# if defined(QAT20_OOT) || defined(QAT_HW_INTREE)
427427
DUMP_EC_GENERIC_POINT_MULTIPLY(qat_instance_handles[inst_num], pOpData, pResultX, pResultY);
428428
status = cpaCyEcGenericPointMultiply(qat_instance_handles[inst_num],
429429
qat_ecCallbackFn,
@@ -595,7 +595,7 @@ int qat_ecdh_compute_key(unsigned char **outX, size_t *outlenX,
595595
OPENSSL_free(pResultY);
596596
}
597597

598-
# if CPA_CY_API_VERSION_NUM_MAJOR >= 3
598+
# if defined(QAT20_OOT) || defined(QAT_HW_INTREE)
599599
if (pOpData) {
600600
QAT_CHK_CLNSE_QMFREE_NONZERO_FLATBUFF(pOpData->k);
601601
QAT_CHK_QMFREE_FLATBUFF(pOpData->xP);

qat_hw_prf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
* down in the driver.
7272
*/
7373
# ifdef ENABLE_QAT_HW_PRF
74-
# if CPA_CY_API_VERSION_NUM_MAJOR > 2
74+
# if defined(QAT20_OOT) || defined(QAT_HW_INTREE)
7575
# define QAT_TLS1_PRF_SECRET_MAXBUF 1024
7676
# else
7777
# define QAT_TLS1_PRF_SECRET_MAXBUF 512

qat_hw_rsa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
#else
8989
# define RSA_QAT_RANGE_MIN 2048
9090
#endif
91-
#if CPA_CY_API_VERSION_NUM_MAJOR > 2
91+
#if defined(QAT20_OOT) || defined(QAT_HW_INTREE)
9292
# define RSA_QAT_RANGE_MAX 8192
9393
#else
9494
# define RSA_QAT_RANGE_MAX 4096

qat_hw_sha3.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ const EVP_MD *qat_create_sha3_meth(int nid , int key_type)
163163
} else {
164164
qat_hw_sha_offload = 0;
165165
DEBUG("QAT HW SHA3 is disabled, using OpenSSL SW\n");
166+
EVP_MD_meth_free(c);
166167
return qat_sha3_sw_impl(nid);
167168
}
168169
#else
@@ -983,15 +984,14 @@ static int qat_sha3_final(EVP_MD_CTX *ctx, unsigned char *md)
983984

984985
/* Copy digest result into "md" buffer. */
985986
memcpy(md, sha3_ctx->digest_data, sha3_ctx->md_size);
987+
memset(sha3_ctx->digest_data, 0x00, sha3_ctx->md_size);
986988

989+
#ifndef QAT_OPENSSL_PROVIDER
987990
if (!qat_sha3_cleanup(ctx)) {
988991
WARN("qat_sha3_cleanup failed\n");
989992
QATerr(QAT_F_QAT_SHA3_FINAL, ERR_R_INTERNAL_ERROR);
990993
return 0;
991994
}
992-
993-
#ifdef QAT_OPENSSL_PROVIDER
994-
OPENSSL_clear_free(sha3_ctx, sizeof(qat_sha3_ctx));
995995
#endif
996996
return 1;
997997
}

qat_prov_bio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ static int bio_core_new(BIO *bio)
186186
return 1;
187187
}
188188

189-
static BIO_METHOD *ossl_prov_ctx_get0_core_bio_method(QAT_PROV_CTX *ctx)
189+
BIO_METHOD *ossl_prov_ctx_get0_core_bio_method(QAT_PROV_CTX *ctx)
190190
{
191191
if (ctx == NULL)
192192
return NULL;

qat_prov_bio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ int ossl_prov_bio_printf(OSSL_CORE_BIO *bio, const char *format, ...);
2121

2222
BIO_METHOD *ossl_bio_prov_init_bio_method(void);
2323
BIO *ossl_bio_new_from_core_bio(QAT_PROV_CTX *provctx, OSSL_CORE_BIO *corebio);
24+
BIO_METHOD *ossl_prov_ctx_get0_core_bio_method(QAT_PROV_CTX *ctx);

qat_prov_init.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
# include "qat_sw_gcm.h"
2525
#endif
2626

27+
OSSL_PROVIDER *prov = NULL;
2728
/* By default, qat provider always in a happy state */
2829
int qat_prov_is_running(void)
2930
{
@@ -73,9 +74,13 @@ extern const OSSL_DISPATCH qat_X25519_keymgmt_functions[];
7374
#ifdef ENABLE_QAT_HW_ECX
7475
extern const OSSL_DISPATCH qat_X448_keymgmt_functions[];
7576
#endif
77+
#if defined(ENABLE_QAT_HW_GCM) || defined(ENABLE_QAT_SW_GCM)
7678
extern const OSSL_DISPATCH qat_aes128gcm_functions[];
79+
# ifdef ENABLE_QAT_SW_GCM
7780
extern const OSSL_DISPATCH qat_aes192gcm_functions[];
81+
# endif
7882
extern const OSSL_DISPATCH qat_aes256gcm_functions[];
83+
#endif
7984
#if defined(ENABLE_QAT_HW_DSA) && defined(QAT_INSECURE_ALGO)
8085
extern const OSSL_DISPATCH qat_dsa_keymgmt_functions[];
8186
#endif
@@ -211,7 +216,9 @@ static void qat_teardown(void *provctx)
211216

212217
if (provctx) {
213218
QAT_PROV_CTX *qat_ctx = (QAT_PROV_CTX *)provctx;
219+
BIO_meth_free(ossl_prov_ctx_get0_core_bio_method(qat_ctx));
214220
OPENSSL_free(qat_ctx);
221+
OSSL_PROVIDER_unload(prov);
215222
}
216223
}
217224

@@ -262,10 +269,10 @@ static const OSSL_ALGORITHM_CAPABLE qat_deflt_ciphers[] = {
262269
# endif
263270
ALG(QAT_NAMES_AES_128_CBC_HMAC_SHA256, qat_aes128cbc_hmac_sha256_functions),
264271
ALG(QAT_NAMES_AES_256_CBC_HMAC_SHA256, qat_aes256cbc_hmac_sha256_functions),
272+
#endif
265273
# ifdef ENABLE_QAT_HW_CHACHAPOLY
266274
ALG(QAT_NAMES_CHACHA20_POLY1305, qat_chacha20_poly1305_functions),
267275
# endif /* ENABLE_QAT_HW_CHACHAPOLY */
268-
#endif
269276
{ { NULL, NULL, NULL }, NULL }};
270277

271278
static OSSL_ALGORITHM qat_exported_ciphers[OSSL_NELEM(qat_deflt_ciphers)];
@@ -355,7 +362,6 @@ static const OSSL_ALGORITHM qat_digests[] = {
355362
static const OSSL_ALGORITHM *qat_query(void *provctx, int operation_id, int *no_cache)
356363
{
357364
static int prov_init = 0;
358-
OSSL_PROVIDER *prov = NULL;
359365
prov = OSSL_PROVIDER_load(NULL, "default");
360366
if (!prov_init) {
361367
prov_init = 1;

qat_prov_sha3.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ static void qat_keccak_freectx(void *vctx)
150150
if (!qat_sha3_cleanup(ctx)){
151151
WARN("qat sha3 ctx cleanup failed.\n");
152152
}
153+
#ifndef ENABLE_QAT_HW_SMALL_PKT_OFFLOAD
154+
EVP_MD_CTX_free(ctx->sw_md_ctx);
155+
EVP_MD_free(ctx->sw_md);
156+
ctx->sw_md_ctx = NULL;
157+
ctx->sw_md = NULL;
158+
#endif
159+
OPENSSL_clear_free(ctx->qctx, sizeof(qat_sha3_ctx));
153160
OPENSSL_clear_free(ctx, sizeof(*ctx));
154161
}
155162

@@ -261,9 +268,9 @@ static void *qat_##name##_newctx(void *provctx)
261268
ctx->pad = pad_val; \
262269
} \
263270
set_ctx_md_type(ctx, bitlen); \
264-
ctx->qctx = OPENSSL_malloc(sizeof(qat_sha3_ctx)); \
271+
ctx->qctx = OPENSSL_zalloc(sizeof(qat_sha3_ctx)); \
265272
if (ctx->qctx == NULL) \
266-
WARN("malloc failed.\n"); \
273+
WARN("zalloc failed.\n"); \
267274
ctx->meth = sha3_generic_md; \
268275
ctx->sw_md_ctx = EVP_MD_CTX_new(); \
269276
if (ctx->sw_md_ctx == NULL) \
@@ -294,9 +301,9 @@ static void *qat_##name##_newctx(void *provctx)
294301
ctx->pad = pad_val; \
295302
} \
296303
set_ctx_md_type(ctx, bitlen); \
297-
ctx->qctx = OPENSSL_malloc(sizeof(qat_sha3_ctx)); \
304+
ctx->qctx = OPENSSL_zalloc(sizeof(qat_sha3_ctx)); \
298305
if (ctx->qctx == NULL) \
299-
WARN("malloc failed.\n"); \
306+
WARN("zalloc failed.\n"); \
300307
ctx->meth = sha3_generic_md; \
301308
return ctx; \
302309
}

0 commit comments

Comments
 (0)