14418919fSjohnjiang /* SPDX-License-Identifier: BSD-3-Clause
24418919fSjohnjiang  * Copyright(c) 2015-2017 Intel Corporation
34418919fSjohnjiang  */
44418919fSjohnjiang 
54418919fSjohnjiang #include <rte_common.h>
64418919fSjohnjiang #include <rte_hexdump.h>
74418919fSjohnjiang #include <rte_mbuf.h>
84418919fSjohnjiang #include <rte_malloc.h>
94418919fSjohnjiang #include <rte_memcpy.h>
104418919fSjohnjiang #include <rte_pause.h>
114418919fSjohnjiang 
124418919fSjohnjiang #include <rte_crypto.h>
134418919fSjohnjiang #include <rte_cryptodev.h>
144418919fSjohnjiang #include <rte_cryptodev_pmd.h>
154418919fSjohnjiang 
164418919fSjohnjiang #include "test.h"
174418919fSjohnjiang #include "test_cryptodev.h"
184418919fSjohnjiang #include "test_cryptodev_blockcipher.h"
194418919fSjohnjiang #include "test_cryptodev_aes_test_vectors.h"
204418919fSjohnjiang #include "test_cryptodev_des_test_vectors.h"
214418919fSjohnjiang #include "test_cryptodev_hash_test_vectors.h"
224418919fSjohnjiang 
234418919fSjohnjiang static int
verify_algo_support(const struct blockcipher_test_case * t,const uint8_t dev_id,const uint32_t digest_len)24*2d9fd380Sjfb8856606 verify_algo_support(const struct blockcipher_test_case *t,
25*2d9fd380Sjfb8856606 		const uint8_t dev_id, const uint32_t digest_len)
26*2d9fd380Sjfb8856606 {
27*2d9fd380Sjfb8856606 	int ret = 0;
28*2d9fd380Sjfb8856606 	const struct blockcipher_test_data *tdata = t->test_data;
29*2d9fd380Sjfb8856606 	struct rte_cryptodev_sym_capability_idx cap_idx;
30*2d9fd380Sjfb8856606 	const struct rte_cryptodev_symmetric_capability *capability;
31*2d9fd380Sjfb8856606 
32*2d9fd380Sjfb8856606 	if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
33*2d9fd380Sjfb8856606 		cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
34*2d9fd380Sjfb8856606 		cap_idx.algo.cipher = tdata->crypto_algo;
35*2d9fd380Sjfb8856606 		capability = rte_cryptodev_sym_capability_get(dev_id, &cap_idx);
36*2d9fd380Sjfb8856606 		if (capability == NULL)
37*2d9fd380Sjfb8856606 			return -1;
38*2d9fd380Sjfb8856606 
39*2d9fd380Sjfb8856606 		if (cap_idx.algo.cipher != RTE_CRYPTO_CIPHER_NULL)
40*2d9fd380Sjfb8856606 			ret = rte_cryptodev_sym_capability_check_cipher(capability,
41*2d9fd380Sjfb8856606 							tdata->cipher_key.len,
42*2d9fd380Sjfb8856606 							tdata->iv.len);
43*2d9fd380Sjfb8856606 		if (ret != 0)
44*2d9fd380Sjfb8856606 			return -1;
45*2d9fd380Sjfb8856606 	}
46*2d9fd380Sjfb8856606 
47*2d9fd380Sjfb8856606 	if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) {
48*2d9fd380Sjfb8856606 		cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
49*2d9fd380Sjfb8856606 		cap_idx.algo.auth = tdata->auth_algo;
50*2d9fd380Sjfb8856606 		capability = rte_cryptodev_sym_capability_get(dev_id, &cap_idx);
51*2d9fd380Sjfb8856606 		if (capability == NULL)
52*2d9fd380Sjfb8856606 			return -1;
53*2d9fd380Sjfb8856606 
54*2d9fd380Sjfb8856606 		if (cap_idx.algo.auth != RTE_CRYPTO_AUTH_NULL)
55*2d9fd380Sjfb8856606 			ret = rte_cryptodev_sym_capability_check_auth(capability,
56*2d9fd380Sjfb8856606 							tdata->auth_key.len,
57*2d9fd380Sjfb8856606 							digest_len,
58*2d9fd380Sjfb8856606 							0);
59*2d9fd380Sjfb8856606 		if (ret != 0)
60*2d9fd380Sjfb8856606 			return -1;
61*2d9fd380Sjfb8856606 	}
62*2d9fd380Sjfb8856606 
63*2d9fd380Sjfb8856606 	return 0;
64*2d9fd380Sjfb8856606 }
65*2d9fd380Sjfb8856606 
66*2d9fd380Sjfb8856606 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)674418919fSjohnjiang test_blockcipher_one_case(const struct blockcipher_test_case *t,
684418919fSjohnjiang 	struct rte_mempool *mbuf_pool,
694418919fSjohnjiang 	struct rte_mempool *op_mpool,
704418919fSjohnjiang 	struct rte_mempool *sess_mpool,
714418919fSjohnjiang 	struct rte_mempool *sess_priv_mpool,
724418919fSjohnjiang 	uint8_t dev_id,
734418919fSjohnjiang 	char *test_msg)
744418919fSjohnjiang {
754418919fSjohnjiang 	struct rte_mbuf *ibuf = NULL;
764418919fSjohnjiang 	struct rte_mbuf *obuf = NULL;
774418919fSjohnjiang 	struct rte_mbuf *iobuf;
784418919fSjohnjiang 	struct rte_crypto_sym_xform *cipher_xform = NULL;
794418919fSjohnjiang 	struct rte_crypto_sym_xform *auth_xform = NULL;
804418919fSjohnjiang 	struct rte_crypto_sym_xform *init_xform = NULL;
814418919fSjohnjiang 	struct rte_crypto_sym_op *sym_op = NULL;
824418919fSjohnjiang 	struct rte_crypto_op *op = NULL;
834418919fSjohnjiang 	struct rte_cryptodev_info dev_info;
844418919fSjohnjiang 	struct rte_cryptodev_sym_session *sess = NULL;
854418919fSjohnjiang 
864418919fSjohnjiang 	int status = TEST_SUCCESS;
874418919fSjohnjiang 	const struct blockcipher_test_data *tdata = t->test_data;
884418919fSjohnjiang 	uint8_t cipher_key[tdata->cipher_key.len];
894418919fSjohnjiang 	uint8_t auth_key[tdata->auth_key.len];
904418919fSjohnjiang 	uint32_t buf_len = tdata->ciphertext.len;
91*2d9fd380Sjfb8856606 	uint32_t digest_len = tdata->digest.len;
924418919fSjohnjiang 	char *buf_p = NULL;
934418919fSjohnjiang 	uint8_t src_pattern = 0xa5;
944418919fSjohnjiang 	uint8_t dst_pattern = 0xb6;
954418919fSjohnjiang 	uint8_t tmp_src_buf[MBUF_SIZE];
964418919fSjohnjiang 	uint8_t tmp_dst_buf[MBUF_SIZE];
974418919fSjohnjiang 
984418919fSjohnjiang 	int nb_segs = 1;
994418919fSjohnjiang 	uint32_t nb_iterates = 0;
1004418919fSjohnjiang 
1014418919fSjohnjiang 	rte_cryptodev_info_get(dev_id, &dev_info);
1024418919fSjohnjiang 	uint64_t feat_flags = dev_info.feature_flags;
103*2d9fd380Sjfb8856606 
104*2d9fd380Sjfb8856606 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
105*2d9fd380Sjfb8856606 		if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
106*2d9fd380Sjfb8856606 			printf("Device doesn't support sessionless operations "
107*2d9fd380Sjfb8856606 				"Test Skipped.\n");
108*2d9fd380Sjfb8856606 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
109*2d9fd380Sjfb8856606 				"SKIPPED");
110*2d9fd380Sjfb8856606 			return TEST_SKIPPED;
111*2d9fd380Sjfb8856606 		}
112*2d9fd380Sjfb8856606 	}
113*2d9fd380Sjfb8856606 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SG) {
1144418919fSjohnjiang 		uint64_t oop_flag = RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT;
1154418919fSjohnjiang 
1160c6bd470Sfengbojiang 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
1174418919fSjohnjiang 			if (!(feat_flags & oop_flag)) {
1184418919fSjohnjiang 				printf("Device doesn't support out-of-place "
1194418919fSjohnjiang 					"scatter-gather in input mbuf. "
1204418919fSjohnjiang 					"Test Skipped.\n");
121*2d9fd380Sjfb8856606 				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
122*2d9fd380Sjfb8856606 					"SKIPPED");
123*2d9fd380Sjfb8856606 				return TEST_SKIPPED;
1244418919fSjohnjiang 			}
1254418919fSjohnjiang 		} else {
1264418919fSjohnjiang 			if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
1274418919fSjohnjiang 				printf("Device doesn't support in-place "
1284418919fSjohnjiang 					"scatter-gather mbufs. "
1294418919fSjohnjiang 					"Test Skipped.\n");
130*2d9fd380Sjfb8856606 				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
131*2d9fd380Sjfb8856606 					"SKIPPED");
132*2d9fd380Sjfb8856606 				return TEST_SKIPPED;
1334418919fSjohnjiang 			}
1344418919fSjohnjiang 		}
1354418919fSjohnjiang 
1364418919fSjohnjiang 		nb_segs = 3;
1374418919fSjohnjiang 	}
1384418919fSjohnjiang 
139*2d9fd380Sjfb8856606 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST &&
140*2d9fd380Sjfb8856606 		!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP)) {
141*2d9fd380Sjfb8856606 		printf("Device doesn't support raw data-path APIs. "
142*2d9fd380Sjfb8856606 			"Test Skipped.\n");
143*2d9fd380Sjfb8856606 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "SKIPPED");
144*2d9fd380Sjfb8856606 		return TEST_SKIPPED;
145*2d9fd380Sjfb8856606 	}
146*2d9fd380Sjfb8856606 
147*2d9fd380Sjfb8856606 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
148*2d9fd380Sjfb8856606 		uint64_t oop_flags = RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT |
149*2d9fd380Sjfb8856606 			RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT |
150*2d9fd380Sjfb8856606 			RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
151*2d9fd380Sjfb8856606 			RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT;
152*2d9fd380Sjfb8856606 		if (!(feat_flags & oop_flags)) {
153*2d9fd380Sjfb8856606 			printf("Device doesn't support out-of-place operations."
154*2d9fd380Sjfb8856606 				"Test Skipped.\n");
155*2d9fd380Sjfb8856606 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
156*2d9fd380Sjfb8856606 				"SKIPPED");
157*2d9fd380Sjfb8856606 			return TEST_SKIPPED;
158*2d9fd380Sjfb8856606 		}
159*2d9fd380Sjfb8856606 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
160*2d9fd380Sjfb8856606 			printf("Raw Data Path APIs do not support OOP, "
161*2d9fd380Sjfb8856606 				"Test Skipped.\n");
162*2d9fd380Sjfb8856606 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "SKIPPED");
163*2d9fd380Sjfb8856606 			status = TEST_SUCCESS;
164*2d9fd380Sjfb8856606 			goto error_exit;
165*2d9fd380Sjfb8856606 		}
166*2d9fd380Sjfb8856606 	}
167*2d9fd380Sjfb8856606 
1684418919fSjohnjiang 	if (tdata->cipher_key.len)
1694418919fSjohnjiang 		memcpy(cipher_key, tdata->cipher_key.data,
1704418919fSjohnjiang 			tdata->cipher_key.len);
1714418919fSjohnjiang 	if (tdata->auth_key.len)
1724418919fSjohnjiang 		memcpy(auth_key, tdata->auth_key.data,
1734418919fSjohnjiang 			tdata->auth_key.len);
1744418919fSjohnjiang 
175*2d9fd380Sjfb8856606 	/* Check if PMD is capable of performing that test */
176*2d9fd380Sjfb8856606 	if (verify_algo_support(t, dev_id, digest_len) < 0) {
177*2d9fd380Sjfb8856606 		RTE_LOG(DEBUG, USER1,
178*2d9fd380Sjfb8856606 			"Device does not support this algorithm."
179*2d9fd380Sjfb8856606 			"Test Skipped.\n");
180*2d9fd380Sjfb8856606 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "SKIPPED");
181*2d9fd380Sjfb8856606 		return TEST_SKIPPED;
1824418919fSjohnjiang 	}
1834418919fSjohnjiang 
1844418919fSjohnjiang 	/* preparing data */
1854418919fSjohnjiang 	if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH)
1864418919fSjohnjiang 		buf_len += digest_len;
1874418919fSjohnjiang 
1884418919fSjohnjiang 	/* for contiguous mbuf, nb_segs is 1 */
1894418919fSjohnjiang 	ibuf = create_segmented_mbuf(mbuf_pool,
1904418919fSjohnjiang 			tdata->ciphertext.len, nb_segs, src_pattern);
1914418919fSjohnjiang 	if (ibuf == NULL) {
1924418919fSjohnjiang 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
1934418919fSjohnjiang 			"line %u FAILED: %s",
1944418919fSjohnjiang 			__LINE__, "Cannot create source mbuf");
1954418919fSjohnjiang 		status = TEST_FAILED;
1964418919fSjohnjiang 		goto error_exit;
1974418919fSjohnjiang 	}
1984418919fSjohnjiang 
1994418919fSjohnjiang 	/* only encryption requires plaintext.data input,
2004418919fSjohnjiang 	 * decryption/(digest gen)/(digest verify) use ciphertext.data
2014418919fSjohnjiang 	 * to be computed
2024418919fSjohnjiang 	 */
2034418919fSjohnjiang 	if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT)
2044418919fSjohnjiang 		pktmbuf_write(ibuf, 0, tdata->plaintext.len,
2054418919fSjohnjiang 				tdata->plaintext.data);
2064418919fSjohnjiang 	else
2074418919fSjohnjiang 		pktmbuf_write(ibuf, 0, tdata->ciphertext.len,
2084418919fSjohnjiang 				tdata->ciphertext.data);
2094418919fSjohnjiang 
2104418919fSjohnjiang 	buf_p = rte_pktmbuf_append(ibuf, digest_len);
2114418919fSjohnjiang 	if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY)
2124418919fSjohnjiang 		rte_memcpy(buf_p, tdata->digest.data, digest_len);
2134418919fSjohnjiang 	else
2144418919fSjohnjiang 		memset(buf_p, 0, digest_len);
2154418919fSjohnjiang 
2164418919fSjohnjiang 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
2174418919fSjohnjiang 		obuf = rte_pktmbuf_alloc(mbuf_pool);
2184418919fSjohnjiang 		if (!obuf) {
2194418919fSjohnjiang 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
2204418919fSjohnjiang 				"FAILED: %s", __LINE__,
2214418919fSjohnjiang 				"Allocation of rte_mbuf failed");
2224418919fSjohnjiang 			status = TEST_FAILED;
2234418919fSjohnjiang 			goto error_exit;
2244418919fSjohnjiang 		}
2254418919fSjohnjiang 		memset(obuf->buf_addr, dst_pattern, obuf->buf_len);
2264418919fSjohnjiang 
2274418919fSjohnjiang 		buf_p = rte_pktmbuf_append(obuf, buf_len);
2284418919fSjohnjiang 		if (!buf_p) {
2294418919fSjohnjiang 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
2304418919fSjohnjiang 				"FAILED: %s", __LINE__,
2314418919fSjohnjiang 				"No room to append mbuf");
2324418919fSjohnjiang 			status = TEST_FAILED;
2334418919fSjohnjiang 			goto error_exit;
2344418919fSjohnjiang 		}
2354418919fSjohnjiang 		memset(buf_p, 0, buf_len);
2364418919fSjohnjiang 	}
2374418919fSjohnjiang 
2384418919fSjohnjiang 	/* Generate Crypto op data structure */
2394418919fSjohnjiang 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2404418919fSjohnjiang 	if (!op) {
2414418919fSjohnjiang 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
2424418919fSjohnjiang 			"line %u FAILED: %s",
2434418919fSjohnjiang 			__LINE__, "Failed to allocate symmetric crypto "
2444418919fSjohnjiang 			"operation struct");
2454418919fSjohnjiang 		status = TEST_FAILED;
2464418919fSjohnjiang 		goto error_exit;
2474418919fSjohnjiang 	}
2484418919fSjohnjiang 
2494418919fSjohnjiang 	sym_op = op->sym;
2504418919fSjohnjiang 
2514418919fSjohnjiang iterate:
2524418919fSjohnjiang 	if (nb_iterates) {
2534418919fSjohnjiang 		struct rte_mbuf *tmp_buf = ibuf;
2544418919fSjohnjiang 
2554418919fSjohnjiang 		ibuf = obuf;
2564418919fSjohnjiang 		obuf = tmp_buf;
2574418919fSjohnjiang 
2584418919fSjohnjiang 		rte_pktmbuf_reset(ibuf);
2594418919fSjohnjiang 		rte_pktmbuf_reset(obuf);
2604418919fSjohnjiang 
2614418919fSjohnjiang 		rte_pktmbuf_append(ibuf, tdata->ciphertext.len);
2624418919fSjohnjiang 
2634418919fSjohnjiang 		/* only encryption requires plaintext.data input,
2644418919fSjohnjiang 		 * decryption/(digest gen)/(digest verify) use ciphertext.data
2654418919fSjohnjiang 		 * to be computed
2664418919fSjohnjiang 		 */
2674418919fSjohnjiang 		if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT)
2684418919fSjohnjiang 			pktmbuf_write(ibuf, 0, tdata->plaintext.len,
2694418919fSjohnjiang 					tdata->plaintext.data);
2704418919fSjohnjiang 		else
2714418919fSjohnjiang 			pktmbuf_write(ibuf, 0, tdata->ciphertext.len,
2724418919fSjohnjiang 					tdata->ciphertext.data);
2734418919fSjohnjiang 
2744418919fSjohnjiang 		buf_p = rte_pktmbuf_append(ibuf, digest_len);
2754418919fSjohnjiang 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY)
2764418919fSjohnjiang 			rte_memcpy(buf_p, tdata->digest.data, digest_len);
2774418919fSjohnjiang 		else
2784418919fSjohnjiang 			memset(buf_p, 0, digest_len);
2794418919fSjohnjiang 
2804418919fSjohnjiang 		memset(obuf->buf_addr, dst_pattern, obuf->buf_len);
2814418919fSjohnjiang 
2824418919fSjohnjiang 		buf_p = rte_pktmbuf_append(obuf, buf_len);
2834418919fSjohnjiang 		if (!buf_p) {
2844418919fSjohnjiang 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
2854418919fSjohnjiang 				"FAILED: %s", __LINE__,
2864418919fSjohnjiang 				"No room to append mbuf");
2874418919fSjohnjiang 			status = TEST_FAILED;
2884418919fSjohnjiang 			goto error_exit;
2894418919fSjohnjiang 		}
2904418919fSjohnjiang 		memset(buf_p, 0, buf_len);
2914418919fSjohnjiang 	}
2924418919fSjohnjiang 
2934418919fSjohnjiang 	sym_op->m_src = ibuf;
2944418919fSjohnjiang 
2954418919fSjohnjiang 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
2964418919fSjohnjiang 		sym_op->m_dst = obuf;
2974418919fSjohnjiang 		iobuf = obuf;
2984418919fSjohnjiang 	} else {
2994418919fSjohnjiang 		sym_op->m_dst = NULL;
3004418919fSjohnjiang 		iobuf = ibuf;
3014418919fSjohnjiang 	}
3024418919fSjohnjiang 
3034418919fSjohnjiang 	/* sessionless op requires allocate xform using
3044418919fSjohnjiang 	 * rte_crypto_op_sym_xforms_alloc(), otherwise rte_zmalloc()
3054418919fSjohnjiang 	 * is used
3064418919fSjohnjiang 	 */
3074418919fSjohnjiang 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
3084418919fSjohnjiang 		uint32_t n_xforms = 0;
3094418919fSjohnjiang 
3104418919fSjohnjiang 		if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER)
3114418919fSjohnjiang 			n_xforms++;
3124418919fSjohnjiang 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH)
3134418919fSjohnjiang 			n_xforms++;
3144418919fSjohnjiang 
3154418919fSjohnjiang 		if (rte_crypto_op_sym_xforms_alloc(op, n_xforms)
3164418919fSjohnjiang 			== NULL) {
3174418919fSjohnjiang 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
3184418919fSjohnjiang 				"FAILED: %s", __LINE__, "Failed to "
3194418919fSjohnjiang 				"allocate space for crypto transforms");
3204418919fSjohnjiang 			status = TEST_FAILED;
3214418919fSjohnjiang 			goto error_exit;
3224418919fSjohnjiang 		}
3234418919fSjohnjiang 	} else {
3244418919fSjohnjiang 		cipher_xform = rte_zmalloc(NULL,
3254418919fSjohnjiang 			sizeof(struct rte_crypto_sym_xform), 0);
3264418919fSjohnjiang 
3274418919fSjohnjiang 		auth_xform = rte_zmalloc(NULL,
3284418919fSjohnjiang 			sizeof(struct rte_crypto_sym_xform), 0);
3294418919fSjohnjiang 
3304418919fSjohnjiang 		if (!cipher_xform || !auth_xform) {
3314418919fSjohnjiang 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
3324418919fSjohnjiang 				"FAILED: %s", __LINE__, "Failed to "
3334418919fSjohnjiang 				"allocate memory for crypto transforms");
3344418919fSjohnjiang 			status = TEST_FAILED;
3354418919fSjohnjiang 			goto error_exit;
3364418919fSjohnjiang 		}
3374418919fSjohnjiang 	}
3384418919fSjohnjiang 
3394418919fSjohnjiang 	/* preparing xform, for sessioned op, init_xform is initialized
3404418919fSjohnjiang 	 * here and later as param in rte_cryptodev_sym_session_create() call
3414418919fSjohnjiang 	 */
3424418919fSjohnjiang 	if (t->op_mask == BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN) {
3434418919fSjohnjiang 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
3444418919fSjohnjiang 			cipher_xform = op->sym->xform;
3454418919fSjohnjiang 			auth_xform = cipher_xform->next;
3464418919fSjohnjiang 			auth_xform->next = NULL;
3474418919fSjohnjiang 		} else {
3484418919fSjohnjiang 			cipher_xform->next = auth_xform;
3494418919fSjohnjiang 			auth_xform->next = NULL;
3504418919fSjohnjiang 			init_xform = cipher_xform;
3514418919fSjohnjiang 		}
3524418919fSjohnjiang 	} else if (t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC) {
3534418919fSjohnjiang 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) {
3544418919fSjohnjiang 			auth_xform = op->sym->xform;
3554418919fSjohnjiang 			cipher_xform = auth_xform->next;
3564418919fSjohnjiang 			cipher_xform->next = NULL;
3574418919fSjohnjiang 		} else {
3584418919fSjohnjiang 			auth_xform->next = cipher_xform;
3594418919fSjohnjiang 			cipher_xform->next = NULL;
3604418919fSjohnjiang 			init_xform = auth_xform;
3614418919fSjohnjiang 		}
3624418919fSjohnjiang 	} else if ((t->op_mask == BLOCKCIPHER_TEST_OP_ENCRYPT) ||
3634418919fSjohnjiang 			(t->op_mask == BLOCKCIPHER_TEST_OP_DECRYPT)) {
3644418919fSjohnjiang 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)
3654418919fSjohnjiang 			cipher_xform = op->sym->xform;
3664418919fSjohnjiang 		else
3674418919fSjohnjiang 			init_xform = cipher_xform;
3684418919fSjohnjiang 		cipher_xform->next = NULL;
3694418919fSjohnjiang 	} else if ((t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_GEN) ||
3704418919fSjohnjiang 			(t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_VERIFY)) {
3714418919fSjohnjiang 		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)
3724418919fSjohnjiang 			auth_xform = op->sym->xform;
3734418919fSjohnjiang 		else
3744418919fSjohnjiang 			init_xform = auth_xform;
3754418919fSjohnjiang 		auth_xform->next = NULL;
3764418919fSjohnjiang 	} else {
3774418919fSjohnjiang 		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
3784418919fSjohnjiang 			"line %u FAILED: %s",
3794418919fSjohnjiang 			__LINE__, "Unrecognized operation");
3804418919fSjohnjiang 		status = TEST_FAILED;
3814418919fSjohnjiang 		goto error_exit;
3824418919fSjohnjiang 	}
3834418919fSjohnjiang 
3844418919fSjohnjiang 	/*configure xforms & sym_op cipher and auth data*/
3854418919fSjohnjiang 	if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
3864418919fSjohnjiang 		cipher_xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3874418919fSjohnjiang 		cipher_xform->cipher.algo = tdata->crypto_algo;
3884418919fSjohnjiang 		if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT)
3894418919fSjohnjiang 			cipher_xform->cipher.op =
3904418919fSjohnjiang 				RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3914418919fSjohnjiang 		else
3924418919fSjohnjiang 			cipher_xform->cipher.op =
3934418919fSjohnjiang 				RTE_CRYPTO_CIPHER_OP_DECRYPT;
3944418919fSjohnjiang 		cipher_xform->cipher.key.data = cipher_key;
3954418919fSjohnjiang 		cipher_xform->cipher.key.length = tdata->cipher_key.len;
3964418919fSjohnjiang 		cipher_xform->cipher.iv.offset = IV_OFFSET;
397*2d9fd380Sjfb8856606 
398*2d9fd380Sjfb8856606 		if (tdata->crypto_algo == RTE_CRYPTO_CIPHER_NULL)
399*2d9fd380Sjfb8856606 			cipher_xform->cipher.iv.length = 0;
400*2d9fd380Sjfb8856606 		else
4014418919fSjohnjiang 			cipher_xform->cipher.iv.length = tdata->iv.len;
4024418919fSjohnjiang 
4034418919fSjohnjiang 		sym_op->cipher.data.offset = tdata->cipher_offset;
4044418919fSjohnjiang 		sym_op->cipher.data.length = tdata->ciphertext.len -
4054418919fSjohnjiang 				tdata->cipher_offset;
4064418919fSjohnjiang 		rte_memcpy(rte_crypto_op_ctod_offset(op, uint8_t *, IV_OFFSET),
4074418919fSjohnjiang 				tdata->iv.data,
4084418919fSjohnjiang 				tdata->iv.len);
4094418919fSjohnjiang 	}
4104418919fSjohnjiang 
4114418919fSjohnjiang 	if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) {
4124418919fSjohnjiang 		uint32_t digest_offset = tdata->ciphertext.len;
4134418919fSjohnjiang 
4144418919fSjohnjiang 		auth_xform->type = RTE_CRYPTO_SYM_XFORM_AUTH;
4154418919fSjohnjiang 		auth_xform->auth.algo = tdata->auth_algo;
4164418919fSjohnjiang 		auth_xform->auth.key.length = tdata->auth_key.len;
4174418919fSjohnjiang 		auth_xform->auth.key.data = auth_key;
4184418919fSjohnjiang 		auth_xform->auth.digest_length = digest_len;
4194418919fSjohnjiang 
4204418919fSjohnjiang 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) {
4214418919fSjohnjiang 			auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4224418919fSjohnjiang 			sym_op->auth.digest.data = pktmbuf_mtod_offset
4234418919fSjohnjiang 				(iobuf, digest_offset);
4244418919fSjohnjiang 			sym_op->auth.digest.phys_addr =
4254418919fSjohnjiang 				pktmbuf_iova_offset(iobuf,
4264418919fSjohnjiang 					digest_offset);
4274418919fSjohnjiang 		} else {
4284418919fSjohnjiang 			auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
4294418919fSjohnjiang 			sym_op->auth.digest.data = pktmbuf_mtod_offset
4304418919fSjohnjiang 				(sym_op->m_src, digest_offset);
4314418919fSjohnjiang 			sym_op->auth.digest.phys_addr =
4324418919fSjohnjiang 				pktmbuf_iova_offset(sym_op->m_src,
4334418919fSjohnjiang 					digest_offset);
4344418919fSjohnjiang 		}
4354418919fSjohnjiang 
4364418919fSjohnjiang 		sym_op->auth.data.offset = tdata->auth_offset;
4374418919fSjohnjiang 		sym_op->auth.data.length = tdata->ciphertext.len -
4384418919fSjohnjiang 				tdata->auth_offset;
4394418919fSjohnjiang 	}
4404418919fSjohnjiang 
4414418919fSjohnjiang 	/**
4424418919fSjohnjiang 	 * Create session for sessioned op. For mbuf iteration test,
4434418919fSjohnjiang 	 * skip the session creation for the second iteration.
4444418919fSjohnjiang 	 */
4454418919fSjohnjiang 	if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) &&
4464418919fSjohnjiang 			nb_iterates == 0) {
4474418919fSjohnjiang 		sess = rte_cryptodev_sym_session_create(sess_mpool);
4484418919fSjohnjiang 
449*2d9fd380Sjfb8856606 		status = rte_cryptodev_sym_session_init(dev_id, sess,
450*2d9fd380Sjfb8856606 				init_xform, sess_priv_mpool);
451*2d9fd380Sjfb8856606 		if (status == -ENOTSUP) {
452*2d9fd380Sjfb8856606 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "UNSUPPORTED");
453*2d9fd380Sjfb8856606 			status = TEST_SKIPPED;
454*2d9fd380Sjfb8856606 			goto error_exit;
455*2d9fd380Sjfb8856606 		}
456*2d9fd380Sjfb8856606 		if (!sess || status < 0) {
4574418919fSjohnjiang 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
4584418919fSjohnjiang 				"FAILED: %s", __LINE__,
4594418919fSjohnjiang 				"Session creation failed");
4604418919fSjohnjiang 			status = TEST_FAILED;
4614418919fSjohnjiang 			goto error_exit;
4624418919fSjohnjiang 		}
4634418919fSjohnjiang 
4644418919fSjohnjiang 		/* attach symmetric crypto session to crypto operations */
4654418919fSjohnjiang 		rte_crypto_op_attach_sym_session(op, sess);
4664418919fSjohnjiang 	}
4674418919fSjohnjiang 
4684418919fSjohnjiang 	debug_hexdump(stdout, "m_src(before):",
4694418919fSjohnjiang 			sym_op->m_src->buf_addr, sym_op->m_src->buf_len);
4704418919fSjohnjiang 	rte_memcpy(tmp_src_buf, sym_op->m_src->buf_addr,
4714418919fSjohnjiang 						sym_op->m_src->buf_len);
4724418919fSjohnjiang 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
4734418919fSjohnjiang 		debug_hexdump(stdout, "m_dst(before):",
4744418919fSjohnjiang 			sym_op->m_dst->buf_addr, sym_op->m_dst->buf_len);
4754418919fSjohnjiang 		rte_memcpy(tmp_dst_buf, sym_op->m_dst->buf_addr,
4764418919fSjohnjiang 						sym_op->m_dst->buf_len);
4774418919fSjohnjiang 	}
4784418919fSjohnjiang 
4794418919fSjohnjiang 	/* Process crypto operation */
480*2d9fd380Sjfb8856606 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
481*2d9fd380Sjfb8856606 		uint8_t is_cipher = 0, is_auth = 0;
482*2d9fd380Sjfb8856606 		if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER)
483*2d9fd380Sjfb8856606 			is_cipher = 1;
484*2d9fd380Sjfb8856606 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH)
485*2d9fd380Sjfb8856606 			is_auth = 1;
486*2d9fd380Sjfb8856606 
487*2d9fd380Sjfb8856606 		process_sym_raw_dp_op(dev_id, 0, op, is_cipher, is_auth, 0,
488*2d9fd380Sjfb8856606 				tdata->iv.len);
489*2d9fd380Sjfb8856606 	} else {
4904418919fSjohnjiang 		if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
4914418919fSjohnjiang 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
4924418919fSjohnjiang 				"line %u FAILED: %s",
4934418919fSjohnjiang 				__LINE__, "Error sending packet for encryption");
4944418919fSjohnjiang 			status = TEST_FAILED;
4954418919fSjohnjiang 			goto error_exit;
4964418919fSjohnjiang 		}
4974418919fSjohnjiang 
4984418919fSjohnjiang 		op = NULL;
4994418919fSjohnjiang 
5004418919fSjohnjiang 		while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
5014418919fSjohnjiang 			rte_pause();
5024418919fSjohnjiang 
5034418919fSjohnjiang 		if (!op) {
5044418919fSjohnjiang 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
5054418919fSjohnjiang 				"line %u FAILED: %s",
5064418919fSjohnjiang 				__LINE__, "Failed to process sym crypto op");
5074418919fSjohnjiang 			status = TEST_FAILED;
5084418919fSjohnjiang 			goto error_exit;
5094418919fSjohnjiang 		}
510*2d9fd380Sjfb8856606 	}
5114418919fSjohnjiang 
5124418919fSjohnjiang 	debug_hexdump(stdout, "m_src(after):",
5134418919fSjohnjiang 			sym_op->m_src->buf_addr, sym_op->m_src->buf_len);
5144418919fSjohnjiang 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP)
5154418919fSjohnjiang 		debug_hexdump(stdout, "m_dst(after):",
5164418919fSjohnjiang 			sym_op->m_dst->buf_addr, sym_op->m_dst->buf_len);
5174418919fSjohnjiang 
5184418919fSjohnjiang 	/* Verify results */
5194418919fSjohnjiang 	if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
5204418919fSjohnjiang 		if ((t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY) &&
5214418919fSjohnjiang 			(op->status == RTE_CRYPTO_OP_STATUS_AUTH_FAILED))
5224418919fSjohnjiang 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
5234418919fSjohnjiang 				"FAILED: Digest verification failed "
5244418919fSjohnjiang 				"(0x%X)", __LINE__, op->status);
5254418919fSjohnjiang 		else
5264418919fSjohnjiang 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
5274418919fSjohnjiang 				"FAILED: Operation failed "
5284418919fSjohnjiang 				"(0x%X)", __LINE__, op->status);
5294418919fSjohnjiang 		status = TEST_FAILED;
5304418919fSjohnjiang 		goto error_exit;
5314418919fSjohnjiang 	}
5324418919fSjohnjiang 
5334418919fSjohnjiang 	if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
5344418919fSjohnjiang 		uint8_t buffer[2048];
5354418919fSjohnjiang 		const uint8_t *compare_ref;
5364418919fSjohnjiang 		uint32_t compare_len;
5374418919fSjohnjiang 
5384418919fSjohnjiang 		if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT) {
5394418919fSjohnjiang 			compare_ref = tdata->ciphertext.data +
5404418919fSjohnjiang 					tdata->cipher_offset;
5414418919fSjohnjiang 			compare_len = tdata->ciphertext.len -
5424418919fSjohnjiang 					tdata->cipher_offset;
5434418919fSjohnjiang 		} else {
5444418919fSjohnjiang 			compare_ref = tdata->plaintext.data +
5454418919fSjohnjiang 					tdata->cipher_offset;
5464418919fSjohnjiang 			compare_len = tdata->plaintext.len -
5474418919fSjohnjiang 					tdata->cipher_offset;
5484418919fSjohnjiang 		}
5494418919fSjohnjiang 
5504418919fSjohnjiang 		if (memcmp(rte_pktmbuf_read(iobuf, tdata->cipher_offset,
5514418919fSjohnjiang 				compare_len, buffer), compare_ref,
5524418919fSjohnjiang 				compare_len)) {
5534418919fSjohnjiang 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
5544418919fSjohnjiang 				"FAILED: %s", __LINE__,
5554418919fSjohnjiang 				"Crypto data not as expected");
5564418919fSjohnjiang 			status = TEST_FAILED;
5574418919fSjohnjiang 			goto error_exit;
5584418919fSjohnjiang 		}
5594418919fSjohnjiang 	}
5604418919fSjohnjiang 
5614418919fSjohnjiang 	if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) {
5624418919fSjohnjiang 		uint8_t *auth_res = pktmbuf_mtod_offset(iobuf,
5634418919fSjohnjiang 					tdata->ciphertext.len);
5644418919fSjohnjiang 
5654418919fSjohnjiang 		if (memcmp(auth_res, tdata->digest.data, digest_len)) {
5664418919fSjohnjiang 			snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u "
5674418919fSjohnjiang 				"FAILED: %s", __LINE__, "Generated "
5684418919fSjohnjiang 				"digest data not as expected");
5694418919fSjohnjiang 			status = TEST_FAILED;
5704418919fSjohnjiang 			goto error_exit;
5714418919fSjohnjiang 		}
5724418919fSjohnjiang 	}
5734418919fSjohnjiang 
5744418919fSjohnjiang 	/* The only parts that should have changed in the buffer are
5754418919fSjohnjiang 	 * plaintext/ciphertext and digest.
5764418919fSjohnjiang 	 * In OOP only the dest buffer should change.
5774418919fSjohnjiang 	 */
5784418919fSjohnjiang 	if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
5794418919fSjohnjiang 		struct rte_mbuf *mbuf;
5804418919fSjohnjiang 		uint8_t value;
5814418919fSjohnjiang 		uint32_t head_unchanged_len, changed_len = 0;
5824418919fSjohnjiang 		uint32_t i;
5834418919fSjohnjiang 		uint32_t hdroom_used = 0, tlroom_used = 0;
5844418919fSjohnjiang 		uint32_t hdroom = 0;
5854418919fSjohnjiang 
5864418919fSjohnjiang 		mbuf = sym_op->m_src;
5874418919fSjohnjiang 		/*
5884418919fSjohnjiang 		 * Crypto PMDs specify the headroom & tailroom it would use
5894418919fSjohnjiang 		 * when processing the crypto operation. PMD is free to modify
5904418919fSjohnjiang 		 * this space, and so the verification check should skip that
5914418919fSjohnjiang 		 * block.
5924418919fSjohnjiang 		 */
5934418919fSjohnjiang 		hdroom_used = dev_info.min_mbuf_headroom_req;
5944418919fSjohnjiang 		tlroom_used = dev_info.min_mbuf_tailroom_req;
5954418919fSjohnjiang 
5964418919fSjohnjiang 		/* Get headroom */
5974418919fSjohnjiang 		hdroom = rte_pktmbuf_headroom(mbuf);
5984418919fSjohnjiang 
5994418919fSjohnjiang 		head_unchanged_len = mbuf->buf_len;
6004418919fSjohnjiang 
6014418919fSjohnjiang 		for (i = 0; i < mbuf->buf_len; i++) {
6024418919fSjohnjiang 
6034418919fSjohnjiang 			/* Skip headroom used by PMD */
6044418919fSjohnjiang 			if (i == hdroom - hdroom_used)
6054418919fSjohnjiang 				i += hdroom_used;
6064418919fSjohnjiang 
6074418919fSjohnjiang 			/* Skip tailroom used by PMD */
6084418919fSjohnjiang 			if (i == (hdroom + mbuf->data_len))
6094418919fSjohnjiang 				i += tlroom_used;
6104418919fSjohnjiang 
6114418919fSjohnjiang 			value = *((uint8_t *)(mbuf->buf_addr)+i);
6124418919fSjohnjiang 			if (value != tmp_src_buf[i]) {
6134418919fSjohnjiang 				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
6144418919fSjohnjiang 	"line %u FAILED: OOP src outer mbuf data (0x%x) not as expected (0x%x)",
6154418919fSjohnjiang 					__LINE__, value, tmp_src_buf[i]);
6164418919fSjohnjiang 				status = TEST_FAILED;
6174418919fSjohnjiang 				goto error_exit;
6184418919fSjohnjiang 			}
6194418919fSjohnjiang 		}
6204418919fSjohnjiang 
6214418919fSjohnjiang 		mbuf = sym_op->m_dst;
6224418919fSjohnjiang 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) {
6234418919fSjohnjiang 			head_unchanged_len = hdroom + sym_op->auth.data.offset;
6244418919fSjohnjiang 			changed_len = sym_op->auth.data.length;
6254418919fSjohnjiang 			if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN)
6264418919fSjohnjiang 				changed_len += digest_len;
6274418919fSjohnjiang 		} else {
6284418919fSjohnjiang 			/* cipher-only */
6294418919fSjohnjiang 			head_unchanged_len = hdroom +
6304418919fSjohnjiang 					sym_op->cipher.data.offset;
6314418919fSjohnjiang 			changed_len = sym_op->cipher.data.length;
6324418919fSjohnjiang 		}
6334418919fSjohnjiang 
6344418919fSjohnjiang 		for (i = 0; i < mbuf->buf_len; i++) {
6354418919fSjohnjiang 			if (i == head_unchanged_len)
6364418919fSjohnjiang 				i += changed_len;
6374418919fSjohnjiang 			value = *((uint8_t *)(mbuf->buf_addr)+i);
6384418919fSjohnjiang 			if (value != tmp_dst_buf[i]) {
6394418919fSjohnjiang 				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
6404418919fSjohnjiang 				"line %u FAILED: OOP dst outer mbuf data "
6414418919fSjohnjiang 				"(0x%x) not as expected (0x%x)",
6424418919fSjohnjiang 				__LINE__, value, tmp_dst_buf[i]);
6434418919fSjohnjiang 				status = TEST_FAILED;
6444418919fSjohnjiang 				goto error_exit;
6454418919fSjohnjiang 			}
6464418919fSjohnjiang 		}
6474418919fSjohnjiang 
6484418919fSjohnjiang 		if (!nb_iterates) {
6494418919fSjohnjiang 			nb_iterates++;
6504418919fSjohnjiang 			goto iterate;
6514418919fSjohnjiang 		}
6524418919fSjohnjiang 	} else {
6534418919fSjohnjiang 		/* In-place operation */
6544418919fSjohnjiang 		struct rte_mbuf *mbuf;
6554418919fSjohnjiang 		uint8_t value;
6564418919fSjohnjiang 		uint32_t head_unchanged_len = 0, changed_len = 0;
6574418919fSjohnjiang 		uint32_t i;
6584418919fSjohnjiang 		uint32_t hdroom_used = 0, tlroom_used = 0;
6594418919fSjohnjiang 		uint32_t hdroom = 0;
6604418919fSjohnjiang 
6614418919fSjohnjiang 		/*
6624418919fSjohnjiang 		 * Crypto PMDs specify the headroom & tailroom it would use
6634418919fSjohnjiang 		 * when processing the crypto operation. PMD is free to modify
6644418919fSjohnjiang 		 * this space, and so the verification check should skip that
6654418919fSjohnjiang 		 * block.
6664418919fSjohnjiang 		 */
6674418919fSjohnjiang 		hdroom_used = dev_info.min_mbuf_headroom_req;
6684418919fSjohnjiang 		tlroom_used = dev_info.min_mbuf_tailroom_req;
6694418919fSjohnjiang 
6704418919fSjohnjiang 		mbuf = sym_op->m_src;
6714418919fSjohnjiang 
6724418919fSjohnjiang 		/* Get headroom */
6734418919fSjohnjiang 		hdroom = rte_pktmbuf_headroom(mbuf);
6744418919fSjohnjiang 
6754418919fSjohnjiang 		if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
6764418919fSjohnjiang 			head_unchanged_len = hdroom +
6774418919fSjohnjiang 					sym_op->cipher.data.offset;
6784418919fSjohnjiang 			changed_len = sym_op->cipher.data.length;
6794418919fSjohnjiang 		} else {
6804418919fSjohnjiang 			/* auth-only */
6814418919fSjohnjiang 			head_unchanged_len = hdroom +
6824418919fSjohnjiang 					sym_op->auth.data.offset +
6834418919fSjohnjiang 					sym_op->auth.data.length;
6844418919fSjohnjiang 			changed_len = 0;
6854418919fSjohnjiang 		}
6864418919fSjohnjiang 
6874418919fSjohnjiang 		if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN)
6884418919fSjohnjiang 			changed_len += digest_len;
6894418919fSjohnjiang 
6904418919fSjohnjiang 		for (i = 0; i < mbuf->buf_len; i++) {
6914418919fSjohnjiang 
6924418919fSjohnjiang 			/* Skip headroom used by PMD */
6934418919fSjohnjiang 			if (i == hdroom - hdroom_used)
6944418919fSjohnjiang 				i += hdroom_used;
6954418919fSjohnjiang 
6964418919fSjohnjiang 			if (i == head_unchanged_len)
6974418919fSjohnjiang 				i += changed_len;
6984418919fSjohnjiang 
6994418919fSjohnjiang 			/* Skip tailroom used by PMD */
7004418919fSjohnjiang 			if (i == (hdroom + mbuf->data_len))
7014418919fSjohnjiang 				i += tlroom_used;
7024418919fSjohnjiang 
7034418919fSjohnjiang 			value = *((uint8_t *)(mbuf->buf_addr)+i);
7044418919fSjohnjiang 			if (value != tmp_src_buf[i]) {
7054418919fSjohnjiang 				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
7064418919fSjohnjiang 				"line %u FAILED: outer mbuf data (0x%x) "
7074418919fSjohnjiang 				"not as expected (0x%x)",
7084418919fSjohnjiang 				__LINE__, value, tmp_src_buf[i]);
7094418919fSjohnjiang 				status = TEST_FAILED;
7104418919fSjohnjiang 				goto error_exit;
7114418919fSjohnjiang 			}
7124418919fSjohnjiang 		}
7134418919fSjohnjiang 	}
7144418919fSjohnjiang 
7154418919fSjohnjiang 	snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "PASS");
7164418919fSjohnjiang 
7174418919fSjohnjiang error_exit:
7184418919fSjohnjiang 	if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)) {
7194418919fSjohnjiang 		if (sess) {
7204418919fSjohnjiang 			rte_cryptodev_sym_session_clear(dev_id, sess);
7214418919fSjohnjiang 			rte_cryptodev_sym_session_free(sess);
7224418919fSjohnjiang 		}
7234418919fSjohnjiang 		if (cipher_xform)
7244418919fSjohnjiang 			rte_free(cipher_xform);
7254418919fSjohnjiang 		if (auth_xform)
7264418919fSjohnjiang 			rte_free(auth_xform);
7274418919fSjohnjiang 	}
7284418919fSjohnjiang 
7294418919fSjohnjiang 	if (op)
7304418919fSjohnjiang 		rte_crypto_op_free(op);
7314418919fSjohnjiang 
7324418919fSjohnjiang 	if (obuf)
7334418919fSjohnjiang 		rte_pktmbuf_free(obuf);
7344418919fSjohnjiang 
7354418919fSjohnjiang 	if (ibuf)
7364418919fSjohnjiang 		rte_pktmbuf_free(ibuf);
7374418919fSjohnjiang 
7384418919fSjohnjiang 	return status;
7394418919fSjohnjiang }
7404418919fSjohnjiang 
7414418919fSjohnjiang int
test_blockcipher_all_tests(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,enum blockcipher_test_type test_type)7424418919fSjohnjiang test_blockcipher_all_tests(struct rte_mempool *mbuf_pool,
7434418919fSjohnjiang 	struct rte_mempool *op_mpool,
7444418919fSjohnjiang 	struct rte_mempool *sess_mpool,
7454418919fSjohnjiang 	struct rte_mempool *sess_priv_mpool,
7464418919fSjohnjiang 	uint8_t dev_id,
7474418919fSjohnjiang 	enum blockcipher_test_type test_type)
7484418919fSjohnjiang {
7494418919fSjohnjiang 	int status, overall_status = TEST_SUCCESS;
7504418919fSjohnjiang 	uint32_t i, test_index = 0;
7514418919fSjohnjiang 	char test_msg[BLOCKCIPHER_TEST_MSG_LEN + 1];
7524418919fSjohnjiang 	uint32_t n_test_cases = 0;
7534418919fSjohnjiang 	const struct blockcipher_test_case *tcs = NULL;
7544418919fSjohnjiang 
7554418919fSjohnjiang 	switch (test_type) {
7564418919fSjohnjiang 	case BLKCIPHER_AES_CHAIN_TYPE:
7574418919fSjohnjiang 		n_test_cases = sizeof(aes_chain_test_cases) /
7584418919fSjohnjiang 		sizeof(aes_chain_test_cases[0]);
7594418919fSjohnjiang 		tcs = aes_chain_test_cases;
7604418919fSjohnjiang 		break;
7614418919fSjohnjiang 	case BLKCIPHER_AES_CIPHERONLY_TYPE:
7624418919fSjohnjiang 		n_test_cases = sizeof(aes_cipheronly_test_cases) /
7634418919fSjohnjiang 		sizeof(aes_cipheronly_test_cases[0]);
7644418919fSjohnjiang 		tcs = aes_cipheronly_test_cases;
7654418919fSjohnjiang 		break;
7664418919fSjohnjiang 	case BLKCIPHER_AES_DOCSIS_TYPE:
7674418919fSjohnjiang 		n_test_cases = sizeof(aes_docsis_test_cases) /
7684418919fSjohnjiang 		sizeof(aes_docsis_test_cases[0]);
7694418919fSjohnjiang 		tcs = aes_docsis_test_cases;
7704418919fSjohnjiang 		break;
7714418919fSjohnjiang 	case BLKCIPHER_3DES_CHAIN_TYPE:
7724418919fSjohnjiang 		n_test_cases = sizeof(triple_des_chain_test_cases) /
7734418919fSjohnjiang 		sizeof(triple_des_chain_test_cases[0]);
7744418919fSjohnjiang 		tcs = triple_des_chain_test_cases;
7754418919fSjohnjiang 		break;
7764418919fSjohnjiang 	case BLKCIPHER_3DES_CIPHERONLY_TYPE:
7774418919fSjohnjiang 		n_test_cases = sizeof(triple_des_cipheronly_test_cases) /
7784418919fSjohnjiang 		sizeof(triple_des_cipheronly_test_cases[0]);
7794418919fSjohnjiang 		tcs = triple_des_cipheronly_test_cases;
7804418919fSjohnjiang 		break;
7814418919fSjohnjiang 	case BLKCIPHER_DES_CIPHERONLY_TYPE:
7824418919fSjohnjiang 		n_test_cases = sizeof(des_cipheronly_test_cases) /
7834418919fSjohnjiang 		sizeof(des_cipheronly_test_cases[0]);
7844418919fSjohnjiang 		tcs = des_cipheronly_test_cases;
7854418919fSjohnjiang 		break;
7864418919fSjohnjiang 	case BLKCIPHER_DES_DOCSIS_TYPE:
7874418919fSjohnjiang 		n_test_cases = sizeof(des_docsis_test_cases) /
7884418919fSjohnjiang 		sizeof(des_docsis_test_cases[0]);
7894418919fSjohnjiang 		tcs = des_docsis_test_cases;
7904418919fSjohnjiang 		break;
7914418919fSjohnjiang 	case BLKCIPHER_AUTHONLY_TYPE:
7924418919fSjohnjiang 		n_test_cases = sizeof(hash_test_cases) /
7934418919fSjohnjiang 		sizeof(hash_test_cases[0]);
7944418919fSjohnjiang 		tcs = hash_test_cases;
7954418919fSjohnjiang 		break;
7964418919fSjohnjiang 	default:
7974418919fSjohnjiang 		break;
7984418919fSjohnjiang 	}
7994418919fSjohnjiang 
8004418919fSjohnjiang 	for (i = 0; i < n_test_cases; i++) {
8014418919fSjohnjiang 		const struct blockcipher_test_case *tc = &tcs[i];
8024418919fSjohnjiang 
8034418919fSjohnjiang 		status = test_blockcipher_one_case(tc, mbuf_pool, op_mpool,
804*2d9fd380Sjfb8856606 			sess_mpool, sess_priv_mpool, dev_id,
8054418919fSjohnjiang 			test_msg);
8064418919fSjohnjiang 
8074418919fSjohnjiang 		printf("  %u) TestCase %s %s\n", test_index ++,
8084418919fSjohnjiang 			tc->test_descr, test_msg);
8094418919fSjohnjiang 
810*2d9fd380Sjfb8856606 		if (status == TEST_FAILED) {
8114418919fSjohnjiang 			overall_status = status;
8124418919fSjohnjiang 
8134418919fSjohnjiang 			if (tc->feature_mask & BLOCKCIPHER_TEST_FEATURE_STOPPER)
8144418919fSjohnjiang 				break;
8154418919fSjohnjiang 		}
8164418919fSjohnjiang 	}
8174418919fSjohnjiang 
8184418919fSjohnjiang 	return overall_status;
8194418919fSjohnjiang }
820