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