[v4,11/11] test/cryptodev: fix incomplete data length

Message ID 20211105001932.28784-12-kai.ji@intel.com (mailing list archive)
State Superseded, archived
Delegated to: akhil goyal
Headers
Series drivers/qat: QAT symmetric crypto datapatch rework |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues
ci/intel-Testing success Testing PASS

Commit Message

Ji, Kai Nov. 5, 2021, 12:19 a.m. UTC
  This patch fixes incorrect data lengths computation in cryptodev
unit test. Previously some data lengths were incorrectly set, which
was insensitive for crypto op unit tets but is critical for raw data
path API unit tests. The patch addressed the issue by setting the
correct data lengths for some tests.

Fixes: 681f540da52b ("cryptodev: do not use AAD in wireless algorithms")
Cc: pablo.de.lara.guarch@intel.com

Fixes: e847fc512817 ("test/crypto: add encrypted digest case for AES-CTR-CMAC")
Cc: adamx.dybkowski@intel.com

Signed-off-by: Kai Ji <kai.ji@intel.com>
---
 app/test/test_cryptodev.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
  

Patch

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index efd8bfd7a0..e1f7c6454d 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -209,6 +209,7 @@  process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
 	int enqueue_status, dequeue_status;
 	struct crypto_unittest_params *ut_params = &unittest_params;
 	int is_sgl = sop->m_src->nb_segs > 1;
+	int is_oop = 0;
 
 	ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
 	if (ctx_service_size < 0) {
@@ -247,6 +248,9 @@  process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
 
 	ofs.raw = 0;
 
+	if ((sop->m_dst != NULL) && (sop->m_dst != sop->m_src))
+		is_oop = 1;
+
 	if (is_cipher && is_auth) {
 		cipher_offset = sop->cipher.data.offset;
 		cipher_len = sop->cipher.data.length;
@@ -277,6 +281,8 @@  process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
 		if (is_sgl) {
 			uint32_t remaining_off = auth_offset + auth_len;
 			struct rte_mbuf *sgl_buf = sop->m_src;
+			if (is_oop)
+				sgl_buf = sop->m_dst;
 
 			while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)
 					&& sgl_buf->next != NULL) {
@@ -293,7 +299,8 @@  process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
 		/* Then check if digest-encrypted conditions are met */
 		if ((auth_offset + auth_len < cipher_offset + cipher_len) &&
 				(digest.iova == auth_end_iova) && is_sgl)
-			max_len = RTE_MAX(max_len, auth_offset + auth_len +
+			max_len = RTE_MAX(max_len,
+				auth_offset + auth_len +
 				ut_params->auth_xform.auth.digest_length);
 
 	} else if (is_cipher) {
@@ -356,7 +363,7 @@  process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
 
 	sgl.num = n;
 	/* Out of place */
-	if (sop->m_dst != NULL) {
+	if (is_oop) {
 		dest_sgl.vec = dest_data_vec;
 		vec.dest_sgl = &dest_sgl;
 		n = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len,
@@ -4102,9 +4109,9 @@  test_kasumi_decryption(const struct kasumi_test_data *tdata)
 
 	/* Create KASUMI operation */
 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
-					tdata->cipher_iv.len,
-					tdata->ciphertext.len,
-					tdata->validCipherOffsetInBits.len);
+			tdata->cipher_iv.len,
+			RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
+			tdata->validCipherOffsetInBits.len);
 	if (retval < 0)
 		return retval;
 
@@ -7335,6 +7342,7 @@  test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
 	unsigned int plaintext_len;
 	unsigned int ciphertext_pad_len;
 	unsigned int ciphertext_len;
+	unsigned int data_len;
 
 	struct rte_cryptodev_info dev_info;
 	struct rte_crypto_op *op;
@@ -7395,21 +7403,22 @@  test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
+	data_len = RTE_MAX(ciphertext_pad_len, plaintext_pad_len);
 
 	if (verify) {
 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
-				ciphertext_pad_len);
+				data_len);
 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
 		if (op_mode == OUT_OF_PLACE)
-			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
+			rte_pktmbuf_append(ut_params->obuf, data_len);
 		debug_hexdump(stdout, "ciphertext:", ciphertext,
 				ciphertext_len);
 	} else {
 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
-				plaintext_pad_len);
+				data_len);
 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
 		if (op_mode == OUT_OF_PLACE)
-			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
+			rte_pktmbuf_append(ut_params->obuf, data_len);
 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
 	}