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