1a9de470cSBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2a9de470cSBruce Richardson  * Copyright(c) 2015-2017 Intel Corporation
3a9de470cSBruce Richardson  */
4a9de470cSBruce Richardson 
5*3c60274cSJie Zhou #ifndef RTE_EXEC_ENV_WINDOWS
6*3c60274cSJie Zhou 
7a9de470cSBruce Richardson #include <rte_common.h>
8a9de470cSBruce Richardson #include <rte_hexdump.h>
9a9de470cSBruce Richardson #include <rte_mbuf.h>
10a9de470cSBruce Richardson #include <rte_malloc.h>
11a9de470cSBruce Richardson #include <rte_memcpy.h>
12a9de470cSBruce Richardson #include <rte_pause.h>
13a9de470cSBruce Richardson 
14a9de470cSBruce Richardson #include <rte_crypto.h>
15a9de470cSBruce Richardson #include <rte_cryptodev.h>
16a9de470cSBruce Richardson 
17a9de470cSBruce Richardson #include "test.h"
18a9de470cSBruce Richardson #include "test_cryptodev.h"
19a9de470cSBruce Richardson #include "test_cryptodev_blockcipher.h"
20a9de470cSBruce Richardson #include "test_cryptodev_aes_test_vectors.h"
21a9de470cSBruce Richardson #include "test_cryptodev_des_test_vectors.h"
22a9de470cSBruce Richardson #include "test_cryptodev_hash_test_vectors.h"
23a9de470cSBruce Richardson 
24a9de470cSBruce Richardson static int
verify_algo_support(const struct blockcipher_test_case * t,const uint8_t dev_id,const uint32_t digest_len)2593982b21SPablo de Lara verify_algo_support(const struct blockcipher_test_case *t,
2693982b21SPablo de Lara 		const uint8_t dev_id, const uint32_t digest_len)
2793982b21SPablo de Lara {
2893982b21SPablo de Lara 	int ret = 0;
2993982b21SPablo de Lara 	const struct blockcipher_test_data *tdata = t->test_data;
3093982b21SPablo de Lara 	struct rte_cryptodev_sym_capability_idx cap_idx;
3193982b21SPablo de Lara 	const struct rte_cryptodev_symmetric_capability *capability;
3293982b21SPablo de Lara 
3393982b21SPablo de Lara 	if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
3493982b21SPablo de Lara 		cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3593982b21SPablo de Lara 		cap_idx.algo.cipher = tdata->crypto_algo;
3693982b21SPablo de Lara 		capability = rte_cryptodev_sym_capability_get(dev_id, &cap_idx);
3793982b21SPablo de Lara 		if (capability == NULL)
3893982b21SPablo de Lara 			return -1;
3993982b21SPablo de Lara 
40d5728a5aSShiri Kuzin 		if (cap_idx.algo.cipher != RTE_CRYPTO_CIPHER_NULL &&
41d5728a5aSShiri Kuzin 				!(t->test_data->wrapped_key))
4293982b21SPablo de Lara 			ret = rte_cryptodev_sym_capability_check_cipher(capability,
4393982b21SPablo de Lara 							tdata->cipher_key.len,
4493982b21SPablo de Lara 							tdata->iv.len);
4593982b21SPablo de Lara 		if (ret != 0)
4693982b21SPablo de Lara 			return -1;
4793982b21SPablo de Lara 	}
4893982b21SPablo de Lara 
4993982b21SPablo de Lara 	if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) {
5093982b21SPablo de Lara 		cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5193982b21SPablo de Lara 		cap_idx.algo.auth = tdata->auth_algo;
5293982b21SPablo de Lara 		capability = rte_cryptodev_sym_capability_get(dev_id, &cap_idx);
5393982b21SPablo de Lara 		if (capability == NULL)
5493982b21SPablo de Lara 			return -1;
5593982b21SPablo de Lara 
5693982b21SPablo de Lara 		if (cap_idx.algo.auth != RTE_CRYPTO_AUTH_NULL)
5793982b21SPablo de Lara 			ret = rte_cryptodev_sym_capability_check_auth(capability,
5893982b21SPablo de Lara 							tdata->auth_key.len,
5993982b21SPablo de Lara 							digest_len,
6093982b21SPablo de Lara 							0);
6193982b21SPablo de Lara 		if (ret != 0)
6293982b21SPablo de Lara 			return -1;
6393982b21SPablo de Lara 	}
6493982b21SPablo de Lara 
6593982b21SPablo de Lara 	return 0;
6693982b21SPablo de Lara }
6793982b21SPablo de Lara 
6893982b21SPablo de Lara static int
test_blockcipher_one_case(const struct blockcipher_test_case * t,struct rte_mempool * mbuf_pool,struct rte_mempool * op_mpool,struct rte_mempool * sess_mpool,struct rte_mempool * sess_priv_mpool,uint8_t dev_id,char * test_msg)69a9de470cSBruce Richardson test_blockcipher_one_case(const struct blockcipher_test_case *t,
70a9de470cSBruce Richardson 	struct rte_mempool *mbuf_pool,
71a9de470cSBruce Richardson 	struct rte_mempool *op_mpool,
72a9de470cSBruce Richardson 	struct rte_mempool *sess_mpool,
73a9de470cSBruce Richardson 	struct rte_mempool *sess_priv_mpool,
74a9de470cSBruce Richardson 	uint8_t dev_id,
75a9de470cSBruce Richardson 	char *test_msg)
76a9de470cSBruce Richardson {
77a9de470cSBruce Richardson 	struct rte_mbuf *ibuf = NULL;
78a9de470cSBruce Richardson 	struct rte_mbuf *obuf = NULL;
79a9de470cSBruce Richardson 	struct rte_mbuf *iobuf;
80a9de470cSBruce Richardson 	struct rte_crypto_sym_xform *cipher_xform = NULL;
81a9de470cSBruce Richardson 	struct rte_crypto_sym_xform *auth_xform = NULL;
82a9de470cSBruce Richardson 	struct rte_crypto_sym_xform *init_xform = NULL;
83a9de470cSBruce Richardson 	struct rte_crypto_sym_op *sym_op = NULL;
84a9de470cSBruce Richardson 	struct rte_crypto_op *op = NULL;
85a9de470cSBruce Richardson 	struct rte_cryptodev_info dev_info;
86a9de470cSBruce Richardson 	struct rte_cryptodev_sym_session *sess = NULL;
87a9de470cSBruce Richardson 
88a9de470cSBruce Richardson 	int status = TEST_SUCCESS;
89a9de470cSBruce Richardson 	const struct blockcipher_test_data *tdata = t->test_data;
90a9de470cSBruce Richardson 	uint8_t cipher_key[tdata->cipher_key.len];
91a9de470cSBruce Richardson 	uint8_t auth_key[tdata->auth_key.len];
92a9de470cSBruce Richardson 	uint32_t buf_len = tdata->ciphertext.len;
93b4c469ecSPablo de Lara 	uint32_t digest_len = tdata->digest.len;
94a9de470cSBruce Richardson 	char *buf_p = NULL;
95a9de470cSBruce Richardson 	uint8_t src_pattern = 0xa5;
96a9de470cSBruce Richardson 	uint8_t dst_pattern = 0xb6;
97a9de470cSBruce Richardson 	uint8_t tmp_src_buf[MBUF_SIZE];
98a9de470cSBruce Richardson 	uint8_t tmp_dst_buf[MBUF_SIZE];
996356c286STejasree Kondoj 	uint32_t pad_len;
100a9de470cSBruce Richardson 
101a9de470cSBruce Richardson 	int nb_segs = 1;
1025e73a1f8SFan Zhang 	uint32_t nb_iterates = 0;
103a9de470cSBruce Richardson 
104a9de470cSBruce Richardson 	rte_cryptodev_info_get(dev_id, &dev_info);
105a9de470cSBruce Richardson 	uint64_t feat_flags = dev_info.feature_flags;
106afcfa2fdSPablo de Lara 
107afcfa2fdSPablo de Lara 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
108afcfa2fdSPablo de Lara 		if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
109bf5c7112SCiara Power 			printf("Device doesn't support sessionless operations "
110afcfa2fdSPablo de Lara 				"Test Skipped.\n");
111afcfa2fdSPablo de Lara 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
112afcfa2fdSPablo de Lara 				"SKIPPED");
113cf43d9d0SAkhil Goyal 			return TEST_SKIPPED;
114afcfa2fdSPablo de Lara 		}
115afcfa2fdSPablo de Lara 	}
1166356c286STejasree Kondoj 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_DIGEST_ENCRYPTED) {
1176356c286STejasree Kondoj 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
1186356c286STejasree Kondoj 			printf("Device doesn't support encrypted digest "
1196356c286STejasree Kondoj 				"Test Skipped.\n");
1206356c286STejasree Kondoj 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
1216356c286STejasree Kondoj 				"SKIPPED");
1226356c286STejasree Kondoj 			return TEST_SKIPPED;
1236356c286STejasree Kondoj 		}
1246356c286STejasree Kondoj 	}
125afcfa2fdSPablo de Lara 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SG) {
126a9de470cSBruce Richardson 		uint64_t oop_flag = RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT;
127a9de470cSBruce Richardson 
128042bb565SPablo de Lara 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
129a9de470cSBruce Richardson 			if (!(feat_flags & oop_flag)) {
130a9de470cSBruce Richardson 				printf("Device doesn't support out-of-place "
131a9de470cSBruce Richardson 					"scatter-gather in input mbuf. "
132a9de470cSBruce Richardson 					"Test Skipped.\n");
13393982b21SPablo de Lara 				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
13493982b21SPablo de Lara 					"SKIPPED");
135cf43d9d0SAkhil Goyal 				return TEST_SKIPPED;
136a9de470cSBruce Richardson 			}
137a9de470cSBruce Richardson 		} else {
138a9de470cSBruce Richardson 			if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
139a9de470cSBruce Richardson 				printf("Device doesn't support in-place "
140a9de470cSBruce Richardson 					"scatter-gather mbufs. "
141a9de470cSBruce Richardson 					"Test Skipped.\n");
14293982b21SPablo de Lara 				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
14393982b21SPablo de Lara 					"SKIPPED");
144cf43d9d0SAkhil Goyal 				return TEST_SKIPPED;
145a9de470cSBruce Richardson 			}
146a9de470cSBruce Richardson 		}
147a9de470cSBruce Richardson 
148a9de470cSBruce Richardson 		nb_segs = 3;
149a9de470cSBruce Richardson 	}
150d5728a5aSShiri Kuzin 	if (!!(feat_flags & RTE_CRYPTODEV_FF_CIPHER_WRAPPED_KEY) ^
151d5728a5aSShiri Kuzin 		tdata->wrapped_key) {
152d5728a5aSShiri Kuzin 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
153d5728a5aSShiri Kuzin 			"SKIPPED");
154d5728a5aSShiri Kuzin 		return TEST_SKIPPED;
155d5728a5aSShiri Kuzin 	}
156a9de470cSBruce Richardson 
1574868f659SFan Zhang 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST &&
1584868f659SFan Zhang 		!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP)) {
1594868f659SFan Zhang 		printf("Device doesn't support raw data-path APIs. "
1604868f659SFan Zhang 			"Test Skipped.\n");
1614868f659SFan Zhang 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "SKIPPED");
1624868f659SFan Zhang 		return TEST_SKIPPED;
1634868f659SFan Zhang 	}
1644868f659SFan Zhang 
16555be2162SPablo de Lara 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
16655be2162SPablo de Lara 		uint64_t oop_flags = RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT |
16755be2162SPablo de Lara 			RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT |
16855be2162SPablo de Lara 			RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
16955be2162SPablo de Lara 			RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT;
17055be2162SPablo de Lara 		if (!(feat_flags & oop_flags)) {
17155be2162SPablo de Lara 			printf("Device doesn't support out-of-place operations."
17255be2162SPablo de Lara 				"Test Skipped.\n");
17355be2162SPablo de Lara 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
17455be2162SPablo de Lara 				"SKIPPED");
175cf43d9d0SAkhil Goyal 			return TEST_SKIPPED;
17655be2162SPablo de Lara 		}
1774868f659SFan Zhang 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
1784868f659SFan Zhang 			printf("Raw Data Path APIs do not support OOP, "
1794868f659SFan Zhang 				"Test Skipped.\n");
1804868f659SFan Zhang 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "SKIPPED");
181085f128aSCiara Power 			status = TEST_SKIPPED;
1824868f659SFan Zhang 			goto error_exit;
1834868f659SFan Zhang 		}
18455be2162SPablo de Lara 	}
18555be2162SPablo de Lara 
186a9de470cSBruce Richardson 	if (tdata->cipher_key.len)
187a9de470cSBruce Richardson 		memcpy(cipher_key, tdata->cipher_key.data,
188a9de470cSBruce Richardson 			tdata->cipher_key.len);
189a9de470cSBruce Richardson 	if (tdata->auth_key.len)
190a9de470cSBruce Richardson 		memcpy(auth_key, tdata->auth_key.data,
191a9de470cSBruce Richardson 			tdata->auth_key.len);
192a9de470cSBruce Richardson 
19393982b21SPablo de Lara 	/* Check if PMD is capable of performing that test */
19493982b21SPablo de Lara 	if (verify_algo_support(t, dev_id, digest_len) < 0) {
19593982b21SPablo de Lara 		RTE_LOG(DEBUG, USER1,
19693982b21SPablo de Lara 			"Device does not support this algorithm."
19793982b21SPablo de Lara 			"Test Skipped.\n");
19893982b21SPablo de Lara 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "SKIPPED");
199cf43d9d0SAkhil Goyal 		return TEST_SKIPPED;
20093982b21SPablo de Lara 	}
20193982b21SPablo de Lara 
202a9de470cSBruce Richardson 	/* preparing data */
203a9de470cSBruce Richardson 	if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH)
204a9de470cSBruce Richardson 		buf_len += digest_len;
205a9de470cSBruce Richardson 
2066356c286STejasree Kondoj 	pad_len = RTE_ALIGN(buf_len, 16) - buf_len;
2076356c286STejasree Kondoj 	if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED)
2086356c286STejasree Kondoj 		buf_len += pad_len;
2096356c286STejasree Kondoj 
210a9de470cSBruce Richardson 	/* for contiguous mbuf, nb_segs is 1 */
211a9de470cSBruce Richardson 	ibuf = create_segmented_mbuf(mbuf_pool,
212a9de470cSBruce Richardson 			tdata->ciphertext.len, nb_segs, src_pattern);
213a9de470cSBruce Richardson 	if (ibuf == NULL) {
214a9de470cSBruce Richardson 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
215a9de470cSBruce Richardson 			"line %u FAILED: %s",
216a9de470cSBruce Richardson 			__LINE__, "Cannot create source mbuf");
217a9de470cSBruce Richardson 		status = TEST_FAILED;
218a9de470cSBruce Richardson 		goto error_exit;
219a9de470cSBruce Richardson 	}
220a9de470cSBruce Richardson 
221a9de470cSBruce Richardson 	/* only encryption requires plaintext.data input,
222a9de470cSBruce Richardson 	 * decryption/(digest gen)/(digest verify) use ciphertext.data
223a9de470cSBruce Richardson 	 * to be computed
224a9de470cSBruce Richardson 	 */
225a9de470cSBruce Richardson 	if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT)
226a9de470cSBruce Richardson 		pktmbuf_write(ibuf, 0, tdata->plaintext.len,
227a9de470cSBruce Richardson 				tdata->plaintext.data);
228a9de470cSBruce Richardson 	else
229a9de470cSBruce Richardson 		pktmbuf_write(ibuf, 0, tdata->ciphertext.len,
230a9de470cSBruce Richardson 				tdata->ciphertext.data);
231a9de470cSBruce Richardson 
232a9de470cSBruce Richardson 	buf_p = rte_pktmbuf_append(ibuf, digest_len);
233a9de470cSBruce Richardson 	if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY)
2346356c286STejasree Kondoj 		if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED)
2356356c286STejasree Kondoj 			rte_memcpy(buf_p,
2366356c286STejasree Kondoj 				tdata->ciphertext.data + tdata->ciphertext.len,
2376356c286STejasree Kondoj 				 digest_len);
2386356c286STejasree Kondoj 		else
239a9de470cSBruce Richardson 			rte_memcpy(buf_p, tdata->digest.data, digest_len);
240a9de470cSBruce Richardson 	else
241a9de470cSBruce Richardson 		memset(buf_p, 0, digest_len);
2426356c286STejasree Kondoj 	if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED) {
2436356c286STejasree Kondoj 		buf_p = rte_pktmbuf_append(ibuf, pad_len);
2446356c286STejasree Kondoj 		if (!buf_p) {
2456356c286STejasree Kondoj 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
2466356c286STejasree Kondoj 				"FAILED: %s", __LINE__,
2476356c286STejasree Kondoj 				"No room to append mbuf");
2486356c286STejasree Kondoj 			status = TEST_FAILED;
2496356c286STejasree Kondoj 			goto error_exit;
2506356c286STejasree Kondoj 		}
2516356c286STejasree Kondoj 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY) {
2526356c286STejasree Kondoj 			const uint8_t *temp_p = tdata->ciphertext.data +
2536356c286STejasree Kondoj 					tdata->ciphertext.len +
2546356c286STejasree Kondoj 					digest_len;
2556356c286STejasree Kondoj 			rte_memcpy(buf_p, temp_p, pad_len);
2566356c286STejasree Kondoj 		} else
2576356c286STejasree Kondoj 			memset(buf_p, 0xa5, pad_len);
2586356c286STejasree Kondoj 	}
259a9de470cSBruce Richardson 
260a9de470cSBruce Richardson 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
261a9de470cSBruce Richardson 		obuf = rte_pktmbuf_alloc(mbuf_pool);
262a9de470cSBruce Richardson 		if (!obuf) {
263a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
264a9de470cSBruce Richardson 				"FAILED: %s", __LINE__,
265a9de470cSBruce Richardson 				"Allocation of rte_mbuf failed");
266a9de470cSBruce Richardson 			status = TEST_FAILED;
267a9de470cSBruce Richardson 			goto error_exit;
268a9de470cSBruce Richardson 		}
269a9de470cSBruce Richardson 		memset(obuf->buf_addr, dst_pattern, obuf->buf_len);
270a9de470cSBruce Richardson 
2710e51e342SGagandeep Singh 		if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED)
2726356c286STejasree Kondoj 			buf_p = rte_pktmbuf_append(obuf, buf_len + pad_len);
2730e51e342SGagandeep Singh 		else
2740e51e342SGagandeep Singh 			buf_p = rte_pktmbuf_append(obuf, buf_len);
275a9de470cSBruce Richardson 		if (!buf_p) {
276a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
277a9de470cSBruce Richardson 				"FAILED: %s", __LINE__,
278a9de470cSBruce Richardson 				"No room to append mbuf");
279a9de470cSBruce Richardson 			status = TEST_FAILED;
280a9de470cSBruce Richardson 			goto error_exit;
281a9de470cSBruce Richardson 		}
282a9de470cSBruce Richardson 		memset(buf_p, 0, buf_len);
283a9de470cSBruce Richardson 	}
284a9de470cSBruce Richardson 
285a9de470cSBruce Richardson 	/* Generate Crypto op data structure */
286a9de470cSBruce Richardson 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_SYMMETRIC);
287a9de470cSBruce Richardson 	if (!op) {
288a9de470cSBruce Richardson 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
289a9de470cSBruce Richardson 			"line %u FAILED: %s",
290a9de470cSBruce Richardson 			__LINE__, "Failed to allocate symmetric crypto "
291a9de470cSBruce Richardson 			"operation struct");
292a9de470cSBruce Richardson 		status = TEST_FAILED;
293a9de470cSBruce Richardson 		goto error_exit;
294a9de470cSBruce Richardson 	}
295a9de470cSBruce Richardson 
296a9de470cSBruce Richardson 	sym_op = op->sym;
297a9de470cSBruce Richardson 
2985e73a1f8SFan Zhang iterate:
2995e73a1f8SFan Zhang 	if (nb_iterates) {
3005e73a1f8SFan Zhang 		struct rte_mbuf *tmp_buf = ibuf;
3015e73a1f8SFan Zhang 
3025e73a1f8SFan Zhang 		ibuf = obuf;
3035e73a1f8SFan Zhang 		obuf = tmp_buf;
3045e73a1f8SFan Zhang 
3055e73a1f8SFan Zhang 		rte_pktmbuf_reset(ibuf);
3065e73a1f8SFan Zhang 		rte_pktmbuf_reset(obuf);
3075e73a1f8SFan Zhang 
3085e73a1f8SFan Zhang 		rte_pktmbuf_append(ibuf, tdata->ciphertext.len);
3095e73a1f8SFan Zhang 
3105e73a1f8SFan Zhang 		/* only encryption requires plaintext.data input,
3115e73a1f8SFan Zhang 		 * decryption/(digest gen)/(digest verify) use ciphertext.data
3125e73a1f8SFan Zhang 		 * to be computed
3135e73a1f8SFan Zhang 		 */
3145e73a1f8SFan Zhang 		if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT)
3155e73a1f8SFan Zhang 			pktmbuf_write(ibuf, 0, tdata->plaintext.len,
3165e73a1f8SFan Zhang 					tdata->plaintext.data);
3175e73a1f8SFan Zhang 		else
3185e73a1f8SFan Zhang 			pktmbuf_write(ibuf, 0, tdata->ciphertext.len,
3195e73a1f8SFan Zhang 					tdata->ciphertext.data);
3205e73a1f8SFan Zhang 
3215e73a1f8SFan Zhang 		buf_p = rte_pktmbuf_append(ibuf, digest_len);
3225e73a1f8SFan Zhang 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY)
3235e73a1f8SFan Zhang 			rte_memcpy(buf_p, tdata->digest.data, digest_len);
3245e73a1f8SFan Zhang 		else
3255e73a1f8SFan Zhang 			memset(buf_p, 0, digest_len);
3265e73a1f8SFan Zhang 
3275e73a1f8SFan Zhang 		memset(obuf->buf_addr, dst_pattern, obuf->buf_len);
3285e73a1f8SFan Zhang 
3295e73a1f8SFan Zhang 		buf_p = rte_pktmbuf_append(obuf, buf_len);
3305e73a1f8SFan Zhang 		if (!buf_p) {
3315e73a1f8SFan Zhang 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
3325e73a1f8SFan Zhang 				"FAILED: %s", __LINE__,
3335e73a1f8SFan Zhang 				"No room to append mbuf");
3345e73a1f8SFan Zhang 			status = TEST_FAILED;
3355e73a1f8SFan Zhang 			goto error_exit;
3365e73a1f8SFan Zhang 		}
3375e73a1f8SFan Zhang 		memset(buf_p, 0, buf_len);
3385e73a1f8SFan Zhang 	}
3395e73a1f8SFan Zhang 
340a9de470cSBruce Richardson 	sym_op->m_src = ibuf;
341a9de470cSBruce Richardson 
342a9de470cSBruce Richardson 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
343a9de470cSBruce Richardson 		sym_op->m_dst = obuf;
344a9de470cSBruce Richardson 		iobuf = obuf;
345a9de470cSBruce Richardson 	} else {
346a9de470cSBruce Richardson 		sym_op->m_dst = NULL;
347a9de470cSBruce Richardson 		iobuf = ibuf;
348a9de470cSBruce Richardson 	}
349a9de470cSBruce Richardson 
350a9de470cSBruce Richardson 	/* sessionless op requires allocate xform using
351a9de470cSBruce Richardson 	 * rte_crypto_op_sym_xforms_alloc(), otherwise rte_zmalloc()
352a9de470cSBruce Richardson 	 * is used
353a9de470cSBruce Richardson 	 */
354a9de470cSBruce Richardson 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
355a9de470cSBruce Richardson 		uint32_t n_xforms = 0;
356a9de470cSBruce Richardson 
357a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER)
358a9de470cSBruce Richardson 			n_xforms++;
359a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH)
360a9de470cSBruce Richardson 			n_xforms++;
361a9de470cSBruce Richardson 
362a9de470cSBruce Richardson 		if (rte_crypto_op_sym_xforms_alloc(op, n_xforms)
363a9de470cSBruce Richardson 			== NULL) {
364a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
365a9de470cSBruce Richardson 				"FAILED: %s", __LINE__, "Failed to "
366a9de470cSBruce Richardson 				"allocate space for crypto transforms");
367a9de470cSBruce Richardson 			status = TEST_FAILED;
368a9de470cSBruce Richardson 			goto error_exit;
369a9de470cSBruce Richardson 		}
370a9de470cSBruce Richardson 	} else {
371a9de470cSBruce Richardson 		cipher_xform = rte_zmalloc(NULL,
372a9de470cSBruce Richardson 			sizeof(struct rte_crypto_sym_xform), 0);
373a9de470cSBruce Richardson 
374a9de470cSBruce Richardson 		auth_xform = rte_zmalloc(NULL,
375a9de470cSBruce Richardson 			sizeof(struct rte_crypto_sym_xform), 0);
376a9de470cSBruce Richardson 
377a9de470cSBruce Richardson 		if (!cipher_xform || !auth_xform) {
378a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
379a9de470cSBruce Richardson 				"FAILED: %s", __LINE__, "Failed to "
380a9de470cSBruce Richardson 				"allocate memory for crypto transforms");
381a9de470cSBruce Richardson 			status = TEST_FAILED;
382a9de470cSBruce Richardson 			goto error_exit;
383a9de470cSBruce Richardson 		}
384a9de470cSBruce Richardson 	}
385a9de470cSBruce Richardson 
386a9de470cSBruce Richardson 	/* preparing xform, for sessioned op, init_xform is initialized
387a9de470cSBruce Richardson 	 * here and later as param in rte_cryptodev_sym_session_create() call
388a9de470cSBruce Richardson 	 */
389a9de470cSBruce Richardson 	if (t->op_mask == BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN) {
390a9de470cSBruce Richardson 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
391a9de470cSBruce Richardson 			cipher_xform = op->sym->xform;
392a9de470cSBruce Richardson 			auth_xform = cipher_xform->next;
393a9de470cSBruce Richardson 			auth_xform->next = NULL;
394a9de470cSBruce Richardson 		} else {
395a9de470cSBruce Richardson 			cipher_xform->next = auth_xform;
396a9de470cSBruce Richardson 			auth_xform->next = NULL;
397a9de470cSBruce Richardson 			init_xform = cipher_xform;
398a9de470cSBruce Richardson 		}
399a9de470cSBruce Richardson 	} else if (t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC) {
400a9de470cSBruce Richardson 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
401a9de470cSBruce Richardson 			auth_xform = op->sym->xform;
402a9de470cSBruce Richardson 			cipher_xform = auth_xform->next;
403a9de470cSBruce Richardson 			cipher_xform->next = NULL;
404a9de470cSBruce Richardson 		} else {
405a9de470cSBruce Richardson 			auth_xform->next = cipher_xform;
406a9de470cSBruce Richardson 			cipher_xform->next = NULL;
407a9de470cSBruce Richardson 			init_xform = auth_xform;
408a9de470cSBruce Richardson 		}
4096356c286STejasree Kondoj 	} else if (t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_GEN_ENC) {
4106356c286STejasree Kondoj 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
4116356c286STejasree Kondoj 			auth_xform = op->sym->xform;
4126356c286STejasree Kondoj 			cipher_xform = auth_xform->next;
4136356c286STejasree Kondoj 			cipher_xform->next = NULL;
4146356c286STejasree Kondoj 		} else {
4156356c286STejasree Kondoj 			auth_xform->next = cipher_xform;
4166356c286STejasree Kondoj 			cipher_xform->next = NULL;
4176356c286STejasree Kondoj 			init_xform = auth_xform;
4186356c286STejasree Kondoj 		}
4196356c286STejasree Kondoj 	} else if (t->op_mask == BLOCKCIPHER_TEST_OP_DEC_AUTH_VERIFY) {
4206356c286STejasree Kondoj 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
4216356c286STejasree Kondoj 			cipher_xform = op->sym->xform;
4226356c286STejasree Kondoj 			auth_xform = cipher_xform->next;
4236356c286STejasree Kondoj 			auth_xform->next = NULL;
4246356c286STejasree Kondoj 		} else {
4256356c286STejasree Kondoj 			cipher_xform->next = auth_xform;
4266356c286STejasree Kondoj 			auth_xform->next = NULL;
4276356c286STejasree Kondoj 			init_xform = cipher_xform;
4286356c286STejasree Kondoj 		}
429a9de470cSBruce Richardson 	} else if ((t->op_mask == BLOCKCIPHER_TEST_OP_ENCRYPT) ||
430a9de470cSBruce Richardson 			(t->op_mask == BLOCKCIPHER_TEST_OP_DECRYPT)) {
431a9de470cSBruce Richardson 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)
432a9de470cSBruce Richardson 			cipher_xform = op->sym->xform;
433a9de470cSBruce Richardson 		else
434a9de470cSBruce Richardson 			init_xform = cipher_xform;
435a9de470cSBruce Richardson 		cipher_xform->next = NULL;
436a9de470cSBruce Richardson 	} else if ((t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_GEN) ||
437a9de470cSBruce Richardson 			(t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_VERIFY)) {
438a9de470cSBruce Richardson 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)
439a9de470cSBruce Richardson 			auth_xform = op->sym->xform;
440a9de470cSBruce Richardson 		else
441a9de470cSBruce Richardson 			init_xform = auth_xform;
442a9de470cSBruce Richardson 		auth_xform->next = NULL;
443a9de470cSBruce Richardson 	} else {
444a9de470cSBruce Richardson 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
445a9de470cSBruce Richardson 			"line %u FAILED: %s",
446a9de470cSBruce Richardson 			__LINE__, "Unrecognized operation");
447a9de470cSBruce Richardson 		status = TEST_FAILED;
448a9de470cSBruce Richardson 		goto error_exit;
449a9de470cSBruce Richardson 	}
450a9de470cSBruce Richardson 
451a9de470cSBruce Richardson 	/*configure xforms & sym_op cipher and auth data*/
452a9de470cSBruce Richardson 	if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
453a9de470cSBruce Richardson 		cipher_xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
454a9de470cSBruce Richardson 		cipher_xform->cipher.algo = tdata->crypto_algo;
455a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT)
456a9de470cSBruce Richardson 			cipher_xform->cipher.op =
457a9de470cSBruce Richardson 				RTE_CRYPTO_CIPHER_OP_ENCRYPT;
458a9de470cSBruce Richardson 		else
459a9de470cSBruce Richardson 			cipher_xform->cipher.op =
460a9de470cSBruce Richardson 				RTE_CRYPTO_CIPHER_OP_DECRYPT;
461a9de470cSBruce Richardson 		cipher_xform->cipher.key.data = cipher_key;
462a9de470cSBruce Richardson 		cipher_xform->cipher.key.length = tdata->cipher_key.len;
463a9de470cSBruce Richardson 		cipher_xform->cipher.iv.offset = IV_OFFSET;
464d5728a5aSShiri Kuzin 		cipher_xform->cipher.dataunit_len = tdata->xts_dataunit_len;
465d954825aSAnkur Dwivedi 
466d954825aSAnkur Dwivedi 		if (tdata->crypto_algo == RTE_CRYPTO_CIPHER_NULL)
467d954825aSAnkur Dwivedi 			cipher_xform->cipher.iv.length = 0;
468d954825aSAnkur Dwivedi 		else
469a9de470cSBruce Richardson 			cipher_xform->cipher.iv.length = tdata->iv.len;
470a9de470cSBruce Richardson 
4715e73a1f8SFan Zhang 		sym_op->cipher.data.offset = tdata->cipher_offset;
4725e73a1f8SFan Zhang 		sym_op->cipher.data.length = tdata->ciphertext.len -
4735e73a1f8SFan Zhang 				tdata->cipher_offset;
4746356c286STejasree Kondoj 		if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED) {
4756356c286STejasree Kondoj 			sym_op->cipher.data.length += tdata->digest.len;
4766356c286STejasree Kondoj 			sym_op->cipher.data.length += pad_len;
4776356c286STejasree Kondoj 		}
478a9de470cSBruce Richardson 		rte_memcpy(rte_crypto_op_ctod_offset(op, uint8_t *, IV_OFFSET),
479a9de470cSBruce Richardson 				tdata->iv.data,
480a9de470cSBruce Richardson 				tdata->iv.len);
481a9de470cSBruce Richardson 	}
482a9de470cSBruce Richardson 
483a9de470cSBruce Richardson 	if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) {
484a9de470cSBruce Richardson 		uint32_t digest_offset = tdata->ciphertext.len;
485a9de470cSBruce Richardson 
486a9de470cSBruce Richardson 		auth_xform->type = RTE_CRYPTO_SYM_XFORM_AUTH;
487a9de470cSBruce Richardson 		auth_xform->auth.algo = tdata->auth_algo;
488a9de470cSBruce Richardson 		auth_xform->auth.key.length = tdata->auth_key.len;
489a9de470cSBruce Richardson 		auth_xform->auth.key.data = auth_key;
490a9de470cSBruce Richardson 		auth_xform->auth.digest_length = digest_len;
491a9de470cSBruce Richardson 
492a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) {
493a9de470cSBruce Richardson 			auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
494a9de470cSBruce Richardson 			sym_op->auth.digest.data = pktmbuf_mtod_offset
495a9de470cSBruce Richardson 				(iobuf, digest_offset);
496a9de470cSBruce Richardson 			sym_op->auth.digest.phys_addr =
497a9de470cSBruce Richardson 				pktmbuf_iova_offset(iobuf,
498a9de470cSBruce Richardson 					digest_offset);
499a9de470cSBruce Richardson 		} else {
500a9de470cSBruce Richardson 			auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
501a9de470cSBruce Richardson 			sym_op->auth.digest.data = pktmbuf_mtod_offset
502a9de470cSBruce Richardson 				(sym_op->m_src, digest_offset);
503a9de470cSBruce Richardson 			sym_op->auth.digest.phys_addr =
504a9de470cSBruce Richardson 				pktmbuf_iova_offset(sym_op->m_src,
505a9de470cSBruce Richardson 					digest_offset);
506a9de470cSBruce Richardson 		}
507a9de470cSBruce Richardson 
5085e73a1f8SFan Zhang 		sym_op->auth.data.offset = tdata->auth_offset;
5095e73a1f8SFan Zhang 		sym_op->auth.data.length = tdata->ciphertext.len -
5105e73a1f8SFan Zhang 				tdata->auth_offset;
511a9de470cSBruce Richardson 	}
512a9de470cSBruce Richardson 
5135e73a1f8SFan Zhang 	/**
5145e73a1f8SFan Zhang 	 * Create session for sessioned op. For mbuf iteration test,
5155e73a1f8SFan Zhang 	 * skip the session creation for the second iteration.
5165e73a1f8SFan Zhang 	 */
5175e73a1f8SFan Zhang 	if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) &&
5185e73a1f8SFan Zhang 			nb_iterates == 0) {
519a9de470cSBruce Richardson 		sess = rte_cryptodev_sym_session_create(sess_mpool);
520a9de470cSBruce Richardson 
521439d222bSAnkur Dwivedi 		status = rte_cryptodev_sym_session_init(dev_id, sess,
522439d222bSAnkur Dwivedi 				init_xform, sess_priv_mpool);
523439d222bSAnkur Dwivedi 		if (status == -ENOTSUP) {
524439d222bSAnkur Dwivedi 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "UNSUPPORTED");
525cf43d9d0SAkhil Goyal 			status = TEST_SKIPPED;
526439d222bSAnkur Dwivedi 			goto error_exit;
527439d222bSAnkur Dwivedi 		}
528439d222bSAnkur Dwivedi 		if (!sess || status < 0) {
529a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
530a9de470cSBruce Richardson 				"FAILED: %s", __LINE__,
531a9de470cSBruce Richardson 				"Session creation failed");
532a9de470cSBruce Richardson 			status = TEST_FAILED;
533a9de470cSBruce Richardson 			goto error_exit;
534a9de470cSBruce Richardson 		}
535a9de470cSBruce Richardson 
536a9de470cSBruce Richardson 		/* attach symmetric crypto session to crypto operations */
537a9de470cSBruce Richardson 		rte_crypto_op_attach_sym_session(op, sess);
538a9de470cSBruce Richardson 	}
539a9de470cSBruce Richardson 
540a9de470cSBruce Richardson 	debug_hexdump(stdout, "m_src(before):",
541a9de470cSBruce Richardson 			sym_op->m_src->buf_addr, sym_op->m_src->buf_len);
542a9de470cSBruce Richardson 	rte_memcpy(tmp_src_buf, sym_op->m_src->buf_addr,
543a9de470cSBruce Richardson 						sym_op->m_src->buf_len);
544a9de470cSBruce Richardson 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
545a9de470cSBruce Richardson 		debug_hexdump(stdout, "m_dst(before):",
546a9de470cSBruce Richardson 			sym_op->m_dst->buf_addr, sym_op->m_dst->buf_len);
547a9de470cSBruce Richardson 		rte_memcpy(tmp_dst_buf, sym_op->m_dst->buf_addr,
548a9de470cSBruce Richardson 						sym_op->m_dst->buf_len);
549a9de470cSBruce Richardson 	}
550a9de470cSBruce Richardson 
551a9de470cSBruce Richardson 	/* Process crypto operation */
5524868f659SFan Zhang 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
5534868f659SFan Zhang 		uint8_t is_cipher = 0, is_auth = 0;
5544868f659SFan Zhang 		if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER)
5554868f659SFan Zhang 			is_cipher = 1;
5564868f659SFan Zhang 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH)
5574868f659SFan Zhang 			is_auth = 1;
5584868f659SFan Zhang 
5594868f659SFan Zhang 		process_sym_raw_dp_op(dev_id, 0, op, is_cipher, is_auth, 0,
5604868f659SFan Zhang 				tdata->iv.len);
5614868f659SFan Zhang 	} else {
562a9de470cSBruce Richardson 		if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
563a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
564a9de470cSBruce Richardson 				"line %u FAILED: %s",
565a9de470cSBruce Richardson 				__LINE__, "Error sending packet for encryption");
566a9de470cSBruce Richardson 			status = TEST_FAILED;
567a9de470cSBruce Richardson 			goto error_exit;
568a9de470cSBruce Richardson 		}
569a9de470cSBruce Richardson 
570a9de470cSBruce Richardson 		op = NULL;
571a9de470cSBruce Richardson 
572a9de470cSBruce Richardson 		while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
573a9de470cSBruce Richardson 			rte_pause();
574a9de470cSBruce Richardson 
575a9de470cSBruce Richardson 		if (!op) {
576a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
577a9de470cSBruce Richardson 				"line %u FAILED: %s",
578a9de470cSBruce Richardson 				__LINE__, "Failed to process sym crypto op");
579a9de470cSBruce Richardson 			status = TEST_FAILED;
580a9de470cSBruce Richardson 			goto error_exit;
581a9de470cSBruce Richardson 		}
5824868f659SFan Zhang 	}
583a9de470cSBruce Richardson 
584a9de470cSBruce Richardson 	debug_hexdump(stdout, "m_src(after):",
585a9de470cSBruce Richardson 			sym_op->m_src->buf_addr, sym_op->m_src->buf_len);
586a9de470cSBruce Richardson 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP)
587a9de470cSBruce Richardson 		debug_hexdump(stdout, "m_dst(after):",
588a9de470cSBruce Richardson 			sym_op->m_dst->buf_addr, sym_op->m_dst->buf_len);
589a9de470cSBruce Richardson 
590a9de470cSBruce Richardson 	/* Verify results */
591a9de470cSBruce Richardson 	if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
592a9de470cSBruce Richardson 		if ((t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY) &&
593a9de470cSBruce Richardson 			(op->status == RTE_CRYPTO_OP_STATUS_AUTH_FAILED))
594a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
595a9de470cSBruce Richardson 				"FAILED: Digest verification failed "
596a9de470cSBruce Richardson 				"(0x%X)", __LINE__, op->status);
597a9de470cSBruce Richardson 		else
598a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
599a9de470cSBruce Richardson 				"FAILED: Operation failed "
600a9de470cSBruce Richardson 				"(0x%X)", __LINE__, op->status);
601a9de470cSBruce Richardson 		status = TEST_FAILED;
602a9de470cSBruce Richardson 		goto error_exit;
603a9de470cSBruce Richardson 	}
604a9de470cSBruce Richardson 
605a9de470cSBruce Richardson 	if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
606a9de470cSBruce Richardson 		uint8_t buffer[2048];
607a9de470cSBruce Richardson 		const uint8_t *compare_ref;
608a9de470cSBruce Richardson 		uint32_t compare_len;
609a9de470cSBruce Richardson 
610a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT) {
6115e73a1f8SFan Zhang 			compare_ref = tdata->ciphertext.data +
6125e73a1f8SFan Zhang 					tdata->cipher_offset;
6135e73a1f8SFan Zhang 			compare_len = tdata->ciphertext.len -
6145e73a1f8SFan Zhang 					tdata->cipher_offset;
6156356c286STejasree Kondoj 			if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED)
6166356c286STejasree Kondoj 				compare_len += tdata->digest.len;
617a9de470cSBruce Richardson 		} else {
6185e73a1f8SFan Zhang 			compare_ref = tdata->plaintext.data +
6195e73a1f8SFan Zhang 					tdata->cipher_offset;
6205e73a1f8SFan Zhang 			compare_len = tdata->plaintext.len -
6215e73a1f8SFan Zhang 					tdata->cipher_offset;
622a9de470cSBruce Richardson 		}
623a9de470cSBruce Richardson 
6245e73a1f8SFan Zhang 		if (memcmp(rte_pktmbuf_read(iobuf, tdata->cipher_offset,
6255e73a1f8SFan Zhang 				compare_len, buffer), compare_ref,
6265e73a1f8SFan Zhang 				compare_len)) {
627a9de470cSBruce Richardson 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
628a9de470cSBruce Richardson 				"FAILED: %s", __LINE__,
629a9de470cSBruce Richardson 				"Crypto data not as expected");
630a9de470cSBruce Richardson 			status = TEST_FAILED;
631a9de470cSBruce Richardson 			goto error_exit;
632a9de470cSBruce Richardson 		}
633a9de470cSBruce Richardson 	}
634a9de470cSBruce Richardson 
6356356c286STejasree Kondoj 	/* Check digest data only in enc-then-auth_gen case.
6366356c286STejasree Kondoj 	 * In auth_gen-then-enc case, cipher text contains both encrypted
6376356c286STejasree Kondoj 	 * plain text and encrypted digest value. If cipher text is correct,
6386356c286STejasree Kondoj 	 * it implies digest is also generated properly.
6396356c286STejasree Kondoj 	 */
6406356c286STejasree Kondoj 	if (!(t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED))
641a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) {
642a9de470cSBruce Richardson 			uint8_t *auth_res = pktmbuf_mtod_offset(iobuf,
643a9de470cSBruce Richardson 						tdata->ciphertext.len);
644a9de470cSBruce Richardson 
645a9de470cSBruce Richardson 			if (memcmp(auth_res, tdata->digest.data, digest_len)) {
646a9de470cSBruce Richardson 				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
647a9de470cSBruce Richardson 					"FAILED: %s", __LINE__, "Generated "
648a9de470cSBruce Richardson 					"digest data not as expected");
649a9de470cSBruce Richardson 				status = TEST_FAILED;
650a9de470cSBruce Richardson 				goto error_exit;
651a9de470cSBruce Richardson 			}
652a9de470cSBruce Richardson 		}
653a9de470cSBruce Richardson 
654a9de470cSBruce Richardson 	/* The only parts that should have changed in the buffer are
655a9de470cSBruce Richardson 	 * plaintext/ciphertext and digest.
656a9de470cSBruce Richardson 	 * In OOP only the dest buffer should change.
657a9de470cSBruce Richardson 	 */
658a9de470cSBruce Richardson 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
659a9de470cSBruce Richardson 		struct rte_mbuf *mbuf;
660a9de470cSBruce Richardson 		uint8_t value;
661a9de470cSBruce Richardson 		uint32_t head_unchanged_len, changed_len = 0;
662a9de470cSBruce Richardson 		uint32_t i;
663a9de470cSBruce Richardson 		uint32_t hdroom_used = 0, tlroom_used = 0;
664a9de470cSBruce Richardson 		uint32_t hdroom = 0;
665a9de470cSBruce Richardson 
666a9de470cSBruce Richardson 		mbuf = sym_op->m_src;
667a9de470cSBruce Richardson 		/*
668a9de470cSBruce Richardson 		 * Crypto PMDs specify the headroom & tailroom it would use
669a9de470cSBruce Richardson 		 * when processing the crypto operation. PMD is free to modify
670a9de470cSBruce Richardson 		 * this space, and so the verification check should skip that
671a9de470cSBruce Richardson 		 * block.
672a9de470cSBruce Richardson 		 */
673a9de470cSBruce Richardson 		hdroom_used = dev_info.min_mbuf_headroom_req;
674a9de470cSBruce Richardson 		tlroom_used = dev_info.min_mbuf_tailroom_req;
675a9de470cSBruce Richardson 
676a9de470cSBruce Richardson 		/* Get headroom */
677a9de470cSBruce Richardson 		hdroom = rte_pktmbuf_headroom(mbuf);
678a9de470cSBruce Richardson 
679a9de470cSBruce Richardson 		head_unchanged_len = mbuf->buf_len;
680a9de470cSBruce Richardson 
681a9de470cSBruce Richardson 		for (i = 0; i < mbuf->buf_len; i++) {
682a9de470cSBruce Richardson 
683a9de470cSBruce Richardson 			/* Skip headroom used by PMD */
684a9de470cSBruce Richardson 			if (i == hdroom - hdroom_used)
685a9de470cSBruce Richardson 				i += hdroom_used;
686a9de470cSBruce Richardson 
687a9de470cSBruce Richardson 			/* Skip tailroom used by PMD */
688a9de470cSBruce Richardson 			if (i == (hdroom + mbuf->data_len))
689a9de470cSBruce Richardson 				i += tlroom_used;
690a9de470cSBruce Richardson 
691a9de470cSBruce Richardson 			value = *((uint8_t *)(mbuf->buf_addr)+i);
692a9de470cSBruce Richardson 			if (value != tmp_src_buf[i]) {
693a9de470cSBruce Richardson 				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
694a9de470cSBruce Richardson 	"line %u FAILED: OOP src outer mbuf data (0x%x) not as expected (0x%x)",
695a9de470cSBruce Richardson 					__LINE__, value, tmp_src_buf[i]);
696a9de470cSBruce Richardson 				status = TEST_FAILED;
697a9de470cSBruce Richardson 				goto error_exit;
698a9de470cSBruce Richardson 			}
699a9de470cSBruce Richardson 		}
700a9de470cSBruce Richardson 
701a9de470cSBruce Richardson 		mbuf = sym_op->m_dst;
702a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) {
703a9de470cSBruce Richardson 			head_unchanged_len = hdroom + sym_op->auth.data.offset;
704a9de470cSBruce Richardson 			changed_len = sym_op->auth.data.length;
705a9de470cSBruce Richardson 			if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN)
706a9de470cSBruce Richardson 				changed_len += digest_len;
707a9de470cSBruce Richardson 		} else {
708a9de470cSBruce Richardson 			/* cipher-only */
709a9de470cSBruce Richardson 			head_unchanged_len = hdroom +
710a9de470cSBruce Richardson 					sym_op->cipher.data.offset;
711a9de470cSBruce Richardson 			changed_len = sym_op->cipher.data.length;
712a9de470cSBruce Richardson 		}
713a9de470cSBruce Richardson 
7146356c286STejasree Kondoj 		if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED)
7156356c286STejasree Kondoj 			changed_len = sym_op->cipher.data.length +
7166356c286STejasree Kondoj 				digest_len + pad_len;
7176356c286STejasree Kondoj 
718a9de470cSBruce Richardson 		for (i = 0; i < mbuf->buf_len; i++) {
719a9de470cSBruce Richardson 			if (i == head_unchanged_len)
720a9de470cSBruce Richardson 				i += changed_len;
721a9de470cSBruce Richardson 			value = *((uint8_t *)(mbuf->buf_addr)+i);
722a9de470cSBruce Richardson 			if (value != tmp_dst_buf[i]) {
723a9de470cSBruce Richardson 				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
724a9de470cSBruce Richardson 				"line %u FAILED: OOP dst outer mbuf data "
725a9de470cSBruce Richardson 				"(0x%x) not as expected (0x%x)",
726a9de470cSBruce Richardson 				__LINE__, value, tmp_dst_buf[i]);
727a9de470cSBruce Richardson 				status = TEST_FAILED;
728a9de470cSBruce Richardson 				goto error_exit;
729a9de470cSBruce Richardson 			}
730a9de470cSBruce Richardson 		}
7315e73a1f8SFan Zhang 
7325e73a1f8SFan Zhang 		if (!nb_iterates) {
7335e73a1f8SFan Zhang 			nb_iterates++;
7345e73a1f8SFan Zhang 			goto iterate;
7355e73a1f8SFan Zhang 		}
736a9de470cSBruce Richardson 	} else {
737a9de470cSBruce Richardson 		/* In-place operation */
738a9de470cSBruce Richardson 		struct rte_mbuf *mbuf;
739a9de470cSBruce Richardson 		uint8_t value;
740a9de470cSBruce Richardson 		uint32_t head_unchanged_len = 0, changed_len = 0;
741a9de470cSBruce Richardson 		uint32_t i;
742a9de470cSBruce Richardson 		uint32_t hdroom_used = 0, tlroom_used = 0;
743a9de470cSBruce Richardson 		uint32_t hdroom = 0;
744a9de470cSBruce Richardson 
745a9de470cSBruce Richardson 		/*
746a9de470cSBruce Richardson 		 * Crypto PMDs specify the headroom & tailroom it would use
747a9de470cSBruce Richardson 		 * when processing the crypto operation. PMD is free to modify
748a9de470cSBruce Richardson 		 * this space, and so the verification check should skip that
749a9de470cSBruce Richardson 		 * block.
750a9de470cSBruce Richardson 		 */
751a9de470cSBruce Richardson 		hdroom_used = dev_info.min_mbuf_headroom_req;
752a9de470cSBruce Richardson 		tlroom_used = dev_info.min_mbuf_tailroom_req;
753a9de470cSBruce Richardson 
754a9de470cSBruce Richardson 		mbuf = sym_op->m_src;
755a9de470cSBruce Richardson 
756a9de470cSBruce Richardson 		/* Get headroom */
757a9de470cSBruce Richardson 		hdroom = rte_pktmbuf_headroom(mbuf);
758a9de470cSBruce Richardson 
759a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
760a9de470cSBruce Richardson 			head_unchanged_len = hdroom +
761a9de470cSBruce Richardson 					sym_op->cipher.data.offset;
762a9de470cSBruce Richardson 			changed_len = sym_op->cipher.data.length;
763a9de470cSBruce Richardson 		} else {
764a9de470cSBruce Richardson 			/* auth-only */
765a9de470cSBruce Richardson 			head_unchanged_len = hdroom +
766a9de470cSBruce Richardson 					sym_op->auth.data.offset +
767a9de470cSBruce Richardson 					sym_op->auth.data.length;
768a9de470cSBruce Richardson 			changed_len = 0;
769a9de470cSBruce Richardson 		}
770a9de470cSBruce Richardson 
771a9de470cSBruce Richardson 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN)
772a9de470cSBruce Richardson 			changed_len += digest_len;
773a9de470cSBruce Richardson 
7746356c286STejasree Kondoj 		if (t->op_mask & BLOCKCIPHER_TEST_OP_DIGEST_ENCRYPTED)
7756356c286STejasree Kondoj 			changed_len = sym_op->cipher.data.length;
7766356c286STejasree Kondoj 
777a9de470cSBruce Richardson 		for (i = 0; i < mbuf->buf_len; i++) {
778a9de470cSBruce Richardson 
779a9de470cSBruce Richardson 			/* Skip headroom used by PMD */
780a9de470cSBruce Richardson 			if (i == hdroom - hdroom_used)
781a9de470cSBruce Richardson 				i += hdroom_used;
782a9de470cSBruce Richardson 
783a9de470cSBruce Richardson 			if (i == head_unchanged_len)
784a9de470cSBruce Richardson 				i += changed_len;
785a9de470cSBruce Richardson 
786a9de470cSBruce Richardson 			/* Skip tailroom used by PMD */
787a9de470cSBruce Richardson 			if (i == (hdroom + mbuf->data_len))
788a9de470cSBruce Richardson 				i += tlroom_used;
789a9de470cSBruce Richardson 
790a9de470cSBruce Richardson 			value = *((uint8_t *)(mbuf->buf_addr)+i);
791a9de470cSBruce Richardson 			if (value != tmp_src_buf[i]) {
792a9de470cSBruce Richardson 				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
793a9de470cSBruce Richardson 				"line %u FAILED: outer mbuf data (0x%x) "
794a9de470cSBruce Richardson 				"not as expected (0x%x)",
795a9de470cSBruce Richardson 				__LINE__, value, tmp_src_buf[i]);
796a9de470cSBruce Richardson 				status = TEST_FAILED;
797a9de470cSBruce Richardson 				goto error_exit;
798a9de470cSBruce Richardson 			}
799a9de470cSBruce Richardson 		}
800a9de470cSBruce Richardson 	}
801a9de470cSBruce Richardson 
802a9de470cSBruce Richardson 	snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "PASS");
803a9de470cSBruce Richardson 
804a9de470cSBruce Richardson error_exit:
805a9de470cSBruce Richardson 	if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)) {
806a9de470cSBruce Richardson 		if (sess) {
807a9de470cSBruce Richardson 			rte_cryptodev_sym_session_clear(dev_id, sess);
808a9de470cSBruce Richardson 			rte_cryptodev_sym_session_free(sess);
809a9de470cSBruce Richardson 		}
810a9de470cSBruce Richardson 		rte_free(cipher_xform);
811a9de470cSBruce Richardson 		rte_free(auth_xform);
812a9de470cSBruce Richardson 	}
813a9de470cSBruce Richardson 
814a9de470cSBruce Richardson 	if (op)
815a9de470cSBruce Richardson 		rte_crypto_op_free(op);
816a9de470cSBruce Richardson 
817a9de470cSBruce Richardson 	rte_pktmbuf_free(obuf);
818a9de470cSBruce Richardson 
819a9de470cSBruce Richardson 	rte_pktmbuf_free(ibuf);
820a9de470cSBruce Richardson 
821a9de470cSBruce Richardson 	return status;
822a9de470cSBruce Richardson }
823a9de470cSBruce Richardson 
824e65da89cSCiara Power static int
blockcipher_test_case_run(const void * data)825e65da89cSCiara Power blockcipher_test_case_run(const void *data)
826a9de470cSBruce Richardson {
827e65da89cSCiara Power 	const struct blockcipher_test_case *tc_data = data;
828e65da89cSCiara Power 	int status;
829a9de470cSBruce Richardson 	char test_msg[BLOCKCIPHER_TEST_MSG_LEN + 1];
830e65da89cSCiara Power 
831e65da89cSCiara Power 	status = test_blockcipher_one_case(tc_data,
832e65da89cSCiara Power 			p_testsuite_params->mbuf_pool,
833e65da89cSCiara Power 			p_testsuite_params->op_mpool,
834e65da89cSCiara Power 			p_testsuite_params->session_mpool,
835e65da89cSCiara Power 			p_testsuite_params->session_priv_mpool,
836e65da89cSCiara Power 			p_testsuite_params->valid_devs[0],
837e65da89cSCiara Power 			test_msg);
838e65da89cSCiara Power 	return status;
839e65da89cSCiara Power }
840e65da89cSCiara Power 
841e65da89cSCiara Power static int
aes_chain_setup(void)842e65da89cSCiara Power aes_chain_setup(void)
843e65da89cSCiara Power {
844e65da89cSCiara Power 	uint8_t dev_id = p_testsuite_params->valid_devs[0];
845e65da89cSCiara Power 	struct rte_cryptodev_info dev_info;
846e65da89cSCiara Power 	uint64_t feat_flags;
847e65da89cSCiara Power 	const enum rte_crypto_cipher_algorithm ciphers[] = {
848e65da89cSCiara Power 		RTE_CRYPTO_CIPHER_NULL,
849e65da89cSCiara Power 		RTE_CRYPTO_CIPHER_AES_CTR,
850e65da89cSCiara Power 		RTE_CRYPTO_CIPHER_AES_CBC
851e65da89cSCiara Power 	};
852e65da89cSCiara Power 	const enum rte_crypto_auth_algorithm auths[] = {
853e65da89cSCiara Power 		RTE_CRYPTO_AUTH_NULL,
854e65da89cSCiara Power 		RTE_CRYPTO_AUTH_SHA1_HMAC,
855e65da89cSCiara Power 		RTE_CRYPTO_AUTH_AES_XCBC_MAC,
856e65da89cSCiara Power 		RTE_CRYPTO_AUTH_SHA256_HMAC,
857e65da89cSCiara Power 		RTE_CRYPTO_AUTH_SHA512_HMAC,
858e65da89cSCiara Power 		RTE_CRYPTO_AUTH_SHA224_HMAC,
859e65da89cSCiara Power 		RTE_CRYPTO_AUTH_SHA384_HMAC
860e65da89cSCiara Power 	};
861e65da89cSCiara Power 
862e65da89cSCiara Power 	rte_cryptodev_info_get(dev_id, &dev_info);
863e65da89cSCiara Power 	feat_flags = dev_info.feature_flags;
864e65da89cSCiara Power 
865e65da89cSCiara Power 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
866e65da89cSCiara Power 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
867e65da89cSCiara Power 			!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
868e65da89cSCiara Power 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES Chain "
869e65da89cSCiara Power 				"testsuite not met\n");
870e65da89cSCiara Power 		return TEST_SKIPPED;
871e65da89cSCiara Power 	}
872e65da89cSCiara Power 
873e65da89cSCiara Power 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
874e65da89cSCiara Power 			&& check_auth_capabilities_supported(auths,
875e65da89cSCiara Power 			RTE_DIM(auths)) != 0) {
876e65da89cSCiara Power 		RTE_LOG(INFO, USER1, "Capability requirements for AES Chain "
877e65da89cSCiara Power 				"testsuite not met\n");
878e65da89cSCiara Power 		return TEST_SKIPPED;
879e65da89cSCiara Power 	}
880e65da89cSCiara Power 
881e65da89cSCiara Power 	return 0;
882e65da89cSCiara Power }
883e65da89cSCiara Power 
884e65da89cSCiara Power static int
aes_cipheronly_setup(void)885e65da89cSCiara Power aes_cipheronly_setup(void)
886e65da89cSCiara Power {
887e65da89cSCiara Power 	uint8_t dev_id = p_testsuite_params->valid_devs[0];
888e65da89cSCiara Power 	struct rte_cryptodev_info dev_info;
889e65da89cSCiara Power 	uint64_t feat_flags;
890e65da89cSCiara Power 	const enum rte_crypto_cipher_algorithm ciphers[] = {
891e65da89cSCiara Power 		RTE_CRYPTO_CIPHER_NULL,
892e65da89cSCiara Power 		RTE_CRYPTO_CIPHER_AES_CTR,
893e65da89cSCiara Power 		RTE_CRYPTO_CIPHER_AES_CBC,
894e65da89cSCiara Power 		RTE_CRYPTO_CIPHER_AES_ECB,
895e65da89cSCiara Power 		RTE_CRYPTO_CIPHER_AES_XTS
896e65da89cSCiara Power 	};
897e65da89cSCiara Power 	const enum rte_crypto_auth_algorithm auths[] = {
898e65da89cSCiara Power 		RTE_CRYPTO_AUTH_NULL,
899e65da89cSCiara Power 		RTE_CRYPTO_AUTH_SHA1_HMAC,
900e65da89cSCiara Power 		RTE_CRYPTO_AUTH_AES_XCBC_MAC
901e65da89cSCiara Power 	};
902e65da89cSCiara Power 
903e65da89cSCiara Power 	rte_cryptodev_info_get(dev_id, &dev_info);
904e65da89cSCiara Power 	feat_flags = dev_info.feature_flags;
905e65da89cSCiara Power 
906e65da89cSCiara Power 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
907e65da89cSCiara Power 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
908e65da89cSCiara Power 			!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
909e65da89cSCiara Power 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES Cipheronly "
910e65da89cSCiara Power 				"testsuite not met\n");
911e65da89cSCiara Power 		return TEST_SKIPPED;
912e65da89cSCiara Power 	}
913e65da89cSCiara Power 
914e65da89cSCiara Power 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
915e65da89cSCiara Power 			&& check_auth_capabilities_supported(auths,
916e65da89cSCiara Power 			RTE_DIM(auths)) != 0) {
917e65da89cSCiara Power 		RTE_LOG(INFO, USER1, "Capability requirements for AES Cipheronly "
918e65da89cSCiara Power 				"testsuite not met\n");
919e65da89cSCiara Power 		return TEST_SKIPPED;
920e65da89cSCiara Power 	}
921e65da89cSCiara Power 
922e65da89cSCiara Power 	return 0;
923e65da89cSCiara Power }
924e65da89cSCiara Power 
925e65da89cSCiara Power static int
aes_docsis_setup(void)926e65da89cSCiara Power aes_docsis_setup(void)
927e65da89cSCiara Power {
928e65da89cSCiara Power 	uint8_t dev_id = p_testsuite_params->valid_devs[0];
929e65da89cSCiara Power 	struct rte_cryptodev_info dev_info;
930e65da89cSCiara Power 	uint64_t feat_flags;
931e65da89cSCiara Power 	const enum rte_crypto_cipher_algorithm ciphers[] = {
932e65da89cSCiara Power 		RTE_CRYPTO_CIPHER_AES_DOCSISBPI
933e65da89cSCiara Power 	};
934e65da89cSCiara Power 
935e65da89cSCiara Power 	rte_cryptodev_info_get(dev_id, &dev_info);
936e65da89cSCiara Power 	feat_flags = dev_info.feature_flags;
937e65da89cSCiara Power 
938e65da89cSCiara Power 	/* Data-path service does not support DOCSIS yet */
939e65da89cSCiara Power 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
940e65da89cSCiara Power 			(global_api_test_type == CRYPTODEV_RAW_API_TEST)) {
941e65da89cSCiara Power 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES Docsis "
942e65da89cSCiara Power 				"testsuite not met\n");
943e65da89cSCiara Power 		return TEST_SKIPPED;
944e65da89cSCiara Power 	}
945e65da89cSCiara Power 
946e65da89cSCiara Power 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
947e65da89cSCiara Power 		RTE_LOG(INFO, USER1, "Capability requirements for AES Docsis "
948e65da89cSCiara Power 				"testsuite not met\n");
949e65da89cSCiara Power 		return TEST_SKIPPED;
950e65da89cSCiara Power 	}
951e65da89cSCiara Power 
952e65da89cSCiara Power 	return 0;
953e65da89cSCiara Power }
954e65da89cSCiara Power 
955e65da89cSCiara Power static int
triple_des_chain_setup(void)956e65da89cSCiara Power triple_des_chain_setup(void)
957e65da89cSCiara Power {
958e65da89cSCiara Power 	uint8_t dev_id = p_testsuite_params->valid_devs[0];
959e65da89cSCiara Power 	struct rte_cryptodev_info dev_info;
960e65da89cSCiara Power 	uint64_t feat_flags;
961e65da89cSCiara Power 	const enum rte_crypto_cipher_algorithm ciphers[] = {
962e65da89cSCiara Power 		RTE_CRYPTO_CIPHER_3DES_CTR,
963e65da89cSCiara Power 		RTE_CRYPTO_CIPHER_3DES_CBC
964e65da89cSCiara Power 	};
965e65da89cSCiara Power 	const enum rte_crypto_auth_algorithm auths[] = {
966e65da89cSCiara Power 		RTE_CRYPTO_AUTH_SHA1_HMAC,
967e65da89cSCiara Power 		RTE_CRYPTO_AUTH_SHA1
968e65da89cSCiara Power 	};
969e65da89cSCiara Power 
970e65da89cSCiara Power 	rte_cryptodev_info_get(dev_id, &dev_info);
971e65da89cSCiara Power 	feat_flags = dev_info.feature_flags;
972e65da89cSCiara Power 
973e65da89cSCiara Power 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
974e65da89cSCiara Power 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
975e65da89cSCiara Power 			!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
976e65da89cSCiara Power 		RTE_LOG(INFO, USER1, "Feature flag requirements for 3DES Chain "
977e65da89cSCiara Power 				"testsuite not met\n");
978e65da89cSCiara Power 		return TEST_SKIPPED;
979e65da89cSCiara Power 	}
980e65da89cSCiara Power 
981e65da89cSCiara Power 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
982e65da89cSCiara Power 			&& check_auth_capabilities_supported(auths,
983e65da89cSCiara Power 			RTE_DIM(auths)) != 0) {
984e65da89cSCiara Power 		RTE_LOG(INFO, USER1, "Capability requirements for 3DES Chain "
985e65da89cSCiara Power 				"testsuite not met\n");
986e65da89cSCiara Power 		return TEST_SKIPPED;
987e65da89cSCiara Power 	}
988e65da89cSCiara Power 
989e65da89cSCiara Power 	return 0;
990e65da89cSCiara Power }
991e65da89cSCiara Power 
992e65da89cSCiara Power static int
triple_des_cipheronly_setup(void)993e65da89cSCiara Power triple_des_cipheronly_setup(void)
994e65da89cSCiara Power {
995e65da89cSCiara Power 	uint8_t dev_id = p_testsuite_params->valid_devs[0];
996e65da89cSCiara Power 	struct rte_cryptodev_info dev_info;
997e65da89cSCiara Power 	uint64_t feat_flags;
998e65da89cSCiara Power 	const enum rte_crypto_cipher_algorithm ciphers[] = {
999e65da89cSCiara Power 		RTE_CRYPTO_CIPHER_3DES_CTR,
1000e65da89cSCiara Power 		RTE_CRYPTO_CIPHER_3DES_CBC
1001e65da89cSCiara Power 	};
1002e65da89cSCiara Power 
1003e65da89cSCiara Power 	rte_cryptodev_info_get(dev_id, &dev_info);
1004e65da89cSCiara Power 	feat_flags = dev_info.feature_flags;
1005e65da89cSCiara Power 
1006e65da89cSCiara Power 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1007e65da89cSCiara Power 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1008e65da89cSCiara Power 			!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1009e65da89cSCiara Power 		RTE_LOG(INFO, USER1, "Feature flag requirements for 3DES "
1010e65da89cSCiara Power 				"Cipheronly testsuite not met\n");
1011e65da89cSCiara Power 		return TEST_SKIPPED;
1012e65da89cSCiara Power 	}
1013e65da89cSCiara Power 
1014e65da89cSCiara Power 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
1015e65da89cSCiara Power 		RTE_LOG(INFO, USER1, "Capability requirements for 3DES "
1016e65da89cSCiara Power 				"Cipheronly testsuite not met\n");
1017e65da89cSCiara Power 		return TEST_SKIPPED;
1018e65da89cSCiara Power 	}
1019e65da89cSCiara Power 
1020e65da89cSCiara Power 	return 0;
1021e65da89cSCiara Power }
1022e65da89cSCiara Power 
1023e65da89cSCiara Power static int
des_cipheronly_setup(void)1024e65da89cSCiara Power des_cipheronly_setup(void)
1025e65da89cSCiara Power {
1026e65da89cSCiara Power 	uint8_t dev_id = p_testsuite_params->valid_devs[0];
1027e65da89cSCiara Power 	struct rte_cryptodev_info dev_info;
1028e65da89cSCiara Power 	uint64_t feat_flags;
1029e65da89cSCiara Power 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1030e65da89cSCiara Power 		RTE_CRYPTO_CIPHER_DES_CBC
1031e65da89cSCiara Power 	};
1032e65da89cSCiara Power 
1033e65da89cSCiara Power 	rte_cryptodev_info_get(dev_id, &dev_info);
1034e65da89cSCiara Power 	feat_flags = dev_info.feature_flags;
1035e65da89cSCiara Power 
1036e65da89cSCiara Power 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1037e65da89cSCiara Power 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1038e65da89cSCiara Power 			!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1039e65da89cSCiara Power 		RTE_LOG(INFO, USER1, "Feature flag requirements for DES "
1040e65da89cSCiara Power 				"Cipheronly testsuite not met\n");
1041e65da89cSCiara Power 		return TEST_SKIPPED;
1042e65da89cSCiara Power 	}
1043e65da89cSCiara Power 
1044e65da89cSCiara Power 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
1045e65da89cSCiara Power 		RTE_LOG(INFO, USER1, "Capability requirements for DES "
1046e65da89cSCiara Power 				"Cipheronly testsuite not met\n");
1047e65da89cSCiara Power 		return TEST_SKIPPED;
1048e65da89cSCiara Power 	}
1049e65da89cSCiara Power 
1050e65da89cSCiara Power 	return 0;
1051e65da89cSCiara Power }
1052e65da89cSCiara Power 
1053e65da89cSCiara Power static int
des_docsis_setup(void)1054e65da89cSCiara Power des_docsis_setup(void)
1055e65da89cSCiara Power {
1056e65da89cSCiara Power 	uint8_t dev_id = p_testsuite_params->valid_devs[0];
1057e65da89cSCiara Power 	struct rte_cryptodev_info dev_info;
1058e65da89cSCiara Power 	uint64_t feat_flags;
1059e65da89cSCiara Power 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1060e65da89cSCiara Power 		RTE_CRYPTO_CIPHER_DES_DOCSISBPI
1061e65da89cSCiara Power 	};
1062e65da89cSCiara Power 
1063e65da89cSCiara Power 	rte_cryptodev_info_get(dev_id, &dev_info);
1064e65da89cSCiara Power 	feat_flags = dev_info.feature_flags;
1065e65da89cSCiara Power 
1066e65da89cSCiara Power 	/* Data-path service does not support DOCSIS yet */
1067e65da89cSCiara Power 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1068e65da89cSCiara Power 			(global_api_test_type == CRYPTODEV_RAW_API_TEST)) {
1069e65da89cSCiara Power 		RTE_LOG(INFO, USER1, "Feature flag requirements for DES Docsis "
1070e65da89cSCiara Power 				"testsuite not met\n");
1071e65da89cSCiara Power 		return TEST_SKIPPED;
1072e65da89cSCiara Power 	}
1073e65da89cSCiara Power 
1074e65da89cSCiara Power 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
1075e65da89cSCiara Power 		RTE_LOG(INFO, USER1, "Capability requirements for DES Docsis "
1076e65da89cSCiara Power 				"testsuite not met\n");
1077e65da89cSCiara Power 		return TEST_SKIPPED;
1078e65da89cSCiara Power 	}
1079e65da89cSCiara Power 
1080e65da89cSCiara Power 	return 0;
1081e65da89cSCiara Power }
1082e65da89cSCiara Power 
1083e65da89cSCiara Power static int
authonly_setup(void)1084e65da89cSCiara Power authonly_setup(void)
1085e65da89cSCiara Power {
1086e65da89cSCiara Power 	uint8_t dev_id = p_testsuite_params->valid_devs[0];
1087e65da89cSCiara Power 	struct rte_cryptodev_info dev_info;
1088e65da89cSCiara Power 	uint64_t feat_flags;
1089e65da89cSCiara Power 	const enum rte_crypto_auth_algorithm auths[] = {
1090e65da89cSCiara Power 		RTE_CRYPTO_AUTH_MD5,
1091e65da89cSCiara Power 		RTE_CRYPTO_AUTH_MD5_HMAC,
1092e65da89cSCiara Power 		RTE_CRYPTO_AUTH_SHA1,
1093e65da89cSCiara Power 		RTE_CRYPTO_AUTH_SHA1_HMAC,
1094e65da89cSCiara Power 		RTE_CRYPTO_AUTH_SHA224,
1095e65da89cSCiara Power 		RTE_CRYPTO_AUTH_SHA224_HMAC,
1096e65da89cSCiara Power 		RTE_CRYPTO_AUTH_SHA256,
1097e65da89cSCiara Power 		RTE_CRYPTO_AUTH_SHA256_HMAC,
1098e65da89cSCiara Power 		RTE_CRYPTO_AUTH_SHA384,
1099e65da89cSCiara Power 		RTE_CRYPTO_AUTH_SHA384_HMAC,
1100e65da89cSCiara Power 		RTE_CRYPTO_AUTH_SHA512,
1101e65da89cSCiara Power 		RTE_CRYPTO_AUTH_SHA512_HMAC,
1102e65da89cSCiara Power 		RTE_CRYPTO_AUTH_AES_CMAC,
1103e65da89cSCiara Power 		RTE_CRYPTO_AUTH_NULL,
1104e65da89cSCiara Power 		RTE_CRYPTO_AUTH_AES_XCBC_MAC
1105e65da89cSCiara Power 	};
1106e65da89cSCiara Power 
1107e65da89cSCiara Power 	rte_cryptodev_info_get(dev_id, &dev_info);
1108e65da89cSCiara Power 	feat_flags = dev_info.feature_flags;
1109e65da89cSCiara Power 
1110e65da89cSCiara Power 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1111e65da89cSCiara Power 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1112e65da89cSCiara Power 			!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1113e65da89cSCiara Power 		RTE_LOG(INFO, USER1, "Feature flag requirements for Auth Only "
1114e65da89cSCiara Power 				"testsuite not met\n");
1115e65da89cSCiara Power 		return TEST_SKIPPED;
1116e65da89cSCiara Power 	}
1117e65da89cSCiara Power 
1118e65da89cSCiara Power 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1119e65da89cSCiara Power 		RTE_LOG(INFO, USER1, "Capability requirements for Auth Only "
1120e65da89cSCiara Power 				"testsuite not met\n");
1121e65da89cSCiara Power 		return TEST_SKIPPED;
1122e65da89cSCiara Power 	}
1123e65da89cSCiara Power 
1124e65da89cSCiara Power 	return 0;
1125e65da89cSCiara Power }
1126e65da89cSCiara Power 
1127e65da89cSCiara Power struct unit_test_suite *
build_blockcipher_test_suite(enum blockcipher_test_type test_type)1128e65da89cSCiara Power build_blockcipher_test_suite(enum blockcipher_test_type test_type)
1129e65da89cSCiara Power {
1130e65da89cSCiara Power 	int i, n_test_cases = 0;
1131e65da89cSCiara Power 	struct unit_test_suite *ts;
1132e65da89cSCiara Power 	const char *ts_name = NULL;
1133e65da89cSCiara Power 	const struct blockcipher_test_case *blk_tcs;
1134e65da89cSCiara Power 	struct unit_test_case *tc;
1135e65da89cSCiara Power 	int (*ts_setup)(void) = NULL;
1136a9de470cSBruce Richardson 
1137a9de470cSBruce Richardson 	switch (test_type) {
1138a9de470cSBruce Richardson 	case BLKCIPHER_AES_CHAIN_TYPE:
1139e65da89cSCiara Power 		n_test_cases = RTE_DIM(aes_chain_test_cases);
1140e65da89cSCiara Power 		blk_tcs = aes_chain_test_cases;
1141e65da89cSCiara Power 		ts_name = "AES Chain";
1142e65da89cSCiara Power 		ts_setup = aes_chain_setup;
1143a9de470cSBruce Richardson 		break;
1144a9de470cSBruce Richardson 	case BLKCIPHER_AES_CIPHERONLY_TYPE:
1145e65da89cSCiara Power 		n_test_cases = RTE_DIM(aes_cipheronly_test_cases);
1146e65da89cSCiara Power 		blk_tcs = aes_cipheronly_test_cases;
1147e65da89cSCiara Power 		ts_name = "AES Cipher Only";
1148e65da89cSCiara Power 		ts_setup = aes_cipheronly_setup;
1149a9de470cSBruce Richardson 		break;
1150a9de470cSBruce Richardson 	case BLKCIPHER_AES_DOCSIS_TYPE:
1151e65da89cSCiara Power 		n_test_cases = RTE_DIM(aes_docsis_test_cases);
1152e65da89cSCiara Power 		blk_tcs = aes_docsis_test_cases;
1153e65da89cSCiara Power 		ts_name = "AES Docsis";
1154e65da89cSCiara Power 		ts_setup = aes_docsis_setup;
1155a9de470cSBruce Richardson 		break;
1156a9de470cSBruce Richardson 	case BLKCIPHER_3DES_CHAIN_TYPE:
1157e65da89cSCiara Power 		n_test_cases = RTE_DIM(triple_des_chain_test_cases);
1158e65da89cSCiara Power 		blk_tcs = triple_des_chain_test_cases;
1159e65da89cSCiara Power 		ts_name = "3DES Chain";
1160e65da89cSCiara Power 		ts_setup = triple_des_chain_setup;
1161a9de470cSBruce Richardson 		break;
1162a9de470cSBruce Richardson 	case BLKCIPHER_3DES_CIPHERONLY_TYPE:
1163e65da89cSCiara Power 		n_test_cases = RTE_DIM(triple_des_cipheronly_test_cases);
1164e65da89cSCiara Power 		blk_tcs = triple_des_cipheronly_test_cases;
1165e65da89cSCiara Power 		ts_name = "3DES Cipher Only";
1166e65da89cSCiara Power 		ts_setup = triple_des_cipheronly_setup;
1167a9de470cSBruce Richardson 		break;
1168a9de470cSBruce Richardson 	case BLKCIPHER_DES_CIPHERONLY_TYPE:
1169e65da89cSCiara Power 		n_test_cases = RTE_DIM(des_cipheronly_test_cases);
1170e65da89cSCiara Power 		blk_tcs = des_cipheronly_test_cases;
1171e65da89cSCiara Power 		ts_name = "DES Cipher Only";
1172e65da89cSCiara Power 		ts_setup = des_cipheronly_setup;
1173a9de470cSBruce Richardson 		break;
1174a9de470cSBruce Richardson 	case BLKCIPHER_DES_DOCSIS_TYPE:
1175e65da89cSCiara Power 		n_test_cases = RTE_DIM(des_docsis_test_cases);
1176e65da89cSCiara Power 		blk_tcs = des_docsis_test_cases;
1177e65da89cSCiara Power 		ts_name = "DES Docsis";
1178e65da89cSCiara Power 		ts_setup = des_docsis_setup;
1179a9de470cSBruce Richardson 		break;
1180a9de470cSBruce Richardson 	case BLKCIPHER_AUTHONLY_TYPE:
1181e65da89cSCiara Power 		n_test_cases = RTE_DIM(hash_test_cases);
1182e65da89cSCiara Power 		blk_tcs = hash_test_cases;
1183e65da89cSCiara Power 		ts_name = "Auth Only";
1184e65da89cSCiara Power 		ts_setup = authonly_setup;
1185a9de470cSBruce Richardson 		break;
1186a9de470cSBruce Richardson 	default:
11879c8c8064SThomas Monjalon 		return NULL;
1188a9de470cSBruce Richardson 	}
1189a9de470cSBruce Richardson 
1190e65da89cSCiara Power 	ts = calloc(1, sizeof(struct unit_test_suite) +
1191e65da89cSCiara Power 			(sizeof(struct unit_test_case) * (n_test_cases + 1)));
1192e65da89cSCiara Power 	ts->suite_name = ts_name;
1193e65da89cSCiara Power 	ts->setup = ts_setup;
1194e65da89cSCiara Power 
1195a9de470cSBruce Richardson 	for (i = 0; i < n_test_cases; i++) {
1196e65da89cSCiara Power 		tc = &ts->unit_test_cases[i];
1197e65da89cSCiara Power 		tc->name = blk_tcs[i].test_descr;
1198e65da89cSCiara Power 		tc->enabled = 1;
1199e65da89cSCiara Power 		tc->setup = ut_setup;
1200e65da89cSCiara Power 		tc->teardown = ut_teardown;
1201e65da89cSCiara Power 		tc->testcase = NULL;
1202e65da89cSCiara Power 		tc->testcase_with_data = blockcipher_test_case_run;
1203e65da89cSCiara Power 		tc->data = &blk_tcs[i];
1204a9de470cSBruce Richardson 	}
1205e65da89cSCiara Power 	tc = &ts->unit_test_cases[i];
1206e65da89cSCiara Power 	tc->name = NULL;
1207e65da89cSCiara Power 	tc->enabled = 0;
1208e65da89cSCiara Power 	tc->setup = NULL;
1209e65da89cSCiara Power 	tc->teardown = NULL;
1210e65da89cSCiara Power 	tc->testcase = NULL;
1211e65da89cSCiara Power 	tc->testcase_with_data = NULL;
1212e65da89cSCiara Power 	tc->data = NULL;
1213e65da89cSCiara Power 
1214e65da89cSCiara Power 	return ts;
1215a9de470cSBruce Richardson }
1216a9de470cSBruce Richardson 
1217e65da89cSCiara Power void
free_blockcipher_test_suite(struct unit_test_suite * ts)1218e65da89cSCiara Power free_blockcipher_test_suite(struct unit_test_suite *ts)
1219e65da89cSCiara Power {
1220e65da89cSCiara Power 	free(ts);
1221a9de470cSBruce Richardson }
1222*3c60274cSJie Zhou 
1223*3c60274cSJie Zhou #endif /* !RTE_EXEC_ENV_WINDOWS */
1224