1a9de470cSBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2a9de470cSBruce Richardson  * Copyright(c) 2015-2017 Intel Corporation
3a9de470cSBruce Richardson  */
4a9de470cSBruce Richardson 
5a9de470cSBruce Richardson #include <rte_common.h>
6a9de470cSBruce Richardson #include <rte_hexdump.h>
7a9de470cSBruce Richardson #include <rte_mbuf.h>
8a9de470cSBruce Richardson #include <rte_malloc.h>
9a9de470cSBruce Richardson #include <rte_memcpy.h>
10a9de470cSBruce Richardson #include <rte_pause.h>
11a9de470cSBruce Richardson 
12a9de470cSBruce Richardson #include <rte_crypto.h>
13a9de470cSBruce Richardson #include <rte_cryptodev.h>
14a9de470cSBruce Richardson #include <rte_cryptodev_pmd.h>
15a9de470cSBruce Richardson 
16a9de470cSBruce Richardson #include "test.h"
17a9de470cSBruce Richardson #include "test_cryptodev.h"
18a9de470cSBruce Richardson #include "test_cryptodev_blockcipher.h"
19a9de470cSBruce Richardson #include "test_cryptodev_aes_test_vectors.h"
20a9de470cSBruce Richardson #include "test_cryptodev_des_test_vectors.h"
21a9de470cSBruce Richardson #include "test_cryptodev_hash_test_vectors.h"
22a9de470cSBruce Richardson 
23a9de470cSBruce Richardson static int
2493982b21SPablo de Lara verify_algo_support(const struct blockcipher_test_case *t,
2593982b21SPablo de Lara 		const uint8_t dev_id, const uint32_t digest_len)
2693982b21SPablo de Lara {
2793982b21SPablo de Lara 	int ret = 0;
2893982b21SPablo de Lara 	const struct blockcipher_test_data *tdata = t->test_data;
2993982b21SPablo de Lara 	struct rte_cryptodev_sym_capability_idx cap_idx;
3093982b21SPablo de Lara 	const struct rte_cryptodev_symmetric_capability *capability;
3193982b21SPablo de Lara 
3293982b21SPablo de Lara 	if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
3393982b21SPablo de Lara 		cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3493982b21SPablo de Lara 		cap_idx.algo.cipher = tdata->crypto_algo;
3593982b21SPablo de Lara 		capability = rte_cryptodev_sym_capability_get(dev_id, &cap_idx);
3693982b21SPablo de Lara 		if (capability == NULL)
3793982b21SPablo de Lara 			return -1;
3893982b21SPablo de Lara 
3993982b21SPablo de Lara 		if (cap_idx.algo.cipher != RTE_CRYPTO_CIPHER_NULL)
4093982b21SPablo de Lara 			ret = rte_cryptodev_sym_capability_check_cipher(capability,
4193982b21SPablo de Lara 							tdata->cipher_key.len,
4293982b21SPablo de Lara 							tdata->iv.len);
4393982b21SPablo de Lara 		if (ret != 0)
4493982b21SPablo de Lara 			return -1;
4593982b21SPablo de Lara 	}
4693982b21SPablo de Lara 
4793982b21SPablo de Lara 	if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) {
4893982b21SPablo de Lara 		cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4993982b21SPablo de Lara 		cap_idx.algo.auth = tdata->auth_algo;
5093982b21SPablo de Lara 		capability = rte_cryptodev_sym_capability_get(dev_id, &cap_idx);
5193982b21SPablo de Lara 		if (capability == NULL)
5293982b21SPablo de Lara 			return -1;
5393982b21SPablo de Lara 
5493982b21SPablo de Lara 		if (cap_idx.algo.auth != RTE_CRYPTO_AUTH_NULL)
5593982b21SPablo de Lara 			ret = rte_cryptodev_sym_capability_check_auth(capability,
5693982b21SPablo de Lara 							tdata->auth_key.len,
5793982b21SPablo de Lara 							digest_len,
5893982b21SPablo de Lara 							0);
5993982b21SPablo de Lara 		if (ret != 0)
6093982b21SPablo de Lara 			return -1;
6193982b21SPablo de Lara 	}
6293982b21SPablo de Lara 
6393982b21SPablo de Lara 	return 0;
6493982b21SPablo de Lara }
6593982b21SPablo de Lara 
6693982b21SPablo de Lara static int
67a9de470cSBruce Richardson test_blockcipher_one_case(const struct blockcipher_test_case *t,
68a9de470cSBruce Richardson 	struct rte_mempool *mbuf_pool,
69a9de470cSBruce Richardson 	struct rte_mempool *op_mpool,
70a9de470cSBruce Richardson 	struct rte_mempool *sess_mpool,
71a9de470cSBruce Richardson 	struct rte_mempool *sess_priv_mpool,
72a9de470cSBruce Richardson 	uint8_t dev_id,
73a9de470cSBruce Richardson 	int driver_id,
74a9de470cSBruce Richardson 	char *test_msg)
75a9de470cSBruce Richardson {
76a9de470cSBruce Richardson 	struct rte_mbuf *ibuf = NULL;
77a9de470cSBruce Richardson 	struct rte_mbuf *obuf = NULL;
78a9de470cSBruce Richardson 	struct rte_mbuf *iobuf;
79a9de470cSBruce Richardson 	struct rte_crypto_sym_xform *cipher_xform = NULL;
80a9de470cSBruce Richardson 	struct rte_crypto_sym_xform *auth_xform = NULL;
81a9de470cSBruce Richardson 	struct rte_crypto_sym_xform *init_xform = NULL;
82a9de470cSBruce Richardson 	struct rte_crypto_sym_op *sym_op = NULL;
83a9de470cSBruce Richardson 	struct rte_crypto_op *op = NULL;
84a9de470cSBruce Richardson 	struct rte_cryptodev_info dev_info;
85a9de470cSBruce Richardson 	struct rte_cryptodev_sym_session *sess = NULL;
86a9de470cSBruce Richardson 
87a9de470cSBruce Richardson 	int status = TEST_SUCCESS;
88a9de470cSBruce Richardson 	const struct blockcipher_test_data *tdata = t->test_data;
89a9de470cSBruce Richardson 	uint8_t cipher_key[tdata->cipher_key.len];
90a9de470cSBruce Richardson 	uint8_t auth_key[tdata->auth_key.len];
91a9de470cSBruce Richardson 	uint32_t buf_len = tdata->ciphertext.len;
92a9de470cSBruce Richardson 	uint32_t digest_len = 0;
93a9de470cSBruce Richardson 	char *buf_p = NULL;
94a9de470cSBruce Richardson 	uint8_t src_pattern = 0xa5;
95a9de470cSBruce Richardson 	uint8_t dst_pattern = 0xb6;
96a9de470cSBruce Richardson 	uint8_t tmp_src_buf[MBUF_SIZE];
97a9de470cSBruce Richardson 	uint8_t tmp_dst_buf[MBUF_SIZE];
98a9de470cSBruce Richardson 
99a9de470cSBruce Richardson 	int openssl_pmd = rte_cryptodev_driver_id_get(
100a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
101a9de470cSBruce Richardson 	int ccp_pmd = rte_cryptodev_driver_id_get(
102a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_CCP_PMD));
103a9de470cSBruce Richardson 	int scheduler_pmd = rte_cryptodev_driver_id_get(
104a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
105a9de470cSBruce Richardson 	int armv8_pmd = rte_cryptodev_driver_id_get(
106a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
107a9de470cSBruce Richardson 	int aesni_mb_pmd = rte_cryptodev_driver_id_get(
108a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
109a9de470cSBruce Richardson 	int qat_pmd = rte_cryptodev_driver_id_get(
110a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
111a9de470cSBruce Richardson 	int dpaa2_sec_pmd = rte_cryptodev_driver_id_get(
112a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
113a9de470cSBruce Richardson 	int dpaa_sec_pmd = rte_cryptodev_driver_id_get(
114a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
115a9de470cSBruce Richardson 	int caam_jr_pmd = rte_cryptodev_driver_id_get(
116a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
117a9de470cSBruce Richardson 	int mrvl_pmd = rte_cryptodev_driver_id_get(
118a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
119a9de470cSBruce Richardson 	int virtio_pmd = rte_cryptodev_driver_id_get(
120a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
121a9de470cSBruce Richardson 	int octeontx_pmd = rte_cryptodev_driver_id_get(
122a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
1236995630eSAnoob Joseph 	int octeontx2_pmd = rte_cryptodev_driver_id_get(
1246995630eSAnoob Joseph 			RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
125af46a0bcSFiona Trahe 	int null_pmd = rte_cryptodev_driver_id_get(
126af46a0bcSFiona Trahe 				RTE_STR(CRYPTODEV_NAME_NULL_PMD));
1275adf37e6SNagadheeraj Rottela 	int nitrox_pmd = rte_cryptodev_driver_id_get(
1285adf37e6SNagadheeraj Rottela 			RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
129a9de470cSBruce Richardson 
130a9de470cSBruce Richardson 	int nb_segs = 1;
1315e73a1f8SFan Zhang 	uint32_t nb_iterates = 0;
132a9de470cSBruce Richardson 
133a9de470cSBruce Richardson 	rte_cryptodev_info_get(dev_id, &dev_info);
134a9de470cSBruce Richardson 	uint64_t feat_flags = dev_info.feature_flags;
135*afcfa2fdSPablo de Lara 
136*afcfa2fdSPablo de Lara 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
137*afcfa2fdSPablo de Lara 		if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
138*afcfa2fdSPablo de Lara 			printf("Device doesn't support sesionless operations "
139*afcfa2fdSPablo de Lara 				"Test Skipped.\n");
140*afcfa2fdSPablo de Lara 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
141*afcfa2fdSPablo de Lara 				"SKIPPED");
142*afcfa2fdSPablo de Lara 			return 0;
143*afcfa2fdSPablo de Lara 		}
144*afcfa2fdSPablo de Lara 	}
145*afcfa2fdSPablo de Lara 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SG) {
146a9de470cSBruce Richardson 		uint64_t oop_flag = RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT;
147a9de470cSBruce Richardson 
148042bb565SPablo de Lara 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
149a9de470cSBruce Richardson 			if (!(feat_flags & oop_flag)) {
150a9de470cSBruce Richardson 				printf("Device doesn't support out-of-place "
151a9de470cSBruce Richardson 					"scatter-gather in input mbuf. "
152a9de470cSBruce Richardson 					"Test Skipped.\n");
15393982b21SPablo de Lara 				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
15493982b21SPablo de Lara 					"SKIPPED");
155a9de470cSBruce Richardson 				return 0;
156a9de470cSBruce Richardson 			}
157a9de470cSBruce Richardson 		} else {
158a9de470cSBruce Richardson 			if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
159a9de470cSBruce Richardson 				printf("Device doesn't support in-place "
160a9de470cSBruce Richardson 					"scatter-gather mbufs. "
161a9de470cSBruce Richardson 					"Test Skipped.\n");
16293982b21SPablo de Lara 				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
16393982b21SPablo de Lara 					"SKIPPED");
164a9de470cSBruce Richardson 				return 0;
165a9de470cSBruce Richardson 			}
166a9de470cSBruce Richardson 		}
167a9de470cSBruce Richardson 
168a9de470cSBruce Richardson 		nb_segs = 3;
169a9de470cSBruce Richardson 	}
170a9de470cSBruce Richardson 
171a9de470cSBruce Richardson 	if (tdata->cipher_key.len)
172a9de470cSBruce Richardson 		memcpy(cipher_key, tdata->cipher_key.data,
173a9de470cSBruce Richardson 			tdata->cipher_key.len);
174a9de470cSBruce Richardson 	if (tdata->auth_key.len)
175a9de470cSBruce Richardson 		memcpy(auth_key, tdata->auth_key.data,
176a9de470cSBruce Richardson 			tdata->auth_key.len);
177a9de470cSBruce Richardson 
178a9de470cSBruce Richardson 	if (driver_id == dpaa2_sec_pmd ||
179a9de470cSBruce Richardson 			driver_id == dpaa_sec_pmd ||
180a9de470cSBruce Richardson 			driver_id == caam_jr_pmd ||
181a9de470cSBruce Richardson 			driver_id == qat_pmd ||
182a9de470cSBruce Richardson 			driver_id == openssl_pmd ||
183a9de470cSBruce Richardson 			driver_id == armv8_pmd ||
184a9de470cSBruce Richardson 			driver_id == mrvl_pmd ||
185a9de470cSBruce Richardson 			driver_id == ccp_pmd ||
186a9de470cSBruce Richardson 			driver_id == virtio_pmd ||
187af46a0bcSFiona Trahe 			driver_id == octeontx_pmd ||
1886995630eSAnoob Joseph 			driver_id == octeontx2_pmd ||
1895adf37e6SNagadheeraj Rottela 			driver_id == null_pmd ||
1905adf37e6SNagadheeraj Rottela 			driver_id == nitrox_pmd) { /* Fall through */
191a9de470cSBruce Richardson 		digest_len = tdata->digest.len;
192a9de470cSBruce Richardson 	} else if (driver_id == aesni_mb_pmd ||
193a9de470cSBruce Richardson 			driver_id == scheduler_pmd) {
194a9de470cSBruce Richardson 		digest_len = tdata->digest.truncated_len;
195a9de470cSBruce Richardson 	} else {
196a9de470cSBruce Richardson 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
197a9de470cSBruce Richardson 			"line %u FAILED: %s",
198a9de470cSBruce Richardson 			__LINE__, "Unsupported PMD type");
199a9de470cSBruce Richardson 		status = TEST_FAILED;
200a9de470cSBruce Richardson 		goto error_exit;
201a9de470cSBruce Richardson 	}
202a9de470cSBruce Richardson 
20393982b21SPablo de Lara 	/* Check if PMD is capable of performing that test */
20493982b21SPablo de Lara 	if (verify_algo_support(t, dev_id, digest_len) < 0) {
20593982b21SPablo de Lara 		RTE_LOG(DEBUG, USER1,
20693982b21SPablo de Lara 			"Device does not support this algorithm."
20793982b21SPablo de Lara 			"Test Skipped.\n");
20893982b21SPablo de Lara 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "SKIPPED");
20993982b21SPablo de Lara 		return 0;
21093982b21SPablo de Lara 	}
21193982b21SPablo de Lara 
212a9de470cSBruce Richardson 	/* preparing data */
213a9de470cSBruce Richardson 	if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH)
214a9de470cSBruce Richardson 		buf_len += digest_len;
215a9de470cSBruce Richardson 
216a9de470cSBruce Richardson 	/* for contiguous mbuf, nb_segs is 1 */
217a9de470cSBruce Richardson 	ibuf = create_segmented_mbuf(mbuf_pool,
218a9de470cSBruce Richardson 			tdata->ciphertext.len, nb_segs, src_pattern);
219a9de470cSBruce Richardson 	if (ibuf == NULL) {
220a9de470cSBruce Richardson 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
221a9de470cSBruce Richardson 			"line %u FAILED: %s",
222a9de470cSBruce Richardson 			__LINE__, "Cannot create source mbuf");
223a9de470cSBruce Richardson 		status = TEST_FAILED;
224a9de470cSBruce Richardson 		goto error_exit;
225a9de470cSBruce Richardson 	}
226a9de470cSBruce Richardson 
227a9de470cSBruce Richardson 	/* only encryption requires plaintext.data input,
228a9de470cSBruce Richardson 	 * decryption/(digest gen)/(digest verify) use ciphertext.data
229a9de470cSBruce Richardson 	 * to be computed
230a9de470cSBruce Richardson 	 */
231a9de470cSBruce Richardson 	if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT)
232a9de470cSBruce Richardson 		pktmbuf_write(ibuf, 0, tdata->plaintext.len,
233a9de470cSBruce Richardson 				tdata->plaintext.data);
234a9de470cSBruce Richardson 	else
235a9de470cSBruce Richardson 		pktmbuf_write(ibuf, 0, tdata->ciphertext.len,
236a9de470cSBruce Richardson 				tdata->ciphertext.data);
237a9de470cSBruce Richardson 
238a9de470cSBruce Richardson 	buf_p = rte_pktmbuf_append(ibuf, digest_len);
239a9de470cSBruce Richardson 	if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY)
240a9de470cSBruce Richardson 		rte_memcpy(buf_p, tdata->digest.data, digest_len);
241a9de470cSBruce Richardson 	else
242a9de470cSBruce Richardson 		memset(buf_p, 0, digest_len);
243a9de470cSBruce Richardson 
244a9de470cSBruce Richardson 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
245a9de470cSBruce Richardson 		obuf = rte_pktmbuf_alloc(mbuf_pool);
246a9de470cSBruce Richardson 		if (!obuf) {
247a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
248a9de470cSBruce Richardson 				"FAILED: %s", __LINE__,
249a9de470cSBruce Richardson 				"Allocation of rte_mbuf failed");
250a9de470cSBruce Richardson 			status = TEST_FAILED;
251a9de470cSBruce Richardson 			goto error_exit;
252a9de470cSBruce Richardson 		}
253a9de470cSBruce Richardson 		memset(obuf->buf_addr, dst_pattern, obuf->buf_len);
254a9de470cSBruce Richardson 
255a9de470cSBruce Richardson 		buf_p = rte_pktmbuf_append(obuf, buf_len);
256a9de470cSBruce Richardson 		if (!buf_p) {
257a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
258a9de470cSBruce Richardson 				"FAILED: %s", __LINE__,
259a9de470cSBruce Richardson 				"No room to append mbuf");
260a9de470cSBruce Richardson 			status = TEST_FAILED;
261a9de470cSBruce Richardson 			goto error_exit;
262a9de470cSBruce Richardson 		}
263a9de470cSBruce Richardson 		memset(buf_p, 0, buf_len);
264a9de470cSBruce Richardson 	}
265a9de470cSBruce Richardson 
266a9de470cSBruce Richardson 	/* Generate Crypto op data structure */
267a9de470cSBruce Richardson 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_SYMMETRIC);
268a9de470cSBruce Richardson 	if (!op) {
269a9de470cSBruce Richardson 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
270a9de470cSBruce Richardson 			"line %u FAILED: %s",
271a9de470cSBruce Richardson 			__LINE__, "Failed to allocate symmetric crypto "
272a9de470cSBruce Richardson 			"operation struct");
273a9de470cSBruce Richardson 		status = TEST_FAILED;
274a9de470cSBruce Richardson 		goto error_exit;
275a9de470cSBruce Richardson 	}
276a9de470cSBruce Richardson 
277a9de470cSBruce Richardson 	sym_op = op->sym;
278a9de470cSBruce Richardson 
2795e73a1f8SFan Zhang iterate:
2805e73a1f8SFan Zhang 	if (nb_iterates) {
2815e73a1f8SFan Zhang 		struct rte_mbuf *tmp_buf = ibuf;
2825e73a1f8SFan Zhang 
2835e73a1f8SFan Zhang 		ibuf = obuf;
2845e73a1f8SFan Zhang 		obuf = tmp_buf;
2855e73a1f8SFan Zhang 
2865e73a1f8SFan Zhang 		rte_pktmbuf_reset(ibuf);
2875e73a1f8SFan Zhang 		rte_pktmbuf_reset(obuf);
2885e73a1f8SFan Zhang 
2895e73a1f8SFan Zhang 		rte_pktmbuf_append(ibuf, tdata->ciphertext.len);
2905e73a1f8SFan Zhang 
2915e73a1f8SFan Zhang 		/* only encryption requires plaintext.data input,
2925e73a1f8SFan Zhang 		 * decryption/(digest gen)/(digest verify) use ciphertext.data
2935e73a1f8SFan Zhang 		 * to be computed
2945e73a1f8SFan Zhang 		 */
2955e73a1f8SFan Zhang 		if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT)
2965e73a1f8SFan Zhang 			pktmbuf_write(ibuf, 0, tdata->plaintext.len,
2975e73a1f8SFan Zhang 					tdata->plaintext.data);
2985e73a1f8SFan Zhang 		else
2995e73a1f8SFan Zhang 			pktmbuf_write(ibuf, 0, tdata->ciphertext.len,
3005e73a1f8SFan Zhang 					tdata->ciphertext.data);
3015e73a1f8SFan Zhang 
3025e73a1f8SFan Zhang 		buf_p = rte_pktmbuf_append(ibuf, digest_len);
3035e73a1f8SFan Zhang 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY)
3045e73a1f8SFan Zhang 			rte_memcpy(buf_p, tdata->digest.data, digest_len);
3055e73a1f8SFan Zhang 		else
3065e73a1f8SFan Zhang 			memset(buf_p, 0, digest_len);
3075e73a1f8SFan Zhang 
3085e73a1f8SFan Zhang 		memset(obuf->buf_addr, dst_pattern, obuf->buf_len);
3095e73a1f8SFan Zhang 
3105e73a1f8SFan Zhang 		buf_p = rte_pktmbuf_append(obuf, buf_len);
3115e73a1f8SFan Zhang 		if (!buf_p) {
3125e73a1f8SFan Zhang 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
3135e73a1f8SFan Zhang 				"FAILED: %s", __LINE__,
3145e73a1f8SFan Zhang 				"No room to append mbuf");
3155e73a1f8SFan Zhang 			status = TEST_FAILED;
3165e73a1f8SFan Zhang 			goto error_exit;
3175e73a1f8SFan Zhang 		}
3185e73a1f8SFan Zhang 		memset(buf_p, 0, buf_len);
3195e73a1f8SFan Zhang 	}
3205e73a1f8SFan Zhang 
321a9de470cSBruce Richardson 	sym_op->m_src = ibuf;
322a9de470cSBruce Richardson 
323a9de470cSBruce Richardson 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
324a9de470cSBruce Richardson 		sym_op->m_dst = obuf;
325a9de470cSBruce Richardson 		iobuf = obuf;
326a9de470cSBruce Richardson 	} else {
327a9de470cSBruce Richardson 		sym_op->m_dst = NULL;
328a9de470cSBruce Richardson 		iobuf = ibuf;
329a9de470cSBruce Richardson 	}
330a9de470cSBruce Richardson 
331a9de470cSBruce Richardson 	/* sessionless op requires allocate xform using
332a9de470cSBruce Richardson 	 * rte_crypto_op_sym_xforms_alloc(), otherwise rte_zmalloc()
333a9de470cSBruce Richardson 	 * is used
334a9de470cSBruce Richardson 	 */
335a9de470cSBruce Richardson 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
336a9de470cSBruce Richardson 		uint32_t n_xforms = 0;
337a9de470cSBruce Richardson 
338a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER)
339a9de470cSBruce Richardson 			n_xforms++;
340a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH)
341a9de470cSBruce Richardson 			n_xforms++;
342a9de470cSBruce Richardson 
343a9de470cSBruce Richardson 		if (rte_crypto_op_sym_xforms_alloc(op, n_xforms)
344a9de470cSBruce Richardson 			== NULL) {
345a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
346a9de470cSBruce Richardson 				"FAILED: %s", __LINE__, "Failed to "
347a9de470cSBruce Richardson 				"allocate space for crypto transforms");
348a9de470cSBruce Richardson 			status = TEST_FAILED;
349a9de470cSBruce Richardson 			goto error_exit;
350a9de470cSBruce Richardson 		}
351a9de470cSBruce Richardson 	} else {
352a9de470cSBruce Richardson 		cipher_xform = rte_zmalloc(NULL,
353a9de470cSBruce Richardson 			sizeof(struct rte_crypto_sym_xform), 0);
354a9de470cSBruce Richardson 
355a9de470cSBruce Richardson 		auth_xform = rte_zmalloc(NULL,
356a9de470cSBruce Richardson 			sizeof(struct rte_crypto_sym_xform), 0);
357a9de470cSBruce Richardson 
358a9de470cSBruce Richardson 		if (!cipher_xform || !auth_xform) {
359a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
360a9de470cSBruce Richardson 				"FAILED: %s", __LINE__, "Failed to "
361a9de470cSBruce Richardson 				"allocate memory for crypto transforms");
362a9de470cSBruce Richardson 			status = TEST_FAILED;
363a9de470cSBruce Richardson 			goto error_exit;
364a9de470cSBruce Richardson 		}
365a9de470cSBruce Richardson 	}
366a9de470cSBruce Richardson 
367a9de470cSBruce Richardson 	/* preparing xform, for sessioned op, init_xform is initialized
368a9de470cSBruce Richardson 	 * here and later as param in rte_cryptodev_sym_session_create() call
369a9de470cSBruce Richardson 	 */
370a9de470cSBruce Richardson 	if (t->op_mask == BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN) {
371a9de470cSBruce Richardson 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
372a9de470cSBruce Richardson 			cipher_xform = op->sym->xform;
373a9de470cSBruce Richardson 			auth_xform = cipher_xform->next;
374a9de470cSBruce Richardson 			auth_xform->next = NULL;
375a9de470cSBruce Richardson 		} else {
376a9de470cSBruce Richardson 			cipher_xform->next = auth_xform;
377a9de470cSBruce Richardson 			auth_xform->next = NULL;
378a9de470cSBruce Richardson 			init_xform = cipher_xform;
379a9de470cSBruce Richardson 		}
380a9de470cSBruce Richardson 	} else if (t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC) {
381a9de470cSBruce Richardson 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
382a9de470cSBruce Richardson 			auth_xform = op->sym->xform;
383a9de470cSBruce Richardson 			cipher_xform = auth_xform->next;
384a9de470cSBruce Richardson 			cipher_xform->next = NULL;
385a9de470cSBruce Richardson 		} else {
386a9de470cSBruce Richardson 			auth_xform->next = cipher_xform;
387a9de470cSBruce Richardson 			cipher_xform->next = NULL;
388a9de470cSBruce Richardson 			init_xform = auth_xform;
389a9de470cSBruce Richardson 		}
390a9de470cSBruce Richardson 	} else if ((t->op_mask == BLOCKCIPHER_TEST_OP_ENCRYPT) ||
391a9de470cSBruce Richardson 			(t->op_mask == BLOCKCIPHER_TEST_OP_DECRYPT)) {
392a9de470cSBruce Richardson 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)
393a9de470cSBruce Richardson 			cipher_xform = op->sym->xform;
394a9de470cSBruce Richardson 		else
395a9de470cSBruce Richardson 			init_xform = cipher_xform;
396a9de470cSBruce Richardson 		cipher_xform->next = NULL;
397a9de470cSBruce Richardson 	} else if ((t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_GEN) ||
398a9de470cSBruce Richardson 			(t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_VERIFY)) {
399a9de470cSBruce Richardson 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)
400a9de470cSBruce Richardson 			auth_xform = op->sym->xform;
401a9de470cSBruce Richardson 		else
402a9de470cSBruce Richardson 			init_xform = auth_xform;
403a9de470cSBruce Richardson 		auth_xform->next = NULL;
404a9de470cSBruce Richardson 	} else {
405a9de470cSBruce Richardson 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
406a9de470cSBruce Richardson 			"line %u FAILED: %s",
407a9de470cSBruce Richardson 			__LINE__, "Unrecognized operation");
408a9de470cSBruce Richardson 		status = TEST_FAILED;
409a9de470cSBruce Richardson 		goto error_exit;
410a9de470cSBruce Richardson 	}
411a9de470cSBruce Richardson 
412a9de470cSBruce Richardson 	/*configure xforms & sym_op cipher and auth data*/
413a9de470cSBruce Richardson 	if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
414a9de470cSBruce Richardson 		cipher_xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
415a9de470cSBruce Richardson 		cipher_xform->cipher.algo = tdata->crypto_algo;
416a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT)
417a9de470cSBruce Richardson 			cipher_xform->cipher.op =
418a9de470cSBruce Richardson 				RTE_CRYPTO_CIPHER_OP_ENCRYPT;
419a9de470cSBruce Richardson 		else
420a9de470cSBruce Richardson 			cipher_xform->cipher.op =
421a9de470cSBruce Richardson 				RTE_CRYPTO_CIPHER_OP_DECRYPT;
422a9de470cSBruce Richardson 		cipher_xform->cipher.key.data = cipher_key;
423a9de470cSBruce Richardson 		cipher_xform->cipher.key.length = tdata->cipher_key.len;
424a9de470cSBruce Richardson 		cipher_xform->cipher.iv.offset = IV_OFFSET;
425a9de470cSBruce Richardson 		cipher_xform->cipher.iv.length = tdata->iv.len;
426a9de470cSBruce Richardson 
4275e73a1f8SFan Zhang 		sym_op->cipher.data.offset = tdata->cipher_offset;
4285e73a1f8SFan Zhang 		sym_op->cipher.data.length = tdata->ciphertext.len -
4295e73a1f8SFan Zhang 				tdata->cipher_offset;
430a9de470cSBruce Richardson 		rte_memcpy(rte_crypto_op_ctod_offset(op, uint8_t *, IV_OFFSET),
431a9de470cSBruce Richardson 				tdata->iv.data,
432a9de470cSBruce Richardson 				tdata->iv.len);
433a9de470cSBruce Richardson 	}
434a9de470cSBruce Richardson 
435a9de470cSBruce Richardson 	if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) {
436a9de470cSBruce Richardson 		uint32_t digest_offset = tdata->ciphertext.len;
437a9de470cSBruce Richardson 
438a9de470cSBruce Richardson 		auth_xform->type = RTE_CRYPTO_SYM_XFORM_AUTH;
439a9de470cSBruce Richardson 		auth_xform->auth.algo = tdata->auth_algo;
440a9de470cSBruce Richardson 		auth_xform->auth.key.length = tdata->auth_key.len;
441a9de470cSBruce Richardson 		auth_xform->auth.key.data = auth_key;
442a9de470cSBruce Richardson 		auth_xform->auth.digest_length = digest_len;
443a9de470cSBruce Richardson 
444a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) {
445a9de470cSBruce Richardson 			auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
446a9de470cSBruce Richardson 			sym_op->auth.digest.data = pktmbuf_mtod_offset
447a9de470cSBruce Richardson 				(iobuf, digest_offset);
448a9de470cSBruce Richardson 			sym_op->auth.digest.phys_addr =
449a9de470cSBruce Richardson 				pktmbuf_iova_offset(iobuf,
450a9de470cSBruce Richardson 					digest_offset);
451a9de470cSBruce Richardson 		} else {
452a9de470cSBruce Richardson 			auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
453a9de470cSBruce Richardson 			sym_op->auth.digest.data = pktmbuf_mtod_offset
454a9de470cSBruce Richardson 				(sym_op->m_src, digest_offset);
455a9de470cSBruce Richardson 			sym_op->auth.digest.phys_addr =
456a9de470cSBruce Richardson 				pktmbuf_iova_offset(sym_op->m_src,
457a9de470cSBruce Richardson 					digest_offset);
458a9de470cSBruce Richardson 		}
459a9de470cSBruce Richardson 
4605e73a1f8SFan Zhang 		sym_op->auth.data.offset = tdata->auth_offset;
4615e73a1f8SFan Zhang 		sym_op->auth.data.length = tdata->ciphertext.len -
4625e73a1f8SFan Zhang 				tdata->auth_offset;
463a9de470cSBruce Richardson 	}
464a9de470cSBruce Richardson 
4655e73a1f8SFan Zhang 	/**
4665e73a1f8SFan Zhang 	 * Create session for sessioned op. For mbuf iteration test,
4675e73a1f8SFan Zhang 	 * skip the session creation for the second iteration.
4685e73a1f8SFan Zhang 	 */
4695e73a1f8SFan Zhang 	if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) &&
4705e73a1f8SFan Zhang 			nb_iterates == 0) {
471a9de470cSBruce Richardson 		sess = rte_cryptodev_sym_session_create(sess_mpool);
472a9de470cSBruce Richardson 
473a9de470cSBruce Richardson 		rte_cryptodev_sym_session_init(dev_id, sess, init_xform,
474a9de470cSBruce Richardson 				sess_priv_mpool);
475a9de470cSBruce Richardson 		if (!sess) {
476a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
477a9de470cSBruce Richardson 				"FAILED: %s", __LINE__,
478a9de470cSBruce Richardson 				"Session creation failed");
479a9de470cSBruce Richardson 			status = TEST_FAILED;
480a9de470cSBruce Richardson 			goto error_exit;
481a9de470cSBruce Richardson 		}
482a9de470cSBruce Richardson 
483a9de470cSBruce Richardson 		/* attach symmetric crypto session to crypto operations */
484a9de470cSBruce Richardson 		rte_crypto_op_attach_sym_session(op, sess);
485a9de470cSBruce Richardson 	}
486a9de470cSBruce Richardson 
487a9de470cSBruce Richardson 	debug_hexdump(stdout, "m_src(before):",
488a9de470cSBruce Richardson 			sym_op->m_src->buf_addr, sym_op->m_src->buf_len);
489a9de470cSBruce Richardson 	rte_memcpy(tmp_src_buf, sym_op->m_src->buf_addr,
490a9de470cSBruce Richardson 						sym_op->m_src->buf_len);
491a9de470cSBruce Richardson 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
492a9de470cSBruce Richardson 		debug_hexdump(stdout, "m_dst(before):",
493a9de470cSBruce Richardson 			sym_op->m_dst->buf_addr, sym_op->m_dst->buf_len);
494a9de470cSBruce Richardson 		rte_memcpy(tmp_dst_buf, sym_op->m_dst->buf_addr,
495a9de470cSBruce Richardson 						sym_op->m_dst->buf_len);
496a9de470cSBruce Richardson 	}
497a9de470cSBruce Richardson 
498a9de470cSBruce Richardson 	/* Process crypto operation */
499a9de470cSBruce Richardson 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
500a9de470cSBruce Richardson 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
501a9de470cSBruce Richardson 			"line %u FAILED: %s",
502a9de470cSBruce Richardson 			__LINE__, "Error sending packet for encryption");
503a9de470cSBruce Richardson 		status = TEST_FAILED;
504a9de470cSBruce Richardson 		goto error_exit;
505a9de470cSBruce Richardson 	}
506a9de470cSBruce Richardson 
507a9de470cSBruce Richardson 	op = NULL;
508a9de470cSBruce Richardson 
509a9de470cSBruce Richardson 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
510a9de470cSBruce Richardson 		rte_pause();
511a9de470cSBruce Richardson 
512a9de470cSBruce Richardson 	if (!op) {
513a9de470cSBruce Richardson 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
514a9de470cSBruce Richardson 			"line %u FAILED: %s",
515a9de470cSBruce Richardson 			__LINE__, "Failed to process sym crypto op");
516a9de470cSBruce Richardson 		status = TEST_FAILED;
517a9de470cSBruce Richardson 		goto error_exit;
518a9de470cSBruce Richardson 	}
519a9de470cSBruce Richardson 
520a9de470cSBruce Richardson 	debug_hexdump(stdout, "m_src(after):",
521a9de470cSBruce Richardson 			sym_op->m_src->buf_addr, sym_op->m_src->buf_len);
522a9de470cSBruce Richardson 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP)
523a9de470cSBruce Richardson 		debug_hexdump(stdout, "m_dst(after):",
524a9de470cSBruce Richardson 			sym_op->m_dst->buf_addr, sym_op->m_dst->buf_len);
525a9de470cSBruce Richardson 
526a9de470cSBruce Richardson 	/* Verify results */
527a9de470cSBruce Richardson 	if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
528a9de470cSBruce Richardson 		if ((t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY) &&
529a9de470cSBruce Richardson 			(op->status == RTE_CRYPTO_OP_STATUS_AUTH_FAILED))
530a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
531a9de470cSBruce Richardson 				"FAILED: Digest verification failed "
532a9de470cSBruce Richardson 				"(0x%X)", __LINE__, op->status);
533a9de470cSBruce Richardson 		else
534a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
535a9de470cSBruce Richardson 				"FAILED: Operation failed "
536a9de470cSBruce Richardson 				"(0x%X)", __LINE__, op->status);
537a9de470cSBruce Richardson 		status = TEST_FAILED;
538a9de470cSBruce Richardson 		goto error_exit;
539a9de470cSBruce Richardson 	}
540a9de470cSBruce Richardson 
541a9de470cSBruce Richardson 	if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
542a9de470cSBruce Richardson 		uint8_t buffer[2048];
543a9de470cSBruce Richardson 		const uint8_t *compare_ref;
544a9de470cSBruce Richardson 		uint32_t compare_len;
545a9de470cSBruce Richardson 
546a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT) {
5475e73a1f8SFan Zhang 			compare_ref = tdata->ciphertext.data +
5485e73a1f8SFan Zhang 					tdata->cipher_offset;
5495e73a1f8SFan Zhang 			compare_len = tdata->ciphertext.len -
5505e73a1f8SFan Zhang 					tdata->cipher_offset;
551a9de470cSBruce Richardson 		} else {
5525e73a1f8SFan Zhang 			compare_ref = tdata->plaintext.data +
5535e73a1f8SFan Zhang 					tdata->cipher_offset;
5545e73a1f8SFan Zhang 			compare_len = tdata->plaintext.len -
5555e73a1f8SFan Zhang 					tdata->cipher_offset;
556a9de470cSBruce Richardson 		}
557a9de470cSBruce Richardson 
5585e73a1f8SFan Zhang 		if (memcmp(rte_pktmbuf_read(iobuf, tdata->cipher_offset,
5595e73a1f8SFan Zhang 				compare_len, buffer), compare_ref,
5605e73a1f8SFan Zhang 				compare_len)) {
561a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
562a9de470cSBruce Richardson 				"FAILED: %s", __LINE__,
563a9de470cSBruce Richardson 				"Crypto data not as expected");
564a9de470cSBruce Richardson 			status = TEST_FAILED;
565a9de470cSBruce Richardson 			goto error_exit;
566a9de470cSBruce Richardson 		}
567a9de470cSBruce Richardson 	}
568a9de470cSBruce Richardson 
569a9de470cSBruce Richardson 	if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) {
570a9de470cSBruce Richardson 		uint8_t *auth_res = pktmbuf_mtod_offset(iobuf,
571a9de470cSBruce Richardson 					tdata->ciphertext.len);
572a9de470cSBruce Richardson 
573a9de470cSBruce Richardson 		if (memcmp(auth_res, tdata->digest.data, digest_len)) {
574a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
575a9de470cSBruce Richardson 				"FAILED: %s", __LINE__, "Generated "
576a9de470cSBruce Richardson 				"digest data not as expected");
577a9de470cSBruce Richardson 			status = TEST_FAILED;
578a9de470cSBruce Richardson 			goto error_exit;
579a9de470cSBruce Richardson 		}
580a9de470cSBruce Richardson 	}
581a9de470cSBruce Richardson 
582a9de470cSBruce Richardson 	/* The only parts that should have changed in the buffer are
583a9de470cSBruce Richardson 	 * plaintext/ciphertext and digest.
584a9de470cSBruce Richardson 	 * In OOP only the dest buffer should change.
585a9de470cSBruce Richardson 	 */
586a9de470cSBruce Richardson 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
587a9de470cSBruce Richardson 		struct rte_mbuf *mbuf;
588a9de470cSBruce Richardson 		uint8_t value;
589a9de470cSBruce Richardson 		uint32_t head_unchanged_len, changed_len = 0;
590a9de470cSBruce Richardson 		uint32_t i;
591a9de470cSBruce Richardson 		uint32_t hdroom_used = 0, tlroom_used = 0;
592a9de470cSBruce Richardson 		uint32_t hdroom = 0;
593a9de470cSBruce Richardson 
594a9de470cSBruce Richardson 		mbuf = sym_op->m_src;
595a9de470cSBruce Richardson 		/*
596a9de470cSBruce Richardson 		 * Crypto PMDs specify the headroom & tailroom it would use
597a9de470cSBruce Richardson 		 * when processing the crypto operation. PMD is free to modify
598a9de470cSBruce Richardson 		 * this space, and so the verification check should skip that
599a9de470cSBruce Richardson 		 * block.
600a9de470cSBruce Richardson 		 */
601a9de470cSBruce Richardson 		hdroom_used = dev_info.min_mbuf_headroom_req;
602a9de470cSBruce Richardson 		tlroom_used = dev_info.min_mbuf_tailroom_req;
603a9de470cSBruce Richardson 
604a9de470cSBruce Richardson 		/* Get headroom */
605a9de470cSBruce Richardson 		hdroom = rte_pktmbuf_headroom(mbuf);
606a9de470cSBruce Richardson 
607a9de470cSBruce Richardson 		head_unchanged_len = mbuf->buf_len;
608a9de470cSBruce Richardson 
609a9de470cSBruce Richardson 		for (i = 0; i < mbuf->buf_len; i++) {
610a9de470cSBruce Richardson 
611a9de470cSBruce Richardson 			/* Skip headroom used by PMD */
612a9de470cSBruce Richardson 			if (i == hdroom - hdroom_used)
613a9de470cSBruce Richardson 				i += hdroom_used;
614a9de470cSBruce Richardson 
615a9de470cSBruce Richardson 			/* Skip tailroom used by PMD */
616a9de470cSBruce Richardson 			if (i == (hdroom + mbuf->data_len))
617a9de470cSBruce Richardson 				i += tlroom_used;
618a9de470cSBruce Richardson 
619a9de470cSBruce Richardson 			value = *((uint8_t *)(mbuf->buf_addr)+i);
620a9de470cSBruce Richardson 			if (value != tmp_src_buf[i]) {
621a9de470cSBruce Richardson 				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
622a9de470cSBruce Richardson 	"line %u FAILED: OOP src outer mbuf data (0x%x) not as expected (0x%x)",
623a9de470cSBruce Richardson 					__LINE__, value, tmp_src_buf[i]);
624a9de470cSBruce Richardson 				status = TEST_FAILED;
625a9de470cSBruce Richardson 				goto error_exit;
626a9de470cSBruce Richardson 			}
627a9de470cSBruce Richardson 		}
628a9de470cSBruce Richardson 
629a9de470cSBruce Richardson 		mbuf = sym_op->m_dst;
630a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) {
631a9de470cSBruce Richardson 			head_unchanged_len = hdroom + sym_op->auth.data.offset;
632a9de470cSBruce Richardson 			changed_len = sym_op->auth.data.length;
633a9de470cSBruce Richardson 			if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN)
634a9de470cSBruce Richardson 				changed_len += digest_len;
635a9de470cSBruce Richardson 		} else {
636a9de470cSBruce Richardson 			/* cipher-only */
637a9de470cSBruce Richardson 			head_unchanged_len = hdroom +
638a9de470cSBruce Richardson 					sym_op->cipher.data.offset;
639a9de470cSBruce Richardson 			changed_len = sym_op->cipher.data.length;
640a9de470cSBruce Richardson 		}
641a9de470cSBruce Richardson 
642a9de470cSBruce Richardson 		for (i = 0; i < mbuf->buf_len; i++) {
643a9de470cSBruce Richardson 			if (i == head_unchanged_len)
644a9de470cSBruce Richardson 				i += changed_len;
645a9de470cSBruce Richardson 			value = *((uint8_t *)(mbuf->buf_addr)+i);
646a9de470cSBruce Richardson 			if (value != tmp_dst_buf[i]) {
647a9de470cSBruce Richardson 				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
648a9de470cSBruce Richardson 				"line %u FAILED: OOP dst outer mbuf data "
649a9de470cSBruce Richardson 				"(0x%x) not as expected (0x%x)",
650a9de470cSBruce Richardson 				__LINE__, value, tmp_dst_buf[i]);
651a9de470cSBruce Richardson 				status = TEST_FAILED;
652a9de470cSBruce Richardson 				goto error_exit;
653a9de470cSBruce Richardson 			}
654a9de470cSBruce Richardson 		}
6555e73a1f8SFan Zhang 
6565e73a1f8SFan Zhang 		if (!nb_iterates) {
6575e73a1f8SFan Zhang 			nb_iterates++;
6585e73a1f8SFan Zhang 			goto iterate;
6595e73a1f8SFan Zhang 		}
660a9de470cSBruce Richardson 	} else {
661a9de470cSBruce Richardson 		/* In-place operation */
662a9de470cSBruce Richardson 		struct rte_mbuf *mbuf;
663a9de470cSBruce Richardson 		uint8_t value;
664a9de470cSBruce Richardson 		uint32_t head_unchanged_len = 0, changed_len = 0;
665a9de470cSBruce Richardson 		uint32_t i;
666a9de470cSBruce Richardson 		uint32_t hdroom_used = 0, tlroom_used = 0;
667a9de470cSBruce Richardson 		uint32_t hdroom = 0;
668a9de470cSBruce Richardson 
669a9de470cSBruce Richardson 		/*
670a9de470cSBruce Richardson 		 * Crypto PMDs specify the headroom & tailroom it would use
671a9de470cSBruce Richardson 		 * when processing the crypto operation. PMD is free to modify
672a9de470cSBruce Richardson 		 * this space, and so the verification check should skip that
673a9de470cSBruce Richardson 		 * block.
674a9de470cSBruce Richardson 		 */
675a9de470cSBruce Richardson 		hdroom_used = dev_info.min_mbuf_headroom_req;
676a9de470cSBruce Richardson 		tlroom_used = dev_info.min_mbuf_tailroom_req;
677a9de470cSBruce Richardson 
678a9de470cSBruce Richardson 		mbuf = sym_op->m_src;
679a9de470cSBruce Richardson 
680a9de470cSBruce Richardson 		/* Get headroom */
681a9de470cSBruce Richardson 		hdroom = rte_pktmbuf_headroom(mbuf);
682a9de470cSBruce Richardson 
683a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
684a9de470cSBruce Richardson 			head_unchanged_len = hdroom +
685a9de470cSBruce Richardson 					sym_op->cipher.data.offset;
686a9de470cSBruce Richardson 			changed_len = sym_op->cipher.data.length;
687a9de470cSBruce Richardson 		} else {
688a9de470cSBruce Richardson 			/* auth-only */
689a9de470cSBruce Richardson 			head_unchanged_len = hdroom +
690a9de470cSBruce Richardson 					sym_op->auth.data.offset +
691a9de470cSBruce Richardson 					sym_op->auth.data.length;
692a9de470cSBruce Richardson 			changed_len = 0;
693a9de470cSBruce Richardson 		}
694a9de470cSBruce Richardson 
695a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN)
696a9de470cSBruce Richardson 			changed_len += digest_len;
697a9de470cSBruce Richardson 
698a9de470cSBruce Richardson 		for (i = 0; i < mbuf->buf_len; i++) {
699a9de470cSBruce Richardson 
700a9de470cSBruce Richardson 			/* Skip headroom used by PMD */
701a9de470cSBruce Richardson 			if (i == hdroom - hdroom_used)
702a9de470cSBruce Richardson 				i += hdroom_used;
703a9de470cSBruce Richardson 
704a9de470cSBruce Richardson 			if (i == head_unchanged_len)
705a9de470cSBruce Richardson 				i += changed_len;
706a9de470cSBruce Richardson 
707a9de470cSBruce Richardson 			/* Skip tailroom used by PMD */
708a9de470cSBruce Richardson 			if (i == (hdroom + mbuf->data_len))
709a9de470cSBruce Richardson 				i += tlroom_used;
710a9de470cSBruce Richardson 
711a9de470cSBruce Richardson 			value = *((uint8_t *)(mbuf->buf_addr)+i);
712a9de470cSBruce Richardson 			if (value != tmp_src_buf[i]) {
713a9de470cSBruce Richardson 				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
714a9de470cSBruce Richardson 				"line %u FAILED: outer mbuf data (0x%x) "
715a9de470cSBruce Richardson 				"not as expected (0x%x)",
716a9de470cSBruce Richardson 				__LINE__, value, tmp_src_buf[i]);
717a9de470cSBruce Richardson 				status = TEST_FAILED;
718a9de470cSBruce Richardson 				goto error_exit;
719a9de470cSBruce Richardson 			}
720a9de470cSBruce Richardson 		}
721a9de470cSBruce Richardson 	}
722a9de470cSBruce Richardson 
723a9de470cSBruce Richardson 	snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "PASS");
724a9de470cSBruce Richardson 
725a9de470cSBruce Richardson error_exit:
726a9de470cSBruce Richardson 	if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)) {
727a9de470cSBruce Richardson 		if (sess) {
728a9de470cSBruce Richardson 			rte_cryptodev_sym_session_clear(dev_id, sess);
729a9de470cSBruce Richardson 			rte_cryptodev_sym_session_free(sess);
730a9de470cSBruce Richardson 		}
731a9de470cSBruce Richardson 		if (cipher_xform)
732a9de470cSBruce Richardson 			rte_free(cipher_xform);
733a9de470cSBruce Richardson 		if (auth_xform)
734a9de470cSBruce Richardson 			rte_free(auth_xform);
735a9de470cSBruce Richardson 	}
736a9de470cSBruce Richardson 
737a9de470cSBruce Richardson 	if (op)
738a9de470cSBruce Richardson 		rte_crypto_op_free(op);
739a9de470cSBruce Richardson 
740a9de470cSBruce Richardson 	if (obuf)
741a9de470cSBruce Richardson 		rte_pktmbuf_free(obuf);
742a9de470cSBruce Richardson 
743a9de470cSBruce Richardson 	if (ibuf)
744a9de470cSBruce Richardson 		rte_pktmbuf_free(ibuf);
745a9de470cSBruce Richardson 
746a9de470cSBruce Richardson 	return status;
747a9de470cSBruce Richardson }
748a9de470cSBruce Richardson 
749a9de470cSBruce Richardson int
750a9de470cSBruce Richardson test_blockcipher_all_tests(struct rte_mempool *mbuf_pool,
751a9de470cSBruce Richardson 	struct rte_mempool *op_mpool,
752a9de470cSBruce Richardson 	struct rte_mempool *sess_mpool,
753a9de470cSBruce Richardson 	struct rte_mempool *sess_priv_mpool,
754a9de470cSBruce Richardson 	uint8_t dev_id,
755a9de470cSBruce Richardson 	int driver_id,
756a9de470cSBruce Richardson 	enum blockcipher_test_type test_type)
757a9de470cSBruce Richardson {
758a9de470cSBruce Richardson 	int status, overall_status = TEST_SUCCESS;
759a9de470cSBruce Richardson 	uint32_t i, test_index = 0;
760a9de470cSBruce Richardson 	char test_msg[BLOCKCIPHER_TEST_MSG_LEN + 1];
761a9de470cSBruce Richardson 	uint32_t n_test_cases = 0;
762a9de470cSBruce Richardson 	uint32_t target_pmd_mask = 0;
763a9de470cSBruce Richardson 	const struct blockcipher_test_case *tcs = NULL;
764a9de470cSBruce Richardson 
765a9de470cSBruce Richardson 	int openssl_pmd = rte_cryptodev_driver_id_get(
766a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
767a9de470cSBruce Richardson 	int ccp_pmd = rte_cryptodev_driver_id_get(
768a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_CCP_PMD));
769a9de470cSBruce Richardson 	int dpaa2_sec_pmd = rte_cryptodev_driver_id_get(
770a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
771a9de470cSBruce Richardson 	int dpaa_sec_pmd = rte_cryptodev_driver_id_get(
772a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
773a9de470cSBruce Richardson 	int caam_jr_pmd = rte_cryptodev_driver_id_get(
774a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
775a9de470cSBruce Richardson 	int scheduler_pmd = rte_cryptodev_driver_id_get(
776a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
777a9de470cSBruce Richardson 	int armv8_pmd = rte_cryptodev_driver_id_get(
778a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
779a9de470cSBruce Richardson 	int aesni_mb_pmd = rte_cryptodev_driver_id_get(
780a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
781a9de470cSBruce Richardson 	int qat_pmd = rte_cryptodev_driver_id_get(
782a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
783a9de470cSBruce Richardson 	int mrvl_pmd = rte_cryptodev_driver_id_get(
784a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
785a9de470cSBruce Richardson 	int virtio_pmd = rte_cryptodev_driver_id_get(
786a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
787a9de470cSBruce Richardson 	int octeontx_pmd = rte_cryptodev_driver_id_get(
788a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
7896995630eSAnoob Joseph 	int octeontx2_pmd = rte_cryptodev_driver_id_get(
7906995630eSAnoob Joseph 			RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
791af46a0bcSFiona Trahe 	int null_pmd = rte_cryptodev_driver_id_get(
792af46a0bcSFiona Trahe 				RTE_STR(CRYPTODEV_NAME_NULL_PMD));
7935adf37e6SNagadheeraj Rottela 	int nitrox_pmd = rte_cryptodev_driver_id_get(
7945adf37e6SNagadheeraj Rottela 			RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
795a9de470cSBruce Richardson 
796a9de470cSBruce Richardson 	switch (test_type) {
797a9de470cSBruce Richardson 	case BLKCIPHER_AES_CHAIN_TYPE:
798a9de470cSBruce Richardson 		n_test_cases = sizeof(aes_chain_test_cases) /
799a9de470cSBruce Richardson 		sizeof(aes_chain_test_cases[0]);
800a9de470cSBruce Richardson 		tcs = aes_chain_test_cases;
801a9de470cSBruce Richardson 		break;
802a9de470cSBruce Richardson 	case BLKCIPHER_AES_CIPHERONLY_TYPE:
803a9de470cSBruce Richardson 		n_test_cases = sizeof(aes_cipheronly_test_cases) /
804a9de470cSBruce Richardson 		sizeof(aes_cipheronly_test_cases[0]);
805a9de470cSBruce Richardson 		tcs = aes_cipheronly_test_cases;
806a9de470cSBruce Richardson 		break;
807a9de470cSBruce Richardson 	case BLKCIPHER_AES_DOCSIS_TYPE:
808a9de470cSBruce Richardson 		n_test_cases = sizeof(aes_docsis_test_cases) /
809a9de470cSBruce Richardson 		sizeof(aes_docsis_test_cases[0]);
810a9de470cSBruce Richardson 		tcs = aes_docsis_test_cases;
811a9de470cSBruce Richardson 		break;
812a9de470cSBruce Richardson 	case BLKCIPHER_3DES_CHAIN_TYPE:
813a9de470cSBruce Richardson 		n_test_cases = sizeof(triple_des_chain_test_cases) /
814a9de470cSBruce Richardson 		sizeof(triple_des_chain_test_cases[0]);
815a9de470cSBruce Richardson 		tcs = triple_des_chain_test_cases;
816a9de470cSBruce Richardson 		break;
817a9de470cSBruce Richardson 	case BLKCIPHER_3DES_CIPHERONLY_TYPE:
818a9de470cSBruce Richardson 		n_test_cases = sizeof(triple_des_cipheronly_test_cases) /
819a9de470cSBruce Richardson 		sizeof(triple_des_cipheronly_test_cases[0]);
820a9de470cSBruce Richardson 		tcs = triple_des_cipheronly_test_cases;
821a9de470cSBruce Richardson 		break;
822a9de470cSBruce Richardson 	case BLKCIPHER_DES_CIPHERONLY_TYPE:
823a9de470cSBruce Richardson 		n_test_cases = sizeof(des_cipheronly_test_cases) /
824a9de470cSBruce Richardson 		sizeof(des_cipheronly_test_cases[0]);
825a9de470cSBruce Richardson 		tcs = des_cipheronly_test_cases;
826a9de470cSBruce Richardson 		break;
827a9de470cSBruce Richardson 	case BLKCIPHER_DES_DOCSIS_TYPE:
828a9de470cSBruce Richardson 		n_test_cases = sizeof(des_docsis_test_cases) /
829a9de470cSBruce Richardson 		sizeof(des_docsis_test_cases[0]);
830a9de470cSBruce Richardson 		tcs = des_docsis_test_cases;
831a9de470cSBruce Richardson 		break;
832a9de470cSBruce Richardson 	case BLKCIPHER_AUTHONLY_TYPE:
833a9de470cSBruce Richardson 		n_test_cases = sizeof(hash_test_cases) /
834a9de470cSBruce Richardson 		sizeof(hash_test_cases[0]);
835a9de470cSBruce Richardson 		tcs = hash_test_cases;
836a9de470cSBruce Richardson 		break;
837a9de470cSBruce Richardson 	default:
838a9de470cSBruce Richardson 		break;
839a9de470cSBruce Richardson 	}
840a9de470cSBruce Richardson 
841a9de470cSBruce Richardson 	if (driver_id == aesni_mb_pmd)
842a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_MB;
843a9de470cSBruce Richardson 	else if (driver_id == qat_pmd)
844a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_QAT;
845a9de470cSBruce Richardson 	else if (driver_id == openssl_pmd)
846a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_OPENSSL;
847a9de470cSBruce Richardson 	else if (driver_id == armv8_pmd)
848a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_ARMV8;
849a9de470cSBruce Richardson 	else if (driver_id == scheduler_pmd)
850a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER;
851a9de470cSBruce Richardson 	else if (driver_id == dpaa2_sec_pmd)
852a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC;
853a9de470cSBruce Richardson 	else if (driver_id == ccp_pmd)
854a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_CCP;
855a9de470cSBruce Richardson 	else if (driver_id == dpaa_sec_pmd)
856a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC;
857a9de470cSBruce Richardson 	else if (driver_id == caam_jr_pmd)
858a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_CAAM_JR;
859a9de470cSBruce Richardson 	else if (driver_id == mrvl_pmd)
860a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_MVSAM;
861a9de470cSBruce Richardson 	else if (driver_id == virtio_pmd)
862a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO;
863a9de470cSBruce Richardson 	else if (driver_id == octeontx_pmd)
864a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_OCTEONTX;
8656995630eSAnoob Joseph 	else if (driver_id == octeontx2_pmd)
8666995630eSAnoob Joseph 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_OCTEONTX2;
867af46a0bcSFiona Trahe 	else if (driver_id == null_pmd)
868af46a0bcSFiona Trahe 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_NULL;
8695adf37e6SNagadheeraj Rottela 	else if (driver_id == nitrox_pmd)
8705adf37e6SNagadheeraj Rottela 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_NITROX;
871a9de470cSBruce Richardson 	else
872a7cfae49SAdam Dybkowski 		return -ENOTSUP; /* Unrecognized cryptodev type */
873a9de470cSBruce Richardson 
874a9de470cSBruce Richardson 	for (i = 0; i < n_test_cases; i++) {
875a9de470cSBruce Richardson 		const struct blockcipher_test_case *tc = &tcs[i];
876a9de470cSBruce Richardson 
877a9de470cSBruce Richardson 		if (!(tc->pmd_mask & target_pmd_mask))
878a9de470cSBruce Richardson 			continue;
879a9de470cSBruce Richardson 
880a9de470cSBruce Richardson 		status = test_blockcipher_one_case(tc, mbuf_pool, op_mpool,
881a9de470cSBruce Richardson 			sess_mpool, sess_priv_mpool, dev_id, driver_id,
882a9de470cSBruce Richardson 			test_msg);
883a9de470cSBruce Richardson 
884a9de470cSBruce Richardson 		printf("  %u) TestCase %s %s\n", test_index ++,
885a9de470cSBruce Richardson 			tc->test_descr, test_msg);
886a9de470cSBruce Richardson 
887a9de470cSBruce Richardson 		if (status != TEST_SUCCESS) {
888a9de470cSBruce Richardson 			if (overall_status == TEST_SUCCESS)
889a9de470cSBruce Richardson 				overall_status = status;
890a9de470cSBruce Richardson 
891a9de470cSBruce Richardson 			if (tc->feature_mask & BLOCKCIPHER_TEST_FEATURE_STOPPER)
892a9de470cSBruce Richardson 				break;
893a9de470cSBruce Richardson 		}
894a9de470cSBruce Richardson 	}
895a9de470cSBruce Richardson 
896a9de470cSBruce Richardson 	return overall_status;
897a9de470cSBruce Richardson }
898