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
24a9de470cSBruce Richardson test_blockcipher_one_case(const struct blockcipher_test_case *t,
25a9de470cSBruce Richardson 	struct rte_mempool *mbuf_pool,
26a9de470cSBruce Richardson 	struct rte_mempool *op_mpool,
27a9de470cSBruce Richardson 	struct rte_mempool *sess_mpool,
28a9de470cSBruce Richardson 	struct rte_mempool *sess_priv_mpool,
29a9de470cSBruce Richardson 	uint8_t dev_id,
30a9de470cSBruce Richardson 	int driver_id,
31a9de470cSBruce Richardson 	char *test_msg)
32a9de470cSBruce Richardson {
33a9de470cSBruce Richardson 	struct rte_mbuf *ibuf = NULL;
34a9de470cSBruce Richardson 	struct rte_mbuf *obuf = NULL;
35a9de470cSBruce Richardson 	struct rte_mbuf *iobuf;
36a9de470cSBruce Richardson 	struct rte_crypto_sym_xform *cipher_xform = NULL;
37a9de470cSBruce Richardson 	struct rte_crypto_sym_xform *auth_xform = NULL;
38a9de470cSBruce Richardson 	struct rte_crypto_sym_xform *init_xform = NULL;
39a9de470cSBruce Richardson 	struct rte_crypto_sym_op *sym_op = NULL;
40a9de470cSBruce Richardson 	struct rte_crypto_op *op = NULL;
41a9de470cSBruce Richardson 	struct rte_cryptodev_info dev_info;
42a9de470cSBruce Richardson 	struct rte_cryptodev_sym_session *sess = NULL;
43a9de470cSBruce Richardson 
44a9de470cSBruce Richardson 	int status = TEST_SUCCESS;
45a9de470cSBruce Richardson 	const struct blockcipher_test_data *tdata = t->test_data;
46a9de470cSBruce Richardson 	uint8_t cipher_key[tdata->cipher_key.len];
47a9de470cSBruce Richardson 	uint8_t auth_key[tdata->auth_key.len];
48a9de470cSBruce Richardson 	uint32_t buf_len = tdata->ciphertext.len;
49a9de470cSBruce Richardson 	uint32_t digest_len = 0;
50a9de470cSBruce Richardson 	char *buf_p = NULL;
51a9de470cSBruce Richardson 	uint8_t src_pattern = 0xa5;
52a9de470cSBruce Richardson 	uint8_t dst_pattern = 0xb6;
53a9de470cSBruce Richardson 	uint8_t tmp_src_buf[MBUF_SIZE];
54a9de470cSBruce Richardson 	uint8_t tmp_dst_buf[MBUF_SIZE];
55a9de470cSBruce Richardson 
56a9de470cSBruce Richardson 	int openssl_pmd = rte_cryptodev_driver_id_get(
57a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
58a9de470cSBruce Richardson 	int ccp_pmd = rte_cryptodev_driver_id_get(
59a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_CCP_PMD));
60a9de470cSBruce Richardson 	int scheduler_pmd = rte_cryptodev_driver_id_get(
61a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
62a9de470cSBruce Richardson 	int armv8_pmd = rte_cryptodev_driver_id_get(
63a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
64a9de470cSBruce Richardson 	int aesni_mb_pmd = rte_cryptodev_driver_id_get(
65a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
66a9de470cSBruce Richardson 	int qat_pmd = rte_cryptodev_driver_id_get(
67a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
68a9de470cSBruce Richardson 	int dpaa2_sec_pmd = rte_cryptodev_driver_id_get(
69a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
70a9de470cSBruce Richardson 	int dpaa_sec_pmd = rte_cryptodev_driver_id_get(
71a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
72a9de470cSBruce Richardson 	int caam_jr_pmd = rte_cryptodev_driver_id_get(
73a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
74a9de470cSBruce Richardson 	int mrvl_pmd = rte_cryptodev_driver_id_get(
75a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
76a9de470cSBruce Richardson 	int virtio_pmd = rte_cryptodev_driver_id_get(
77a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
78a9de470cSBruce Richardson 	int octeontx_pmd = rte_cryptodev_driver_id_get(
79a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
80*6995630eSAnoob Joseph 	int octeontx2_pmd = rte_cryptodev_driver_id_get(
81*6995630eSAnoob Joseph 			RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
82af46a0bcSFiona Trahe 	int null_pmd = rte_cryptodev_driver_id_get(
83af46a0bcSFiona Trahe 				RTE_STR(CRYPTODEV_NAME_NULL_PMD));
845adf37e6SNagadheeraj Rottela 	int nitrox_pmd = rte_cryptodev_driver_id_get(
855adf37e6SNagadheeraj Rottela 			RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
86a9de470cSBruce Richardson 
87a9de470cSBruce Richardson 	int nb_segs = 1;
885e73a1f8SFan Zhang 	uint32_t nb_iterates = 0;
89a9de470cSBruce Richardson 
90a9de470cSBruce Richardson 	rte_cryptodev_info_get(dev_id, &dev_info);
91a9de470cSBruce Richardson 
92a9de470cSBruce Richardson 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SG) {
93a9de470cSBruce Richardson 		uint64_t feat_flags = dev_info.feature_flags;
94a9de470cSBruce Richardson 		uint64_t oop_flag = RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT;
95a9de470cSBruce Richardson 
96a9de470cSBruce Richardson 		if (t->feature_mask && BLOCKCIPHER_TEST_FEATURE_OOP) {
97a9de470cSBruce Richardson 			if (!(feat_flags & oop_flag)) {
98a9de470cSBruce Richardson 				printf("Device doesn't support out-of-place "
99a9de470cSBruce Richardson 					"scatter-gather in input mbuf. "
100a9de470cSBruce Richardson 					"Test Skipped.\n");
101a9de470cSBruce Richardson 				return 0;
102a9de470cSBruce Richardson 			}
103a9de470cSBruce Richardson 		} else {
104a9de470cSBruce Richardson 			if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
105a9de470cSBruce Richardson 				printf("Device doesn't support in-place "
106a9de470cSBruce Richardson 					"scatter-gather mbufs. "
107a9de470cSBruce Richardson 					"Test Skipped.\n");
108a9de470cSBruce Richardson 				return 0;
109a9de470cSBruce Richardson 			}
110a9de470cSBruce Richardson 		}
111a9de470cSBruce Richardson 
112a9de470cSBruce Richardson 		nb_segs = 3;
113a9de470cSBruce Richardson 	}
114a9de470cSBruce Richardson 
115a9de470cSBruce Richardson 	if (tdata->cipher_key.len)
116a9de470cSBruce Richardson 		memcpy(cipher_key, tdata->cipher_key.data,
117a9de470cSBruce Richardson 			tdata->cipher_key.len);
118a9de470cSBruce Richardson 	if (tdata->auth_key.len)
119a9de470cSBruce Richardson 		memcpy(auth_key, tdata->auth_key.data,
120a9de470cSBruce Richardson 			tdata->auth_key.len);
121a9de470cSBruce Richardson 
122a9de470cSBruce Richardson 	if (driver_id == dpaa2_sec_pmd ||
123a9de470cSBruce Richardson 			driver_id == dpaa_sec_pmd ||
124a9de470cSBruce Richardson 			driver_id == caam_jr_pmd ||
125a9de470cSBruce Richardson 			driver_id == qat_pmd ||
126a9de470cSBruce Richardson 			driver_id == openssl_pmd ||
127a9de470cSBruce Richardson 			driver_id == armv8_pmd ||
128a9de470cSBruce Richardson 			driver_id == mrvl_pmd ||
129a9de470cSBruce Richardson 			driver_id == ccp_pmd ||
130a9de470cSBruce Richardson 			driver_id == virtio_pmd ||
131af46a0bcSFiona Trahe 			driver_id == octeontx_pmd ||
132*6995630eSAnoob Joseph 			driver_id == octeontx2_pmd ||
1335adf37e6SNagadheeraj Rottela 			driver_id == null_pmd ||
1345adf37e6SNagadheeraj Rottela 			driver_id == nitrox_pmd) { /* Fall through */
135a9de470cSBruce Richardson 		digest_len = tdata->digest.len;
136a9de470cSBruce Richardson 	} else if (driver_id == aesni_mb_pmd ||
137a9de470cSBruce Richardson 			driver_id == scheduler_pmd) {
138a9de470cSBruce Richardson 		digest_len = tdata->digest.truncated_len;
139a9de470cSBruce Richardson 	} else {
140a9de470cSBruce Richardson 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
141a9de470cSBruce Richardson 			"line %u FAILED: %s",
142a9de470cSBruce Richardson 			__LINE__, "Unsupported PMD type");
143a9de470cSBruce Richardson 		status = TEST_FAILED;
144a9de470cSBruce Richardson 		goto error_exit;
145a9de470cSBruce Richardson 	}
146a9de470cSBruce Richardson 
147a9de470cSBruce Richardson 	/* preparing data */
148a9de470cSBruce Richardson 	if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH)
149a9de470cSBruce Richardson 		buf_len += digest_len;
150a9de470cSBruce Richardson 
151a9de470cSBruce Richardson 	/* for contiguous mbuf, nb_segs is 1 */
152a9de470cSBruce Richardson 	ibuf = create_segmented_mbuf(mbuf_pool,
153a9de470cSBruce Richardson 			tdata->ciphertext.len, nb_segs, src_pattern);
154a9de470cSBruce Richardson 	if (ibuf == NULL) {
155a9de470cSBruce Richardson 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
156a9de470cSBruce Richardson 			"line %u FAILED: %s",
157a9de470cSBruce Richardson 			__LINE__, "Cannot create source mbuf");
158a9de470cSBruce Richardson 		status = TEST_FAILED;
159a9de470cSBruce Richardson 		goto error_exit;
160a9de470cSBruce Richardson 	}
161a9de470cSBruce Richardson 
162a9de470cSBruce Richardson 	/* only encryption requires plaintext.data input,
163a9de470cSBruce Richardson 	 * decryption/(digest gen)/(digest verify) use ciphertext.data
164a9de470cSBruce Richardson 	 * to be computed
165a9de470cSBruce Richardson 	 */
166a9de470cSBruce Richardson 	if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT)
167a9de470cSBruce Richardson 		pktmbuf_write(ibuf, 0, tdata->plaintext.len,
168a9de470cSBruce Richardson 				tdata->plaintext.data);
169a9de470cSBruce Richardson 	else
170a9de470cSBruce Richardson 		pktmbuf_write(ibuf, 0, tdata->ciphertext.len,
171a9de470cSBruce Richardson 				tdata->ciphertext.data);
172a9de470cSBruce Richardson 
173a9de470cSBruce Richardson 	buf_p = rte_pktmbuf_append(ibuf, digest_len);
174a9de470cSBruce Richardson 	if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY)
175a9de470cSBruce Richardson 		rte_memcpy(buf_p, tdata->digest.data, digest_len);
176a9de470cSBruce Richardson 	else
177a9de470cSBruce Richardson 		memset(buf_p, 0, digest_len);
178a9de470cSBruce Richardson 
179a9de470cSBruce Richardson 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
180a9de470cSBruce Richardson 		obuf = rte_pktmbuf_alloc(mbuf_pool);
181a9de470cSBruce Richardson 		if (!obuf) {
182a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
183a9de470cSBruce Richardson 				"FAILED: %s", __LINE__,
184a9de470cSBruce Richardson 				"Allocation of rte_mbuf failed");
185a9de470cSBruce Richardson 			status = TEST_FAILED;
186a9de470cSBruce Richardson 			goto error_exit;
187a9de470cSBruce Richardson 		}
188a9de470cSBruce Richardson 		memset(obuf->buf_addr, dst_pattern, obuf->buf_len);
189a9de470cSBruce Richardson 
190a9de470cSBruce Richardson 		buf_p = rte_pktmbuf_append(obuf, buf_len);
191a9de470cSBruce Richardson 		if (!buf_p) {
192a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
193a9de470cSBruce Richardson 				"FAILED: %s", __LINE__,
194a9de470cSBruce Richardson 				"No room to append mbuf");
195a9de470cSBruce Richardson 			status = TEST_FAILED;
196a9de470cSBruce Richardson 			goto error_exit;
197a9de470cSBruce Richardson 		}
198a9de470cSBruce Richardson 		memset(buf_p, 0, buf_len);
199a9de470cSBruce Richardson 	}
200a9de470cSBruce Richardson 
201a9de470cSBruce Richardson 	/* Generate Crypto op data structure */
202a9de470cSBruce Richardson 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_SYMMETRIC);
203a9de470cSBruce Richardson 	if (!op) {
204a9de470cSBruce Richardson 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
205a9de470cSBruce Richardson 			"line %u FAILED: %s",
206a9de470cSBruce Richardson 			__LINE__, "Failed to allocate symmetric crypto "
207a9de470cSBruce Richardson 			"operation struct");
208a9de470cSBruce Richardson 		status = TEST_FAILED;
209a9de470cSBruce Richardson 		goto error_exit;
210a9de470cSBruce Richardson 	}
211a9de470cSBruce Richardson 
212a9de470cSBruce Richardson 	sym_op = op->sym;
213a9de470cSBruce Richardson 
2145e73a1f8SFan Zhang iterate:
2155e73a1f8SFan Zhang 	if (nb_iterates) {
2165e73a1f8SFan Zhang 		struct rte_mbuf *tmp_buf = ibuf;
2175e73a1f8SFan Zhang 
2185e73a1f8SFan Zhang 		ibuf = obuf;
2195e73a1f8SFan Zhang 		obuf = tmp_buf;
2205e73a1f8SFan Zhang 
2215e73a1f8SFan Zhang 		rte_pktmbuf_reset(ibuf);
2225e73a1f8SFan Zhang 		rte_pktmbuf_reset(obuf);
2235e73a1f8SFan Zhang 
2245e73a1f8SFan Zhang 		rte_pktmbuf_append(ibuf, tdata->ciphertext.len);
2255e73a1f8SFan Zhang 
2265e73a1f8SFan Zhang 		/* only encryption requires plaintext.data input,
2275e73a1f8SFan Zhang 		 * decryption/(digest gen)/(digest verify) use ciphertext.data
2285e73a1f8SFan Zhang 		 * to be computed
2295e73a1f8SFan Zhang 		 */
2305e73a1f8SFan Zhang 		if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT)
2315e73a1f8SFan Zhang 			pktmbuf_write(ibuf, 0, tdata->plaintext.len,
2325e73a1f8SFan Zhang 					tdata->plaintext.data);
2335e73a1f8SFan Zhang 		else
2345e73a1f8SFan Zhang 			pktmbuf_write(ibuf, 0, tdata->ciphertext.len,
2355e73a1f8SFan Zhang 					tdata->ciphertext.data);
2365e73a1f8SFan Zhang 
2375e73a1f8SFan Zhang 		buf_p = rte_pktmbuf_append(ibuf, digest_len);
2385e73a1f8SFan Zhang 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY)
2395e73a1f8SFan Zhang 			rte_memcpy(buf_p, tdata->digest.data, digest_len);
2405e73a1f8SFan Zhang 		else
2415e73a1f8SFan Zhang 			memset(buf_p, 0, digest_len);
2425e73a1f8SFan Zhang 
2435e73a1f8SFan Zhang 		memset(obuf->buf_addr, dst_pattern, obuf->buf_len);
2445e73a1f8SFan Zhang 
2455e73a1f8SFan Zhang 		buf_p = rte_pktmbuf_append(obuf, buf_len);
2465e73a1f8SFan Zhang 		if (!buf_p) {
2475e73a1f8SFan Zhang 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
2485e73a1f8SFan Zhang 				"FAILED: %s", __LINE__,
2495e73a1f8SFan Zhang 				"No room to append mbuf");
2505e73a1f8SFan Zhang 			status = TEST_FAILED;
2515e73a1f8SFan Zhang 			goto error_exit;
2525e73a1f8SFan Zhang 		}
2535e73a1f8SFan Zhang 		memset(buf_p, 0, buf_len);
2545e73a1f8SFan Zhang 	}
2555e73a1f8SFan Zhang 
256a9de470cSBruce Richardson 	sym_op->m_src = ibuf;
257a9de470cSBruce Richardson 
258a9de470cSBruce Richardson 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
259a9de470cSBruce Richardson 		sym_op->m_dst = obuf;
260a9de470cSBruce Richardson 		iobuf = obuf;
261a9de470cSBruce Richardson 	} else {
262a9de470cSBruce Richardson 		sym_op->m_dst = NULL;
263a9de470cSBruce Richardson 		iobuf = ibuf;
264a9de470cSBruce Richardson 	}
265a9de470cSBruce Richardson 
266a9de470cSBruce Richardson 	/* sessionless op requires allocate xform using
267a9de470cSBruce Richardson 	 * rte_crypto_op_sym_xforms_alloc(), otherwise rte_zmalloc()
268a9de470cSBruce Richardson 	 * is used
269a9de470cSBruce Richardson 	 */
270a9de470cSBruce Richardson 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
271a9de470cSBruce Richardson 		uint32_t n_xforms = 0;
272a9de470cSBruce Richardson 
273a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER)
274a9de470cSBruce Richardson 			n_xforms++;
275a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH)
276a9de470cSBruce Richardson 			n_xforms++;
277a9de470cSBruce Richardson 
278a9de470cSBruce Richardson 		if (rte_crypto_op_sym_xforms_alloc(op, n_xforms)
279a9de470cSBruce Richardson 			== NULL) {
280a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
281a9de470cSBruce Richardson 				"FAILED: %s", __LINE__, "Failed to "
282a9de470cSBruce Richardson 				"allocate space for crypto transforms");
283a9de470cSBruce Richardson 			status = TEST_FAILED;
284a9de470cSBruce Richardson 			goto error_exit;
285a9de470cSBruce Richardson 		}
286a9de470cSBruce Richardson 	} else {
287a9de470cSBruce Richardson 		cipher_xform = rte_zmalloc(NULL,
288a9de470cSBruce Richardson 			sizeof(struct rte_crypto_sym_xform), 0);
289a9de470cSBruce Richardson 
290a9de470cSBruce Richardson 		auth_xform = rte_zmalloc(NULL,
291a9de470cSBruce Richardson 			sizeof(struct rte_crypto_sym_xform), 0);
292a9de470cSBruce Richardson 
293a9de470cSBruce Richardson 		if (!cipher_xform || !auth_xform) {
294a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
295a9de470cSBruce Richardson 				"FAILED: %s", __LINE__, "Failed to "
296a9de470cSBruce Richardson 				"allocate memory for crypto transforms");
297a9de470cSBruce Richardson 			status = TEST_FAILED;
298a9de470cSBruce Richardson 			goto error_exit;
299a9de470cSBruce Richardson 		}
300a9de470cSBruce Richardson 	}
301a9de470cSBruce Richardson 
302a9de470cSBruce Richardson 	/* preparing xform, for sessioned op, init_xform is initialized
303a9de470cSBruce Richardson 	 * here and later as param in rte_cryptodev_sym_session_create() call
304a9de470cSBruce Richardson 	 */
305a9de470cSBruce Richardson 	if (t->op_mask == BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN) {
306a9de470cSBruce Richardson 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
307a9de470cSBruce Richardson 			cipher_xform = op->sym->xform;
308a9de470cSBruce Richardson 			auth_xform = cipher_xform->next;
309a9de470cSBruce Richardson 			auth_xform->next = NULL;
310a9de470cSBruce Richardson 		} else {
311a9de470cSBruce Richardson 			cipher_xform->next = auth_xform;
312a9de470cSBruce Richardson 			auth_xform->next = NULL;
313a9de470cSBruce Richardson 			init_xform = cipher_xform;
314a9de470cSBruce Richardson 		}
315a9de470cSBruce Richardson 	} else if (t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC) {
316a9de470cSBruce Richardson 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
317a9de470cSBruce Richardson 			auth_xform = op->sym->xform;
318a9de470cSBruce Richardson 			cipher_xform = auth_xform->next;
319a9de470cSBruce Richardson 			cipher_xform->next = NULL;
320a9de470cSBruce Richardson 		} else {
321a9de470cSBruce Richardson 			auth_xform->next = cipher_xform;
322a9de470cSBruce Richardson 			cipher_xform->next = NULL;
323a9de470cSBruce Richardson 			init_xform = auth_xform;
324a9de470cSBruce Richardson 		}
325a9de470cSBruce Richardson 	} else if ((t->op_mask == BLOCKCIPHER_TEST_OP_ENCRYPT) ||
326a9de470cSBruce Richardson 			(t->op_mask == BLOCKCIPHER_TEST_OP_DECRYPT)) {
327a9de470cSBruce Richardson 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)
328a9de470cSBruce Richardson 			cipher_xform = op->sym->xform;
329a9de470cSBruce Richardson 		else
330a9de470cSBruce Richardson 			init_xform = cipher_xform;
331a9de470cSBruce Richardson 		cipher_xform->next = NULL;
332a9de470cSBruce Richardson 	} else if ((t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_GEN) ||
333a9de470cSBruce Richardson 			(t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_VERIFY)) {
334a9de470cSBruce Richardson 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)
335a9de470cSBruce Richardson 			auth_xform = op->sym->xform;
336a9de470cSBruce Richardson 		else
337a9de470cSBruce Richardson 			init_xform = auth_xform;
338a9de470cSBruce Richardson 		auth_xform->next = NULL;
339a9de470cSBruce Richardson 	} else {
340a9de470cSBruce Richardson 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
341a9de470cSBruce Richardson 			"line %u FAILED: %s",
342a9de470cSBruce Richardson 			__LINE__, "Unrecognized operation");
343a9de470cSBruce Richardson 		status = TEST_FAILED;
344a9de470cSBruce Richardson 		goto error_exit;
345a9de470cSBruce Richardson 	}
346a9de470cSBruce Richardson 
347a9de470cSBruce Richardson 	/*configure xforms & sym_op cipher and auth data*/
348a9de470cSBruce Richardson 	if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
349a9de470cSBruce Richardson 		cipher_xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
350a9de470cSBruce Richardson 		cipher_xform->cipher.algo = tdata->crypto_algo;
351a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT)
352a9de470cSBruce Richardson 			cipher_xform->cipher.op =
353a9de470cSBruce Richardson 				RTE_CRYPTO_CIPHER_OP_ENCRYPT;
354a9de470cSBruce Richardson 		else
355a9de470cSBruce Richardson 			cipher_xform->cipher.op =
356a9de470cSBruce Richardson 				RTE_CRYPTO_CIPHER_OP_DECRYPT;
357a9de470cSBruce Richardson 		cipher_xform->cipher.key.data = cipher_key;
358a9de470cSBruce Richardson 		cipher_xform->cipher.key.length = tdata->cipher_key.len;
359a9de470cSBruce Richardson 		cipher_xform->cipher.iv.offset = IV_OFFSET;
360a9de470cSBruce Richardson 		cipher_xform->cipher.iv.length = tdata->iv.len;
361a9de470cSBruce Richardson 
3625e73a1f8SFan Zhang 		sym_op->cipher.data.offset = tdata->cipher_offset;
3635e73a1f8SFan Zhang 		sym_op->cipher.data.length = tdata->ciphertext.len -
3645e73a1f8SFan Zhang 				tdata->cipher_offset;
365a9de470cSBruce Richardson 		rte_memcpy(rte_crypto_op_ctod_offset(op, uint8_t *, IV_OFFSET),
366a9de470cSBruce Richardson 				tdata->iv.data,
367a9de470cSBruce Richardson 				tdata->iv.len);
368a9de470cSBruce Richardson 	}
369a9de470cSBruce Richardson 
370a9de470cSBruce Richardson 	if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) {
371a9de470cSBruce Richardson 		uint32_t digest_offset = tdata->ciphertext.len;
372a9de470cSBruce Richardson 
373a9de470cSBruce Richardson 		auth_xform->type = RTE_CRYPTO_SYM_XFORM_AUTH;
374a9de470cSBruce Richardson 		auth_xform->auth.algo = tdata->auth_algo;
375a9de470cSBruce Richardson 		auth_xform->auth.key.length = tdata->auth_key.len;
376a9de470cSBruce Richardson 		auth_xform->auth.key.data = auth_key;
377a9de470cSBruce Richardson 		auth_xform->auth.digest_length = digest_len;
378a9de470cSBruce Richardson 
379a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) {
380a9de470cSBruce Richardson 			auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
381a9de470cSBruce Richardson 			sym_op->auth.digest.data = pktmbuf_mtod_offset
382a9de470cSBruce Richardson 				(iobuf, digest_offset);
383a9de470cSBruce Richardson 			sym_op->auth.digest.phys_addr =
384a9de470cSBruce Richardson 				pktmbuf_iova_offset(iobuf,
385a9de470cSBruce Richardson 					digest_offset);
386a9de470cSBruce Richardson 		} else {
387a9de470cSBruce Richardson 			auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
388a9de470cSBruce Richardson 			sym_op->auth.digest.data = pktmbuf_mtod_offset
389a9de470cSBruce Richardson 				(sym_op->m_src, digest_offset);
390a9de470cSBruce Richardson 			sym_op->auth.digest.phys_addr =
391a9de470cSBruce Richardson 				pktmbuf_iova_offset(sym_op->m_src,
392a9de470cSBruce Richardson 					digest_offset);
393a9de470cSBruce Richardson 		}
394a9de470cSBruce Richardson 
3955e73a1f8SFan Zhang 		sym_op->auth.data.offset = tdata->auth_offset;
3965e73a1f8SFan Zhang 		sym_op->auth.data.length = tdata->ciphertext.len -
3975e73a1f8SFan Zhang 				tdata->auth_offset;
398a9de470cSBruce Richardson 	}
399a9de470cSBruce Richardson 
4005e73a1f8SFan Zhang 	/**
4015e73a1f8SFan Zhang 	 * Create session for sessioned op. For mbuf iteration test,
4025e73a1f8SFan Zhang 	 * skip the session creation for the second iteration.
4035e73a1f8SFan Zhang 	 */
4045e73a1f8SFan Zhang 	if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) &&
4055e73a1f8SFan Zhang 			nb_iterates == 0) {
406a9de470cSBruce Richardson 		sess = rte_cryptodev_sym_session_create(sess_mpool);
407a9de470cSBruce Richardson 
408a9de470cSBruce Richardson 		rte_cryptodev_sym_session_init(dev_id, sess, init_xform,
409a9de470cSBruce Richardson 				sess_priv_mpool);
410a9de470cSBruce Richardson 		if (!sess) {
411a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
412a9de470cSBruce Richardson 				"FAILED: %s", __LINE__,
413a9de470cSBruce Richardson 				"Session creation failed");
414a9de470cSBruce Richardson 			status = TEST_FAILED;
415a9de470cSBruce Richardson 			goto error_exit;
416a9de470cSBruce Richardson 		}
417a9de470cSBruce Richardson 
418a9de470cSBruce Richardson 		/* attach symmetric crypto session to crypto operations */
419a9de470cSBruce Richardson 		rte_crypto_op_attach_sym_session(op, sess);
420a9de470cSBruce Richardson 	}
421a9de470cSBruce Richardson 
422a9de470cSBruce Richardson 	debug_hexdump(stdout, "m_src(before):",
423a9de470cSBruce Richardson 			sym_op->m_src->buf_addr, sym_op->m_src->buf_len);
424a9de470cSBruce Richardson 	rte_memcpy(tmp_src_buf, sym_op->m_src->buf_addr,
425a9de470cSBruce Richardson 						sym_op->m_src->buf_len);
426a9de470cSBruce Richardson 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
427a9de470cSBruce Richardson 		debug_hexdump(stdout, "m_dst(before):",
428a9de470cSBruce Richardson 			sym_op->m_dst->buf_addr, sym_op->m_dst->buf_len);
429a9de470cSBruce Richardson 		rte_memcpy(tmp_dst_buf, sym_op->m_dst->buf_addr,
430a9de470cSBruce Richardson 						sym_op->m_dst->buf_len);
431a9de470cSBruce Richardson 	}
432a9de470cSBruce Richardson 
433a9de470cSBruce Richardson 	/* Process crypto operation */
434a9de470cSBruce Richardson 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
435a9de470cSBruce Richardson 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
436a9de470cSBruce Richardson 			"line %u FAILED: %s",
437a9de470cSBruce Richardson 			__LINE__, "Error sending packet for encryption");
438a9de470cSBruce Richardson 		status = TEST_FAILED;
439a9de470cSBruce Richardson 		goto error_exit;
440a9de470cSBruce Richardson 	}
441a9de470cSBruce Richardson 
442a9de470cSBruce Richardson 	op = NULL;
443a9de470cSBruce Richardson 
444a9de470cSBruce Richardson 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
445a9de470cSBruce Richardson 		rte_pause();
446a9de470cSBruce Richardson 
447a9de470cSBruce Richardson 	if (!op) {
448a9de470cSBruce Richardson 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
449a9de470cSBruce Richardson 			"line %u FAILED: %s",
450a9de470cSBruce Richardson 			__LINE__, "Failed to process sym crypto op");
451a9de470cSBruce Richardson 		status = TEST_FAILED;
452a9de470cSBruce Richardson 		goto error_exit;
453a9de470cSBruce Richardson 	}
454a9de470cSBruce Richardson 
455a9de470cSBruce Richardson 	debug_hexdump(stdout, "m_src(after):",
456a9de470cSBruce Richardson 			sym_op->m_src->buf_addr, sym_op->m_src->buf_len);
457a9de470cSBruce Richardson 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP)
458a9de470cSBruce Richardson 		debug_hexdump(stdout, "m_dst(after):",
459a9de470cSBruce Richardson 			sym_op->m_dst->buf_addr, sym_op->m_dst->buf_len);
460a9de470cSBruce Richardson 
461a9de470cSBruce Richardson 	/* Verify results */
462a9de470cSBruce Richardson 	if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
463a9de470cSBruce Richardson 		if ((t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY) &&
464a9de470cSBruce Richardson 			(op->status == RTE_CRYPTO_OP_STATUS_AUTH_FAILED))
465a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
466a9de470cSBruce Richardson 				"FAILED: Digest verification failed "
467a9de470cSBruce Richardson 				"(0x%X)", __LINE__, op->status);
468a9de470cSBruce Richardson 		else
469a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
470a9de470cSBruce Richardson 				"FAILED: Operation failed "
471a9de470cSBruce Richardson 				"(0x%X)", __LINE__, op->status);
472a9de470cSBruce Richardson 		status = TEST_FAILED;
473a9de470cSBruce Richardson 		goto error_exit;
474a9de470cSBruce Richardson 	}
475a9de470cSBruce Richardson 
476a9de470cSBruce Richardson 	if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
477a9de470cSBruce Richardson 		uint8_t buffer[2048];
478a9de470cSBruce Richardson 		const uint8_t *compare_ref;
479a9de470cSBruce Richardson 		uint32_t compare_len;
480a9de470cSBruce Richardson 
481a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT) {
4825e73a1f8SFan Zhang 			compare_ref = tdata->ciphertext.data +
4835e73a1f8SFan Zhang 					tdata->cipher_offset;
4845e73a1f8SFan Zhang 			compare_len = tdata->ciphertext.len -
4855e73a1f8SFan Zhang 					tdata->cipher_offset;
486a9de470cSBruce Richardson 		} else {
4875e73a1f8SFan Zhang 			compare_ref = tdata->plaintext.data +
4885e73a1f8SFan Zhang 					tdata->cipher_offset;
4895e73a1f8SFan Zhang 			compare_len = tdata->plaintext.len -
4905e73a1f8SFan Zhang 					tdata->cipher_offset;
491a9de470cSBruce Richardson 		}
492a9de470cSBruce Richardson 
4935e73a1f8SFan Zhang 		if (memcmp(rte_pktmbuf_read(iobuf, tdata->cipher_offset,
4945e73a1f8SFan Zhang 				compare_len, buffer), compare_ref,
4955e73a1f8SFan Zhang 				compare_len)) {
496a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
497a9de470cSBruce Richardson 				"FAILED: %s", __LINE__,
498a9de470cSBruce Richardson 				"Crypto data not as expected");
499a9de470cSBruce Richardson 			status = TEST_FAILED;
500a9de470cSBruce Richardson 			goto error_exit;
501a9de470cSBruce Richardson 		}
502a9de470cSBruce Richardson 	}
503a9de470cSBruce Richardson 
504a9de470cSBruce Richardson 	if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) {
505a9de470cSBruce Richardson 		uint8_t *auth_res = pktmbuf_mtod_offset(iobuf,
506a9de470cSBruce Richardson 					tdata->ciphertext.len);
507a9de470cSBruce Richardson 
508a9de470cSBruce Richardson 		if (memcmp(auth_res, tdata->digest.data, digest_len)) {
509a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
510a9de470cSBruce Richardson 				"FAILED: %s", __LINE__, "Generated "
511a9de470cSBruce Richardson 				"digest data not as expected");
512a9de470cSBruce Richardson 			status = TEST_FAILED;
513a9de470cSBruce Richardson 			goto error_exit;
514a9de470cSBruce Richardson 		}
515a9de470cSBruce Richardson 	}
516a9de470cSBruce Richardson 
517a9de470cSBruce Richardson 	/* The only parts that should have changed in the buffer are
518a9de470cSBruce Richardson 	 * plaintext/ciphertext and digest.
519a9de470cSBruce Richardson 	 * In OOP only the dest buffer should change.
520a9de470cSBruce Richardson 	 */
521a9de470cSBruce Richardson 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
522a9de470cSBruce Richardson 		struct rte_mbuf *mbuf;
523a9de470cSBruce Richardson 		uint8_t value;
524a9de470cSBruce Richardson 		uint32_t head_unchanged_len, changed_len = 0;
525a9de470cSBruce Richardson 		uint32_t i;
526a9de470cSBruce Richardson 		uint32_t hdroom_used = 0, tlroom_used = 0;
527a9de470cSBruce Richardson 		uint32_t hdroom = 0;
528a9de470cSBruce Richardson 
529a9de470cSBruce Richardson 		mbuf = sym_op->m_src;
530a9de470cSBruce Richardson 		/*
531a9de470cSBruce Richardson 		 * Crypto PMDs specify the headroom & tailroom it would use
532a9de470cSBruce Richardson 		 * when processing the crypto operation. PMD is free to modify
533a9de470cSBruce Richardson 		 * this space, and so the verification check should skip that
534a9de470cSBruce Richardson 		 * block.
535a9de470cSBruce Richardson 		 */
536a9de470cSBruce Richardson 		hdroom_used = dev_info.min_mbuf_headroom_req;
537a9de470cSBruce Richardson 		tlroom_used = dev_info.min_mbuf_tailroom_req;
538a9de470cSBruce Richardson 
539a9de470cSBruce Richardson 		/* Get headroom */
540a9de470cSBruce Richardson 		hdroom = rte_pktmbuf_headroom(mbuf);
541a9de470cSBruce Richardson 
542a9de470cSBruce Richardson 		head_unchanged_len = mbuf->buf_len;
543a9de470cSBruce Richardson 
544a9de470cSBruce Richardson 		for (i = 0; i < mbuf->buf_len; i++) {
545a9de470cSBruce Richardson 
546a9de470cSBruce Richardson 			/* Skip headroom used by PMD */
547a9de470cSBruce Richardson 			if (i == hdroom - hdroom_used)
548a9de470cSBruce Richardson 				i += hdroom_used;
549a9de470cSBruce Richardson 
550a9de470cSBruce Richardson 			/* Skip tailroom used by PMD */
551a9de470cSBruce Richardson 			if (i == (hdroom + mbuf->data_len))
552a9de470cSBruce Richardson 				i += tlroom_used;
553a9de470cSBruce Richardson 
554a9de470cSBruce Richardson 			value = *((uint8_t *)(mbuf->buf_addr)+i);
555a9de470cSBruce Richardson 			if (value != tmp_src_buf[i]) {
556a9de470cSBruce Richardson 				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
557a9de470cSBruce Richardson 	"line %u FAILED: OOP src outer mbuf data (0x%x) not as expected (0x%x)",
558a9de470cSBruce Richardson 					__LINE__, value, tmp_src_buf[i]);
559a9de470cSBruce Richardson 				status = TEST_FAILED;
560a9de470cSBruce Richardson 				goto error_exit;
561a9de470cSBruce Richardson 			}
562a9de470cSBruce Richardson 		}
563a9de470cSBruce Richardson 
564a9de470cSBruce Richardson 		mbuf = sym_op->m_dst;
565a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) {
566a9de470cSBruce Richardson 			head_unchanged_len = hdroom + sym_op->auth.data.offset;
567a9de470cSBruce Richardson 			changed_len = sym_op->auth.data.length;
568a9de470cSBruce Richardson 			if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN)
569a9de470cSBruce Richardson 				changed_len += digest_len;
570a9de470cSBruce Richardson 		} else {
571a9de470cSBruce Richardson 			/* cipher-only */
572a9de470cSBruce Richardson 			head_unchanged_len = hdroom +
573a9de470cSBruce Richardson 					sym_op->cipher.data.offset;
574a9de470cSBruce Richardson 			changed_len = sym_op->cipher.data.length;
575a9de470cSBruce Richardson 		}
576a9de470cSBruce Richardson 
577a9de470cSBruce Richardson 		for (i = 0; i < mbuf->buf_len; i++) {
578a9de470cSBruce Richardson 			if (i == head_unchanged_len)
579a9de470cSBruce Richardson 				i += changed_len;
580a9de470cSBruce Richardson 			value = *((uint8_t *)(mbuf->buf_addr)+i);
581a9de470cSBruce Richardson 			if (value != tmp_dst_buf[i]) {
582a9de470cSBruce Richardson 				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
583a9de470cSBruce Richardson 				"line %u FAILED: OOP dst outer mbuf data "
584a9de470cSBruce Richardson 				"(0x%x) not as expected (0x%x)",
585a9de470cSBruce Richardson 				__LINE__, value, tmp_dst_buf[i]);
586a9de470cSBruce Richardson 				status = TEST_FAILED;
587a9de470cSBruce Richardson 				goto error_exit;
588a9de470cSBruce Richardson 			}
589a9de470cSBruce Richardson 		}
5905e73a1f8SFan Zhang 
5915e73a1f8SFan Zhang 		if (!nb_iterates) {
5925e73a1f8SFan Zhang 			nb_iterates++;
5935e73a1f8SFan Zhang 			goto iterate;
5945e73a1f8SFan Zhang 		}
595a9de470cSBruce Richardson 	} else {
596a9de470cSBruce Richardson 		/* In-place operation */
597a9de470cSBruce Richardson 		struct rte_mbuf *mbuf;
598a9de470cSBruce Richardson 		uint8_t value;
599a9de470cSBruce Richardson 		uint32_t head_unchanged_len = 0, changed_len = 0;
600a9de470cSBruce Richardson 		uint32_t i;
601a9de470cSBruce Richardson 		uint32_t hdroom_used = 0, tlroom_used = 0;
602a9de470cSBruce Richardson 		uint32_t hdroom = 0;
603a9de470cSBruce Richardson 
604a9de470cSBruce Richardson 		/*
605a9de470cSBruce Richardson 		 * Crypto PMDs specify the headroom & tailroom it would use
606a9de470cSBruce Richardson 		 * when processing the crypto operation. PMD is free to modify
607a9de470cSBruce Richardson 		 * this space, and so the verification check should skip that
608a9de470cSBruce Richardson 		 * block.
609a9de470cSBruce Richardson 		 */
610a9de470cSBruce Richardson 		hdroom_used = dev_info.min_mbuf_headroom_req;
611a9de470cSBruce Richardson 		tlroom_used = dev_info.min_mbuf_tailroom_req;
612a9de470cSBruce Richardson 
613a9de470cSBruce Richardson 		mbuf = sym_op->m_src;
614a9de470cSBruce Richardson 
615a9de470cSBruce Richardson 		/* Get headroom */
616a9de470cSBruce Richardson 		hdroom = rte_pktmbuf_headroom(mbuf);
617a9de470cSBruce Richardson 
618a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
619a9de470cSBruce Richardson 			head_unchanged_len = hdroom +
620a9de470cSBruce Richardson 					sym_op->cipher.data.offset;
621a9de470cSBruce Richardson 			changed_len = sym_op->cipher.data.length;
622a9de470cSBruce Richardson 		} else {
623a9de470cSBruce Richardson 			/* auth-only */
624a9de470cSBruce Richardson 			head_unchanged_len = hdroom +
625a9de470cSBruce Richardson 					sym_op->auth.data.offset +
626a9de470cSBruce Richardson 					sym_op->auth.data.length;
627a9de470cSBruce Richardson 			changed_len = 0;
628a9de470cSBruce Richardson 		}
629a9de470cSBruce Richardson 
630a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN)
631a9de470cSBruce Richardson 			changed_len += digest_len;
632a9de470cSBruce Richardson 
633a9de470cSBruce Richardson 		for (i = 0; i < mbuf->buf_len; i++) {
634a9de470cSBruce Richardson 
635a9de470cSBruce Richardson 			/* Skip headroom used by PMD */
636a9de470cSBruce Richardson 			if (i == hdroom - hdroom_used)
637a9de470cSBruce Richardson 				i += hdroom_used;
638a9de470cSBruce Richardson 
639a9de470cSBruce Richardson 			if (i == head_unchanged_len)
640a9de470cSBruce Richardson 				i += changed_len;
641a9de470cSBruce Richardson 
642a9de470cSBruce Richardson 			/* Skip tailroom used by PMD */
643a9de470cSBruce Richardson 			if (i == (hdroom + mbuf->data_len))
644a9de470cSBruce Richardson 				i += tlroom_used;
645a9de470cSBruce Richardson 
646a9de470cSBruce Richardson 			value = *((uint8_t *)(mbuf->buf_addr)+i);
647a9de470cSBruce Richardson 			if (value != tmp_src_buf[i]) {
648a9de470cSBruce Richardson 				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
649a9de470cSBruce Richardson 				"line %u FAILED: outer mbuf data (0x%x) "
650a9de470cSBruce Richardson 				"not as expected (0x%x)",
651a9de470cSBruce Richardson 				__LINE__, value, tmp_src_buf[i]);
652a9de470cSBruce Richardson 				status = TEST_FAILED;
653a9de470cSBruce Richardson 				goto error_exit;
654a9de470cSBruce Richardson 			}
655a9de470cSBruce Richardson 		}
656a9de470cSBruce Richardson 	}
657a9de470cSBruce Richardson 
658a9de470cSBruce Richardson 	snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "PASS");
659a9de470cSBruce Richardson 
660a9de470cSBruce Richardson error_exit:
661a9de470cSBruce Richardson 	if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)) {
662a9de470cSBruce Richardson 		if (sess) {
663a9de470cSBruce Richardson 			rte_cryptodev_sym_session_clear(dev_id, sess);
664a9de470cSBruce Richardson 			rte_cryptodev_sym_session_free(sess);
665a9de470cSBruce Richardson 		}
666a9de470cSBruce Richardson 		if (cipher_xform)
667a9de470cSBruce Richardson 			rte_free(cipher_xform);
668a9de470cSBruce Richardson 		if (auth_xform)
669a9de470cSBruce Richardson 			rte_free(auth_xform);
670a9de470cSBruce Richardson 	}
671a9de470cSBruce Richardson 
672a9de470cSBruce Richardson 	if (op)
673a9de470cSBruce Richardson 		rte_crypto_op_free(op);
674a9de470cSBruce Richardson 
675a9de470cSBruce Richardson 	if (obuf)
676a9de470cSBruce Richardson 		rte_pktmbuf_free(obuf);
677a9de470cSBruce Richardson 
678a9de470cSBruce Richardson 	if (ibuf)
679a9de470cSBruce Richardson 		rte_pktmbuf_free(ibuf);
680a9de470cSBruce Richardson 
681a9de470cSBruce Richardson 	return status;
682a9de470cSBruce Richardson }
683a9de470cSBruce Richardson 
684a9de470cSBruce Richardson int
685a9de470cSBruce Richardson test_blockcipher_all_tests(struct rte_mempool *mbuf_pool,
686a9de470cSBruce Richardson 	struct rte_mempool *op_mpool,
687a9de470cSBruce Richardson 	struct rte_mempool *sess_mpool,
688a9de470cSBruce Richardson 	struct rte_mempool *sess_priv_mpool,
689a9de470cSBruce Richardson 	uint8_t dev_id,
690a9de470cSBruce Richardson 	int driver_id,
691a9de470cSBruce Richardson 	enum blockcipher_test_type test_type)
692a9de470cSBruce Richardson {
693a9de470cSBruce Richardson 	int status, overall_status = TEST_SUCCESS;
694a9de470cSBruce Richardson 	uint32_t i, test_index = 0;
695a9de470cSBruce Richardson 	char test_msg[BLOCKCIPHER_TEST_MSG_LEN + 1];
696a9de470cSBruce Richardson 	uint32_t n_test_cases = 0;
697a9de470cSBruce Richardson 	uint32_t target_pmd_mask = 0;
698a9de470cSBruce Richardson 	const struct blockcipher_test_case *tcs = NULL;
699a9de470cSBruce Richardson 
700a9de470cSBruce Richardson 	int openssl_pmd = rte_cryptodev_driver_id_get(
701a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
702a9de470cSBruce Richardson 	int ccp_pmd = rte_cryptodev_driver_id_get(
703a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_CCP_PMD));
704a9de470cSBruce Richardson 	int dpaa2_sec_pmd = rte_cryptodev_driver_id_get(
705a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
706a9de470cSBruce Richardson 	int dpaa_sec_pmd = rte_cryptodev_driver_id_get(
707a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
708a9de470cSBruce Richardson 	int caam_jr_pmd = rte_cryptodev_driver_id_get(
709a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
710a9de470cSBruce Richardson 	int scheduler_pmd = rte_cryptodev_driver_id_get(
711a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
712a9de470cSBruce Richardson 	int armv8_pmd = rte_cryptodev_driver_id_get(
713a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
714a9de470cSBruce Richardson 	int aesni_mb_pmd = rte_cryptodev_driver_id_get(
715a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
716a9de470cSBruce Richardson 	int qat_pmd = rte_cryptodev_driver_id_get(
717a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
718a9de470cSBruce Richardson 	int mrvl_pmd = rte_cryptodev_driver_id_get(
719a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
720a9de470cSBruce Richardson 	int virtio_pmd = rte_cryptodev_driver_id_get(
721a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
722a9de470cSBruce Richardson 	int octeontx_pmd = rte_cryptodev_driver_id_get(
723a9de470cSBruce Richardson 			RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
724*6995630eSAnoob Joseph 	int octeontx2_pmd = rte_cryptodev_driver_id_get(
725*6995630eSAnoob Joseph 			RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
726af46a0bcSFiona Trahe 	int null_pmd = rte_cryptodev_driver_id_get(
727af46a0bcSFiona Trahe 				RTE_STR(CRYPTODEV_NAME_NULL_PMD));
7285adf37e6SNagadheeraj Rottela 	int nitrox_pmd = rte_cryptodev_driver_id_get(
7295adf37e6SNagadheeraj Rottela 			RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
730a9de470cSBruce Richardson 
731a9de470cSBruce Richardson 	switch (test_type) {
732a9de470cSBruce Richardson 	case BLKCIPHER_AES_CHAIN_TYPE:
733a9de470cSBruce Richardson 		n_test_cases = sizeof(aes_chain_test_cases) /
734a9de470cSBruce Richardson 		sizeof(aes_chain_test_cases[0]);
735a9de470cSBruce Richardson 		tcs = aes_chain_test_cases;
736a9de470cSBruce Richardson 		break;
737a9de470cSBruce Richardson 	case BLKCIPHER_AES_CIPHERONLY_TYPE:
738a9de470cSBruce Richardson 		n_test_cases = sizeof(aes_cipheronly_test_cases) /
739a9de470cSBruce Richardson 		sizeof(aes_cipheronly_test_cases[0]);
740a9de470cSBruce Richardson 		tcs = aes_cipheronly_test_cases;
741a9de470cSBruce Richardson 		break;
742a9de470cSBruce Richardson 	case BLKCIPHER_AES_DOCSIS_TYPE:
743a9de470cSBruce Richardson 		n_test_cases = sizeof(aes_docsis_test_cases) /
744a9de470cSBruce Richardson 		sizeof(aes_docsis_test_cases[0]);
745a9de470cSBruce Richardson 		tcs = aes_docsis_test_cases;
746a9de470cSBruce Richardson 		break;
747a9de470cSBruce Richardson 	case BLKCIPHER_3DES_CHAIN_TYPE:
748a9de470cSBruce Richardson 		n_test_cases = sizeof(triple_des_chain_test_cases) /
749a9de470cSBruce Richardson 		sizeof(triple_des_chain_test_cases[0]);
750a9de470cSBruce Richardson 		tcs = triple_des_chain_test_cases;
751a9de470cSBruce Richardson 		break;
752a9de470cSBruce Richardson 	case BLKCIPHER_3DES_CIPHERONLY_TYPE:
753a9de470cSBruce Richardson 		n_test_cases = sizeof(triple_des_cipheronly_test_cases) /
754a9de470cSBruce Richardson 		sizeof(triple_des_cipheronly_test_cases[0]);
755a9de470cSBruce Richardson 		tcs = triple_des_cipheronly_test_cases;
756a9de470cSBruce Richardson 		break;
757a9de470cSBruce Richardson 	case BLKCIPHER_DES_CIPHERONLY_TYPE:
758a9de470cSBruce Richardson 		n_test_cases = sizeof(des_cipheronly_test_cases) /
759a9de470cSBruce Richardson 		sizeof(des_cipheronly_test_cases[0]);
760a9de470cSBruce Richardson 		tcs = des_cipheronly_test_cases;
761a9de470cSBruce Richardson 		break;
762a9de470cSBruce Richardson 	case BLKCIPHER_DES_DOCSIS_TYPE:
763a9de470cSBruce Richardson 		n_test_cases = sizeof(des_docsis_test_cases) /
764a9de470cSBruce Richardson 		sizeof(des_docsis_test_cases[0]);
765a9de470cSBruce Richardson 		tcs = des_docsis_test_cases;
766a9de470cSBruce Richardson 		break;
767a9de470cSBruce Richardson 	case BLKCIPHER_AUTHONLY_TYPE:
768a9de470cSBruce Richardson 		n_test_cases = sizeof(hash_test_cases) /
769a9de470cSBruce Richardson 		sizeof(hash_test_cases[0]);
770a9de470cSBruce Richardson 		tcs = hash_test_cases;
771a9de470cSBruce Richardson 		break;
772a9de470cSBruce Richardson 	default:
773a9de470cSBruce Richardson 		break;
774a9de470cSBruce Richardson 	}
775a9de470cSBruce Richardson 
776a9de470cSBruce Richardson 	if (driver_id == aesni_mb_pmd)
777a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_MB;
778a9de470cSBruce Richardson 	else if (driver_id == qat_pmd)
779a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_QAT;
780a9de470cSBruce Richardson 	else if (driver_id == openssl_pmd)
781a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_OPENSSL;
782a9de470cSBruce Richardson 	else if (driver_id == armv8_pmd)
783a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_ARMV8;
784a9de470cSBruce Richardson 	else if (driver_id == scheduler_pmd)
785a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER;
786a9de470cSBruce Richardson 	else if (driver_id == dpaa2_sec_pmd)
787a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC;
788a9de470cSBruce Richardson 	else if (driver_id == ccp_pmd)
789a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_CCP;
790a9de470cSBruce Richardson 	else if (driver_id == dpaa_sec_pmd)
791a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_DPAA_SEC;
792a9de470cSBruce Richardson 	else if (driver_id == caam_jr_pmd)
793a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_CAAM_JR;
794a9de470cSBruce Richardson 	else if (driver_id == mrvl_pmd)
795a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_MVSAM;
796a9de470cSBruce Richardson 	else if (driver_id == virtio_pmd)
797a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_VIRTIO;
798a9de470cSBruce Richardson 	else if (driver_id == octeontx_pmd)
799a9de470cSBruce Richardson 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_OCTEONTX;
800*6995630eSAnoob Joseph 	else if (driver_id == octeontx2_pmd)
801*6995630eSAnoob Joseph 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_OCTEONTX2;
802af46a0bcSFiona Trahe 	else if (driver_id == null_pmd)
803af46a0bcSFiona Trahe 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_NULL;
8045adf37e6SNagadheeraj Rottela 	else if (driver_id == nitrox_pmd)
8055adf37e6SNagadheeraj Rottela 		target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_NITROX;
806a9de470cSBruce Richardson 	else
807a9de470cSBruce Richardson 		TEST_ASSERT(0, "Unrecognized cryptodev type");
808a9de470cSBruce Richardson 
809a9de470cSBruce Richardson 	for (i = 0; i < n_test_cases; i++) {
810a9de470cSBruce Richardson 		const struct blockcipher_test_case *tc = &tcs[i];
811a9de470cSBruce Richardson 
812a9de470cSBruce Richardson 		if (!(tc->pmd_mask & target_pmd_mask))
813a9de470cSBruce Richardson 			continue;
814a9de470cSBruce Richardson 
815a9de470cSBruce Richardson 		status = test_blockcipher_one_case(tc, mbuf_pool, op_mpool,
816a9de470cSBruce Richardson 			sess_mpool, sess_priv_mpool, dev_id, driver_id,
817a9de470cSBruce Richardson 			test_msg);
818a9de470cSBruce Richardson 
819a9de470cSBruce Richardson 		printf("  %u) TestCase %s %s\n", test_index ++,
820a9de470cSBruce Richardson 			tc->test_descr, test_msg);
821a9de470cSBruce Richardson 
822a9de470cSBruce Richardson 		if (status != TEST_SUCCESS) {
823a9de470cSBruce Richardson 			if (overall_status == TEST_SUCCESS)
824a9de470cSBruce Richardson 				overall_status = status;
825a9de470cSBruce Richardson 
826a9de470cSBruce Richardson 			if (tc->feature_mask & BLOCKCIPHER_TEST_FEATURE_STOPPER)
827a9de470cSBruce Richardson 				break;
828a9de470cSBruce Richardson 		}
829a9de470cSBruce Richardson 	}
830a9de470cSBruce Richardson 
831a9de470cSBruce Richardson 	return overall_status;
832a9de470cSBruce Richardson }
833