xref: /dpdk/app/test/test_cryptodev.c (revision 54140461b60485941da282d8da2db2f2bc19e281)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020 Intel Corporation
3  * Copyright 2020 NXP
4  */
5 
6 #include <time.h>
7 
8 #include <rte_common.h>
9 #include <rte_hexdump.h>
10 #include <rte_mbuf.h>
11 #include <rte_malloc.h>
12 #include <rte_memcpy.h>
13 #include <rte_pause.h>
14 #include <rte_bus_vdev.h>
15 #include <rte_ether.h>
16 #include <rte_errno.h>
17 
18 #include <rte_crypto.h>
19 #include <rte_cryptodev.h>
20 #include <rte_ip.h>
21 #include <rte_string_fns.h>
22 #include <rte_tcp.h>
23 #include <rte_udp.h>
24 
25 #ifdef RTE_CRYPTO_SCHEDULER
26 #include <rte_cryptodev_scheduler.h>
27 #include <rte_cryptodev_scheduler_operations.h>
28 #endif
29 
30 #include <rte_lcore.h>
31 
32 #include "test.h"
33 #include "test_cryptodev.h"
34 
35 #include "test_cryptodev_blockcipher.h"
36 #include "test_cryptodev_aes_test_vectors.h"
37 #include "test_cryptodev_des_test_vectors.h"
38 #include "test_cryptodev_hash_test_vectors.h"
39 #include "test_cryptodev_kasumi_test_vectors.h"
40 #include "test_cryptodev_kasumi_hash_test_vectors.h"
41 #include "test_cryptodev_snow3g_test_vectors.h"
42 #include "test_cryptodev_snow3g_hash_test_vectors.h"
43 #include "test_cryptodev_zuc_test_vectors.h"
44 #include "test_cryptodev_aead_test_vectors.h"
45 #include "test_cryptodev_hmac_test_vectors.h"
46 #include "test_cryptodev_mixed_test_vectors.h"
47 #include "test_cryptodev_sm4_test_vectors.h"
48 #ifdef RTE_LIB_SECURITY
49 #include "test_cryptodev_security_ipsec.h"
50 #include "test_cryptodev_security_ipsec_test_vectors.h"
51 #include "test_cryptodev_security_pdcp_test_vectors.h"
52 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h"
53 #include "test_cryptodev_security_pdcp_test_func.h"
54 #include "test_cryptodev_security_docsis_test_vectors.h"
55 
56 #define SDAP_DISABLED	0
57 #define SDAP_ENABLED	1
58 #endif
59 
60 #define VDEV_ARGS_SIZE 100
61 #define MAX_NB_SESSIONS 4
62 
63 #define MAX_DRV_SERVICE_CTX_SIZE 256
64 
65 #define MAX_RAW_DEQUEUE_COUNT	65535
66 
67 #define IN_PLACE 0
68 #define OUT_OF_PLACE 1
69 
70 static int gbl_driver_id;
71 
72 static enum rte_security_session_action_type gbl_action_type =
73 	RTE_SECURITY_ACTION_TYPE_NONE;
74 
75 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST;
76 
77 struct crypto_unittest_params {
78 	struct rte_crypto_sym_xform cipher_xform;
79 	struct rte_crypto_sym_xform auth_xform;
80 	struct rte_crypto_sym_xform aead_xform;
81 #ifdef RTE_LIB_SECURITY
82 	struct rte_security_docsis_xform docsis_xform;
83 #endif
84 
85 	union {
86 		void *sess;
87 #ifdef RTE_LIB_SECURITY
88 		void *sec_session;
89 #endif
90 	};
91 #ifdef RTE_LIB_SECURITY
92 	enum rte_security_session_action_type type;
93 #endif
94 	struct rte_crypto_op *op;
95 
96 	struct rte_mbuf *obuf, *ibuf;
97 
98 	uint8_t *digest;
99 };
100 
101 #define ALIGN_POW2_ROUNDUP(num, align) \
102 	(((num) + (align) - 1) & ~((align) - 1))
103 
104 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts)	\
105 	for (j = 0; j < num_child_ts; index++, j++)			\
106 		parent_ts.unit_test_suites[index] = child_ts[j]
107 
108 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types)	\
109 	for (j = 0; j < num_blk_types; index++, j++)				\
110 		parent_ts.unit_test_suites[index] =				\
111 				build_blockcipher_test_suite(blk_types[j])
112 
113 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types)		\
114 	for (j = index; j < index + num_blk_types; j++)				\
115 		free_blockcipher_test_suite(parent_ts.unit_test_suites[j])
116 
117 /*
118  * Forward declarations.
119  */
120 static int
121 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
122 		struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
123 		uint8_t *hmac_key);
124 
125 static int
126 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess,
127 		struct crypto_unittest_params *ut_params,
128 		struct crypto_testsuite_params *ts_param,
129 		const uint8_t *cipher,
130 		const uint8_t *digest,
131 		const uint8_t *iv);
132 
133 static int
134 security_proto_supported(enum rte_security_session_action_type action,
135 	enum rte_security_session_protocol proto);
136 
137 static int
138 dev_configure_and_start(uint64_t ff_disable);
139 
140 static int
141 check_cipher_capability(const struct crypto_testsuite_params *ts_params,
142 			const enum rte_crypto_cipher_algorithm cipher_algo,
143 			const uint16_t key_size, const uint16_t iv_size);
144 
145 static int
146 check_auth_capability(const struct crypto_testsuite_params *ts_params,
147 			const enum rte_crypto_auth_algorithm auth_algo,
148 			const uint16_t key_size, const uint16_t iv_size,
149 			const uint16_t tag_size);
150 
151 static struct rte_mbuf *
152 setup_test_string(struct rte_mempool *mpool,
153 		const char *string, size_t len, uint8_t blocksize)
154 {
155 	struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
156 	size_t t_len = len - (blocksize ? (len % blocksize) : 0);
157 
158 	if (m) {
159 		char *dst;
160 
161 		memset(m->buf_addr, 0, m->buf_len);
162 		dst = rte_pktmbuf_append(m, t_len);
163 		if (!dst) {
164 			rte_pktmbuf_free(m);
165 			return NULL;
166 		}
167 		if (string != NULL)
168 			rte_memcpy(dst, string, t_len);
169 		else
170 			memset(dst, 0, t_len);
171 	}
172 
173 	return m;
174 }
175 
176 /* Get number of bytes in X bits (rounding up) */
177 static uint32_t
178 ceil_byte_length(uint32_t num_bits)
179 {
180 	if (num_bits % 8)
181 		return ((num_bits >> 3) + 1);
182 	else
183 		return (num_bits >> 3);
184 }
185 
186 static void
187 post_process_raw_dp_op(void *user_data,	uint32_t index __rte_unused,
188 		uint8_t is_op_success)
189 {
190 	struct rte_crypto_op *op = user_data;
191 	op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS :
192 			RTE_CRYPTO_OP_STATUS_ERROR;
193 }
194 
195 static struct crypto_testsuite_params testsuite_params = { NULL };
196 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params;
197 static struct crypto_unittest_params unittest_params;
198 
199 int
200 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
201 		struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
202 		uint8_t len_in_bits, uint8_t cipher_iv_len)
203 {
204 	struct rte_crypto_sym_op *sop = op->sym;
205 	struct rte_crypto_op *ret_op = NULL;
206 	struct rte_crypto_vec data_vec[UINT8_MAX], dest_data_vec[UINT8_MAX];
207 	struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv;
208 	union rte_crypto_sym_ofs ofs;
209 	struct rte_crypto_sym_vec vec;
210 	struct rte_crypto_sgl sgl, dest_sgl;
211 	uint32_t max_len;
212 	union rte_cryptodev_session_ctx sess;
213 	uint64_t auth_end_iova;
214 	uint32_t count = 0;
215 	struct rte_crypto_raw_dp_ctx *ctx;
216 	uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0,
217 			auth_len = 0;
218 	int32_t n;
219 	uint32_t n_success;
220 	int ctx_service_size;
221 	int32_t status = 0;
222 	int enqueue_status, dequeue_status;
223 	struct crypto_unittest_params *ut_params = &unittest_params;
224 	int is_sgl = sop->m_src->nb_segs > 1;
225 	int ret = TEST_SUCCESS, is_oop = 0;
226 
227 	ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
228 	if (ctx_service_size < 0)
229 		return TEST_SKIPPED;
230 
231 	ctx = malloc(ctx_service_size);
232 	if (ctx == NULL)
233 		return TEST_FAILED;
234 
235 	/* Both are enums, setting crypto_sess will suit any session type */
236 	sess.crypto_sess = op->sym->session;
237 
238 	ret = rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx, op->sess_type, sess, 0);
239 	if (ret == -ENOTSUP) {
240 		ret = TEST_SKIPPED;
241 		goto exit;
242 	} else if (ret) {
243 		ret = TEST_FAILED;
244 		goto exit;
245 	}
246 
247 	cipher_iv.iova = 0;
248 	cipher_iv.va = NULL;
249 	aad_auth_iv.iova = 0;
250 	aad_auth_iv.va = NULL;
251 	digest.iova = 0;
252 	digest.va = NULL;
253 	sgl.vec = data_vec;
254 	vec.num = 1;
255 	vec.src_sgl = &sgl;
256 	vec.iv = &cipher_iv;
257 	vec.digest = &digest;
258 	vec.aad = &aad_auth_iv;
259 	vec.status = &status;
260 
261 	ofs.raw = 0;
262 
263 	if ((sop->m_dst != NULL) && (sop->m_dst != sop->m_src))
264 		is_oop = 1;
265 
266 	if (is_cipher && is_auth) {
267 		cipher_offset = sop->cipher.data.offset;
268 		cipher_len = sop->cipher.data.length;
269 		auth_offset = sop->auth.data.offset;
270 		auth_len = sop->auth.data.length;
271 		max_len = RTE_MAX(cipher_offset + cipher_len,
272 				auth_offset + auth_len);
273 		if (len_in_bits) {
274 			max_len = max_len >> 3;
275 			cipher_offset = cipher_offset >> 3;
276 			auth_offset = auth_offset >> 3;
277 			cipher_len = cipher_len >> 3;
278 			auth_len = auth_len >> 3;
279 		}
280 		ofs.ofs.cipher.head = cipher_offset;
281 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
282 		ofs.ofs.auth.head = auth_offset;
283 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
284 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
285 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
286 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
287 				op, void *, IV_OFFSET + cipher_iv_len);
288 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
289 				cipher_iv_len);
290 		digest.va = (void *)sop->auth.digest.data;
291 		digest.iova = sop->auth.digest.phys_addr;
292 
293 		if (is_sgl) {
294 			uint32_t remaining_off = auth_offset + auth_len;
295 			struct rte_mbuf *sgl_buf = sop->m_src;
296 			if (is_oop)
297 				sgl_buf = sop->m_dst;
298 
299 			while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)
300 					&& sgl_buf->next != NULL) {
301 				remaining_off -= rte_pktmbuf_data_len(sgl_buf);
302 				sgl_buf = sgl_buf->next;
303 			}
304 
305 			auth_end_iova = (uint64_t)rte_pktmbuf_iova_offset(
306 				sgl_buf, remaining_off);
307 		} else {
308 			auth_end_iova = rte_pktmbuf_iova(op->sym->m_src) +
309 							 auth_offset + auth_len;
310 		}
311 		/* Then check if digest-encrypted conditions are met */
312 		if ((auth_offset + auth_len < cipher_offset + cipher_len) &&
313 				(digest.iova == auth_end_iova) && is_sgl)
314 			max_len = RTE_MAX(max_len,
315 				auth_offset + auth_len +
316 				ut_params->auth_xform.auth.digest_length);
317 
318 	} else if (is_cipher) {
319 		cipher_offset = sop->cipher.data.offset;
320 		cipher_len = sop->cipher.data.length;
321 		max_len = cipher_len + cipher_offset;
322 		if (len_in_bits) {
323 			max_len = max_len >> 3;
324 			cipher_offset = cipher_offset >> 3;
325 			cipher_len = cipher_len >> 3;
326 		}
327 		ofs.ofs.cipher.head = cipher_offset;
328 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
329 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
330 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
331 
332 	} else if (is_auth) {
333 		auth_offset = sop->auth.data.offset;
334 		auth_len = sop->auth.data.length;
335 		max_len = auth_len + auth_offset;
336 		if (len_in_bits) {
337 			max_len = max_len >> 3;
338 			auth_offset = auth_offset >> 3;
339 			auth_len = auth_len >> 3;
340 		}
341 		ofs.ofs.auth.head = auth_offset;
342 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
343 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
344 				op, void *, IV_OFFSET + cipher_iv_len);
345 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
346 				cipher_iv_len);
347 		digest.va = (void *)sop->auth.digest.data;
348 		digest.iova = sop->auth.digest.phys_addr;
349 
350 	} else { /* aead */
351 		cipher_offset = sop->aead.data.offset;
352 		cipher_len = sop->aead.data.length;
353 		max_len = cipher_len + cipher_offset;
354 		if (len_in_bits) {
355 			max_len = max_len >> 3;
356 			cipher_offset = cipher_offset >> 3;
357 			cipher_len = cipher_len >> 3;
358 		}
359 		ofs.ofs.cipher.head = cipher_offset;
360 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
361 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
362 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
363 		aad_auth_iv.va = (void *)sop->aead.aad.data;
364 		aad_auth_iv.iova = sop->aead.aad.phys_addr;
365 		digest.va = (void *)sop->aead.digest.data;
366 		digest.iova = sop->aead.digest.phys_addr;
367 	}
368 
369 	n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
370 			data_vec, RTE_DIM(data_vec));
371 	if (n < 0 || n > sop->m_src->nb_segs) {
372 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
373 		goto exit;
374 	}
375 
376 	sgl.num = n;
377 	/* Out of place */
378 	if (is_oop) {
379 		dest_sgl.vec = dest_data_vec;
380 		vec.dest_sgl = &dest_sgl;
381 		n = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len,
382 				dest_data_vec, RTE_DIM(dest_data_vec));
383 		if (n < 0 || n > sop->m_dst->nb_segs) {
384 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
385 			goto exit;
386 		}
387 		dest_sgl.num = n;
388 	} else
389 		vec.dest_sgl = NULL;
390 
391 	if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op,
392 			&enqueue_status) < 1) {
393 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
394 		goto exit;
395 	}
396 
397 	if (enqueue_status == 0) {
398 		status = rte_cryptodev_raw_enqueue_done(ctx, 1);
399 		if (status < 0) {
400 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
401 			goto exit;
402 		}
403 	} else if (enqueue_status < 0) {
404 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
405 		goto exit;
406 	}
407 
408 	n = n_success = 0;
409 	while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) {
410 		n = rte_cryptodev_raw_dequeue_burst(ctx,
411 			NULL, 1, post_process_raw_dp_op,
412 				(void **)&ret_op, 0, &n_success,
413 				&dequeue_status);
414 		if (dequeue_status < 0) {
415 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
416 			goto exit;
417 		}
418 		if (n == 0)
419 			rte_pause();
420 	}
421 
422 	if (n == 1 && dequeue_status == 0) {
423 		if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) {
424 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
425 			goto exit;
426 		}
427 	}
428 
429 	op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op ||
430 			ret_op->status == RTE_CRYPTO_OP_STATUS_ERROR ||
431 			n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
432 					RTE_CRYPTO_OP_STATUS_SUCCESS;
433 
434 exit:
435 	free(ctx);
436 	return ret;
437 }
438 
439 static void
440 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
441 {
442 	int32_t n, st;
443 	struct rte_crypto_sym_op *sop;
444 	union rte_crypto_sym_ofs ofs;
445 	struct rte_crypto_sgl sgl;
446 	struct rte_crypto_sym_vec symvec;
447 	struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
448 	struct rte_crypto_vec vec[UINT8_MAX];
449 
450 	sop = op->sym;
451 
452 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
453 		sop->aead.data.length, vec, RTE_DIM(vec));
454 
455 	if (n < 0 || n != sop->m_src->nb_segs) {
456 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
457 		return;
458 	}
459 
460 	sgl.vec = vec;
461 	sgl.num = n;
462 	symvec.src_sgl = &sgl;
463 	symvec.iv = &iv_ptr;
464 	symvec.digest = &digest_ptr;
465 	symvec.aad = &aad_ptr;
466 	symvec.status = &st;
467 	symvec.num = 1;
468 
469 	/* for CPU crypto the IOVA address is not required */
470 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
471 	digest_ptr.va = (void *)sop->aead.digest.data;
472 	aad_ptr.va = (void *)sop->aead.aad.data;
473 
474 	ofs.raw = 0;
475 
476 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
477 		&symvec);
478 
479 	if (n != 1)
480 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
481 	else
482 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
483 }
484 
485 static void
486 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
487 {
488 	int32_t n, st;
489 	struct rte_crypto_sym_op *sop;
490 	union rte_crypto_sym_ofs ofs;
491 	struct rte_crypto_sgl sgl;
492 	struct rte_crypto_sym_vec symvec;
493 	struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
494 	struct rte_crypto_vec vec[UINT8_MAX];
495 
496 	sop = op->sym;
497 
498 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
499 		sop->auth.data.length, vec, RTE_DIM(vec));
500 
501 	if (n < 0 || n != sop->m_src->nb_segs) {
502 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
503 		return;
504 	}
505 
506 	sgl.vec = vec;
507 	sgl.num = n;
508 	symvec.src_sgl = &sgl;
509 	symvec.iv = &iv_ptr;
510 	symvec.digest = &digest_ptr;
511 	symvec.status = &st;
512 	symvec.num = 1;
513 
514 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
515 	digest_ptr.va = (void *)sop->auth.digest.data;
516 
517 	ofs.raw = 0;
518 	ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
519 	ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
520 		(sop->cipher.data.offset + sop->cipher.data.length);
521 
522 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
523 		&symvec);
524 
525 	if (n != 1)
526 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
527 	else
528 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
529 }
530 
531 static struct rte_crypto_op *
532 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
533 {
534 
535 	RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
536 
537 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
538 		RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
539 		return NULL;
540 	}
541 
542 	op = NULL;
543 
544 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
545 		rte_pause();
546 
547 	if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
548 		RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
549 		return NULL;
550 	}
551 
552 	return op;
553 }
554 
555 static int
556 testsuite_setup(void)
557 {
558 	struct crypto_testsuite_params *ts_params = &testsuite_params;
559 	struct rte_cryptodev_info info;
560 	uint32_t i = 0, nb_devs, dev_id;
561 	uint16_t qp_id;
562 
563 	memset(ts_params, 0, sizeof(*ts_params));
564 
565 	ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
566 	if (ts_params->mbuf_pool == NULL) {
567 		/* Not already created so create */
568 		ts_params->mbuf_pool = rte_pktmbuf_pool_create(
569 				"CRYPTO_MBUFPOOL",
570 				NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
571 				rte_socket_id());
572 		if (ts_params->mbuf_pool == NULL) {
573 			RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
574 			return TEST_FAILED;
575 		}
576 	}
577 
578 	ts_params->large_mbuf_pool = rte_mempool_lookup(
579 			"CRYPTO_LARGE_MBUFPOOL");
580 	if (ts_params->large_mbuf_pool == NULL) {
581 		/* Not already created so create */
582 		ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
583 				"CRYPTO_LARGE_MBUFPOOL",
584 				1, 0, 0, UINT16_MAX,
585 				rte_socket_id());
586 		if (ts_params->large_mbuf_pool == NULL) {
587 			RTE_LOG(ERR, USER1,
588 				"Can't create CRYPTO_LARGE_MBUFPOOL\n");
589 			return TEST_FAILED;
590 		}
591 	}
592 
593 	ts_params->op_mpool = rte_crypto_op_pool_create(
594 			"MBUF_CRYPTO_SYM_OP_POOL",
595 			RTE_CRYPTO_OP_TYPE_SYMMETRIC,
596 			NUM_MBUFS, MBUF_CACHE_SIZE,
597 			DEFAULT_NUM_XFORMS *
598 			sizeof(struct rte_crypto_sym_xform) +
599 			MAXIMUM_IV_LENGTH,
600 			rte_socket_id());
601 	if (ts_params->op_mpool == NULL) {
602 		RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
603 		return TEST_FAILED;
604 	}
605 
606 	nb_devs = rte_cryptodev_count();
607 	if (nb_devs < 1) {
608 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
609 		return TEST_SKIPPED;
610 	}
611 
612 	if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) {
613 		RTE_LOG(WARNING, USER1, "No %s devices found?\n",
614 				rte_cryptodev_driver_name_get(gbl_driver_id));
615 		return TEST_SKIPPED;
616 	}
617 
618 	/* Create list of valid crypto devs */
619 	for (i = 0; i < nb_devs; i++) {
620 		rte_cryptodev_info_get(i, &info);
621 		if (info.driver_id == gbl_driver_id)
622 			ts_params->valid_devs[ts_params->valid_dev_count++] = i;
623 	}
624 
625 	if (ts_params->valid_dev_count < 1)
626 		return TEST_FAILED;
627 
628 	/* Set up all the qps on the first of the valid devices found */
629 
630 	dev_id = ts_params->valid_devs[0];
631 
632 	rte_cryptodev_info_get(dev_id, &info);
633 
634 	ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
635 	ts_params->conf.socket_id = SOCKET_ID_ANY;
636 	ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
637 
638 	unsigned int session_size =
639 		rte_cryptodev_sym_get_private_session_size(dev_id);
640 
641 #ifdef RTE_LIB_SECURITY
642 	unsigned int security_session_size = rte_security_session_get_size(
643 			rte_cryptodev_get_sec_ctx(dev_id));
644 
645 	if (session_size < security_session_size)
646 		session_size = security_session_size;
647 #endif
648 	/*
649 	 * Create mempool with maximum number of sessions.
650 	 */
651 	if (info.sym.max_nb_sessions != 0 &&
652 			info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
653 		RTE_LOG(ERR, USER1, "Device does not support "
654 				"at least %u sessions\n",
655 				MAX_NB_SESSIONS);
656 		return TEST_FAILED;
657 	}
658 
659 	ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
660 			"test_sess_mp", MAX_NB_SESSIONS, session_size, 0, 0,
661 			SOCKET_ID_ANY);
662 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
663 			"session mempool allocation failed");
664 
665 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
666 			&ts_params->conf),
667 			"Failed to configure cryptodev %u with %u qps",
668 			dev_id, ts_params->conf.nb_queue_pairs);
669 
670 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
671 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
672 
673 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
674 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
675 			dev_id, qp_id, &ts_params->qp_conf,
676 			rte_cryptodev_socket_id(dev_id)),
677 			"Failed to setup queue pair %u on cryptodev %u",
678 			qp_id, dev_id);
679 	}
680 
681 	return TEST_SUCCESS;
682 }
683 
684 static void
685 testsuite_teardown(void)
686 {
687 	struct crypto_testsuite_params *ts_params = &testsuite_params;
688 	int res;
689 
690 	if (ts_params->mbuf_pool != NULL) {
691 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
692 		rte_mempool_avail_count(ts_params->mbuf_pool));
693 	}
694 
695 	if (ts_params->op_mpool != NULL) {
696 		RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
697 		rte_mempool_avail_count(ts_params->op_mpool));
698 	}
699 
700 	if (ts_params->session_mpool != NULL) {
701 		rte_mempool_free(ts_params->session_mpool);
702 		ts_params->session_mpool = NULL;
703 	}
704 
705 	res = rte_cryptodev_close(ts_params->valid_devs[0]);
706 	if (res)
707 		RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res);
708 }
709 
710 static int
711 check_capabilities_supported(enum rte_crypto_sym_xform_type type,
712 		const int *algs, uint16_t num_algs)
713 {
714 	uint8_t dev_id = testsuite_params.valid_devs[0];
715 	bool some_alg_supported = FALSE;
716 	uint16_t i;
717 
718 	for (i = 0; i < num_algs && !some_alg_supported; i++) {
719 		struct rte_cryptodev_sym_capability_idx alg = {
720 			type, {algs[i]}
721 		};
722 		if (rte_cryptodev_sym_capability_get(dev_id,
723 				&alg) != NULL)
724 			some_alg_supported = TRUE;
725 	}
726 	if (!some_alg_supported)
727 		return TEST_SKIPPED;
728 
729 	return 0;
730 }
731 
732 int
733 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
734 		uint16_t num_ciphers)
735 {
736 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER,
737 			(const int *) ciphers, num_ciphers);
738 }
739 
740 int
741 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
742 		uint16_t num_auths)
743 {
744 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH,
745 			(const int *) auths, num_auths);
746 }
747 
748 int
749 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
750 		uint16_t num_aeads)
751 {
752 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD,
753 			(const int *) aeads, num_aeads);
754 }
755 
756 static int
757 null_testsuite_setup(void)
758 {
759 	struct crypto_testsuite_params *ts_params = &testsuite_params;
760 	uint8_t dev_id = ts_params->valid_devs[0];
761 	struct rte_cryptodev_info dev_info;
762 	const enum rte_crypto_cipher_algorithm ciphers[] = {
763 		RTE_CRYPTO_CIPHER_NULL
764 	};
765 	const enum rte_crypto_auth_algorithm auths[] = {
766 		RTE_CRYPTO_AUTH_NULL
767 	};
768 
769 	rte_cryptodev_info_get(dev_id, &dev_info);
770 
771 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
772 		RTE_LOG(INFO, USER1, "Feature flag requirements for NULL "
773 				"testsuite not met\n");
774 		return TEST_SKIPPED;
775 	}
776 
777 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
778 			&& check_auth_capabilities_supported(auths,
779 			RTE_DIM(auths)) != 0) {
780 		RTE_LOG(INFO, USER1, "Capability requirements for NULL "
781 				"testsuite not met\n");
782 		return TEST_SKIPPED;
783 	}
784 
785 	return 0;
786 }
787 
788 static int
789 crypto_gen_testsuite_setup(void)
790 {
791 	struct crypto_testsuite_params *ts_params = &testsuite_params;
792 	uint8_t dev_id = ts_params->valid_devs[0];
793 	struct rte_cryptodev_info dev_info;
794 
795 	rte_cryptodev_info_get(dev_id, &dev_info);
796 
797 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
798 		RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen "
799 				"testsuite not met\n");
800 		return TEST_SKIPPED;
801 	}
802 
803 	return 0;
804 }
805 
806 #ifdef RTE_LIB_SECURITY
807 static int
808 ipsec_proto_testsuite_setup(void)
809 {
810 	struct crypto_testsuite_params *ts_params = &testsuite_params;
811 	struct crypto_unittest_params *ut_params = &unittest_params;
812 	struct rte_cryptodev_info dev_info;
813 	int ret = 0;
814 
815 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
816 
817 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) {
818 		RTE_LOG(INFO, USER1, "Feature flag requirements for IPsec Proto "
819 				"testsuite not met\n");
820 		return TEST_SKIPPED;
821 	}
822 
823 	/* Reconfigure to enable security */
824 	ret = dev_configure_and_start(0);
825 	if (ret != TEST_SUCCESS)
826 		return ret;
827 
828 	/* Set action type */
829 	ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
830 
831 	if (security_proto_supported(
832 			RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
833 			RTE_SECURITY_PROTOCOL_IPSEC) < 0) {
834 		RTE_LOG(INFO, USER1, "Capability requirements for IPsec Proto "
835 				"test not met\n");
836 		ret = TEST_SKIPPED;
837 	}
838 
839 	test_ipsec_alg_list_populate();
840 	test_ipsec_ah_alg_list_populate();
841 
842 	/*
843 	 * Stop the device. Device would be started again by individual test
844 	 * case setup routine.
845 	 */
846 	rte_cryptodev_stop(ts_params->valid_devs[0]);
847 
848 	return ret;
849 }
850 
851 static int
852 pdcp_proto_testsuite_setup(void)
853 {
854 	struct crypto_testsuite_params *ts_params = &testsuite_params;
855 	uint8_t dev_id = ts_params->valid_devs[0];
856 	struct rte_cryptodev_info dev_info;
857 	const enum rte_crypto_cipher_algorithm ciphers[] = {
858 		RTE_CRYPTO_CIPHER_NULL,
859 		RTE_CRYPTO_CIPHER_AES_CTR,
860 		RTE_CRYPTO_CIPHER_ZUC_EEA3,
861 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
862 	};
863 	const enum rte_crypto_auth_algorithm auths[] = {
864 		RTE_CRYPTO_AUTH_NULL,
865 		RTE_CRYPTO_AUTH_SNOW3G_UIA2,
866 		RTE_CRYPTO_AUTH_AES_CMAC,
867 		RTE_CRYPTO_AUTH_ZUC_EIA3
868 	};
869 
870 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_auth_key));
871 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_bearer));
872 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_crypto_key));
873 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_in));
874 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_in_len));
875 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_out));
876 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_sn_size));
877 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_hfn));
878 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_hfn_threshold));
879 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_packet_direction));
880 
881 	rte_cryptodev_info_get(dev_id, &dev_info);
882 
883 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
884 			!(dev_info.feature_flags &
885 			RTE_CRYPTODEV_FF_SECURITY)) {
886 		RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto "
887 				"testsuite not met\n");
888 		return TEST_SKIPPED;
889 	}
890 
891 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
892 			&& check_auth_capabilities_supported(auths,
893 			RTE_DIM(auths)) != 0) {
894 		RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto "
895 				"testsuite not met\n");
896 		return TEST_SKIPPED;
897 	}
898 
899 	return 0;
900 }
901 
902 static int
903 docsis_proto_testsuite_setup(void)
904 {
905 	struct crypto_testsuite_params *ts_params = &testsuite_params;
906 	uint8_t dev_id = ts_params->valid_devs[0];
907 	struct rte_cryptodev_info dev_info;
908 	const enum rte_crypto_cipher_algorithm ciphers[] = {
909 		RTE_CRYPTO_CIPHER_AES_DOCSISBPI
910 	};
911 
912 	rte_cryptodev_info_get(dev_id, &dev_info);
913 
914 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
915 			!(dev_info.feature_flags &
916 			RTE_CRYPTODEV_FF_SECURITY)) {
917 		RTE_LOG(INFO, USER1, "Feature flag requirements for DOCSIS "
918 				"Proto testsuite not met\n");
919 		return TEST_SKIPPED;
920 	}
921 
922 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
923 		RTE_LOG(INFO, USER1, "Capability requirements for DOCSIS Proto "
924 				"testsuite not met\n");
925 		return TEST_SKIPPED;
926 	}
927 
928 	return 0;
929 }
930 #endif
931 
932 static int
933 aes_ccm_auth_testsuite_setup(void)
934 {
935 	struct crypto_testsuite_params *ts_params = &testsuite_params;
936 	uint8_t dev_id = ts_params->valid_devs[0];
937 	struct rte_cryptodev_info dev_info;
938 	const enum rte_crypto_aead_algorithm aeads[] = {
939 		RTE_CRYPTO_AEAD_AES_CCM
940 	};
941 
942 	rte_cryptodev_info_get(dev_id, &dev_info);
943 
944 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
945 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
946 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
947 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM "
948 				"testsuite not met\n");
949 		return TEST_SKIPPED;
950 	}
951 
952 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
953 		RTE_LOG(INFO, USER1, "Capability requirements for AES CCM "
954 				"testsuite not met\n");
955 		return TEST_SKIPPED;
956 	}
957 
958 	return 0;
959 }
960 
961 static int
962 aes_gcm_auth_testsuite_setup(void)
963 {
964 	struct crypto_testsuite_params *ts_params = &testsuite_params;
965 	uint8_t dev_id = ts_params->valid_devs[0];
966 	struct rte_cryptodev_info dev_info;
967 	const enum rte_crypto_aead_algorithm aeads[] = {
968 		RTE_CRYPTO_AEAD_AES_GCM
969 	};
970 
971 	rte_cryptodev_info_get(dev_id, &dev_info);
972 
973 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
974 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM "
975 				"testsuite not met\n");
976 		return TEST_SKIPPED;
977 	}
978 
979 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
980 		RTE_LOG(INFO, USER1, "Capability requirements for AES GCM "
981 				"testsuite not met\n");
982 		return TEST_SKIPPED;
983 	}
984 
985 	return 0;
986 }
987 
988 static int
989 aes_gmac_auth_testsuite_setup(void)
990 {
991 	struct crypto_testsuite_params *ts_params = &testsuite_params;
992 	uint8_t dev_id = ts_params->valid_devs[0];
993 	struct rte_cryptodev_info dev_info;
994 	const enum rte_crypto_auth_algorithm auths[] = {
995 		RTE_CRYPTO_AUTH_AES_GMAC
996 	};
997 
998 	rte_cryptodev_info_get(dev_id, &dev_info);
999 
1000 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1001 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1002 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1003 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC "
1004 				"testsuite not met\n");
1005 		return TEST_SKIPPED;
1006 	}
1007 
1008 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1009 		RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC "
1010 				"testsuite not met\n");
1011 		return TEST_SKIPPED;
1012 	}
1013 
1014 	return 0;
1015 }
1016 
1017 static int
1018 chacha20_poly1305_testsuite_setup(void)
1019 {
1020 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1021 	uint8_t dev_id = ts_params->valid_devs[0];
1022 	struct rte_cryptodev_info dev_info;
1023 	const enum rte_crypto_aead_algorithm aeads[] = {
1024 		RTE_CRYPTO_AEAD_CHACHA20_POLY1305
1025 	};
1026 
1027 	rte_cryptodev_info_get(dev_id, &dev_info);
1028 
1029 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1030 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1031 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1032 		RTE_LOG(INFO, USER1, "Feature flag requirements for "
1033 				"Chacha20-Poly1305 testsuite not met\n");
1034 		return TEST_SKIPPED;
1035 	}
1036 
1037 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1038 		RTE_LOG(INFO, USER1, "Capability requirements for "
1039 				"Chacha20-Poly1305 testsuite not met\n");
1040 		return TEST_SKIPPED;
1041 	}
1042 
1043 	return 0;
1044 }
1045 
1046 static int
1047 snow3g_testsuite_setup(void)
1048 {
1049 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1050 	uint8_t dev_id = ts_params->valid_devs[0];
1051 	struct rte_cryptodev_info dev_info;
1052 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1053 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1054 
1055 	};
1056 	const enum rte_crypto_auth_algorithm auths[] = {
1057 		RTE_CRYPTO_AUTH_SNOW3G_UIA2
1058 	};
1059 
1060 	rte_cryptodev_info_get(dev_id, &dev_info);
1061 
1062 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1063 		RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G "
1064 				"testsuite not met\n");
1065 		return TEST_SKIPPED;
1066 	}
1067 
1068 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1069 			&& check_auth_capabilities_supported(auths,
1070 			RTE_DIM(auths)) != 0) {
1071 		RTE_LOG(INFO, USER1, "Capability requirements for Snow3G "
1072 				"testsuite not met\n");
1073 		return TEST_SKIPPED;
1074 	}
1075 
1076 	return 0;
1077 }
1078 
1079 static int
1080 zuc_testsuite_setup(void)
1081 {
1082 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1083 	uint8_t dev_id = ts_params->valid_devs[0];
1084 	struct rte_cryptodev_info dev_info;
1085 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1086 		RTE_CRYPTO_CIPHER_ZUC_EEA3
1087 	};
1088 	const enum rte_crypto_auth_algorithm auths[] = {
1089 		RTE_CRYPTO_AUTH_ZUC_EIA3
1090 	};
1091 
1092 	rte_cryptodev_info_get(dev_id, &dev_info);
1093 
1094 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1095 		RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC "
1096 				"testsuite not met\n");
1097 		return TEST_SKIPPED;
1098 	}
1099 
1100 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1101 			&& check_auth_capabilities_supported(auths,
1102 			RTE_DIM(auths)) != 0) {
1103 		RTE_LOG(INFO, USER1, "Capability requirements for ZUC "
1104 				"testsuite not met\n");
1105 		return TEST_SKIPPED;
1106 	}
1107 
1108 	return 0;
1109 }
1110 
1111 static int
1112 hmac_md5_auth_testsuite_setup(void)
1113 {
1114 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1115 	uint8_t dev_id = ts_params->valid_devs[0];
1116 	struct rte_cryptodev_info dev_info;
1117 	const enum rte_crypto_auth_algorithm auths[] = {
1118 		RTE_CRYPTO_AUTH_MD5_HMAC
1119 	};
1120 
1121 	rte_cryptodev_info_get(dev_id, &dev_info);
1122 
1123 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1124 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1125 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1126 		RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 "
1127 				"Auth testsuite not met\n");
1128 		return TEST_SKIPPED;
1129 	}
1130 
1131 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1132 		RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 "
1133 				"testsuite not met\n");
1134 		return TEST_SKIPPED;
1135 	}
1136 
1137 	return 0;
1138 }
1139 
1140 static int
1141 kasumi_testsuite_setup(void)
1142 {
1143 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1144 	uint8_t dev_id = ts_params->valid_devs[0];
1145 	struct rte_cryptodev_info dev_info;
1146 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1147 		RTE_CRYPTO_CIPHER_KASUMI_F8
1148 	};
1149 	const enum rte_crypto_auth_algorithm auths[] = {
1150 		RTE_CRYPTO_AUTH_KASUMI_F9
1151 	};
1152 
1153 	rte_cryptodev_info_get(dev_id, &dev_info);
1154 
1155 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1156 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1157 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1158 		RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi "
1159 				"testsuite not met\n");
1160 		return TEST_SKIPPED;
1161 	}
1162 
1163 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1164 			&& check_auth_capabilities_supported(auths,
1165 			RTE_DIM(auths)) != 0) {
1166 		RTE_LOG(INFO, USER1, "Capability requirements for Kasumi "
1167 				"testsuite not met\n");
1168 		return TEST_SKIPPED;
1169 	}
1170 
1171 	return 0;
1172 }
1173 
1174 static int
1175 negative_aes_gcm_testsuite_setup(void)
1176 {
1177 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1178 	uint8_t dev_id = ts_params->valid_devs[0];
1179 	struct rte_cryptodev_info dev_info;
1180 	const enum rte_crypto_aead_algorithm aeads[] = {
1181 		RTE_CRYPTO_AEAD_AES_GCM
1182 	};
1183 
1184 	rte_cryptodev_info_get(dev_id, &dev_info);
1185 
1186 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1187 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1188 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1189 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1190 				"AES GCM testsuite not met\n");
1191 		return TEST_SKIPPED;
1192 	}
1193 
1194 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1195 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1196 				"AES GCM testsuite not met\n");
1197 		return TEST_SKIPPED;
1198 	}
1199 
1200 	return 0;
1201 }
1202 
1203 static int
1204 negative_aes_gmac_testsuite_setup(void)
1205 {
1206 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1207 	uint8_t dev_id = ts_params->valid_devs[0];
1208 	struct rte_cryptodev_info dev_info;
1209 	const enum rte_crypto_auth_algorithm auths[] = {
1210 		RTE_CRYPTO_AUTH_AES_GMAC
1211 	};
1212 
1213 	rte_cryptodev_info_get(dev_id, &dev_info);
1214 
1215 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1216 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1217 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1218 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1219 				"AES GMAC testsuite not met\n");
1220 		return TEST_SKIPPED;
1221 	}
1222 
1223 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1224 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1225 				"AES GMAC testsuite not met\n");
1226 		return TEST_SKIPPED;
1227 	}
1228 
1229 	return 0;
1230 }
1231 
1232 static int
1233 mixed_cipher_hash_testsuite_setup(void)
1234 {
1235 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1236 	uint8_t dev_id = ts_params->valid_devs[0];
1237 	struct rte_cryptodev_info dev_info;
1238 	uint64_t feat_flags;
1239 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1240 		RTE_CRYPTO_CIPHER_NULL,
1241 		RTE_CRYPTO_CIPHER_AES_CTR,
1242 		RTE_CRYPTO_CIPHER_ZUC_EEA3,
1243 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1244 	};
1245 	const enum rte_crypto_auth_algorithm auths[] = {
1246 		RTE_CRYPTO_AUTH_NULL,
1247 		RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1248 		RTE_CRYPTO_AUTH_AES_CMAC,
1249 		RTE_CRYPTO_AUTH_ZUC_EIA3
1250 	};
1251 
1252 	rte_cryptodev_info_get(dev_id, &dev_info);
1253 	feat_flags = dev_info.feature_flags;
1254 
1255 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1256 			(global_api_test_type == CRYPTODEV_RAW_API_TEST)) {
1257 		RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed "
1258 				"Cipher Hash testsuite not met\n");
1259 		return TEST_SKIPPED;
1260 	}
1261 
1262 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1263 			&& check_auth_capabilities_supported(auths,
1264 			RTE_DIM(auths)) != 0) {
1265 		RTE_LOG(INFO, USER1, "Capability requirements for Mixed "
1266 				"Cipher Hash testsuite not met\n");
1267 		return TEST_SKIPPED;
1268 	}
1269 
1270 	return 0;
1271 }
1272 
1273 static int
1274 esn_testsuite_setup(void)
1275 {
1276 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1277 	uint8_t dev_id = ts_params->valid_devs[0];
1278 	struct rte_cryptodev_info dev_info;
1279 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1280 		RTE_CRYPTO_CIPHER_AES_CBC
1281 	};
1282 	const enum rte_crypto_auth_algorithm auths[] = {
1283 		RTE_CRYPTO_AUTH_SHA1_HMAC
1284 	};
1285 
1286 	rte_cryptodev_info_get(dev_id, &dev_info);
1287 
1288 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1289 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1290 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1291 		RTE_LOG(INFO, USER1, "Feature flag requirements for ESN "
1292 				"testsuite not met\n");
1293 		return TEST_SKIPPED;
1294 	}
1295 
1296 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1297 			&& check_auth_capabilities_supported(auths,
1298 			RTE_DIM(auths)) != 0) {
1299 		RTE_LOG(INFO, USER1, "Capability requirements for ESN "
1300 				"testsuite not met\n");
1301 		return TEST_SKIPPED;
1302 	}
1303 
1304 	return 0;
1305 }
1306 
1307 static int
1308 multi_session_testsuite_setup(void)
1309 {
1310 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1311 	uint8_t dev_id = ts_params->valid_devs[0];
1312 	struct rte_cryptodev_info dev_info;
1313 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1314 		RTE_CRYPTO_CIPHER_AES_CBC
1315 	};
1316 	const enum rte_crypto_auth_algorithm auths[] = {
1317 		RTE_CRYPTO_AUTH_SHA512_HMAC
1318 	};
1319 
1320 	rte_cryptodev_info_get(dev_id, &dev_info);
1321 
1322 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1323 		RTE_LOG(INFO, USER1, "Feature flag requirements for Multi "
1324 				"Session testsuite not met\n");
1325 		return TEST_SKIPPED;
1326 	}
1327 
1328 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1329 			&& check_auth_capabilities_supported(auths,
1330 			RTE_DIM(auths)) != 0) {
1331 		RTE_LOG(INFO, USER1, "Capability requirements for Multi "
1332 				"Session testsuite not met\n");
1333 		return TEST_SKIPPED;
1334 	}
1335 
1336 	return 0;
1337 }
1338 
1339 static int
1340 negative_hmac_sha1_testsuite_setup(void)
1341 {
1342 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1343 	uint8_t dev_id = ts_params->valid_devs[0];
1344 	struct rte_cryptodev_info dev_info;
1345 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1346 		RTE_CRYPTO_CIPHER_AES_CBC
1347 	};
1348 	const enum rte_crypto_auth_algorithm auths[] = {
1349 		RTE_CRYPTO_AUTH_SHA1_HMAC
1350 	};
1351 
1352 	rte_cryptodev_info_get(dev_id, &dev_info);
1353 
1354 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1355 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1356 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1357 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1358 				"HMAC SHA1 testsuite not met\n");
1359 		return TEST_SKIPPED;
1360 	}
1361 
1362 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1363 			&& check_auth_capabilities_supported(auths,
1364 			RTE_DIM(auths)) != 0) {
1365 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1366 				"HMAC SHA1 testsuite not met\n");
1367 		return TEST_SKIPPED;
1368 	}
1369 
1370 	return 0;
1371 }
1372 
1373 static int
1374 dev_configure_and_start(uint64_t ff_disable)
1375 {
1376 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1377 	struct crypto_unittest_params *ut_params = &unittest_params;
1378 
1379 	uint16_t qp_id;
1380 
1381 	/* Clear unit test parameters before running test */
1382 	memset(ut_params, 0, sizeof(*ut_params));
1383 
1384 	/* Reconfigure device to default parameters */
1385 	ts_params->conf.socket_id = SOCKET_ID_ANY;
1386 	ts_params->conf.ff_disable = ff_disable;
1387 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
1388 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
1389 
1390 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1391 			&ts_params->conf),
1392 			"Failed to configure cryptodev %u",
1393 			ts_params->valid_devs[0]);
1394 
1395 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
1396 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1397 			ts_params->valid_devs[0], qp_id,
1398 			&ts_params->qp_conf,
1399 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1400 			"Failed to setup queue pair %u on cryptodev %u",
1401 			qp_id, ts_params->valid_devs[0]);
1402 	}
1403 
1404 
1405 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1406 
1407 	/* Start the device */
1408 	TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1409 			"Failed to start cryptodev %u",
1410 			ts_params->valid_devs[0]);
1411 
1412 	return TEST_SUCCESS;
1413 }
1414 
1415 int
1416 ut_setup(void)
1417 {
1418 	/* Configure and start the device with security feature disabled */
1419 	return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
1420 }
1421 
1422 static int
1423 ut_setup_security(void)
1424 {
1425 	/* Configure and start the device with no features disabled */
1426 	return dev_configure_and_start(0);
1427 }
1428 
1429 void
1430 ut_teardown(void)
1431 {
1432 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1433 	struct crypto_unittest_params *ut_params = &unittest_params;
1434 
1435 	/* free crypto session structure */
1436 #ifdef RTE_LIB_SECURITY
1437 	if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
1438 		if (ut_params->sec_session) {
1439 			rte_security_session_destroy(rte_cryptodev_get_sec_ctx
1440 						(ts_params->valid_devs[0]),
1441 						ut_params->sec_session);
1442 			ut_params->sec_session = NULL;
1443 		}
1444 	} else
1445 #endif
1446 	{
1447 		if (ut_params->sess) {
1448 			rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
1449 					ut_params->sess);
1450 			ut_params->sess = NULL;
1451 		}
1452 	}
1453 
1454 	/* free crypto operation structure */
1455 	rte_crypto_op_free(ut_params->op);
1456 
1457 	/*
1458 	 * free mbuf - both obuf and ibuf are usually the same,
1459 	 * so check if they point at the same address is necessary,
1460 	 * to avoid freeing the mbuf twice.
1461 	 */
1462 	if (ut_params->obuf) {
1463 		rte_pktmbuf_free(ut_params->obuf);
1464 		if (ut_params->ibuf == ut_params->obuf)
1465 			ut_params->ibuf = 0;
1466 		ut_params->obuf = 0;
1467 	}
1468 	if (ut_params->ibuf) {
1469 		rte_pktmbuf_free(ut_params->ibuf);
1470 		ut_params->ibuf = 0;
1471 	}
1472 
1473 	if (ts_params->mbuf_pool != NULL)
1474 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
1475 			rte_mempool_avail_count(ts_params->mbuf_pool));
1476 
1477 	/* Stop the device */
1478 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1479 }
1480 
1481 static int
1482 test_device_configure_invalid_dev_id(void)
1483 {
1484 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1485 	uint16_t dev_id, num_devs = 0;
1486 
1487 	TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
1488 			"Need at least %d devices for test", 1);
1489 
1490 	/* valid dev_id values */
1491 	dev_id = ts_params->valid_devs[0];
1492 
1493 	/* Stop the device in case it's started so it can be configured */
1494 	rte_cryptodev_stop(dev_id);
1495 
1496 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
1497 			"Failed test for rte_cryptodev_configure: "
1498 			"invalid dev_num %u", dev_id);
1499 
1500 	/* invalid dev_id values */
1501 	dev_id = num_devs;
1502 
1503 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1504 			"Failed test for rte_cryptodev_configure: "
1505 			"invalid dev_num %u", dev_id);
1506 
1507 	dev_id = 0xff;
1508 
1509 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1510 			"Failed test for rte_cryptodev_configure:"
1511 			"invalid dev_num %u", dev_id);
1512 
1513 	return TEST_SUCCESS;
1514 }
1515 
1516 static int
1517 test_device_configure_invalid_queue_pair_ids(void)
1518 {
1519 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1520 	uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1521 
1522 	/* Stop the device in case it's started so it can be configured */
1523 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1524 
1525 	/* valid - max value queue pairs */
1526 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1527 
1528 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1529 			&ts_params->conf),
1530 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1531 			ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1532 
1533 	/* valid - one queue pairs */
1534 	ts_params->conf.nb_queue_pairs = 1;
1535 
1536 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1537 			&ts_params->conf),
1538 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1539 			ts_params->valid_devs[0],
1540 			ts_params->conf.nb_queue_pairs);
1541 
1542 
1543 	/* invalid - zero queue pairs */
1544 	ts_params->conf.nb_queue_pairs = 0;
1545 
1546 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1547 			&ts_params->conf),
1548 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1549 			" invalid qps: %u",
1550 			ts_params->valid_devs[0],
1551 			ts_params->conf.nb_queue_pairs);
1552 
1553 
1554 	/* invalid - max value supported by field queue pairs */
1555 	ts_params->conf.nb_queue_pairs = UINT16_MAX;
1556 
1557 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1558 			&ts_params->conf),
1559 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1560 			" invalid qps: %u",
1561 			ts_params->valid_devs[0],
1562 			ts_params->conf.nb_queue_pairs);
1563 
1564 
1565 	/* invalid - max value + 1 queue pairs */
1566 	ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1567 
1568 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1569 			&ts_params->conf),
1570 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1571 			" invalid qps: %u",
1572 			ts_params->valid_devs[0],
1573 			ts_params->conf.nb_queue_pairs);
1574 
1575 	/* revert to original testsuite value */
1576 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1577 
1578 	return TEST_SUCCESS;
1579 }
1580 
1581 static int
1582 test_queue_pair_descriptor_setup(void)
1583 {
1584 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1585 	struct rte_cryptodev_qp_conf qp_conf = {
1586 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
1587 	};
1588 	uint16_t qp_id;
1589 
1590 	/* Stop the device in case it's started so it can be configured */
1591 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1592 
1593 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1594 			&ts_params->conf),
1595 			"Failed to configure cryptodev %u",
1596 			ts_params->valid_devs[0]);
1597 
1598 	/*
1599 	 * Test various ring sizes on this device. memzones can't be
1600 	 * freed so are re-used if ring is released and re-created.
1601 	 */
1602 	qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1603 	qp_conf.mp_session = ts_params->session_mpool;
1604 
1605 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1606 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1607 				ts_params->valid_devs[0], qp_id, &qp_conf,
1608 				rte_cryptodev_socket_id(
1609 						ts_params->valid_devs[0])),
1610 				"Failed test for "
1611 				"rte_cryptodev_queue_pair_setup: num_inflights "
1612 				"%u on qp %u on cryptodev %u",
1613 				qp_conf.nb_descriptors, qp_id,
1614 				ts_params->valid_devs[0]);
1615 	}
1616 
1617 	qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1618 
1619 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1620 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1621 				ts_params->valid_devs[0], qp_id, &qp_conf,
1622 				rte_cryptodev_socket_id(
1623 						ts_params->valid_devs[0])),
1624 				"Failed test for"
1625 				" rte_cryptodev_queue_pair_setup: num_inflights"
1626 				" %u on qp %u on cryptodev %u",
1627 				qp_conf.nb_descriptors, qp_id,
1628 				ts_params->valid_devs[0]);
1629 	}
1630 
1631 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
1632 
1633 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1634 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1635 				ts_params->valid_devs[0], qp_id, &qp_conf,
1636 				rte_cryptodev_socket_id(
1637 						ts_params->valid_devs[0])),
1638 				"Failed test for "
1639 				"rte_cryptodev_queue_pair_setup: num_inflights"
1640 				" %u on qp %u on cryptodev %u",
1641 				qp_conf.nb_descriptors, qp_id,
1642 				ts_params->valid_devs[0]);
1643 	}
1644 
1645 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1646 
1647 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1648 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1649 				ts_params->valid_devs[0], qp_id, &qp_conf,
1650 				rte_cryptodev_socket_id(
1651 						ts_params->valid_devs[0])),
1652 				"Failed test for"
1653 				" rte_cryptodev_queue_pair_setup:"
1654 				"num_inflights %u on qp %u on cryptodev %u",
1655 				qp_conf.nb_descriptors, qp_id,
1656 				ts_params->valid_devs[0]);
1657 	}
1658 
1659 	/* test invalid queue pair id */
1660 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;	/*valid */
1661 
1662 	qp_id = ts_params->conf.nb_queue_pairs;		/*invalid */
1663 
1664 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1665 			ts_params->valid_devs[0],
1666 			qp_id, &qp_conf,
1667 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1668 			"Failed test for rte_cryptodev_queue_pair_setup:"
1669 			"invalid qp %u on cryptodev %u",
1670 			qp_id, ts_params->valid_devs[0]);
1671 
1672 	qp_id = 0xffff; /*invalid*/
1673 
1674 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1675 			ts_params->valid_devs[0],
1676 			qp_id, &qp_conf,
1677 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1678 			"Failed test for rte_cryptodev_queue_pair_setup:"
1679 			"invalid qp %u on cryptodev %u",
1680 			qp_id, ts_params->valid_devs[0]);
1681 
1682 	return TEST_SUCCESS;
1683 }
1684 
1685 /* ***** Plaintext data for tests ***** */
1686 
1687 const char catch_22_quote_1[] =
1688 		"There was only one catch and that was Catch-22, which "
1689 		"specified that a concern for one's safety in the face of "
1690 		"dangers that were real and immediate was the process of a "
1691 		"rational mind. Orr was crazy and could be grounded. All he "
1692 		"had to do was ask; and as soon as he did, he would no longer "
1693 		"be crazy and would have to fly more missions. Orr would be "
1694 		"crazy to fly more missions and sane if he didn't, but if he "
1695 		"was sane he had to fly them. If he flew them he was crazy "
1696 		"and didn't have to; but if he didn't want to he was sane and "
1697 		"had to. Yossarian was moved very deeply by the absolute "
1698 		"simplicity of this clause of Catch-22 and let out a "
1699 		"respectful whistle. \"That's some catch, that Catch-22\", he "
1700 		"observed. \"It's the best there is,\" Doc Daneeka agreed.";
1701 
1702 const char catch_22_quote[] =
1703 		"What a lousy earth! He wondered how many people were "
1704 		"destitute that same night even in his own prosperous country, "
1705 		"how many homes were shanties, how many husbands were drunk "
1706 		"and wives socked, and how many children were bullied, abused, "
1707 		"or abandoned. How many families hungered for food they could "
1708 		"not afford to buy? How many hearts were broken? How many "
1709 		"suicides would take place that same night, how many people "
1710 		"would go insane? How many cockroaches and landlords would "
1711 		"triumph? How many winners were losers, successes failures, "
1712 		"and rich men poor men? How many wise guys were stupid? How "
1713 		"many happy endings were unhappy endings? How many honest men "
1714 		"were liars, brave men cowards, loyal men traitors, how many "
1715 		"sainted men were corrupt, how many people in positions of "
1716 		"trust had sold their souls to bodyguards, how many had never "
1717 		"had souls? How many straight-and-narrow paths were crooked "
1718 		"paths? How many best families were worst families and how "
1719 		"many good people were bad people? When you added them all up "
1720 		"and then subtracted, you might be left with only the children, "
1721 		"and perhaps with Albert Einstein and an old violinist or "
1722 		"sculptor somewhere.";
1723 
1724 #define QUOTE_480_BYTES		(480)
1725 #define QUOTE_512_BYTES		(512)
1726 #define QUOTE_768_BYTES		(768)
1727 #define QUOTE_1024_BYTES	(1024)
1728 
1729 
1730 
1731 /* ***** SHA1 Hash Tests ***** */
1732 
1733 #define HMAC_KEY_LENGTH_SHA1	(DIGEST_BYTE_LENGTH_SHA1)
1734 
1735 static uint8_t hmac_sha1_key[] = {
1736 	0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1737 	0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1738 	0xDE, 0xF4, 0xDE, 0xAD };
1739 
1740 /* ***** SHA224 Hash Tests ***** */
1741 
1742 #define HMAC_KEY_LENGTH_SHA224	(DIGEST_BYTE_LENGTH_SHA224)
1743 
1744 
1745 /* ***** AES-CBC Cipher Tests ***** */
1746 
1747 #define CIPHER_KEY_LENGTH_AES_CBC	(16)
1748 #define CIPHER_IV_LENGTH_AES_CBC	(CIPHER_KEY_LENGTH_AES_CBC)
1749 
1750 static uint8_t aes_cbc_key[] = {
1751 	0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1752 	0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1753 
1754 static uint8_t aes_cbc_iv[] = {
1755 	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1756 	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1757 
1758 
1759 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1760 
1761 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1762 	0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1763 	0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1764 	0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1765 	0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1766 	0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1767 	0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1768 	0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1769 	0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1770 	0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1771 	0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1772 	0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1773 	0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1774 	0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1775 	0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1776 	0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1777 	0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1778 	0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1779 	0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1780 	0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1781 	0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1782 	0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1783 	0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1784 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1785 	0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1786 	0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1787 	0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1788 	0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1789 	0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1790 	0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1791 	0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1792 	0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1793 	0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1794 	0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1795 	0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1796 	0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1797 	0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1798 	0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1799 	0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1800 	0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1801 	0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1802 	0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1803 	0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1804 	0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1805 	0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1806 	0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1807 	0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1808 	0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1809 	0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1810 	0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1811 	0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1812 	0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1813 	0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1814 	0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1815 	0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1816 	0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1817 	0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1818 	0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1819 	0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1820 	0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1821 	0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1822 	0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1823 	0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1824 	0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1825 	0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1826 };
1827 
1828 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1829 	0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1830 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1831 	0x18, 0x8c, 0x1d, 0x32
1832 };
1833 
1834 
1835 /* Multisession Vector context Test */
1836 /*Begin Session 0 */
1837 static uint8_t ms_aes_cbc_key0[] = {
1838 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1839 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1840 };
1841 
1842 static uint8_t ms_aes_cbc_iv0[] = {
1843 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1844 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1845 };
1846 
1847 static const uint8_t ms_aes_cbc_cipher0[] = {
1848 		0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1849 		0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1850 		0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1851 		0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1852 		0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1853 		0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1854 		0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1855 		0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1856 		0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1857 		0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1858 		0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1859 		0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1860 		0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1861 		0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1862 		0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1863 		0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1864 		0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1865 		0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1866 		0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1867 		0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1868 		0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1869 		0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1870 		0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1871 		0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1872 		0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1873 		0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1874 		0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1875 		0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1876 		0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1877 		0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1878 		0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1879 		0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1880 		0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1881 		0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1882 		0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1883 		0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1884 		0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1885 		0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1886 		0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1887 		0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1888 		0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1889 		0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1890 		0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1891 		0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1892 		0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1893 		0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1894 		0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1895 		0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1896 		0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1897 		0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1898 		0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1899 		0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1900 		0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1901 		0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1902 		0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1903 		0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1904 		0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1905 		0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1906 		0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1907 		0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1908 		0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1909 		0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1910 		0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1911 		0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1912 };
1913 
1914 
1915 static  uint8_t ms_hmac_key0[] = {
1916 		0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1917 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1918 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1919 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1920 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1921 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1922 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1923 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1924 };
1925 
1926 static const uint8_t ms_hmac_digest0[] = {
1927 		0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1928 		0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1929 		0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1930 		0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1931 		0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1932 		0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1933 		0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1934 		0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1935 		};
1936 
1937 /* End Session 0 */
1938 /* Begin session 1 */
1939 
1940 static  uint8_t ms_aes_cbc_key1[] = {
1941 		0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1942 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1943 };
1944 
1945 static  uint8_t ms_aes_cbc_iv1[] = {
1946 	0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1947 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1948 };
1949 
1950 static const uint8_t ms_aes_cbc_cipher1[] = {
1951 		0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1952 		0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1953 		0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1954 		0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1955 		0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1956 		0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1957 		0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1958 		0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1959 		0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1960 		0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1961 		0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1962 		0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1963 		0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1964 		0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1965 		0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1966 		0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1967 		0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1968 		0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1969 		0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1970 		0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1971 		0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1972 		0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1973 		0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1974 		0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1975 		0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1976 		0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1977 		0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1978 		0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1979 		0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1980 		0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1981 		0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1982 		0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1983 		0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1984 		0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1985 		0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1986 		0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1987 		0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1988 		0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1989 		0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1990 		0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1991 		0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1992 		0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1993 		0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1994 		0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1995 		0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1996 		0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1997 		0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1998 		0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1999 		0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
2000 		0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
2001 		0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
2002 		0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
2003 		0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
2004 		0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
2005 		0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
2006 		0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
2007 		0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
2008 		0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
2009 		0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
2010 		0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
2011 		0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
2012 		0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
2013 		0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
2014 		0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
2015 
2016 };
2017 
2018 static uint8_t ms_hmac_key1[] = {
2019 		0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2020 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2021 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2022 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2023 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2024 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2025 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2026 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2027 };
2028 
2029 static const uint8_t ms_hmac_digest1[] = {
2030 		0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
2031 		0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
2032 		0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
2033 		0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
2034 		0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
2035 		0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
2036 		0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
2037 		0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
2038 };
2039 /* End Session 1  */
2040 /* Begin Session 2 */
2041 static  uint8_t ms_aes_cbc_key2[] = {
2042 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2043 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2044 };
2045 
2046 static  uint8_t ms_aes_cbc_iv2[] = {
2047 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2048 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2049 };
2050 
2051 static const uint8_t ms_aes_cbc_cipher2[] = {
2052 		0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
2053 		0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
2054 		0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
2055 		0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
2056 		0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
2057 		0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
2058 		0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
2059 		0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
2060 		0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
2061 		0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
2062 		0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
2063 		0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
2064 		0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
2065 		0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
2066 		0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
2067 		0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
2068 		0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
2069 		0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
2070 		0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
2071 		0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
2072 		0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
2073 		0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
2074 		0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
2075 		0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
2076 		0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
2077 		0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
2078 		0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
2079 		0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
2080 		0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
2081 		0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
2082 		0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
2083 		0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
2084 		0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
2085 		0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
2086 		0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
2087 		0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
2088 		0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
2089 		0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
2090 		0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
2091 		0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
2092 		0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
2093 		0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
2094 		0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
2095 		0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
2096 		0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
2097 		0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
2098 		0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
2099 		0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
2100 		0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
2101 		0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
2102 		0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
2103 		0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
2104 		0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
2105 		0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
2106 		0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
2107 		0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
2108 		0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
2109 		0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
2110 		0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
2111 		0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
2112 		0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
2113 		0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
2114 		0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
2115 		0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
2116 };
2117 
2118 static  uint8_t ms_hmac_key2[] = {
2119 		0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2120 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2121 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2122 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2123 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2124 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2125 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2126 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2127 };
2128 
2129 static const uint8_t ms_hmac_digest2[] = {
2130 		0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
2131 		0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
2132 		0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
2133 		0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
2134 		0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
2135 		0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
2136 		0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
2137 		0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
2138 };
2139 
2140 /* End Session 2 */
2141 
2142 
2143 static int
2144 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
2145 {
2146 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2147 	struct crypto_unittest_params *ut_params = &unittest_params;
2148 	/* Verify the capabilities */
2149 	struct rte_cryptodev_sym_capability_idx cap_idx;
2150 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2151 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
2152 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2153 			&cap_idx) == NULL)
2154 		return TEST_SKIPPED;
2155 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2156 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
2157 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2158 			&cap_idx) == NULL)
2159 		return TEST_SKIPPED;
2160 
2161 	/* Generate test mbuf data and space for digest */
2162 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2163 			catch_22_quote,	QUOTE_512_BYTES, 0);
2164 
2165 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2166 			DIGEST_BYTE_LENGTH_SHA1);
2167 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2168 
2169 	/* Setup Cipher Parameters */
2170 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2171 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2172 
2173 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2174 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2175 	ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2176 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2177 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2178 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2179 
2180 	/* Setup HMAC Parameters */
2181 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2182 
2183 	ut_params->auth_xform.next = NULL;
2184 
2185 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2186 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
2187 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
2188 	ut_params->auth_xform.auth.key.data = hmac_sha1_key;
2189 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
2190 
2191 	rte_errno = 0;
2192 	ut_params->sess = rte_cryptodev_sym_session_create(
2193 			ts_params->valid_devs[0], &ut_params->cipher_xform,
2194 			ts_params->session_mpool);
2195 	if (rte_errno == ENOTSUP)
2196 		return TEST_SKIPPED;
2197 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2198 
2199 	/* Generate crypto op data structure */
2200 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2201 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2202 	TEST_ASSERT_NOT_NULL(ut_params->op,
2203 			"Failed to allocate symmetric crypto operation struct");
2204 
2205 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2206 
2207 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2208 
2209 	/* set crypto operation source mbuf */
2210 	sym_op->m_src = ut_params->ibuf;
2211 
2212 	/* Set crypto operation authentication parameters */
2213 	sym_op->auth.digest.data = ut_params->digest;
2214 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2215 			ut_params->ibuf, QUOTE_512_BYTES);
2216 
2217 	sym_op->auth.data.offset = 0;
2218 	sym_op->auth.data.length = QUOTE_512_BYTES;
2219 
2220 	/* Copy IV at the end of the crypto operation */
2221 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2222 			aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
2223 
2224 	/* Set crypto operation cipher parameters */
2225 	sym_op->cipher.data.offset = 0;
2226 	sym_op->cipher.data.length = QUOTE_512_BYTES;
2227 
2228 	/* Process crypto operation */
2229 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2230 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2231 			ut_params->op);
2232 	else
2233 		TEST_ASSERT_NOT_NULL(
2234 			process_crypto_request(ts_params->valid_devs[0],
2235 				ut_params->op),
2236 				"failed to process sym crypto op");
2237 
2238 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2239 			"crypto op processing failed");
2240 
2241 	/* Validate obuf */
2242 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
2243 			uint8_t *);
2244 
2245 	TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
2246 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2247 			QUOTE_512_BYTES,
2248 			"ciphertext data not as expected");
2249 
2250 	uint8_t *digest = ciphertext + QUOTE_512_BYTES;
2251 
2252 	TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
2253 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
2254 			gbl_driver_id == rte_cryptodev_driver_id_get(
2255 					RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
2256 					TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
2257 					DIGEST_BYTE_LENGTH_SHA1,
2258 			"Generated digest data not as expected");
2259 
2260 	return TEST_SUCCESS;
2261 }
2262 
2263 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
2264 
2265 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
2266 
2267 static uint8_t hmac_sha512_key[] = {
2268 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
2269 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2270 	0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2271 	0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
2272 	0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
2273 	0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2274 	0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
2275 	0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
2276 
2277 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
2278 	0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
2279 	0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
2280 	0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
2281 	0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
2282 	0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
2283 	0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
2284 	0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
2285 	0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
2286 
2287 
2288 
2289 static int
2290 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2291 		struct crypto_unittest_params *ut_params,
2292 		uint8_t *cipher_key,
2293 		uint8_t *hmac_key);
2294 
2295 static int
2296 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess,
2297 		struct crypto_unittest_params *ut_params,
2298 		struct crypto_testsuite_params *ts_params,
2299 		const uint8_t *cipher,
2300 		const uint8_t *digest,
2301 		const uint8_t *iv);
2302 
2303 
2304 static int
2305 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2306 		struct crypto_unittest_params *ut_params,
2307 		uint8_t *cipher_key,
2308 		uint8_t *hmac_key)
2309 {
2310 
2311 	/* Setup Cipher Parameters */
2312 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2313 	ut_params->cipher_xform.next = NULL;
2314 
2315 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2316 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
2317 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2318 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2319 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2320 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2321 
2322 	/* Setup HMAC Parameters */
2323 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2324 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2325 
2326 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
2327 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
2328 	ut_params->auth_xform.auth.key.data = hmac_key;
2329 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
2330 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
2331 
2332 	return TEST_SUCCESS;
2333 }
2334 
2335 
2336 static int
2337 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess,
2338 		struct crypto_unittest_params *ut_params,
2339 		struct crypto_testsuite_params *ts_params,
2340 		const uint8_t *cipher,
2341 		const uint8_t *digest,
2342 		const uint8_t *iv)
2343 {
2344 	int ret;
2345 
2346 	/* Generate test mbuf data and digest */
2347 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2348 			(const char *)
2349 			cipher,
2350 			QUOTE_512_BYTES, 0);
2351 
2352 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2353 			DIGEST_BYTE_LENGTH_SHA512);
2354 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2355 
2356 	rte_memcpy(ut_params->digest,
2357 			digest,
2358 			DIGEST_BYTE_LENGTH_SHA512);
2359 
2360 	/* Generate Crypto op data structure */
2361 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2362 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2363 	TEST_ASSERT_NOT_NULL(ut_params->op,
2364 			"Failed to allocate symmetric crypto operation struct");
2365 
2366 	rte_crypto_op_attach_sym_session(ut_params->op, sess);
2367 
2368 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2369 
2370 	/* set crypto operation source mbuf */
2371 	sym_op->m_src = ut_params->ibuf;
2372 
2373 	sym_op->auth.digest.data = ut_params->digest;
2374 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2375 			ut_params->ibuf, QUOTE_512_BYTES);
2376 
2377 	sym_op->auth.data.offset = 0;
2378 	sym_op->auth.data.length = QUOTE_512_BYTES;
2379 
2380 	/* Copy IV at the end of the crypto operation */
2381 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2382 			iv, CIPHER_IV_LENGTH_AES_CBC);
2383 
2384 	sym_op->cipher.data.offset = 0;
2385 	sym_op->cipher.data.length = QUOTE_512_BYTES;
2386 
2387 	/* Process crypto operation */
2388 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2389 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2390 			ut_params->op);
2391 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
2392 		ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 0);
2393 		if (ret != TEST_SUCCESS)
2394 			return ret;
2395 	} else
2396 		TEST_ASSERT_NOT_NULL(
2397 				process_crypto_request(ts_params->valid_devs[0],
2398 					ut_params->op),
2399 					"failed to process sym crypto op");
2400 
2401 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2402 			"crypto op processing failed");
2403 
2404 	ut_params->obuf = ut_params->op->sym->m_src;
2405 
2406 	/* Validate obuf */
2407 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
2408 			rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
2409 			catch_22_quote,
2410 			QUOTE_512_BYTES,
2411 			"Plaintext data not as expected");
2412 
2413 	/* Validate obuf */
2414 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2415 			"Digest verification failed");
2416 
2417 	return TEST_SUCCESS;
2418 }
2419 
2420 /* ***** SNOW 3G Tests ***** */
2421 static int
2422 create_wireless_algo_hash_session(uint8_t dev_id,
2423 	const uint8_t *key, const uint8_t key_len,
2424 	const uint8_t iv_len, const uint8_t auth_len,
2425 	enum rte_crypto_auth_operation op,
2426 	enum rte_crypto_auth_algorithm algo)
2427 {
2428 	uint8_t hash_key[key_len];
2429 
2430 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2431 	struct crypto_unittest_params *ut_params = &unittest_params;
2432 
2433 	memcpy(hash_key, key, key_len);
2434 
2435 	debug_hexdump(stdout, "key:", key, key_len);
2436 
2437 	/* Setup Authentication Parameters */
2438 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2439 	ut_params->auth_xform.next = NULL;
2440 
2441 	ut_params->auth_xform.auth.op = op;
2442 	ut_params->auth_xform.auth.algo = algo;
2443 	ut_params->auth_xform.auth.key.length = key_len;
2444 	ut_params->auth_xform.auth.key.data = hash_key;
2445 	ut_params->auth_xform.auth.digest_length = auth_len;
2446 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2447 	ut_params->auth_xform.auth.iv.length = iv_len;
2448 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2449 			&ut_params->auth_xform, ts_params->session_mpool);
2450 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
2451 		return TEST_SKIPPED;
2452 
2453 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2454 	return 0;
2455 }
2456 
2457 static int
2458 create_wireless_algo_cipher_session(uint8_t dev_id,
2459 			enum rte_crypto_cipher_operation op,
2460 			enum rte_crypto_cipher_algorithm algo,
2461 			const uint8_t *key, const uint8_t key_len,
2462 			uint8_t iv_len)
2463 {
2464 	uint8_t cipher_key[key_len];
2465 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2466 	struct crypto_unittest_params *ut_params = &unittest_params;
2467 
2468 	memcpy(cipher_key, key, key_len);
2469 
2470 	/* Setup Cipher Parameters */
2471 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2472 	ut_params->cipher_xform.next = NULL;
2473 
2474 	ut_params->cipher_xform.cipher.algo = algo;
2475 	ut_params->cipher_xform.cipher.op = op;
2476 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2477 	ut_params->cipher_xform.cipher.key.length = key_len;
2478 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2479 	ut_params->cipher_xform.cipher.iv.length = iv_len;
2480 
2481 	debug_hexdump(stdout, "key:", key, key_len);
2482 
2483 	/* Create Crypto session */
2484 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2485 			&ut_params->cipher_xform, ts_params->session_mpool);
2486 
2487 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
2488 		return TEST_SKIPPED;
2489 
2490 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2491 	return 0;
2492 }
2493 
2494 static int
2495 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2496 			unsigned int cipher_len,
2497 			unsigned int cipher_offset)
2498 {
2499 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2500 	struct crypto_unittest_params *ut_params = &unittest_params;
2501 
2502 	/* Generate Crypto op data structure */
2503 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2504 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2505 	TEST_ASSERT_NOT_NULL(ut_params->op,
2506 				"Failed to allocate pktmbuf offload");
2507 
2508 	/* Set crypto operation data parameters */
2509 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2510 
2511 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2512 
2513 	/* set crypto operation source mbuf */
2514 	sym_op->m_src = ut_params->ibuf;
2515 
2516 	/* iv */
2517 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2518 			iv, iv_len);
2519 	sym_op->cipher.data.length = cipher_len;
2520 	sym_op->cipher.data.offset = cipher_offset;
2521 	return 0;
2522 }
2523 
2524 static int
2525 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2526 			unsigned int cipher_len,
2527 			unsigned int cipher_offset)
2528 {
2529 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2530 	struct crypto_unittest_params *ut_params = &unittest_params;
2531 
2532 	/* Generate Crypto op data structure */
2533 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2534 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2535 	TEST_ASSERT_NOT_NULL(ut_params->op,
2536 				"Failed to allocate pktmbuf offload");
2537 
2538 	/* Set crypto operation data parameters */
2539 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2540 
2541 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2542 
2543 	/* set crypto operation source mbuf */
2544 	sym_op->m_src = ut_params->ibuf;
2545 	sym_op->m_dst = ut_params->obuf;
2546 
2547 	/* iv */
2548 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2549 			iv, iv_len);
2550 	sym_op->cipher.data.length = cipher_len;
2551 	sym_op->cipher.data.offset = cipher_offset;
2552 	return 0;
2553 }
2554 
2555 static int
2556 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2557 		enum rte_crypto_cipher_operation cipher_op,
2558 		enum rte_crypto_auth_operation auth_op,
2559 		enum rte_crypto_auth_algorithm auth_algo,
2560 		enum rte_crypto_cipher_algorithm cipher_algo,
2561 		const uint8_t *a_key, uint8_t a_key_len,
2562 		const uint8_t *c_key, uint8_t c_key_len,
2563 		uint8_t auth_iv_len, uint8_t auth_len,
2564 		uint8_t cipher_iv_len)
2565 
2566 {
2567 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2568 	struct crypto_unittest_params *ut_params = &unittest_params;
2569 
2570 	/* Setup Authentication Parameters */
2571 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2572 	ut_params->auth_xform.next = NULL;
2573 
2574 	ut_params->auth_xform.auth.op = auth_op;
2575 	ut_params->auth_xform.auth.algo = auth_algo;
2576 	ut_params->auth_xform.auth.key.length = a_key_len;
2577 	ut_params->auth_xform.auth.key.data = a_key;
2578 	ut_params->auth_xform.auth.digest_length = auth_len;
2579 	/* Auth IV will be after cipher IV */
2580 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2581 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2582 
2583 	/* Setup Cipher Parameters */
2584 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2585 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2586 
2587 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2588 	ut_params->cipher_xform.cipher.op = cipher_op;
2589 	ut_params->cipher_xform.cipher.key.data = c_key;
2590 	ut_params->cipher_xform.cipher.key.length = c_key_len;
2591 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2592 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2593 
2594 	debug_hexdump(stdout, "Auth key:", a_key, c_key_len);
2595 	debug_hexdump(stdout, "Cipher key:", c_key, c_key_len);
2596 
2597 	/* Create Crypto session*/
2598 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2599 			&ut_params->cipher_xform, ts_params->session_mpool);
2600 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
2601 		return TEST_SKIPPED;
2602 
2603 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2604 	return 0;
2605 }
2606 
2607 static int
2608 create_wireless_cipher_auth_session(uint8_t dev_id,
2609 		enum rte_crypto_cipher_operation cipher_op,
2610 		enum rte_crypto_auth_operation auth_op,
2611 		enum rte_crypto_auth_algorithm auth_algo,
2612 		enum rte_crypto_cipher_algorithm cipher_algo,
2613 		const struct wireless_test_data *tdata)
2614 {
2615 	const uint8_t key_len = tdata->key.len;
2616 	uint8_t cipher_auth_key[key_len];
2617 
2618 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2619 	struct crypto_unittest_params *ut_params = &unittest_params;
2620 	const uint8_t *key = tdata->key.data;
2621 	const uint8_t auth_len = tdata->digest.len;
2622 	uint8_t cipher_iv_len = tdata->cipher_iv.len;
2623 	uint8_t auth_iv_len = tdata->auth_iv.len;
2624 
2625 	memcpy(cipher_auth_key, key, key_len);
2626 
2627 	/* Setup Authentication Parameters */
2628 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2629 	ut_params->auth_xform.next = NULL;
2630 
2631 	ut_params->auth_xform.auth.op = auth_op;
2632 	ut_params->auth_xform.auth.algo = auth_algo;
2633 	ut_params->auth_xform.auth.key.length = key_len;
2634 	/* Hash key = cipher key */
2635 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2636 	ut_params->auth_xform.auth.digest_length = auth_len;
2637 	/* Auth IV will be after cipher IV */
2638 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2639 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2640 
2641 	/* Setup Cipher Parameters */
2642 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2643 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2644 
2645 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2646 	ut_params->cipher_xform.cipher.op = cipher_op;
2647 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2648 	ut_params->cipher_xform.cipher.key.length = key_len;
2649 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2650 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2651 
2652 
2653 	debug_hexdump(stdout, "key:", key, key_len);
2654 
2655 	/* Create Crypto session*/
2656 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2657 			&ut_params->cipher_xform, ts_params->session_mpool);
2658 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
2659 		return TEST_SKIPPED;
2660 
2661 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2662 	return 0;
2663 }
2664 
2665 static int
2666 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2667 		const struct wireless_test_data *tdata)
2668 {
2669 	return create_wireless_cipher_auth_session(dev_id,
2670 		RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2671 		RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2672 		RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2673 }
2674 
2675 static int
2676 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2677 		enum rte_crypto_cipher_operation cipher_op,
2678 		enum rte_crypto_auth_operation auth_op,
2679 		enum rte_crypto_auth_algorithm auth_algo,
2680 		enum rte_crypto_cipher_algorithm cipher_algo,
2681 		const uint8_t *a_key, const uint8_t a_key_len,
2682 		const uint8_t *c_key, const uint8_t c_key_len,
2683 		uint8_t auth_iv_len, uint8_t auth_len,
2684 		uint8_t cipher_iv_len)
2685 {
2686 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2687 	struct crypto_unittest_params *ut_params = &unittest_params;
2688 
2689 	/* Setup Authentication Parameters */
2690 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2691 	ut_params->auth_xform.auth.op = auth_op;
2692 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2693 	ut_params->auth_xform.auth.algo = auth_algo;
2694 	ut_params->auth_xform.auth.key.length = a_key_len;
2695 	ut_params->auth_xform.auth.key.data = a_key;
2696 	ut_params->auth_xform.auth.digest_length = auth_len;
2697 	/* Auth IV will be after cipher IV */
2698 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2699 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2700 
2701 	/* Setup Cipher Parameters */
2702 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2703 	ut_params->cipher_xform.next = NULL;
2704 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2705 	ut_params->cipher_xform.cipher.op = cipher_op;
2706 	ut_params->cipher_xform.cipher.key.data = c_key;
2707 	ut_params->cipher_xform.cipher.key.length = c_key_len;
2708 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2709 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2710 
2711 	debug_hexdump(stdout, "Auth key:", a_key, a_key_len);
2712 	debug_hexdump(stdout, "Cipher key:", c_key, c_key_len);
2713 
2714 	/* Create Crypto session*/
2715 	if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2716 		ut_params->auth_xform.next = NULL;
2717 		ut_params->cipher_xform.next = &ut_params->auth_xform;
2718 		ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2719 			&ut_params->cipher_xform, ts_params->session_mpool);
2720 	} else
2721 		ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2722 			&ut_params->auth_xform, ts_params->session_mpool);
2723 
2724 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
2725 		return TEST_SKIPPED;
2726 
2727 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2728 
2729 	return 0;
2730 }
2731 
2732 static int
2733 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2734 		unsigned int auth_tag_len,
2735 		const uint8_t *iv, unsigned int iv_len,
2736 		unsigned int data_pad_len,
2737 		enum rte_crypto_auth_operation op,
2738 		unsigned int auth_len, unsigned int auth_offset)
2739 {
2740 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2741 
2742 	struct crypto_unittest_params *ut_params = &unittest_params;
2743 
2744 	/* Generate Crypto op data structure */
2745 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2746 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2747 	TEST_ASSERT_NOT_NULL(ut_params->op,
2748 		"Failed to allocate pktmbuf offload");
2749 
2750 	/* Set crypto operation data parameters */
2751 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2752 
2753 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2754 
2755 	/* set crypto operation source mbuf */
2756 	sym_op->m_src = ut_params->ibuf;
2757 
2758 	/* iv */
2759 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2760 			iv, iv_len);
2761 	/* digest */
2762 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2763 					ut_params->ibuf, auth_tag_len);
2764 
2765 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2766 				"no room to append auth tag");
2767 	ut_params->digest = sym_op->auth.digest.data;
2768 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2769 			ut_params->ibuf, data_pad_len);
2770 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2771 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2772 	else
2773 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2774 
2775 	debug_hexdump(stdout, "digest:",
2776 		sym_op->auth.digest.data,
2777 		auth_tag_len);
2778 
2779 	sym_op->auth.data.length = auth_len;
2780 	sym_op->auth.data.offset = auth_offset;
2781 
2782 	return 0;
2783 }
2784 
2785 static int
2786 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2787 	enum rte_crypto_auth_operation op)
2788 {
2789 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2790 	struct crypto_unittest_params *ut_params = &unittest_params;
2791 
2792 	const uint8_t *auth_tag = tdata->digest.data;
2793 	const unsigned int auth_tag_len = tdata->digest.len;
2794 	unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2795 	unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2796 
2797 	const uint8_t *cipher_iv = tdata->cipher_iv.data;
2798 	const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2799 	const uint8_t *auth_iv = tdata->auth_iv.data;
2800 	const uint8_t auth_iv_len = tdata->auth_iv.len;
2801 	const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2802 	const unsigned int auth_len = tdata->validAuthLenInBits.len;
2803 
2804 	/* Generate Crypto op data structure */
2805 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2806 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2807 	TEST_ASSERT_NOT_NULL(ut_params->op,
2808 			"Failed to allocate pktmbuf offload");
2809 	/* Set crypto operation data parameters */
2810 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2811 
2812 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2813 
2814 	/* set crypto operation source mbuf */
2815 	sym_op->m_src = ut_params->ibuf;
2816 
2817 	/* digest */
2818 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2819 			ut_params->ibuf, auth_tag_len);
2820 
2821 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2822 			"no room to append auth tag");
2823 	ut_params->digest = sym_op->auth.digest.data;
2824 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2825 			ut_params->ibuf, data_pad_len);
2826 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2827 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2828 	else
2829 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2830 
2831 	debug_hexdump(stdout, "digest:",
2832 		sym_op->auth.digest.data,
2833 		auth_tag_len);
2834 
2835 	/* Copy cipher and auth IVs at the end of the crypto operation */
2836 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2837 						IV_OFFSET);
2838 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2839 	iv_ptr += cipher_iv_len;
2840 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2841 
2842 	sym_op->cipher.data.length = cipher_len;
2843 	sym_op->cipher.data.offset = 0;
2844 	sym_op->auth.data.length = auth_len;
2845 	sym_op->auth.data.offset = 0;
2846 
2847 	return 0;
2848 }
2849 
2850 static int
2851 create_zuc_cipher_hash_generate_operation(
2852 		const struct wireless_test_data *tdata)
2853 {
2854 	return create_wireless_cipher_hash_operation(tdata,
2855 		RTE_CRYPTO_AUTH_OP_GENERATE);
2856 }
2857 
2858 static int
2859 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2860 		const unsigned auth_tag_len,
2861 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2862 		unsigned data_pad_len,
2863 		enum rte_crypto_auth_operation op,
2864 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2865 		const unsigned cipher_len, const unsigned cipher_offset,
2866 		const unsigned auth_len, const unsigned auth_offset)
2867 {
2868 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2869 	struct crypto_unittest_params *ut_params = &unittest_params;
2870 
2871 	enum rte_crypto_cipher_algorithm cipher_algo =
2872 			ut_params->cipher_xform.cipher.algo;
2873 	enum rte_crypto_auth_algorithm auth_algo =
2874 			ut_params->auth_xform.auth.algo;
2875 
2876 	/* Generate Crypto op data structure */
2877 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2878 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2879 	TEST_ASSERT_NOT_NULL(ut_params->op,
2880 			"Failed to allocate pktmbuf offload");
2881 	/* Set crypto operation data parameters */
2882 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2883 
2884 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2885 
2886 	/* set crypto operation source mbuf */
2887 	sym_op->m_src = ut_params->ibuf;
2888 
2889 	/* digest */
2890 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2891 			ut_params->ibuf, auth_tag_len);
2892 
2893 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2894 			"no room to append auth tag");
2895 	ut_params->digest = sym_op->auth.digest.data;
2896 
2897 	if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2898 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2899 				ut_params->ibuf, data_pad_len);
2900 	} else {
2901 		struct rte_mbuf *m = ut_params->ibuf;
2902 		unsigned int offset = data_pad_len;
2903 
2904 		while (offset > m->data_len && m->next != NULL) {
2905 			offset -= m->data_len;
2906 			m = m->next;
2907 		}
2908 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2909 			m, offset);
2910 	}
2911 
2912 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2913 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2914 	else
2915 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2916 
2917 	debug_hexdump(stdout, "digest:",
2918 		sym_op->auth.digest.data,
2919 		auth_tag_len);
2920 
2921 	/* Copy cipher and auth IVs at the end of the crypto operation */
2922 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2923 						IV_OFFSET);
2924 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2925 	iv_ptr += cipher_iv_len;
2926 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2927 
2928 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2929 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2930 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2931 		sym_op->cipher.data.length = cipher_len;
2932 		sym_op->cipher.data.offset = cipher_offset;
2933 	} else {
2934 		sym_op->cipher.data.length = cipher_len >> 3;
2935 		sym_op->cipher.data.offset = cipher_offset >> 3;
2936 	}
2937 
2938 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2939 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2940 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2941 		sym_op->auth.data.length = auth_len;
2942 		sym_op->auth.data.offset = auth_offset;
2943 	} else {
2944 		sym_op->auth.data.length = auth_len >> 3;
2945 		sym_op->auth.data.offset = auth_offset >> 3;
2946 	}
2947 
2948 	return 0;
2949 }
2950 
2951 static int
2952 create_wireless_algo_auth_cipher_operation(
2953 		const uint8_t *auth_tag, unsigned int auth_tag_len,
2954 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2955 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2956 		unsigned int data_pad_len,
2957 		unsigned int cipher_len, unsigned int cipher_offset,
2958 		unsigned int auth_len, unsigned int auth_offset,
2959 		uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2960 {
2961 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2962 	struct crypto_unittest_params *ut_params = &unittest_params;
2963 
2964 	enum rte_crypto_cipher_algorithm cipher_algo =
2965 			ut_params->cipher_xform.cipher.algo;
2966 	enum rte_crypto_auth_algorithm auth_algo =
2967 			ut_params->auth_xform.auth.algo;
2968 
2969 	/* Generate Crypto op data structure */
2970 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2971 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2972 	TEST_ASSERT_NOT_NULL(ut_params->op,
2973 			"Failed to allocate pktmbuf offload");
2974 
2975 	/* Set crypto operation data parameters */
2976 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2977 
2978 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2979 
2980 	/* set crypto operation mbufs */
2981 	sym_op->m_src = ut_params->ibuf;
2982 	if (op_mode == OUT_OF_PLACE)
2983 		sym_op->m_dst = ut_params->obuf;
2984 
2985 	/* digest */
2986 	if (!do_sgl) {
2987 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
2988 			(op_mode == IN_PLACE ?
2989 				ut_params->ibuf : ut_params->obuf),
2990 			uint8_t *, data_pad_len);
2991 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2992 			(op_mode == IN_PLACE ?
2993 				ut_params->ibuf : ut_params->obuf),
2994 			data_pad_len);
2995 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2996 	} else {
2997 		uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
2998 		struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
2999 				sym_op->m_src : sym_op->m_dst);
3000 		while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
3001 			remaining_off -= rte_pktmbuf_data_len(sgl_buf);
3002 			sgl_buf = sgl_buf->next;
3003 		}
3004 
3005 		/* The last segment should be large enough to hold full digest */
3006 		if (sgl_buf->data_len < auth_tag_len) {
3007 			rte_pktmbuf_free(sgl_buf->next);
3008 			sgl_buf->next = NULL;
3009 			TEST_ASSERT_NOT_NULL(rte_pktmbuf_append(sgl_buf,
3010 					auth_tag_len - sgl_buf->data_len),
3011 					"No room to append auth tag");
3012 		}
3013 
3014 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
3015 				uint8_t *, remaining_off);
3016 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
3017 				remaining_off);
3018 		memset(sym_op->auth.digest.data, 0, remaining_off);
3019 		while (sgl_buf->next != NULL) {
3020 			memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
3021 				0, rte_pktmbuf_data_len(sgl_buf));
3022 			sgl_buf = sgl_buf->next;
3023 		}
3024 	}
3025 
3026 	/* Copy digest for the verification */
3027 	if (verify)
3028 		memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3029 
3030 	/* Copy cipher and auth IVs at the end of the crypto operation */
3031 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
3032 			ut_params->op, uint8_t *, IV_OFFSET);
3033 
3034 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
3035 	iv_ptr += cipher_iv_len;
3036 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
3037 
3038 	/* Only copy over the offset data needed from src to dst in OOP,
3039 	 * if the auth and cipher offsets are not aligned
3040 	 */
3041 	if (op_mode == OUT_OF_PLACE) {
3042 		if (cipher_offset > auth_offset)
3043 			rte_memcpy(
3044 				rte_pktmbuf_mtod_offset(
3045 					sym_op->m_dst,
3046 					uint8_t *, auth_offset >> 3),
3047 				rte_pktmbuf_mtod_offset(
3048 					sym_op->m_src,
3049 					uint8_t *, auth_offset >> 3),
3050 				((cipher_offset >> 3) - (auth_offset >> 3)));
3051 	}
3052 
3053 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
3054 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
3055 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
3056 		sym_op->cipher.data.length = cipher_len;
3057 		sym_op->cipher.data.offset = cipher_offset;
3058 	} else {
3059 		sym_op->cipher.data.length = cipher_len >> 3;
3060 		sym_op->cipher.data.offset = cipher_offset >> 3;
3061 	}
3062 
3063 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
3064 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
3065 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
3066 		sym_op->auth.data.length = auth_len;
3067 		sym_op->auth.data.offset = auth_offset;
3068 	} else {
3069 		sym_op->auth.data.length = auth_len >> 3;
3070 		sym_op->auth.data.offset = auth_offset >> 3;
3071 	}
3072 
3073 	return 0;
3074 }
3075 
3076 static int
3077 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
3078 {
3079 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3080 	struct crypto_unittest_params *ut_params = &unittest_params;
3081 
3082 	int retval;
3083 	unsigned plaintext_pad_len;
3084 	unsigned plaintext_len;
3085 	uint8_t *plaintext;
3086 	struct rte_cryptodev_info dev_info;
3087 
3088 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3089 	uint64_t feat_flags = dev_info.feature_flags;
3090 
3091 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3092 			((tdata->validAuthLenInBits.len % 8) != 0)) {
3093 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3094 		return TEST_SKIPPED;
3095 	}
3096 
3097 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3098 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3099 		printf("Device doesn't support RAW data-path APIs.\n");
3100 		return TEST_SKIPPED;
3101 	}
3102 
3103 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3104 		return TEST_SKIPPED;
3105 
3106 	/* Verify the capabilities */
3107 	struct rte_cryptodev_sym_capability_idx cap_idx;
3108 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3109 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3110 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3111 			&cap_idx) == NULL)
3112 		return TEST_SKIPPED;
3113 
3114 	/* Create SNOW 3G session */
3115 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3116 			tdata->key.data, tdata->key.len,
3117 			tdata->auth_iv.len, tdata->digest.len,
3118 			RTE_CRYPTO_AUTH_OP_GENERATE,
3119 			RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3120 	if (retval < 0)
3121 		return retval;
3122 
3123 	/* alloc mbuf and set payload */
3124 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3125 
3126 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3127 	rte_pktmbuf_tailroom(ut_params->ibuf));
3128 
3129 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3130 	/* Append data which is padded to a multiple of */
3131 	/* the algorithms block size */
3132 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3133 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3134 				plaintext_pad_len);
3135 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3136 
3137 	/* Create SNOW 3G operation */
3138 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3139 			tdata->auth_iv.data, tdata->auth_iv.len,
3140 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3141 			tdata->validAuthLenInBits.len,
3142 			0);
3143 	if (retval < 0)
3144 		return retval;
3145 
3146 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
3147 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1,
3148 					       0);
3149 		if (retval != TEST_SUCCESS)
3150 			return retval;
3151 	} else
3152 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3153 				ut_params->op);
3154 	ut_params->obuf = ut_params->op->sym->m_src;
3155 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3156 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3157 			+ plaintext_pad_len;
3158 
3159 	/* Validate obuf */
3160 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3161 	ut_params->digest,
3162 	tdata->digest.data,
3163 	DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3164 	"SNOW 3G Generated auth tag not as expected");
3165 
3166 	return 0;
3167 }
3168 
3169 static int
3170 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
3171 {
3172 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3173 	struct crypto_unittest_params *ut_params = &unittest_params;
3174 
3175 	int retval;
3176 	unsigned plaintext_pad_len;
3177 	unsigned plaintext_len;
3178 	uint8_t *plaintext;
3179 	struct rte_cryptodev_info dev_info;
3180 
3181 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3182 	uint64_t feat_flags = dev_info.feature_flags;
3183 
3184 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3185 			((tdata->validAuthLenInBits.len % 8) != 0)) {
3186 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3187 		return TEST_SKIPPED;
3188 	}
3189 
3190 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3191 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3192 		printf("Device doesn't support RAW data-path APIs.\n");
3193 		return TEST_SKIPPED;
3194 	}
3195 
3196 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3197 		return TEST_SKIPPED;
3198 
3199 	/* Verify the capabilities */
3200 	struct rte_cryptodev_sym_capability_idx cap_idx;
3201 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3202 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3203 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3204 			&cap_idx) == NULL)
3205 		return TEST_SKIPPED;
3206 
3207 	/* Create SNOW 3G session */
3208 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3209 				tdata->key.data, tdata->key.len,
3210 				tdata->auth_iv.len, tdata->digest.len,
3211 				RTE_CRYPTO_AUTH_OP_VERIFY,
3212 				RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3213 	if (retval < 0)
3214 		return retval;
3215 	/* alloc mbuf and set payload */
3216 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3217 
3218 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3219 	rte_pktmbuf_tailroom(ut_params->ibuf));
3220 
3221 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3222 	/* Append data which is padded to a multiple of */
3223 	/* the algorithms block size */
3224 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3225 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3226 				plaintext_pad_len);
3227 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3228 
3229 	/* Create SNOW 3G operation */
3230 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
3231 			tdata->digest.len,
3232 			tdata->auth_iv.data, tdata->auth_iv.len,
3233 			plaintext_pad_len,
3234 			RTE_CRYPTO_AUTH_OP_VERIFY,
3235 			tdata->validAuthLenInBits.len,
3236 			0);
3237 	if (retval < 0)
3238 		return retval;
3239 
3240 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
3241 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1,
3242 					       0);
3243 		if (retval != TEST_SUCCESS)
3244 			return retval;
3245 	} else
3246 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3247 				ut_params->op);
3248 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3249 	ut_params->obuf = ut_params->op->sym->m_src;
3250 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3251 				+ plaintext_pad_len;
3252 
3253 	/* Validate obuf */
3254 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3255 		return 0;
3256 	else
3257 		return -1;
3258 
3259 	return 0;
3260 }
3261 
3262 static int
3263 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
3264 {
3265 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3266 	struct crypto_unittest_params *ut_params = &unittest_params;
3267 
3268 	int retval;
3269 	unsigned plaintext_pad_len;
3270 	unsigned plaintext_len;
3271 	uint8_t *plaintext;
3272 	struct rte_cryptodev_info dev_info;
3273 
3274 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3275 	uint64_t feat_flags = dev_info.feature_flags;
3276 
3277 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3278 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3279 		printf("Device doesn't support RAW data-path APIs.\n");
3280 		return TEST_SKIPPED;
3281 	}
3282 
3283 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3284 		return TEST_SKIPPED;
3285 
3286 	/* Verify the capabilities */
3287 	struct rte_cryptodev_sym_capability_idx cap_idx;
3288 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3289 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3290 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3291 			&cap_idx) == NULL)
3292 		return TEST_SKIPPED;
3293 
3294 	/* Create KASUMI session */
3295 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3296 			tdata->key.data, tdata->key.len,
3297 			0, tdata->digest.len,
3298 			RTE_CRYPTO_AUTH_OP_GENERATE,
3299 			RTE_CRYPTO_AUTH_KASUMI_F9);
3300 	if (retval < 0)
3301 		return retval;
3302 
3303 	/* alloc mbuf and set payload */
3304 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3305 
3306 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3307 	rte_pktmbuf_tailroom(ut_params->ibuf));
3308 
3309 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3310 	/* Append data which is padded to a multiple of */
3311 	/* the algorithms block size */
3312 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3313 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3314 				plaintext_pad_len);
3315 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3316 
3317 	/* Create KASUMI operation */
3318 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3319 			NULL, 0,
3320 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3321 			tdata->plaintext.len,
3322 			0);
3323 	if (retval < 0)
3324 		return retval;
3325 
3326 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3327 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
3328 			ut_params->op);
3329 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
3330 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1,
3331 					       0);
3332 		if (retval != TEST_SUCCESS)
3333 			return retval;
3334 	} else
3335 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3336 			ut_params->op);
3337 
3338 	ut_params->obuf = ut_params->op->sym->m_src;
3339 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3340 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3341 			+ plaintext_pad_len;
3342 
3343 	/* Validate obuf */
3344 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3345 	ut_params->digest,
3346 	tdata->digest.data,
3347 	DIGEST_BYTE_LENGTH_KASUMI_F9,
3348 	"KASUMI Generated auth tag not as expected");
3349 
3350 	return 0;
3351 }
3352 
3353 static int
3354 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
3355 {
3356 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3357 	struct crypto_unittest_params *ut_params = &unittest_params;
3358 
3359 	int retval;
3360 	unsigned plaintext_pad_len;
3361 	unsigned plaintext_len;
3362 	uint8_t *plaintext;
3363 	struct rte_cryptodev_info dev_info;
3364 
3365 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3366 	uint64_t feat_flags = dev_info.feature_flags;
3367 
3368 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3369 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3370 		printf("Device doesn't support RAW data-path APIs.\n");
3371 		return TEST_SKIPPED;
3372 	}
3373 
3374 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3375 		return TEST_SKIPPED;
3376 
3377 	/* Verify the capabilities */
3378 	struct rte_cryptodev_sym_capability_idx cap_idx;
3379 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3380 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3381 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3382 			&cap_idx) == NULL)
3383 		return TEST_SKIPPED;
3384 
3385 	/* Create KASUMI session */
3386 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3387 				tdata->key.data, tdata->key.len,
3388 				0, tdata->digest.len,
3389 				RTE_CRYPTO_AUTH_OP_VERIFY,
3390 				RTE_CRYPTO_AUTH_KASUMI_F9);
3391 	if (retval < 0)
3392 		return retval;
3393 	/* alloc mbuf and set payload */
3394 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3395 
3396 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3397 	rte_pktmbuf_tailroom(ut_params->ibuf));
3398 
3399 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3400 	/* Append data which is padded to a multiple */
3401 	/* of the algorithms block size */
3402 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3403 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3404 				plaintext_pad_len);
3405 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3406 
3407 	/* Create KASUMI operation */
3408 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
3409 			tdata->digest.len,
3410 			NULL, 0,
3411 			plaintext_pad_len,
3412 			RTE_CRYPTO_AUTH_OP_VERIFY,
3413 			tdata->plaintext.len,
3414 			0);
3415 	if (retval < 0)
3416 		return retval;
3417 
3418 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
3419 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1,
3420 					       0);
3421 		if (retval != TEST_SUCCESS)
3422 			return retval;
3423 	} else
3424 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3425 				ut_params->op);
3426 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3427 	ut_params->obuf = ut_params->op->sym->m_src;
3428 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3429 				+ plaintext_pad_len;
3430 
3431 	/* Validate obuf */
3432 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3433 		return 0;
3434 	else
3435 		return -1;
3436 
3437 	return 0;
3438 }
3439 
3440 static int
3441 test_snow3g_hash_generate_test_case_1(void)
3442 {
3443 	return test_snow3g_authentication(&snow3g_hash_test_case_1);
3444 }
3445 
3446 static int
3447 test_snow3g_hash_generate_test_case_2(void)
3448 {
3449 	return test_snow3g_authentication(&snow3g_hash_test_case_2);
3450 }
3451 
3452 static int
3453 test_snow3g_hash_generate_test_case_3(void)
3454 {
3455 	return test_snow3g_authentication(&snow3g_hash_test_case_3);
3456 }
3457 
3458 static int
3459 test_snow3g_hash_generate_test_case_4(void)
3460 {
3461 	return test_snow3g_authentication(&snow3g_hash_test_case_4);
3462 }
3463 
3464 static int
3465 test_snow3g_hash_generate_test_case_5(void)
3466 {
3467 	return test_snow3g_authentication(&snow3g_hash_test_case_5);
3468 }
3469 
3470 static int
3471 test_snow3g_hash_generate_test_case_6(void)
3472 {
3473 	return test_snow3g_authentication(&snow3g_hash_test_case_6);
3474 }
3475 
3476 static int
3477 test_snow3g_hash_verify_test_case_1(void)
3478 {
3479 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3480 
3481 }
3482 
3483 static int
3484 test_snow3g_hash_verify_test_case_2(void)
3485 {
3486 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3487 }
3488 
3489 static int
3490 test_snow3g_hash_verify_test_case_3(void)
3491 {
3492 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3493 }
3494 
3495 static int
3496 test_snow3g_hash_verify_test_case_4(void)
3497 {
3498 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3499 }
3500 
3501 static int
3502 test_snow3g_hash_verify_test_case_5(void)
3503 {
3504 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3505 }
3506 
3507 static int
3508 test_snow3g_hash_verify_test_case_6(void)
3509 {
3510 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3511 }
3512 
3513 static int
3514 test_kasumi_hash_generate_test_case_1(void)
3515 {
3516 	return test_kasumi_authentication(&kasumi_hash_test_case_1);
3517 }
3518 
3519 static int
3520 test_kasumi_hash_generate_test_case_2(void)
3521 {
3522 	return test_kasumi_authentication(&kasumi_hash_test_case_2);
3523 }
3524 
3525 static int
3526 test_kasumi_hash_generate_test_case_3(void)
3527 {
3528 	return test_kasumi_authentication(&kasumi_hash_test_case_3);
3529 }
3530 
3531 static int
3532 test_kasumi_hash_generate_test_case_4(void)
3533 {
3534 	return test_kasumi_authentication(&kasumi_hash_test_case_4);
3535 }
3536 
3537 static int
3538 test_kasumi_hash_generate_test_case_5(void)
3539 {
3540 	return test_kasumi_authentication(&kasumi_hash_test_case_5);
3541 }
3542 
3543 static int
3544 test_kasumi_hash_generate_test_case_6(void)
3545 {
3546 	return test_kasumi_authentication(&kasumi_hash_test_case_6);
3547 }
3548 
3549 static int
3550 test_kasumi_hash_verify_test_case_1(void)
3551 {
3552 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3553 }
3554 
3555 static int
3556 test_kasumi_hash_verify_test_case_2(void)
3557 {
3558 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3559 }
3560 
3561 static int
3562 test_kasumi_hash_verify_test_case_3(void)
3563 {
3564 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3565 }
3566 
3567 static int
3568 test_kasumi_hash_verify_test_case_4(void)
3569 {
3570 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3571 }
3572 
3573 static int
3574 test_kasumi_hash_verify_test_case_5(void)
3575 {
3576 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3577 }
3578 
3579 static int
3580 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3581 {
3582 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3583 	struct crypto_unittest_params *ut_params = &unittest_params;
3584 
3585 	int retval;
3586 	uint8_t *plaintext, *ciphertext;
3587 	unsigned plaintext_pad_len;
3588 	unsigned plaintext_len;
3589 	struct rte_cryptodev_info dev_info;
3590 
3591 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3592 	uint64_t feat_flags = dev_info.feature_flags;
3593 
3594 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3595 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3596 		printf("Device doesn't support RAW data-path APIs.\n");
3597 		return TEST_SKIPPED;
3598 	}
3599 
3600 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3601 		return TEST_SKIPPED;
3602 
3603 	/* Verify the capabilities */
3604 	struct rte_cryptodev_sym_capability_idx cap_idx;
3605 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3606 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3607 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3608 			&cap_idx) == NULL)
3609 		return TEST_SKIPPED;
3610 
3611 	/* Create KASUMI session */
3612 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3613 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3614 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3615 					tdata->key.data, tdata->key.len,
3616 					tdata->cipher_iv.len);
3617 	if (retval < 0)
3618 		return retval;
3619 
3620 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3621 
3622 	/* Clear mbuf payload */
3623 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3624 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3625 
3626 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3627 	/* Append data which is padded to a multiple */
3628 	/* of the algorithms block size */
3629 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3630 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3631 				plaintext_pad_len);
3632 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3633 
3634 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3635 
3636 	/* Create KASUMI operation */
3637 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3638 				tdata->cipher_iv.len,
3639 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3640 				tdata->validCipherOffsetInBits.len);
3641 	if (retval < 0)
3642 		return retval;
3643 
3644 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
3645 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
3646 					       tdata->cipher_iv.len);
3647 		if (retval != TEST_SUCCESS)
3648 			return retval;
3649 	} else
3650 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3651 				ut_params->op);
3652 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3653 
3654 	ut_params->obuf = ut_params->op->sym->m_dst;
3655 	if (ut_params->obuf)
3656 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3657 	else
3658 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3659 
3660 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3661 
3662 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3663 				(tdata->validCipherOffsetInBits.len >> 3);
3664 	/* Validate obuf */
3665 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3666 		ciphertext,
3667 		reference_ciphertext,
3668 		tdata->validCipherLenInBits.len,
3669 		"KASUMI Ciphertext data not as expected");
3670 	return 0;
3671 }
3672 
3673 static int
3674 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3675 {
3676 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3677 	struct crypto_unittest_params *ut_params = &unittest_params;
3678 
3679 	int retval;
3680 
3681 	unsigned int plaintext_pad_len;
3682 	unsigned int plaintext_len;
3683 
3684 	uint8_t buffer[10000];
3685 	const uint8_t *ciphertext;
3686 
3687 	struct rte_cryptodev_info dev_info;
3688 
3689 	/* Verify the capabilities */
3690 	struct rte_cryptodev_sym_capability_idx cap_idx;
3691 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3692 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3693 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3694 			&cap_idx) == NULL)
3695 		return TEST_SKIPPED;
3696 
3697 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3698 
3699 	uint64_t feat_flags = dev_info.feature_flags;
3700 
3701 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3702 		printf("Device doesn't support in-place scatter-gather. "
3703 				"Test Skipped.\n");
3704 		return TEST_SKIPPED;
3705 	}
3706 
3707 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3708 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3709 		printf("Device doesn't support RAW data-path APIs.\n");
3710 		return TEST_SKIPPED;
3711 	}
3712 
3713 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3714 		return TEST_SKIPPED;
3715 
3716 	/* Create KASUMI session */
3717 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3718 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3719 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3720 					tdata->key.data, tdata->key.len,
3721 					tdata->cipher_iv.len);
3722 	if (retval < 0)
3723 		return retval;
3724 
3725 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3726 
3727 
3728 	/* Append data which is padded to a multiple */
3729 	/* of the algorithms block size */
3730 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3731 
3732 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3733 			plaintext_pad_len, 10, 0);
3734 
3735 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3736 
3737 	/* Create KASUMI operation */
3738 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3739 				tdata->cipher_iv.len,
3740 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3741 				tdata->validCipherOffsetInBits.len);
3742 	if (retval < 0)
3743 		return retval;
3744 
3745 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
3746 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
3747 					       tdata->cipher_iv.len);
3748 		if (retval != TEST_SUCCESS)
3749 			return retval;
3750 	} else
3751 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3752 						ut_params->op);
3753 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3754 
3755 	ut_params->obuf = ut_params->op->sym->m_dst;
3756 
3757 	if (ut_params->obuf)
3758 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3759 				plaintext_len, buffer);
3760 	else
3761 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3762 				tdata->validCipherOffsetInBits.len >> 3,
3763 				plaintext_len, buffer);
3764 
3765 	/* Validate obuf */
3766 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3767 
3768 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3769 				(tdata->validCipherOffsetInBits.len >> 3);
3770 	/* Validate obuf */
3771 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3772 		ciphertext,
3773 		reference_ciphertext,
3774 		tdata->validCipherLenInBits.len,
3775 		"KASUMI Ciphertext data not as expected");
3776 	return 0;
3777 }
3778 
3779 static int
3780 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3781 {
3782 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3783 	struct crypto_unittest_params *ut_params = &unittest_params;
3784 
3785 	int retval;
3786 	uint8_t *plaintext, *ciphertext;
3787 	unsigned plaintext_pad_len;
3788 	unsigned plaintext_len;
3789 
3790 	/* Verify the capabilities */
3791 	struct rte_cryptodev_sym_capability_idx cap_idx;
3792 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3793 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3794 	/* Data-path service does not support OOP */
3795 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3796 			&cap_idx) == NULL)
3797 		return TEST_SKIPPED;
3798 
3799 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3800 		return TEST_SKIPPED;
3801 
3802 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3803 		return TEST_SKIPPED;
3804 
3805 	/* Create KASUMI session */
3806 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3807 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3808 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3809 					tdata->key.data, tdata->key.len,
3810 					tdata->cipher_iv.len);
3811 	if (retval < 0)
3812 		return retval;
3813 
3814 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3815 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3816 
3817 	/* Clear mbuf payload */
3818 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3819 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3820 
3821 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3822 	/* Append data which is padded to a multiple */
3823 	/* of the algorithms block size */
3824 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3825 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3826 				plaintext_pad_len);
3827 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3828 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3829 
3830 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3831 
3832 	/* Create KASUMI operation */
3833 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3834 				tdata->cipher_iv.len,
3835 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3836 				tdata->validCipherOffsetInBits.len);
3837 	if (retval < 0)
3838 		return retval;
3839 
3840 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3841 						ut_params->op);
3842 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3843 
3844 	ut_params->obuf = ut_params->op->sym->m_dst;
3845 	if (ut_params->obuf)
3846 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3847 	else
3848 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3849 
3850 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3851 
3852 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3853 				(tdata->validCipherOffsetInBits.len >> 3);
3854 	/* Validate obuf */
3855 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3856 		ciphertext,
3857 		reference_ciphertext,
3858 		tdata->validCipherLenInBits.len,
3859 		"KASUMI Ciphertext data not as expected");
3860 	return 0;
3861 }
3862 
3863 static int
3864 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3865 {
3866 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3867 	struct crypto_unittest_params *ut_params = &unittest_params;
3868 
3869 	int retval;
3870 	unsigned int plaintext_pad_len;
3871 	unsigned int plaintext_len;
3872 
3873 	const uint8_t *ciphertext;
3874 	uint8_t buffer[2048];
3875 
3876 	struct rte_cryptodev_info dev_info;
3877 
3878 	/* Verify the capabilities */
3879 	struct rte_cryptodev_sym_capability_idx cap_idx;
3880 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3881 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3882 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3883 			&cap_idx) == NULL)
3884 		return TEST_SKIPPED;
3885 
3886 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3887 		return TEST_SKIPPED;
3888 
3889 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3890 		return TEST_SKIPPED;
3891 
3892 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3893 
3894 	uint64_t feat_flags = dev_info.feature_flags;
3895 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3896 		printf("Device doesn't support out-of-place scatter-gather "
3897 				"in both input and output mbufs. "
3898 				"Test Skipped.\n");
3899 		return TEST_SKIPPED;
3900 	}
3901 
3902 	/* Create KASUMI session */
3903 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3904 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3905 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3906 					tdata->key.data, tdata->key.len,
3907 					tdata->cipher_iv.len);
3908 	if (retval < 0)
3909 		return retval;
3910 
3911 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3912 	/* Append data which is padded to a multiple */
3913 	/* of the algorithms block size */
3914 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3915 
3916 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3917 			plaintext_pad_len, 10, 0);
3918 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3919 			plaintext_pad_len, 3, 0);
3920 
3921 	/* Append data which is padded to a multiple */
3922 	/* of the algorithms block size */
3923 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3924 
3925 	/* Create KASUMI operation */
3926 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3927 				tdata->cipher_iv.len,
3928 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3929 				tdata->validCipherOffsetInBits.len);
3930 	if (retval < 0)
3931 		return retval;
3932 
3933 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3934 						ut_params->op);
3935 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3936 
3937 	ut_params->obuf = ut_params->op->sym->m_dst;
3938 	if (ut_params->obuf)
3939 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3940 				plaintext_pad_len, buffer);
3941 	else
3942 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3943 				tdata->validCipherOffsetInBits.len >> 3,
3944 				plaintext_pad_len, buffer);
3945 
3946 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3947 				(tdata->validCipherOffsetInBits.len >> 3);
3948 	/* Validate obuf */
3949 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3950 		ciphertext,
3951 		reference_ciphertext,
3952 		tdata->validCipherLenInBits.len,
3953 		"KASUMI Ciphertext data not as expected");
3954 	return 0;
3955 }
3956 
3957 
3958 static int
3959 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3960 {
3961 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3962 	struct crypto_unittest_params *ut_params = &unittest_params;
3963 
3964 	int retval;
3965 	uint8_t *ciphertext, *plaintext;
3966 	unsigned ciphertext_pad_len;
3967 	unsigned ciphertext_len;
3968 
3969 	/* Verify the capabilities */
3970 	struct rte_cryptodev_sym_capability_idx cap_idx;
3971 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3972 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3973 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3974 			&cap_idx) == NULL)
3975 		return TEST_SKIPPED;
3976 
3977 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3978 		return TEST_SKIPPED;
3979 
3980 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3981 		return TEST_SKIPPED;
3982 
3983 	/* Create KASUMI session */
3984 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3985 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
3986 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3987 					tdata->key.data, tdata->key.len,
3988 					tdata->cipher_iv.len);
3989 	if (retval < 0)
3990 		return retval;
3991 
3992 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3993 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3994 
3995 	/* Clear mbuf payload */
3996 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3997 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3998 
3999 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4000 	/* Append data which is padded to a multiple */
4001 	/* of the algorithms block size */
4002 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4003 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4004 				ciphertext_pad_len);
4005 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4006 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4007 
4008 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4009 
4010 	/* Create KASUMI operation */
4011 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4012 				tdata->cipher_iv.len,
4013 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
4014 				tdata->validCipherOffsetInBits.len);
4015 	if (retval < 0)
4016 		return retval;
4017 
4018 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4019 						ut_params->op);
4020 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4021 
4022 	ut_params->obuf = ut_params->op->sym->m_dst;
4023 	if (ut_params->obuf)
4024 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4025 	else
4026 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4027 
4028 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4029 
4030 	const uint8_t *reference_plaintext = tdata->plaintext.data +
4031 				(tdata->validCipherOffsetInBits.len >> 3);
4032 	/* Validate obuf */
4033 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4034 		plaintext,
4035 		reference_plaintext,
4036 		tdata->validCipherLenInBits.len,
4037 		"KASUMI Plaintext data not as expected");
4038 	return 0;
4039 }
4040 
4041 static int
4042 test_kasumi_decryption(const struct kasumi_test_data *tdata)
4043 {
4044 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4045 	struct crypto_unittest_params *ut_params = &unittest_params;
4046 
4047 	int retval;
4048 	uint8_t *ciphertext, *plaintext;
4049 	unsigned ciphertext_pad_len;
4050 	unsigned ciphertext_len;
4051 	struct rte_cryptodev_info dev_info;
4052 
4053 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4054 	uint64_t feat_flags = dev_info.feature_flags;
4055 
4056 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4057 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4058 		printf("Device doesn't support RAW data-path APIs.\n");
4059 		return TEST_SKIPPED;
4060 	}
4061 
4062 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4063 		return TEST_SKIPPED;
4064 
4065 	/* Verify the capabilities */
4066 	struct rte_cryptodev_sym_capability_idx cap_idx;
4067 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4068 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4069 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4070 			&cap_idx) == NULL)
4071 		return TEST_SKIPPED;
4072 
4073 	/* Create KASUMI session */
4074 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4075 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4076 					RTE_CRYPTO_CIPHER_KASUMI_F8,
4077 					tdata->key.data, tdata->key.len,
4078 					tdata->cipher_iv.len);
4079 	if (retval < 0)
4080 		return retval;
4081 
4082 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4083 
4084 	/* Clear mbuf payload */
4085 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4086 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4087 
4088 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4089 	/* Append data which is padded to a multiple */
4090 	/* of the algorithms block size */
4091 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4092 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4093 				ciphertext_pad_len);
4094 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4095 
4096 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4097 
4098 	/* Create KASUMI operation */
4099 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4100 			tdata->cipher_iv.len,
4101 			RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
4102 			tdata->validCipherOffsetInBits.len);
4103 	if (retval < 0)
4104 		return retval;
4105 
4106 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
4107 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
4108 					       0);
4109 		if (retval != TEST_SUCCESS)
4110 			return retval;
4111 	} else
4112 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4113 						ut_params->op);
4114 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4115 
4116 	ut_params->obuf = ut_params->op->sym->m_dst;
4117 	if (ut_params->obuf)
4118 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4119 	else
4120 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4121 
4122 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4123 
4124 	const uint8_t *reference_plaintext = tdata->plaintext.data +
4125 				(tdata->validCipherOffsetInBits.len >> 3);
4126 	/* Validate obuf */
4127 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4128 		plaintext,
4129 		reference_plaintext,
4130 		tdata->validCipherLenInBits.len,
4131 		"KASUMI Plaintext data not as expected");
4132 	return 0;
4133 }
4134 
4135 static int
4136 test_snow3g_encryption(const struct snow3g_test_data *tdata)
4137 {
4138 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4139 	struct crypto_unittest_params *ut_params = &unittest_params;
4140 
4141 	int retval;
4142 	uint8_t *plaintext, *ciphertext;
4143 	unsigned plaintext_pad_len;
4144 	unsigned plaintext_len;
4145 	struct rte_cryptodev_info dev_info;
4146 
4147 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4148 	uint64_t feat_flags = dev_info.feature_flags;
4149 
4150 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4151 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4152 		printf("Device doesn't support RAW data-path APIs.\n");
4153 		return TEST_SKIPPED;
4154 	}
4155 
4156 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4157 		return TEST_SKIPPED;
4158 
4159 	/* Verify the capabilities */
4160 	struct rte_cryptodev_sym_capability_idx cap_idx;
4161 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4162 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4163 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4164 			&cap_idx) == NULL)
4165 		return TEST_SKIPPED;
4166 
4167 	/* Create SNOW 3G session */
4168 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4169 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4170 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4171 					tdata->key.data, tdata->key.len,
4172 					tdata->cipher_iv.len);
4173 	if (retval < 0)
4174 		return retval;
4175 
4176 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4177 
4178 	/* Clear mbuf payload */
4179 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4180 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4181 
4182 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4183 	/* Append data which is padded to a multiple of */
4184 	/* the algorithms block size */
4185 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4186 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4187 				plaintext_pad_len);
4188 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4189 
4190 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4191 
4192 	/* Create SNOW 3G operation */
4193 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4194 					tdata->cipher_iv.len,
4195 					tdata->validCipherLenInBits.len,
4196 					0);
4197 	if (retval < 0)
4198 		return retval;
4199 
4200 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
4201 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
4202 					       tdata->cipher_iv.len);
4203 		if (retval != TEST_SUCCESS)
4204 			return retval;
4205 	} else
4206 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4207 						ut_params->op);
4208 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4209 
4210 	ut_params->obuf = ut_params->op->sym->m_dst;
4211 	if (ut_params->obuf)
4212 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4213 	else
4214 		ciphertext = plaintext;
4215 
4216 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4217 
4218 	/* Validate obuf */
4219 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4220 		ciphertext,
4221 		tdata->ciphertext.data,
4222 		tdata->validDataLenInBits.len,
4223 		"SNOW 3G Ciphertext data not as expected");
4224 	return 0;
4225 }
4226 
4227 
4228 static int
4229 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
4230 {
4231 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4232 	struct crypto_unittest_params *ut_params = &unittest_params;
4233 	uint8_t *plaintext, *ciphertext;
4234 
4235 	int retval;
4236 	unsigned plaintext_pad_len;
4237 	unsigned plaintext_len;
4238 	struct rte_cryptodev_info dev_info;
4239 
4240 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4241 	uint64_t feat_flags = dev_info.feature_flags;
4242 
4243 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4244 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4245 		printf("Device does not support RAW data-path APIs.\n");
4246 		return -ENOTSUP;
4247 	}
4248 
4249 	/* Verify the capabilities */
4250 	struct rte_cryptodev_sym_capability_idx cap_idx;
4251 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4252 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4253 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4254 			&cap_idx) == NULL)
4255 		return TEST_SKIPPED;
4256 
4257 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4258 		return TEST_SKIPPED;
4259 
4260 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4261 		return TEST_SKIPPED;
4262 
4263 	/* Create SNOW 3G session */
4264 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4265 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4266 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4267 					tdata->key.data, tdata->key.len,
4268 					tdata->cipher_iv.len);
4269 	if (retval < 0)
4270 		return retval;
4271 
4272 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4273 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4274 
4275 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4276 			"Failed to allocate input buffer in mempool");
4277 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4278 			"Failed to allocate output buffer in mempool");
4279 
4280 	/* Clear mbuf payload */
4281 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4282 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4283 
4284 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4285 	/* Append data which is padded to a multiple of */
4286 	/* the algorithms block size */
4287 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4288 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4289 				plaintext_pad_len);
4290 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4291 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4292 
4293 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4294 
4295 	/* Create SNOW 3G operation */
4296 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4297 					tdata->cipher_iv.len,
4298 					tdata->validCipherLenInBits.len,
4299 					0);
4300 	if (retval < 0)
4301 		return retval;
4302 
4303 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
4304 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
4305 					       tdata->cipher_iv.len);
4306 		if (retval != TEST_SUCCESS)
4307 			return retval;
4308 	} else
4309 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4310 						ut_params->op);
4311 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4312 
4313 	ut_params->obuf = ut_params->op->sym->m_dst;
4314 	if (ut_params->obuf)
4315 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4316 	else
4317 		ciphertext = plaintext;
4318 
4319 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4320 
4321 	/* Validate obuf */
4322 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4323 		ciphertext,
4324 		tdata->ciphertext.data,
4325 		tdata->validDataLenInBits.len,
4326 		"SNOW 3G Ciphertext data not as expected");
4327 	return 0;
4328 }
4329 
4330 static int
4331 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata,
4332 		uint8_t sgl_in, uint8_t sgl_out)
4333 {
4334 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4335 	struct crypto_unittest_params *ut_params = &unittest_params;
4336 
4337 	int retval;
4338 	unsigned int plaintext_pad_len;
4339 	unsigned int plaintext_len;
4340 	uint8_t buffer[10000];
4341 	const uint8_t *ciphertext;
4342 
4343 	struct rte_cryptodev_info dev_info;
4344 
4345 	/* Verify the capabilities */
4346 	struct rte_cryptodev_sym_capability_idx cap_idx;
4347 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4348 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4349 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4350 			&cap_idx) == NULL)
4351 		return TEST_SKIPPED;
4352 
4353 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4354 		return TEST_SKIPPED;
4355 
4356 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4357 		return TEST_SKIPPED;
4358 
4359 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4360 
4361 	uint64_t feat_flags = dev_info.feature_flags;
4362 
4363 	if (((sgl_in && sgl_out) && !(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
4364 			|| ((!sgl_in && sgl_out) &&
4365 			!(feat_flags & RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
4366 			|| ((sgl_in && !sgl_out) &&
4367 			!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))) {
4368 		printf("Device doesn't support out-of-place scatter gather type. "
4369 				"Test Skipped.\n");
4370 		return TEST_SKIPPED;
4371 	}
4372 
4373 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4374 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4375 		printf("Device does not support RAW data-path APIs.\n");
4376 		return -ENOTSUP;
4377 	}
4378 
4379 	/* Create SNOW 3G session */
4380 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4381 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4382 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4383 					tdata->key.data, tdata->key.len,
4384 					tdata->cipher_iv.len);
4385 	if (retval < 0)
4386 		return retval;
4387 
4388 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4389 	/* Append data which is padded to a multiple of */
4390 	/* the algorithms block size */
4391 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4392 
4393 	if (sgl_in)
4394 		ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4395 				plaintext_pad_len, 10, 0);
4396 	else {
4397 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4398 		rte_pktmbuf_append(ut_params->ibuf, plaintext_pad_len);
4399 	}
4400 
4401 	if (sgl_out)
4402 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4403 				plaintext_pad_len, 3, 0);
4404 	else {
4405 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4406 		rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4407 	}
4408 
4409 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4410 			"Failed to allocate input buffer in mempool");
4411 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4412 			"Failed to allocate output buffer in mempool");
4413 
4414 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4415 
4416 	/* Create SNOW 3G operation */
4417 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4418 					tdata->cipher_iv.len,
4419 					tdata->validCipherLenInBits.len,
4420 					0);
4421 	if (retval < 0)
4422 		return retval;
4423 
4424 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
4425 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
4426 					       tdata->cipher_iv.len);
4427 		if (retval != TEST_SUCCESS)
4428 			return retval;
4429 	} else
4430 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4431 						ut_params->op);
4432 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4433 
4434 	ut_params->obuf = ut_params->op->sym->m_dst;
4435 	if (ut_params->obuf)
4436 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4437 				plaintext_len, buffer);
4438 	else
4439 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4440 				plaintext_len, buffer);
4441 
4442 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4443 
4444 	/* Validate obuf */
4445 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4446 		ciphertext,
4447 		tdata->ciphertext.data,
4448 		tdata->validDataLenInBits.len,
4449 		"SNOW 3G Ciphertext data not as expected");
4450 
4451 	return 0;
4452 }
4453 
4454 /* Shift right a buffer by "offset" bits, "offset" < 8 */
4455 static void
4456 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
4457 {
4458 	uint8_t curr_byte, prev_byte;
4459 	uint32_t length_in_bytes = ceil_byte_length(length + offset);
4460 	uint8_t lower_byte_mask = (1 << offset) - 1;
4461 	unsigned i;
4462 
4463 	prev_byte = buffer[0];
4464 	buffer[0] >>= offset;
4465 
4466 	for (i = 1; i < length_in_bytes; i++) {
4467 		curr_byte = buffer[i];
4468 		buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
4469 				(curr_byte >> offset);
4470 		prev_byte = curr_byte;
4471 	}
4472 }
4473 
4474 static int
4475 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
4476 {
4477 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4478 	struct crypto_unittest_params *ut_params = &unittest_params;
4479 	uint8_t *plaintext, *ciphertext;
4480 	int retval;
4481 	uint32_t plaintext_len;
4482 	uint32_t plaintext_pad_len;
4483 	uint8_t extra_offset = 4;
4484 	uint8_t *expected_ciphertext_shifted;
4485 	struct rte_cryptodev_info dev_info;
4486 
4487 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4488 	uint64_t feat_flags = dev_info.feature_flags;
4489 
4490 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4491 			((tdata->validDataLenInBits.len % 8) != 0)) {
4492 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4493 		return TEST_SKIPPED;
4494 	}
4495 
4496 	/* Verify the capabilities */
4497 	struct rte_cryptodev_sym_capability_idx cap_idx;
4498 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4499 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4500 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4501 			&cap_idx) == NULL)
4502 		return TEST_SKIPPED;
4503 
4504 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4505 		return TEST_SKIPPED;
4506 
4507 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4508 		return TEST_SKIPPED;
4509 
4510 	/* Create SNOW 3G session */
4511 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4512 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4513 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4514 					tdata->key.data, tdata->key.len,
4515 					tdata->cipher_iv.len);
4516 	if (retval < 0)
4517 		return retval;
4518 
4519 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4520 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4521 
4522 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4523 			"Failed to allocate input buffer in mempool");
4524 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4525 			"Failed to allocate output buffer in mempool");
4526 
4527 	/* Clear mbuf payload */
4528 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4529 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4530 
4531 	plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4532 	/*
4533 	 * Append data which is padded to a
4534 	 * multiple of the algorithms block size
4535 	 */
4536 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4537 
4538 	plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4539 						plaintext_pad_len);
4540 
4541 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4542 
4543 	memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4544 	buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4545 
4546 #ifdef RTE_APP_TEST_DEBUG
4547 	rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4548 #endif
4549 	/* Create SNOW 3G operation */
4550 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4551 					tdata->cipher_iv.len,
4552 					tdata->validCipherLenInBits.len,
4553 					extra_offset);
4554 	if (retval < 0)
4555 		return retval;
4556 
4557 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
4558 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
4559 					       tdata->cipher_iv.len);
4560 		if (retval != TEST_SUCCESS)
4561 			return retval;
4562 	} else
4563 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4564 						ut_params->op);
4565 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4566 
4567 	ut_params->obuf = ut_params->op->sym->m_dst;
4568 	if (ut_params->obuf)
4569 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4570 	else
4571 		ciphertext = plaintext;
4572 
4573 #ifdef RTE_APP_TEST_DEBUG
4574 	rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4575 #endif
4576 
4577 	expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4578 
4579 	TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4580 			"failed to reserve memory for ciphertext shifted\n");
4581 
4582 	memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4583 			ceil_byte_length(tdata->ciphertext.len));
4584 	buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4585 			extra_offset);
4586 	/* Validate obuf */
4587 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4588 		ciphertext,
4589 		expected_ciphertext_shifted,
4590 		tdata->validDataLenInBits.len,
4591 		extra_offset,
4592 		"SNOW 3G Ciphertext data not as expected");
4593 	return 0;
4594 }
4595 
4596 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4597 {
4598 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4599 	struct crypto_unittest_params *ut_params = &unittest_params;
4600 
4601 	int retval;
4602 
4603 	uint8_t *plaintext, *ciphertext;
4604 	unsigned ciphertext_pad_len;
4605 	unsigned ciphertext_len;
4606 	struct rte_cryptodev_info dev_info;
4607 
4608 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4609 	uint64_t feat_flags = dev_info.feature_flags;
4610 
4611 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4612 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4613 		printf("Device doesn't support RAW data-path APIs.\n");
4614 		return TEST_SKIPPED;
4615 	}
4616 
4617 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4618 		return TEST_SKIPPED;
4619 
4620 	/* Verify the capabilities */
4621 	struct rte_cryptodev_sym_capability_idx cap_idx;
4622 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4623 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4624 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4625 			&cap_idx) == NULL)
4626 		return TEST_SKIPPED;
4627 
4628 	/* Create SNOW 3G session */
4629 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4630 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4631 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4632 					tdata->key.data, tdata->key.len,
4633 					tdata->cipher_iv.len);
4634 	if (retval < 0)
4635 		return retval;
4636 
4637 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4638 
4639 	/* Clear mbuf payload */
4640 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4641 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4642 
4643 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4644 	/* Append data which is padded to a multiple of */
4645 	/* the algorithms block size */
4646 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4647 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4648 				ciphertext_pad_len);
4649 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4650 
4651 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4652 
4653 	/* Create SNOW 3G operation */
4654 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4655 					tdata->cipher_iv.len,
4656 					tdata->validCipherLenInBits.len,
4657 					tdata->cipher.offset_bits);
4658 	if (retval < 0)
4659 		return retval;
4660 
4661 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
4662 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
4663 					       tdata->cipher_iv.len);
4664 		if (retval != TEST_SUCCESS)
4665 			return retval;
4666 	} else
4667 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4668 						ut_params->op);
4669 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4670 	ut_params->obuf = ut_params->op->sym->m_dst;
4671 	if (ut_params->obuf)
4672 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4673 	else
4674 		plaintext = ciphertext;
4675 
4676 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4677 
4678 	/* Validate obuf */
4679 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4680 				tdata->plaintext.data,
4681 				tdata->validDataLenInBits.len,
4682 				"SNOW 3G Plaintext data not as expected");
4683 	return 0;
4684 }
4685 
4686 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4687 {
4688 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4689 	struct crypto_unittest_params *ut_params = &unittest_params;
4690 
4691 	int retval;
4692 
4693 	uint8_t *plaintext, *ciphertext;
4694 	unsigned ciphertext_pad_len;
4695 	unsigned ciphertext_len;
4696 	struct rte_cryptodev_info dev_info;
4697 
4698 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4699 	uint64_t feat_flags = dev_info.feature_flags;
4700 
4701 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4702 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4703 		printf("Device does not support RAW data-path APIs.\n");
4704 		return -ENOTSUP;
4705 	}
4706 	/* Verify the capabilities */
4707 	struct rte_cryptodev_sym_capability_idx cap_idx;
4708 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4709 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4710 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4711 			&cap_idx) == NULL)
4712 		return TEST_SKIPPED;
4713 
4714 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4715 		return TEST_SKIPPED;
4716 
4717 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4718 		return TEST_SKIPPED;
4719 
4720 	/* Create SNOW 3G session */
4721 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4722 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4723 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4724 					tdata->key.data, tdata->key.len,
4725 					tdata->cipher_iv.len);
4726 	if (retval < 0)
4727 		return retval;
4728 
4729 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4730 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4731 
4732 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4733 			"Failed to allocate input buffer");
4734 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4735 			"Failed to allocate output buffer");
4736 
4737 	/* Clear mbuf payload */
4738 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4739 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4740 
4741 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4742 		       rte_pktmbuf_tailroom(ut_params->obuf));
4743 
4744 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4745 	/* Append data which is padded to a multiple of */
4746 	/* the algorithms block size */
4747 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4748 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4749 				ciphertext_pad_len);
4750 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4751 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4752 
4753 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4754 
4755 	/* Create SNOW 3G operation */
4756 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4757 					tdata->cipher_iv.len,
4758 					tdata->validCipherLenInBits.len,
4759 					0);
4760 	if (retval < 0)
4761 		return retval;
4762 
4763 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
4764 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
4765 					       tdata->cipher_iv.len);
4766 		if (retval != TEST_SUCCESS)
4767 			return retval;
4768 	} else
4769 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4770 						ut_params->op);
4771 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4772 	ut_params->obuf = ut_params->op->sym->m_dst;
4773 	if (ut_params->obuf)
4774 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4775 	else
4776 		plaintext = ciphertext;
4777 
4778 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4779 
4780 	/* Validate obuf */
4781 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4782 				tdata->plaintext.data,
4783 				tdata->validDataLenInBits.len,
4784 				"SNOW 3G Plaintext data not as expected");
4785 	return 0;
4786 }
4787 
4788 static int
4789 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4790 {
4791 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4792 	struct crypto_unittest_params *ut_params = &unittest_params;
4793 
4794 	int retval;
4795 
4796 	uint8_t *plaintext, *ciphertext;
4797 	unsigned int plaintext_pad_len;
4798 	unsigned int plaintext_len;
4799 
4800 	struct rte_cryptodev_info dev_info;
4801 
4802 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4803 	uint64_t feat_flags = dev_info.feature_flags;
4804 
4805 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4806 			((tdata->validAuthLenInBits.len % 8 != 0) ||
4807 			(tdata->validDataLenInBits.len % 8 != 0))) {
4808 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4809 		return TEST_SKIPPED;
4810 	}
4811 
4812 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4813 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4814 		printf("Device doesn't support RAW data-path APIs.\n");
4815 		return TEST_SKIPPED;
4816 	}
4817 
4818 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4819 		return TEST_SKIPPED;
4820 
4821 	/* Check if device supports ZUC EEA3 */
4822 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
4823 			tdata->key.len, tdata->cipher_iv.len) < 0)
4824 		return TEST_SKIPPED;
4825 
4826 	/* Check if device supports ZUC EIA3 */
4827 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
4828 			tdata->key.len, tdata->auth_iv.len,
4829 			tdata->digest.len) < 0)
4830 		return TEST_SKIPPED;
4831 
4832 	/* Create ZUC session */
4833 	retval = create_zuc_cipher_auth_encrypt_generate_session(
4834 			ts_params->valid_devs[0],
4835 			tdata);
4836 	if (retval != 0)
4837 		return retval;
4838 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4839 
4840 	/* clear mbuf payload */
4841 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4842 			rte_pktmbuf_tailroom(ut_params->ibuf));
4843 
4844 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4845 	/* Append data which is padded to a multiple of */
4846 	/* the algorithms block size */
4847 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4848 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4849 				plaintext_pad_len);
4850 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4851 
4852 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4853 
4854 	/* Create ZUC operation */
4855 	retval = create_zuc_cipher_hash_generate_operation(tdata);
4856 	if (retval < 0)
4857 		return retval;
4858 
4859 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
4860 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1,
4861 					       tdata->cipher_iv.len);
4862 		if (retval != TEST_SUCCESS)
4863 			return retval;
4864 	} else
4865 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4866 			ut_params->op);
4867 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4868 	ut_params->obuf = ut_params->op->sym->m_src;
4869 	if (ut_params->obuf)
4870 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4871 	else
4872 		ciphertext = plaintext;
4873 
4874 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4875 	/* Validate obuf */
4876 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4877 			ciphertext,
4878 			tdata->ciphertext.data,
4879 			tdata->validDataLenInBits.len,
4880 			"ZUC Ciphertext data not as expected");
4881 
4882 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4883 	    + plaintext_pad_len;
4884 
4885 	/* Validate obuf */
4886 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4887 			ut_params->digest,
4888 			tdata->digest.data,
4889 			tdata->digest.len,
4890 			"ZUC Generated auth tag not as expected");
4891 	return 0;
4892 }
4893 
4894 static int
4895 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4896 {
4897 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4898 	struct crypto_unittest_params *ut_params = &unittest_params;
4899 
4900 	int retval;
4901 
4902 	uint8_t *plaintext, *ciphertext;
4903 	unsigned plaintext_pad_len;
4904 	unsigned plaintext_len;
4905 	struct rte_cryptodev_info dev_info;
4906 
4907 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4908 	uint64_t feat_flags = dev_info.feature_flags;
4909 
4910 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4911 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4912 		printf("Device doesn't support RAW data-path APIs.\n");
4913 		return TEST_SKIPPED;
4914 	}
4915 
4916 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4917 		return TEST_SKIPPED;
4918 
4919 	/* Verify the capabilities */
4920 	struct rte_cryptodev_sym_capability_idx cap_idx;
4921 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4922 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4923 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4924 			&cap_idx) == NULL)
4925 		return TEST_SKIPPED;
4926 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4927 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4928 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4929 			&cap_idx) == NULL)
4930 		return TEST_SKIPPED;
4931 
4932 	/* Create SNOW 3G session */
4933 	retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4934 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4935 			RTE_CRYPTO_AUTH_OP_GENERATE,
4936 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4937 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4938 			tdata->key.data, tdata->key.len,
4939 			tdata->key.data, tdata->key.len,
4940 			tdata->auth_iv.len, tdata->digest.len,
4941 			tdata->cipher_iv.len);
4942 	if (retval != 0)
4943 		return retval;
4944 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4945 
4946 	/* clear mbuf payload */
4947 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4948 			rte_pktmbuf_tailroom(ut_params->ibuf));
4949 
4950 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4951 	/* Append data which is padded to a multiple of */
4952 	/* the algorithms block size */
4953 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4954 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4955 				plaintext_pad_len);
4956 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4957 
4958 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4959 
4960 	/* Create SNOW 3G operation */
4961 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4962 			tdata->digest.len, tdata->auth_iv.data,
4963 			tdata->auth_iv.len,
4964 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4965 			tdata->cipher_iv.data, tdata->cipher_iv.len,
4966 			tdata->validCipherLenInBits.len,
4967 			0,
4968 			tdata->validAuthLenInBits.len,
4969 			0
4970 			);
4971 	if (retval < 0)
4972 		return retval;
4973 
4974 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
4975 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1,
4976 					       tdata->cipher_iv.len);
4977 		if (retval != TEST_SUCCESS)
4978 			return retval;
4979 	} else
4980 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4981 			ut_params->op);
4982 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4983 	ut_params->obuf = ut_params->op->sym->m_src;
4984 	if (ut_params->obuf)
4985 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4986 	else
4987 		ciphertext = plaintext;
4988 
4989 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4990 	/* Validate obuf */
4991 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4992 			ciphertext,
4993 			tdata->ciphertext.data,
4994 			tdata->validDataLenInBits.len,
4995 			"SNOW 3G Ciphertext data not as expected");
4996 
4997 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4998 	    + plaintext_pad_len;
4999 
5000 	/* Validate obuf */
5001 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
5002 			ut_params->digest,
5003 			tdata->digest.data,
5004 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5005 			"SNOW 3G Generated auth tag not as expected");
5006 	return 0;
5007 }
5008 
5009 static int
5010 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
5011 	uint8_t op_mode, uint8_t verify)
5012 {
5013 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5014 	struct crypto_unittest_params *ut_params = &unittest_params;
5015 
5016 	int retval;
5017 
5018 	uint8_t *plaintext = NULL, *ciphertext = NULL;
5019 	unsigned int plaintext_pad_len;
5020 	unsigned int plaintext_len;
5021 	unsigned int ciphertext_pad_len;
5022 	unsigned int ciphertext_len;
5023 
5024 	struct rte_cryptodev_info dev_info;
5025 
5026 	/* Verify the capabilities */
5027 	struct rte_cryptodev_sym_capability_idx cap_idx;
5028 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5029 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5030 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5031 			&cap_idx) == NULL)
5032 		return TEST_SKIPPED;
5033 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5034 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5035 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5036 			&cap_idx) == NULL)
5037 		return TEST_SKIPPED;
5038 
5039 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5040 		return TEST_SKIPPED;
5041 
5042 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5043 
5044 	uint64_t feat_flags = dev_info.feature_flags;
5045 
5046 	if (op_mode == OUT_OF_PLACE) {
5047 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5048 			printf("Device doesn't support digest encrypted.\n");
5049 			return TEST_SKIPPED;
5050 		}
5051 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5052 			return TEST_SKIPPED;
5053 	}
5054 
5055 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5056 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5057 		printf("Device doesn't support RAW data-path APIs.\n");
5058 		return TEST_SKIPPED;
5059 	}
5060 
5061 	/* Create SNOW 3G session */
5062 	retval = create_wireless_algo_auth_cipher_session(
5063 			ts_params->valid_devs[0],
5064 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5065 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5066 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5067 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5068 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5069 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5070 			tdata->key.data, tdata->key.len,
5071 			tdata->key.data, tdata->key.len,
5072 			tdata->auth_iv.len, tdata->digest.len,
5073 			tdata->cipher_iv.len);
5074 	if (retval != 0)
5075 		return retval;
5076 
5077 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5078 	if (op_mode == OUT_OF_PLACE)
5079 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5080 
5081 	/* clear mbuf payload */
5082 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5083 		rte_pktmbuf_tailroom(ut_params->ibuf));
5084 	if (op_mode == OUT_OF_PLACE)
5085 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5086 			rte_pktmbuf_tailroom(ut_params->obuf));
5087 
5088 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5089 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5090 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5091 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5092 
5093 	if (verify) {
5094 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5095 					ciphertext_pad_len);
5096 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5097 		if (op_mode == OUT_OF_PLACE)
5098 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5099 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5100 			ciphertext_len);
5101 	} else {
5102 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5103 					plaintext_pad_len);
5104 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5105 		if (op_mode == OUT_OF_PLACE)
5106 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5107 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5108 	}
5109 
5110 	/* Create SNOW 3G operation */
5111 	retval = create_wireless_algo_auth_cipher_operation(
5112 		tdata->digest.data, tdata->digest.len,
5113 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5114 		tdata->auth_iv.data, tdata->auth_iv.len,
5115 		(tdata->digest.offset_bytes == 0 ?
5116 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5117 			: tdata->digest.offset_bytes),
5118 		tdata->validCipherLenInBits.len,
5119 		tdata->cipher.offset_bits,
5120 		tdata->validAuthLenInBits.len,
5121 		tdata->auth.offset_bits,
5122 		op_mode, 0, verify);
5123 
5124 	if (retval < 0)
5125 		return retval;
5126 
5127 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
5128 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1,
5129 					       tdata->cipher_iv.len);
5130 		if (retval != TEST_SUCCESS)
5131 			return retval;
5132 	} else
5133 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5134 			ut_params->op);
5135 
5136 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5137 
5138 	ut_params->obuf = (op_mode == IN_PLACE ?
5139 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5140 
5141 	if (verify) {
5142 		if (ut_params->obuf)
5143 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5144 							uint8_t *);
5145 		else
5146 			plaintext = ciphertext +
5147 				(tdata->cipher.offset_bits >> 3);
5148 
5149 		debug_hexdump(stdout, "plaintext:", plaintext,
5150 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5151 		debug_hexdump(stdout, "plaintext expected:",
5152 			tdata->plaintext.data,
5153 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5154 	} else {
5155 		if (ut_params->obuf)
5156 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5157 							uint8_t *);
5158 		else
5159 			ciphertext = plaintext;
5160 
5161 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5162 			ciphertext_len);
5163 		debug_hexdump(stdout, "ciphertext expected:",
5164 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5165 
5166 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5167 			+ (tdata->digest.offset_bytes == 0 ?
5168 		plaintext_pad_len : tdata->digest.offset_bytes);
5169 
5170 		debug_hexdump(stdout, "digest:", ut_params->digest,
5171 			tdata->digest.len);
5172 		debug_hexdump(stdout, "digest expected:", tdata->digest.data,
5173 				tdata->digest.len);
5174 	}
5175 
5176 	/* Validate obuf */
5177 	if (verify) {
5178 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5179 			plaintext,
5180 			tdata->plaintext.data,
5181 			(tdata->plaintext.len - tdata->cipher.offset_bits -
5182 			 (tdata->digest.len << 3)),
5183 			tdata->cipher.offset_bits,
5184 			"SNOW 3G Plaintext data not as expected");
5185 	} else {
5186 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5187 			ciphertext,
5188 			tdata->ciphertext.data,
5189 			(tdata->validDataLenInBits.len -
5190 			 tdata->cipher.offset_bits),
5191 			tdata->cipher.offset_bits,
5192 			"SNOW 3G Ciphertext data not as expected");
5193 
5194 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5195 			ut_params->digest,
5196 			tdata->digest.data,
5197 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5198 			"SNOW 3G Generated auth tag not as expected");
5199 	}
5200 	return 0;
5201 }
5202 
5203 static int
5204 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
5205 	uint8_t op_mode, uint8_t verify)
5206 {
5207 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5208 	struct crypto_unittest_params *ut_params = &unittest_params;
5209 
5210 	int retval;
5211 
5212 	const uint8_t *plaintext = NULL;
5213 	const uint8_t *ciphertext = NULL;
5214 	const uint8_t *digest = NULL;
5215 	unsigned int plaintext_pad_len;
5216 	unsigned int plaintext_len;
5217 	unsigned int ciphertext_pad_len;
5218 	unsigned int ciphertext_len;
5219 	uint8_t buffer[10000];
5220 	uint8_t digest_buffer[10000];
5221 
5222 	struct rte_cryptodev_info dev_info;
5223 
5224 	/* Verify the capabilities */
5225 	struct rte_cryptodev_sym_capability_idx cap_idx;
5226 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5227 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5228 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5229 			&cap_idx) == NULL)
5230 		return TEST_SKIPPED;
5231 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5232 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5233 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5234 			&cap_idx) == NULL)
5235 		return TEST_SKIPPED;
5236 
5237 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5238 		return TEST_SKIPPED;
5239 
5240 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5241 
5242 	uint64_t feat_flags = dev_info.feature_flags;
5243 
5244 	if (op_mode == IN_PLACE) {
5245 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5246 			printf("Device doesn't support in-place scatter-gather "
5247 					"in both input and output mbufs.\n");
5248 			return TEST_SKIPPED;
5249 		}
5250 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5251 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5252 			printf("Device doesn't support RAW data-path APIs.\n");
5253 			return TEST_SKIPPED;
5254 		}
5255 	} else {
5256 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5257 			return TEST_SKIPPED;
5258 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5259 			printf("Device doesn't support out-of-place scatter-gather "
5260 					"in both input and output mbufs.\n");
5261 			return TEST_SKIPPED;
5262 		}
5263 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5264 			printf("Device doesn't support digest encrypted.\n");
5265 			return TEST_SKIPPED;
5266 		}
5267 	}
5268 
5269 	/* Create SNOW 3G session */
5270 	retval = create_wireless_algo_auth_cipher_session(
5271 			ts_params->valid_devs[0],
5272 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5273 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5274 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5275 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5276 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5277 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5278 			tdata->key.data, tdata->key.len,
5279 			tdata->key.data, tdata->key.len,
5280 			tdata->auth_iv.len, tdata->digest.len,
5281 			tdata->cipher_iv.len);
5282 
5283 	if (retval != 0)
5284 		return retval;
5285 
5286 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5287 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5288 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5289 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5290 
5291 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5292 			plaintext_pad_len, 15, 0);
5293 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5294 			"Failed to allocate input buffer in mempool");
5295 
5296 	if (op_mode == OUT_OF_PLACE) {
5297 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5298 				plaintext_pad_len, 15, 0);
5299 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5300 				"Failed to allocate output buffer in mempool");
5301 	}
5302 
5303 	if (verify) {
5304 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5305 			tdata->ciphertext.data);
5306 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5307 					ciphertext_len, buffer);
5308 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5309 			ciphertext_len);
5310 	} else {
5311 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5312 			tdata->plaintext.data);
5313 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5314 					plaintext_len, buffer);
5315 		debug_hexdump(stdout, "plaintext:", plaintext,
5316 			plaintext_len);
5317 	}
5318 	memset(buffer, 0, sizeof(buffer));
5319 
5320 	/* Create SNOW 3G operation */
5321 	retval = create_wireless_algo_auth_cipher_operation(
5322 		tdata->digest.data, tdata->digest.len,
5323 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5324 		tdata->auth_iv.data, tdata->auth_iv.len,
5325 		(tdata->digest.offset_bytes == 0 ?
5326 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5327 			: tdata->digest.offset_bytes),
5328 		tdata->validCipherLenInBits.len,
5329 		tdata->cipher.offset_bits,
5330 		tdata->validAuthLenInBits.len,
5331 		tdata->auth.offset_bits,
5332 		op_mode, 1, verify);
5333 
5334 	if (retval < 0)
5335 		return retval;
5336 
5337 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
5338 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1,
5339 					       tdata->cipher_iv.len);
5340 		if (retval != TEST_SUCCESS)
5341 			return retval;
5342 	} else
5343 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5344 			ut_params->op);
5345 
5346 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5347 
5348 	ut_params->obuf = (op_mode == IN_PLACE ?
5349 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5350 
5351 	if (verify) {
5352 		if (ut_params->obuf)
5353 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5354 					plaintext_len, buffer);
5355 		else
5356 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5357 					plaintext_len, buffer);
5358 
5359 		debug_hexdump(stdout, "plaintext:", plaintext,
5360 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5361 		debug_hexdump(stdout, "plaintext expected:",
5362 			tdata->plaintext.data,
5363 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5364 	} else {
5365 		if (ut_params->obuf)
5366 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5367 					ciphertext_len, buffer);
5368 		else
5369 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5370 					ciphertext_len, buffer);
5371 
5372 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5373 			ciphertext_len);
5374 		debug_hexdump(stdout, "ciphertext expected:",
5375 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5376 
5377 		if (ut_params->obuf)
5378 			digest = rte_pktmbuf_read(ut_params->obuf,
5379 				(tdata->digest.offset_bytes == 0 ?
5380 				plaintext_pad_len : tdata->digest.offset_bytes),
5381 				tdata->digest.len, digest_buffer);
5382 		else
5383 			digest = rte_pktmbuf_read(ut_params->ibuf,
5384 				(tdata->digest.offset_bytes == 0 ?
5385 				plaintext_pad_len : tdata->digest.offset_bytes),
5386 				tdata->digest.len, digest_buffer);
5387 
5388 		debug_hexdump(stdout, "digest:", digest,
5389 			tdata->digest.len);
5390 		debug_hexdump(stdout, "digest expected:",
5391 			tdata->digest.data, tdata->digest.len);
5392 	}
5393 
5394 	/* Validate obuf */
5395 	if (verify) {
5396 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5397 			plaintext,
5398 			tdata->plaintext.data,
5399 			(tdata->plaintext.len - tdata->cipher.offset_bits -
5400 			 (tdata->digest.len << 3)),
5401 			tdata->cipher.offset_bits,
5402 			"SNOW 3G Plaintext data not as expected");
5403 	} else {
5404 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5405 			ciphertext,
5406 			tdata->ciphertext.data,
5407 			(tdata->validDataLenInBits.len -
5408 			 tdata->cipher.offset_bits),
5409 			tdata->cipher.offset_bits,
5410 			"SNOW 3G Ciphertext data not as expected");
5411 
5412 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5413 			digest,
5414 			tdata->digest.data,
5415 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5416 			"SNOW 3G Generated auth tag not as expected");
5417 	}
5418 	return 0;
5419 }
5420 
5421 static int
5422 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
5423 	uint8_t op_mode, uint8_t verify)
5424 {
5425 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5426 	struct crypto_unittest_params *ut_params = &unittest_params;
5427 
5428 	int retval;
5429 
5430 	uint8_t *plaintext = NULL, *ciphertext = NULL;
5431 	unsigned int plaintext_pad_len;
5432 	unsigned int plaintext_len;
5433 	unsigned int ciphertext_pad_len;
5434 	unsigned int ciphertext_len;
5435 
5436 	struct rte_cryptodev_info dev_info;
5437 
5438 	/* Verify the capabilities */
5439 	struct rte_cryptodev_sym_capability_idx cap_idx;
5440 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5441 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5442 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5443 			&cap_idx) == NULL)
5444 		return TEST_SKIPPED;
5445 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5446 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5447 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5448 			&cap_idx) == NULL)
5449 		return TEST_SKIPPED;
5450 
5451 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5452 
5453 	uint64_t feat_flags = dev_info.feature_flags;
5454 
5455 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5456 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5457 		printf("Device doesn't support RAW data-path APIs.\n");
5458 		return TEST_SKIPPED;
5459 	}
5460 
5461 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5462 		return TEST_SKIPPED;
5463 
5464 	if (op_mode == OUT_OF_PLACE) {
5465 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5466 			return TEST_SKIPPED;
5467 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5468 			printf("Device doesn't support digest encrypted.\n");
5469 			return TEST_SKIPPED;
5470 		}
5471 	}
5472 
5473 	/* Create KASUMI session */
5474 	retval = create_wireless_algo_auth_cipher_session(
5475 			ts_params->valid_devs[0],
5476 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5477 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5478 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5479 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5480 			RTE_CRYPTO_AUTH_KASUMI_F9,
5481 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5482 			tdata->key.data, tdata->key.len,
5483 			tdata->key.data, tdata->key.len,
5484 			0, tdata->digest.len,
5485 			tdata->cipher_iv.len);
5486 
5487 	if (retval != 0)
5488 		return retval;
5489 
5490 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5491 	if (op_mode == OUT_OF_PLACE)
5492 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5493 
5494 	/* clear mbuf payload */
5495 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5496 		rte_pktmbuf_tailroom(ut_params->ibuf));
5497 	if (op_mode == OUT_OF_PLACE)
5498 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5499 			rte_pktmbuf_tailroom(ut_params->obuf));
5500 
5501 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5502 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5503 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5504 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5505 
5506 	if (verify) {
5507 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5508 					ciphertext_pad_len);
5509 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5510 		if (op_mode == OUT_OF_PLACE)
5511 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5512 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5513 			ciphertext_len);
5514 	} else {
5515 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5516 					plaintext_pad_len);
5517 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5518 		if (op_mode == OUT_OF_PLACE)
5519 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5520 		debug_hexdump(stdout, "plaintext:", plaintext,
5521 			plaintext_len);
5522 	}
5523 
5524 	/* Create KASUMI operation */
5525 	retval = create_wireless_algo_auth_cipher_operation(
5526 		tdata->digest.data, tdata->digest.len,
5527 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5528 		NULL, 0,
5529 		(tdata->digest.offset_bytes == 0 ?
5530 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5531 			: tdata->digest.offset_bytes),
5532 		tdata->validCipherLenInBits.len,
5533 		tdata->validCipherOffsetInBits.len,
5534 		tdata->validAuthLenInBits.len,
5535 		0,
5536 		op_mode, 0, verify);
5537 
5538 	if (retval < 0)
5539 		return retval;
5540 
5541 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
5542 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1,
5543 					       tdata->cipher_iv.len);
5544 		if (retval != TEST_SUCCESS)
5545 			return retval;
5546 	} else
5547 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5548 			ut_params->op);
5549 
5550 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5551 
5552 	ut_params->obuf = (op_mode == IN_PLACE ?
5553 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5554 
5555 
5556 	if (verify) {
5557 		if (ut_params->obuf)
5558 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5559 							uint8_t *);
5560 		else
5561 			plaintext = ciphertext;
5562 
5563 		debug_hexdump(stdout, "plaintext:", plaintext,
5564 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5565 		debug_hexdump(stdout, "plaintext expected:",
5566 			tdata->plaintext.data,
5567 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5568 	} else {
5569 		if (ut_params->obuf)
5570 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5571 							uint8_t *);
5572 		else
5573 			ciphertext = plaintext;
5574 
5575 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5576 			ciphertext_len);
5577 		debug_hexdump(stdout, "ciphertext expected:",
5578 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5579 
5580 		ut_params->digest = rte_pktmbuf_mtod(
5581 			ut_params->obuf, uint8_t *) +
5582 			(tdata->digest.offset_bytes == 0 ?
5583 			plaintext_pad_len : tdata->digest.offset_bytes);
5584 
5585 		debug_hexdump(stdout, "digest:", ut_params->digest,
5586 			tdata->digest.len);
5587 		debug_hexdump(stdout, "digest expected:",
5588 			tdata->digest.data, tdata->digest.len);
5589 	}
5590 
5591 	/* Validate obuf */
5592 	if (verify) {
5593 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5594 			plaintext,
5595 			tdata->plaintext.data,
5596 			tdata->plaintext.len >> 3,
5597 			"KASUMI Plaintext data not as expected");
5598 	} else {
5599 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5600 			ciphertext,
5601 			tdata->ciphertext.data,
5602 			tdata->ciphertext.len >> 3,
5603 			"KASUMI Ciphertext data not as expected");
5604 
5605 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5606 			ut_params->digest,
5607 			tdata->digest.data,
5608 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5609 			"KASUMI Generated auth tag not as expected");
5610 	}
5611 	return 0;
5612 }
5613 
5614 static int
5615 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5616 	uint8_t op_mode, uint8_t verify)
5617 {
5618 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5619 	struct crypto_unittest_params *ut_params = &unittest_params;
5620 
5621 	int retval;
5622 
5623 	const uint8_t *plaintext = NULL;
5624 	const uint8_t *ciphertext = NULL;
5625 	const uint8_t *digest = NULL;
5626 	unsigned int plaintext_pad_len;
5627 	unsigned int plaintext_len;
5628 	unsigned int ciphertext_pad_len;
5629 	unsigned int ciphertext_len;
5630 	uint8_t buffer[10000];
5631 	uint8_t digest_buffer[10000];
5632 
5633 	struct rte_cryptodev_info dev_info;
5634 
5635 	/* Verify the capabilities */
5636 	struct rte_cryptodev_sym_capability_idx cap_idx;
5637 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5638 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5639 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5640 			&cap_idx) == NULL)
5641 		return TEST_SKIPPED;
5642 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5643 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5644 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5645 			&cap_idx) == NULL)
5646 		return TEST_SKIPPED;
5647 
5648 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5649 		return TEST_SKIPPED;
5650 
5651 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5652 
5653 	uint64_t feat_flags = dev_info.feature_flags;
5654 
5655 	if (op_mode == IN_PLACE) {
5656 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5657 			printf("Device doesn't support in-place scatter-gather "
5658 					"in both input and output mbufs.\n");
5659 			return TEST_SKIPPED;
5660 		}
5661 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5662 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5663 			printf("Device doesn't support RAW data-path APIs.\n");
5664 			return TEST_SKIPPED;
5665 		}
5666 	} else {
5667 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5668 			return TEST_SKIPPED;
5669 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5670 			printf("Device doesn't support out-of-place scatter-gather "
5671 					"in both input and output mbufs.\n");
5672 			return TEST_SKIPPED;
5673 		}
5674 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5675 			printf("Device doesn't support digest encrypted.\n");
5676 			return TEST_SKIPPED;
5677 		}
5678 	}
5679 
5680 	/* Create KASUMI session */
5681 	retval = create_wireless_algo_auth_cipher_session(
5682 			ts_params->valid_devs[0],
5683 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5684 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5685 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5686 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5687 			RTE_CRYPTO_AUTH_KASUMI_F9,
5688 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5689 			tdata->key.data, tdata->key.len,
5690 			tdata->key.data, tdata->key.len,
5691 			0, tdata->digest.len,
5692 			tdata->cipher_iv.len);
5693 
5694 	if (retval != 0)
5695 		return retval;
5696 
5697 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5698 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5699 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5700 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5701 
5702 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5703 			plaintext_pad_len, 15, 0);
5704 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5705 			"Failed to allocate input buffer in mempool");
5706 
5707 	if (op_mode == OUT_OF_PLACE) {
5708 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5709 				plaintext_pad_len, 15, 0);
5710 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5711 				"Failed to allocate output buffer in mempool");
5712 	}
5713 
5714 	if (verify) {
5715 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5716 			tdata->ciphertext.data);
5717 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5718 					ciphertext_len, buffer);
5719 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5720 			ciphertext_len);
5721 	} else {
5722 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5723 			tdata->plaintext.data);
5724 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5725 					plaintext_len, buffer);
5726 		debug_hexdump(stdout, "plaintext:", plaintext,
5727 			plaintext_len);
5728 	}
5729 	memset(buffer, 0, sizeof(buffer));
5730 
5731 	/* Create KASUMI operation */
5732 	retval = create_wireless_algo_auth_cipher_operation(
5733 		tdata->digest.data, tdata->digest.len,
5734 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5735 		NULL, 0,
5736 		(tdata->digest.offset_bytes == 0 ?
5737 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5738 			: tdata->digest.offset_bytes),
5739 		tdata->validCipherLenInBits.len,
5740 		tdata->validCipherOffsetInBits.len,
5741 		tdata->validAuthLenInBits.len,
5742 		0,
5743 		op_mode, 1, verify);
5744 
5745 	if (retval < 0)
5746 		return retval;
5747 
5748 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
5749 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1,
5750 					       tdata->cipher_iv.len);
5751 		if (retval != TEST_SUCCESS)
5752 			return retval;
5753 	} else
5754 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5755 			ut_params->op);
5756 
5757 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5758 
5759 	ut_params->obuf = (op_mode == IN_PLACE ?
5760 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5761 
5762 	if (verify) {
5763 		if (ut_params->obuf)
5764 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5765 					plaintext_len, buffer);
5766 		else
5767 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5768 					plaintext_len, buffer);
5769 
5770 		debug_hexdump(stdout, "plaintext:", plaintext,
5771 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5772 		debug_hexdump(stdout, "plaintext expected:",
5773 			tdata->plaintext.data,
5774 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5775 	} else {
5776 		if (ut_params->obuf)
5777 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5778 					ciphertext_len, buffer);
5779 		else
5780 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5781 					ciphertext_len, buffer);
5782 
5783 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5784 			ciphertext_len);
5785 		debug_hexdump(stdout, "ciphertext expected:",
5786 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5787 
5788 		if (ut_params->obuf)
5789 			digest = rte_pktmbuf_read(ut_params->obuf,
5790 				(tdata->digest.offset_bytes == 0 ?
5791 				plaintext_pad_len : tdata->digest.offset_bytes),
5792 				tdata->digest.len, digest_buffer);
5793 		else
5794 			digest = rte_pktmbuf_read(ut_params->ibuf,
5795 				(tdata->digest.offset_bytes == 0 ?
5796 				plaintext_pad_len : tdata->digest.offset_bytes),
5797 				tdata->digest.len, digest_buffer);
5798 
5799 		debug_hexdump(stdout, "digest:", digest,
5800 			tdata->digest.len);
5801 		debug_hexdump(stdout, "digest expected:",
5802 			tdata->digest.data, tdata->digest.len);
5803 	}
5804 
5805 	/* Validate obuf */
5806 	if (verify) {
5807 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5808 			plaintext,
5809 			tdata->plaintext.data,
5810 			tdata->plaintext.len >> 3,
5811 			"KASUMI Plaintext data not as expected");
5812 	} else {
5813 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5814 			ciphertext,
5815 			tdata->ciphertext.data,
5816 			tdata->validDataLenInBits.len,
5817 			"KASUMI Ciphertext data not as expected");
5818 
5819 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5820 			digest,
5821 			tdata->digest.data,
5822 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5823 			"KASUMI Generated auth tag not as expected");
5824 	}
5825 	return 0;
5826 }
5827 
5828 static int
5829 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5830 {
5831 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5832 	struct crypto_unittest_params *ut_params = &unittest_params;
5833 
5834 	int retval;
5835 
5836 	uint8_t *plaintext, *ciphertext;
5837 	unsigned plaintext_pad_len;
5838 	unsigned plaintext_len;
5839 	struct rte_cryptodev_info dev_info;
5840 
5841 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5842 	uint64_t feat_flags = dev_info.feature_flags;
5843 
5844 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5845 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5846 		printf("Device doesn't support RAW data-path APIs.\n");
5847 		return TEST_SKIPPED;
5848 	}
5849 
5850 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5851 		return TEST_SKIPPED;
5852 
5853 	/* Verify the capabilities */
5854 	struct rte_cryptodev_sym_capability_idx cap_idx;
5855 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5856 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5857 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5858 			&cap_idx) == NULL)
5859 		return TEST_SKIPPED;
5860 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5861 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5862 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5863 			&cap_idx) == NULL)
5864 		return TEST_SKIPPED;
5865 
5866 	/* Create KASUMI session */
5867 	retval = create_wireless_algo_cipher_auth_session(
5868 			ts_params->valid_devs[0],
5869 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5870 			RTE_CRYPTO_AUTH_OP_GENERATE,
5871 			RTE_CRYPTO_AUTH_KASUMI_F9,
5872 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5873 			tdata->key.data, tdata->key.len,
5874 			tdata->key.data, tdata->key.len,
5875 			0, tdata->digest.len,
5876 			tdata->cipher_iv.len);
5877 	if (retval != 0)
5878 		return retval;
5879 
5880 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5881 
5882 	/* clear mbuf payload */
5883 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5884 			rte_pktmbuf_tailroom(ut_params->ibuf));
5885 
5886 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5887 	/* Append data which is padded to a multiple of */
5888 	/* the algorithms block size */
5889 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5890 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5891 				plaintext_pad_len);
5892 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5893 
5894 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5895 
5896 	/* Create KASUMI operation */
5897 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5898 				tdata->digest.len, NULL, 0,
5899 				plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5900 				tdata->cipher_iv.data, tdata->cipher_iv.len,
5901 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5902 				tdata->validCipherOffsetInBits.len,
5903 				tdata->validAuthLenInBits.len,
5904 				0
5905 				);
5906 	if (retval < 0)
5907 		return retval;
5908 
5909 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
5910 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1,
5911 					       tdata->cipher_iv.len);
5912 		if (retval != TEST_SUCCESS)
5913 			return retval;
5914 	} else
5915 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5916 			ut_params->op);
5917 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5918 
5919 	if (ut_params->op->sym->m_dst)
5920 		ut_params->obuf = ut_params->op->sym->m_dst;
5921 	else
5922 		ut_params->obuf = ut_params->op->sym->m_src;
5923 
5924 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5925 				tdata->validCipherOffsetInBits.len >> 3);
5926 
5927 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5928 			+ plaintext_pad_len;
5929 
5930 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5931 				(tdata->validCipherOffsetInBits.len >> 3);
5932 	/* Validate obuf */
5933 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5934 		ciphertext,
5935 		reference_ciphertext,
5936 		tdata->validCipherLenInBits.len,
5937 		"KASUMI Ciphertext data not as expected");
5938 
5939 	/* Validate obuf */
5940 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
5941 		ut_params->digest,
5942 		tdata->digest.data,
5943 		DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5944 		"KASUMI Generated auth tag not as expected");
5945 	return 0;
5946 }
5947 
5948 static int
5949 check_cipher_capability(const struct crypto_testsuite_params *ts_params,
5950 			const enum rte_crypto_cipher_algorithm cipher_algo,
5951 			const uint16_t key_size, const uint16_t iv_size)
5952 {
5953 	struct rte_cryptodev_sym_capability_idx cap_idx;
5954 	const struct rte_cryptodev_symmetric_capability *cap;
5955 
5956 	/* Check if device supports the algorithm */
5957 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5958 	cap_idx.algo.cipher = cipher_algo;
5959 
5960 	cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5961 			&cap_idx);
5962 
5963 	if (cap == NULL)
5964 		return -1;
5965 
5966 	/* Check if device supports key size and IV size */
5967 	if (rte_cryptodev_sym_capability_check_cipher(cap, key_size,
5968 			iv_size) < 0) {
5969 		return -1;
5970 	}
5971 
5972 	return 0;
5973 }
5974 
5975 static int
5976 check_auth_capability(const struct crypto_testsuite_params *ts_params,
5977 			const enum rte_crypto_auth_algorithm auth_algo,
5978 			const uint16_t key_size, const uint16_t iv_size,
5979 			const uint16_t tag_size)
5980 {
5981 	struct rte_cryptodev_sym_capability_idx cap_idx;
5982 	const struct rte_cryptodev_symmetric_capability *cap;
5983 
5984 	/* Check if device supports the algorithm */
5985 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5986 	cap_idx.algo.auth = auth_algo;
5987 
5988 	cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5989 			&cap_idx);
5990 
5991 	if (cap == NULL)
5992 		return -1;
5993 
5994 	/* Check if device supports key size and IV size */
5995 	if (rte_cryptodev_sym_capability_check_auth(cap, key_size,
5996 			tag_size, iv_size) < 0) {
5997 		return -1;
5998 	}
5999 
6000 	return 0;
6001 }
6002 
6003 static int
6004 test_zuc_cipher(const struct wireless_test_data *tdata,
6005 		enum rte_crypto_cipher_operation direction)
6006 {
6007 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6008 	struct crypto_unittest_params *ut_params = &unittest_params;
6009 
6010 	int retval;
6011 	uint8_t *plaintext = NULL;
6012 	uint8_t *ciphertext = NULL;
6013 	unsigned int plaintext_pad_len, ciphertext_pad_len;
6014 	unsigned int plaintext_len = 0;
6015 	unsigned int ciphertext_len = 0;
6016 	struct rte_cryptodev_info dev_info;
6017 
6018 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6019 	uint64_t feat_flags = dev_info.feature_flags;
6020 
6021 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6022 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6023 		printf("Device doesn't support RAW data-path APIs.\n");
6024 		return TEST_SKIPPED;
6025 	}
6026 
6027 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6028 		return TEST_SKIPPED;
6029 
6030 	/* Check if device supports ZUC EEA3 */
6031 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6032 			tdata->key.len, tdata->cipher_iv.len) < 0)
6033 		return TEST_SKIPPED;
6034 
6035 	/* Create ZUC session */
6036 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
6037 					direction,
6038 					RTE_CRYPTO_CIPHER_ZUC_EEA3,
6039 					tdata->key.data, tdata->key.len,
6040 					tdata->cipher_iv.len);
6041 	if (retval != 0)
6042 		return retval;
6043 
6044 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6045 
6046 	/* Clear mbuf payload */
6047 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6048 	       rte_pktmbuf_tailroom(ut_params->ibuf));
6049 
6050 	if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
6051 		plaintext_len = ceil_byte_length(tdata->plaintext.len);
6052 		/* Append data which is padded to a multiple */
6053 		/* of the algorithms block size */
6054 		plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6055 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6056 				plaintext_pad_len);
6057 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6058 
6059 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
6060 	} else {
6061 		ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6062 		/* Append data which is padded to a multiple */
6063 		/* of the algorithms block size */
6064 		ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
6065 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6066 				ciphertext_pad_len);
6067 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6068 
6069 		debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
6070 	}
6071 
6072 	/* Create ZUC operation */
6073 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
6074 					tdata->cipher_iv.len,
6075 					tdata->plaintext.len,
6076 					tdata->validCipherOffsetInBits.len);
6077 	if (retval < 0)
6078 		return retval;
6079 
6080 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
6081 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
6082 					       tdata->cipher_iv.len);
6083 		if (retval != TEST_SUCCESS)
6084 			return retval;
6085 	} else
6086 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6087 						ut_params->op);
6088 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6089 
6090 	ut_params->obuf = ut_params->op->sym->m_dst;
6091 
6092 	if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
6093 		if (ut_params->obuf)
6094 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
6095 		else
6096 			ciphertext = plaintext;
6097 
6098 		debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6099 
6100 		/* Validate obuf */
6101 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6102 				ciphertext,
6103 				tdata->ciphertext.data,
6104 				tdata->validCipherLenInBits.len,
6105 				"ZUC Ciphertext data not as expected");
6106 	} else {
6107 		if (ut_params->obuf)
6108 			plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
6109 		else
6110 			plaintext = ciphertext;
6111 
6112 		debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
6113 
6114 		const uint8_t *reference_plaintext = tdata->plaintext.data +
6115 				(tdata->validCipherOffsetInBits.len >> 3);
6116 
6117 		/* Validate obuf */
6118 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6119 				plaintext,
6120 				reference_plaintext,
6121 				tdata->validCipherLenInBits.len,
6122 				"ZUC Plaintext data not as expected");
6123 	}
6124 
6125 	return 0;
6126 }
6127 
6128 static int
6129 test_zuc_cipher_sgl(const struct wireless_test_data *tdata,
6130 		enum rte_crypto_cipher_operation direction)
6131 {
6132 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6133 	struct crypto_unittest_params *ut_params = &unittest_params;
6134 
6135 	int retval;
6136 
6137 	unsigned int plaintext_pad_len, ciphertext_pad_len;
6138 	unsigned int plaintext_len = 0;
6139 	unsigned int ciphertext_len = 0;
6140 	const uint8_t *ciphertext, *plaintext;
6141 	uint8_t buffer[2048];
6142 	struct rte_cryptodev_info dev_info;
6143 
6144 	/* Check if device supports ZUC EEA3 */
6145 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6146 			tdata->key.len, tdata->cipher_iv.len) < 0)
6147 		return TEST_SKIPPED;
6148 
6149 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6150 		return TEST_SKIPPED;
6151 
6152 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6153 
6154 	uint64_t feat_flags = dev_info.feature_flags;
6155 
6156 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6157 		printf("Device doesn't support in-place scatter-gather. "
6158 				"Test Skipped.\n");
6159 		return TEST_SKIPPED;
6160 	}
6161 
6162 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6163 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6164 		printf("Device doesn't support RAW data-path APIs.\n");
6165 		return TEST_SKIPPED;
6166 	}
6167 
6168 	if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
6169 		plaintext_len = ceil_byte_length(tdata->plaintext.len);
6170 
6171 		/* Append data which is padded to a multiple */
6172 		/* of the algorithms block size */
6173 		plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6174 
6175 		ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6176 				plaintext_pad_len, 10, 0);
6177 
6178 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6179 				tdata->plaintext.data);
6180 	} else {
6181 		ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6182 
6183 		/* Append data which is padded to a multiple */
6184 		/* of the algorithms block size */
6185 		ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
6186 
6187 		ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6188 				ciphertext_pad_len, 10, 0);
6189 
6190 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6191 				tdata->ciphertext.data);
6192 
6193 	}
6194 
6195 	/* Create ZUC session */
6196 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
6197 			direction,
6198 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6199 			tdata->key.data, tdata->key.len,
6200 			tdata->cipher_iv.len);
6201 	if (retval < 0)
6202 		return retval;
6203 
6204 	/* Clear mbuf payload */
6205 	if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
6206 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
6207 	else
6208 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, tdata->ciphertext.data);
6209 
6210 	/* Create ZUC operation */
6211 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
6212 			tdata->cipher_iv.len, tdata->plaintext.len,
6213 			tdata->validCipherOffsetInBits.len);
6214 	if (retval < 0)
6215 		return retval;
6216 
6217 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
6218 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
6219 					       tdata->cipher_iv.len);
6220 		if (retval != TEST_SUCCESS)
6221 			return retval;
6222 	} else
6223 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6224 						ut_params->op);
6225 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6226 
6227 	ut_params->obuf = ut_params->op->sym->m_dst;
6228 
6229 	if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
6230 		if (ut_params->obuf)
6231 			ciphertext = rte_pktmbuf_read(ut_params->obuf,
6232 				0, plaintext_len, buffer);
6233 		else
6234 			ciphertext = rte_pktmbuf_read(ut_params->ibuf,
6235 				0, plaintext_len, buffer);
6236 
6237 		/* Validate obuf */
6238 		debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6239 
6240 		/* Validate obuf */
6241 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6242 			ciphertext,
6243 			tdata->ciphertext.data,
6244 			tdata->validCipherLenInBits.len,
6245 			"ZUC Ciphertext data not as expected");
6246 	} else {
6247 		if (ut_params->obuf)
6248 			plaintext = rte_pktmbuf_read(ut_params->obuf,
6249 				0, ciphertext_len, buffer);
6250 		else
6251 			plaintext = rte_pktmbuf_read(ut_params->ibuf,
6252 				0, ciphertext_len, buffer);
6253 
6254 		/* Validate obuf */
6255 		debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
6256 
6257 		/* Validate obuf */
6258 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6259 			plaintext,
6260 			tdata->plaintext.data,
6261 			tdata->validCipherLenInBits.len,
6262 			"ZUC Plaintext data not as expected");
6263 		}
6264 
6265 	return 0;
6266 }
6267 
6268 static int
6269 test_zuc_authentication(const struct wireless_test_data *tdata,
6270 		enum rte_crypto_auth_operation auth_op)
6271 {
6272 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6273 	struct crypto_unittest_params *ut_params = &unittest_params;
6274 
6275 	int retval;
6276 	unsigned plaintext_pad_len;
6277 	unsigned plaintext_len;
6278 	uint8_t *plaintext;
6279 
6280 	struct rte_cryptodev_info dev_info;
6281 
6282 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6283 	uint64_t feat_flags = dev_info.feature_flags;
6284 
6285 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
6286 			(tdata->validAuthLenInBits.len % 8 != 0)) {
6287 		printf("Device doesn't support NON-Byte Aligned Data.\n");
6288 		return TEST_SKIPPED;
6289 	}
6290 
6291 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6292 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6293 		printf("Device doesn't support RAW data-path APIs.\n");
6294 		return TEST_SKIPPED;
6295 	}
6296 
6297 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6298 		return TEST_SKIPPED;
6299 
6300 	/* Check if device supports ZUC EIA3 */
6301 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6302 			tdata->key.len, tdata->auth_iv.len,
6303 			tdata->digest.len) < 0)
6304 		return TEST_SKIPPED;
6305 
6306 	/* Create ZUC session */
6307 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
6308 			tdata->key.data, tdata->key.len,
6309 			tdata->auth_iv.len, tdata->digest.len,
6310 			auth_op, RTE_CRYPTO_AUTH_ZUC_EIA3);
6311 	if (retval != 0)
6312 		return retval;
6313 
6314 	/* alloc mbuf and set payload */
6315 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6316 
6317 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6318 	rte_pktmbuf_tailroom(ut_params->ibuf));
6319 
6320 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6321 	/* Append data which is padded to a multiple of */
6322 	/* the algorithms block size */
6323 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6324 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6325 				plaintext_pad_len);
6326 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6327 
6328 	/* Create ZUC operation */
6329 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
6330 			tdata->digest.len,
6331 			tdata->auth_iv.data, tdata->auth_iv.len,
6332 			plaintext_pad_len,
6333 			auth_op, tdata->validAuthLenInBits.len, 0);
6334 	if (retval < 0)
6335 		return retval;
6336 
6337 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
6338 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1,
6339 					       0);
6340 		if (retval != TEST_SUCCESS)
6341 			return retval;
6342 	} else
6343 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6344 				ut_params->op);
6345 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6346 	ut_params->obuf = ut_params->op->sym->m_src;
6347 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6348 			+ plaintext_pad_len;
6349 
6350 	if (auth_op != RTE_CRYPTO_AUTH_OP_VERIFY) {
6351 		/* Validate obuf */
6352 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6353 				ut_params->digest,
6354 				tdata->digest.data,
6355 				tdata->digest.len,
6356 				"ZUC Generated auth tag not as expected");
6357 		return 0;
6358 	}
6359 
6360 	/* Validate obuf */
6361 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
6362 		return 0;
6363 	else
6364 		return -1;
6365 
6366 	return 0;
6367 }
6368 
6369 static int
6370 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
6371 	uint8_t op_mode, uint8_t verify)
6372 {
6373 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6374 	struct crypto_unittest_params *ut_params = &unittest_params;
6375 
6376 	int retval;
6377 
6378 	uint8_t *plaintext = NULL, *ciphertext = NULL;
6379 	unsigned int plaintext_pad_len;
6380 	unsigned int plaintext_len;
6381 	unsigned int ciphertext_pad_len;
6382 	unsigned int ciphertext_len;
6383 
6384 	struct rte_cryptodev_info dev_info;
6385 
6386 	/* Check if device supports ZUC EEA3 */
6387 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6388 			tdata->key.len, tdata->cipher_iv.len) < 0)
6389 		return TEST_SKIPPED;
6390 
6391 	/* Check if device supports ZUC EIA3 */
6392 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6393 			tdata->key.len, tdata->auth_iv.len,
6394 			tdata->digest.len) < 0)
6395 		return TEST_SKIPPED;
6396 
6397 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6398 		return TEST_SKIPPED;
6399 
6400 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6401 
6402 	uint64_t feat_flags = dev_info.feature_flags;
6403 
6404 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6405 		printf("Device doesn't support digest encrypted.\n");
6406 		return TEST_SKIPPED;
6407 	}
6408 	if (op_mode == IN_PLACE) {
6409 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6410 			printf("Device doesn't support in-place scatter-gather "
6411 					"in both input and output mbufs.\n");
6412 			return TEST_SKIPPED;
6413 		}
6414 
6415 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6416 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6417 			printf("Device doesn't support RAW data-path APIs.\n");
6418 			return TEST_SKIPPED;
6419 		}
6420 	} else {
6421 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6422 			return TEST_SKIPPED;
6423 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6424 			printf("Device doesn't support out-of-place scatter-gather "
6425 					"in both input and output mbufs.\n");
6426 			return TEST_SKIPPED;
6427 		}
6428 	}
6429 
6430 	/* Create ZUC session */
6431 	retval = create_wireless_algo_auth_cipher_session(
6432 			ts_params->valid_devs[0],
6433 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6434 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6435 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6436 					: RTE_CRYPTO_AUTH_OP_GENERATE),
6437 			RTE_CRYPTO_AUTH_ZUC_EIA3,
6438 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6439 			tdata->key.data, tdata->key.len,
6440 			tdata->key.data, tdata->key.len,
6441 			tdata->auth_iv.len, tdata->digest.len,
6442 			tdata->cipher_iv.len);
6443 
6444 	if (retval != 0)
6445 		return retval;
6446 
6447 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6448 	if (op_mode == OUT_OF_PLACE)
6449 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6450 
6451 	/* clear mbuf payload */
6452 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6453 		rte_pktmbuf_tailroom(ut_params->ibuf));
6454 	if (op_mode == OUT_OF_PLACE)
6455 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6456 			rte_pktmbuf_tailroom(ut_params->obuf));
6457 
6458 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6459 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6460 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6461 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6462 
6463 	if (verify) {
6464 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6465 					ciphertext_pad_len);
6466 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6467 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6468 			ciphertext_len);
6469 	} else {
6470 		/* make sure enough space to cover partial digest verify case */
6471 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6472 					ciphertext_pad_len);
6473 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6474 		debug_hexdump(stdout, "plaintext:", plaintext,
6475 			plaintext_len);
6476 	}
6477 
6478 	if (op_mode == OUT_OF_PLACE)
6479 		rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6480 
6481 	/* Create ZUC operation */
6482 	retval = create_wireless_algo_auth_cipher_operation(
6483 		tdata->digest.data, tdata->digest.len,
6484 		tdata->cipher_iv.data, tdata->cipher_iv.len,
6485 		tdata->auth_iv.data, tdata->auth_iv.len,
6486 		(tdata->digest.offset_bytes == 0 ?
6487 		(verify ? ciphertext_pad_len : plaintext_pad_len)
6488 			: tdata->digest.offset_bytes),
6489 		tdata->validCipherLenInBits.len,
6490 		tdata->validCipherOffsetInBits.len,
6491 		tdata->validAuthLenInBits.len,
6492 		0,
6493 		op_mode, 0, verify);
6494 
6495 	if (retval < 0)
6496 		return retval;
6497 
6498 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
6499 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1,
6500 					       tdata->cipher_iv.len);
6501 		if (retval != TEST_SUCCESS)
6502 			return retval;
6503 	} else
6504 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6505 			ut_params->op);
6506 
6507 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6508 
6509 	ut_params->obuf = (op_mode == IN_PLACE ?
6510 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6511 
6512 
6513 	if (verify) {
6514 		if (ut_params->obuf)
6515 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6516 							uint8_t *);
6517 		else
6518 			plaintext = ciphertext;
6519 
6520 		debug_hexdump(stdout, "plaintext:", plaintext,
6521 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6522 		debug_hexdump(stdout, "plaintext expected:",
6523 			tdata->plaintext.data,
6524 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6525 	} else {
6526 		if (ut_params->obuf)
6527 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6528 							uint8_t *);
6529 		else
6530 			ciphertext = plaintext;
6531 
6532 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6533 			ciphertext_len);
6534 		debug_hexdump(stdout, "ciphertext expected:",
6535 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6536 
6537 		ut_params->digest = rte_pktmbuf_mtod(
6538 			ut_params->obuf, uint8_t *) +
6539 			(tdata->digest.offset_bytes == 0 ?
6540 			plaintext_pad_len : tdata->digest.offset_bytes);
6541 
6542 		debug_hexdump(stdout, "digest:", ut_params->digest,
6543 			tdata->digest.len);
6544 		debug_hexdump(stdout, "digest expected:",
6545 			tdata->digest.data, tdata->digest.len);
6546 	}
6547 
6548 	/* Validate obuf */
6549 	if (verify) {
6550 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6551 			plaintext,
6552 			tdata->plaintext.data,
6553 			tdata->plaintext.len >> 3,
6554 			"ZUC Plaintext data not as expected");
6555 	} else {
6556 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6557 			ciphertext,
6558 			tdata->ciphertext.data,
6559 			tdata->ciphertext.len >> 3,
6560 			"ZUC Ciphertext data not as expected");
6561 
6562 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6563 			ut_params->digest,
6564 			tdata->digest.data,
6565 			tdata->digest.len,
6566 			"ZUC Generated auth tag not as expected");
6567 	}
6568 	return 0;
6569 }
6570 
6571 static int
6572 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
6573 	uint8_t op_mode, uint8_t verify)
6574 {
6575 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6576 	struct crypto_unittest_params *ut_params = &unittest_params;
6577 
6578 	int retval;
6579 
6580 	const uint8_t *plaintext = NULL;
6581 	const uint8_t *ciphertext = NULL;
6582 	const uint8_t *digest = NULL;
6583 	unsigned int plaintext_pad_len;
6584 	unsigned int plaintext_len;
6585 	unsigned int ciphertext_pad_len;
6586 	unsigned int ciphertext_len;
6587 	uint8_t buffer[10000];
6588 	uint8_t digest_buffer[10000];
6589 
6590 	struct rte_cryptodev_info dev_info;
6591 
6592 	/* Check if device supports ZUC EEA3 */
6593 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6594 			tdata->key.len, tdata->cipher_iv.len) < 0)
6595 		return TEST_SKIPPED;
6596 
6597 	/* Check if device supports ZUC EIA3 */
6598 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6599 			tdata->key.len, tdata->auth_iv.len,
6600 			tdata->digest.len) < 0)
6601 		return TEST_SKIPPED;
6602 
6603 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6604 		return TEST_SKIPPED;
6605 
6606 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6607 
6608 	uint64_t feat_flags = dev_info.feature_flags;
6609 
6610 	if (op_mode == IN_PLACE) {
6611 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6612 			printf("Device doesn't support in-place scatter-gather "
6613 					"in both input and output mbufs.\n");
6614 			return TEST_SKIPPED;
6615 		}
6616 
6617 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6618 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6619 			printf("Device doesn't support RAW data-path APIs.\n");
6620 			return TEST_SKIPPED;
6621 		}
6622 	} else {
6623 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6624 			return TEST_SKIPPED;
6625 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6626 			printf("Device doesn't support out-of-place scatter-gather "
6627 					"in both input and output mbufs.\n");
6628 			return TEST_SKIPPED;
6629 		}
6630 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6631 			printf("Device doesn't support digest encrypted.\n");
6632 			return TEST_SKIPPED;
6633 		}
6634 	}
6635 
6636 	/* Create ZUC session */
6637 	retval = create_wireless_algo_auth_cipher_session(
6638 			ts_params->valid_devs[0],
6639 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6640 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6641 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6642 					: RTE_CRYPTO_AUTH_OP_GENERATE),
6643 			RTE_CRYPTO_AUTH_ZUC_EIA3,
6644 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6645 			tdata->key.data, tdata->key.len,
6646 			tdata->key.data, tdata->key.len,
6647 			tdata->auth_iv.len, tdata->digest.len,
6648 			tdata->cipher_iv.len);
6649 
6650 	if (retval != 0)
6651 		return retval;
6652 
6653 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6654 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6655 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6656 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6657 
6658 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6659 			plaintext_pad_len, 15, 0);
6660 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6661 			"Failed to allocate input buffer in mempool");
6662 
6663 	if (op_mode == OUT_OF_PLACE) {
6664 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6665 				plaintext_pad_len, 15, 0);
6666 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
6667 				"Failed to allocate output buffer in mempool");
6668 	}
6669 
6670 	if (verify) {
6671 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6672 			tdata->ciphertext.data);
6673 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6674 					ciphertext_len, buffer);
6675 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6676 			ciphertext_len);
6677 	} else {
6678 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6679 			tdata->plaintext.data);
6680 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6681 					plaintext_len, buffer);
6682 		debug_hexdump(stdout, "plaintext:", plaintext,
6683 			plaintext_len);
6684 	}
6685 	memset(buffer, 0, sizeof(buffer));
6686 
6687 	/* Create ZUC operation */
6688 	retval = create_wireless_algo_auth_cipher_operation(
6689 		tdata->digest.data, tdata->digest.len,
6690 		tdata->cipher_iv.data, tdata->cipher_iv.len,
6691 		tdata->auth_iv.data, tdata->auth_iv.len,
6692 		(tdata->digest.offset_bytes == 0 ?
6693 		(verify ? ciphertext_pad_len : plaintext_pad_len)
6694 			: tdata->digest.offset_bytes),
6695 		tdata->validCipherLenInBits.len,
6696 		tdata->validCipherOffsetInBits.len,
6697 		tdata->validAuthLenInBits.len,
6698 		0,
6699 		op_mode, 1, verify);
6700 
6701 	if (retval < 0)
6702 		return retval;
6703 
6704 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
6705 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1,
6706 					       tdata->cipher_iv.len);
6707 		if (retval != TEST_SUCCESS)
6708 			return retval;
6709 	} else
6710 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6711 			ut_params->op);
6712 
6713 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6714 
6715 	ut_params->obuf = (op_mode == IN_PLACE ?
6716 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6717 
6718 	if (verify) {
6719 		if (ut_params->obuf)
6720 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6721 					plaintext_len, buffer);
6722 		else
6723 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6724 					plaintext_len, buffer);
6725 
6726 		debug_hexdump(stdout, "plaintext:", plaintext,
6727 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6728 		debug_hexdump(stdout, "plaintext expected:",
6729 			tdata->plaintext.data,
6730 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6731 	} else {
6732 		if (ut_params->obuf)
6733 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6734 					ciphertext_len, buffer);
6735 		else
6736 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6737 					ciphertext_len, buffer);
6738 
6739 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6740 			ciphertext_len);
6741 		debug_hexdump(stdout, "ciphertext expected:",
6742 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6743 
6744 		if (ut_params->obuf)
6745 			digest = rte_pktmbuf_read(ut_params->obuf,
6746 				(tdata->digest.offset_bytes == 0 ?
6747 				plaintext_pad_len : tdata->digest.offset_bytes),
6748 				tdata->digest.len, digest_buffer);
6749 		else
6750 			digest = rte_pktmbuf_read(ut_params->ibuf,
6751 				(tdata->digest.offset_bytes == 0 ?
6752 				plaintext_pad_len : tdata->digest.offset_bytes),
6753 				tdata->digest.len, digest_buffer);
6754 
6755 		debug_hexdump(stdout, "digest:", digest,
6756 			tdata->digest.len);
6757 		debug_hexdump(stdout, "digest expected:",
6758 			tdata->digest.data, tdata->digest.len);
6759 	}
6760 
6761 	/* Validate obuf */
6762 	if (verify) {
6763 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6764 			plaintext,
6765 			tdata->plaintext.data,
6766 			tdata->plaintext.len >> 3,
6767 			"ZUC Plaintext data not as expected");
6768 	} else {
6769 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6770 			ciphertext,
6771 			tdata->ciphertext.data,
6772 			tdata->validDataLenInBits.len,
6773 			"ZUC Ciphertext data not as expected");
6774 
6775 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6776 			digest,
6777 			tdata->digest.data,
6778 			tdata->digest.len,
6779 			"ZUC Generated auth tag not as expected");
6780 	}
6781 	return 0;
6782 }
6783 
6784 static int
6785 test_kasumi_encryption_test_case_1(void)
6786 {
6787 	return test_kasumi_encryption(&kasumi_test_case_1);
6788 }
6789 
6790 static int
6791 test_kasumi_encryption_test_case_1_sgl(void)
6792 {
6793 	return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6794 }
6795 
6796 static int
6797 test_kasumi_encryption_test_case_1_oop(void)
6798 {
6799 	return test_kasumi_encryption_oop(&kasumi_test_case_1);
6800 }
6801 
6802 static int
6803 test_kasumi_encryption_test_case_1_oop_sgl(void)
6804 {
6805 	return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6806 }
6807 
6808 static int
6809 test_kasumi_encryption_test_case_2(void)
6810 {
6811 	return test_kasumi_encryption(&kasumi_test_case_2);
6812 }
6813 
6814 static int
6815 test_kasumi_encryption_test_case_3(void)
6816 {
6817 	return test_kasumi_encryption(&kasumi_test_case_3);
6818 }
6819 
6820 static int
6821 test_kasumi_encryption_test_case_4(void)
6822 {
6823 	return test_kasumi_encryption(&kasumi_test_case_4);
6824 }
6825 
6826 static int
6827 test_kasumi_encryption_test_case_5(void)
6828 {
6829 	return test_kasumi_encryption(&kasumi_test_case_5);
6830 }
6831 
6832 static int
6833 test_kasumi_decryption_test_case_1(void)
6834 {
6835 	return test_kasumi_decryption(&kasumi_test_case_1);
6836 }
6837 
6838 static int
6839 test_kasumi_decryption_test_case_1_oop(void)
6840 {
6841 	return test_kasumi_decryption_oop(&kasumi_test_case_1);
6842 }
6843 
6844 static int
6845 test_kasumi_decryption_test_case_2(void)
6846 {
6847 	return test_kasumi_decryption(&kasumi_test_case_2);
6848 }
6849 
6850 static int
6851 test_kasumi_decryption_test_case_3(void)
6852 {
6853 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6854 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6855 		return TEST_SKIPPED;
6856 	return test_kasumi_decryption(&kasumi_test_case_3);
6857 }
6858 
6859 static int
6860 test_kasumi_decryption_test_case_4(void)
6861 {
6862 	return test_kasumi_decryption(&kasumi_test_case_4);
6863 }
6864 
6865 static int
6866 test_kasumi_decryption_test_case_5(void)
6867 {
6868 	return test_kasumi_decryption(&kasumi_test_case_5);
6869 }
6870 static int
6871 test_snow3g_encryption_test_case_1(void)
6872 {
6873 	return test_snow3g_encryption(&snow3g_test_case_1);
6874 }
6875 
6876 static int
6877 test_snow3g_encryption_test_case_1_oop(void)
6878 {
6879 	return test_snow3g_encryption_oop(&snow3g_test_case_1);
6880 }
6881 
6882 static int
6883 test_snow3g_encryption_test_case_1_oop_sgl(void)
6884 {
6885 	return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 1, 1);
6886 }
6887 
6888 static int
6889 test_snow3g_encryption_test_case_1_oop_lb_in_sgl_out(void)
6890 {
6891 	return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 0, 1);
6892 }
6893 
6894 static int
6895 test_snow3g_encryption_test_case_1_oop_sgl_in_lb_out(void)
6896 {
6897 	return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 1, 0);
6898 }
6899 
6900 static int
6901 test_snow3g_encryption_test_case_1_offset_oop(void)
6902 {
6903 	return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6904 }
6905 
6906 static int
6907 test_snow3g_encryption_test_case_2(void)
6908 {
6909 	return test_snow3g_encryption(&snow3g_test_case_2);
6910 }
6911 
6912 static int
6913 test_snow3g_encryption_test_case_3(void)
6914 {
6915 	return test_snow3g_encryption(&snow3g_test_case_3);
6916 }
6917 
6918 static int
6919 test_snow3g_encryption_test_case_4(void)
6920 {
6921 	return test_snow3g_encryption(&snow3g_test_case_4);
6922 }
6923 
6924 static int
6925 test_snow3g_encryption_test_case_5(void)
6926 {
6927 	return test_snow3g_encryption(&snow3g_test_case_5);
6928 }
6929 
6930 static int
6931 test_snow3g_decryption_test_case_1(void)
6932 {
6933 	return test_snow3g_decryption(&snow3g_test_case_1);
6934 }
6935 
6936 static int
6937 test_snow3g_decryption_test_case_1_oop(void)
6938 {
6939 	return test_snow3g_decryption_oop(&snow3g_test_case_1);
6940 }
6941 
6942 static int
6943 test_snow3g_decryption_test_case_2(void)
6944 {
6945 	return test_snow3g_decryption(&snow3g_test_case_2);
6946 }
6947 
6948 static int
6949 test_snow3g_decryption_test_case_3(void)
6950 {
6951 	return test_snow3g_decryption(&snow3g_test_case_3);
6952 }
6953 
6954 static int
6955 test_snow3g_decryption_test_case_4(void)
6956 {
6957 	return test_snow3g_decryption(&snow3g_test_case_4);
6958 }
6959 
6960 static int
6961 test_snow3g_decryption_test_case_5(void)
6962 {
6963 	return test_snow3g_decryption(&snow3g_test_case_5);
6964 }
6965 
6966 /*
6967  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6968  * Pattern digest from snow3g_test_data must be allocated as
6969  * 4 last bytes in plaintext.
6970  */
6971 static void
6972 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6973 		struct snow3g_hash_test_data *output)
6974 {
6975 	if ((pattern != NULL) && (output != NULL)) {
6976 		output->key.len = pattern->key.len;
6977 
6978 		memcpy(output->key.data,
6979 		pattern->key.data, pattern->key.len);
6980 
6981 		output->auth_iv.len = pattern->auth_iv.len;
6982 
6983 		memcpy(output->auth_iv.data,
6984 		pattern->auth_iv.data, pattern->auth_iv.len);
6985 
6986 		output->plaintext.len = pattern->plaintext.len;
6987 
6988 		memcpy(output->plaintext.data,
6989 		pattern->plaintext.data, pattern->plaintext.len >> 3);
6990 
6991 		output->digest.len = pattern->digest.len;
6992 
6993 		memcpy(output->digest.data,
6994 		&pattern->plaintext.data[pattern->digest.offset_bytes],
6995 		pattern->digest.len);
6996 
6997 		output->validAuthLenInBits.len =
6998 		pattern->validAuthLenInBits.len;
6999 	}
7000 }
7001 
7002 /*
7003  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
7004  */
7005 static int
7006 test_snow3g_decryption_with_digest_test_case_1(void)
7007 {
7008 	int ret;
7009 	struct snow3g_hash_test_data snow3g_hash_data;
7010 	struct rte_cryptodev_info dev_info;
7011 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7012 
7013 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7014 	uint64_t feat_flags = dev_info.feature_flags;
7015 
7016 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7017 		printf("Device doesn't support encrypted digest operations.\n");
7018 		return TEST_SKIPPED;
7019 	}
7020 
7021 	/*
7022 	 * Function prepare data for hash verification test case.
7023 	 * Digest is allocated in 4 last bytes in plaintext, pattern.
7024 	 */
7025 	snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
7026 
7027 	ret = test_snow3g_decryption(&snow3g_test_case_7);
7028 	if (ret != 0)
7029 		return ret;
7030 
7031 	return test_snow3g_authentication_verify(&snow3g_hash_data);
7032 }
7033 
7034 static int
7035 test_snow3g_cipher_auth_test_case_1(void)
7036 {
7037 	return test_snow3g_cipher_auth(&snow3g_test_case_3);
7038 }
7039 
7040 static int
7041 test_snow3g_auth_cipher_test_case_1(void)
7042 {
7043 	return test_snow3g_auth_cipher(
7044 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
7045 }
7046 
7047 static int
7048 test_snow3g_auth_cipher_test_case_2(void)
7049 {
7050 	return test_snow3g_auth_cipher(
7051 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
7052 }
7053 
7054 static int
7055 test_snow3g_auth_cipher_test_case_2_oop(void)
7056 {
7057 	return test_snow3g_auth_cipher(
7058 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7059 }
7060 
7061 static int
7062 test_snow3g_auth_cipher_part_digest_enc(void)
7063 {
7064 	return test_snow3g_auth_cipher(
7065 		&snow3g_auth_cipher_partial_digest_encryption,
7066 			IN_PLACE, 0);
7067 }
7068 
7069 static int
7070 test_snow3g_auth_cipher_part_digest_enc_oop(void)
7071 {
7072 	return test_snow3g_auth_cipher(
7073 		&snow3g_auth_cipher_partial_digest_encryption,
7074 			OUT_OF_PLACE, 0);
7075 }
7076 
7077 static int
7078 test_snow3g_auth_cipher_test_case_3_sgl(void)
7079 {
7080 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
7081 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7082 		return TEST_SKIPPED;
7083 	return test_snow3g_auth_cipher_sgl(
7084 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
7085 }
7086 
7087 static int
7088 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
7089 {
7090 	return test_snow3g_auth_cipher_sgl(
7091 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
7092 }
7093 
7094 static int
7095 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
7096 {
7097 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
7098 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7099 		return TEST_SKIPPED;
7100 	return test_snow3g_auth_cipher_sgl(
7101 		&snow3g_auth_cipher_partial_digest_encryption,
7102 			IN_PLACE, 0);
7103 }
7104 
7105 static int
7106 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
7107 {
7108 	return test_snow3g_auth_cipher_sgl(
7109 		&snow3g_auth_cipher_partial_digest_encryption,
7110 			OUT_OF_PLACE, 0);
7111 }
7112 
7113 static int
7114 test_snow3g_auth_cipher_total_digest_enc_1(void)
7115 {
7116 	return test_snow3g_auth_cipher(
7117 		&snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 0);
7118 }
7119 
7120 static int
7121 test_snow3g_auth_cipher_total_digest_enc_1_oop(void)
7122 {
7123 	return test_snow3g_auth_cipher(
7124 		&snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 0);
7125 }
7126 
7127 static int
7128 test_snow3g_auth_cipher_total_digest_enc_1_sgl(void)
7129 {
7130 	return test_snow3g_auth_cipher_sgl(
7131 		&snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 0);
7132 }
7133 
7134 static int
7135 test_snow3g_auth_cipher_total_digest_enc_1_oop_sgl(void)
7136 {
7137 	return test_snow3g_auth_cipher_sgl(
7138 		&snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 0);
7139 }
7140 
7141 static int
7142 test_snow3g_auth_cipher_verify_test_case_1(void)
7143 {
7144 	return test_snow3g_auth_cipher(
7145 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
7146 }
7147 
7148 static int
7149 test_snow3g_auth_cipher_verify_test_case_2(void)
7150 {
7151 	return test_snow3g_auth_cipher(
7152 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
7153 }
7154 
7155 static int
7156 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
7157 {
7158 	return test_snow3g_auth_cipher(
7159 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7160 }
7161 
7162 static int
7163 test_snow3g_auth_cipher_verify_part_digest_enc(void)
7164 {
7165 	return test_snow3g_auth_cipher(
7166 		&snow3g_auth_cipher_partial_digest_encryption,
7167 			IN_PLACE, 1);
7168 }
7169 
7170 static int
7171 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
7172 {
7173 	return test_snow3g_auth_cipher(
7174 		&snow3g_auth_cipher_partial_digest_encryption,
7175 			OUT_OF_PLACE, 1);
7176 }
7177 
7178 static int
7179 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
7180 {
7181 	return test_snow3g_auth_cipher_sgl(
7182 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
7183 }
7184 
7185 static int
7186 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
7187 {
7188 	return test_snow3g_auth_cipher_sgl(
7189 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
7190 }
7191 
7192 static int
7193 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
7194 {
7195 	return test_snow3g_auth_cipher_sgl(
7196 		&snow3g_auth_cipher_partial_digest_encryption,
7197 			IN_PLACE, 1);
7198 }
7199 
7200 static int
7201 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
7202 {
7203 	return test_snow3g_auth_cipher_sgl(
7204 		&snow3g_auth_cipher_partial_digest_encryption,
7205 			OUT_OF_PLACE, 1);
7206 }
7207 
7208 static int
7209 test_snow3g_auth_cipher_verify_total_digest_enc_1(void)
7210 {
7211 	return test_snow3g_auth_cipher(
7212 		&snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 1);
7213 }
7214 
7215 static int
7216 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop(void)
7217 {
7218 	return test_snow3g_auth_cipher(
7219 		&snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 1);
7220 }
7221 
7222 static int
7223 test_snow3g_auth_cipher_verify_total_digest_enc_1_sgl(void)
7224 {
7225 	return test_snow3g_auth_cipher_sgl(
7226 		&snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 1);
7227 }
7228 
7229 static int
7230 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop_sgl(void)
7231 {
7232 	return test_snow3g_auth_cipher_sgl(
7233 		&snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 1);
7234 }
7235 
7236 static int
7237 test_snow3g_auth_cipher_with_digest_test_case_1(void)
7238 {
7239 	return test_snow3g_auth_cipher(
7240 		&snow3g_test_case_7, IN_PLACE, 0);
7241 }
7242 
7243 static int
7244 test_kasumi_auth_cipher_test_case_1(void)
7245 {
7246 	return test_kasumi_auth_cipher(
7247 		&kasumi_test_case_3, IN_PLACE, 0);
7248 }
7249 
7250 static int
7251 test_kasumi_auth_cipher_test_case_2(void)
7252 {
7253 	return test_kasumi_auth_cipher(
7254 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
7255 }
7256 
7257 static int
7258 test_kasumi_auth_cipher_test_case_2_oop(void)
7259 {
7260 	return test_kasumi_auth_cipher(
7261 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7262 }
7263 
7264 static int
7265 test_kasumi_auth_cipher_test_case_2_sgl(void)
7266 {
7267 	return test_kasumi_auth_cipher_sgl(
7268 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
7269 }
7270 
7271 static int
7272 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
7273 {
7274 	return test_kasumi_auth_cipher_sgl(
7275 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7276 }
7277 
7278 static int
7279 test_kasumi_auth_cipher_verify_test_case_1(void)
7280 {
7281 	return test_kasumi_auth_cipher(
7282 		&kasumi_test_case_3, IN_PLACE, 1);
7283 }
7284 
7285 static int
7286 test_kasumi_auth_cipher_verify_test_case_2(void)
7287 {
7288 	return test_kasumi_auth_cipher(
7289 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
7290 }
7291 
7292 static int
7293 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
7294 {
7295 	return test_kasumi_auth_cipher(
7296 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7297 }
7298 
7299 static int
7300 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
7301 {
7302 	return test_kasumi_auth_cipher_sgl(
7303 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
7304 }
7305 
7306 static int
7307 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
7308 {
7309 	return test_kasumi_auth_cipher_sgl(
7310 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7311 }
7312 
7313 static int
7314 test_kasumi_cipher_auth_test_case_1(void)
7315 {
7316 	return test_kasumi_cipher_auth(&kasumi_test_case_6);
7317 }
7318 
7319 static int
7320 test_zuc_encryption_test_case_1(void)
7321 {
7322 	return test_zuc_cipher(&zuc_test_case_cipher_193b,
7323 			RTE_CRYPTO_CIPHER_OP_ENCRYPT);
7324 }
7325 
7326 static int
7327 test_zuc_encryption_test_case_2(void)
7328 {
7329 	return test_zuc_cipher(&zuc_test_case_cipher_800b,
7330 			RTE_CRYPTO_CIPHER_OP_ENCRYPT);
7331 }
7332 
7333 static int
7334 test_zuc_encryption_test_case_3(void)
7335 {
7336 	return test_zuc_cipher(&zuc_test_case_cipher_1570b,
7337 			RTE_CRYPTO_CIPHER_OP_ENCRYPT);
7338 }
7339 
7340 static int
7341 test_zuc_encryption_test_case_4(void)
7342 {
7343 	return test_zuc_cipher(&zuc_test_case_cipher_2798b,
7344 			RTE_CRYPTO_CIPHER_OP_ENCRYPT);
7345 }
7346 
7347 static int
7348 test_zuc_encryption_test_case_5(void)
7349 {
7350 	return test_zuc_cipher(&zuc_test_case_cipher_4019b,
7351 			RTE_CRYPTO_CIPHER_OP_ENCRYPT);
7352 }
7353 
7354 static int
7355 test_zuc_encryption_test_case_6_sgl(void)
7356 {
7357 	return test_zuc_cipher_sgl(&zuc_test_case_cipher_193b,
7358 			RTE_CRYPTO_CIPHER_OP_ENCRYPT);
7359 }
7360 
7361 static int
7362 test_zuc_decryption_test_case_1(void)
7363 {
7364 	return test_zuc_cipher(&zuc_test_case_cipher_193b,
7365 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
7366 }
7367 
7368 static int
7369 test_zuc_decryption_test_case_2(void)
7370 {
7371 	return test_zuc_cipher(&zuc_test_case_cipher_800b,
7372 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
7373 }
7374 
7375 static int
7376 test_zuc_decryption_test_case_3(void)
7377 {
7378 	return test_zuc_cipher(&zuc_test_case_cipher_1570b,
7379 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
7380 }
7381 
7382 static int
7383 test_zuc_decryption_test_case_4(void)
7384 {
7385 	return test_zuc_cipher(&zuc_test_case_cipher_2798b,
7386 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
7387 }
7388 
7389 static int
7390 test_zuc_decryption_test_case_5(void)
7391 {
7392 	return test_zuc_cipher(&zuc_test_case_cipher_4019b,
7393 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
7394 }
7395 
7396 static int
7397 test_zuc_decryption_test_case_6_sgl(void)
7398 {
7399 	return test_zuc_cipher_sgl(&zuc_test_case_cipher_193b,
7400 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
7401 }
7402 
7403 static int
7404 test_zuc_hash_generate_test_case_1(void)
7405 {
7406 	return test_zuc_authentication(&zuc_test_case_auth_1b,
7407 			RTE_CRYPTO_AUTH_OP_GENERATE);
7408 }
7409 
7410 static int
7411 test_zuc_hash_generate_test_case_2(void)
7412 {
7413 	return test_zuc_authentication(&zuc_test_case_auth_90b,
7414 			RTE_CRYPTO_AUTH_OP_GENERATE);
7415 }
7416 
7417 static int
7418 test_zuc_hash_generate_test_case_3(void)
7419 {
7420 	return test_zuc_authentication(&zuc_test_case_auth_577b,
7421 			RTE_CRYPTO_AUTH_OP_GENERATE);
7422 }
7423 
7424 static int
7425 test_zuc_hash_generate_test_case_4(void)
7426 {
7427 	return test_zuc_authentication(&zuc_test_case_auth_2079b,
7428 			RTE_CRYPTO_AUTH_OP_GENERATE);
7429 }
7430 
7431 static int
7432 test_zuc_hash_generate_test_case_5(void)
7433 {
7434 	return test_zuc_authentication(&zuc_test_auth_5670b,
7435 			RTE_CRYPTO_AUTH_OP_GENERATE);
7436 }
7437 
7438 static int
7439 test_zuc_hash_generate_test_case_6(void)
7440 {
7441 	return test_zuc_authentication(&zuc_test_case_auth_128b,
7442 			RTE_CRYPTO_AUTH_OP_GENERATE);
7443 }
7444 
7445 static int
7446 test_zuc_hash_generate_test_case_7(void)
7447 {
7448 	return test_zuc_authentication(&zuc_test_case_auth_2080b,
7449 			RTE_CRYPTO_AUTH_OP_GENERATE);
7450 }
7451 
7452 static int
7453 test_zuc_hash_generate_test_case_8(void)
7454 {
7455 	return test_zuc_authentication(&zuc_test_case_auth_584b,
7456 			RTE_CRYPTO_AUTH_OP_GENERATE);
7457 }
7458 
7459 static int
7460 test_zuc_hash_verify_test_case_1(void)
7461 {
7462 	return test_zuc_authentication(&zuc_test_case_auth_1b,
7463 			RTE_CRYPTO_AUTH_OP_VERIFY);
7464 }
7465 
7466 static int
7467 test_zuc_hash_verify_test_case_2(void)
7468 {
7469 	return test_zuc_authentication(&zuc_test_case_auth_90b,
7470 			RTE_CRYPTO_AUTH_OP_VERIFY);
7471 }
7472 
7473 static int
7474 test_zuc_hash_verify_test_case_3(void)
7475 {
7476 	return test_zuc_authentication(&zuc_test_case_auth_577b,
7477 			RTE_CRYPTO_AUTH_OP_VERIFY);
7478 }
7479 
7480 static int
7481 test_zuc_hash_verify_test_case_4(void)
7482 {
7483 	return test_zuc_authentication(&zuc_test_case_auth_2079b,
7484 			RTE_CRYPTO_AUTH_OP_VERIFY);
7485 }
7486 
7487 static int
7488 test_zuc_hash_verify_test_case_5(void)
7489 {
7490 	return test_zuc_authentication(&zuc_test_auth_5670b,
7491 			RTE_CRYPTO_AUTH_OP_VERIFY);
7492 }
7493 
7494 static int
7495 test_zuc_hash_verify_test_case_6(void)
7496 {
7497 	return test_zuc_authentication(&zuc_test_case_auth_128b,
7498 			RTE_CRYPTO_AUTH_OP_VERIFY);
7499 }
7500 
7501 static int
7502 test_zuc_hash_verify_test_case_7(void)
7503 {
7504 	return test_zuc_authentication(&zuc_test_case_auth_2080b,
7505 			RTE_CRYPTO_AUTH_OP_VERIFY);
7506 }
7507 
7508 static int
7509 test_zuc_hash_verify_test_case_8(void)
7510 {
7511 	return test_zuc_authentication(&zuc_test_case_auth_584b,
7512 			RTE_CRYPTO_AUTH_OP_VERIFY);
7513 }
7514 
7515 static int
7516 test_zuc_cipher_auth_test_case_1(void)
7517 {
7518 	return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
7519 }
7520 
7521 static int
7522 test_zuc_cipher_auth_test_case_2(void)
7523 {
7524 	return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
7525 }
7526 
7527 static int
7528 test_zuc_auth_cipher_test_case_1(void)
7529 {
7530 	return test_zuc_auth_cipher(
7531 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7532 }
7533 
7534 static int
7535 test_zuc_auth_cipher_test_case_1_oop(void)
7536 {
7537 	return test_zuc_auth_cipher(
7538 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7539 }
7540 
7541 static int
7542 test_zuc_auth_cipher_test_case_1_sgl(void)
7543 {
7544 	return test_zuc_auth_cipher_sgl(
7545 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7546 }
7547 
7548 static int
7549 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
7550 {
7551 	return test_zuc_auth_cipher_sgl(
7552 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7553 }
7554 
7555 static int
7556 test_zuc_auth_cipher_test_case_2(void)
7557 {
7558 	return test_zuc_auth_cipher(
7559 		&zuc_auth_cipher_test_case_2, IN_PLACE, 0);
7560 }
7561 
7562 static int
7563 test_zuc_auth_cipher_test_case_2_oop(void)
7564 {
7565 	return test_zuc_auth_cipher(
7566 		&zuc_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7567 }
7568 
7569 static int
7570 test_zuc_auth_cipher_verify_test_case_1(void)
7571 {
7572 	return test_zuc_auth_cipher(
7573 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7574 }
7575 
7576 static int
7577 test_zuc_auth_cipher_verify_test_case_1_oop(void)
7578 {
7579 	return test_zuc_auth_cipher(
7580 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7581 }
7582 
7583 static int
7584 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
7585 {
7586 	return test_zuc_auth_cipher_sgl(
7587 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7588 }
7589 
7590 static int
7591 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
7592 {
7593 	return test_zuc_auth_cipher_sgl(
7594 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7595 }
7596 
7597 static int
7598 test_zuc_auth_cipher_verify_test_case_2(void)
7599 {
7600 	return test_zuc_auth_cipher(
7601 		&zuc_auth_cipher_test_case_2, IN_PLACE, 1);
7602 }
7603 
7604 static int
7605 test_zuc_auth_cipher_verify_test_case_2_oop(void)
7606 {
7607 	return test_zuc_auth_cipher(
7608 		&zuc_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7609 }
7610 
7611 static int
7612 test_zuc256_encryption_test_case_1(void)
7613 {
7614 	return test_zuc_cipher(&zuc256_test_case_cipher_1,
7615 			RTE_CRYPTO_CIPHER_OP_ENCRYPT);
7616 }
7617 
7618 static int
7619 test_zuc256_encryption_test_case_2(void)
7620 {
7621 	return test_zuc_cipher(&zuc256_test_case_cipher_2,
7622 			RTE_CRYPTO_CIPHER_OP_ENCRYPT);
7623 }
7624 
7625 static int
7626 test_zuc256_decryption_test_case_1(void)
7627 {
7628 	return test_zuc_cipher(&zuc256_test_case_cipher_1,
7629 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
7630 }
7631 
7632 static int
7633 test_zuc256_decryption_test_case_2(void)
7634 {
7635 	return test_zuc_cipher(&zuc256_test_case_cipher_2,
7636 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
7637 }
7638 
7639 static int
7640 test_zuc256_hash_generate_4b_tag_test_case_1(void)
7641 {
7642 	return test_zuc_authentication(&zuc256_test_case_auth_1,
7643 			RTE_CRYPTO_AUTH_OP_GENERATE);
7644 }
7645 
7646 static int
7647 test_zuc256_hash_generate_4b_tag_test_case_2(void)
7648 {
7649 	return test_zuc_authentication(&zuc256_test_case_auth_2,
7650 			RTE_CRYPTO_AUTH_OP_GENERATE);
7651 }
7652 
7653 static int
7654 test_zuc256_hash_generate_4b_tag_test_case_3(void)
7655 {
7656 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b,
7657 			RTE_CRYPTO_AUTH_OP_GENERATE);
7658 }
7659 
7660 static int
7661 test_zuc256_hash_generate_8b_tag_test_case_1(void)
7662 {
7663 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b,
7664 			RTE_CRYPTO_AUTH_OP_GENERATE);
7665 }
7666 
7667 static int
7668 test_zuc256_hash_generate_16b_tag_test_case_1(void)
7669 {
7670 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b,
7671 			RTE_CRYPTO_AUTH_OP_GENERATE);
7672 }
7673 
7674 static int
7675 test_zuc256_hash_verify_4b_tag_test_case_1(void)
7676 {
7677 	return test_zuc_authentication(&zuc256_test_case_auth_1,
7678 			RTE_CRYPTO_AUTH_OP_VERIFY);
7679 }
7680 
7681 static int
7682 test_zuc256_hash_verify_4b_tag_test_case_2(void)
7683 {
7684 	return test_zuc_authentication(&zuc256_test_case_auth_2,
7685 			RTE_CRYPTO_AUTH_OP_VERIFY);
7686 }
7687 
7688 static int
7689 test_zuc256_hash_verify_4b_tag_test_case_3(void)
7690 {
7691 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b,
7692 			RTE_CRYPTO_AUTH_OP_VERIFY);
7693 }
7694 
7695 static int
7696 test_zuc256_hash_verify_8b_tag_test_case_1(void)
7697 {
7698 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b,
7699 			RTE_CRYPTO_AUTH_OP_VERIFY);
7700 }
7701 
7702 static int
7703 test_zuc256_hash_verify_16b_tag_test_case_1(void)
7704 {
7705 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b,
7706 			RTE_CRYPTO_AUTH_OP_VERIFY);
7707 }
7708 
7709 static int
7710 test_zuc256_cipher_auth_4b_tag_test_case_1(void)
7711 {
7712 	return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_1);
7713 }
7714 
7715 static int
7716 test_zuc256_cipher_auth_4b_tag_test_case_2(void)
7717 {
7718 	return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_2);
7719 }
7720 
7721 static int
7722 test_zuc256_cipher_auth_8b_tag_test_case_1(void)
7723 {
7724 	return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_3);
7725 }
7726 
7727 static int
7728 test_zuc256_cipher_auth_16b_tag_test_case_1(void)
7729 {
7730 	return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_4);
7731 }
7732 
7733 static int
7734 test_zuc256_auth_cipher_4b_tag_test_case_1(void)
7735 {
7736 	return test_zuc_auth_cipher(
7737 		&zuc256_auth_cipher_test_case_1, IN_PLACE, 0);
7738 }
7739 
7740 static int
7741 test_zuc256_auth_cipher_4b_tag_test_case_2(void)
7742 {
7743 	return test_zuc_auth_cipher(
7744 		&zuc256_auth_cipher_test_case_2, IN_PLACE, 0);
7745 }
7746 
7747 static int
7748 test_zuc256_auth_cipher_8b_tag_test_case_1(void)
7749 {
7750 	return test_zuc_auth_cipher(
7751 		&zuc256_auth_cipher_test_case_3, IN_PLACE, 0);
7752 }
7753 
7754 static int
7755 test_zuc256_auth_cipher_16b_tag_test_case_1(void)
7756 {
7757 	return test_zuc_auth_cipher(
7758 		&zuc256_auth_cipher_test_case_4, IN_PLACE, 0);
7759 }
7760 
7761 static int
7762 test_zuc256_auth_cipher_verify_4b_tag_test_case_1(void)
7763 {
7764 	return test_zuc_auth_cipher(
7765 		&zuc256_auth_cipher_test_case_1, IN_PLACE, 1);
7766 }
7767 
7768 static int
7769 test_zuc256_auth_cipher_verify_4b_tag_test_case_2(void)
7770 {
7771 	return test_zuc_auth_cipher(
7772 		&zuc256_auth_cipher_test_case_2, IN_PLACE, 1);
7773 }
7774 
7775 static int
7776 test_zuc256_auth_cipher_verify_8b_tag_test_case_1(void)
7777 {
7778 	return test_zuc_auth_cipher(
7779 		&zuc256_auth_cipher_test_case_3, IN_PLACE, 1);
7780 }
7781 
7782 static int
7783 test_zuc256_auth_cipher_verify_16b_tag_test_case_1(void)
7784 {
7785 	return test_zuc_auth_cipher(
7786 		&zuc256_auth_cipher_test_case_4, IN_PLACE, 1);
7787 }
7788 
7789 static int
7790 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
7791 {
7792 	uint8_t dev_id = testsuite_params.valid_devs[0];
7793 
7794 	struct rte_cryptodev_sym_capability_idx cap_idx;
7795 
7796 	/* Check if device supports particular cipher algorithm */
7797 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7798 	cap_idx.algo.cipher = tdata->cipher_algo;
7799 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7800 		return TEST_SKIPPED;
7801 
7802 	/* Check if device supports particular hash algorithm */
7803 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7804 	cap_idx.algo.auth = tdata->auth_algo;
7805 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7806 		return TEST_SKIPPED;
7807 
7808 	return 0;
7809 }
7810 
7811 static int
7812 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
7813 	uint8_t op_mode, uint8_t verify)
7814 {
7815 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7816 	struct crypto_unittest_params *ut_params = &unittest_params;
7817 
7818 	int retval;
7819 
7820 	uint8_t *plaintext = NULL, *ciphertext = NULL;
7821 	unsigned int plaintext_pad_len;
7822 	unsigned int plaintext_len;
7823 	unsigned int ciphertext_pad_len;
7824 	unsigned int ciphertext_len;
7825 
7826 	struct rte_cryptodev_info dev_info;
7827 	struct rte_crypto_op *op;
7828 
7829 	/* Check if device supports particular algorithms separately */
7830 	if (test_mixed_check_if_unsupported(tdata))
7831 		return TEST_SKIPPED;
7832 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7833 		return TEST_SKIPPED;
7834 
7835 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
7836 		return TEST_SKIPPED;
7837 
7838 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7839 
7840 	uint64_t feat_flags = dev_info.feature_flags;
7841 
7842 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7843 		printf("Device doesn't support digest encrypted.\n");
7844 		return TEST_SKIPPED;
7845 	}
7846 
7847 	/* Create the session */
7848 	if (verify)
7849 		retval = create_wireless_algo_cipher_auth_session(
7850 				ts_params->valid_devs[0],
7851 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
7852 				RTE_CRYPTO_AUTH_OP_VERIFY,
7853 				tdata->auth_algo,
7854 				tdata->cipher_algo,
7855 				tdata->auth_key.data, tdata->auth_key.len,
7856 				tdata->cipher_key.data, tdata->cipher_key.len,
7857 				tdata->auth_iv.len, tdata->digest_enc.len,
7858 				tdata->cipher_iv.len);
7859 	else
7860 		retval = create_wireless_algo_auth_cipher_session(
7861 				ts_params->valid_devs[0],
7862 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7863 				RTE_CRYPTO_AUTH_OP_GENERATE,
7864 				tdata->auth_algo,
7865 				tdata->cipher_algo,
7866 				tdata->auth_key.data, tdata->auth_key.len,
7867 				tdata->cipher_key.data, tdata->cipher_key.len,
7868 				tdata->auth_iv.len, tdata->digest_enc.len,
7869 				tdata->cipher_iv.len);
7870 	if (retval != 0)
7871 		return retval;
7872 
7873 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7874 	if (op_mode == OUT_OF_PLACE)
7875 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7876 
7877 	/* clear mbuf payload */
7878 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7879 		rte_pktmbuf_tailroom(ut_params->ibuf));
7880 	if (op_mode == OUT_OF_PLACE) {
7881 
7882 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
7883 				rte_pktmbuf_tailroom(ut_params->obuf));
7884 	}
7885 
7886 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7887 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7888 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7889 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7890 
7891 	if (verify) {
7892 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7893 				ciphertext_pad_len);
7894 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
7895 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7896 				ciphertext_len);
7897 	} else {
7898 		/* make sure enough space to cover partial digest verify case */
7899 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7900 				ciphertext_pad_len);
7901 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7902 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
7903 	}
7904 
7905 	if (op_mode == OUT_OF_PLACE)
7906 		rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
7907 
7908 	/* Create the operation */
7909 	retval = create_wireless_algo_auth_cipher_operation(
7910 			tdata->digest_enc.data, tdata->digest_enc.len,
7911 			tdata->cipher_iv.data, tdata->cipher_iv.len,
7912 			tdata->auth_iv.data, tdata->auth_iv.len,
7913 			(tdata->digest_enc.offset == 0 ?
7914 				plaintext_pad_len
7915 				: tdata->digest_enc.offset),
7916 			tdata->validCipherLen.len_bits,
7917 			tdata->cipher.offset_bits,
7918 			tdata->validAuthLen.len_bits,
7919 			tdata->auth.offset_bits,
7920 			op_mode, 0, verify);
7921 
7922 	if (retval < 0)
7923 		return retval;
7924 
7925 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7926 
7927 	/* Check if the op failed because the device doesn't */
7928 	/* support this particular combination of algorithms */
7929 	if (op == NULL && ut_params->op->status ==
7930 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7931 		printf("Device doesn't support this mixed combination. "
7932 				"Test Skipped.\n");
7933 		return TEST_SKIPPED;
7934 	}
7935 	ut_params->op = op;
7936 
7937 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7938 
7939 	ut_params->obuf = (op_mode == IN_PLACE ?
7940 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7941 
7942 	if (verify) {
7943 		if (ut_params->obuf)
7944 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
7945 							uint8_t *);
7946 		else
7947 			plaintext = ciphertext +
7948 					(tdata->cipher.offset_bits >> 3);
7949 
7950 		debug_hexdump(stdout, "plaintext:", plaintext,
7951 				tdata->plaintext.len_bits >> 3);
7952 		debug_hexdump(stdout, "plaintext expected:",
7953 				tdata->plaintext.data,
7954 				tdata->plaintext.len_bits >> 3);
7955 	} else {
7956 		if (ut_params->obuf)
7957 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
7958 					uint8_t *);
7959 		else
7960 			ciphertext = plaintext;
7961 
7962 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7963 				ciphertext_len);
7964 		debug_hexdump(stdout, "ciphertext expected:",
7965 				tdata->ciphertext.data,
7966 				tdata->ciphertext.len_bits >> 3);
7967 
7968 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
7969 				+ (tdata->digest_enc.offset == 0 ?
7970 		plaintext_pad_len : tdata->digest_enc.offset);
7971 
7972 		debug_hexdump(stdout, "digest:", ut_params->digest,
7973 				tdata->digest_enc.len);
7974 		debug_hexdump(stdout, "digest expected:",
7975 				tdata->digest_enc.data,
7976 				tdata->digest_enc.len);
7977 	}
7978 
7979 	if (!verify) {
7980 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
7981 				ut_params->digest,
7982 				tdata->digest_enc.data,
7983 				tdata->digest_enc.len,
7984 				"Generated auth tag not as expected");
7985 	}
7986 
7987 	if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
7988 		if (verify) {
7989 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7990 					plaintext,
7991 					tdata->plaintext.data,
7992 					tdata->plaintext.len_bits >> 3,
7993 					"Plaintext data not as expected");
7994 		} else {
7995 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7996 					ciphertext,
7997 					tdata->ciphertext.data,
7998 					tdata->validDataLen.len_bits,
7999 					"Ciphertext data not as expected");
8000 		}
8001 	}
8002 
8003 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8004 			"crypto op processing failed");
8005 
8006 	return 0;
8007 }
8008 
8009 static int
8010 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
8011 	uint8_t op_mode, uint8_t verify)
8012 {
8013 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8014 	struct crypto_unittest_params *ut_params = &unittest_params;
8015 
8016 	int retval;
8017 
8018 	const uint8_t *plaintext = NULL;
8019 	const uint8_t *ciphertext = NULL;
8020 	const uint8_t *digest = NULL;
8021 	unsigned int plaintext_pad_len;
8022 	unsigned int plaintext_len;
8023 	unsigned int ciphertext_pad_len;
8024 	unsigned int ciphertext_len;
8025 	uint8_t buffer[10000];
8026 	uint8_t digest_buffer[10000];
8027 
8028 	struct rte_cryptodev_info dev_info;
8029 	struct rte_crypto_op *op;
8030 
8031 	/* Check if device supports particular algorithms */
8032 	if (test_mixed_check_if_unsupported(tdata))
8033 		return TEST_SKIPPED;
8034 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
8035 		return TEST_SKIPPED;
8036 
8037 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8038 
8039 	uint64_t feat_flags = dev_info.feature_flags;
8040 
8041 	if (op_mode == IN_PLACE) {
8042 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
8043 			printf("Device doesn't support in-place scatter-gather "
8044 					"in both input and output mbufs.\n");
8045 			return TEST_SKIPPED;
8046 		}
8047 	} else {
8048 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
8049 			printf("Device doesn't support out-of-place scatter-gather "
8050 					"in both input and output mbufs.\n");
8051 			return TEST_SKIPPED;
8052 		}
8053 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
8054 			printf("Device doesn't support digest encrypted.\n");
8055 			return TEST_SKIPPED;
8056 		}
8057 	}
8058 
8059 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8060 		return TEST_SKIPPED;
8061 
8062 	/* Create the session */
8063 	if (verify)
8064 		retval = create_wireless_algo_cipher_auth_session(
8065 				ts_params->valid_devs[0],
8066 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
8067 				RTE_CRYPTO_AUTH_OP_VERIFY,
8068 				tdata->auth_algo,
8069 				tdata->cipher_algo,
8070 				tdata->auth_key.data, tdata->auth_key.len,
8071 				tdata->cipher_key.data, tdata->cipher_key.len,
8072 				tdata->auth_iv.len, tdata->digest_enc.len,
8073 				tdata->cipher_iv.len);
8074 	else
8075 		retval = create_wireless_algo_auth_cipher_session(
8076 				ts_params->valid_devs[0],
8077 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8078 				RTE_CRYPTO_AUTH_OP_GENERATE,
8079 				tdata->auth_algo,
8080 				tdata->cipher_algo,
8081 				tdata->auth_key.data, tdata->auth_key.len,
8082 				tdata->cipher_key.data, tdata->cipher_key.len,
8083 				tdata->auth_iv.len, tdata->digest_enc.len,
8084 				tdata->cipher_iv.len);
8085 	if (retval != 0)
8086 		return retval;
8087 
8088 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
8089 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
8090 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
8091 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
8092 
8093 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
8094 			ciphertext_pad_len, 15, 0);
8095 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
8096 			"Failed to allocate input buffer in mempool");
8097 
8098 	if (op_mode == OUT_OF_PLACE) {
8099 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
8100 				plaintext_pad_len, 15, 0);
8101 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
8102 				"Failed to allocate output buffer in mempool");
8103 	}
8104 
8105 	if (verify) {
8106 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
8107 			tdata->ciphertext.data);
8108 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
8109 					ciphertext_len, buffer);
8110 		debug_hexdump(stdout, "ciphertext:", ciphertext,
8111 			ciphertext_len);
8112 	} else {
8113 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
8114 			tdata->plaintext.data);
8115 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
8116 					plaintext_len, buffer);
8117 		debug_hexdump(stdout, "plaintext:", plaintext,
8118 			plaintext_len);
8119 	}
8120 	memset(buffer, 0, sizeof(buffer));
8121 
8122 	/* Create the operation */
8123 	retval = create_wireless_algo_auth_cipher_operation(
8124 			tdata->digest_enc.data, tdata->digest_enc.len,
8125 			tdata->cipher_iv.data, tdata->cipher_iv.len,
8126 			tdata->auth_iv.data, tdata->auth_iv.len,
8127 			(tdata->digest_enc.offset == 0 ?
8128 				plaintext_pad_len
8129 				: tdata->digest_enc.offset),
8130 			tdata->validCipherLen.len_bits,
8131 			tdata->cipher.offset_bits,
8132 			tdata->validAuthLen.len_bits,
8133 			tdata->auth.offset_bits,
8134 			op_mode, 1, verify);
8135 
8136 	if (retval < 0)
8137 		return retval;
8138 
8139 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
8140 
8141 	/* Check if the op failed because the device doesn't */
8142 	/* support this particular combination of algorithms */
8143 	if (op == NULL && ut_params->op->status ==
8144 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
8145 		printf("Device doesn't support this mixed combination. "
8146 				"Test Skipped.\n");
8147 		return TEST_SKIPPED;
8148 	}
8149 	ut_params->op = op;
8150 
8151 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
8152 
8153 	ut_params->obuf = (op_mode == IN_PLACE ?
8154 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
8155 
8156 	if (verify) {
8157 		if (ut_params->obuf)
8158 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
8159 					plaintext_len, buffer);
8160 		else
8161 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
8162 					plaintext_len, buffer);
8163 
8164 		debug_hexdump(stdout, "plaintext:", plaintext,
8165 				(tdata->plaintext.len_bits >> 3) -
8166 				tdata->digest_enc.len);
8167 		debug_hexdump(stdout, "plaintext expected:",
8168 				tdata->plaintext.data,
8169 				(tdata->plaintext.len_bits >> 3) -
8170 				tdata->digest_enc.len);
8171 	} else {
8172 		if (ut_params->obuf)
8173 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
8174 					ciphertext_len, buffer);
8175 		else
8176 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
8177 					ciphertext_len, buffer);
8178 
8179 		debug_hexdump(stdout, "ciphertext:", ciphertext,
8180 			ciphertext_len);
8181 		debug_hexdump(stdout, "ciphertext expected:",
8182 			tdata->ciphertext.data,
8183 			tdata->ciphertext.len_bits >> 3);
8184 
8185 		if (ut_params->obuf)
8186 			digest = rte_pktmbuf_read(ut_params->obuf,
8187 					(tdata->digest_enc.offset == 0 ?
8188 						plaintext_pad_len :
8189 						tdata->digest_enc.offset),
8190 					tdata->digest_enc.len, digest_buffer);
8191 		else
8192 			digest = rte_pktmbuf_read(ut_params->ibuf,
8193 					(tdata->digest_enc.offset == 0 ?
8194 						plaintext_pad_len :
8195 						tdata->digest_enc.offset),
8196 					tdata->digest_enc.len, digest_buffer);
8197 
8198 		debug_hexdump(stdout, "digest:", digest,
8199 				tdata->digest_enc.len);
8200 		debug_hexdump(stdout, "digest expected:",
8201 				tdata->digest_enc.data, tdata->digest_enc.len);
8202 	}
8203 
8204 	if (!verify) {
8205 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
8206 				digest,
8207 				tdata->digest_enc.data,
8208 				tdata->digest_enc.len,
8209 				"Generated auth tag not as expected");
8210 	}
8211 
8212 	if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
8213 		if (verify) {
8214 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
8215 					plaintext,
8216 					tdata->plaintext.data,
8217 					tdata->plaintext.len_bits >> 3,
8218 					"Plaintext data not as expected");
8219 		} else {
8220 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
8221 					ciphertext,
8222 					tdata->ciphertext.data,
8223 					tdata->validDataLen.len_bits,
8224 					"Ciphertext data not as expected");
8225 		}
8226 	}
8227 
8228 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8229 			"crypto op processing failed");
8230 
8231 	return 0;
8232 }
8233 
8234 /** AUTH AES CMAC + CIPHER AES CTR */
8235 
8236 static int
8237 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
8238 {
8239 	return test_mixed_auth_cipher(
8240 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
8241 }
8242 
8243 static int
8244 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
8245 {
8246 	return test_mixed_auth_cipher(
8247 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
8248 }
8249 
8250 static int
8251 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
8252 {
8253 	return test_mixed_auth_cipher_sgl(
8254 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
8255 }
8256 
8257 static int
8258 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
8259 {
8260 	return test_mixed_auth_cipher_sgl(
8261 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
8262 }
8263 
8264 static int
8265 test_aes_cmac_aes_ctr_digest_enc_test_case_2(void)
8266 {
8267 	return test_mixed_auth_cipher(
8268 		&auth_aes_cmac_cipher_aes_ctr_test_case_2, IN_PLACE, 0);
8269 }
8270 
8271 static int
8272 test_aes_cmac_aes_ctr_digest_enc_test_case_2_oop(void)
8273 {
8274 	return test_mixed_auth_cipher(
8275 		&auth_aes_cmac_cipher_aes_ctr_test_case_2, OUT_OF_PLACE, 0);
8276 }
8277 
8278 static int
8279 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
8280 {
8281 	return test_mixed_auth_cipher(
8282 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
8283 }
8284 
8285 static int
8286 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2(void)
8287 {
8288 	return test_mixed_auth_cipher(
8289 		&auth_aes_cmac_cipher_aes_ctr_test_case_2, IN_PLACE, 1);
8290 }
8291 
8292 static int
8293 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
8294 {
8295 	return test_mixed_auth_cipher(
8296 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
8297 }
8298 
8299 static int
8300 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
8301 {
8302 	return test_mixed_auth_cipher_sgl(
8303 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
8304 }
8305 
8306 static int
8307 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
8308 {
8309 	return test_mixed_auth_cipher_sgl(
8310 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
8311 }
8312 
8313 static int
8314 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2_oop(void)
8315 {
8316 	return test_mixed_auth_cipher(
8317 		&auth_aes_cmac_cipher_aes_ctr_test_case_2, OUT_OF_PLACE, 1);
8318 }
8319 
8320 /** MIXED AUTH + CIPHER */
8321 
8322 static int
8323 test_auth_zuc_cipher_snow_test_case_1(void)
8324 {
8325 	return test_mixed_auth_cipher(
8326 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
8327 }
8328 
8329 static int
8330 test_verify_auth_zuc_cipher_snow_test_case_1(void)
8331 {
8332 	return test_mixed_auth_cipher(
8333 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
8334 }
8335 
8336 static int
8337 test_auth_zuc_cipher_snow_test_case_1_inplace(void)
8338 {
8339 	return test_mixed_auth_cipher(
8340 		&auth_zuc_cipher_snow_test_case_1, IN_PLACE, 0);
8341 }
8342 
8343 static int
8344 test_verify_auth_zuc_cipher_snow_test_case_1_inplace(void)
8345 {
8346 	return test_mixed_auth_cipher(
8347 		&auth_zuc_cipher_snow_test_case_1, IN_PLACE, 1);
8348 }
8349 
8350 
8351 static int
8352 test_auth_aes_cmac_cipher_snow_test_case_1(void)
8353 {
8354 	return test_mixed_auth_cipher(
8355 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
8356 }
8357 
8358 static int
8359 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
8360 {
8361 	return test_mixed_auth_cipher(
8362 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
8363 }
8364 
8365 static int
8366 test_auth_aes_cmac_cipher_snow_test_case_1_inplace(void)
8367 {
8368 	return test_mixed_auth_cipher(
8369 		&auth_aes_cmac_cipher_snow_test_case_1, IN_PLACE, 0);
8370 }
8371 
8372 static int
8373 test_verify_auth_aes_cmac_cipher_snow_test_case_1_inplace(void)
8374 {
8375 	return test_mixed_auth_cipher(
8376 		&auth_aes_cmac_cipher_snow_test_case_1, IN_PLACE, 1);
8377 }
8378 
8379 static int
8380 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
8381 {
8382 	return test_mixed_auth_cipher(
8383 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
8384 }
8385 
8386 static int
8387 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
8388 {
8389 	return test_mixed_auth_cipher(
8390 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
8391 }
8392 
8393 static int
8394 test_auth_zuc_cipher_aes_ctr_test_case_1_inplace(void)
8395 {
8396 	return test_mixed_auth_cipher(
8397 		&auth_zuc_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
8398 }
8399 
8400 static int
8401 test_verify_auth_zuc_cipher_aes_ctr_test_case_1_inplace(void)
8402 {
8403 	return test_mixed_auth_cipher(
8404 		&auth_zuc_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
8405 }
8406 
8407 static int
8408 test_auth_snow_cipher_aes_ctr_test_case_1(void)
8409 {
8410 	return test_mixed_auth_cipher(
8411 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
8412 }
8413 
8414 static int
8415 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
8416 {
8417 	return test_mixed_auth_cipher(
8418 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
8419 }
8420 
8421 static int
8422 test_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl(void)
8423 {
8424 	return test_mixed_auth_cipher_sgl(
8425 		&auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
8426 }
8427 
8428 static int
8429 test_auth_snow_cipher_aes_ctr_test_case_1_inplace(void)
8430 {
8431 	return test_mixed_auth_cipher(
8432 		&auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
8433 }
8434 
8435 static int
8436 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl(void)
8437 {
8438 	return test_mixed_auth_cipher_sgl(
8439 		&auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
8440 }
8441 
8442 static int
8443 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace(void)
8444 {
8445 	return test_mixed_auth_cipher(
8446 		&auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
8447 }
8448 
8449 static int
8450 test_auth_snow_cipher_zuc_test_case_1(void)
8451 {
8452 	return test_mixed_auth_cipher(
8453 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
8454 }
8455 
8456 static int
8457 test_verify_auth_snow_cipher_zuc_test_case_1(void)
8458 {
8459 	return test_mixed_auth_cipher(
8460 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
8461 }
8462 
8463 static int
8464 test_auth_snow_cipher_zuc_test_case_1_inplace(void)
8465 {
8466 	return test_mixed_auth_cipher(
8467 		&auth_snow_cipher_zuc_test_case_1, IN_PLACE, 0);
8468 }
8469 
8470 static int
8471 test_verify_auth_snow_cipher_zuc_test_case_1_inplace(void)
8472 {
8473 	return test_mixed_auth_cipher(
8474 		&auth_snow_cipher_zuc_test_case_1, IN_PLACE, 1);
8475 }
8476 
8477 static int
8478 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
8479 {
8480 	return test_mixed_auth_cipher(
8481 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
8482 }
8483 
8484 static int
8485 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
8486 {
8487 	return test_mixed_auth_cipher(
8488 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
8489 }
8490 static int
8491 test_auth_aes_cmac_cipher_zuc_test_case_1_inplace(void)
8492 {
8493 	return test_mixed_auth_cipher(
8494 		&auth_aes_cmac_cipher_zuc_test_case_1, IN_PLACE, 0);
8495 }
8496 
8497 static int
8498 test_verify_auth_aes_cmac_cipher_zuc_test_case_1_inplace(void)
8499 {
8500 	return test_mixed_auth_cipher(
8501 		&auth_aes_cmac_cipher_zuc_test_case_1, IN_PLACE, 1);
8502 }
8503 
8504 static int
8505 test_auth_null_cipher_snow_test_case_1(void)
8506 {
8507 	return test_mixed_auth_cipher(
8508 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
8509 }
8510 
8511 static int
8512 test_verify_auth_null_cipher_snow_test_case_1(void)
8513 {
8514 	return test_mixed_auth_cipher(
8515 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
8516 }
8517 
8518 static int
8519 test_auth_null_cipher_zuc_test_case_1(void)
8520 {
8521 	return test_mixed_auth_cipher(
8522 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
8523 }
8524 
8525 static int
8526 test_verify_auth_null_cipher_zuc_test_case_1(void)
8527 {
8528 	return test_mixed_auth_cipher(
8529 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
8530 }
8531 
8532 static int
8533 test_auth_snow_cipher_null_test_case_1(void)
8534 {
8535 	return test_mixed_auth_cipher(
8536 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
8537 }
8538 
8539 static int
8540 test_verify_auth_snow_cipher_null_test_case_1(void)
8541 {
8542 	return test_mixed_auth_cipher(
8543 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
8544 }
8545 
8546 static int
8547 test_auth_zuc_cipher_null_test_case_1(void)
8548 {
8549 	return test_mixed_auth_cipher(
8550 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
8551 }
8552 
8553 static int
8554 test_verify_auth_zuc_cipher_null_test_case_1(void)
8555 {
8556 	return test_mixed_auth_cipher(
8557 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
8558 }
8559 
8560 static int
8561 test_auth_null_cipher_aes_ctr_test_case_1(void)
8562 {
8563 	return test_mixed_auth_cipher(
8564 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
8565 }
8566 
8567 static int
8568 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
8569 {
8570 	return test_mixed_auth_cipher(
8571 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
8572 }
8573 
8574 static int
8575 test_auth_aes_cmac_cipher_null_test_case_1(void)
8576 {
8577 	return test_mixed_auth_cipher(
8578 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
8579 }
8580 
8581 static int
8582 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
8583 {
8584 	return test_mixed_auth_cipher(
8585 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
8586 }
8587 
8588 /* ***** AEAD algorithm Tests ***** */
8589 
8590 static int
8591 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
8592 		enum rte_crypto_aead_operation op,
8593 		const uint8_t *key, const uint8_t key_len,
8594 		const uint16_t aad_len, const uint8_t auth_len,
8595 		uint8_t iv_len)
8596 {
8597 	uint8_t aead_key[key_len];
8598 
8599 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8600 	struct crypto_unittest_params *ut_params = &unittest_params;
8601 
8602 	memcpy(aead_key, key, key_len);
8603 
8604 	/* Setup AEAD Parameters */
8605 	ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8606 	ut_params->aead_xform.next = NULL;
8607 	ut_params->aead_xform.aead.algo = algo;
8608 	ut_params->aead_xform.aead.op = op;
8609 	ut_params->aead_xform.aead.key.data = aead_key;
8610 	ut_params->aead_xform.aead.key.length = key_len;
8611 	ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
8612 	ut_params->aead_xform.aead.iv.length = iv_len;
8613 	ut_params->aead_xform.aead.digest_length = auth_len;
8614 	ut_params->aead_xform.aead.aad_length = aad_len;
8615 
8616 	debug_hexdump(stdout, "key:", key, key_len);
8617 
8618 	/* Create Crypto session*/
8619 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
8620 			&ut_params->aead_xform, ts_params->session_mpool);
8621 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
8622 		return TEST_SKIPPED;
8623 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
8624 	return 0;
8625 }
8626 
8627 static int
8628 create_aead_xform(struct rte_crypto_op *op,
8629 		enum rte_crypto_aead_algorithm algo,
8630 		enum rte_crypto_aead_operation aead_op,
8631 		uint8_t *key, const uint8_t key_len,
8632 		const uint8_t aad_len, const uint8_t auth_len,
8633 		uint8_t iv_len)
8634 {
8635 	TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
8636 			"failed to allocate space for crypto transform");
8637 
8638 	struct rte_crypto_sym_op *sym_op = op->sym;
8639 
8640 	/* Setup AEAD Parameters */
8641 	sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
8642 	sym_op->xform->next = NULL;
8643 	sym_op->xform->aead.algo = algo;
8644 	sym_op->xform->aead.op = aead_op;
8645 	sym_op->xform->aead.key.data = key;
8646 	sym_op->xform->aead.key.length = key_len;
8647 	sym_op->xform->aead.iv.offset = IV_OFFSET;
8648 	sym_op->xform->aead.iv.length = iv_len;
8649 	sym_op->xform->aead.digest_length = auth_len;
8650 	sym_op->xform->aead.aad_length = aad_len;
8651 
8652 	debug_hexdump(stdout, "key:", key, key_len);
8653 
8654 	return 0;
8655 }
8656 
8657 static int
8658 create_aead_operation(enum rte_crypto_aead_operation op,
8659 		const struct aead_test_data *tdata)
8660 {
8661 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8662 	struct crypto_unittest_params *ut_params = &unittest_params;
8663 
8664 	uint8_t *plaintext, *ciphertext;
8665 	unsigned int aad_pad_len, plaintext_pad_len;
8666 
8667 	/* Generate Crypto op data structure */
8668 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8669 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8670 	TEST_ASSERT_NOT_NULL(ut_params->op,
8671 			"Failed to allocate symmetric crypto operation struct");
8672 
8673 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
8674 
8675 	/* Append aad data */
8676 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
8677 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
8678 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8679 				aad_pad_len);
8680 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
8681 				"no room to append aad");
8682 
8683 		sym_op->aead.aad.phys_addr =
8684 				rte_pktmbuf_iova(ut_params->ibuf);
8685 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
8686 		memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
8687 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data + 18,
8688 			tdata->aad.len);
8689 
8690 		/* Append IV at the end of the crypto operation*/
8691 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
8692 				uint8_t *, IV_OFFSET);
8693 
8694 		/* Copy IV 1 byte after the IV pointer, according to the API */
8695 		rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
8696 		debug_hexdump(stdout, "iv:", iv_ptr + 1,
8697 			tdata->iv.len);
8698 	} else {
8699 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
8700 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8701 				aad_pad_len);
8702 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
8703 				"no room to append aad");
8704 
8705 		sym_op->aead.aad.phys_addr =
8706 				rte_pktmbuf_iova(ut_params->ibuf);
8707 		memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
8708 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
8709 			tdata->aad.len);
8710 
8711 		/* Append IV at the end of the crypto operation*/
8712 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
8713 				uint8_t *, IV_OFFSET);
8714 
8715 		if (tdata->iv.len == 0) {
8716 			rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
8717 			debug_hexdump(stdout, "iv:", iv_ptr,
8718 				AES_GCM_J0_LENGTH);
8719 		} else {
8720 			rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
8721 			debug_hexdump(stdout, "iv:", iv_ptr,
8722 				tdata->iv.len);
8723 		}
8724 	}
8725 
8726 	/* Append plaintext/ciphertext */
8727 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
8728 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8729 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8730 				plaintext_pad_len);
8731 		TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
8732 
8733 		memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
8734 		debug_hexdump(stdout, "plaintext:", plaintext,
8735 				tdata->plaintext.len);
8736 
8737 		if (ut_params->obuf) {
8738 			ciphertext = (uint8_t *)rte_pktmbuf_append(
8739 					ut_params->obuf,
8740 					plaintext_pad_len + aad_pad_len);
8741 			TEST_ASSERT_NOT_NULL(ciphertext,
8742 					"no room to append ciphertext");
8743 
8744 			memset(ciphertext + aad_pad_len, 0,
8745 					tdata->ciphertext.len);
8746 		}
8747 	} else {
8748 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
8749 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8750 				plaintext_pad_len);
8751 		TEST_ASSERT_NOT_NULL(ciphertext,
8752 				"no room to append ciphertext");
8753 
8754 		memcpy(ciphertext, tdata->ciphertext.data,
8755 				tdata->ciphertext.len);
8756 		debug_hexdump(stdout, "ciphertext:", ciphertext,
8757 				tdata->ciphertext.len);
8758 
8759 		if (ut_params->obuf) {
8760 			plaintext = (uint8_t *)rte_pktmbuf_append(
8761 					ut_params->obuf,
8762 					plaintext_pad_len + aad_pad_len);
8763 			TEST_ASSERT_NOT_NULL(plaintext,
8764 					"no room to append plaintext");
8765 
8766 			memset(plaintext + aad_pad_len, 0,
8767 					tdata->plaintext.len);
8768 		}
8769 	}
8770 
8771 	/* Append digest data */
8772 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
8773 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8774 				ut_params->obuf ? ut_params->obuf :
8775 						ut_params->ibuf,
8776 						tdata->auth_tag.len);
8777 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8778 				"no room to append digest");
8779 		memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
8780 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8781 				ut_params->obuf ? ut_params->obuf :
8782 						ut_params->ibuf,
8783 						plaintext_pad_len +
8784 						aad_pad_len);
8785 	} else {
8786 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8787 				ut_params->ibuf, tdata->auth_tag.len);
8788 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8789 				"no room to append digest");
8790 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8791 				ut_params->ibuf,
8792 				plaintext_pad_len + aad_pad_len);
8793 
8794 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
8795 			tdata->auth_tag.len);
8796 		debug_hexdump(stdout, "digest:",
8797 			sym_op->aead.digest.data,
8798 			tdata->auth_tag.len);
8799 	}
8800 
8801 	sym_op->aead.data.length = tdata->plaintext.len;
8802 	sym_op->aead.data.offset = aad_pad_len;
8803 
8804 	return 0;
8805 }
8806 
8807 static int
8808 test_authenticated_encryption(const struct aead_test_data *tdata)
8809 {
8810 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8811 	struct crypto_unittest_params *ut_params = &unittest_params;
8812 
8813 	int retval;
8814 	uint8_t *ciphertext, *auth_tag;
8815 	uint16_t plaintext_pad_len;
8816 	uint32_t i;
8817 	struct rte_cryptodev_info dev_info;
8818 
8819 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8820 	uint64_t feat_flags = dev_info.feature_flags;
8821 
8822 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8823 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8824 		printf("Device doesn't support RAW data-path APIs.\n");
8825 		return TEST_SKIPPED;
8826 	}
8827 
8828 	/* Verify the capabilities */
8829 	struct rte_cryptodev_sym_capability_idx cap_idx;
8830 	const struct rte_cryptodev_symmetric_capability *capability;
8831 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8832 	cap_idx.algo.aead = tdata->algo;
8833 	capability = rte_cryptodev_sym_capability_get(
8834 			ts_params->valid_devs[0], &cap_idx);
8835 	if (capability == NULL)
8836 		return TEST_SKIPPED;
8837 	if (rte_cryptodev_sym_capability_check_aead(
8838 			capability, tdata->key.len, tdata->auth_tag.len,
8839 			tdata->aad.len, tdata->iv.len))
8840 		return TEST_SKIPPED;
8841 
8842 	/* Create AEAD session */
8843 	retval = create_aead_session(ts_params->valid_devs[0],
8844 			tdata->algo,
8845 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
8846 			tdata->key.data, tdata->key.len,
8847 			tdata->aad.len, tdata->auth_tag.len,
8848 			tdata->iv.len);
8849 	if (retval != TEST_SUCCESS)
8850 		return retval;
8851 
8852 	if (tdata->aad.len > MBUF_SIZE) {
8853 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8854 		/* Populate full size of add data */
8855 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
8856 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
8857 	} else
8858 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8859 
8860 	/* clear mbuf payload */
8861 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8862 			rte_pktmbuf_tailroom(ut_params->ibuf));
8863 
8864 	/* Create AEAD operation */
8865 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8866 	if (retval < 0)
8867 		return retval;
8868 
8869 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8870 
8871 	ut_params->op->sym->m_src = ut_params->ibuf;
8872 
8873 	/* Process crypto operation */
8874 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8875 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
8876 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
8877 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0,
8878 					       0);
8879 		if (retval != TEST_SUCCESS)
8880 			return retval;
8881 	} else
8882 		TEST_ASSERT_NOT_NULL(
8883 			process_crypto_request(ts_params->valid_devs[0],
8884 			ut_params->op), "failed to process sym crypto op");
8885 
8886 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8887 			"crypto op processing failed");
8888 
8889 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8890 
8891 	if (ut_params->op->sym->m_dst) {
8892 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8893 				uint8_t *);
8894 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8895 				uint8_t *, plaintext_pad_len);
8896 	} else {
8897 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8898 				uint8_t *,
8899 				ut_params->op->sym->cipher.data.offset);
8900 		auth_tag = ciphertext + plaintext_pad_len;
8901 	}
8902 
8903 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8904 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8905 
8906 	/* Validate obuf */
8907 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
8908 			ciphertext,
8909 			tdata->ciphertext.data,
8910 			tdata->ciphertext.len,
8911 			"Ciphertext data not as expected");
8912 
8913 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
8914 			auth_tag,
8915 			tdata->auth_tag.data,
8916 			tdata->auth_tag.len,
8917 			"Generated auth tag not as expected");
8918 
8919 	return 0;
8920 
8921 }
8922 
8923 #ifdef RTE_LIB_SECURITY
8924 static int
8925 security_proto_supported(enum rte_security_session_action_type action,
8926 	enum rte_security_session_protocol proto)
8927 {
8928 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8929 
8930 	const struct rte_security_capability *capabilities;
8931 	const struct rte_security_capability *capability;
8932 	uint16_t i = 0;
8933 
8934 	void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]);
8935 
8936 
8937 	capabilities = rte_security_capabilities_get(ctx);
8938 
8939 	if (capabilities == NULL)
8940 		return -ENOTSUP;
8941 
8942 	while ((capability = &capabilities[i++])->action !=
8943 			RTE_SECURITY_ACTION_TYPE_NONE) {
8944 		if (capability->action == action &&
8945 				capability->protocol == proto)
8946 			return 0;
8947 	}
8948 
8949 	return -ENOTSUP;
8950 }
8951 
8952 /* Basic algorithm run function for async inplace mode.
8953  * Creates a session from input parameters and runs one operation
8954  * on input_vec. Checks the output of the crypto operation against
8955  * output_vec.
8956  */
8957 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
8958 			   enum rte_crypto_auth_operation opa,
8959 			   const uint8_t *input_vec, unsigned int input_vec_len,
8960 			   const uint8_t *output_vec,
8961 			   unsigned int output_vec_len,
8962 			   enum rte_crypto_cipher_algorithm cipher_alg,
8963 			   const uint8_t *cipher_key, uint32_t cipher_key_len,
8964 			   enum rte_crypto_auth_algorithm auth_alg,
8965 			   const uint8_t *auth_key, uint32_t auth_key_len,
8966 			   uint8_t bearer, enum rte_security_pdcp_domain domain,
8967 			   uint8_t packet_direction, uint8_t sn_size,
8968 			   uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
8969 {
8970 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8971 	struct crypto_unittest_params *ut_params = &unittest_params;
8972 	uint8_t *plaintext;
8973 	int ret = TEST_SUCCESS;
8974 	void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]);
8975 	struct rte_cryptodev_info dev_info;
8976 	uint64_t feat_flags;
8977 
8978 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8979 	feat_flags = dev_info.feature_flags;
8980 
8981 	/* Verify the capabilities */
8982 	struct rte_security_capability_idx sec_cap_idx;
8983 
8984 	sec_cap_idx.action = ut_params->type;
8985 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8986 	sec_cap_idx.pdcp.domain = domain;
8987 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8988 		return TEST_SKIPPED;
8989 
8990 	/* Generate test mbuf data */
8991 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8992 
8993 	/* clear mbuf payload */
8994 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8995 			rte_pktmbuf_tailroom(ut_params->ibuf));
8996 
8997 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8998 						  input_vec_len);
8999 	memcpy(plaintext, input_vec, input_vec_len);
9000 
9001 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
9002 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
9003 		printf("Device does not support RAW data-path APIs.\n");
9004 		return TEST_SKIPPED;
9005 	}
9006 	/* Out of place support */
9007 	if (oop) {
9008 		/*
9009 		 * For out-op-place we need to alloc another mbuf
9010 		 */
9011 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9012 		rte_pktmbuf_append(ut_params->obuf, output_vec_len);
9013 	}
9014 
9015 	/* Setup Cipher Parameters */
9016 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9017 	ut_params->cipher_xform.cipher.algo = cipher_alg;
9018 	ut_params->cipher_xform.cipher.op = opc;
9019 	ut_params->cipher_xform.cipher.key.data = cipher_key;
9020 	ut_params->cipher_xform.cipher.key.length = cipher_key_len;
9021 	ut_params->cipher_xform.cipher.iv.length =
9022 				packet_direction ? 4 : 0;
9023 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9024 
9025 	/* Setup HMAC Parameters if ICV header is required */
9026 	if (auth_alg != 0) {
9027 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9028 		ut_params->auth_xform.next = NULL;
9029 		ut_params->auth_xform.auth.algo = auth_alg;
9030 		ut_params->auth_xform.auth.op = opa;
9031 		ut_params->auth_xform.auth.key.data = auth_key;
9032 		ut_params->auth_xform.auth.key.length = auth_key_len;
9033 
9034 		ut_params->cipher_xform.next = &ut_params->auth_xform;
9035 	} else {
9036 		ut_params->cipher_xform.next = NULL;
9037 	}
9038 
9039 	struct rte_security_session_conf sess_conf = {
9040 		.action_type = ut_params->type,
9041 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
9042 		{.pdcp = {
9043 			.bearer = bearer,
9044 			.domain = domain,
9045 			.pkt_dir = packet_direction,
9046 			.sn_size = sn_size,
9047 			.hfn = packet_direction ? 0 : hfn,
9048 			/**
9049 			 * hfn can be set as pdcp_test_hfn[i]
9050 			 * if hfn_ovrd is not set. Here, PDCP
9051 			 * packet direction is just used to
9052 			 * run half of the cases with session
9053 			 * HFN and other half with per packet
9054 			 * HFN.
9055 			 */
9056 			.hfn_threshold = hfn_threshold,
9057 			.hfn_ovrd = packet_direction ? 1 : 0,
9058 			.sdap_enabled = sdap,
9059 		} },
9060 		.crypto_xform = &ut_params->cipher_xform
9061 	};
9062 
9063 	/* Create security session */
9064 	ut_params->sec_session = rte_security_session_create(ctx,
9065 				&sess_conf, ts_params->session_mpool);
9066 
9067 	if (!ut_params->sec_session) {
9068 		printf("TestCase %s()-%d line %d failed %s: ",
9069 			__func__, i, __LINE__, "Failed to allocate session");
9070 		ret = TEST_FAILED;
9071 		goto on_err;
9072 	}
9073 
9074 	/* Generate crypto op data structure */
9075 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9076 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9077 	if (!ut_params->op) {
9078 		printf("TestCase %s()-%d line %d failed %s: ",
9079 			__func__, i, __LINE__,
9080 			"Failed to allocate symmetric crypto operation struct");
9081 		ret = TEST_FAILED;
9082 		goto on_err;
9083 	}
9084 
9085 	uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
9086 					uint32_t *, IV_OFFSET);
9087 	*per_pkt_hfn = packet_direction ? hfn : 0;
9088 
9089 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
9090 
9091 	/* set crypto operation source mbuf */
9092 	ut_params->op->sym->m_src = ut_params->ibuf;
9093 	if (oop)
9094 		ut_params->op->sym->m_dst = ut_params->obuf;
9095 
9096 	/* Process crypto operation */
9097 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
9098 		/* filling lengths */
9099 		ut_params->op->sym->cipher.data.length = ut_params->op->sym->m_src->pkt_len;
9100 		ut_params->op->sym->auth.data.length = ut_params->op->sym->m_src->pkt_len;
9101 
9102 		ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 0);
9103 		if (ret != TEST_SUCCESS)
9104 			return ret;
9105 	} else {
9106 		ut_params->op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
9107 	}
9108 	if (ut_params->op == NULL) {
9109 		printf("TestCase %s()-%d line %d failed %s: ",
9110 			__func__, i, __LINE__,
9111 			"failed to process sym crypto op");
9112 		ret = TEST_FAILED;
9113 		goto on_err;
9114 	}
9115 
9116 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9117 		printf("TestCase %s()-%d line %d failed %s: ",
9118 			__func__, i, __LINE__, "crypto op processing failed");
9119 		ret = TEST_FAILED;
9120 		goto on_err;
9121 	}
9122 
9123 	/* Validate obuf */
9124 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
9125 			uint8_t *);
9126 	if (oop) {
9127 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
9128 				uint8_t *);
9129 	}
9130 
9131 	if (memcmp(ciphertext, output_vec, output_vec_len)) {
9132 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
9133 		rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
9134 		rte_hexdump(stdout, "reference", output_vec, output_vec_len);
9135 		ret = TEST_FAILED;
9136 		goto on_err;
9137 	}
9138 
9139 on_err:
9140 	rte_crypto_op_free(ut_params->op);
9141 	ut_params->op = NULL;
9142 
9143 	if (ut_params->sec_session)
9144 		rte_security_session_destroy(ctx, ut_params->sec_session);
9145 	ut_params->sec_session = NULL;
9146 
9147 	rte_pktmbuf_free(ut_params->ibuf);
9148 	ut_params->ibuf = NULL;
9149 	if (oop) {
9150 		rte_pktmbuf_free(ut_params->obuf);
9151 		ut_params->obuf = NULL;
9152 	}
9153 
9154 	return ret;
9155 }
9156 
9157 static int
9158 test_pdcp_proto_SGL(int i, int oop,
9159 	enum rte_crypto_cipher_operation opc,
9160 	enum rte_crypto_auth_operation opa,
9161 	uint8_t *input_vec,
9162 	unsigned int input_vec_len,
9163 	uint8_t *output_vec,
9164 	unsigned int output_vec_len,
9165 	uint32_t fragsz,
9166 	uint32_t fragsz_oop)
9167 {
9168 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9169 	struct crypto_unittest_params *ut_params = &unittest_params;
9170 	uint8_t *plaintext;
9171 	struct rte_mbuf *buf, *buf_oop = NULL;
9172 	int ret = TEST_SUCCESS;
9173 	int to_trn = 0;
9174 	int to_trn_tbl[16];
9175 	int segs = 1;
9176 	unsigned int trn_data = 0;
9177 	struct rte_cryptodev_info dev_info;
9178 	uint64_t feat_flags;
9179 	void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]);
9180 	struct rte_mbuf *temp_mbuf;
9181 
9182 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9183 	feat_flags = dev_info.feature_flags;
9184 
9185 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
9186 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
9187 		printf("Device does not support RAW data-path APIs.\n");
9188 		return -ENOTSUP;
9189 	}
9190 	/* Verify the capabilities */
9191 	struct rte_security_capability_idx sec_cap_idx;
9192 
9193 	sec_cap_idx.action = ut_params->type;
9194 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
9195 	sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
9196 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
9197 		return TEST_SKIPPED;
9198 
9199 	if (fragsz > input_vec_len)
9200 		fragsz = input_vec_len;
9201 
9202 	uint16_t plaintext_len = fragsz;
9203 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
9204 
9205 	if (fragsz_oop > output_vec_len)
9206 		frag_size_oop = output_vec_len;
9207 
9208 	int ecx = 0;
9209 	if (input_vec_len % fragsz != 0) {
9210 		if (input_vec_len / fragsz + 1 > 16)
9211 			return 1;
9212 	} else if (input_vec_len / fragsz > 16)
9213 		return 1;
9214 
9215 	/* Out of place support */
9216 	if (oop) {
9217 		/*
9218 		 * For out-op-place we need to alloc another mbuf
9219 		 */
9220 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9221 		rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
9222 		buf_oop = ut_params->obuf;
9223 	}
9224 
9225 	/* Generate test mbuf data */
9226 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9227 
9228 	/* clear mbuf payload */
9229 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9230 			rte_pktmbuf_tailroom(ut_params->ibuf));
9231 
9232 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9233 						  plaintext_len);
9234 	memcpy(plaintext, input_vec, plaintext_len);
9235 	trn_data += plaintext_len;
9236 
9237 	buf = ut_params->ibuf;
9238 
9239 	/*
9240 	 * Loop until no more fragments
9241 	 */
9242 
9243 	while (trn_data < input_vec_len) {
9244 		++segs;
9245 		to_trn = (input_vec_len - trn_data < fragsz) ?
9246 				(input_vec_len - trn_data) : fragsz;
9247 
9248 		to_trn_tbl[ecx++] = to_trn;
9249 
9250 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9251 		buf = buf->next;
9252 
9253 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
9254 				rte_pktmbuf_tailroom(buf));
9255 
9256 		/* OOP */
9257 		if (oop && !fragsz_oop) {
9258 			buf_oop->next =
9259 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
9260 			buf_oop = buf_oop->next;
9261 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
9262 					0, rte_pktmbuf_tailroom(buf_oop));
9263 			rte_pktmbuf_append(buf_oop, to_trn);
9264 		}
9265 
9266 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
9267 				to_trn);
9268 
9269 		memcpy(plaintext, input_vec + trn_data, to_trn);
9270 		trn_data += to_trn;
9271 	}
9272 
9273 	ut_params->ibuf->nb_segs = segs;
9274 
9275 	segs = 1;
9276 	if (fragsz_oop && oop) {
9277 		to_trn = 0;
9278 		ecx = 0;
9279 
9280 		trn_data = frag_size_oop;
9281 		while (trn_data < output_vec_len) {
9282 			++segs;
9283 			to_trn =
9284 				(output_vec_len - trn_data <
9285 						frag_size_oop) ?
9286 				(output_vec_len - trn_data) :
9287 						frag_size_oop;
9288 
9289 			to_trn_tbl[ecx++] = to_trn;
9290 
9291 			buf_oop->next =
9292 				rte_pktmbuf_alloc(ts_params->mbuf_pool);
9293 			buf_oop = buf_oop->next;
9294 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
9295 					0, rte_pktmbuf_tailroom(buf_oop));
9296 			rte_pktmbuf_append(buf_oop, to_trn);
9297 
9298 			trn_data += to_trn;
9299 		}
9300 		ut_params->obuf->nb_segs = segs;
9301 	}
9302 
9303 	/* Setup Cipher Parameters */
9304 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9305 	ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
9306 	ut_params->cipher_xform.cipher.op = opc;
9307 	ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
9308 	ut_params->cipher_xform.cipher.key.length =
9309 					pdcp_test_params[i].cipher_key_len;
9310 	ut_params->cipher_xform.cipher.iv.length = 0;
9311 
9312 	/* Setup HMAC Parameters if ICV header is required */
9313 	if (pdcp_test_params[i].auth_alg != 0) {
9314 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9315 		ut_params->auth_xform.next = NULL;
9316 		ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
9317 		ut_params->auth_xform.auth.op = opa;
9318 		ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
9319 		ut_params->auth_xform.auth.key.length =
9320 					pdcp_test_params[i].auth_key_len;
9321 
9322 		ut_params->cipher_xform.next = &ut_params->auth_xform;
9323 	} else {
9324 		ut_params->cipher_xform.next = NULL;
9325 	}
9326 
9327 	struct rte_security_session_conf sess_conf = {
9328 		.action_type = ut_params->type,
9329 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
9330 		{.pdcp = {
9331 			.bearer = pdcp_test_bearer[i],
9332 			.domain = pdcp_test_params[i].domain,
9333 			.pkt_dir = pdcp_test_packet_direction[i],
9334 			.sn_size = pdcp_test_data_sn_size[i],
9335 			.hfn = pdcp_test_hfn[i],
9336 			.hfn_threshold = pdcp_test_hfn_threshold[i],
9337 			.hfn_ovrd = 0,
9338 		} },
9339 		.crypto_xform = &ut_params->cipher_xform
9340 	};
9341 
9342 	/* Create security session */
9343 	ut_params->sec_session = rte_security_session_create(ctx,
9344 				&sess_conf, ts_params->session_mpool);
9345 
9346 	if (!ut_params->sec_session) {
9347 		printf("TestCase %s()-%d line %d failed %s: ",
9348 			__func__, i, __LINE__, "Failed to allocate session");
9349 		ret = TEST_FAILED;
9350 		goto on_err;
9351 	}
9352 
9353 	/* Generate crypto op data structure */
9354 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9355 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9356 	if (!ut_params->op) {
9357 		printf("TestCase %s()-%d line %d failed %s: ",
9358 			__func__, i, __LINE__,
9359 			"Failed to allocate symmetric crypto operation struct");
9360 		ret = TEST_FAILED;
9361 		goto on_err;
9362 	}
9363 
9364 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
9365 
9366 	/* set crypto operation source mbuf */
9367 	ut_params->op->sym->m_src = ut_params->ibuf;
9368 	if (oop)
9369 		ut_params->op->sym->m_dst = ut_params->obuf;
9370 
9371 	/* Process crypto operation */
9372 	temp_mbuf = ut_params->op->sym->m_src;
9373 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
9374 		/* filling lengths */
9375 		while (temp_mbuf) {
9376 			ut_params->op->sym->cipher.data.length
9377 				+= temp_mbuf->pkt_len;
9378 			ut_params->op->sym->auth.data.length
9379 				+= temp_mbuf->pkt_len;
9380 			temp_mbuf = temp_mbuf->next;
9381 		}
9382 
9383 		ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 0);
9384 		if (ret != TEST_SUCCESS)
9385 			return ret;
9386 	} else {
9387 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
9388 							ut_params->op);
9389 	}
9390 	if (ut_params->op == NULL) {
9391 		printf("TestCase %s()-%d line %d failed %s: ",
9392 			__func__, i, __LINE__,
9393 			"failed to process sym crypto op");
9394 		ret = TEST_FAILED;
9395 		goto on_err;
9396 	}
9397 
9398 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9399 		printf("TestCase %s()-%d line %d failed %s: ",
9400 			__func__, i, __LINE__, "crypto op processing failed");
9401 		ret = TEST_FAILED;
9402 		goto on_err;
9403 	}
9404 
9405 	/* Validate obuf */
9406 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
9407 			uint8_t *);
9408 	if (oop) {
9409 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
9410 				uint8_t *);
9411 	}
9412 	if (fragsz_oop)
9413 		fragsz = frag_size_oop;
9414 	if (memcmp(ciphertext, output_vec, fragsz)) {
9415 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
9416 		rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
9417 		rte_hexdump(stdout, "reference", output_vec, fragsz);
9418 		ret = TEST_FAILED;
9419 		goto on_err;
9420 	}
9421 
9422 	buf = ut_params->op->sym->m_src->next;
9423 	if (oop)
9424 		buf = ut_params->op->sym->m_dst->next;
9425 
9426 	unsigned int off = fragsz;
9427 
9428 	ecx = 0;
9429 	while (buf) {
9430 		ciphertext = rte_pktmbuf_mtod(buf,
9431 				uint8_t *);
9432 		if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
9433 			printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
9434 			rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
9435 			rte_hexdump(stdout, "reference", output_vec + off,
9436 					to_trn_tbl[ecx]);
9437 			ret = TEST_FAILED;
9438 			goto on_err;
9439 		}
9440 		off += to_trn_tbl[ecx++];
9441 		buf = buf->next;
9442 	}
9443 on_err:
9444 	rte_crypto_op_free(ut_params->op);
9445 	ut_params->op = NULL;
9446 
9447 	if (ut_params->sec_session)
9448 		rte_security_session_destroy(ctx, ut_params->sec_session);
9449 	ut_params->sec_session = NULL;
9450 
9451 	rte_pktmbuf_free(ut_params->ibuf);
9452 	ut_params->ibuf = NULL;
9453 	if (oop) {
9454 		rte_pktmbuf_free(ut_params->obuf);
9455 		ut_params->obuf = NULL;
9456 	}
9457 
9458 	return ret;
9459 }
9460 
9461 int
9462 test_pdcp_proto_cplane_encap(int i)
9463 {
9464 	return test_pdcp_proto(
9465 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
9466 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
9467 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
9468 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
9469 		pdcp_test_params[i].cipher_key_len,
9470 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
9471 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
9472 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
9473 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
9474 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
9475 }
9476 
9477 int
9478 test_pdcp_proto_uplane_encap(int i)
9479 {
9480 	return test_pdcp_proto(
9481 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
9482 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
9483 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
9484 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
9485 		pdcp_test_params[i].cipher_key_len,
9486 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
9487 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
9488 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
9489 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
9490 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
9491 }
9492 
9493 int
9494 test_pdcp_proto_uplane_encap_with_int(int i)
9495 {
9496 	return test_pdcp_proto(
9497 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
9498 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
9499 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
9500 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
9501 		pdcp_test_params[i].cipher_key_len,
9502 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
9503 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
9504 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
9505 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
9506 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
9507 }
9508 
9509 int
9510 test_pdcp_proto_cplane_decap(int i)
9511 {
9512 	return test_pdcp_proto(
9513 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
9514 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
9515 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
9516 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
9517 		pdcp_test_params[i].cipher_key_len,
9518 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
9519 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
9520 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
9521 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
9522 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
9523 }
9524 
9525 int
9526 test_pdcp_proto_uplane_decap(int i)
9527 {
9528 	return test_pdcp_proto(
9529 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
9530 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
9531 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
9532 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
9533 		pdcp_test_params[i].cipher_key_len,
9534 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
9535 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
9536 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
9537 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
9538 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
9539 }
9540 
9541 int
9542 test_pdcp_proto_uplane_decap_with_int(int i)
9543 {
9544 	return test_pdcp_proto(
9545 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
9546 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
9547 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
9548 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
9549 		pdcp_test_params[i].cipher_key_len,
9550 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
9551 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
9552 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
9553 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
9554 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
9555 }
9556 
9557 static int
9558 test_PDCP_PROTO_SGL_in_place_32B(void)
9559 {
9560 	/* i can be used for running any PDCP case
9561 	 * In this case it is uplane 12-bit AES-SNOW DL encap
9562 	 */
9563 	int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
9564 	return test_pdcp_proto_SGL(i, IN_PLACE,
9565 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
9566 			RTE_CRYPTO_AUTH_OP_GENERATE,
9567 			pdcp_test_data_in[i],
9568 			pdcp_test_data_in_len[i],
9569 			pdcp_test_data_out[i],
9570 			pdcp_test_data_in_len[i]+4,
9571 			32, 0);
9572 }
9573 static int
9574 test_PDCP_PROTO_SGL_oop_32B_128B(void)
9575 {
9576 	/* i can be used for running any PDCP case
9577 	 * In this case it is uplane 18-bit NULL-NULL DL encap
9578 	 */
9579 	int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
9580 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
9581 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
9582 			RTE_CRYPTO_AUTH_OP_GENERATE,
9583 			pdcp_test_data_in[i],
9584 			pdcp_test_data_in_len[i],
9585 			pdcp_test_data_out[i],
9586 			pdcp_test_data_in_len[i]+4,
9587 			32, 128);
9588 }
9589 static int
9590 test_PDCP_PROTO_SGL_oop_32B_40B(void)
9591 {
9592 	/* i can be used for running any PDCP case
9593 	 * In this case it is uplane 18-bit AES DL encap
9594 	 */
9595 	int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
9596 			+ DOWNLINK;
9597 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
9598 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
9599 			RTE_CRYPTO_AUTH_OP_GENERATE,
9600 			pdcp_test_data_in[i],
9601 			pdcp_test_data_in_len[i],
9602 			pdcp_test_data_out[i],
9603 			pdcp_test_data_in_len[i],
9604 			32, 40);
9605 }
9606 static int
9607 test_PDCP_PROTO_SGL_oop_128B_32B(void)
9608 {
9609 	/* i can be used for running any PDCP case
9610 	 * In this case it is cplane 12-bit AES-ZUC DL encap
9611 	 */
9612 	int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
9613 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
9614 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
9615 			RTE_CRYPTO_AUTH_OP_GENERATE,
9616 			pdcp_test_data_in[i],
9617 			pdcp_test_data_in_len[i],
9618 			pdcp_test_data_out[i],
9619 			pdcp_test_data_in_len[i]+4,
9620 			128, 32);
9621 }
9622 
9623 static int
9624 test_PDCP_SDAP_PROTO_encap_all(void)
9625 {
9626 	int i = 0, size = 0;
9627 	int err, all_err = TEST_SUCCESS;
9628 	const struct pdcp_sdap_test *cur_test;
9629 
9630 	size = RTE_DIM(list_pdcp_sdap_tests);
9631 
9632 	for (i = 0; i < size; i++) {
9633 		cur_test = &list_pdcp_sdap_tests[i];
9634 		err = test_pdcp_proto(
9635 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
9636 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
9637 			cur_test->in_len, cur_test->data_out,
9638 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
9639 			cur_test->param.cipher_alg, cur_test->cipher_key,
9640 			cur_test->param.cipher_key_len,
9641 			cur_test->param.auth_alg,
9642 			cur_test->auth_key, cur_test->param.auth_key_len,
9643 			cur_test->bearer, cur_test->param.domain,
9644 			cur_test->packet_direction, cur_test->sn_size,
9645 			cur_test->hfn,
9646 			cur_test->hfn_threshold, SDAP_ENABLED);
9647 		if (err) {
9648 			printf("\t%d) %s: Encapsulation failed\n",
9649 					cur_test->test_idx,
9650 					cur_test->param.name);
9651 			err = TEST_FAILED;
9652 		} else {
9653 			printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
9654 					cur_test->param.name);
9655 			err = TEST_SUCCESS;
9656 		}
9657 		all_err += err;
9658 	}
9659 
9660 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
9661 
9662 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
9663 }
9664 
9665 static int
9666 test_PDCP_PROTO_short_mac(void)
9667 {
9668 	int i = 0, size = 0;
9669 	int err, all_err = TEST_SUCCESS;
9670 	const struct pdcp_short_mac_test *cur_test;
9671 
9672 	size = RTE_DIM(list_pdcp_smac_tests);
9673 
9674 	for (i = 0; i < size; i++) {
9675 		cur_test = &list_pdcp_smac_tests[i];
9676 		err = test_pdcp_proto(
9677 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
9678 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
9679 			cur_test->in_len, cur_test->data_out,
9680 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
9681 			RTE_CRYPTO_CIPHER_NULL, NULL,
9682 			0, cur_test->param.auth_alg,
9683 			cur_test->auth_key, cur_test->param.auth_key_len,
9684 			0, cur_test->param.domain, 0, 0,
9685 			0, 0, 0);
9686 		if (err) {
9687 			printf("\t%d) %s: Short MAC test failed\n",
9688 					cur_test->test_idx,
9689 					cur_test->param.name);
9690 			err = TEST_FAILED;
9691 		} else {
9692 			printf("\t%d) %s: Short MAC test PASS\n",
9693 					cur_test->test_idx,
9694 					cur_test->param.name);
9695 			rte_hexdump(stdout, "MAC I",
9696 				    cur_test->data_out + cur_test->in_len + 2,
9697 				    2);
9698 			err = TEST_SUCCESS;
9699 		}
9700 		all_err += err;
9701 	}
9702 
9703 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
9704 
9705 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
9706 
9707 }
9708 
9709 static int
9710 test_PDCP_SDAP_PROTO_decap_all(void)
9711 {
9712 	int i = 0, size = 0;
9713 	int err, all_err = TEST_SUCCESS;
9714 	const struct pdcp_sdap_test *cur_test;
9715 
9716 	size = RTE_DIM(list_pdcp_sdap_tests);
9717 
9718 	for (i = 0; i < size; i++) {
9719 		cur_test = &list_pdcp_sdap_tests[i];
9720 		err = test_pdcp_proto(
9721 			i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
9722 			RTE_CRYPTO_AUTH_OP_VERIFY,
9723 			cur_test->data_out,
9724 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
9725 			cur_test->data_in, cur_test->in_len,
9726 			cur_test->param.cipher_alg,
9727 			cur_test->cipher_key, cur_test->param.cipher_key_len,
9728 			cur_test->param.auth_alg, cur_test->auth_key,
9729 			cur_test->param.auth_key_len, cur_test->bearer,
9730 			cur_test->param.domain, cur_test->packet_direction,
9731 			cur_test->sn_size, cur_test->hfn,
9732 			cur_test->hfn_threshold, SDAP_ENABLED);
9733 		if (err) {
9734 			printf("\t%d) %s: Decapsulation failed\n",
9735 					cur_test->test_idx,
9736 					cur_test->param.name);
9737 			err = TEST_FAILED;
9738 		} else {
9739 			printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
9740 					cur_test->param.name);
9741 			err = TEST_SUCCESS;
9742 		}
9743 		all_err += err;
9744 	}
9745 
9746 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
9747 
9748 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
9749 }
9750 
9751 static inline void
9752 ext_mbuf_callback_fn_free(void *addr __rte_unused, void *opaque __rte_unused)
9753 {
9754 }
9755 
9756 static inline void
9757 ext_mbuf_memzone_free(int nb_segs)
9758 {
9759 	int i;
9760 
9761 	for (i = 0; i <= nb_segs; i++) {
9762 		char mz_name[RTE_MEMZONE_NAMESIZE];
9763 		const struct rte_memzone *memzone;
9764 		snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "ext_buf_%d", i);
9765 		memzone = rte_memzone_lookup(mz_name);
9766 		if (memzone != NULL) {
9767 			rte_memzone_free(memzone);
9768 			memzone = NULL;
9769 		}
9770 	}
9771 }
9772 
9773 static inline struct rte_mbuf *
9774 ext_mbuf_create(struct rte_mempool *mbuf_pool, int pkt_len,
9775 		int nb_segs, const void *input_text)
9776 {
9777 	struct rte_mbuf *m = NULL, *mbuf = NULL;
9778 	size_t data_off = 0;
9779 	uint8_t *dst;
9780 	int i, size;
9781 	int t_len;
9782 
9783 	if (pkt_len < 1) {
9784 		printf("Packet size must be 1 or more (is %d)\n", pkt_len);
9785 		return NULL;
9786 	}
9787 
9788 	if (nb_segs < 1) {
9789 		printf("Number of segments must be 1 or more (is %d)\n",
9790 				nb_segs);
9791 		return NULL;
9792 	}
9793 
9794 	t_len = pkt_len >= nb_segs ? pkt_len / nb_segs : 1;
9795 	size = pkt_len;
9796 
9797 	/* Create chained mbuf_src with external buffer */
9798 	for (i = 0; size > 0; i++) {
9799 		struct rte_mbuf_ext_shared_info *ret_shinfo = NULL;
9800 		uint16_t data_len = RTE_MIN(size, t_len);
9801 		char mz_name[RTE_MEMZONE_NAMESIZE];
9802 		const struct rte_memzone *memzone;
9803 		void *ext_buf_addr = NULL;
9804 		rte_iova_t buf_iova;
9805 		bool freed = false;
9806 		uint16_t buf_len;
9807 
9808 		buf_len = RTE_ALIGN_CEIL(data_len + 1024 +
9809 			sizeof(struct rte_mbuf_ext_shared_info), 8);
9810 
9811 		snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "ext_buf_%d", i);
9812 		memzone = rte_memzone_lookup(mz_name);
9813 		if (memzone != NULL && memzone->len != buf_len) {
9814 			rte_memzone_free(memzone);
9815 			memzone = NULL;
9816 		}
9817 		if (memzone == NULL) {
9818 			memzone = rte_memzone_reserve_aligned(mz_name, buf_len, SOCKET_ID_ANY,
9819 				RTE_MEMZONE_IOVA_CONTIG, RTE_CACHE_LINE_SIZE);
9820 			if (memzone == NULL) {
9821 				printf("Can't allocate memory zone %s\n", mz_name);
9822 				return NULL;
9823 			}
9824 		}
9825 
9826 		ext_buf_addr = memzone->addr;
9827 		memcpy(ext_buf_addr, RTE_PTR_ADD(input_text, data_off), data_len);
9828 
9829 		/* Create buffer to hold rte_mbuf header */
9830 		m = rte_pktmbuf_alloc(mbuf_pool);
9831 		if (i == 0)
9832 			mbuf = m;
9833 
9834 		if (m == NULL) {
9835 			printf("Cannot create segment for source mbuf");
9836 			goto fail;
9837 		}
9838 
9839 		/* Save shared data (like callback function) in external buffer's end */
9840 		ret_shinfo = rte_pktmbuf_ext_shinfo_init_helper(ext_buf_addr, &buf_len,
9841 			ext_mbuf_callback_fn_free, &freed);
9842 		if (ret_shinfo == NULL) {
9843 			printf("Shared mem initialization failed!\n");
9844 			goto fail;
9845 		}
9846 
9847 		buf_iova = rte_mem_virt2iova(ext_buf_addr);
9848 
9849 		/* Attach external buffer to mbuf */
9850 		rte_pktmbuf_attach_extbuf(m, ext_buf_addr, buf_iova, buf_len,
9851 			ret_shinfo);
9852 		if (m->ol_flags != RTE_MBUF_F_EXTERNAL) {
9853 			printf("External buffer is not attached to mbuf\n");
9854 			goto fail;
9855 		}
9856 
9857 		dst = (uint8_t *)rte_pktmbuf_append(m, data_len);
9858 		if (dst == NULL) {
9859 			printf("Cannot append %d bytes to the mbuf\n", data_len);
9860 			goto fail;
9861 		}
9862 
9863 		if (mbuf != m)
9864 			rte_pktmbuf_chain(mbuf, m);
9865 
9866 		size -= data_len;
9867 		data_off += data_len;
9868 	}
9869 
9870 	return mbuf;
9871 
9872 fail:
9873 	rte_pktmbuf_free(mbuf);
9874 	ext_mbuf_memzone_free(nb_segs);
9875 	return NULL;
9876 }
9877 
9878 static int
9879 test_ipsec_proto_process(const struct ipsec_test_data td[],
9880 			 struct ipsec_test_data res_d[],
9881 			 int nb_td,
9882 			 bool silent,
9883 			 const struct ipsec_test_flags *flags)
9884 {
9885 	uint16_t v6_src[8] = {0x2607, 0xf8b0, 0x400c, 0x0c03, 0x0000, 0x0000,
9886 				0x0000, 0x001a};
9887 	uint16_t v6_dst[8] = {0x2001, 0x0470, 0xe5bf, 0xdead, 0x4957, 0x2174,
9888 				0xe82c, 0x4887};
9889 	const struct rte_ipv4_hdr *ipv4 =
9890 			(const struct rte_ipv4_hdr *)td[0].output_text.data;
9891 	int nb_segs = flags->nb_segs_in_mbuf ? flags->nb_segs_in_mbuf : 1;
9892 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9893 	struct crypto_unittest_params *ut_params = &unittest_params;
9894 	struct rte_security_capability_idx sec_cap_idx;
9895 	const struct rte_security_capability *sec_cap;
9896 	struct rte_security_ipsec_xform ipsec_xform;
9897 	uint8_t dev_id = ts_params->valid_devs[0];
9898 	enum rte_security_ipsec_sa_direction dir;
9899 	struct ipsec_test_data *res_d_tmp = NULL;
9900 	uint8_t input_text[IPSEC_TEXT_MAX_LEN];
9901 	int salt_len, i, ret = TEST_SUCCESS;
9902 	void *ctx;
9903 	uint32_t src, dst;
9904 	uint32_t verify;
9905 
9906 	ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
9907 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
9908 
9909 	/* Use first test data to create session */
9910 
9911 	/* Copy IPsec xform */
9912 	memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform));
9913 
9914 	dir = ipsec_xform.direction;
9915 	verify = flags->tunnel_hdr_verify;
9916 
9917 	memcpy(&src, &ipv4->src_addr, sizeof(ipv4->src_addr));
9918 	memcpy(&dst, &ipv4->dst_addr, sizeof(ipv4->dst_addr));
9919 
9920 	if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) {
9921 		if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR)
9922 			src += 1;
9923 		else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR)
9924 			dst += 1;
9925 	}
9926 
9927 	if (td->ipsec_xform.mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) {
9928 		if (td->ipsec_xform.tunnel.type ==
9929 				RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
9930 			memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src,
9931 			       sizeof(src));
9932 			memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst,
9933 			       sizeof(dst));
9934 
9935 			if (flags->df == TEST_IPSEC_SET_DF_0_INNER_1)
9936 				ipsec_xform.tunnel.ipv4.df = 0;
9937 
9938 			if (flags->df == TEST_IPSEC_SET_DF_1_INNER_0)
9939 				ipsec_xform.tunnel.ipv4.df = 1;
9940 
9941 			if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1)
9942 				ipsec_xform.tunnel.ipv4.dscp = 0;
9943 
9944 			if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0)
9945 				ipsec_xform.tunnel.ipv4.dscp =
9946 						TEST_IPSEC_DSCP_VAL;
9947 
9948 		} else {
9949 			if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1)
9950 				ipsec_xform.tunnel.ipv6.dscp = 0;
9951 
9952 			if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0)
9953 				ipsec_xform.tunnel.ipv6.dscp =
9954 						TEST_IPSEC_DSCP_VAL;
9955 
9956 			memcpy(&ipsec_xform.tunnel.ipv6.src_addr, &v6_src,
9957 			       sizeof(v6_src));
9958 			memcpy(&ipsec_xform.tunnel.ipv6.dst_addr, &v6_dst,
9959 			       sizeof(v6_dst));
9960 		}
9961 	}
9962 
9963 	ctx = rte_cryptodev_get_sec_ctx(dev_id);
9964 
9965 	sec_cap_idx.action = ut_params->type;
9966 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC;
9967 	sec_cap_idx.ipsec.proto = ipsec_xform.proto;
9968 	sec_cap_idx.ipsec.mode = ipsec_xform.mode;
9969 	sec_cap_idx.ipsec.direction = ipsec_xform.direction;
9970 
9971 	if (flags->udp_encap)
9972 		ipsec_xform.options.udp_encap = 1;
9973 
9974 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9975 	if (sec_cap == NULL)
9976 		return TEST_SKIPPED;
9977 
9978 	/* Copy cipher session parameters */
9979 	if (td[0].aead) {
9980 		memcpy(&ut_params->aead_xform, &td[0].xform.aead,
9981 		       sizeof(ut_params->aead_xform));
9982 		ut_params->aead_xform.aead.key.data = td[0].key.data;
9983 		ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
9984 
9985 		/* Verify crypto capabilities */
9986 		if (test_ipsec_crypto_caps_aead_verify(
9987 				sec_cap,
9988 				&ut_params->aead_xform) != 0) {
9989 			if (!silent)
9990 				RTE_LOG(INFO, USER1,
9991 					"Crypto capabilities not supported\n");
9992 			return TEST_SKIPPED;
9993 		}
9994 	} else if (td[0].auth_only) {
9995 		memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth,
9996 		       sizeof(ut_params->auth_xform));
9997 		ut_params->auth_xform.auth.key.data = td[0].auth_key.data;
9998 
9999 		if (test_ipsec_crypto_caps_auth_verify(
10000 				sec_cap,
10001 				&ut_params->auth_xform) != 0) {
10002 			if (!silent)
10003 				RTE_LOG(INFO, USER1,
10004 					"Auth crypto capabilities not supported\n");
10005 			return TEST_SKIPPED;
10006 		}
10007 	} else {
10008 		memcpy(&ut_params->cipher_xform, &td[0].xform.chain.cipher,
10009 		       sizeof(ut_params->cipher_xform));
10010 		memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth,
10011 		       sizeof(ut_params->auth_xform));
10012 		ut_params->cipher_xform.cipher.key.data = td[0].key.data;
10013 		ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
10014 		ut_params->auth_xform.auth.key.data = td[0].auth_key.data;
10015 
10016 		/* Verify crypto capabilities */
10017 
10018 		if (test_ipsec_crypto_caps_cipher_verify(
10019 				sec_cap,
10020 				&ut_params->cipher_xform) != 0) {
10021 			if (!silent)
10022 				RTE_LOG(INFO, USER1,
10023 					"Cipher crypto capabilities not supported\n");
10024 			return TEST_SKIPPED;
10025 		}
10026 
10027 		if (test_ipsec_crypto_caps_auth_verify(
10028 				sec_cap,
10029 				&ut_params->auth_xform) != 0) {
10030 			if (!silent)
10031 				RTE_LOG(INFO, USER1,
10032 					"Auth crypto capabilities not supported\n");
10033 			return TEST_SKIPPED;
10034 		}
10035 	}
10036 
10037 	if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0)
10038 		return TEST_SKIPPED;
10039 
10040 	struct rte_security_session_conf sess_conf = {
10041 		.action_type = ut_params->type,
10042 		.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
10043 	};
10044 
10045 	if (td[0].aead || td[0].aes_gmac) {
10046 		salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len);
10047 		memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len);
10048 	}
10049 
10050 	if (td[0].aead) {
10051 		sess_conf.ipsec = ipsec_xform;
10052 		sess_conf.crypto_xform = &ut_params->aead_xform;
10053 	} else if (td[0].auth_only) {
10054 		sess_conf.ipsec = ipsec_xform;
10055 		sess_conf.crypto_xform = &ut_params->auth_xform;
10056 	} else {
10057 		sess_conf.ipsec = ipsec_xform;
10058 		if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
10059 			sess_conf.crypto_xform = &ut_params->cipher_xform;
10060 			ut_params->cipher_xform.next = &ut_params->auth_xform;
10061 		} else {
10062 			sess_conf.crypto_xform = &ut_params->auth_xform;
10063 			ut_params->auth_xform.next = &ut_params->cipher_xform;
10064 		}
10065 	}
10066 
10067 	/* Create security session */
10068 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
10069 					ts_params->session_mpool);
10070 
10071 	if (ut_params->sec_session == NULL)
10072 		return TEST_SKIPPED;
10073 
10074 	for (i = 0; i < nb_td; i++) {
10075 		if (flags->antireplay &&
10076 		    (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)) {
10077 			sess_conf.ipsec.esn.value = td[i].ipsec_xform.esn.value;
10078 			ret = rte_security_session_update(ctx,
10079 				ut_params->sec_session, &sess_conf);
10080 			if (ret) {
10081 				printf("Could not update sequence number in "
10082 				       "session\n");
10083 				return TEST_SKIPPED;
10084 			}
10085 		}
10086 
10087 		/* Copy test data before modification */
10088 		memcpy(input_text, td[i].input_text.data, td[i].input_text.len);
10089 		if (test_ipsec_pkt_update(input_text, flags))
10090 			return TEST_FAILED;
10091 
10092 		/* Setup source mbuf payload */
10093 		if (flags->use_ext_mbuf) {
10094 			ut_params->ibuf = ext_mbuf_create(ts_params->mbuf_pool,
10095 					td[i].input_text.len, nb_segs, input_text);
10096 		} else {
10097 			ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
10098 					td[i].input_text.len, nb_segs, 0);
10099 			pktmbuf_write(ut_params->ibuf, 0, td[i].input_text.len, input_text);
10100 		}
10101 
10102 		/* Generate crypto op data structure */
10103 		ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10104 					RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10105 		if (!ut_params->op) {
10106 			printf("TestCase %s line %d: %s\n",
10107 				__func__, __LINE__,
10108 				"failed to allocate crypto op");
10109 			ret = TEST_FAILED;
10110 			goto crypto_op_free;
10111 		}
10112 
10113 		/* Attach session to operation */
10114 		rte_security_attach_session(ut_params->op,
10115 					    ut_params->sec_session);
10116 
10117 		/* Set crypto operation mbufs */
10118 		ut_params->op->sym->m_src = ut_params->ibuf;
10119 		ut_params->op->sym->m_dst = NULL;
10120 
10121 		/* Copy IV in crypto operation when IV generation is disabled */
10122 		if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS &&
10123 		    ipsec_xform.options.iv_gen_disable == 1) {
10124 			uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op,
10125 								uint8_t *,
10126 								IV_OFFSET);
10127 			int len;
10128 
10129 			if (td[i].aead)
10130 				len = td[i].xform.aead.aead.iv.length;
10131 			else if (td[i].aes_gmac)
10132 				len = td[i].xform.chain.auth.auth.iv.length;
10133 			else
10134 				len = td[i].xform.chain.cipher.cipher.iv.length;
10135 
10136 			memcpy(iv, td[i].iv.data, len);
10137 		}
10138 
10139 		/* Process crypto operation */
10140 		process_crypto_request(dev_id, ut_params->op);
10141 
10142 		ret = test_ipsec_status_check(&td[i], ut_params->op, flags, dir,
10143 					      i + 1);
10144 		if (ret != TEST_SUCCESS)
10145 			goto crypto_op_free;
10146 
10147 		if (res_d != NULL)
10148 			res_d_tmp = &res_d[i];
10149 
10150 		ret = test_ipsec_post_process(ut_params->ibuf, &td[i],
10151 					      res_d_tmp, silent, flags);
10152 		if (ret != TEST_SUCCESS)
10153 			goto crypto_op_free;
10154 
10155 		ret = test_ipsec_stats_verify(ctx, ut_params->sec_session,
10156 					      flags, dir);
10157 		if (ret != TEST_SUCCESS)
10158 			goto crypto_op_free;
10159 
10160 		rte_crypto_op_free(ut_params->op);
10161 		ut_params->op = NULL;
10162 
10163 		rte_pktmbuf_free(ut_params->ibuf);
10164 		ut_params->ibuf = NULL;
10165 	}
10166 
10167 crypto_op_free:
10168 	rte_crypto_op_free(ut_params->op);
10169 	ut_params->op = NULL;
10170 
10171 	if (flags->use_ext_mbuf)
10172 		ext_mbuf_memzone_free(nb_segs);
10173 
10174 	rte_pktmbuf_free(ut_params->ibuf);
10175 	ut_params->ibuf = NULL;
10176 
10177 	if (ut_params->sec_session)
10178 		rte_security_session_destroy(ctx, ut_params->sec_session);
10179 	ut_params->sec_session = NULL;
10180 
10181 	return ret;
10182 }
10183 
10184 static int
10185 test_ipsec_proto_known_vec(const void *test_data)
10186 {
10187 	struct ipsec_test_data td_outb;
10188 	struct ipsec_test_flags flags;
10189 
10190 	memset(&flags, 0, sizeof(flags));
10191 
10192 	memcpy(&td_outb, test_data, sizeof(td_outb));
10193 
10194 	if (td_outb.aes_gmac || td_outb.aead ||
10195 	    ((td_outb.ipsec_xform.proto != RTE_SECURITY_IPSEC_SA_PROTO_AH) &&
10196 	     (td_outb.xform.chain.cipher.cipher.algo != RTE_CRYPTO_CIPHER_NULL))) {
10197 		/* Disable IV gen to be able to test with known vectors */
10198 		td_outb.ipsec_xform.options.iv_gen_disable = 1;
10199 	}
10200 
10201 	return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
10202 }
10203 
10204 static int
10205 test_ipsec_proto_known_vec_ext_mbuf(const void *test_data)
10206 {
10207 	struct ipsec_test_data td_outb;
10208 	struct ipsec_test_flags flags;
10209 
10210 	memset(&flags, 0, sizeof(flags));
10211 	flags.use_ext_mbuf = true;
10212 
10213 	memcpy(&td_outb, test_data, sizeof(td_outb));
10214 
10215 	if (td_outb.aes_gmac || td_outb.aead ||
10216 	    ((td_outb.ipsec_xform.proto != RTE_SECURITY_IPSEC_SA_PROTO_AH) &&
10217 	     (td_outb.xform.chain.cipher.cipher.algo != RTE_CRYPTO_CIPHER_NULL))) {
10218 		/* Disable IV gen to be able to test with known vectors */
10219 		td_outb.ipsec_xform.options.iv_gen_disable = 1;
10220 	}
10221 
10222 	return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
10223 }
10224 
10225 static int
10226 test_ipsec_proto_known_vec_inb(const void *test_data)
10227 {
10228 	const struct ipsec_test_data *td = test_data;
10229 	struct ipsec_test_flags flags;
10230 	struct ipsec_test_data td_inb;
10231 
10232 	memset(&flags, 0, sizeof(flags));
10233 
10234 	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)
10235 		test_ipsec_td_in_from_out(td, &td_inb);
10236 	else
10237 		memcpy(&td_inb, td, sizeof(td_inb));
10238 
10239 	return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags);
10240 }
10241 
10242 static int
10243 test_ipsec_proto_known_vec_fragmented(const void *test_data)
10244 {
10245 	struct ipsec_test_data td_outb;
10246 	struct ipsec_test_flags flags;
10247 
10248 	memset(&flags, 0, sizeof(flags));
10249 	flags.fragment = true;
10250 
10251 	memcpy(&td_outb, test_data, sizeof(td_outb));
10252 
10253 	/* Disable IV gen to be able to test with known vectors */
10254 	td_outb.ipsec_xform.options.iv_gen_disable = 1;
10255 
10256 	return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
10257 }
10258 
10259 static int
10260 test_ipsec_proto_all(const struct ipsec_test_flags *flags)
10261 {
10262 	struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
10263 	struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
10264 	unsigned int i, nb_pkts = 1, pass_cnt = 0;
10265 	int ret;
10266 
10267 	if (flags->iv_gen ||
10268 	    flags->sa_expiry_pkts_soft ||
10269 	    flags->sa_expiry_pkts_hard)
10270 		nb_pkts = IPSEC_TEST_PACKETS_MAX;
10271 
10272 	for (i = 0; i < RTE_DIM(alg_list); i++) {
10273 		test_ipsec_td_prepare(alg_list[i].param1,
10274 				      alg_list[i].param2,
10275 				      flags,
10276 				      td_outb,
10277 				      nb_pkts);
10278 
10279 		if (!td_outb->aead) {
10280 			enum rte_crypto_cipher_algorithm cipher_alg;
10281 			enum rte_crypto_auth_algorithm auth_alg;
10282 
10283 			cipher_alg = td_outb->xform.chain.cipher.cipher.algo;
10284 			auth_alg = td_outb->xform.chain.auth.auth.algo;
10285 
10286 			if (td_outb->aes_gmac && cipher_alg != RTE_CRYPTO_CIPHER_NULL)
10287 				continue;
10288 
10289 			/* ICV is not applicable for NULL auth */
10290 			if (flags->icv_corrupt &&
10291 			    auth_alg == RTE_CRYPTO_AUTH_NULL)
10292 				continue;
10293 
10294 			/* IV is not applicable for NULL cipher */
10295 			if (flags->iv_gen &&
10296 			    cipher_alg == RTE_CRYPTO_CIPHER_NULL)
10297 				continue;
10298 		}
10299 
10300 		ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
10301 					       flags);
10302 		if (ret == TEST_SKIPPED)
10303 			continue;
10304 
10305 		if (ret == TEST_FAILED)
10306 			return TEST_FAILED;
10307 
10308 		test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags);
10309 
10310 		ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
10311 					       flags);
10312 		if (ret == TEST_SKIPPED)
10313 			continue;
10314 
10315 		if (ret == TEST_FAILED)
10316 			return TEST_FAILED;
10317 
10318 		if (flags->display_alg)
10319 			test_ipsec_display_alg(alg_list[i].param1,
10320 					       alg_list[i].param2);
10321 
10322 		pass_cnt++;
10323 	}
10324 
10325 	if (pass_cnt > 0)
10326 		return TEST_SUCCESS;
10327 	else
10328 		return TEST_SKIPPED;
10329 }
10330 
10331 static int
10332 test_ipsec_ah_proto_all(const struct ipsec_test_flags *flags)
10333 {
10334 	struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
10335 	struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
10336 	unsigned int i, nb_pkts = 1, pass_cnt = 0;
10337 	int ret;
10338 
10339 	for (i = 0; i < RTE_DIM(ah_alg_list); i++) {
10340 		test_ipsec_td_prepare(ah_alg_list[i].param1,
10341 				      ah_alg_list[i].param2,
10342 				      flags,
10343 				      td_outb,
10344 				      nb_pkts);
10345 
10346 		ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
10347 					       flags);
10348 		if (ret == TEST_SKIPPED)
10349 			continue;
10350 
10351 		if (ret == TEST_FAILED)
10352 			return TEST_FAILED;
10353 
10354 		test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags);
10355 
10356 		ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
10357 					       flags);
10358 		if (ret == TEST_SKIPPED)
10359 			continue;
10360 
10361 		if (ret == TEST_FAILED)
10362 			return TEST_FAILED;
10363 
10364 		if (flags->display_alg)
10365 			test_ipsec_display_alg(ah_alg_list[i].param1,
10366 					       ah_alg_list[i].param2);
10367 
10368 		pass_cnt++;
10369 	}
10370 
10371 	if (pass_cnt > 0)
10372 		return TEST_SUCCESS;
10373 	else
10374 		return TEST_SKIPPED;
10375 }
10376 
10377 static int
10378 test_ipsec_proto_display_list(void)
10379 {
10380 	struct ipsec_test_flags flags;
10381 
10382 	memset(&flags, 0, sizeof(flags));
10383 
10384 	flags.display_alg = true;
10385 
10386 	return test_ipsec_proto_all(&flags);
10387 }
10388 
10389 static int
10390 test_ipsec_proto_ah_tunnel_ipv4(void)
10391 {
10392 	struct ipsec_test_flags flags;
10393 
10394 	memset(&flags, 0, sizeof(flags));
10395 
10396 	flags.ah = true;
10397 	flags.display_alg = true;
10398 
10399 	return test_ipsec_ah_proto_all(&flags);
10400 }
10401 
10402 static int
10403 test_ipsec_proto_ah_transport_ipv4(void)
10404 {
10405 	struct ipsec_test_flags flags;
10406 
10407 	memset(&flags, 0, sizeof(flags));
10408 
10409 	flags.ah = true;
10410 	flags.transport = true;
10411 
10412 	return test_ipsec_ah_proto_all(&flags);
10413 }
10414 
10415 static int
10416 test_ipsec_proto_iv_gen(void)
10417 {
10418 	struct ipsec_test_flags flags;
10419 
10420 	memset(&flags, 0, sizeof(flags));
10421 
10422 	flags.iv_gen = true;
10423 
10424 	return test_ipsec_proto_all(&flags);
10425 }
10426 
10427 static int
10428 test_ipsec_proto_sa_exp_pkts_soft(void)
10429 {
10430 	struct ipsec_test_flags flags;
10431 
10432 	memset(&flags, 0, sizeof(flags));
10433 
10434 	flags.sa_expiry_pkts_soft = true;
10435 
10436 	return test_ipsec_proto_all(&flags);
10437 }
10438 
10439 static int
10440 test_ipsec_proto_sa_exp_pkts_hard(void)
10441 {
10442 	struct ipsec_test_flags flags;
10443 
10444 	memset(&flags, 0, sizeof(flags));
10445 
10446 	flags.sa_expiry_pkts_hard = true;
10447 
10448 	return test_ipsec_proto_all(&flags);
10449 }
10450 
10451 static int
10452 test_ipsec_proto_err_icv_corrupt(void)
10453 {
10454 	struct ipsec_test_flags flags;
10455 
10456 	memset(&flags, 0, sizeof(flags));
10457 
10458 	flags.icv_corrupt = true;
10459 
10460 	return test_ipsec_proto_all(&flags);
10461 }
10462 
10463 static int
10464 test_ipsec_proto_udp_encap_custom_ports(void)
10465 {
10466 	struct ipsec_test_flags flags;
10467 
10468 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
10469 			RTE_STR(CRYPTODEV_NAME_CN10K_PMD)))
10470 		return TEST_SKIPPED;
10471 
10472 	memset(&flags, 0, sizeof(flags));
10473 
10474 	flags.udp_encap = true;
10475 	flags.udp_encap_custom_ports = true;
10476 
10477 	return test_ipsec_proto_all(&flags);
10478 }
10479 
10480 static int
10481 test_ipsec_proto_udp_encap(void)
10482 {
10483 	struct ipsec_test_flags flags;
10484 
10485 	memset(&flags, 0, sizeof(flags));
10486 
10487 	flags.udp_encap = true;
10488 
10489 	return test_ipsec_proto_all(&flags);
10490 }
10491 
10492 static int
10493 test_ipsec_proto_tunnel_src_dst_addr_verify(void)
10494 {
10495 	struct ipsec_test_flags flags;
10496 
10497 	memset(&flags, 0, sizeof(flags));
10498 
10499 	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
10500 
10501 	return test_ipsec_proto_all(&flags);
10502 }
10503 
10504 static int
10505 test_ipsec_proto_tunnel_dst_addr_verify(void)
10506 {
10507 	struct ipsec_test_flags flags;
10508 
10509 	memset(&flags, 0, sizeof(flags));
10510 
10511 	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR;
10512 
10513 	return test_ipsec_proto_all(&flags);
10514 }
10515 
10516 static int
10517 test_ipsec_proto_udp_ports_verify(void)
10518 {
10519 	struct ipsec_test_flags flags;
10520 
10521 	memset(&flags, 0, sizeof(flags));
10522 
10523 	flags.udp_encap = true;
10524 	flags.udp_ports_verify = true;
10525 
10526 	return test_ipsec_proto_all(&flags);
10527 }
10528 
10529 static int
10530 test_ipsec_proto_inner_ip_csum(void)
10531 {
10532 	struct ipsec_test_flags flags;
10533 
10534 	memset(&flags, 0, sizeof(flags));
10535 
10536 	flags.ip_csum = true;
10537 
10538 	return test_ipsec_proto_all(&flags);
10539 }
10540 
10541 static int
10542 test_ipsec_proto_inner_l4_csum(void)
10543 {
10544 	struct ipsec_test_flags flags;
10545 
10546 	memset(&flags, 0, sizeof(flags));
10547 
10548 	flags.l4_csum = true;
10549 
10550 	return test_ipsec_proto_all(&flags);
10551 }
10552 
10553 static int
10554 test_ipsec_proto_tunnel_v4_in_v4(void)
10555 {
10556 	struct ipsec_test_flags flags;
10557 
10558 	memset(&flags, 0, sizeof(flags));
10559 
10560 	flags.ipv6 = false;
10561 	flags.tunnel_ipv6 = false;
10562 
10563 	return test_ipsec_proto_all(&flags);
10564 }
10565 
10566 static int
10567 test_ipsec_proto_tunnel_v6_in_v6(void)
10568 {
10569 	struct ipsec_test_flags flags;
10570 
10571 	memset(&flags, 0, sizeof(flags));
10572 
10573 	flags.ipv6 = true;
10574 	flags.tunnel_ipv6 = true;
10575 
10576 	return test_ipsec_proto_all(&flags);
10577 }
10578 
10579 static int
10580 test_ipsec_proto_tunnel_v4_in_v6(void)
10581 {
10582 	struct ipsec_test_flags flags;
10583 
10584 	memset(&flags, 0, sizeof(flags));
10585 
10586 	flags.ipv6 = false;
10587 	flags.tunnel_ipv6 = true;
10588 
10589 	return test_ipsec_proto_all(&flags);
10590 }
10591 
10592 static int
10593 test_ipsec_proto_tunnel_v6_in_v4(void)
10594 {
10595 	struct ipsec_test_flags flags;
10596 
10597 	memset(&flags, 0, sizeof(flags));
10598 
10599 	flags.ipv6 = true;
10600 	flags.tunnel_ipv6 = false;
10601 
10602 	return test_ipsec_proto_all(&flags);
10603 }
10604 
10605 static int
10606 test_ipsec_proto_transport_v4(void)
10607 {
10608 	struct ipsec_test_flags flags;
10609 
10610 	memset(&flags, 0, sizeof(flags));
10611 
10612 	flags.ipv6 = false;
10613 	flags.transport = true;
10614 
10615 	return test_ipsec_proto_all(&flags);
10616 }
10617 
10618 static int
10619 test_ipsec_proto_transport_l4_csum(void)
10620 {
10621 	struct ipsec_test_flags flags = {
10622 		.l4_csum = true,
10623 		.transport = true,
10624 	};
10625 
10626 	return test_ipsec_proto_all(&flags);
10627 }
10628 
10629 static int
10630 test_ipsec_proto_stats(void)
10631 {
10632 	struct ipsec_test_flags flags;
10633 
10634 	memset(&flags, 0, sizeof(flags));
10635 
10636 	flags.stats_success = true;
10637 
10638 	return test_ipsec_proto_all(&flags);
10639 }
10640 
10641 static int
10642 test_ipsec_proto_pkt_fragment(void)
10643 {
10644 	struct ipsec_test_flags flags;
10645 
10646 	memset(&flags, 0, sizeof(flags));
10647 
10648 	flags.fragment = true;
10649 
10650 	return test_ipsec_proto_all(&flags);
10651 
10652 }
10653 
10654 static int
10655 test_ipsec_proto_copy_df_inner_0(void)
10656 {
10657 	struct ipsec_test_flags flags;
10658 
10659 	memset(&flags, 0, sizeof(flags));
10660 
10661 	flags.df = TEST_IPSEC_COPY_DF_INNER_0;
10662 
10663 	return test_ipsec_proto_all(&flags);
10664 }
10665 
10666 static int
10667 test_ipsec_proto_copy_df_inner_1(void)
10668 {
10669 	struct ipsec_test_flags flags;
10670 
10671 	memset(&flags, 0, sizeof(flags));
10672 
10673 	flags.df = TEST_IPSEC_COPY_DF_INNER_1;
10674 
10675 	return test_ipsec_proto_all(&flags);
10676 }
10677 
10678 static int
10679 test_ipsec_proto_set_df_0_inner_1(void)
10680 {
10681 	struct ipsec_test_flags flags;
10682 
10683 	memset(&flags, 0, sizeof(flags));
10684 
10685 	flags.df = TEST_IPSEC_SET_DF_0_INNER_1;
10686 
10687 	return test_ipsec_proto_all(&flags);
10688 }
10689 
10690 static int
10691 test_ipsec_proto_set_df_1_inner_0(void)
10692 {
10693 	struct ipsec_test_flags flags;
10694 
10695 	memset(&flags, 0, sizeof(flags));
10696 
10697 	flags.df = TEST_IPSEC_SET_DF_1_INNER_0;
10698 
10699 	return test_ipsec_proto_all(&flags);
10700 }
10701 
10702 static int
10703 test_ipsec_proto_ipv4_copy_dscp_inner_0(void)
10704 {
10705 	struct ipsec_test_flags flags;
10706 
10707 	memset(&flags, 0, sizeof(flags));
10708 
10709 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0;
10710 
10711 	return test_ipsec_proto_all(&flags);
10712 }
10713 
10714 static int
10715 test_ipsec_proto_ipv4_copy_dscp_inner_1(void)
10716 {
10717 	struct ipsec_test_flags flags;
10718 
10719 	memset(&flags, 0, sizeof(flags));
10720 
10721 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1;
10722 
10723 	return test_ipsec_proto_all(&flags);
10724 }
10725 
10726 static int
10727 test_ipsec_proto_ipv4_set_dscp_0_inner_1(void)
10728 {
10729 	struct ipsec_test_flags flags;
10730 
10731 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
10732 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD)))
10733 		return TEST_SKIPPED;
10734 
10735 	memset(&flags, 0, sizeof(flags));
10736 
10737 	flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1;
10738 
10739 	return test_ipsec_proto_all(&flags);
10740 }
10741 
10742 static int
10743 test_ipsec_proto_ipv4_set_dscp_1_inner_0(void)
10744 {
10745 	struct ipsec_test_flags flags;
10746 
10747 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
10748 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD)))
10749 		return TEST_SKIPPED;
10750 
10751 	memset(&flags, 0, sizeof(flags));
10752 
10753 	flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0;
10754 
10755 	return test_ipsec_proto_all(&flags);
10756 }
10757 
10758 static int
10759 test_ipsec_proto_ipv6_copy_dscp_inner_0(void)
10760 {
10761 	struct ipsec_test_flags flags;
10762 
10763 	memset(&flags, 0, sizeof(flags));
10764 
10765 	flags.ipv6 = true;
10766 	flags.tunnel_ipv6 = true;
10767 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0;
10768 
10769 	return test_ipsec_proto_all(&flags);
10770 }
10771 
10772 static int
10773 test_ipsec_proto_ipv6_copy_dscp_inner_1(void)
10774 {
10775 	struct ipsec_test_flags flags;
10776 
10777 	memset(&flags, 0, sizeof(flags));
10778 
10779 	flags.ipv6 = true;
10780 	flags.tunnel_ipv6 = true;
10781 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1;
10782 
10783 	return test_ipsec_proto_all(&flags);
10784 }
10785 
10786 static int
10787 test_ipsec_proto_ipv6_set_dscp_0_inner_1(void)
10788 {
10789 	struct ipsec_test_flags flags;
10790 
10791 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
10792 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD)))
10793 		return TEST_SKIPPED;
10794 
10795 	memset(&flags, 0, sizeof(flags));
10796 
10797 	flags.ipv6 = true;
10798 	flags.tunnel_ipv6 = true;
10799 	flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1;
10800 
10801 	return test_ipsec_proto_all(&flags);
10802 }
10803 
10804 static int
10805 test_ipsec_proto_ipv6_set_dscp_1_inner_0(void)
10806 {
10807 	struct ipsec_test_flags flags;
10808 
10809 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
10810 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD)))
10811 		return TEST_SKIPPED;
10812 
10813 	memset(&flags, 0, sizeof(flags));
10814 
10815 	flags.ipv6 = true;
10816 	flags.tunnel_ipv6 = true;
10817 	flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0;
10818 
10819 	return test_ipsec_proto_all(&flags);
10820 }
10821 
10822 static int
10823 test_ipsec_proto_sgl(void)
10824 {
10825 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10826 	struct rte_cryptodev_info dev_info;
10827 
10828 	struct ipsec_test_flags flags = {
10829 		.nb_segs_in_mbuf = 5
10830 	};
10831 
10832 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10833 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
10834 		printf("Device doesn't support in-place scatter-gather. "
10835 				"Test Skipped.\n");
10836 		return TEST_SKIPPED;
10837 	}
10838 
10839 	return test_ipsec_proto_all(&flags);
10840 }
10841 
10842 static int
10843 test_ipsec_proto_sgl_ext_mbuf(void)
10844 {
10845 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10846 	struct rte_cryptodev_info dev_info;
10847 
10848 	struct ipsec_test_flags flags = {
10849 		.nb_segs_in_mbuf = 5,
10850 		.use_ext_mbuf = 1
10851 	};
10852 
10853 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10854 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
10855 		printf("Device doesn't support in-place scatter-gather. "
10856 				"Test Skipped.\n");
10857 		return TEST_SKIPPED;
10858 	}
10859 
10860 	return test_ipsec_proto_all(&flags);
10861 }
10862 
10863 static int
10864 test_ipsec_pkt_replay(const void *test_data, const uint64_t esn[],
10865 		      bool replayed_pkt[], uint32_t nb_pkts, bool esn_en,
10866 		      uint64_t winsz)
10867 {
10868 	struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
10869 	struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
10870 	struct ipsec_test_flags flags;
10871 	uint32_t i = 0, ret = 0;
10872 
10873 	if (nb_pkts == 0)
10874 		return TEST_FAILED;
10875 
10876 	memset(&flags, 0, sizeof(flags));
10877 	flags.antireplay = true;
10878 
10879 	for (i = 0; i < nb_pkts; i++) {
10880 		memcpy(&td_outb[i], test_data, sizeof(td_outb[i]));
10881 		td_outb[i].ipsec_xform.options.iv_gen_disable = 1;
10882 		td_outb[i].ipsec_xform.replay_win_sz = winsz;
10883 		td_outb[i].ipsec_xform.options.esn = esn_en;
10884 	}
10885 
10886 	for (i = 0; i < nb_pkts; i++)
10887 		td_outb[i].ipsec_xform.esn.value = esn[i];
10888 
10889 	ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
10890 				       &flags);
10891 	if (ret != TEST_SUCCESS)
10892 		return ret;
10893 
10894 	test_ipsec_td_update(td_inb, td_outb, nb_pkts, &flags);
10895 
10896 	for (i = 0; i < nb_pkts; i++) {
10897 		td_inb[i].ipsec_xform.options.esn = esn_en;
10898 		/* Set antireplay flag for packets to be dropped */
10899 		td_inb[i].ar_packet = replayed_pkt[i];
10900 	}
10901 
10902 	ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
10903 				       &flags);
10904 
10905 	return ret;
10906 }
10907 
10908 static int
10909 test_ipsec_proto_pkt_antireplay(const void *test_data, uint64_t winsz)
10910 {
10911 
10912 	uint32_t nb_pkts = 5;
10913 	bool replayed_pkt[5];
10914 	uint64_t esn[5];
10915 
10916 	/* 1. Advance the TOP of the window to WS * 2 */
10917 	esn[0] = winsz * 2;
10918 	/* 2. Test sequence number within the new window(WS + 1) */
10919 	esn[1] = winsz + 1;
10920 	/* 3. Test sequence number less than the window BOTTOM */
10921 	esn[2] = winsz;
10922 	/* 4. Test sequence number in the middle of the window */
10923 	esn[3] = winsz + (winsz / 2);
10924 	/* 5. Test replay of the packet in the middle of the window */
10925 	esn[4] = winsz + (winsz / 2);
10926 
10927 	replayed_pkt[0] = false;
10928 	replayed_pkt[1] = false;
10929 	replayed_pkt[2] = true;
10930 	replayed_pkt[3] = false;
10931 	replayed_pkt[4] = true;
10932 
10933 	return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts,
10934 				     false, winsz);
10935 }
10936 
10937 static int
10938 test_ipsec_proto_pkt_antireplay1024(const void *test_data)
10939 {
10940 	return test_ipsec_proto_pkt_antireplay(test_data, 1024);
10941 }
10942 
10943 static int
10944 test_ipsec_proto_pkt_antireplay2048(const void *test_data)
10945 {
10946 	return test_ipsec_proto_pkt_antireplay(test_data, 2048);
10947 }
10948 
10949 static int
10950 test_ipsec_proto_pkt_antireplay4096(const void *test_data)
10951 {
10952 	return test_ipsec_proto_pkt_antireplay(test_data, 4096);
10953 }
10954 
10955 static int
10956 test_ipsec_proto_pkt_esn_antireplay(const void *test_data, uint64_t winsz)
10957 {
10958 
10959 	uint32_t nb_pkts = 7;
10960 	bool replayed_pkt[7];
10961 	uint64_t esn[7];
10962 
10963 	/* Set the initial sequence number */
10964 	esn[0] = (uint64_t)(0xFFFFFFFF - winsz);
10965 	/* 1. Advance the TOP of the window to (1<<32 + WS/2) */
10966 	esn[1] = (uint64_t)((1ULL << 32) + (winsz / 2));
10967 	/* 2. Test sequence number within new window (1<<32 + WS/2 + 1) */
10968 	esn[2] = (uint64_t)((1ULL << 32) - (winsz / 2) + 1);
10969 	/* 3. Test with sequence number within window (1<<32 - 1) */
10970 	esn[3] = (uint64_t)((1ULL << 32) - 1);
10971 	/* 4. Test with sequence number within window (1<<32 - 1) */
10972 	esn[4] = (uint64_t)(1ULL << 32);
10973 	/* 5. Test with duplicate sequence number within
10974 	 * new window (1<<32 - 1)
10975 	 */
10976 	esn[5] = (uint64_t)((1ULL << 32) - 1);
10977 	/* 6. Test with duplicate sequence number within new window (1<<32) */
10978 	esn[6] = (uint64_t)(1ULL << 32);
10979 
10980 	replayed_pkt[0] = false;
10981 	replayed_pkt[1] = false;
10982 	replayed_pkt[2] = false;
10983 	replayed_pkt[3] = false;
10984 	replayed_pkt[4] = false;
10985 	replayed_pkt[5] = true;
10986 	replayed_pkt[6] = true;
10987 
10988 	return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts,
10989 				     true, winsz);
10990 }
10991 
10992 static int
10993 test_ipsec_proto_pkt_esn_antireplay1024(const void *test_data)
10994 {
10995 	return test_ipsec_proto_pkt_esn_antireplay(test_data, 1024);
10996 }
10997 
10998 static int
10999 test_ipsec_proto_pkt_esn_antireplay2048(const void *test_data)
11000 {
11001 	return test_ipsec_proto_pkt_esn_antireplay(test_data, 2048);
11002 }
11003 
11004 static int
11005 test_ipsec_proto_pkt_esn_antireplay4096(const void *test_data)
11006 {
11007 	return test_ipsec_proto_pkt_esn_antireplay(test_data, 4096);
11008 }
11009 
11010 static int
11011 test_PDCP_PROTO_all(void)
11012 {
11013 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11014 	struct crypto_unittest_params *ut_params = &unittest_params;
11015 	struct rte_cryptodev_info dev_info;
11016 	int status;
11017 
11018 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11019 	uint64_t feat_flags = dev_info.feature_flags;
11020 
11021 	if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
11022 		return TEST_SKIPPED;
11023 
11024 	/* Set action type */
11025 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
11026 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
11027 		gbl_action_type;
11028 
11029 	if (security_proto_supported(ut_params->type,
11030 			RTE_SECURITY_PROTOCOL_PDCP) < 0)
11031 		return TEST_SKIPPED;
11032 
11033 	status = test_PDCP_PROTO_cplane_encap_all();
11034 	status += test_PDCP_PROTO_cplane_decap_all();
11035 	status += test_PDCP_PROTO_uplane_encap_all();
11036 	status += test_PDCP_PROTO_uplane_decap_all();
11037 	status += test_PDCP_PROTO_SGL_in_place_32B();
11038 	status += test_PDCP_PROTO_SGL_oop_32B_128B();
11039 	status += test_PDCP_PROTO_SGL_oop_32B_40B();
11040 	status += test_PDCP_PROTO_SGL_oop_128B_32B();
11041 	status += test_PDCP_SDAP_PROTO_encap_all();
11042 	status += test_PDCP_SDAP_PROTO_decap_all();
11043 	status += test_PDCP_PROTO_short_mac();
11044 
11045 	if (status)
11046 		return TEST_FAILED;
11047 	else
11048 		return TEST_SUCCESS;
11049 }
11050 
11051 static int
11052 test_ipsec_proto_ipv4_ttl_decrement(void)
11053 {
11054 	struct ipsec_test_flags flags = {
11055 		.dec_ttl_or_hop_limit = true
11056 	};
11057 
11058 	return test_ipsec_proto_all(&flags);
11059 }
11060 
11061 static int
11062 test_ipsec_proto_ipv6_hop_limit_decrement(void)
11063 {
11064 	struct ipsec_test_flags flags = {
11065 		.ipv6 = true,
11066 		.dec_ttl_or_hop_limit = true
11067 	};
11068 
11069 	return test_ipsec_proto_all(&flags);
11070 }
11071 
11072 static int
11073 test_docsis_proto_uplink(const void *data)
11074 {
11075 	const struct docsis_test_data *d_td = data;
11076 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11077 	struct crypto_unittest_params *ut_params = &unittest_params;
11078 	uint8_t *plaintext = NULL;
11079 	uint8_t *ciphertext = NULL;
11080 	uint8_t *iv_ptr;
11081 	int32_t cipher_len, crc_len;
11082 	uint32_t crc_data_len;
11083 	int ret = TEST_SUCCESS;
11084 
11085 	void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]);
11086 
11087 	/* Verify the capabilities */
11088 	struct rte_security_capability_idx sec_cap_idx;
11089 	const struct rte_security_capability *sec_cap;
11090 	const struct rte_cryptodev_capabilities *crypto_cap;
11091 	const struct rte_cryptodev_symmetric_capability *sym_cap;
11092 	int j = 0;
11093 
11094 	/* Set action type */
11095 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
11096 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
11097 		gbl_action_type;
11098 
11099 	if (security_proto_supported(ut_params->type,
11100 			RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
11101 		return TEST_SKIPPED;
11102 
11103 	sec_cap_idx.action = ut_params->type;
11104 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
11105 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
11106 
11107 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
11108 	if (sec_cap == NULL)
11109 		return TEST_SKIPPED;
11110 
11111 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
11112 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
11113 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
11114 				crypto_cap->sym.xform_type ==
11115 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
11116 				crypto_cap->sym.cipher.algo ==
11117 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
11118 			sym_cap = &crypto_cap->sym;
11119 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
11120 						d_td->key.len,
11121 						d_td->iv.len) == 0)
11122 				break;
11123 		}
11124 	}
11125 
11126 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
11127 		return TEST_SKIPPED;
11128 
11129 	/* Setup source mbuf payload */
11130 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11131 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11132 			rte_pktmbuf_tailroom(ut_params->ibuf));
11133 
11134 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11135 			d_td->ciphertext.len);
11136 
11137 	memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
11138 
11139 	/* Setup cipher session parameters */
11140 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11141 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
11142 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
11143 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
11144 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
11145 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
11146 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
11147 	ut_params->cipher_xform.next = NULL;
11148 
11149 	/* Setup DOCSIS session parameters */
11150 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
11151 
11152 	struct rte_security_session_conf sess_conf = {
11153 		.action_type = ut_params->type,
11154 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
11155 		.docsis = ut_params->docsis_xform,
11156 		.crypto_xform = &ut_params->cipher_xform,
11157 	};
11158 
11159 	/* Create security session */
11160 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
11161 					ts_params->session_mpool);
11162 
11163 	if (!ut_params->sec_session) {
11164 		printf("Test function %s line %u: failed to allocate session\n",
11165 			__func__, __LINE__);
11166 		ret = TEST_FAILED;
11167 		goto on_err;
11168 	}
11169 
11170 	/* Generate crypto op data structure */
11171 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11172 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11173 	if (!ut_params->op) {
11174 		printf("Test function %s line %u: failed to allocate symmetric "
11175 			"crypto operation\n", __func__, __LINE__);
11176 		ret = TEST_FAILED;
11177 		goto on_err;
11178 	}
11179 
11180 	/* Setup CRC operation parameters */
11181 	crc_len = d_td->ciphertext.no_crc == false ?
11182 			(d_td->ciphertext.len -
11183 				d_td->ciphertext.crc_offset -
11184 				RTE_ETHER_CRC_LEN) :
11185 			0;
11186 	crc_len = crc_len > 0 ? crc_len : 0;
11187 	crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
11188 	ut_params->op->sym->auth.data.length = crc_len;
11189 	ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
11190 
11191 	/* Setup cipher operation parameters */
11192 	cipher_len = d_td->ciphertext.no_cipher == false ?
11193 			(d_td->ciphertext.len -
11194 				d_td->ciphertext.cipher_offset) :
11195 			0;
11196 	cipher_len = cipher_len > 0 ? cipher_len : 0;
11197 	ut_params->op->sym->cipher.data.length = cipher_len;
11198 	ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
11199 
11200 	/* Setup cipher IV */
11201 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
11202 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
11203 
11204 	/* Attach session to operation */
11205 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
11206 
11207 	/* Set crypto operation mbufs */
11208 	ut_params->op->sym->m_src = ut_params->ibuf;
11209 	ut_params->op->sym->m_dst = NULL;
11210 
11211 	/* Process crypto operation */
11212 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
11213 			NULL) {
11214 		printf("Test function %s line %u: failed to process security "
11215 			"crypto op\n", __func__, __LINE__);
11216 		ret = TEST_FAILED;
11217 		goto on_err;
11218 	}
11219 
11220 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
11221 		printf("Test function %s line %u: failed to process crypto op\n",
11222 			__func__, __LINE__);
11223 		ret = TEST_FAILED;
11224 		goto on_err;
11225 	}
11226 
11227 	/* Validate plaintext */
11228 	plaintext = ciphertext;
11229 
11230 	if (memcmp(plaintext, d_td->plaintext.data,
11231 			d_td->plaintext.len - crc_data_len)) {
11232 		printf("Test function %s line %u: plaintext not as expected\n",
11233 			__func__, __LINE__);
11234 		rte_hexdump(stdout, "expected", d_td->plaintext.data,
11235 				d_td->plaintext.len);
11236 		rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
11237 		ret = TEST_FAILED;
11238 		goto on_err;
11239 	}
11240 
11241 on_err:
11242 	rte_crypto_op_free(ut_params->op);
11243 	ut_params->op = NULL;
11244 
11245 	if (ut_params->sec_session)
11246 		rte_security_session_destroy(ctx, ut_params->sec_session);
11247 	ut_params->sec_session = NULL;
11248 
11249 	rte_pktmbuf_free(ut_params->ibuf);
11250 	ut_params->ibuf = NULL;
11251 
11252 	return ret;
11253 }
11254 
11255 static int
11256 test_docsis_proto_downlink(const void *data)
11257 {
11258 	const struct docsis_test_data *d_td = data;
11259 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11260 	struct crypto_unittest_params *ut_params = &unittest_params;
11261 	uint8_t *plaintext = NULL;
11262 	uint8_t *ciphertext = NULL;
11263 	uint8_t *iv_ptr;
11264 	int32_t cipher_len, crc_len;
11265 	int ret = TEST_SUCCESS;
11266 
11267 	void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]);
11268 
11269 	/* Verify the capabilities */
11270 	struct rte_security_capability_idx sec_cap_idx;
11271 	const struct rte_security_capability *sec_cap;
11272 	const struct rte_cryptodev_capabilities *crypto_cap;
11273 	const struct rte_cryptodev_symmetric_capability *sym_cap;
11274 	int j = 0;
11275 
11276 	/* Set action type */
11277 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
11278 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
11279 		gbl_action_type;
11280 
11281 	if (security_proto_supported(ut_params->type,
11282 			RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
11283 		return TEST_SKIPPED;
11284 
11285 	sec_cap_idx.action = ut_params->type;
11286 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
11287 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
11288 
11289 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
11290 	if (sec_cap == NULL)
11291 		return TEST_SKIPPED;
11292 
11293 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
11294 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
11295 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
11296 				crypto_cap->sym.xform_type ==
11297 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
11298 				crypto_cap->sym.cipher.algo ==
11299 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
11300 			sym_cap = &crypto_cap->sym;
11301 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
11302 						d_td->key.len,
11303 						d_td->iv.len) == 0)
11304 				break;
11305 		}
11306 	}
11307 
11308 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
11309 		return TEST_SKIPPED;
11310 
11311 	/* Setup source mbuf payload */
11312 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11313 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11314 			rte_pktmbuf_tailroom(ut_params->ibuf));
11315 
11316 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11317 			d_td->plaintext.len);
11318 
11319 	memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
11320 
11321 	/* Setup cipher session parameters */
11322 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11323 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
11324 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11325 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
11326 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
11327 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
11328 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
11329 	ut_params->cipher_xform.next = NULL;
11330 
11331 	/* Setup DOCSIS session parameters */
11332 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
11333 
11334 	struct rte_security_session_conf sess_conf = {
11335 		.action_type = ut_params->type,
11336 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
11337 		.docsis = ut_params->docsis_xform,
11338 		.crypto_xform = &ut_params->cipher_xform,
11339 	};
11340 
11341 	/* Create security session */
11342 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
11343 					ts_params->session_mpool);
11344 
11345 	if (!ut_params->sec_session) {
11346 		printf("Test function %s line %u: failed to allocate session\n",
11347 			__func__, __LINE__);
11348 		ret = TEST_FAILED;
11349 		goto on_err;
11350 	}
11351 
11352 	/* Generate crypto op data structure */
11353 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11354 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11355 	if (!ut_params->op) {
11356 		printf("Test function %s line %u: failed to allocate symmetric "
11357 			"crypto operation\n", __func__, __LINE__);
11358 		ret = TEST_FAILED;
11359 		goto on_err;
11360 	}
11361 
11362 	/* Setup CRC operation parameters */
11363 	crc_len = d_td->plaintext.no_crc == false ?
11364 			(d_td->plaintext.len -
11365 				d_td->plaintext.crc_offset -
11366 				RTE_ETHER_CRC_LEN) :
11367 			0;
11368 	crc_len = crc_len > 0 ? crc_len : 0;
11369 	ut_params->op->sym->auth.data.length = crc_len;
11370 	ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
11371 
11372 	/* Setup cipher operation parameters */
11373 	cipher_len = d_td->plaintext.no_cipher == false ?
11374 			(d_td->plaintext.len -
11375 				d_td->plaintext.cipher_offset) :
11376 			0;
11377 	cipher_len = cipher_len > 0 ? cipher_len : 0;
11378 	ut_params->op->sym->cipher.data.length = cipher_len;
11379 	ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
11380 
11381 	/* Setup cipher IV */
11382 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
11383 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
11384 
11385 	/* Attach session to operation */
11386 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
11387 
11388 	/* Set crypto operation mbufs */
11389 	ut_params->op->sym->m_src = ut_params->ibuf;
11390 	ut_params->op->sym->m_dst = NULL;
11391 
11392 	/* Process crypto operation */
11393 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
11394 			NULL) {
11395 		printf("Test function %s line %u: failed to process crypto op\n",
11396 			__func__, __LINE__);
11397 		ret = TEST_FAILED;
11398 		goto on_err;
11399 	}
11400 
11401 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
11402 		printf("Test function %s line %u: crypto op processing failed\n",
11403 			__func__, __LINE__);
11404 		ret = TEST_FAILED;
11405 		goto on_err;
11406 	}
11407 
11408 	/* Validate ciphertext */
11409 	ciphertext = plaintext;
11410 
11411 	if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
11412 		printf("Test function %s line %u: plaintext not as expected\n",
11413 			__func__, __LINE__);
11414 		rte_hexdump(stdout, "expected", d_td->ciphertext.data,
11415 				d_td->ciphertext.len);
11416 		rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
11417 		ret = TEST_FAILED;
11418 		goto on_err;
11419 	}
11420 
11421 on_err:
11422 	rte_crypto_op_free(ut_params->op);
11423 	ut_params->op = NULL;
11424 
11425 	if (ut_params->sec_session)
11426 		rte_security_session_destroy(ctx, ut_params->sec_session);
11427 	ut_params->sec_session = NULL;
11428 
11429 	rte_pktmbuf_free(ut_params->ibuf);
11430 	ut_params->ibuf = NULL;
11431 
11432 	return ret;
11433 }
11434 #endif
11435 
11436 static int
11437 test_AES_GCM_authenticated_encryption_test_case_1(void)
11438 {
11439 	return test_authenticated_encryption(&gcm_test_case_1);
11440 }
11441 
11442 static int
11443 test_AES_GCM_authenticated_encryption_test_case_2(void)
11444 {
11445 	return test_authenticated_encryption(&gcm_test_case_2);
11446 }
11447 
11448 static int
11449 test_AES_GCM_authenticated_encryption_test_case_3(void)
11450 {
11451 	return test_authenticated_encryption(&gcm_test_case_3);
11452 }
11453 
11454 static int
11455 test_AES_GCM_authenticated_encryption_test_case_4(void)
11456 {
11457 	return test_authenticated_encryption(&gcm_test_case_4);
11458 }
11459 
11460 static int
11461 test_AES_GCM_authenticated_encryption_test_case_5(void)
11462 {
11463 	return test_authenticated_encryption(&gcm_test_case_5);
11464 }
11465 
11466 static int
11467 test_AES_GCM_authenticated_encryption_test_case_6(void)
11468 {
11469 	return test_authenticated_encryption(&gcm_test_case_6);
11470 }
11471 
11472 static int
11473 test_AES_GCM_authenticated_encryption_test_case_7(void)
11474 {
11475 	return test_authenticated_encryption(&gcm_test_case_7);
11476 }
11477 
11478 static int
11479 test_AES_GCM_authenticated_encryption_test_case_8(void)
11480 {
11481 	return test_authenticated_encryption(&gcm_test_case_8);
11482 }
11483 
11484 static int
11485 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
11486 {
11487 	return test_authenticated_encryption(&gcm_J0_test_case_1);
11488 }
11489 
11490 static int
11491 test_AES_GCM_auth_encryption_test_case_192_1(void)
11492 {
11493 	return test_authenticated_encryption(&gcm_test_case_192_1);
11494 }
11495 
11496 static int
11497 test_AES_GCM_auth_encryption_test_case_192_2(void)
11498 {
11499 	return test_authenticated_encryption(&gcm_test_case_192_2);
11500 }
11501 
11502 static int
11503 test_AES_GCM_auth_encryption_test_case_192_3(void)
11504 {
11505 	return test_authenticated_encryption(&gcm_test_case_192_3);
11506 }
11507 
11508 static int
11509 test_AES_GCM_auth_encryption_test_case_192_4(void)
11510 {
11511 	return test_authenticated_encryption(&gcm_test_case_192_4);
11512 }
11513 
11514 static int
11515 test_AES_GCM_auth_encryption_test_case_192_5(void)
11516 {
11517 	return test_authenticated_encryption(&gcm_test_case_192_5);
11518 }
11519 
11520 static int
11521 test_AES_GCM_auth_encryption_test_case_192_6(void)
11522 {
11523 	return test_authenticated_encryption(&gcm_test_case_192_6);
11524 }
11525 
11526 static int
11527 test_AES_GCM_auth_encryption_test_case_192_7(void)
11528 {
11529 	return test_authenticated_encryption(&gcm_test_case_192_7);
11530 }
11531 
11532 static int
11533 test_AES_GCM_auth_encryption_test_case_256_1(void)
11534 {
11535 	return test_authenticated_encryption(&gcm_test_case_256_1);
11536 }
11537 
11538 static int
11539 test_AES_GCM_auth_encryption_test_case_256_2(void)
11540 {
11541 	return test_authenticated_encryption(&gcm_test_case_256_2);
11542 }
11543 
11544 static int
11545 test_AES_GCM_auth_encryption_test_case_256_3(void)
11546 {
11547 	return test_authenticated_encryption(&gcm_test_case_256_3);
11548 }
11549 
11550 static int
11551 test_AES_GCM_auth_encryption_test_case_256_4(void)
11552 {
11553 	return test_authenticated_encryption(&gcm_test_case_256_4);
11554 }
11555 
11556 static int
11557 test_AES_GCM_auth_encryption_test_case_256_5(void)
11558 {
11559 	return test_authenticated_encryption(&gcm_test_case_256_5);
11560 }
11561 
11562 static int
11563 test_AES_GCM_auth_encryption_test_case_256_6(void)
11564 {
11565 	return test_authenticated_encryption(&gcm_test_case_256_6);
11566 }
11567 
11568 static int
11569 test_AES_GCM_auth_encryption_test_case_256_7(void)
11570 {
11571 	return test_authenticated_encryption(&gcm_test_case_256_7);
11572 }
11573 
11574 static int
11575 test_AES_GCM_auth_encryption_test_case_aad_1(void)
11576 {
11577 	return test_authenticated_encryption(&gcm_test_case_aad_1);
11578 }
11579 
11580 static int
11581 test_AES_GCM_auth_encryption_test_case_aad_2(void)
11582 {
11583 	return test_authenticated_encryption(&gcm_test_case_aad_2);
11584 }
11585 
11586 static int
11587 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
11588 {
11589 	struct aead_test_data tdata;
11590 	int res;
11591 
11592 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
11593 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11594 	tdata.iv.data[0] += 1;
11595 	res = test_authenticated_encryption(&tdata);
11596 	if (res == TEST_SKIPPED)
11597 		return res;
11598 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
11599 	return TEST_SUCCESS;
11600 }
11601 
11602 static int
11603 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
11604 {
11605 	struct aead_test_data tdata;
11606 	int res;
11607 
11608 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
11609 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11610 	tdata.plaintext.data[0] += 1;
11611 	res = test_authenticated_encryption(&tdata);
11612 	if (res == TEST_SKIPPED)
11613 		return res;
11614 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
11615 	return TEST_SUCCESS;
11616 }
11617 
11618 static int
11619 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
11620 {
11621 	struct aead_test_data tdata;
11622 	int res;
11623 
11624 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
11625 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11626 	tdata.ciphertext.data[0] += 1;
11627 	res = test_authenticated_encryption(&tdata);
11628 	if (res == TEST_SKIPPED)
11629 		return res;
11630 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
11631 	return TEST_SUCCESS;
11632 }
11633 
11634 static int
11635 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
11636 {
11637 	struct aead_test_data tdata;
11638 	int res;
11639 
11640 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
11641 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11642 	tdata.aad.len += 1;
11643 	res = test_authenticated_encryption(&tdata);
11644 	if (res == TEST_SKIPPED)
11645 		return res;
11646 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
11647 	return TEST_SUCCESS;
11648 }
11649 
11650 static int
11651 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
11652 {
11653 	struct aead_test_data tdata;
11654 	uint8_t aad[gcm_test_case_7.aad.len];
11655 	int res;
11656 
11657 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
11658 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11659 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
11660 	aad[0] += 1;
11661 	tdata.aad.data = aad;
11662 	res = test_authenticated_encryption(&tdata);
11663 	if (res == TEST_SKIPPED)
11664 		return res;
11665 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
11666 	return TEST_SUCCESS;
11667 }
11668 
11669 static int
11670 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
11671 {
11672 	struct aead_test_data tdata;
11673 	int res;
11674 
11675 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
11676 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11677 	tdata.auth_tag.data[0] += 1;
11678 	res = test_authenticated_encryption(&tdata);
11679 	if (res == TEST_SKIPPED)
11680 		return res;
11681 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
11682 	return TEST_SUCCESS;
11683 }
11684 
11685 static int
11686 test_authenticated_decryption(const struct aead_test_data *tdata)
11687 {
11688 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11689 	struct crypto_unittest_params *ut_params = &unittest_params;
11690 
11691 	int retval;
11692 	uint8_t *plaintext;
11693 	uint32_t i;
11694 	struct rte_cryptodev_info dev_info;
11695 
11696 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11697 	uint64_t feat_flags = dev_info.feature_flags;
11698 
11699 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11700 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11701 		printf("Device doesn't support RAW data-path APIs.\n");
11702 		return TEST_SKIPPED;
11703 	}
11704 
11705 	/* Verify the capabilities */
11706 	struct rte_cryptodev_sym_capability_idx cap_idx;
11707 	const struct rte_cryptodev_symmetric_capability *capability;
11708 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
11709 	cap_idx.algo.aead = tdata->algo;
11710 	capability = rte_cryptodev_sym_capability_get(
11711 			ts_params->valid_devs[0], &cap_idx);
11712 	if (capability == NULL)
11713 		return TEST_SKIPPED;
11714 	if (rte_cryptodev_sym_capability_check_aead(
11715 			capability, tdata->key.len, tdata->auth_tag.len,
11716 			tdata->aad.len, tdata->iv.len))
11717 		return TEST_SKIPPED;
11718 
11719 	/* Create AEAD session */
11720 	retval = create_aead_session(ts_params->valid_devs[0],
11721 			tdata->algo,
11722 			RTE_CRYPTO_AEAD_OP_DECRYPT,
11723 			tdata->key.data, tdata->key.len,
11724 			tdata->aad.len, tdata->auth_tag.len,
11725 			tdata->iv.len);
11726 	if (retval != TEST_SUCCESS)
11727 		return retval;
11728 
11729 	/* alloc mbuf and set payload */
11730 	if (tdata->aad.len > MBUF_SIZE) {
11731 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
11732 		/* Populate full size of add data */
11733 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
11734 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
11735 	} else
11736 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11737 
11738 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11739 			rte_pktmbuf_tailroom(ut_params->ibuf));
11740 
11741 	/* Create AEAD operation */
11742 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
11743 	if (retval < 0)
11744 		return retval;
11745 
11746 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11747 
11748 	ut_params->op->sym->m_src = ut_params->ibuf;
11749 
11750 	/* Process crypto operation */
11751 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11752 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
11753 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
11754 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0,
11755 					       0);
11756 		if (retval != TEST_SUCCESS)
11757 			return retval;
11758 	} else
11759 		TEST_ASSERT_NOT_NULL(
11760 			process_crypto_request(ts_params->valid_devs[0],
11761 			ut_params->op), "failed to process sym crypto op");
11762 
11763 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11764 			"crypto op processing failed");
11765 
11766 	if (ut_params->op->sym->m_dst)
11767 		plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
11768 				uint8_t *);
11769 	else
11770 		plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
11771 				uint8_t *,
11772 				ut_params->op->sym->cipher.data.offset);
11773 
11774 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
11775 
11776 	/* Validate obuf */
11777 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11778 			plaintext,
11779 			tdata->plaintext.data,
11780 			tdata->plaintext.len,
11781 			"Plaintext data not as expected");
11782 
11783 	TEST_ASSERT_EQUAL(ut_params->op->status,
11784 			RTE_CRYPTO_OP_STATUS_SUCCESS,
11785 			"Authentication failed");
11786 
11787 	return 0;
11788 }
11789 
11790 static int
11791 test_AES_GCM_authenticated_decryption_test_case_1(void)
11792 {
11793 	return test_authenticated_decryption(&gcm_test_case_1);
11794 }
11795 
11796 static int
11797 test_AES_GCM_authenticated_decryption_test_case_2(void)
11798 {
11799 	return test_authenticated_decryption(&gcm_test_case_2);
11800 }
11801 
11802 static int
11803 test_AES_GCM_authenticated_decryption_test_case_3(void)
11804 {
11805 	return test_authenticated_decryption(&gcm_test_case_3);
11806 }
11807 
11808 static int
11809 test_AES_GCM_authenticated_decryption_test_case_4(void)
11810 {
11811 	return test_authenticated_decryption(&gcm_test_case_4);
11812 }
11813 
11814 static int
11815 test_AES_GCM_authenticated_decryption_test_case_5(void)
11816 {
11817 	return test_authenticated_decryption(&gcm_test_case_5);
11818 }
11819 
11820 static int
11821 test_AES_GCM_authenticated_decryption_test_case_6(void)
11822 {
11823 	return test_authenticated_decryption(&gcm_test_case_6);
11824 }
11825 
11826 static int
11827 test_AES_GCM_authenticated_decryption_test_case_7(void)
11828 {
11829 	return test_authenticated_decryption(&gcm_test_case_7);
11830 }
11831 
11832 static int
11833 test_AES_GCM_authenticated_decryption_test_case_8(void)
11834 {
11835 	return test_authenticated_decryption(&gcm_test_case_8);
11836 }
11837 
11838 static int
11839 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
11840 {
11841 	return test_authenticated_decryption(&gcm_J0_test_case_1);
11842 }
11843 
11844 static int
11845 test_AES_GCM_auth_decryption_test_case_192_1(void)
11846 {
11847 	return test_authenticated_decryption(&gcm_test_case_192_1);
11848 }
11849 
11850 static int
11851 test_AES_GCM_auth_decryption_test_case_192_2(void)
11852 {
11853 	return test_authenticated_decryption(&gcm_test_case_192_2);
11854 }
11855 
11856 static int
11857 test_AES_GCM_auth_decryption_test_case_192_3(void)
11858 {
11859 	return test_authenticated_decryption(&gcm_test_case_192_3);
11860 }
11861 
11862 static int
11863 test_AES_GCM_auth_decryption_test_case_192_4(void)
11864 {
11865 	return test_authenticated_decryption(&gcm_test_case_192_4);
11866 }
11867 
11868 static int
11869 test_AES_GCM_auth_decryption_test_case_192_5(void)
11870 {
11871 	return test_authenticated_decryption(&gcm_test_case_192_5);
11872 }
11873 
11874 static int
11875 test_AES_GCM_auth_decryption_test_case_192_6(void)
11876 {
11877 	return test_authenticated_decryption(&gcm_test_case_192_6);
11878 }
11879 
11880 static int
11881 test_AES_GCM_auth_decryption_test_case_192_7(void)
11882 {
11883 	return test_authenticated_decryption(&gcm_test_case_192_7);
11884 }
11885 
11886 static int
11887 test_AES_GCM_auth_decryption_test_case_256_1(void)
11888 {
11889 	return test_authenticated_decryption(&gcm_test_case_256_1);
11890 }
11891 
11892 static int
11893 test_AES_GCM_auth_decryption_test_case_256_2(void)
11894 {
11895 	return test_authenticated_decryption(&gcm_test_case_256_2);
11896 }
11897 
11898 static int
11899 test_AES_GCM_auth_decryption_test_case_256_3(void)
11900 {
11901 	return test_authenticated_decryption(&gcm_test_case_256_3);
11902 }
11903 
11904 static int
11905 test_AES_GCM_auth_decryption_test_case_256_4(void)
11906 {
11907 	return test_authenticated_decryption(&gcm_test_case_256_4);
11908 }
11909 
11910 static int
11911 test_AES_GCM_auth_decryption_test_case_256_5(void)
11912 {
11913 	return test_authenticated_decryption(&gcm_test_case_256_5);
11914 }
11915 
11916 static int
11917 test_AES_GCM_auth_decryption_test_case_256_6(void)
11918 {
11919 	return test_authenticated_decryption(&gcm_test_case_256_6);
11920 }
11921 
11922 static int
11923 test_AES_GCM_auth_decryption_test_case_256_7(void)
11924 {
11925 	return test_authenticated_decryption(&gcm_test_case_256_7);
11926 }
11927 
11928 static int
11929 test_AES_GCM_auth_decryption_test_case_aad_1(void)
11930 {
11931 	return test_authenticated_decryption(&gcm_test_case_aad_1);
11932 }
11933 
11934 static int
11935 test_AES_GCM_auth_decryption_test_case_aad_2(void)
11936 {
11937 	return test_authenticated_decryption(&gcm_test_case_aad_2);
11938 }
11939 
11940 static int
11941 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
11942 {
11943 	struct aead_test_data tdata;
11944 	int res;
11945 
11946 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11947 	tdata.iv.data[0] += 1;
11948 	res = test_authenticated_decryption(&tdata);
11949 	if (res == TEST_SKIPPED)
11950 		return res;
11951 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
11952 	return TEST_SUCCESS;
11953 }
11954 
11955 static int
11956 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
11957 {
11958 	struct aead_test_data tdata;
11959 	int res;
11960 
11961 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
11962 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11963 	tdata.plaintext.data[0] += 1;
11964 	res = test_authenticated_decryption(&tdata);
11965 	if (res == TEST_SKIPPED)
11966 		return res;
11967 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
11968 	return TEST_SUCCESS;
11969 }
11970 
11971 static int
11972 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
11973 {
11974 	struct aead_test_data tdata;
11975 	int res;
11976 
11977 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11978 	tdata.ciphertext.data[0] += 1;
11979 	res = test_authenticated_decryption(&tdata);
11980 	if (res == TEST_SKIPPED)
11981 		return res;
11982 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
11983 	return TEST_SUCCESS;
11984 }
11985 
11986 static int
11987 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
11988 {
11989 	struct aead_test_data tdata;
11990 	int res;
11991 
11992 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11993 	tdata.aad.len += 1;
11994 	res = test_authenticated_decryption(&tdata);
11995 	if (res == TEST_SKIPPED)
11996 		return res;
11997 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
11998 	return TEST_SUCCESS;
11999 }
12000 
12001 static int
12002 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
12003 {
12004 	struct aead_test_data tdata;
12005 	uint8_t aad[gcm_test_case_7.aad.len];
12006 	int res;
12007 
12008 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
12009 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
12010 	aad[0] += 1;
12011 	tdata.aad.data = aad;
12012 	res = test_authenticated_decryption(&tdata);
12013 	if (res == TEST_SKIPPED)
12014 		return res;
12015 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
12016 	return TEST_SUCCESS;
12017 }
12018 
12019 static int
12020 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
12021 {
12022 	struct aead_test_data tdata;
12023 	int res;
12024 
12025 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
12026 	tdata.auth_tag.data[0] += 1;
12027 	res = test_authenticated_decryption(&tdata);
12028 	if (res == TEST_SKIPPED)
12029 		return res;
12030 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
12031 	return TEST_SUCCESS;
12032 }
12033 
12034 static int
12035 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
12036 {
12037 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12038 	struct crypto_unittest_params *ut_params = &unittest_params;
12039 
12040 	int retval;
12041 	uint8_t *ciphertext, *auth_tag;
12042 	uint16_t plaintext_pad_len;
12043 	struct rte_cryptodev_info dev_info;
12044 
12045 	/* Verify the capabilities */
12046 	struct rte_cryptodev_sym_capability_idx cap_idx;
12047 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
12048 	cap_idx.algo.aead = tdata->algo;
12049 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12050 			&cap_idx) == NULL)
12051 		return TEST_SKIPPED;
12052 
12053 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12054 	uint64_t feat_flags = dev_info.feature_flags;
12055 
12056 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12057 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP)))
12058 		return TEST_SKIPPED;
12059 
12060 	/* not supported with CPU crypto */
12061 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12062 		return TEST_SKIPPED;
12063 
12064 	/* Create AEAD session */
12065 	retval = create_aead_session(ts_params->valid_devs[0],
12066 			tdata->algo,
12067 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
12068 			tdata->key.data, tdata->key.len,
12069 			tdata->aad.len, tdata->auth_tag.len,
12070 			tdata->iv.len);
12071 	if (retval < 0)
12072 		return retval;
12073 
12074 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12075 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12076 
12077 	/* clear mbuf payload */
12078 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12079 			rte_pktmbuf_tailroom(ut_params->ibuf));
12080 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
12081 			rte_pktmbuf_tailroom(ut_params->obuf));
12082 
12083 	/* Create AEAD operation */
12084 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
12085 	if (retval < 0)
12086 		return retval;
12087 
12088 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12089 
12090 	ut_params->op->sym->m_src = ut_params->ibuf;
12091 	ut_params->op->sym->m_dst = ut_params->obuf;
12092 
12093 	/* Process crypto operation */
12094 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
12095 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0,
12096 					       0);
12097 		if (retval != TEST_SUCCESS)
12098 			return retval;
12099 	} else
12100 		TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
12101 			ut_params->op), "failed to process sym crypto op");
12102 
12103 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12104 			"crypto op processing failed");
12105 
12106 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12107 
12108 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
12109 			ut_params->op->sym->cipher.data.offset);
12110 	auth_tag = ciphertext + plaintext_pad_len;
12111 
12112 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
12113 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
12114 
12115 	/* Validate obuf */
12116 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12117 			ciphertext,
12118 			tdata->ciphertext.data,
12119 			tdata->ciphertext.len,
12120 			"Ciphertext data not as expected");
12121 
12122 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12123 			auth_tag,
12124 			tdata->auth_tag.data,
12125 			tdata->auth_tag.len,
12126 			"Generated auth tag not as expected");
12127 
12128 	return 0;
12129 
12130 }
12131 
12132 static int
12133 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
12134 {
12135 	return test_authenticated_encryption_oop(&gcm_test_case_5);
12136 }
12137 
12138 static int
12139 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
12140 {
12141 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12142 	struct crypto_unittest_params *ut_params = &unittest_params;
12143 
12144 	int retval;
12145 	uint8_t *plaintext;
12146 	struct rte_cryptodev_info dev_info;
12147 
12148 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12149 	uint64_t feat_flags = dev_info.feature_flags;
12150 
12151 	/* Verify the capabilities */
12152 	struct rte_cryptodev_sym_capability_idx cap_idx;
12153 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
12154 	cap_idx.algo.aead = tdata->algo;
12155 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12156 			&cap_idx) == NULL)
12157 		return TEST_SKIPPED;
12158 
12159 	/* not supported with CPU crypto and raw data-path APIs*/
12160 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
12161 			global_api_test_type == CRYPTODEV_RAW_API_TEST)
12162 		return TEST_SKIPPED;
12163 
12164 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12165 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12166 		printf("Device does not support RAW data-path APIs.\n");
12167 		return TEST_SKIPPED;
12168 	}
12169 
12170 	/* Create AEAD session */
12171 	retval = create_aead_session(ts_params->valid_devs[0],
12172 			tdata->algo,
12173 			RTE_CRYPTO_AEAD_OP_DECRYPT,
12174 			tdata->key.data, tdata->key.len,
12175 			tdata->aad.len, tdata->auth_tag.len,
12176 			tdata->iv.len);
12177 	if (retval < 0)
12178 		return retval;
12179 
12180 	/* alloc mbuf and set payload */
12181 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12182 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12183 
12184 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12185 			rte_pktmbuf_tailroom(ut_params->ibuf));
12186 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
12187 			rte_pktmbuf_tailroom(ut_params->obuf));
12188 
12189 	/* Create AEAD operation */
12190 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
12191 	if (retval < 0)
12192 		return retval;
12193 
12194 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12195 
12196 	ut_params->op->sym->m_src = ut_params->ibuf;
12197 	ut_params->op->sym->m_dst = ut_params->obuf;
12198 
12199 	/* Process crypto operation */
12200 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
12201 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0,
12202 					       0);
12203 		if (retval != TEST_SUCCESS)
12204 			return retval;
12205 	} else
12206 		TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
12207 			ut_params->op), "failed to process sym crypto op");
12208 
12209 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12210 			"crypto op processing failed");
12211 
12212 	plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
12213 			ut_params->op->sym->cipher.data.offset);
12214 
12215 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
12216 
12217 	/* Validate obuf */
12218 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12219 			plaintext,
12220 			tdata->plaintext.data,
12221 			tdata->plaintext.len,
12222 			"Plaintext data not as expected");
12223 
12224 	TEST_ASSERT_EQUAL(ut_params->op->status,
12225 			RTE_CRYPTO_OP_STATUS_SUCCESS,
12226 			"Authentication failed");
12227 	return 0;
12228 }
12229 
12230 static int
12231 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
12232 {
12233 	return test_authenticated_decryption_oop(&gcm_test_case_5);
12234 }
12235 
12236 static int
12237 test_authenticated_encryption_sessionless(
12238 		const struct aead_test_data *tdata)
12239 {
12240 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12241 	struct crypto_unittest_params *ut_params = &unittest_params;
12242 
12243 	int retval;
12244 	uint8_t *ciphertext, *auth_tag;
12245 	uint16_t plaintext_pad_len;
12246 	uint8_t key[tdata->key.len + 1];
12247 	struct rte_cryptodev_info dev_info;
12248 
12249 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12250 	uint64_t feat_flags = dev_info.feature_flags;
12251 
12252 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
12253 		printf("Device doesn't support Sessionless ops.\n");
12254 		return TEST_SKIPPED;
12255 	}
12256 
12257 	/* not supported with CPU crypto */
12258 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12259 		return TEST_SKIPPED;
12260 
12261 	/* Verify the capabilities */
12262 	struct rte_cryptodev_sym_capability_idx cap_idx;
12263 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
12264 	cap_idx.algo.aead = tdata->algo;
12265 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12266 			&cap_idx) == NULL)
12267 		return TEST_SKIPPED;
12268 
12269 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12270 
12271 	/* clear mbuf payload */
12272 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12273 			rte_pktmbuf_tailroom(ut_params->ibuf));
12274 
12275 	/* Create AEAD operation */
12276 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
12277 	if (retval < 0)
12278 		return retval;
12279 
12280 	/* Create GCM xform */
12281 	memcpy(key, tdata->key.data, tdata->key.len);
12282 	retval = create_aead_xform(ut_params->op,
12283 			tdata->algo,
12284 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
12285 			key, tdata->key.len,
12286 			tdata->aad.len, tdata->auth_tag.len,
12287 			tdata->iv.len);
12288 	if (retval < 0)
12289 		return retval;
12290 
12291 	ut_params->op->sym->m_src = ut_params->ibuf;
12292 
12293 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
12294 			RTE_CRYPTO_OP_SESSIONLESS,
12295 			"crypto op session type not sessionless");
12296 
12297 	/* Process crypto operation */
12298 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
12299 			ut_params->op), "failed to process sym crypto op");
12300 
12301 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
12302 
12303 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12304 			"crypto op status not success");
12305 
12306 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12307 
12308 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
12309 			ut_params->op->sym->cipher.data.offset);
12310 	auth_tag = ciphertext + plaintext_pad_len;
12311 
12312 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
12313 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
12314 
12315 	/* Validate obuf */
12316 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12317 			ciphertext,
12318 			tdata->ciphertext.data,
12319 			tdata->ciphertext.len,
12320 			"Ciphertext data not as expected");
12321 
12322 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12323 			auth_tag,
12324 			tdata->auth_tag.data,
12325 			tdata->auth_tag.len,
12326 			"Generated auth tag not as expected");
12327 
12328 	return 0;
12329 
12330 }
12331 
12332 static int
12333 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
12334 {
12335 	return test_authenticated_encryption_sessionless(
12336 			&gcm_test_case_5);
12337 }
12338 
12339 static int
12340 test_authenticated_decryption_sessionless(
12341 		const struct aead_test_data *tdata)
12342 {
12343 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12344 	struct crypto_unittest_params *ut_params = &unittest_params;
12345 
12346 	int retval;
12347 	uint8_t *plaintext;
12348 	uint8_t key[tdata->key.len + 1];
12349 	struct rte_cryptodev_info dev_info;
12350 
12351 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12352 	uint64_t feat_flags = dev_info.feature_flags;
12353 
12354 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
12355 		printf("Device doesn't support Sessionless ops.\n");
12356 		return TEST_SKIPPED;
12357 	}
12358 
12359 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12360 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12361 		printf("Device doesn't support RAW data-path APIs.\n");
12362 		return TEST_SKIPPED;
12363 	}
12364 
12365 	/* not supported with CPU crypto */
12366 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12367 		return TEST_SKIPPED;
12368 
12369 	/* Verify the capabilities */
12370 	struct rte_cryptodev_sym_capability_idx cap_idx;
12371 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
12372 	cap_idx.algo.aead = tdata->algo;
12373 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12374 			&cap_idx) == NULL)
12375 		return TEST_SKIPPED;
12376 
12377 	/* alloc mbuf and set payload */
12378 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12379 
12380 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12381 			rte_pktmbuf_tailroom(ut_params->ibuf));
12382 
12383 	/* Create AEAD operation */
12384 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
12385 	if (retval < 0)
12386 		return retval;
12387 
12388 	/* Create AEAD xform */
12389 	memcpy(key, tdata->key.data, tdata->key.len);
12390 	retval = create_aead_xform(ut_params->op,
12391 			tdata->algo,
12392 			RTE_CRYPTO_AEAD_OP_DECRYPT,
12393 			key, tdata->key.len,
12394 			tdata->aad.len, tdata->auth_tag.len,
12395 			tdata->iv.len);
12396 	if (retval < 0)
12397 		return retval;
12398 
12399 	ut_params->op->sym->m_src = ut_params->ibuf;
12400 
12401 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
12402 			RTE_CRYPTO_OP_SESSIONLESS,
12403 			"crypto op session type not sessionless");
12404 
12405 	/* Process crypto operation */
12406 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
12407 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0,
12408 					       0);
12409 		if (retval != TEST_SUCCESS)
12410 			return retval;
12411 	} else
12412 		TEST_ASSERT_NOT_NULL(process_crypto_request(
12413 			ts_params->valid_devs[0], ut_params->op),
12414 				"failed to process sym crypto op");
12415 
12416 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
12417 
12418 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12419 			"crypto op status not success");
12420 
12421 	plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
12422 			ut_params->op->sym->cipher.data.offset);
12423 
12424 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
12425 
12426 	/* Validate obuf */
12427 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12428 			plaintext,
12429 			tdata->plaintext.data,
12430 			tdata->plaintext.len,
12431 			"Plaintext data not as expected");
12432 
12433 	TEST_ASSERT_EQUAL(ut_params->op->status,
12434 			RTE_CRYPTO_OP_STATUS_SUCCESS,
12435 			"Authentication failed");
12436 	return 0;
12437 }
12438 
12439 static int
12440 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
12441 {
12442 	return test_authenticated_decryption_sessionless(
12443 			&gcm_test_case_5);
12444 }
12445 
12446 static int
12447 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
12448 {
12449 	return test_authenticated_encryption(&ccm_test_case_128_1);
12450 }
12451 
12452 static int
12453 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
12454 {
12455 	return test_authenticated_encryption(&ccm_test_case_128_2);
12456 }
12457 
12458 static int
12459 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
12460 {
12461 	return test_authenticated_encryption(&ccm_test_case_128_3);
12462 }
12463 
12464 static int
12465 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
12466 {
12467 	return test_authenticated_decryption(&ccm_test_case_128_1);
12468 }
12469 
12470 static int
12471 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
12472 {
12473 	return test_authenticated_decryption(&ccm_test_case_128_2);
12474 }
12475 
12476 static int
12477 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
12478 {
12479 	return test_authenticated_decryption(&ccm_test_case_128_3);
12480 }
12481 
12482 static int
12483 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
12484 {
12485 	return test_authenticated_encryption(&ccm_test_case_192_1);
12486 }
12487 
12488 static int
12489 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
12490 {
12491 	return test_authenticated_encryption(&ccm_test_case_192_2);
12492 }
12493 
12494 static int
12495 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
12496 {
12497 	return test_authenticated_encryption(&ccm_test_case_192_3);
12498 }
12499 
12500 static int
12501 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
12502 {
12503 	return test_authenticated_decryption(&ccm_test_case_192_1);
12504 }
12505 
12506 static int
12507 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
12508 {
12509 	return test_authenticated_decryption(&ccm_test_case_192_2);
12510 }
12511 
12512 static int
12513 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
12514 {
12515 	return test_authenticated_decryption(&ccm_test_case_192_3);
12516 }
12517 
12518 static int
12519 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
12520 {
12521 	return test_authenticated_encryption(&ccm_test_case_256_1);
12522 }
12523 
12524 static int
12525 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
12526 {
12527 	return test_authenticated_encryption(&ccm_test_case_256_2);
12528 }
12529 
12530 static int
12531 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
12532 {
12533 	return test_authenticated_encryption(&ccm_test_case_256_3);
12534 }
12535 
12536 static int
12537 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
12538 {
12539 	return test_authenticated_decryption(&ccm_test_case_256_1);
12540 }
12541 
12542 static int
12543 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
12544 {
12545 	return test_authenticated_decryption(&ccm_test_case_256_2);
12546 }
12547 
12548 static int
12549 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
12550 {
12551 	return test_authenticated_decryption(&ccm_test_case_256_3);
12552 }
12553 
12554 static int
12555 test_stats(void)
12556 {
12557 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12558 	struct rte_cryptodev_stats stats;
12559 
12560 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12561 		return TEST_SKIPPED;
12562 
12563 	/* Verify the capabilities */
12564 	struct rte_cryptodev_sym_capability_idx cap_idx;
12565 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12566 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
12567 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12568 			&cap_idx) == NULL)
12569 		return TEST_SKIPPED;
12570 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12571 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
12572 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12573 			&cap_idx) == NULL)
12574 		return TEST_SKIPPED;
12575 
12576 	if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
12577 			== -ENOTSUP)
12578 		return TEST_SKIPPED;
12579 
12580 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
12581 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
12582 			&stats) == -ENODEV),
12583 		"rte_cryptodev_stats_get invalid dev failed");
12584 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
12585 		"rte_cryptodev_stats_get invalid Param failed");
12586 
12587 	/* Test expected values */
12588 	test_AES_CBC_HMAC_SHA1_encrypt_digest();
12589 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
12590 			&stats),
12591 		"rte_cryptodev_stats_get failed");
12592 	TEST_ASSERT((stats.enqueued_count == 1),
12593 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
12594 	TEST_ASSERT((stats.dequeued_count == 1),
12595 		"rte_cryptodev_stats_get returned unexpected dequeued stat");
12596 	TEST_ASSERT((stats.enqueue_err_count == 0),
12597 		"rte_cryptodev_stats_get returned unexpected enqueued error count stat");
12598 	TEST_ASSERT((stats.dequeue_err_count == 0),
12599 		"rte_cryptodev_stats_get returned unexpected dequeued error count stat");
12600 
12601 	/* invalid device but should ignore and not reset device stats*/
12602 	rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
12603 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
12604 			&stats),
12605 		"rte_cryptodev_stats_get failed");
12606 	TEST_ASSERT((stats.enqueued_count == 1),
12607 		"rte_cryptodev_stats_get returned unexpected enqueued stat after invalid reset");
12608 
12609 	/* check that a valid reset clears stats */
12610 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
12611 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
12612 			&stats),
12613 					  "rte_cryptodev_stats_get failed");
12614 	TEST_ASSERT((stats.enqueued_count == 0),
12615 		"rte_cryptodev_stats_get returned unexpected enqueued stat after valid reset");
12616 	TEST_ASSERT((stats.dequeued_count == 0),
12617 		"rte_cryptodev_stats_get returned unexpected dequeued stat after valid reset");
12618 
12619 	return TEST_SUCCESS;
12620 }
12621 
12622 static int
12623 test_device_reconfigure(void)
12624 {
12625 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12626 	uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
12627 	struct rte_cryptodev_qp_conf qp_conf = {
12628 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT,
12629 		.mp_session = ts_params->session_mpool
12630 	};
12631 	uint16_t qp_id, dev_id, num_devs = 0;
12632 
12633 	TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
12634 			"Need at least %d devices for test", 1);
12635 
12636 	dev_id = ts_params->valid_devs[0];
12637 
12638 	/* Stop the device in case it's started so it can be configured */
12639 	rte_cryptodev_stop(dev_id);
12640 
12641 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
12642 			"Failed test for rte_cryptodev_configure: "
12643 			"dev_num %u", dev_id);
12644 
12645 	/* Reconfigure with same configure params */
12646 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
12647 			"Failed test for rte_cryptodev_configure: "
12648 			"dev_num %u", dev_id);
12649 
12650 	/* Reconfigure with just one queue pair */
12651 	ts_params->conf.nb_queue_pairs = 1;
12652 
12653 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
12654 			&ts_params->conf),
12655 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
12656 			ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
12657 
12658 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
12659 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
12660 				ts_params->valid_devs[0], qp_id, &qp_conf,
12661 				rte_cryptodev_socket_id(
12662 						ts_params->valid_devs[0])),
12663 				"Failed test for "
12664 				"rte_cryptodev_queue_pair_setup: num_inflights "
12665 				"%u on qp %u on cryptodev %u",
12666 				qp_conf.nb_descriptors, qp_id,
12667 				ts_params->valid_devs[0]);
12668 	}
12669 
12670 	/* Reconfigure with max number of queue pairs */
12671 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
12672 
12673 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
12674 			&ts_params->conf),
12675 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
12676 			ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
12677 
12678 	qp_conf.mp_session = ts_params->session_mpool;
12679 
12680 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
12681 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
12682 				ts_params->valid_devs[0], qp_id, &qp_conf,
12683 				rte_cryptodev_socket_id(
12684 						ts_params->valid_devs[0])),
12685 				"Failed test for "
12686 				"rte_cryptodev_queue_pair_setup: num_inflights "
12687 				"%u on qp %u on cryptodev %u",
12688 				qp_conf.nb_descriptors, qp_id,
12689 				ts_params->valid_devs[0]);
12690 	}
12691 
12692 	/* Start the device */
12693 	TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
12694 			"Failed to start cryptodev %u",
12695 			ts_params->valid_devs[0]);
12696 
12697 	/* Test expected values */
12698 	return test_AES_CBC_HMAC_SHA1_encrypt_digest();
12699 }
12700 
12701 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
12702 				   struct crypto_unittest_params *ut_params,
12703 				   enum rte_crypto_auth_operation op,
12704 				   const struct HMAC_MD5_vector *test_case)
12705 {
12706 	uint8_t key[64];
12707 
12708 	memcpy(key, test_case->key.data, test_case->key.len);
12709 
12710 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12711 	ut_params->auth_xform.next = NULL;
12712 	ut_params->auth_xform.auth.op = op;
12713 
12714 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
12715 
12716 	ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
12717 	ut_params->auth_xform.auth.key.length = test_case->key.len;
12718 	ut_params->auth_xform.auth.key.data = key;
12719 
12720 	ut_params->sess = rte_cryptodev_sym_session_create(
12721 		ts_params->valid_devs[0], &ut_params->auth_xform,
12722 			ts_params->session_mpool);
12723 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
12724 		return TEST_SKIPPED;
12725 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12726 
12727 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12728 
12729 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12730 			rte_pktmbuf_tailroom(ut_params->ibuf));
12731 
12732 	return 0;
12733 }
12734 
12735 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
12736 			      const struct HMAC_MD5_vector *test_case,
12737 			      uint8_t **plaintext)
12738 {
12739 	uint16_t plaintext_pad_len;
12740 
12741 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12742 
12743 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
12744 				16);
12745 
12746 	*plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12747 			plaintext_pad_len);
12748 	memcpy(*plaintext, test_case->plaintext.data,
12749 			test_case->plaintext.len);
12750 
12751 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12752 			ut_params->ibuf, MD5_DIGEST_LEN);
12753 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12754 			"no room to append digest");
12755 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12756 			ut_params->ibuf, plaintext_pad_len);
12757 
12758 	if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
12759 		rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
12760 			   test_case->auth_tag.len);
12761 	}
12762 
12763 	sym_op->auth.data.offset = 0;
12764 	sym_op->auth.data.length = test_case->plaintext.len;
12765 
12766 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12767 	ut_params->op->sym->m_src = ut_params->ibuf;
12768 
12769 	return 0;
12770 }
12771 
12772 static int
12773 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
12774 {
12775 	uint16_t plaintext_pad_len;
12776 	uint8_t *plaintext, *auth_tag;
12777 	int ret;
12778 
12779 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12780 	struct crypto_unittest_params *ut_params = &unittest_params;
12781 	struct rte_cryptodev_info dev_info;
12782 
12783 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12784 	uint64_t feat_flags = dev_info.feature_flags;
12785 
12786 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12787 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12788 		printf("Device doesn't support RAW data-path APIs.\n");
12789 		return TEST_SKIPPED;
12790 	}
12791 
12792 	/* Verify the capabilities */
12793 	struct rte_cryptodev_sym_capability_idx cap_idx;
12794 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12795 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
12796 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12797 			&cap_idx) == NULL)
12798 		return TEST_SKIPPED;
12799 
12800 	if (MD5_HMAC_create_session(ts_params, ut_params,
12801 			RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
12802 		return TEST_FAILED;
12803 
12804 	/* Generate Crypto op data structure */
12805 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12806 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12807 	TEST_ASSERT_NOT_NULL(ut_params->op,
12808 			"Failed to allocate symmetric crypto operation struct");
12809 
12810 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
12811 				16);
12812 
12813 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
12814 		return TEST_FAILED;
12815 
12816 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12817 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12818 			ut_params->op);
12819 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
12820 		ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 0);
12821 		if (ret != TEST_SUCCESS)
12822 			return ret;
12823 	} else
12824 		TEST_ASSERT_NOT_NULL(
12825 			process_crypto_request(ts_params->valid_devs[0],
12826 				ut_params->op),
12827 				"failed to process sym crypto op");
12828 
12829 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12830 			"crypto op processing failed");
12831 
12832 	if (ut_params->op->sym->m_dst) {
12833 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
12834 				uint8_t *, plaintext_pad_len);
12835 	} else {
12836 		auth_tag = plaintext + plaintext_pad_len;
12837 	}
12838 
12839 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12840 			auth_tag,
12841 			test_case->auth_tag.data,
12842 			test_case->auth_tag.len,
12843 			"HMAC_MD5 generated tag not as expected");
12844 
12845 	return TEST_SUCCESS;
12846 }
12847 
12848 static int
12849 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
12850 {
12851 	uint8_t *plaintext;
12852 	int ret;
12853 
12854 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12855 	struct crypto_unittest_params *ut_params = &unittest_params;
12856 	struct rte_cryptodev_info dev_info;
12857 
12858 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12859 	uint64_t feat_flags = dev_info.feature_flags;
12860 
12861 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12862 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12863 		printf("Device doesn't support RAW data-path APIs.\n");
12864 		return TEST_SKIPPED;
12865 	}
12866 
12867 	/* Verify the capabilities */
12868 	struct rte_cryptodev_sym_capability_idx cap_idx;
12869 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12870 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
12871 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12872 			&cap_idx) == NULL)
12873 		return TEST_SKIPPED;
12874 
12875 	if (MD5_HMAC_create_session(ts_params, ut_params,
12876 			RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
12877 		return TEST_FAILED;
12878 	}
12879 
12880 	/* Generate Crypto op data structure */
12881 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12882 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12883 	TEST_ASSERT_NOT_NULL(ut_params->op,
12884 			"Failed to allocate symmetric crypto operation struct");
12885 
12886 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
12887 		return TEST_FAILED;
12888 
12889 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12890 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12891 			ut_params->op);
12892 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
12893 		ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 0);
12894 		if (ret != TEST_SUCCESS)
12895 			return ret;
12896 	} else
12897 		TEST_ASSERT_NOT_NULL(
12898 			process_crypto_request(ts_params->valid_devs[0],
12899 				ut_params->op),
12900 				"failed to process sym crypto op");
12901 
12902 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12903 			"HMAC_MD5 crypto op processing failed");
12904 
12905 	return TEST_SUCCESS;
12906 }
12907 
12908 static int
12909 test_MD5_HMAC_generate_case_1(void)
12910 {
12911 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
12912 }
12913 
12914 static int
12915 test_MD5_HMAC_verify_case_1(void)
12916 {
12917 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
12918 }
12919 
12920 static int
12921 test_MD5_HMAC_generate_case_2(void)
12922 {
12923 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
12924 }
12925 
12926 static int
12927 test_MD5_HMAC_verify_case_2(void)
12928 {
12929 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
12930 }
12931 
12932 static int
12933 test_multi_session(void)
12934 {
12935 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12936 	struct crypto_unittest_params *ut_params = &unittest_params;
12937 	struct rte_cryptodev_info dev_info;
12938 	int i, nb_sess, ret = TEST_SUCCESS;
12939 	void **sessions;
12940 
12941 	/* Verify the capabilities */
12942 	struct rte_cryptodev_sym_capability_idx cap_idx;
12943 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12944 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
12945 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12946 			&cap_idx) == NULL)
12947 		return TEST_SKIPPED;
12948 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12949 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
12950 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12951 			&cap_idx) == NULL)
12952 		return TEST_SKIPPED;
12953 
12954 	test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
12955 			aes_cbc_key, hmac_sha512_key);
12956 
12957 
12958 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12959 
12960 	sessions = rte_malloc(NULL,
12961 			sizeof(void *) *
12962 			(MAX_NB_SESSIONS + 1), 0);
12963 
12964 	/* Create multiple crypto sessions*/
12965 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
12966 		sessions[i] = rte_cryptodev_sym_session_create(
12967 			ts_params->valid_devs[0], &ut_params->auth_xform,
12968 				ts_params->session_mpool);
12969 		if (sessions[i] == NULL && rte_errno == ENOTSUP) {
12970 			nb_sess = i;
12971 			ret = TEST_SKIPPED;
12972 			break;
12973 		}
12974 
12975 		TEST_ASSERT_NOT_NULL(sessions[i],
12976 				"Session creation failed at session number %u",
12977 				i);
12978 
12979 		/* Attempt to send a request on each session */
12980 		ret = test_AES_CBC_HMAC_SHA512_decrypt_perform(
12981 			sessions[i],
12982 			ut_params,
12983 			ts_params,
12984 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
12985 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
12986 			aes_cbc_iv);
12987 
12988 		/* free crypto operation structure */
12989 		rte_crypto_op_free(ut_params->op);
12990 
12991 		/*
12992 		 * free mbuf - both obuf and ibuf are usually the same,
12993 		 * so check if they point at the same address is necessary,
12994 		 * to avoid freeing the mbuf twice.
12995 		 */
12996 		if (ut_params->obuf) {
12997 			rte_pktmbuf_free(ut_params->obuf);
12998 			if (ut_params->ibuf == ut_params->obuf)
12999 				ut_params->ibuf = 0;
13000 			ut_params->obuf = 0;
13001 		}
13002 		if (ut_params->ibuf) {
13003 			rte_pktmbuf_free(ut_params->ibuf);
13004 			ut_params->ibuf = 0;
13005 		}
13006 
13007 		if (ret != TEST_SUCCESS) {
13008 			i++;
13009 			break;
13010 		}
13011 	}
13012 
13013 	nb_sess = i;
13014 
13015 	for (i = 0; i < nb_sess; i++) {
13016 		rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
13017 				sessions[i]);
13018 	}
13019 
13020 	rte_free(sessions);
13021 
13022 	if (ret != TEST_SKIPPED)
13023 		TEST_ASSERT_SUCCESS(ret, "Failed to perform decrypt on request number %u.", i - 1);
13024 
13025 	return ret;
13026 }
13027 
13028 struct multi_session_params {
13029 	struct crypto_unittest_params ut_params;
13030 	uint8_t *cipher_key;
13031 	uint8_t *hmac_key;
13032 	const uint8_t *cipher;
13033 	const uint8_t *digest;
13034 	uint8_t *iv;
13035 };
13036 
13037 #define MB_SESSION_NUMBER 3
13038 
13039 static int
13040 test_multi_session_random_usage(void)
13041 {
13042 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13043 	struct rte_cryptodev_info dev_info;
13044 	int index = 0, ret = TEST_SUCCESS;
13045 	uint32_t nb_sess, i, j;
13046 	void **sessions;
13047 	struct multi_session_params ut_paramz[] = {
13048 
13049 		{
13050 			.cipher_key = ms_aes_cbc_key0,
13051 			.hmac_key = ms_hmac_key0,
13052 			.cipher = ms_aes_cbc_cipher0,
13053 			.digest = ms_hmac_digest0,
13054 			.iv = ms_aes_cbc_iv0
13055 		},
13056 		{
13057 			.cipher_key = ms_aes_cbc_key1,
13058 			.hmac_key = ms_hmac_key1,
13059 			.cipher = ms_aes_cbc_cipher1,
13060 			.digest = ms_hmac_digest1,
13061 			.iv = ms_aes_cbc_iv1
13062 		},
13063 		{
13064 			.cipher_key = ms_aes_cbc_key2,
13065 			.hmac_key = ms_hmac_key2,
13066 			.cipher = ms_aes_cbc_cipher2,
13067 			.digest = ms_hmac_digest2,
13068 			.iv = ms_aes_cbc_iv2
13069 		},
13070 
13071 	};
13072 
13073 	/* Verify the capabilities */
13074 	struct rte_cryptodev_sym_capability_idx cap_idx;
13075 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13076 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
13077 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13078 			&cap_idx) == NULL)
13079 		return TEST_SKIPPED;
13080 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13081 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
13082 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13083 			&cap_idx) == NULL)
13084 		return TEST_SKIPPED;
13085 
13086 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13087 
13088 	sessions = rte_malloc(NULL, (sizeof(void *)
13089 					* MAX_NB_SESSIONS) + 1, 0);
13090 
13091 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
13092 
13093 		rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
13094 				sizeof(struct crypto_unittest_params));
13095 
13096 		test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
13097 				&ut_paramz[i].ut_params,
13098 				ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
13099 
13100 		/* Create multiple crypto sessions*/
13101 		sessions[i] = rte_cryptodev_sym_session_create(
13102 				ts_params->valid_devs[0],
13103 				&ut_paramz[i].ut_params.auth_xform,
13104 				ts_params->session_mpool);
13105 		if (sessions[i] == NULL && rte_errno == ENOTSUP) {
13106 			nb_sess = i;
13107 			ret = TEST_SKIPPED;
13108 			goto session_clear;
13109 		}
13110 
13111 		TEST_ASSERT_NOT_NULL(sessions[i],
13112 				"Session creation failed at session number %u",
13113 				i);
13114 	}
13115 
13116 	nb_sess = i;
13117 
13118 	srand(time(NULL));
13119 	for (i = 0; i < 40000; i++) {
13120 
13121 		j = rand() % MB_SESSION_NUMBER;
13122 
13123 		ret = test_AES_CBC_HMAC_SHA512_decrypt_perform(
13124 					sessions[j],
13125 					&ut_paramz[j].ut_params,
13126 					ts_params, ut_paramz[j].cipher,
13127 					ut_paramz[j].digest,
13128 					ut_paramz[j].iv);
13129 
13130 		rte_crypto_op_free(ut_paramz[j].ut_params.op);
13131 
13132 		/*
13133 		 * free mbuf - both obuf and ibuf are usually the same,
13134 		 * so check if they point at the same address is necessary,
13135 		 * to avoid freeing the mbuf twice.
13136 		 */
13137 		if (ut_paramz[j].ut_params.obuf) {
13138 			rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
13139 			if (ut_paramz[j].ut_params.ibuf
13140 					== ut_paramz[j].ut_params.obuf)
13141 				ut_paramz[j].ut_params.ibuf = 0;
13142 			ut_paramz[j].ut_params.obuf = 0;
13143 		}
13144 		if (ut_paramz[j].ut_params.ibuf) {
13145 			rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
13146 			ut_paramz[j].ut_params.ibuf = 0;
13147 		}
13148 
13149 		if (ret != TEST_SKIPPED) {
13150 			index = i;
13151 			break;
13152 		}
13153 	}
13154 
13155 session_clear:
13156 	for (i = 0; i < nb_sess; i++) {
13157 		rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
13158 				sessions[i]);
13159 	}
13160 
13161 	rte_free(sessions);
13162 
13163 	if (ret != TEST_SKIPPED)
13164 		TEST_ASSERT_SUCCESS(ret, "Failed to perform decrypt on request number %u.", index);
13165 
13166 	return TEST_SUCCESS;
13167 }
13168 
13169 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
13170 			0xab, 0xab, 0xab, 0xab,
13171 			0xab, 0xab, 0xab, 0xab,
13172 			0xab, 0xab, 0xab, 0xab};
13173 
13174 static int
13175 test_null_invalid_operation(void)
13176 {
13177 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13178 	struct crypto_unittest_params *ut_params = &unittest_params;
13179 
13180 	/* This test is for NULL PMD only */
13181 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
13182 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
13183 		return TEST_SKIPPED;
13184 
13185 	/* Setup Cipher Parameters */
13186 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13187 	ut_params->cipher_xform.next = NULL;
13188 
13189 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
13190 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
13191 
13192 	/* Create Crypto session*/
13193 	ut_params->sess = rte_cryptodev_sym_session_create(
13194 			ts_params->valid_devs[0], &ut_params->cipher_xform,
13195 			ts_params->session_mpool);
13196 	TEST_ASSERT(ut_params->sess == NULL,
13197 			"Session creation succeeded unexpectedly");
13198 
13199 	/* Setup HMAC Parameters */
13200 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13201 	ut_params->auth_xform.next = NULL;
13202 
13203 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
13204 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
13205 
13206 	/* Create Crypto session*/
13207 	ut_params->sess = rte_cryptodev_sym_session_create(
13208 			ts_params->valid_devs[0], &ut_params->auth_xform,
13209 			ts_params->session_mpool);
13210 	TEST_ASSERT(ut_params->sess == NULL,
13211 			"Session creation succeeded unexpectedly");
13212 
13213 	return TEST_SUCCESS;
13214 }
13215 
13216 
13217 #define NULL_BURST_LENGTH (32)
13218 
13219 static int
13220 test_null_burst_operation(void)
13221 {
13222 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13223 	struct crypto_unittest_params *ut_params = &unittest_params;
13224 
13225 	unsigned i, burst_len = NULL_BURST_LENGTH;
13226 
13227 	struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
13228 	struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
13229 
13230 	/* This test is for NULL PMD only */
13231 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
13232 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
13233 		return TEST_SKIPPED;
13234 
13235 	/* Setup Cipher Parameters */
13236 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13237 	ut_params->cipher_xform.next = &ut_params->auth_xform;
13238 
13239 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
13240 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
13241 
13242 	/* Setup HMAC Parameters */
13243 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13244 	ut_params->auth_xform.next = NULL;
13245 
13246 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
13247 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
13248 
13249 	/* Create Crypto session*/
13250 	ut_params->sess = rte_cryptodev_sym_session_create(
13251 				ts_params->valid_devs[0],
13252 				&ut_params->auth_xform,
13253 				ts_params->session_mpool);
13254 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
13255 		return TEST_SKIPPED;
13256 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13257 
13258 	TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
13259 			RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
13260 			burst_len, "failed to generate burst of crypto ops");
13261 
13262 	/* Generate an operation for each mbuf in burst */
13263 	for (i = 0; i < burst_len; i++) {
13264 		struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13265 
13266 		TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
13267 
13268 		unsigned *data = (unsigned *)rte_pktmbuf_append(m,
13269 				sizeof(unsigned));
13270 		*data = i;
13271 
13272 		rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
13273 
13274 		burst[i]->sym->m_src = m;
13275 	}
13276 
13277 	/* Process crypto operation */
13278 	TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
13279 			0, burst, burst_len),
13280 			burst_len,
13281 			"Error enqueuing burst");
13282 
13283 	TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
13284 			0, burst_dequeued, burst_len),
13285 			burst_len,
13286 			"Error dequeuing burst");
13287 
13288 
13289 	for (i = 0; i < burst_len; i++) {
13290 		TEST_ASSERT_EQUAL(
13291 			*rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
13292 			*rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
13293 					uint32_t *),
13294 			"data not as expected");
13295 
13296 		rte_pktmbuf_free(burst[i]->sym->m_src);
13297 		rte_crypto_op_free(burst[i]);
13298 	}
13299 
13300 	return TEST_SUCCESS;
13301 }
13302 
13303 static uint16_t
13304 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
13305 		  uint16_t nb_ops, void *user_param)
13306 {
13307 	RTE_SET_USED(dev_id);
13308 	RTE_SET_USED(qp_id);
13309 	RTE_SET_USED(ops);
13310 	RTE_SET_USED(user_param);
13311 
13312 	printf("crypto enqueue callback called\n");
13313 	return nb_ops;
13314 }
13315 
13316 static uint16_t
13317 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
13318 		  uint16_t nb_ops, void *user_param)
13319 {
13320 	RTE_SET_USED(dev_id);
13321 	RTE_SET_USED(qp_id);
13322 	RTE_SET_USED(ops);
13323 	RTE_SET_USED(user_param);
13324 
13325 	printf("crypto dequeue callback called\n");
13326 	return nb_ops;
13327 }
13328 
13329 /*
13330  * Thread using enqueue/dequeue callback with RCU.
13331  */
13332 static int
13333 test_enqdeq_callback_thread(void *arg)
13334 {
13335 	RTE_SET_USED(arg);
13336 	/* DP thread calls rte_cryptodev_enqueue_burst()/
13337 	 * rte_cryptodev_dequeue_burst() and invokes callback.
13338 	 */
13339 	test_null_burst_operation();
13340 	return 0;
13341 }
13342 
13343 static int
13344 test_enq_callback_setup(void)
13345 {
13346 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13347 	struct rte_cryptodev_info dev_info;
13348 	struct rte_cryptodev_qp_conf qp_conf = {
13349 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
13350 	};
13351 
13352 	struct rte_cryptodev_cb *cb;
13353 	uint16_t qp_id = 0;
13354 
13355 	/* Stop the device in case it's started so it can be configured */
13356 	rte_cryptodev_stop(ts_params->valid_devs[0]);
13357 
13358 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13359 
13360 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
13361 			&ts_params->conf),
13362 			"Failed to configure cryptodev %u",
13363 			ts_params->valid_devs[0]);
13364 
13365 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
13366 	qp_conf.mp_session = ts_params->session_mpool;
13367 
13368 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
13369 			ts_params->valid_devs[0], qp_id, &qp_conf,
13370 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
13371 			"Failed test for "
13372 			"rte_cryptodev_queue_pair_setup: num_inflights "
13373 			"%u on qp %u on cryptodev %u",
13374 			qp_conf.nb_descriptors, qp_id,
13375 			ts_params->valid_devs[0]);
13376 
13377 	/* Test with invalid crypto device */
13378 	cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
13379 			qp_id, test_enq_callback, NULL);
13380 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
13381 			"cryptodev %u did not fail",
13382 			qp_id, RTE_CRYPTO_MAX_DEVS);
13383 
13384 	/* Test with invalid queue pair */
13385 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
13386 			dev_info.max_nb_queue_pairs + 1,
13387 			test_enq_callback, NULL);
13388 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
13389 			"cryptodev %u did not fail",
13390 			dev_info.max_nb_queue_pairs + 1,
13391 			ts_params->valid_devs[0]);
13392 
13393 	/* Test with NULL callback */
13394 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
13395 			qp_id, NULL, NULL);
13396 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
13397 			"cryptodev %u did not fail",
13398 			qp_id, ts_params->valid_devs[0]);
13399 
13400 	/* Test with valid configuration */
13401 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
13402 			qp_id, test_enq_callback, NULL);
13403 	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
13404 			"qp %u on cryptodev %u",
13405 			qp_id, ts_params->valid_devs[0]);
13406 
13407 	rte_cryptodev_start(ts_params->valid_devs[0]);
13408 
13409 	/* Launch a thread */
13410 	rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
13411 				rte_get_next_lcore(-1, 1, 0));
13412 
13413 	/* Wait until reader exited. */
13414 	rte_eal_mp_wait_lcore();
13415 
13416 	/* Test with invalid crypto device */
13417 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
13418 			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
13419 			"Expected call to fail as crypto device is invalid");
13420 
13421 	/* Test with invalid queue pair */
13422 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
13423 			ts_params->valid_devs[0],
13424 			dev_info.max_nb_queue_pairs + 1, cb),
13425 			"Expected call to fail as queue pair is invalid");
13426 
13427 	/* Test with NULL callback */
13428 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
13429 			ts_params->valid_devs[0], qp_id, NULL),
13430 			"Expected call to fail as callback is NULL");
13431 
13432 	/* Test with valid configuration */
13433 	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
13434 			ts_params->valid_devs[0], qp_id, cb),
13435 			"Failed test to remove callback on "
13436 			"qp %u on cryptodev %u",
13437 			qp_id, ts_params->valid_devs[0]);
13438 
13439 	return TEST_SUCCESS;
13440 }
13441 
13442 static int
13443 test_deq_callback_setup(void)
13444 {
13445 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13446 	struct rte_cryptodev_info dev_info;
13447 	struct rte_cryptodev_qp_conf qp_conf = {
13448 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
13449 	};
13450 
13451 	struct rte_cryptodev_cb *cb;
13452 	uint16_t qp_id = 0;
13453 
13454 	/* Stop the device in case it's started so it can be configured */
13455 	rte_cryptodev_stop(ts_params->valid_devs[0]);
13456 
13457 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13458 
13459 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
13460 			&ts_params->conf),
13461 			"Failed to configure cryptodev %u",
13462 			ts_params->valid_devs[0]);
13463 
13464 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
13465 	qp_conf.mp_session = ts_params->session_mpool;
13466 
13467 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
13468 			ts_params->valid_devs[0], qp_id, &qp_conf,
13469 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
13470 			"Failed test for "
13471 			"rte_cryptodev_queue_pair_setup: num_inflights "
13472 			"%u on qp %u on cryptodev %u",
13473 			qp_conf.nb_descriptors, qp_id,
13474 			ts_params->valid_devs[0]);
13475 
13476 	/* Test with invalid crypto device */
13477 	cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
13478 			qp_id, test_deq_callback, NULL);
13479 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
13480 			"cryptodev %u did not fail",
13481 			qp_id, RTE_CRYPTO_MAX_DEVS);
13482 
13483 	/* Test with invalid queue pair */
13484 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
13485 			dev_info.max_nb_queue_pairs + 1,
13486 			test_deq_callback, NULL);
13487 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
13488 			"cryptodev %u did not fail",
13489 			dev_info.max_nb_queue_pairs + 1,
13490 			ts_params->valid_devs[0]);
13491 
13492 	/* Test with NULL callback */
13493 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
13494 			qp_id, NULL, NULL);
13495 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
13496 			"cryptodev %u did not fail",
13497 			qp_id, ts_params->valid_devs[0]);
13498 
13499 	/* Test with valid configuration */
13500 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
13501 			qp_id, test_deq_callback, NULL);
13502 	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
13503 			"qp %u on cryptodev %u",
13504 			qp_id, ts_params->valid_devs[0]);
13505 
13506 	rte_cryptodev_start(ts_params->valid_devs[0]);
13507 
13508 	/* Launch a thread */
13509 	rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
13510 				rte_get_next_lcore(-1, 1, 0));
13511 
13512 	/* Wait until reader exited. */
13513 	rte_eal_mp_wait_lcore();
13514 
13515 	/* Test with invalid crypto device */
13516 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
13517 			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
13518 			"Expected call to fail as crypto device is invalid");
13519 
13520 	/* Test with invalid queue pair */
13521 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
13522 			ts_params->valid_devs[0],
13523 			dev_info.max_nb_queue_pairs + 1, cb),
13524 			"Expected call to fail as queue pair is invalid");
13525 
13526 	/* Test with NULL callback */
13527 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
13528 			ts_params->valid_devs[0], qp_id, NULL),
13529 			"Expected call to fail as callback is NULL");
13530 
13531 	/* Test with valid configuration */
13532 	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
13533 			ts_params->valid_devs[0], qp_id, cb),
13534 			"Failed test to remove callback on "
13535 			"qp %u on cryptodev %u",
13536 			qp_id, ts_params->valid_devs[0]);
13537 
13538 	return TEST_SUCCESS;
13539 }
13540 
13541 static void
13542 generate_gmac_large_plaintext(uint8_t *data)
13543 {
13544 	uint16_t i;
13545 
13546 	for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
13547 		memcpy(&data[i], &data[0], 32);
13548 }
13549 
13550 static int
13551 create_gmac_operation(enum rte_crypto_auth_operation op,
13552 		const struct gmac_test_data *tdata)
13553 {
13554 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13555 	struct crypto_unittest_params *ut_params = &unittest_params;
13556 	struct rte_crypto_sym_op *sym_op;
13557 
13558 	uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
13559 
13560 	/* Generate Crypto op data structure */
13561 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
13562 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
13563 	TEST_ASSERT_NOT_NULL(ut_params->op,
13564 			"Failed to allocate symmetric crypto operation struct");
13565 
13566 	sym_op = ut_params->op->sym;
13567 
13568 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
13569 			ut_params->ibuf, tdata->gmac_tag.len);
13570 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
13571 			"no room to append digest");
13572 
13573 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
13574 			ut_params->ibuf, plaintext_pad_len);
13575 
13576 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
13577 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
13578 				tdata->gmac_tag.len);
13579 		debug_hexdump(stdout, "digest:",
13580 				sym_op->auth.digest.data,
13581 				tdata->gmac_tag.len);
13582 	}
13583 
13584 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
13585 			uint8_t *, IV_OFFSET);
13586 
13587 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
13588 
13589 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
13590 
13591 	sym_op->cipher.data.length = 0;
13592 	sym_op->cipher.data.offset = 0;
13593 
13594 	sym_op->auth.data.offset = 0;
13595 	sym_op->auth.data.length = tdata->plaintext.len;
13596 
13597 	return 0;
13598 }
13599 
13600 static int
13601 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
13602 		const struct gmac_test_data *tdata,
13603 		void *digest_mem, uint64_t digest_phys)
13604 {
13605 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13606 	struct crypto_unittest_params *ut_params = &unittest_params;
13607 	struct rte_crypto_sym_op *sym_op;
13608 
13609 	/* Generate Crypto op data structure */
13610 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
13611 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
13612 	TEST_ASSERT_NOT_NULL(ut_params->op,
13613 			"Failed to allocate symmetric crypto operation struct");
13614 
13615 	sym_op = ut_params->op->sym;
13616 
13617 	sym_op->auth.digest.data = digest_mem;
13618 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
13619 			"no room to append digest");
13620 
13621 	sym_op->auth.digest.phys_addr = digest_phys;
13622 
13623 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
13624 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
13625 				tdata->gmac_tag.len);
13626 		debug_hexdump(stdout, "digest:",
13627 				sym_op->auth.digest.data,
13628 				tdata->gmac_tag.len);
13629 	}
13630 
13631 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
13632 			uint8_t *, IV_OFFSET);
13633 
13634 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
13635 
13636 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
13637 
13638 	sym_op->cipher.data.length = 0;
13639 	sym_op->cipher.data.offset = 0;
13640 
13641 	sym_op->auth.data.offset = 0;
13642 	sym_op->auth.data.length = tdata->plaintext.len;
13643 
13644 	return 0;
13645 }
13646 
13647 static int create_gmac_session(uint8_t dev_id,
13648 		const struct gmac_test_data *tdata,
13649 		enum rte_crypto_auth_operation auth_op)
13650 {
13651 	uint8_t auth_key[tdata->key.len];
13652 
13653 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13654 	struct crypto_unittest_params *ut_params = &unittest_params;
13655 
13656 	memcpy(auth_key, tdata->key.data, tdata->key.len);
13657 
13658 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13659 	ut_params->auth_xform.next = NULL;
13660 
13661 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
13662 	ut_params->auth_xform.auth.op = auth_op;
13663 	ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
13664 	ut_params->auth_xform.auth.key.length = tdata->key.len;
13665 	ut_params->auth_xform.auth.key.data = auth_key;
13666 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
13667 	ut_params->auth_xform.auth.iv.length = tdata->iv.len;
13668 
13669 
13670 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
13671 			&ut_params->auth_xform, ts_params->session_mpool);
13672 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
13673 		return TEST_SKIPPED;
13674 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13675 
13676 	return 0;
13677 }
13678 
13679 static int
13680 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
13681 {
13682 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13683 	struct crypto_unittest_params *ut_params = &unittest_params;
13684 	struct rte_cryptodev_info dev_info;
13685 
13686 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13687 	uint64_t feat_flags = dev_info.feature_flags;
13688 
13689 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13690 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13691 		printf("Device doesn't support RAW data-path APIs.\n");
13692 		return TEST_SKIPPED;
13693 	}
13694 
13695 	int retval;
13696 
13697 	uint8_t *auth_tag, *plaintext;
13698 	uint16_t plaintext_pad_len;
13699 
13700 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
13701 			      "No GMAC length in the source data");
13702 
13703 	/* Verify the capabilities */
13704 	struct rte_cryptodev_sym_capability_idx cap_idx;
13705 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13706 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
13707 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13708 			&cap_idx) == NULL)
13709 		return TEST_SKIPPED;
13710 
13711 	retval = create_gmac_session(ts_params->valid_devs[0],
13712 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
13713 
13714 	if (retval == TEST_SKIPPED)
13715 		return TEST_SKIPPED;
13716 	if (retval < 0)
13717 		return retval;
13718 
13719 	if (tdata->plaintext.len > MBUF_SIZE)
13720 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
13721 	else
13722 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13723 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13724 			"Failed to allocate input buffer in mempool");
13725 
13726 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13727 			rte_pktmbuf_tailroom(ut_params->ibuf));
13728 
13729 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
13730 	/*
13731 	 * Runtime generate the large plain text instead of use hard code
13732 	 * plain text vector. It is done to avoid create huge source file
13733 	 * with the test vector.
13734 	 */
13735 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
13736 		generate_gmac_large_plaintext(tdata->plaintext.data);
13737 
13738 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13739 				plaintext_pad_len);
13740 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13741 
13742 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
13743 	debug_hexdump(stdout, "plaintext:", plaintext,
13744 			tdata->plaintext.len);
13745 
13746 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
13747 			tdata);
13748 
13749 	if (retval < 0)
13750 		return retval;
13751 
13752 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13753 
13754 	ut_params->op->sym->m_src = ut_params->ibuf;
13755 
13756 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13757 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13758 			ut_params->op);
13759 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
13760 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0,
13761 					       0);
13762 		if (retval != TEST_SUCCESS)
13763 			return retval;
13764 	} else
13765 		TEST_ASSERT_NOT_NULL(
13766 			process_crypto_request(ts_params->valid_devs[0],
13767 			ut_params->op), "failed to process sym crypto op");
13768 
13769 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13770 			"crypto op processing failed");
13771 
13772 	if (ut_params->op->sym->m_dst) {
13773 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
13774 				uint8_t *, plaintext_pad_len);
13775 	} else {
13776 		auth_tag = plaintext + plaintext_pad_len;
13777 	}
13778 
13779 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
13780 
13781 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13782 			auth_tag,
13783 			tdata->gmac_tag.data,
13784 			tdata->gmac_tag.len,
13785 			"GMAC Generated auth tag not as expected");
13786 
13787 	return 0;
13788 }
13789 
13790 static int
13791 test_AES_GMAC_authentication_test_case_1(void)
13792 {
13793 	return test_AES_GMAC_authentication(&gmac_test_case_1);
13794 }
13795 
13796 static int
13797 test_AES_GMAC_authentication_test_case_2(void)
13798 {
13799 	return test_AES_GMAC_authentication(&gmac_test_case_2);
13800 }
13801 
13802 static int
13803 test_AES_GMAC_authentication_test_case_3(void)
13804 {
13805 	return test_AES_GMAC_authentication(&gmac_test_case_3);
13806 }
13807 
13808 static int
13809 test_AES_GMAC_authentication_test_case_4(void)
13810 {
13811 	return test_AES_GMAC_authentication(&gmac_test_case_4);
13812 }
13813 
13814 static int
13815 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
13816 {
13817 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13818 	struct crypto_unittest_params *ut_params = &unittest_params;
13819 	int retval;
13820 	uint32_t plaintext_pad_len;
13821 	uint8_t *plaintext;
13822 	struct rte_cryptodev_info dev_info;
13823 
13824 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13825 	uint64_t feat_flags = dev_info.feature_flags;
13826 
13827 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13828 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13829 		printf("Device doesn't support RAW data-path APIs.\n");
13830 		return TEST_SKIPPED;
13831 	}
13832 
13833 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
13834 			      "No GMAC length in the source data");
13835 
13836 	/* Verify the capabilities */
13837 	struct rte_cryptodev_sym_capability_idx cap_idx;
13838 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13839 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
13840 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13841 			&cap_idx) == NULL)
13842 		return TEST_SKIPPED;
13843 
13844 	retval = create_gmac_session(ts_params->valid_devs[0],
13845 			tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
13846 
13847 	if (retval == TEST_SKIPPED)
13848 		return TEST_SKIPPED;
13849 	if (retval < 0)
13850 		return retval;
13851 
13852 	if (tdata->plaintext.len > MBUF_SIZE)
13853 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
13854 	else
13855 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13856 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13857 			"Failed to allocate input buffer in mempool");
13858 
13859 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13860 			rte_pktmbuf_tailroom(ut_params->ibuf));
13861 
13862 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
13863 
13864 	/*
13865 	 * Runtime generate the large plain text instead of use hard code
13866 	 * plain text vector. It is done to avoid create huge source file
13867 	 * with the test vector.
13868 	 */
13869 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
13870 		generate_gmac_large_plaintext(tdata->plaintext.data);
13871 
13872 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13873 				plaintext_pad_len);
13874 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13875 
13876 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
13877 	debug_hexdump(stdout, "plaintext:", plaintext,
13878 			tdata->plaintext.len);
13879 
13880 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
13881 			tdata);
13882 
13883 	if (retval < 0)
13884 		return retval;
13885 
13886 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13887 
13888 	ut_params->op->sym->m_src = ut_params->ibuf;
13889 
13890 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13891 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13892 			ut_params->op);
13893 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
13894 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0,
13895 					       0);
13896 		if (retval != TEST_SUCCESS)
13897 			return retval;
13898 	} else
13899 		TEST_ASSERT_NOT_NULL(
13900 			process_crypto_request(ts_params->valid_devs[0],
13901 			ut_params->op), "failed to process sym crypto op");
13902 
13903 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13904 			"crypto op processing failed");
13905 
13906 	return 0;
13907 
13908 }
13909 
13910 static int
13911 test_AES_GMAC_authentication_verify_test_case_1(void)
13912 {
13913 	return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
13914 }
13915 
13916 static int
13917 test_AES_GMAC_authentication_verify_test_case_2(void)
13918 {
13919 	return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
13920 }
13921 
13922 static int
13923 test_AES_GMAC_authentication_verify_test_case_3(void)
13924 {
13925 	return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
13926 }
13927 
13928 static int
13929 test_AES_GMAC_authentication_verify_test_case_4(void)
13930 {
13931 	return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
13932 }
13933 
13934 static int
13935 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
13936 				uint32_t fragsz)
13937 {
13938 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13939 	struct crypto_unittest_params *ut_params = &unittest_params;
13940 	struct rte_cryptodev_info dev_info;
13941 	uint64_t feature_flags;
13942 	unsigned int trn_data = 0;
13943 	void *digest_mem = NULL;
13944 	uint32_t segs = 1;
13945 	unsigned int to_trn = 0;
13946 	struct rte_mbuf *buf = NULL;
13947 	uint8_t *auth_tag, *plaintext;
13948 	int retval;
13949 
13950 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
13951 			      "No GMAC length in the source data");
13952 
13953 	/* Verify the capabilities */
13954 	struct rte_cryptodev_sym_capability_idx cap_idx;
13955 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13956 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
13957 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13958 			&cap_idx) == NULL)
13959 		return TEST_SKIPPED;
13960 
13961 	/* Check for any input SGL support */
13962 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13963 	feature_flags = dev_info.feature_flags;
13964 
13965 	if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
13966 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
13967 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
13968 		return TEST_SKIPPED;
13969 
13970 	if (fragsz > tdata->plaintext.len)
13971 		fragsz = tdata->plaintext.len;
13972 
13973 	uint16_t plaintext_len = fragsz;
13974 
13975 	retval = create_gmac_session(ts_params->valid_devs[0],
13976 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
13977 
13978 	if (retval == TEST_SKIPPED)
13979 		return TEST_SKIPPED;
13980 	if (retval < 0)
13981 		return retval;
13982 
13983 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13984 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13985 			"Failed to allocate input buffer in mempool");
13986 
13987 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13988 			rte_pktmbuf_tailroom(ut_params->ibuf));
13989 
13990 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13991 				plaintext_len);
13992 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13993 
13994 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
13995 
13996 	trn_data += plaintext_len;
13997 
13998 	buf = ut_params->ibuf;
13999 
14000 	/*
14001 	 * Loop until no more fragments
14002 	 */
14003 
14004 	while (trn_data < tdata->plaintext.len) {
14005 		++segs;
14006 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
14007 				(tdata->plaintext.len - trn_data) : fragsz;
14008 
14009 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14010 		buf = buf->next;
14011 
14012 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
14013 				rte_pktmbuf_tailroom(buf));
14014 
14015 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
14016 				to_trn);
14017 
14018 		memcpy(plaintext, tdata->plaintext.data + trn_data,
14019 				to_trn);
14020 		trn_data += to_trn;
14021 		if (trn_data  == tdata->plaintext.len)
14022 			digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
14023 					tdata->gmac_tag.len);
14024 	}
14025 	ut_params->ibuf->nb_segs = segs;
14026 
14027 	/*
14028 	 * Place digest at the end of the last buffer
14029 	 */
14030 	uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
14031 
14032 	if (!digest_mem) {
14033 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
14034 				+ tdata->gmac_tag.len);
14035 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
14036 				tdata->plaintext.len);
14037 	}
14038 
14039 	retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
14040 			tdata, digest_mem, digest_phys);
14041 
14042 	if (retval < 0)
14043 		return retval;
14044 
14045 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
14046 
14047 	ut_params->op->sym->m_src = ut_params->ibuf;
14048 
14049 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
14050 		return TEST_SKIPPED;
14051 
14052 	TEST_ASSERT_NOT_NULL(
14053 		process_crypto_request(ts_params->valid_devs[0],
14054 		ut_params->op), "failed to process sym crypto op");
14055 
14056 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
14057 			"crypto op processing failed");
14058 
14059 	auth_tag = digest_mem;
14060 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
14061 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
14062 			auth_tag,
14063 			tdata->gmac_tag.data,
14064 			tdata->gmac_tag.len,
14065 			"GMAC Generated auth tag not as expected");
14066 
14067 	return 0;
14068 }
14069 
14070 /* Segment size not multiple of block size (16B) */
14071 static int
14072 test_AES_GMAC_authentication_SGL_40B(void)
14073 {
14074 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
14075 }
14076 
14077 static int
14078 test_AES_GMAC_authentication_SGL_80B(void)
14079 {
14080 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
14081 }
14082 
14083 static int
14084 test_AES_GMAC_authentication_SGL_2048B(void)
14085 {
14086 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
14087 }
14088 
14089 /* Segment size not multiple of block size (16B) */
14090 static int
14091 test_AES_GMAC_authentication_SGL_2047B(void)
14092 {
14093 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
14094 }
14095 
14096 struct test_crypto_vector {
14097 	enum rte_crypto_cipher_algorithm crypto_algo;
14098 	unsigned int cipher_offset;
14099 	unsigned int cipher_len;
14100 
14101 	struct {
14102 		uint8_t data[64];
14103 		unsigned int len;
14104 	} cipher_key;
14105 
14106 	struct {
14107 		uint8_t data[64];
14108 		unsigned int len;
14109 	} iv;
14110 
14111 	struct {
14112 		const uint8_t *data;
14113 		unsigned int len;
14114 	} plaintext;
14115 
14116 	struct {
14117 		const uint8_t *data;
14118 		unsigned int len;
14119 	} ciphertext;
14120 
14121 	enum rte_crypto_auth_algorithm auth_algo;
14122 	unsigned int auth_offset;
14123 
14124 	struct {
14125 		uint8_t data[128];
14126 		unsigned int len;
14127 	} auth_key;
14128 
14129 	struct {
14130 		const uint8_t *data;
14131 		unsigned int len;
14132 	} aad;
14133 
14134 	struct {
14135 		uint8_t data[128];
14136 		unsigned int len;
14137 	} digest;
14138 };
14139 
14140 static const struct test_crypto_vector
14141 hmac_sha1_test_crypto_vector = {
14142 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
14143 	.plaintext = {
14144 		.data = plaintext_hash,
14145 		.len = 512
14146 	},
14147 	.auth_key = {
14148 		.data = {
14149 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
14150 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
14151 			0xDE, 0xF4, 0xDE, 0xAD
14152 		},
14153 		.len = 20
14154 	},
14155 	.digest = {
14156 		.data = {
14157 			0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
14158 			0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
14159 			0x3F, 0x91, 0x64, 0x59
14160 		},
14161 		.len = 20
14162 	}
14163 };
14164 
14165 static const struct test_crypto_vector
14166 aes128_gmac_test_vector = {
14167 	.auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
14168 	.plaintext = {
14169 		.data = plaintext_hash,
14170 		.len = 512
14171 	},
14172 	.iv = {
14173 		.data = {
14174 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
14175 			0x08, 0x09, 0x0A, 0x0B
14176 		},
14177 		.len = 12
14178 	},
14179 	.auth_key = {
14180 		.data = {
14181 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
14182 			0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
14183 		},
14184 		.len = 16
14185 	},
14186 	.digest = {
14187 		.data = {
14188 			0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
14189 			0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
14190 		},
14191 		.len = 16
14192 	}
14193 };
14194 
14195 static const struct test_crypto_vector
14196 aes128cbc_hmac_sha1_test_vector = {
14197 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
14198 	.cipher_offset = 0,
14199 	.cipher_len = 512,
14200 	.cipher_key = {
14201 		.data = {
14202 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
14203 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
14204 		},
14205 		.len = 16
14206 	},
14207 	.iv = {
14208 		.data = {
14209 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
14210 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
14211 		},
14212 		.len = 16
14213 	},
14214 	.plaintext = {
14215 		.data = plaintext_hash,
14216 		.len = 512
14217 	},
14218 	.ciphertext = {
14219 		.data = ciphertext512_aes128cbc,
14220 		.len = 512
14221 	},
14222 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
14223 	.auth_offset = 0,
14224 	.auth_key = {
14225 		.data = {
14226 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
14227 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
14228 			0xDE, 0xF4, 0xDE, 0xAD
14229 		},
14230 		.len = 20
14231 	},
14232 	.digest = {
14233 		.data = {
14234 			0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
14235 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
14236 			0x18, 0x8C, 0x1D, 0x32
14237 		},
14238 		.len = 20
14239 	}
14240 };
14241 
14242 static const struct test_crypto_vector
14243 aes128cbc_hmac_sha1_aad_test_vector = {
14244 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
14245 	.cipher_offset = 8,
14246 	.cipher_len = 496,
14247 	.cipher_key = {
14248 		.data = {
14249 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
14250 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
14251 		},
14252 		.len = 16
14253 	},
14254 	.iv = {
14255 		.data = {
14256 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
14257 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
14258 		},
14259 		.len = 16
14260 	},
14261 	.plaintext = {
14262 		.data = plaintext_hash,
14263 		.len = 512
14264 	},
14265 	.ciphertext = {
14266 		.data = ciphertext512_aes128cbc_aad,
14267 		.len = 512
14268 	},
14269 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
14270 	.auth_offset = 0,
14271 	.auth_key = {
14272 		.data = {
14273 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
14274 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
14275 			0xDE, 0xF4, 0xDE, 0xAD
14276 		},
14277 		.len = 20
14278 	},
14279 	.digest = {
14280 		.data = {
14281 			0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
14282 			0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
14283 			0x62, 0x0F, 0xFB, 0x10
14284 		},
14285 		.len = 20
14286 	}
14287 };
14288 
14289 static void
14290 data_corruption(uint8_t *data)
14291 {
14292 	data[0] += 1;
14293 }
14294 
14295 static void
14296 tag_corruption(uint8_t *data, unsigned int tag_offset)
14297 {
14298 	data[tag_offset] += 1;
14299 }
14300 
14301 static int
14302 create_auth_session(struct crypto_unittest_params *ut_params,
14303 		uint8_t dev_id,
14304 		const struct test_crypto_vector *reference,
14305 		enum rte_crypto_auth_operation auth_op)
14306 {
14307 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14308 	uint8_t auth_key[reference->auth_key.len + 1];
14309 
14310 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
14311 
14312 	/* Setup Authentication Parameters */
14313 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14314 	ut_params->auth_xform.auth.op = auth_op;
14315 	ut_params->auth_xform.next = NULL;
14316 	ut_params->auth_xform.auth.algo = reference->auth_algo;
14317 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
14318 	ut_params->auth_xform.auth.key.data = auth_key;
14319 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
14320 
14321 	/* Create Crypto session*/
14322 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
14323 				&ut_params->auth_xform,
14324 				ts_params->session_mpool);
14325 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
14326 		return TEST_SKIPPED;
14327 
14328 	return 0;
14329 }
14330 
14331 static int
14332 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
14333 		uint8_t dev_id,
14334 		const struct test_crypto_vector *reference,
14335 		enum rte_crypto_auth_operation auth_op,
14336 		enum rte_crypto_cipher_operation cipher_op)
14337 {
14338 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14339 	uint8_t cipher_key[reference->cipher_key.len + 1];
14340 	uint8_t auth_key[reference->auth_key.len + 1];
14341 
14342 	memcpy(cipher_key, reference->cipher_key.data,
14343 			reference->cipher_key.len);
14344 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
14345 
14346 	/* Setup Authentication Parameters */
14347 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14348 	ut_params->auth_xform.auth.op = auth_op;
14349 	ut_params->auth_xform.auth.algo = reference->auth_algo;
14350 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
14351 	ut_params->auth_xform.auth.key.data = auth_key;
14352 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
14353 
14354 	if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
14355 		ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
14356 		ut_params->auth_xform.auth.iv.length = reference->iv.len;
14357 	} else {
14358 		ut_params->auth_xform.next = &ut_params->cipher_xform;
14359 
14360 		/* Setup Cipher Parameters */
14361 		ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
14362 		ut_params->cipher_xform.next = NULL;
14363 		ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
14364 		ut_params->cipher_xform.cipher.op = cipher_op;
14365 		ut_params->cipher_xform.cipher.key.data = cipher_key;
14366 		ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
14367 		ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
14368 		ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
14369 	}
14370 
14371 	/* Create Crypto session*/
14372 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
14373 				&ut_params->auth_xform,
14374 				ts_params->session_mpool);
14375 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
14376 		return TEST_SKIPPED;
14377 
14378 	return 0;
14379 }
14380 
14381 static int
14382 create_auth_operation(struct crypto_testsuite_params *ts_params,
14383 		struct crypto_unittest_params *ut_params,
14384 		const struct test_crypto_vector *reference,
14385 		unsigned int auth_generate)
14386 {
14387 	/* Generate Crypto op data structure */
14388 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
14389 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
14390 	TEST_ASSERT_NOT_NULL(ut_params->op,
14391 			"Failed to allocate pktmbuf offload");
14392 
14393 	/* Set crypto operation data parameters */
14394 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
14395 
14396 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
14397 
14398 	/* set crypto operation source mbuf */
14399 	sym_op->m_src = ut_params->ibuf;
14400 
14401 	/* digest */
14402 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
14403 			ut_params->ibuf, reference->digest.len);
14404 
14405 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
14406 			"no room to append auth tag");
14407 
14408 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
14409 			ut_params->ibuf, reference->plaintext.len);
14410 
14411 	if (auth_generate)
14412 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
14413 	else
14414 		memcpy(sym_op->auth.digest.data,
14415 				reference->digest.data,
14416 				reference->digest.len);
14417 
14418 	debug_hexdump(stdout, "digest:",
14419 			sym_op->auth.digest.data,
14420 			reference->digest.len);
14421 
14422 	sym_op->auth.data.length = reference->plaintext.len;
14423 	sym_op->auth.data.offset = 0;
14424 
14425 	return 0;
14426 }
14427 
14428 static int
14429 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
14430 		struct crypto_unittest_params *ut_params,
14431 		const struct test_crypto_vector *reference,
14432 		unsigned int auth_generate)
14433 {
14434 	/* Generate Crypto op data structure */
14435 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
14436 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
14437 	TEST_ASSERT_NOT_NULL(ut_params->op,
14438 			"Failed to allocate pktmbuf offload");
14439 
14440 	/* Set crypto operation data parameters */
14441 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
14442 
14443 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
14444 
14445 	/* set crypto operation source mbuf */
14446 	sym_op->m_src = ut_params->ibuf;
14447 
14448 	/* digest */
14449 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
14450 			ut_params->ibuf, reference->digest.len);
14451 
14452 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
14453 			"no room to append auth tag");
14454 
14455 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
14456 			ut_params->ibuf, reference->ciphertext.len);
14457 
14458 	if (auth_generate)
14459 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
14460 	else
14461 		memcpy(sym_op->auth.digest.data,
14462 				reference->digest.data,
14463 				reference->digest.len);
14464 
14465 	debug_hexdump(stdout, "digest:",
14466 			sym_op->auth.digest.data,
14467 			reference->digest.len);
14468 
14469 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
14470 			reference->iv.data, reference->iv.len);
14471 
14472 	sym_op->cipher.data.length = 0;
14473 	sym_op->cipher.data.offset = 0;
14474 
14475 	sym_op->auth.data.length = reference->plaintext.len;
14476 	sym_op->auth.data.offset = 0;
14477 
14478 	return 0;
14479 }
14480 
14481 static int
14482 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
14483 		struct crypto_unittest_params *ut_params,
14484 		const struct test_crypto_vector *reference,
14485 		unsigned int auth_generate)
14486 {
14487 	/* Generate Crypto op data structure */
14488 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
14489 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
14490 	TEST_ASSERT_NOT_NULL(ut_params->op,
14491 			"Failed to allocate pktmbuf offload");
14492 
14493 	/* Set crypto operation data parameters */
14494 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
14495 
14496 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
14497 
14498 	/* set crypto operation source mbuf */
14499 	sym_op->m_src = ut_params->ibuf;
14500 
14501 	/* digest */
14502 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
14503 			ut_params->ibuf, reference->digest.len);
14504 
14505 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
14506 			"no room to append auth tag");
14507 
14508 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
14509 			ut_params->ibuf, reference->ciphertext.len);
14510 
14511 	if (auth_generate)
14512 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
14513 	else
14514 		memcpy(sym_op->auth.digest.data,
14515 				reference->digest.data,
14516 				reference->digest.len);
14517 
14518 	debug_hexdump(stdout, "digest:",
14519 			sym_op->auth.digest.data,
14520 			reference->digest.len);
14521 
14522 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
14523 			reference->iv.data, reference->iv.len);
14524 
14525 	sym_op->cipher.data.length = reference->cipher_len;
14526 	sym_op->cipher.data.offset = reference->cipher_offset;
14527 
14528 	sym_op->auth.data.length = reference->plaintext.len;
14529 	sym_op->auth.data.offset = reference->auth_offset;
14530 
14531 	return 0;
14532 }
14533 
14534 static int
14535 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
14536 		struct crypto_unittest_params *ut_params,
14537 		const struct test_crypto_vector *reference)
14538 {
14539 	return create_auth_operation(ts_params, ut_params, reference, 0);
14540 }
14541 
14542 static int
14543 create_auth_verify_GMAC_operation(
14544 		struct crypto_testsuite_params *ts_params,
14545 		struct crypto_unittest_params *ut_params,
14546 		const struct test_crypto_vector *reference)
14547 {
14548 	return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
14549 }
14550 
14551 static int
14552 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
14553 		struct crypto_unittest_params *ut_params,
14554 		const struct test_crypto_vector *reference)
14555 {
14556 	return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
14557 }
14558 
14559 static int
14560 test_authentication_verify_fail_when_data_corruption(
14561 		struct crypto_testsuite_params *ts_params,
14562 		struct crypto_unittest_params *ut_params,
14563 		const struct test_crypto_vector *reference,
14564 		unsigned int data_corrupted)
14565 {
14566 	int retval;
14567 
14568 	uint8_t *plaintext;
14569 	struct rte_cryptodev_info dev_info;
14570 
14571 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
14572 	uint64_t feat_flags = dev_info.feature_flags;
14573 
14574 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
14575 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
14576 		printf("Device doesn't support RAW data-path APIs.\n");
14577 		return TEST_SKIPPED;
14578 	}
14579 
14580 	/* Verify the capabilities */
14581 	struct rte_cryptodev_sym_capability_idx cap_idx;
14582 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14583 	cap_idx.algo.auth = reference->auth_algo;
14584 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14585 			&cap_idx) == NULL)
14586 		return TEST_SKIPPED;
14587 
14588 
14589 	/* Create session */
14590 	retval = create_auth_session(ut_params,
14591 			ts_params->valid_devs[0],
14592 			reference,
14593 			RTE_CRYPTO_AUTH_OP_VERIFY);
14594 
14595 	if (retval == TEST_SKIPPED)
14596 		return TEST_SKIPPED;
14597 	if (retval < 0)
14598 		return retval;
14599 
14600 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14601 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
14602 			"Failed to allocate input buffer in mempool");
14603 
14604 	/* clear mbuf payload */
14605 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
14606 			rte_pktmbuf_tailroom(ut_params->ibuf));
14607 
14608 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
14609 			reference->plaintext.len);
14610 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
14611 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
14612 
14613 	debug_hexdump(stdout, "plaintext:", plaintext,
14614 		reference->plaintext.len);
14615 
14616 	/* Create operation */
14617 	retval = create_auth_verify_operation(ts_params, ut_params, reference);
14618 
14619 	if (retval < 0)
14620 		return retval;
14621 
14622 	if (data_corrupted)
14623 		data_corruption(plaintext);
14624 	else
14625 		tag_corruption(plaintext, reference->plaintext.len);
14626 
14627 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
14628 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
14629 			ut_params->op);
14630 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
14631 			RTE_CRYPTO_OP_STATUS_SUCCESS,
14632 			"authentication not failed");
14633 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
14634 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0,
14635 					       0);
14636 		if (retval != TEST_SUCCESS)
14637 			return retval;
14638 	} else {
14639 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
14640 			ut_params->op);
14641 	}
14642 	if (ut_params->op == NULL)
14643 		return 0;
14644 	else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS)
14645 		return 0;
14646 
14647 	return -1;
14648 }
14649 
14650 static int
14651 test_authentication_verify_GMAC_fail_when_corruption(
14652 		struct crypto_testsuite_params *ts_params,
14653 		struct crypto_unittest_params *ut_params,
14654 		const struct test_crypto_vector *reference,
14655 		unsigned int data_corrupted)
14656 {
14657 	int retval;
14658 	uint8_t *plaintext;
14659 	struct rte_cryptodev_info dev_info;
14660 
14661 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
14662 	uint64_t feat_flags = dev_info.feature_flags;
14663 
14664 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
14665 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
14666 		printf("Device doesn't support RAW data-path APIs.\n");
14667 		return TEST_SKIPPED;
14668 	}
14669 
14670 	/* Verify the capabilities */
14671 	struct rte_cryptodev_sym_capability_idx cap_idx;
14672 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14673 	cap_idx.algo.auth = reference->auth_algo;
14674 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14675 			&cap_idx) == NULL)
14676 		return TEST_SKIPPED;
14677 
14678 	/* Create session */
14679 	retval = create_auth_cipher_session(ut_params,
14680 			ts_params->valid_devs[0],
14681 			reference,
14682 			RTE_CRYPTO_AUTH_OP_VERIFY,
14683 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
14684 	if (retval == TEST_SKIPPED)
14685 		return TEST_SKIPPED;
14686 	if (retval < 0)
14687 		return retval;
14688 
14689 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14690 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
14691 			"Failed to allocate input buffer in mempool");
14692 
14693 	/* clear mbuf payload */
14694 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
14695 			rte_pktmbuf_tailroom(ut_params->ibuf));
14696 
14697 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
14698 			reference->plaintext.len);
14699 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
14700 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
14701 
14702 	debug_hexdump(stdout, "plaintext:", plaintext,
14703 		reference->plaintext.len);
14704 
14705 	/* Create operation */
14706 	retval = create_auth_verify_GMAC_operation(ts_params,
14707 			ut_params,
14708 			reference);
14709 
14710 	if (retval < 0)
14711 		return retval;
14712 
14713 	if (data_corrupted)
14714 		data_corruption(plaintext);
14715 	else
14716 		tag_corruption(plaintext, reference->aad.len);
14717 
14718 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
14719 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
14720 			ut_params->op);
14721 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
14722 			RTE_CRYPTO_OP_STATUS_SUCCESS,
14723 			"authentication not failed");
14724 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
14725 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0,
14726 					       0);
14727 		if (retval != TEST_SUCCESS)
14728 			return retval;
14729 	} else {
14730 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
14731 			ut_params->op);
14732 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
14733 	}
14734 
14735 	return 0;
14736 }
14737 
14738 static int
14739 test_authenticated_decryption_fail_when_corruption(
14740 		struct crypto_testsuite_params *ts_params,
14741 		struct crypto_unittest_params *ut_params,
14742 		const struct test_crypto_vector *reference,
14743 		unsigned int data_corrupted)
14744 {
14745 	int retval;
14746 
14747 	uint8_t *ciphertext;
14748 	struct rte_cryptodev_info dev_info;
14749 
14750 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
14751 	uint64_t feat_flags = dev_info.feature_flags;
14752 
14753 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
14754 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
14755 		printf("Device doesn't support RAW data-path APIs.\n");
14756 		return TEST_SKIPPED;
14757 	}
14758 
14759 	/* Verify the capabilities */
14760 	struct rte_cryptodev_sym_capability_idx cap_idx;
14761 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14762 	cap_idx.algo.auth = reference->auth_algo;
14763 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14764 			&cap_idx) == NULL)
14765 		return TEST_SKIPPED;
14766 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
14767 	cap_idx.algo.cipher = reference->crypto_algo;
14768 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14769 			&cap_idx) == NULL)
14770 		return TEST_SKIPPED;
14771 
14772 	/* Create session */
14773 	retval = create_auth_cipher_session(ut_params,
14774 			ts_params->valid_devs[0],
14775 			reference,
14776 			RTE_CRYPTO_AUTH_OP_VERIFY,
14777 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
14778 	if (retval == TEST_SKIPPED)
14779 		return TEST_SKIPPED;
14780 	if (retval < 0)
14781 		return retval;
14782 
14783 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14784 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
14785 			"Failed to allocate input buffer in mempool");
14786 
14787 	/* clear mbuf payload */
14788 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
14789 			rte_pktmbuf_tailroom(ut_params->ibuf));
14790 
14791 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
14792 			reference->ciphertext.len);
14793 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
14794 	memcpy(ciphertext, reference->ciphertext.data,
14795 			reference->ciphertext.len);
14796 
14797 	/* Create operation */
14798 	retval = create_cipher_auth_verify_operation(ts_params,
14799 			ut_params,
14800 			reference);
14801 
14802 	if (retval < 0)
14803 		return retval;
14804 
14805 	if (data_corrupted)
14806 		data_corruption(ciphertext);
14807 	else
14808 		tag_corruption(ciphertext, reference->ciphertext.len);
14809 
14810 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
14811 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
14812 			ut_params->op);
14813 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
14814 			RTE_CRYPTO_OP_STATUS_SUCCESS,
14815 			"authentication not failed");
14816 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
14817 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0,
14818 					       0);
14819 		if (retval != TEST_SUCCESS)
14820 			return retval;
14821 	} else {
14822 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
14823 			ut_params->op);
14824 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
14825 	}
14826 
14827 	return 0;
14828 }
14829 
14830 static int
14831 test_authenticated_encrypt_with_esn(
14832 		struct crypto_testsuite_params *ts_params,
14833 		struct crypto_unittest_params *ut_params,
14834 		const struct test_crypto_vector *reference)
14835 {
14836 	int retval;
14837 
14838 	uint8_t *authciphertext, *plaintext, *auth_tag;
14839 	uint16_t plaintext_pad_len;
14840 	uint8_t cipher_key[reference->cipher_key.len + 1];
14841 	uint8_t auth_key[reference->auth_key.len + 1];
14842 	struct rte_cryptodev_info dev_info;
14843 
14844 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
14845 	uint64_t feat_flags = dev_info.feature_flags;
14846 
14847 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
14848 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
14849 		printf("Device doesn't support RAW data-path APIs.\n");
14850 		return TEST_SKIPPED;
14851 	}
14852 
14853 	/* Verify the capabilities */
14854 	struct rte_cryptodev_sym_capability_idx cap_idx;
14855 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14856 	cap_idx.algo.auth = reference->auth_algo;
14857 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14858 			&cap_idx) == NULL)
14859 		return TEST_SKIPPED;
14860 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
14861 	cap_idx.algo.cipher = reference->crypto_algo;
14862 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14863 			&cap_idx) == NULL)
14864 		return TEST_SKIPPED;
14865 
14866 	/* Create session */
14867 	memcpy(cipher_key, reference->cipher_key.data,
14868 			reference->cipher_key.len);
14869 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
14870 
14871 	/* Setup Cipher Parameters */
14872 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
14873 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
14874 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
14875 	ut_params->cipher_xform.cipher.key.data = cipher_key;
14876 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
14877 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
14878 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
14879 
14880 	ut_params->cipher_xform.next = &ut_params->auth_xform;
14881 
14882 	/* Setup Authentication Parameters */
14883 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14884 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
14885 	ut_params->auth_xform.auth.algo = reference->auth_algo;
14886 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
14887 	ut_params->auth_xform.auth.key.data = auth_key;
14888 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
14889 	ut_params->auth_xform.next = NULL;
14890 
14891 	/* Create Crypto session*/
14892 	ut_params->sess = rte_cryptodev_sym_session_create(
14893 			ts_params->valid_devs[0], &ut_params->cipher_xform,
14894 			ts_params->session_mpool);
14895 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
14896 		return TEST_SKIPPED;
14897 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
14898 
14899 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14900 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
14901 			"Failed to allocate input buffer in mempool");
14902 
14903 	/* clear mbuf payload */
14904 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
14905 			rte_pktmbuf_tailroom(ut_params->ibuf));
14906 
14907 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
14908 			reference->plaintext.len);
14909 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
14910 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
14911 
14912 	/* Create operation */
14913 	retval = create_cipher_auth_operation(ts_params,
14914 			ut_params,
14915 			reference, 0);
14916 
14917 	if (retval < 0)
14918 		return retval;
14919 
14920 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
14921 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
14922 			ut_params->op);
14923 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
14924 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0,
14925 					       0);
14926 		if (retval != TEST_SUCCESS)
14927 			return retval;
14928 	} else
14929 		ut_params->op = process_crypto_request(
14930 			ts_params->valid_devs[0], ut_params->op);
14931 
14932 	TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
14933 
14934 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
14935 			"crypto op processing failed");
14936 
14937 	plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
14938 
14939 	authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
14940 			ut_params->op->sym->auth.data.offset);
14941 	auth_tag = authciphertext + plaintext_pad_len;
14942 	debug_hexdump(stdout, "ciphertext:", authciphertext,
14943 			reference->ciphertext.len);
14944 	debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
14945 
14946 	/* Validate obuf */
14947 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
14948 			authciphertext,
14949 			reference->ciphertext.data,
14950 			reference->ciphertext.len,
14951 			"Ciphertext data not as expected");
14952 
14953 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
14954 			auth_tag,
14955 			reference->digest.data,
14956 			reference->digest.len,
14957 			"Generated digest not as expected");
14958 
14959 	return TEST_SUCCESS;
14960 
14961 }
14962 
14963 static int
14964 test_authenticated_decrypt_with_esn(
14965 		struct crypto_testsuite_params *ts_params,
14966 		struct crypto_unittest_params *ut_params,
14967 		const struct test_crypto_vector *reference)
14968 {
14969 	int retval;
14970 
14971 	uint8_t *ciphertext;
14972 	uint8_t cipher_key[reference->cipher_key.len + 1];
14973 	uint8_t auth_key[reference->auth_key.len + 1];
14974 	struct rte_cryptodev_info dev_info;
14975 
14976 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
14977 	uint64_t feat_flags = dev_info.feature_flags;
14978 
14979 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
14980 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
14981 		printf("Device doesn't support RAW data-path APIs.\n");
14982 		return TEST_SKIPPED;
14983 	}
14984 
14985 	/* Verify the capabilities */
14986 	struct rte_cryptodev_sym_capability_idx cap_idx;
14987 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14988 	cap_idx.algo.auth = reference->auth_algo;
14989 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14990 			&cap_idx) == NULL)
14991 		return TEST_SKIPPED;
14992 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
14993 	cap_idx.algo.cipher = reference->crypto_algo;
14994 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14995 			&cap_idx) == NULL)
14996 		return TEST_SKIPPED;
14997 
14998 	/* Create session */
14999 	memcpy(cipher_key, reference->cipher_key.data,
15000 			reference->cipher_key.len);
15001 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
15002 
15003 	/* Setup Authentication Parameters */
15004 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
15005 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
15006 	ut_params->auth_xform.auth.algo = reference->auth_algo;
15007 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
15008 	ut_params->auth_xform.auth.key.data = auth_key;
15009 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
15010 	ut_params->auth_xform.next = &ut_params->cipher_xform;
15011 
15012 	/* Setup Cipher Parameters */
15013 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
15014 	ut_params->cipher_xform.next = NULL;
15015 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
15016 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
15017 	ut_params->cipher_xform.cipher.key.data = cipher_key;
15018 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
15019 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
15020 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
15021 
15022 	/* Create Crypto session*/
15023 	ut_params->sess = rte_cryptodev_sym_session_create(
15024 			ts_params->valid_devs[0], &ut_params->auth_xform,
15025 			ts_params->session_mpool);
15026 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
15027 		return TEST_SKIPPED;
15028 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
15029 
15030 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
15031 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
15032 			"Failed to allocate input buffer in mempool");
15033 
15034 	/* clear mbuf payload */
15035 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
15036 			rte_pktmbuf_tailroom(ut_params->ibuf));
15037 
15038 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
15039 			reference->ciphertext.len);
15040 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
15041 	memcpy(ciphertext, reference->ciphertext.data,
15042 			reference->ciphertext.len);
15043 
15044 	/* Create operation */
15045 	retval = create_cipher_auth_verify_operation(ts_params,
15046 			ut_params,
15047 			reference);
15048 
15049 	if (retval < 0)
15050 		return retval;
15051 
15052 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
15053 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
15054 			ut_params->op);
15055 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
15056 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0,
15057 					       0);
15058 		if (retval != TEST_SUCCESS)
15059 			return retval;
15060 	} else
15061 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
15062 			ut_params->op);
15063 
15064 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
15065 	TEST_ASSERT_EQUAL(ut_params->op->status,
15066 			RTE_CRYPTO_OP_STATUS_SUCCESS,
15067 			"crypto op processing passed");
15068 
15069 	ut_params->obuf = ut_params->op->sym->m_src;
15070 	TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
15071 
15072 	return 0;
15073 }
15074 
15075 static int
15076 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
15077 		const struct aead_test_data *tdata,
15078 		void *digest_mem, uint64_t digest_phys)
15079 {
15080 	struct crypto_testsuite_params *ts_params = &testsuite_params;
15081 	struct crypto_unittest_params *ut_params = &unittest_params;
15082 
15083 	const unsigned int auth_tag_len = tdata->auth_tag.len;
15084 	const unsigned int iv_len = tdata->iv.len;
15085 	unsigned int aad_len = tdata->aad.len;
15086 	unsigned int aad_len_pad = 0;
15087 
15088 	/* Generate Crypto op data structure */
15089 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
15090 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
15091 	TEST_ASSERT_NOT_NULL(ut_params->op,
15092 		"Failed to allocate symmetric crypto operation struct");
15093 
15094 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
15095 
15096 	sym_op->aead.digest.data = digest_mem;
15097 
15098 	TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
15099 			"no room to append digest");
15100 
15101 	sym_op->aead.digest.phys_addr = digest_phys;
15102 
15103 	if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
15104 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
15105 				auth_tag_len);
15106 		debug_hexdump(stdout, "digest:",
15107 				sym_op->aead.digest.data,
15108 				auth_tag_len);
15109 	}
15110 
15111 	/* Append aad data */
15112 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
15113 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
15114 				uint8_t *, IV_OFFSET);
15115 
15116 		/* Copy IV 1 byte after the IV pointer, according to the API */
15117 		rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
15118 
15119 		aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
15120 
15121 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
15122 				ut_params->ibuf, aad_len);
15123 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
15124 				"no room to prepend aad");
15125 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
15126 				ut_params->ibuf);
15127 
15128 		memset(sym_op->aead.aad.data, 0, aad_len);
15129 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
15130 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
15131 
15132 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
15133 		debug_hexdump(stdout, "aad:",
15134 				sym_op->aead.aad.data, aad_len);
15135 	} else {
15136 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
15137 				uint8_t *, IV_OFFSET);
15138 
15139 		rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
15140 
15141 		aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
15142 
15143 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
15144 				ut_params->ibuf, aad_len_pad);
15145 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
15146 				"no room to prepend aad");
15147 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
15148 				ut_params->ibuf);
15149 
15150 		memset(sym_op->aead.aad.data, 0, aad_len);
15151 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
15152 
15153 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
15154 		debug_hexdump(stdout, "aad:",
15155 				sym_op->aead.aad.data, aad_len);
15156 	}
15157 
15158 	sym_op->aead.data.length = tdata->plaintext.len;
15159 	sym_op->aead.data.offset = aad_len_pad;
15160 
15161 	return 0;
15162 }
15163 
15164 #define SGL_MAX_NO	16
15165 
15166 static int
15167 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
15168 		const int oop, uint32_t fragsz, uint32_t fragsz_oop)
15169 {
15170 	struct crypto_testsuite_params *ts_params = &testsuite_params;
15171 	struct crypto_unittest_params *ut_params = &unittest_params;
15172 	struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
15173 	int retval;
15174 	int to_trn = 0;
15175 	int to_trn_tbl[SGL_MAX_NO];
15176 	int segs = 1;
15177 	unsigned int trn_data = 0;
15178 	uint8_t *plaintext, *ciphertext, *auth_tag;
15179 	struct rte_cryptodev_info dev_info;
15180 
15181 	/* Verify the capabilities */
15182 	struct rte_cryptodev_sym_capability_idx cap_idx;
15183 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
15184 	cap_idx.algo.aead = tdata->algo;
15185 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
15186 			&cap_idx) == NULL)
15187 		return TEST_SKIPPED;
15188 
15189 	/*
15190 	 * SGL not supported on AESNI_MB PMD CPU crypto,
15191 	 * OOP not supported on AESNI_GCM CPU crypto
15192 	 */
15193 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO &&
15194 			(gbl_driver_id == rte_cryptodev_driver_id_get(
15195 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) || oop))
15196 		return TEST_SKIPPED;
15197 
15198 	/* Detailed check for the particular SGL support flag */
15199 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
15200 	if (!oop) {
15201 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
15202 		if (sgl_in && (!(dev_info.feature_flags &
15203 				RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
15204 			return TEST_SKIPPED;
15205 
15206 		uint64_t feat_flags = dev_info.feature_flags;
15207 
15208 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
15209 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
15210 			printf("Device doesn't support RAW data-path APIs.\n");
15211 			return TEST_SKIPPED;
15212 		}
15213 	} else {
15214 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
15215 		unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
15216 				tdata->plaintext.len;
15217 		/* Raw data path API does not support OOP */
15218 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
15219 			return TEST_SKIPPED;
15220 		if (sgl_in && !sgl_out) {
15221 			if (!(dev_info.feature_flags &
15222 					RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
15223 				return TEST_SKIPPED;
15224 		} else if (!sgl_in && sgl_out) {
15225 			if (!(dev_info.feature_flags &
15226 					RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
15227 				return TEST_SKIPPED;
15228 		} else if (sgl_in && sgl_out) {
15229 			if (!(dev_info.feature_flags &
15230 					RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
15231 				return TEST_SKIPPED;
15232 		}
15233 	}
15234 
15235 	if (fragsz > tdata->plaintext.len)
15236 		fragsz = tdata->plaintext.len;
15237 
15238 	uint16_t plaintext_len = fragsz;
15239 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
15240 
15241 	if (fragsz_oop > tdata->plaintext.len)
15242 		frag_size_oop = tdata->plaintext.len;
15243 
15244 	int ecx = 0;
15245 	void *digest_mem = NULL;
15246 
15247 	uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
15248 
15249 	if (tdata->plaintext.len % fragsz != 0) {
15250 		if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
15251 			return 1;
15252 	}	else {
15253 		if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
15254 			return 1;
15255 	}
15256 
15257 	/*
15258 	 * For out-op-place we need to alloc another mbuf
15259 	 */
15260 	if (oop) {
15261 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
15262 		rte_pktmbuf_append(ut_params->obuf,
15263 				frag_size_oop + prepend_len);
15264 		buf_oop = ut_params->obuf;
15265 	}
15266 
15267 	/* Create AEAD session */
15268 	retval = create_aead_session(ts_params->valid_devs[0],
15269 			tdata->algo,
15270 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
15271 			tdata->key.data, tdata->key.len,
15272 			tdata->aad.len, tdata->auth_tag.len,
15273 			tdata->iv.len);
15274 	if (retval < 0)
15275 		return retval;
15276 
15277 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
15278 
15279 	/* clear mbuf payload */
15280 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
15281 			rte_pktmbuf_tailroom(ut_params->ibuf));
15282 
15283 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
15284 			plaintext_len);
15285 
15286 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
15287 
15288 	trn_data += plaintext_len;
15289 
15290 	buf = ut_params->ibuf;
15291 
15292 	/*
15293 	 * Loop until no more fragments
15294 	 */
15295 
15296 	while (trn_data < tdata->plaintext.len) {
15297 		++segs;
15298 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
15299 				(tdata->plaintext.len - trn_data) : fragsz;
15300 
15301 		to_trn_tbl[ecx++] = to_trn;
15302 
15303 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
15304 		buf = buf->next;
15305 
15306 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
15307 				rte_pktmbuf_tailroom(buf));
15308 
15309 		/* OOP */
15310 		if (oop && !fragsz_oop) {
15311 			buf_last_oop = buf_oop->next =
15312 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
15313 			buf_oop = buf_oop->next;
15314 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
15315 					0, rte_pktmbuf_tailroom(buf_oop));
15316 			rte_pktmbuf_append(buf_oop, to_trn);
15317 		}
15318 
15319 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
15320 				to_trn);
15321 
15322 		memcpy(plaintext, tdata->plaintext.data + trn_data,
15323 				to_trn);
15324 		trn_data += to_trn;
15325 		if (trn_data  == tdata->plaintext.len) {
15326 			if (oop) {
15327 				if (!fragsz_oop)
15328 					digest_mem = rte_pktmbuf_append(buf_oop,
15329 						tdata->auth_tag.len);
15330 			} else
15331 				digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
15332 					tdata->auth_tag.len);
15333 		}
15334 	}
15335 
15336 	uint64_t digest_phys = 0;
15337 
15338 	ut_params->ibuf->nb_segs = segs;
15339 
15340 	segs = 1;
15341 	if (fragsz_oop && oop) {
15342 		to_trn = 0;
15343 		ecx = 0;
15344 
15345 		if (frag_size_oop == tdata->plaintext.len) {
15346 			digest_mem = rte_pktmbuf_append(ut_params->obuf,
15347 				tdata->auth_tag.len);
15348 
15349 			digest_phys = rte_pktmbuf_iova_offset(
15350 					ut_params->obuf,
15351 					tdata->plaintext.len + prepend_len);
15352 		}
15353 
15354 		trn_data = frag_size_oop;
15355 		while (trn_data < tdata->plaintext.len) {
15356 			++segs;
15357 			to_trn =
15358 				(tdata->plaintext.len - trn_data <
15359 						frag_size_oop) ?
15360 				(tdata->plaintext.len - trn_data) :
15361 						frag_size_oop;
15362 
15363 			to_trn_tbl[ecx++] = to_trn;
15364 
15365 			buf_last_oop = buf_oop->next =
15366 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
15367 			buf_oop = buf_oop->next;
15368 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
15369 					0, rte_pktmbuf_tailroom(buf_oop));
15370 			rte_pktmbuf_append(buf_oop, to_trn);
15371 
15372 			trn_data += to_trn;
15373 
15374 			if (trn_data  == tdata->plaintext.len) {
15375 				digest_mem = rte_pktmbuf_append(buf_oop,
15376 					tdata->auth_tag.len);
15377 			}
15378 		}
15379 
15380 		ut_params->obuf->nb_segs = segs;
15381 	}
15382 
15383 	/*
15384 	 * Place digest at the end of the last buffer
15385 	 */
15386 	if (!digest_phys)
15387 		digest_phys = rte_pktmbuf_iova(buf) + to_trn;
15388 	if (oop && buf_last_oop)
15389 		digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
15390 
15391 	if (!digest_mem && !oop) {
15392 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
15393 				+ tdata->auth_tag.len);
15394 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
15395 				tdata->plaintext.len);
15396 	}
15397 
15398 	/* Create AEAD operation */
15399 	retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
15400 			tdata, digest_mem, digest_phys);
15401 
15402 	if (retval < 0)
15403 		return retval;
15404 
15405 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
15406 
15407 	ut_params->op->sym->m_src = ut_params->ibuf;
15408 	if (oop)
15409 		ut_params->op->sym->m_dst = ut_params->obuf;
15410 
15411 	/* Process crypto operation */
15412 	if (oop == IN_PLACE &&
15413 			gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
15414 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
15415 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
15416 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0,
15417 					       0);
15418 		if (retval != TEST_SUCCESS)
15419 			return retval;
15420 	} else
15421 		TEST_ASSERT_NOT_NULL(
15422 			process_crypto_request(ts_params->valid_devs[0],
15423 			ut_params->op), "failed to process sym crypto op");
15424 
15425 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
15426 			"crypto op processing failed");
15427 
15428 
15429 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
15430 			uint8_t *, prepend_len);
15431 	if (oop) {
15432 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
15433 				uint8_t *, prepend_len);
15434 	}
15435 
15436 	if (fragsz_oop)
15437 		fragsz = fragsz_oop;
15438 
15439 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
15440 			ciphertext,
15441 			tdata->ciphertext.data,
15442 			fragsz,
15443 			"Ciphertext data not as expected");
15444 
15445 	buf = ut_params->op->sym->m_src->next;
15446 	if (oop)
15447 		buf = ut_params->op->sym->m_dst->next;
15448 
15449 	unsigned int off = fragsz;
15450 
15451 	ecx = 0;
15452 	while (buf) {
15453 		ciphertext = rte_pktmbuf_mtod(buf,
15454 				uint8_t *);
15455 
15456 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
15457 				ciphertext,
15458 				tdata->ciphertext.data + off,
15459 				to_trn_tbl[ecx],
15460 				"Ciphertext data not as expected");
15461 
15462 		off += to_trn_tbl[ecx++];
15463 		buf = buf->next;
15464 	}
15465 
15466 	auth_tag = digest_mem;
15467 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
15468 			auth_tag,
15469 			tdata->auth_tag.data,
15470 			tdata->auth_tag.len,
15471 			"Generated auth tag not as expected");
15472 
15473 	return 0;
15474 }
15475 
15476 static int
15477 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
15478 {
15479 	return test_authenticated_encryption_SGL(
15480 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
15481 }
15482 
15483 static int
15484 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
15485 {
15486 	return test_authenticated_encryption_SGL(
15487 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
15488 }
15489 
15490 static int
15491 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
15492 {
15493 	return test_authenticated_encryption_SGL(
15494 			&gcm_test_case_8, OUT_OF_PLACE, 400,
15495 			gcm_test_case_8.plaintext.len);
15496 }
15497 
15498 static int
15499 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
15500 {
15501 	/* This test is not for OPENSSL PMD */
15502 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
15503 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
15504 		return TEST_SKIPPED;
15505 
15506 	return test_authenticated_encryption_SGL(
15507 			&gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
15508 }
15509 
15510 static int
15511 test_authentication_verify_fail_when_data_corrupted(
15512 		struct crypto_testsuite_params *ts_params,
15513 		struct crypto_unittest_params *ut_params,
15514 		const struct test_crypto_vector *reference)
15515 {
15516 	return test_authentication_verify_fail_when_data_corruption(
15517 			ts_params, ut_params, reference, 1);
15518 }
15519 
15520 static int
15521 test_authentication_verify_fail_when_tag_corrupted(
15522 		struct crypto_testsuite_params *ts_params,
15523 		struct crypto_unittest_params *ut_params,
15524 		const struct test_crypto_vector *reference)
15525 {
15526 	return test_authentication_verify_fail_when_data_corruption(
15527 			ts_params, ut_params, reference, 0);
15528 }
15529 
15530 static int
15531 test_authentication_verify_GMAC_fail_when_data_corrupted(
15532 		struct crypto_testsuite_params *ts_params,
15533 		struct crypto_unittest_params *ut_params,
15534 		const struct test_crypto_vector *reference)
15535 {
15536 	return test_authentication_verify_GMAC_fail_when_corruption(
15537 			ts_params, ut_params, reference, 1);
15538 }
15539 
15540 static int
15541 test_authentication_verify_GMAC_fail_when_tag_corrupted(
15542 		struct crypto_testsuite_params *ts_params,
15543 		struct crypto_unittest_params *ut_params,
15544 		const struct test_crypto_vector *reference)
15545 {
15546 	return test_authentication_verify_GMAC_fail_when_corruption(
15547 			ts_params, ut_params, reference, 0);
15548 }
15549 
15550 static int
15551 test_authenticated_decryption_fail_when_data_corrupted(
15552 		struct crypto_testsuite_params *ts_params,
15553 		struct crypto_unittest_params *ut_params,
15554 		const struct test_crypto_vector *reference)
15555 {
15556 	return test_authenticated_decryption_fail_when_corruption(
15557 			ts_params, ut_params, reference, 1);
15558 }
15559 
15560 static int
15561 test_authenticated_decryption_fail_when_tag_corrupted(
15562 		struct crypto_testsuite_params *ts_params,
15563 		struct crypto_unittest_params *ut_params,
15564 		const struct test_crypto_vector *reference)
15565 {
15566 	return test_authenticated_decryption_fail_when_corruption(
15567 			ts_params, ut_params, reference, 0);
15568 }
15569 
15570 static int
15571 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
15572 {
15573 	return test_authentication_verify_fail_when_data_corrupted(
15574 			&testsuite_params, &unittest_params,
15575 			&hmac_sha1_test_crypto_vector);
15576 }
15577 
15578 static int
15579 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
15580 {
15581 	return test_authentication_verify_fail_when_tag_corrupted(
15582 			&testsuite_params, &unittest_params,
15583 			&hmac_sha1_test_crypto_vector);
15584 }
15585 
15586 static int
15587 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
15588 {
15589 	return test_authentication_verify_GMAC_fail_when_data_corrupted(
15590 			&testsuite_params, &unittest_params,
15591 			&aes128_gmac_test_vector);
15592 }
15593 
15594 static int
15595 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
15596 {
15597 	return test_authentication_verify_GMAC_fail_when_tag_corrupted(
15598 			&testsuite_params, &unittest_params,
15599 			&aes128_gmac_test_vector);
15600 }
15601 
15602 static int
15603 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
15604 {
15605 	return test_authenticated_decryption_fail_when_data_corrupted(
15606 			&testsuite_params,
15607 			&unittest_params,
15608 			&aes128cbc_hmac_sha1_test_vector);
15609 }
15610 
15611 static int
15612 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
15613 {
15614 	return test_authenticated_decryption_fail_when_tag_corrupted(
15615 			&testsuite_params,
15616 			&unittest_params,
15617 			&aes128cbc_hmac_sha1_test_vector);
15618 }
15619 
15620 static int
15621 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
15622 {
15623 	return test_authenticated_encrypt_with_esn(
15624 			&testsuite_params,
15625 			&unittest_params,
15626 			&aes128cbc_hmac_sha1_aad_test_vector);
15627 }
15628 
15629 static int
15630 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
15631 {
15632 	return test_authenticated_decrypt_with_esn(
15633 			&testsuite_params,
15634 			&unittest_params,
15635 			&aes128cbc_hmac_sha1_aad_test_vector);
15636 }
15637 
15638 static int
15639 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
15640 {
15641 	return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
15642 }
15643 
15644 static int
15645 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
15646 {
15647 	return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
15648 }
15649 
15650 static int
15651 test_chacha20_poly1305_encrypt_SGL_out_of_place(void)
15652 {
15653 	return test_authenticated_encryption_SGL(
15654 		&chacha20_poly1305_case_2, OUT_OF_PLACE, 32,
15655 		chacha20_poly1305_case_2.plaintext.len);
15656 }
15657 
15658 #ifdef RTE_CRYPTO_SCHEDULER
15659 
15660 /* global AESNI worker IDs for the scheduler test */
15661 uint8_t aesni_ids[2];
15662 
15663 static int
15664 scheduler_testsuite_setup(void)
15665 {
15666 	uint32_t i = 0;
15667 	int32_t nb_devs, ret;
15668 	char vdev_args[VDEV_ARGS_SIZE] = {""};
15669 	char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
15670 		"ordering=enable,name=cryptodev_test_scheduler,corelist="};
15671 	uint16_t worker_core_count = 0;
15672 	uint16_t socket_id = 0;
15673 
15674 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
15675 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
15676 
15677 		/* Identify the Worker Cores
15678 		 * Use 2 worker cores for the device args
15679 		 */
15680 		RTE_LCORE_FOREACH_WORKER(i) {
15681 			if (worker_core_count > 1)
15682 				break;
15683 			snprintf(vdev_args, sizeof(vdev_args),
15684 					"%s%d", temp_str, i);
15685 			strcpy(temp_str, vdev_args);
15686 			strlcat(temp_str, ";", sizeof(temp_str));
15687 			worker_core_count++;
15688 			socket_id = rte_lcore_to_socket_id(i);
15689 		}
15690 		if (worker_core_count != 2) {
15691 			RTE_LOG(ERR, USER1,
15692 				"Cryptodev scheduler test require at least "
15693 				"two worker cores to run. "
15694 				"Please use the correct coremask.\n");
15695 			return TEST_FAILED;
15696 		}
15697 		strcpy(temp_str, vdev_args);
15698 		snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
15699 				temp_str, socket_id);
15700 		RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
15701 		nb_devs = rte_cryptodev_device_count_by_driver(
15702 				rte_cryptodev_driver_id_get(
15703 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
15704 		if (nb_devs < 1) {
15705 			ret = rte_vdev_init(
15706 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
15707 					vdev_args);
15708 			TEST_ASSERT(ret == 0,
15709 				"Failed to create instance %u of pmd : %s",
15710 				i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
15711 		}
15712 	}
15713 	return testsuite_setup();
15714 }
15715 
15716 static int
15717 test_scheduler_attach_worker_op(void)
15718 {
15719 	struct crypto_testsuite_params *ts_params = &testsuite_params;
15720 	uint8_t sched_id = ts_params->valid_devs[0];
15721 	uint32_t i, nb_devs_attached = 0;
15722 	int ret;
15723 	char vdev_name[32];
15724 	unsigned int count = rte_cryptodev_count();
15725 
15726 	/* create 2 AESNI_MB vdevs on top of existing devices */
15727 	for (i = count; i < count + 2; i++) {
15728 		snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
15729 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
15730 				i);
15731 		ret = rte_vdev_init(vdev_name, NULL);
15732 
15733 		TEST_ASSERT(ret == 0,
15734 			"Failed to create instance %u of"
15735 			" pmd : %s",
15736 			i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
15737 
15738 		if (ret < 0) {
15739 			RTE_LOG(ERR, USER1,
15740 				"Failed to create 2 AESNI MB PMDs.\n");
15741 			return TEST_SKIPPED;
15742 		}
15743 	}
15744 
15745 	/* attach 2 AESNI_MB cdevs */
15746 	for (i = count; i < count + 2; i++) {
15747 		struct rte_cryptodev_info info;
15748 		unsigned int session_size;
15749 
15750 		rte_cryptodev_info_get(i, &info);
15751 		if (info.driver_id != rte_cryptodev_driver_id_get(
15752 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
15753 			continue;
15754 
15755 		session_size = rte_cryptodev_sym_get_private_session_size(i);
15756 		/*
15757 		 * Create the session mempool again, since now there are new devices
15758 		 * to use the mempool.
15759 		 */
15760 		if (ts_params->session_mpool) {
15761 			rte_mempool_free(ts_params->session_mpool);
15762 			ts_params->session_mpool = NULL;
15763 		}
15764 
15765 		if (info.sym.max_nb_sessions != 0 &&
15766 				info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
15767 			RTE_LOG(ERR, USER1,
15768 					"Device does not support "
15769 					"at least %u sessions\n",
15770 					MAX_NB_SESSIONS);
15771 			return TEST_FAILED;
15772 		}
15773 		/*
15774 		 * Create mempool with maximum number of sessions,
15775 		 * to include the session headers
15776 		 */
15777 		if (ts_params->session_mpool == NULL) {
15778 			ts_params->session_mpool =
15779 				rte_cryptodev_sym_session_pool_create(
15780 						"test_sess_mp",
15781 						MAX_NB_SESSIONS, session_size,
15782 						0, 0, SOCKET_ID_ANY);
15783 			TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
15784 					"session mempool allocation failed");
15785 		}
15786 
15787 		ts_params->qp_conf.mp_session = ts_params->session_mpool;
15788 
15789 		ret = rte_cryptodev_scheduler_worker_attach(sched_id,
15790 				(uint8_t)i);
15791 
15792 		TEST_ASSERT(ret == 0,
15793 			"Failed to attach device %u of pmd : %s", i,
15794 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
15795 
15796 		aesni_ids[nb_devs_attached] = (uint8_t)i;
15797 
15798 		nb_devs_attached++;
15799 	}
15800 
15801 	return 0;
15802 }
15803 
15804 static int
15805 test_scheduler_detach_worker_op(void)
15806 {
15807 	struct crypto_testsuite_params *ts_params = &testsuite_params;
15808 	uint8_t sched_id = ts_params->valid_devs[0];
15809 	uint32_t i;
15810 	int ret;
15811 
15812 	for (i = 0; i < 2; i++) {
15813 		ret = rte_cryptodev_scheduler_worker_detach(sched_id,
15814 				aesni_ids[i]);
15815 		TEST_ASSERT(ret == 0,
15816 			"Failed to detach device %u", aesni_ids[i]);
15817 	}
15818 
15819 	return 0;
15820 }
15821 
15822 static int
15823 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
15824 {
15825 	struct crypto_testsuite_params *ts_params = &testsuite_params;
15826 	uint8_t sched_id = ts_params->valid_devs[0];
15827 	/* set mode */
15828 	return rte_cryptodev_scheduler_mode_set(sched_id,
15829 		scheduler_mode);
15830 }
15831 
15832 static int
15833 test_scheduler_mode_roundrobin_op(void)
15834 {
15835 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
15836 			0, "Failed to set roundrobin mode");
15837 	return 0;
15838 
15839 }
15840 
15841 static int
15842 test_scheduler_mode_multicore_op(void)
15843 {
15844 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
15845 			0, "Failed to set multicore mode");
15846 
15847 	return 0;
15848 }
15849 
15850 static int
15851 test_scheduler_mode_failover_op(void)
15852 {
15853 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
15854 			0, "Failed to set failover mode");
15855 
15856 	return 0;
15857 }
15858 
15859 static int
15860 test_scheduler_mode_pkt_size_distr_op(void)
15861 {
15862 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
15863 			0, "Failed to set pktsize mode");
15864 
15865 	return 0;
15866 }
15867 
15868 static int
15869 scheduler_multicore_testsuite_setup(void)
15870 {
15871 	if (test_scheduler_attach_worker_op() < 0)
15872 		return TEST_SKIPPED;
15873 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0)
15874 		return TEST_SKIPPED;
15875 	return 0;
15876 }
15877 
15878 static int
15879 scheduler_roundrobin_testsuite_setup(void)
15880 {
15881 	if (test_scheduler_attach_worker_op() < 0)
15882 		return TEST_SKIPPED;
15883 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0)
15884 		return TEST_SKIPPED;
15885 	return 0;
15886 }
15887 
15888 static int
15889 scheduler_failover_testsuite_setup(void)
15890 {
15891 	if (test_scheduler_attach_worker_op() < 0)
15892 		return TEST_SKIPPED;
15893 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0)
15894 		return TEST_SKIPPED;
15895 	return 0;
15896 }
15897 
15898 static int
15899 scheduler_pkt_size_distr_testsuite_setup(void)
15900 {
15901 	if (test_scheduler_attach_worker_op() < 0)
15902 		return TEST_SKIPPED;
15903 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0)
15904 		return TEST_SKIPPED;
15905 	return 0;
15906 }
15907 
15908 static void
15909 scheduler_mode_testsuite_teardown(void)
15910 {
15911 	test_scheduler_detach_worker_op();
15912 }
15913 
15914 #endif /* RTE_CRYPTO_SCHEDULER */
15915 
15916 static struct unit_test_suite end_testsuite = {
15917 	.suite_name = NULL,
15918 	.setup = NULL,
15919 	.teardown = NULL,
15920 	.unit_test_suites = NULL
15921 };
15922 
15923 #ifdef RTE_LIB_SECURITY
15924 static struct unit_test_suite ipsec_proto_testsuite  = {
15925 	.suite_name = "IPsec Proto Unit Test Suite",
15926 	.setup = ipsec_proto_testsuite_setup,
15927 	.unit_test_cases = {
15928 		TEST_CASE_NAMED_WITH_DATA(
15929 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
15930 			ut_setup_security, ut_teardown,
15931 			test_ipsec_proto_known_vec, &pkt_aes_128_gcm),
15932 		TEST_CASE_NAMED_WITH_DATA(
15933 			"Outbound known vector ext_mbuf mode (ESP tunnel mode IPv4 AES-GCM 128)",
15934 			ut_setup_security, ut_teardown,
15935 			test_ipsec_proto_known_vec_ext_mbuf, &pkt_aes_128_gcm),
15936 		TEST_CASE_NAMED_WITH_DATA(
15937 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
15938 			ut_setup_security, ut_teardown,
15939 			test_ipsec_proto_known_vec, &pkt_aes_192_gcm),
15940 		TEST_CASE_NAMED_WITH_DATA(
15941 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
15942 			ut_setup_security, ut_teardown,
15943 			test_ipsec_proto_known_vec, &pkt_aes_256_gcm),
15944 		TEST_CASE_NAMED_WITH_DATA(
15945 			"Outbound known vector (ESP tunnel mode IPv4 AES-CCM 256)",
15946 			ut_setup_security, ut_teardown,
15947 			test_ipsec_proto_known_vec, &pkt_aes_256_ccm),
15948 		TEST_CASE_NAMED_WITH_DATA(
15949 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC MD5 [12B ICV])",
15950 			ut_setup_security, ut_teardown,
15951 			test_ipsec_proto_known_vec,
15952 			&pkt_aes_128_cbc_md5),
15953 		TEST_CASE_NAMED_WITH_DATA(
15954 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])",
15955 			ut_setup_security, ut_teardown,
15956 			test_ipsec_proto_known_vec,
15957 			&pkt_aes_128_cbc_hmac_sha256),
15958 		TEST_CASE_NAMED_WITH_DATA(
15959 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])",
15960 			ut_setup_security, ut_teardown,
15961 			test_ipsec_proto_known_vec,
15962 			&pkt_aes_128_cbc_hmac_sha384),
15963 		TEST_CASE_NAMED_WITH_DATA(
15964 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])",
15965 			ut_setup_security, ut_teardown,
15966 			test_ipsec_proto_known_vec,
15967 			&pkt_aes_128_cbc_hmac_sha512),
15968 		TEST_CASE_NAMED_WITH_DATA(
15969 			"Outbound known vector (ESP tunnel mode IPv6 AES-GCM 128)",
15970 			ut_setup_security, ut_teardown,
15971 			test_ipsec_proto_known_vec, &pkt_aes_256_gcm_v6),
15972 		TEST_CASE_NAMED_WITH_DATA(
15973 			"Outbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])",
15974 			ut_setup_security, ut_teardown,
15975 			test_ipsec_proto_known_vec,
15976 			&pkt_aes_128_cbc_hmac_sha256_v6),
15977 		TEST_CASE_NAMED_WITH_DATA(
15978 			"Outbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])",
15979 			ut_setup_security, ut_teardown,
15980 			test_ipsec_proto_known_vec,
15981 			&pkt_null_aes_xcbc),
15982 		TEST_CASE_NAMED_WITH_DATA(
15983 			"Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA256 [16B ICV])",
15984 			ut_setup_security, ut_teardown,
15985 			test_ipsec_proto_known_vec,
15986 			&pkt_des_cbc_hmac_sha256),
15987 		TEST_CASE_NAMED_WITH_DATA(
15988 			"Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA384 [24B ICV])",
15989 			ut_setup_security, ut_teardown,
15990 			test_ipsec_proto_known_vec,
15991 			&pkt_des_cbc_hmac_sha384),
15992 		TEST_CASE_NAMED_WITH_DATA(
15993 			"Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA512 [32B ICV])",
15994 			ut_setup_security, ut_teardown,
15995 			test_ipsec_proto_known_vec,
15996 			&pkt_des_cbc_hmac_sha512),
15997 		TEST_CASE_NAMED_WITH_DATA(
15998 			"Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA256 [16B ICV])",
15999 			ut_setup_security, ut_teardown,
16000 			test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha256),
16001 		TEST_CASE_NAMED_WITH_DATA(
16002 			"Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA384 [24B ICV])",
16003 			ut_setup_security, ut_teardown,
16004 			test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha384),
16005 		TEST_CASE_NAMED_WITH_DATA(
16006 			"Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA512 [32B ICV])",
16007 			ut_setup_security, ut_teardown,
16008 			test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha512),
16009 		TEST_CASE_NAMED_WITH_DATA(
16010 			"Outbound known vector (ESP tunnel mode IPv6 DES-CBC HMAC-SHA256 [16B ICV])",
16011 			ut_setup_security, ut_teardown,
16012 			test_ipsec_proto_known_vec,
16013 			&pkt_des_cbc_hmac_sha256_v6),
16014 		TEST_CASE_NAMED_WITH_DATA(
16015 			"Outbound known vector (ESP tunnel mode IPv6 3DES-CBC HMAC-SHA256 [16B ICV])",
16016 			ut_setup_security, ut_teardown,
16017 			test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha256_v6),
16018 		TEST_CASE_NAMED_WITH_DATA(
16019 			"Outbound known vector (AH tunnel mode IPv4 HMAC-SHA256)",
16020 			ut_setup_security, ut_teardown,
16021 			test_ipsec_proto_known_vec,
16022 			&pkt_ah_tunnel_sha256),
16023 		TEST_CASE_NAMED_WITH_DATA(
16024 			"Outbound known vector (AH transport mode IPv4 HMAC-SHA256)",
16025 			ut_setup_security, ut_teardown,
16026 			test_ipsec_proto_known_vec,
16027 			&pkt_ah_transport_sha256),
16028 		TEST_CASE_NAMED_WITH_DATA(
16029 			"Outbound known vector (AH transport mode IPv4 AES-GMAC 128)",
16030 			ut_setup_security, ut_teardown,
16031 			test_ipsec_proto_known_vec,
16032 			&pkt_ah_ipv4_aes_gmac_128),
16033 		TEST_CASE_NAMED_WITH_DATA(
16034 			"Outbound fragmented packet",
16035 			ut_setup_security, ut_teardown,
16036 			test_ipsec_proto_known_vec_fragmented,
16037 			&pkt_aes_128_gcm_frag),
16038 		TEST_CASE_NAMED_WITH_DATA(
16039 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
16040 			ut_setup_security, ut_teardown,
16041 			test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm),
16042 		TEST_CASE_NAMED_WITH_DATA(
16043 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
16044 			ut_setup_security, ut_teardown,
16045 			test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm),
16046 		TEST_CASE_NAMED_WITH_DATA(
16047 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
16048 			ut_setup_security, ut_teardown,
16049 			test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm),
16050 		TEST_CASE_NAMED_WITH_DATA(
16051 			"Inbound known vector (ESP tunnel mode IPv4 AES-CCM 256)",
16052 			ut_setup_security, ut_teardown,
16053 			test_ipsec_proto_known_vec_inb, &pkt_aes_256_ccm),
16054 		TEST_CASE_NAMED_WITH_DATA(
16055 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128)",
16056 			ut_setup_security, ut_teardown,
16057 			test_ipsec_proto_known_vec_inb, &pkt_aes_128_cbc_null),
16058 		TEST_CASE_NAMED_WITH_DATA(
16059 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC MD5 [12B ICV])",
16060 			ut_setup_security, ut_teardown,
16061 			test_ipsec_proto_known_vec_inb,
16062 			&pkt_aes_128_cbc_md5),
16063 		TEST_CASE_NAMED_WITH_DATA(
16064 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])",
16065 			ut_setup_security, ut_teardown,
16066 			test_ipsec_proto_known_vec_inb,
16067 			&pkt_aes_128_cbc_hmac_sha256),
16068 		TEST_CASE_NAMED_WITH_DATA(
16069 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])",
16070 			ut_setup_security, ut_teardown,
16071 			test_ipsec_proto_known_vec_inb,
16072 			&pkt_aes_128_cbc_hmac_sha384),
16073 		TEST_CASE_NAMED_WITH_DATA(
16074 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])",
16075 			ut_setup_security, ut_teardown,
16076 			test_ipsec_proto_known_vec_inb,
16077 			&pkt_aes_128_cbc_hmac_sha512),
16078 		TEST_CASE_NAMED_WITH_DATA(
16079 			"Inbound known vector (ESP tunnel mode IPv6 AES-GCM 128)",
16080 			ut_setup_security, ut_teardown,
16081 			test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm_v6),
16082 		TEST_CASE_NAMED_WITH_DATA(
16083 			"Inbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])",
16084 			ut_setup_security, ut_teardown,
16085 			test_ipsec_proto_known_vec_inb,
16086 			&pkt_aes_128_cbc_hmac_sha256_v6),
16087 		TEST_CASE_NAMED_WITH_DATA(
16088 			"Inbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])",
16089 			ut_setup_security, ut_teardown,
16090 			test_ipsec_proto_known_vec_inb,
16091 			&pkt_null_aes_xcbc),
16092 		TEST_CASE_NAMED_WITH_DATA(
16093 			"Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA256 [16B ICV])",
16094 			ut_setup_security, ut_teardown,
16095 			test_ipsec_proto_known_vec_inb,
16096 			&pkt_des_cbc_hmac_sha256),
16097 		TEST_CASE_NAMED_WITH_DATA(
16098 			"Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA384 [24B ICV])",
16099 			ut_setup_security, ut_teardown,
16100 			test_ipsec_proto_known_vec_inb,
16101 			&pkt_des_cbc_hmac_sha384),
16102 		TEST_CASE_NAMED_WITH_DATA(
16103 			"Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA512 [32B ICV])",
16104 			ut_setup_security, ut_teardown,
16105 			test_ipsec_proto_known_vec_inb,
16106 			&pkt_des_cbc_hmac_sha512),
16107 		TEST_CASE_NAMED_WITH_DATA(
16108 			"Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA256 [16B ICV])",
16109 			ut_setup_security, ut_teardown,
16110 			test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha256),
16111 		TEST_CASE_NAMED_WITH_DATA(
16112 			"Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA384 [24B ICV])",
16113 			ut_setup_security, ut_teardown,
16114 			test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha384),
16115 		TEST_CASE_NAMED_WITH_DATA(
16116 			"Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA512 [32B ICV])",
16117 			ut_setup_security, ut_teardown,
16118 			test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha512),
16119 		TEST_CASE_NAMED_WITH_DATA(
16120 			"Inbound known vector (ESP tunnel mode IPv6 DES-CBC HMAC-SHA256 [16B ICV])",
16121 			ut_setup_security, ut_teardown,
16122 			test_ipsec_proto_known_vec_inb,
16123 			&pkt_des_cbc_hmac_sha256_v6),
16124 		TEST_CASE_NAMED_WITH_DATA(
16125 			"Inbound known vector (ESP tunnel mode IPv6 3DES-CBC HMAC-SHA256 [16B ICV])",
16126 			ut_setup_security, ut_teardown,
16127 			test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha256_v6),
16128 		TEST_CASE_NAMED_WITH_DATA(
16129 			"Inbound known vector (AH tunnel mode IPv4 HMAC-SHA256)",
16130 			ut_setup_security, ut_teardown,
16131 			test_ipsec_proto_known_vec_inb,
16132 			&pkt_ah_tunnel_sha256),
16133 		TEST_CASE_NAMED_WITH_DATA(
16134 			"Inbound known vector (AH transport mode IPv4 HMAC-SHA256)",
16135 			ut_setup_security, ut_teardown,
16136 			test_ipsec_proto_known_vec_inb,
16137 			&pkt_ah_transport_sha256),
16138 		TEST_CASE_NAMED_WITH_DATA(
16139 			"Inbound known vector (AH transport mode IPv4 AES-GMAC 128)",
16140 			ut_setup_security, ut_teardown,
16141 			test_ipsec_proto_known_vec_inb,
16142 			&pkt_ah_ipv4_aes_gmac_128),
16143 		TEST_CASE_NAMED_ST(
16144 			"Combined test alg list",
16145 			ut_setup_security, ut_teardown,
16146 			test_ipsec_proto_display_list),
16147 		TEST_CASE_NAMED_ST(
16148 			"Combined test alg list (AH)",
16149 			ut_setup_security, ut_teardown,
16150 			test_ipsec_proto_ah_tunnel_ipv4),
16151 		TEST_CASE_NAMED_ST(
16152 			"IV generation",
16153 			ut_setup_security, ut_teardown,
16154 			test_ipsec_proto_iv_gen),
16155 		TEST_CASE_NAMED_ST(
16156 			"UDP encapsulation",
16157 			ut_setup_security, ut_teardown,
16158 			test_ipsec_proto_udp_encap),
16159 		TEST_CASE_NAMED_ST(
16160 			"UDP encapsulation with custom ports",
16161 			ut_setup_security, ut_teardown,
16162 			test_ipsec_proto_udp_encap_custom_ports),
16163 		TEST_CASE_NAMED_ST(
16164 			"UDP encapsulation ports verification test",
16165 			ut_setup_security, ut_teardown,
16166 			test_ipsec_proto_udp_ports_verify),
16167 		TEST_CASE_NAMED_ST(
16168 			"SA expiry packets soft",
16169 			ut_setup_security, ut_teardown,
16170 			test_ipsec_proto_sa_exp_pkts_soft),
16171 		TEST_CASE_NAMED_ST(
16172 			"SA expiry packets hard",
16173 			ut_setup_security, ut_teardown,
16174 			test_ipsec_proto_sa_exp_pkts_hard),
16175 		TEST_CASE_NAMED_ST(
16176 			"Negative test: ICV corruption",
16177 			ut_setup_security, ut_teardown,
16178 			test_ipsec_proto_err_icv_corrupt),
16179 		TEST_CASE_NAMED_ST(
16180 			"Tunnel dst addr verification",
16181 			ut_setup_security, ut_teardown,
16182 			test_ipsec_proto_tunnel_dst_addr_verify),
16183 		TEST_CASE_NAMED_ST(
16184 			"Tunnel src and dst addr verification",
16185 			ut_setup_security, ut_teardown,
16186 			test_ipsec_proto_tunnel_src_dst_addr_verify),
16187 		TEST_CASE_NAMED_ST(
16188 			"Inner IP checksum",
16189 			ut_setup_security, ut_teardown,
16190 			test_ipsec_proto_inner_ip_csum),
16191 		TEST_CASE_NAMED_ST(
16192 			"Inner L4 checksum",
16193 			ut_setup_security, ut_teardown,
16194 			test_ipsec_proto_inner_l4_csum),
16195 		TEST_CASE_NAMED_ST(
16196 			"Tunnel IPv4 in IPv4",
16197 			ut_setup_security, ut_teardown,
16198 			test_ipsec_proto_tunnel_v4_in_v4),
16199 		TEST_CASE_NAMED_ST(
16200 			"Tunnel IPv6 in IPv6",
16201 			ut_setup_security, ut_teardown,
16202 			test_ipsec_proto_tunnel_v6_in_v6),
16203 		TEST_CASE_NAMED_ST(
16204 			"Tunnel IPv4 in IPv6",
16205 			ut_setup_security, ut_teardown,
16206 			test_ipsec_proto_tunnel_v4_in_v6),
16207 		TEST_CASE_NAMED_ST(
16208 			"Tunnel IPv6 in IPv4",
16209 			ut_setup_security, ut_teardown,
16210 			test_ipsec_proto_tunnel_v6_in_v4),
16211 		TEST_CASE_NAMED_ST(
16212 			"Transport IPv4",
16213 			ut_setup_security, ut_teardown,
16214 			test_ipsec_proto_transport_v4),
16215 		TEST_CASE_NAMED_ST(
16216 			"AH transport IPv4",
16217 			ut_setup_security, ut_teardown,
16218 			test_ipsec_proto_ah_transport_ipv4),
16219 		TEST_CASE_NAMED_ST(
16220 			"Transport l4 checksum",
16221 			ut_setup_security, ut_teardown,
16222 			test_ipsec_proto_transport_l4_csum),
16223 		TEST_CASE_NAMED_ST(
16224 			"Statistics: success",
16225 			ut_setup_security, ut_teardown,
16226 			test_ipsec_proto_stats),
16227 		TEST_CASE_NAMED_ST(
16228 			"Fragmented packet",
16229 			ut_setup_security, ut_teardown,
16230 			test_ipsec_proto_pkt_fragment),
16231 		TEST_CASE_NAMED_ST(
16232 			"Tunnel header copy DF (inner 0)",
16233 			ut_setup_security, ut_teardown,
16234 			test_ipsec_proto_copy_df_inner_0),
16235 		TEST_CASE_NAMED_ST(
16236 			"Tunnel header copy DF (inner 1)",
16237 			ut_setup_security, ut_teardown,
16238 			test_ipsec_proto_copy_df_inner_1),
16239 		TEST_CASE_NAMED_ST(
16240 			"Tunnel header set DF 0 (inner 1)",
16241 			ut_setup_security, ut_teardown,
16242 			test_ipsec_proto_set_df_0_inner_1),
16243 		TEST_CASE_NAMED_ST(
16244 			"Tunnel header set DF 1 (inner 0)",
16245 			ut_setup_security, ut_teardown,
16246 			test_ipsec_proto_set_df_1_inner_0),
16247 		TEST_CASE_NAMED_ST(
16248 			"Tunnel header IPv4 copy DSCP (inner 0)",
16249 			ut_setup_security, ut_teardown,
16250 			test_ipsec_proto_ipv4_copy_dscp_inner_0),
16251 		TEST_CASE_NAMED_ST(
16252 			"Tunnel header IPv4 copy DSCP (inner 1)",
16253 			ut_setup_security, ut_teardown,
16254 			test_ipsec_proto_ipv4_copy_dscp_inner_1),
16255 		TEST_CASE_NAMED_ST(
16256 			"Tunnel header IPv4 set DSCP 0 (inner 1)",
16257 			ut_setup_security, ut_teardown,
16258 			test_ipsec_proto_ipv4_set_dscp_0_inner_1),
16259 		TEST_CASE_NAMED_ST(
16260 			"Tunnel header IPv4 set DSCP 1 (inner 0)",
16261 			ut_setup_security, ut_teardown,
16262 			test_ipsec_proto_ipv4_set_dscp_1_inner_0),
16263 		TEST_CASE_NAMED_ST(
16264 			"Tunnel header IPv6 copy DSCP (inner 0)",
16265 			ut_setup_security, ut_teardown,
16266 			test_ipsec_proto_ipv6_copy_dscp_inner_0),
16267 		TEST_CASE_NAMED_ST(
16268 			"Tunnel header IPv6 copy DSCP (inner 1)",
16269 			ut_setup_security, ut_teardown,
16270 			test_ipsec_proto_ipv6_copy_dscp_inner_1),
16271 		TEST_CASE_NAMED_ST(
16272 			"Tunnel header IPv6 set DSCP 0 (inner 1)",
16273 			ut_setup_security, ut_teardown,
16274 			test_ipsec_proto_ipv6_set_dscp_0_inner_1),
16275 		TEST_CASE_NAMED_ST(
16276 			"Tunnel header IPv6 set DSCP 1 (inner 0)",
16277 			ut_setup_security, ut_teardown,
16278 			test_ipsec_proto_ipv6_set_dscp_1_inner_0),
16279 		TEST_CASE_NAMED_WITH_DATA(
16280 			"Antireplay with window size 1024",
16281 			ut_setup_security, ut_teardown,
16282 			test_ipsec_proto_pkt_antireplay1024, &pkt_aes_128_gcm),
16283 		TEST_CASE_NAMED_WITH_DATA(
16284 			"Antireplay with window size 2048",
16285 			ut_setup_security, ut_teardown,
16286 			test_ipsec_proto_pkt_antireplay2048, &pkt_aes_128_gcm),
16287 		TEST_CASE_NAMED_WITH_DATA(
16288 			"Antireplay with window size 4096",
16289 			ut_setup_security, ut_teardown,
16290 			test_ipsec_proto_pkt_antireplay4096, &pkt_aes_128_gcm),
16291 		TEST_CASE_NAMED_WITH_DATA(
16292 			"ESN and Antireplay with window size 1024",
16293 			ut_setup_security, ut_teardown,
16294 			test_ipsec_proto_pkt_esn_antireplay1024,
16295 			&pkt_aes_128_gcm),
16296 		TEST_CASE_NAMED_WITH_DATA(
16297 			"ESN and Antireplay with window size 2048",
16298 			ut_setup_security, ut_teardown,
16299 			test_ipsec_proto_pkt_esn_antireplay2048,
16300 			&pkt_aes_128_gcm),
16301 		TEST_CASE_NAMED_WITH_DATA(
16302 			"ESN and Antireplay with window size 4096",
16303 			ut_setup_security, ut_teardown,
16304 			test_ipsec_proto_pkt_esn_antireplay4096,
16305 			&pkt_aes_128_gcm),
16306 		TEST_CASE_NAMED_ST(
16307 			"Tunnel header IPv4 decrement inner TTL",
16308 			ut_setup_security, ut_teardown,
16309 			test_ipsec_proto_ipv4_ttl_decrement),
16310 		TEST_CASE_NAMED_ST(
16311 			"Tunnel header IPv6 decrement inner hop limit",
16312 			ut_setup_security, ut_teardown,
16313 			test_ipsec_proto_ipv6_hop_limit_decrement),
16314 		TEST_CASE_NAMED_ST(
16315 			"Multi-segmented mode",
16316 			ut_setup_security, ut_teardown,
16317 			test_ipsec_proto_sgl),
16318 		TEST_CASE_NAMED_ST(
16319 			"Multi-segmented external mbuf mode",
16320 			ut_setup_security, ut_teardown,
16321 			test_ipsec_proto_sgl_ext_mbuf),
16322 		TEST_CASES_END() /**< NULL terminate unit test array */
16323 	}
16324 };
16325 
16326 static struct unit_test_suite pdcp_proto_testsuite  = {
16327 	.suite_name = "PDCP Proto Unit Test Suite",
16328 	.setup = pdcp_proto_testsuite_setup,
16329 	.unit_test_cases = {
16330 		TEST_CASE_ST(ut_setup_security, ut_teardown,
16331 			test_PDCP_PROTO_all),
16332 		TEST_CASES_END() /**< NULL terminate unit test array */
16333 	}
16334 };
16335 
16336 #define ADD_UPLINK_TESTCASE(data)						\
16337 	TEST_CASE_NAMED_WITH_DATA(data.test_descr_uplink, ut_setup_security,	\
16338 	ut_teardown, test_docsis_proto_uplink, (const void *) &data),		\
16339 
16340 #define ADD_DOWNLINK_TESTCASE(data)						\
16341 	TEST_CASE_NAMED_WITH_DATA(data.test_descr_downlink, ut_setup_security,	\
16342 	ut_teardown, test_docsis_proto_downlink, (const void *) &data),		\
16343 
16344 static struct unit_test_suite docsis_proto_testsuite  = {
16345 	.suite_name = "DOCSIS Proto Unit Test Suite",
16346 	.setup = docsis_proto_testsuite_setup,
16347 	.unit_test_cases = {
16348 		/* Uplink */
16349 		ADD_UPLINK_TESTCASE(docsis_test_case_1)
16350 		ADD_UPLINK_TESTCASE(docsis_test_case_2)
16351 		ADD_UPLINK_TESTCASE(docsis_test_case_3)
16352 		ADD_UPLINK_TESTCASE(docsis_test_case_4)
16353 		ADD_UPLINK_TESTCASE(docsis_test_case_5)
16354 		ADD_UPLINK_TESTCASE(docsis_test_case_6)
16355 		ADD_UPLINK_TESTCASE(docsis_test_case_7)
16356 		ADD_UPLINK_TESTCASE(docsis_test_case_8)
16357 		ADD_UPLINK_TESTCASE(docsis_test_case_9)
16358 		ADD_UPLINK_TESTCASE(docsis_test_case_10)
16359 		ADD_UPLINK_TESTCASE(docsis_test_case_11)
16360 		ADD_UPLINK_TESTCASE(docsis_test_case_12)
16361 		ADD_UPLINK_TESTCASE(docsis_test_case_13)
16362 		ADD_UPLINK_TESTCASE(docsis_test_case_14)
16363 		ADD_UPLINK_TESTCASE(docsis_test_case_15)
16364 		ADD_UPLINK_TESTCASE(docsis_test_case_16)
16365 		ADD_UPLINK_TESTCASE(docsis_test_case_17)
16366 		ADD_UPLINK_TESTCASE(docsis_test_case_18)
16367 		ADD_UPLINK_TESTCASE(docsis_test_case_19)
16368 		ADD_UPLINK_TESTCASE(docsis_test_case_20)
16369 		ADD_UPLINK_TESTCASE(docsis_test_case_21)
16370 		ADD_UPLINK_TESTCASE(docsis_test_case_22)
16371 		ADD_UPLINK_TESTCASE(docsis_test_case_23)
16372 		ADD_UPLINK_TESTCASE(docsis_test_case_24)
16373 		ADD_UPLINK_TESTCASE(docsis_test_case_25)
16374 		ADD_UPLINK_TESTCASE(docsis_test_case_26)
16375 		/* Downlink */
16376 		ADD_DOWNLINK_TESTCASE(docsis_test_case_1)
16377 		ADD_DOWNLINK_TESTCASE(docsis_test_case_2)
16378 		ADD_DOWNLINK_TESTCASE(docsis_test_case_3)
16379 		ADD_DOWNLINK_TESTCASE(docsis_test_case_4)
16380 		ADD_DOWNLINK_TESTCASE(docsis_test_case_5)
16381 		ADD_DOWNLINK_TESTCASE(docsis_test_case_6)
16382 		ADD_DOWNLINK_TESTCASE(docsis_test_case_7)
16383 		ADD_DOWNLINK_TESTCASE(docsis_test_case_8)
16384 		ADD_DOWNLINK_TESTCASE(docsis_test_case_9)
16385 		ADD_DOWNLINK_TESTCASE(docsis_test_case_10)
16386 		ADD_DOWNLINK_TESTCASE(docsis_test_case_11)
16387 		ADD_DOWNLINK_TESTCASE(docsis_test_case_12)
16388 		ADD_DOWNLINK_TESTCASE(docsis_test_case_13)
16389 		ADD_DOWNLINK_TESTCASE(docsis_test_case_14)
16390 		ADD_DOWNLINK_TESTCASE(docsis_test_case_15)
16391 		ADD_DOWNLINK_TESTCASE(docsis_test_case_16)
16392 		ADD_DOWNLINK_TESTCASE(docsis_test_case_17)
16393 		ADD_DOWNLINK_TESTCASE(docsis_test_case_18)
16394 		ADD_DOWNLINK_TESTCASE(docsis_test_case_19)
16395 		ADD_DOWNLINK_TESTCASE(docsis_test_case_20)
16396 		ADD_DOWNLINK_TESTCASE(docsis_test_case_21)
16397 		ADD_DOWNLINK_TESTCASE(docsis_test_case_22)
16398 		ADD_DOWNLINK_TESTCASE(docsis_test_case_23)
16399 		ADD_DOWNLINK_TESTCASE(docsis_test_case_24)
16400 		ADD_DOWNLINK_TESTCASE(docsis_test_case_25)
16401 		ADD_DOWNLINK_TESTCASE(docsis_test_case_26)
16402 		TEST_CASES_END() /**< NULL terminate unit test array */
16403 	}
16404 };
16405 #endif
16406 
16407 static struct unit_test_suite cryptodev_gen_testsuite  = {
16408 	.suite_name = "Crypto General Unit Test Suite",
16409 	.setup = crypto_gen_testsuite_setup,
16410 	.unit_test_cases = {
16411 		TEST_CASE_ST(ut_setup, ut_teardown,
16412 				test_device_reconfigure),
16413 		TEST_CASE_ST(ut_setup, ut_teardown,
16414 				test_device_configure_invalid_dev_id),
16415 		TEST_CASE_ST(ut_setup, ut_teardown,
16416 				test_queue_pair_descriptor_setup),
16417 		TEST_CASE_ST(ut_setup, ut_teardown,
16418 				test_device_configure_invalid_queue_pair_ids),
16419 		TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
16420 		TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup),
16421 		TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup),
16422 		TEST_CASES_END() /**< NULL terminate unit test array */
16423 	}
16424 };
16425 
16426 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = {
16427 	.suite_name = "Negative HMAC SHA1 Unit Test Suite",
16428 	.setup = negative_hmac_sha1_testsuite_setup,
16429 	.unit_test_cases = {
16430 		/** Negative tests */
16431 		TEST_CASE_ST(ut_setup, ut_teardown,
16432 			authentication_verify_HMAC_SHA1_fail_data_corrupt),
16433 		TEST_CASE_ST(ut_setup, ut_teardown,
16434 			authentication_verify_HMAC_SHA1_fail_tag_corrupt),
16435 		TEST_CASE_ST(ut_setup, ut_teardown,
16436 			auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
16437 		TEST_CASE_ST(ut_setup, ut_teardown,
16438 			auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
16439 
16440 		TEST_CASES_END() /**< NULL terminate unit test array */
16441 	}
16442 };
16443 
16444 static struct unit_test_suite cryptodev_multi_session_testsuite = {
16445 	.suite_name = "Multi Session Unit Test Suite",
16446 	.setup = multi_session_testsuite_setup,
16447 	.unit_test_cases = {
16448 		TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
16449 		TEST_CASE_ST(ut_setup, ut_teardown,
16450 				test_multi_session_random_usage),
16451 
16452 		TEST_CASES_END() /**< NULL terminate unit test array */
16453 	}
16454 };
16455 
16456 static struct unit_test_suite cryptodev_null_testsuite  = {
16457 	.suite_name = "NULL Test Suite",
16458 	.setup = null_testsuite_setup,
16459 	.unit_test_cases = {
16460 		TEST_CASE_ST(ut_setup, ut_teardown,
16461 			test_null_invalid_operation),
16462 		TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
16463 		TEST_CASES_END()
16464 	}
16465 };
16466 
16467 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite  = {
16468 	.suite_name = "AES CCM Authenticated Test Suite",
16469 	.setup = aes_ccm_auth_testsuite_setup,
16470 	.unit_test_cases = {
16471 		/** AES CCM Authenticated Encryption 128 bits key*/
16472 		TEST_CASE_ST(ut_setup, ut_teardown,
16473 			test_AES_CCM_authenticated_encryption_test_case_128_1),
16474 		TEST_CASE_ST(ut_setup, ut_teardown,
16475 			test_AES_CCM_authenticated_encryption_test_case_128_2),
16476 		TEST_CASE_ST(ut_setup, ut_teardown,
16477 			test_AES_CCM_authenticated_encryption_test_case_128_3),
16478 
16479 		/** AES CCM Authenticated Decryption 128 bits key*/
16480 		TEST_CASE_ST(ut_setup, ut_teardown,
16481 			test_AES_CCM_authenticated_decryption_test_case_128_1),
16482 		TEST_CASE_ST(ut_setup, ut_teardown,
16483 			test_AES_CCM_authenticated_decryption_test_case_128_2),
16484 		TEST_CASE_ST(ut_setup, ut_teardown,
16485 			test_AES_CCM_authenticated_decryption_test_case_128_3),
16486 
16487 		/** AES CCM Authenticated Encryption 192 bits key */
16488 		TEST_CASE_ST(ut_setup, ut_teardown,
16489 			test_AES_CCM_authenticated_encryption_test_case_192_1),
16490 		TEST_CASE_ST(ut_setup, ut_teardown,
16491 			test_AES_CCM_authenticated_encryption_test_case_192_2),
16492 		TEST_CASE_ST(ut_setup, ut_teardown,
16493 			test_AES_CCM_authenticated_encryption_test_case_192_3),
16494 
16495 		/** AES CCM Authenticated Decryption 192 bits key*/
16496 		TEST_CASE_ST(ut_setup, ut_teardown,
16497 			test_AES_CCM_authenticated_decryption_test_case_192_1),
16498 		TEST_CASE_ST(ut_setup, ut_teardown,
16499 			test_AES_CCM_authenticated_decryption_test_case_192_2),
16500 		TEST_CASE_ST(ut_setup, ut_teardown,
16501 			test_AES_CCM_authenticated_decryption_test_case_192_3),
16502 
16503 		/** AES CCM Authenticated Encryption 256 bits key */
16504 		TEST_CASE_ST(ut_setup, ut_teardown,
16505 			test_AES_CCM_authenticated_encryption_test_case_256_1),
16506 		TEST_CASE_ST(ut_setup, ut_teardown,
16507 			test_AES_CCM_authenticated_encryption_test_case_256_2),
16508 		TEST_CASE_ST(ut_setup, ut_teardown,
16509 			test_AES_CCM_authenticated_encryption_test_case_256_3),
16510 
16511 		/** AES CCM Authenticated Decryption 256 bits key*/
16512 		TEST_CASE_ST(ut_setup, ut_teardown,
16513 			test_AES_CCM_authenticated_decryption_test_case_256_1),
16514 		TEST_CASE_ST(ut_setup, ut_teardown,
16515 			test_AES_CCM_authenticated_decryption_test_case_256_2),
16516 		TEST_CASE_ST(ut_setup, ut_teardown,
16517 			test_AES_CCM_authenticated_decryption_test_case_256_3),
16518 		TEST_CASES_END()
16519 	}
16520 };
16521 
16522 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite  = {
16523 	.suite_name = "AES GCM Authenticated Test Suite",
16524 	.setup = aes_gcm_auth_testsuite_setup,
16525 	.unit_test_cases = {
16526 		/** AES GCM Authenticated Encryption */
16527 		TEST_CASE_ST(ut_setup, ut_teardown,
16528 			test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
16529 		TEST_CASE_ST(ut_setup, ut_teardown,
16530 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
16531 		TEST_CASE_ST(ut_setup, ut_teardown,
16532 			test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
16533 		TEST_CASE_ST(ut_setup, ut_teardown,
16534 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
16535 		TEST_CASE_ST(ut_setup, ut_teardown,
16536 			test_AES_GCM_authenticated_encryption_test_case_1),
16537 		TEST_CASE_ST(ut_setup, ut_teardown,
16538 			test_AES_GCM_authenticated_encryption_test_case_2),
16539 		TEST_CASE_ST(ut_setup, ut_teardown,
16540 			test_AES_GCM_authenticated_encryption_test_case_3),
16541 		TEST_CASE_ST(ut_setup, ut_teardown,
16542 			test_AES_GCM_authenticated_encryption_test_case_4),
16543 		TEST_CASE_ST(ut_setup, ut_teardown,
16544 			test_AES_GCM_authenticated_encryption_test_case_5),
16545 		TEST_CASE_ST(ut_setup, ut_teardown,
16546 			test_AES_GCM_authenticated_encryption_test_case_6),
16547 		TEST_CASE_ST(ut_setup, ut_teardown,
16548 			test_AES_GCM_authenticated_encryption_test_case_7),
16549 		TEST_CASE_ST(ut_setup, ut_teardown,
16550 			test_AES_GCM_authenticated_encryption_test_case_8),
16551 		TEST_CASE_ST(ut_setup, ut_teardown,
16552 			test_AES_GCM_J0_authenticated_encryption_test_case_1),
16553 
16554 		/** AES GCM Authenticated Decryption */
16555 		TEST_CASE_ST(ut_setup, ut_teardown,
16556 			test_AES_GCM_authenticated_decryption_test_case_1),
16557 		TEST_CASE_ST(ut_setup, ut_teardown,
16558 			test_AES_GCM_authenticated_decryption_test_case_2),
16559 		TEST_CASE_ST(ut_setup, ut_teardown,
16560 			test_AES_GCM_authenticated_decryption_test_case_3),
16561 		TEST_CASE_ST(ut_setup, ut_teardown,
16562 			test_AES_GCM_authenticated_decryption_test_case_4),
16563 		TEST_CASE_ST(ut_setup, ut_teardown,
16564 			test_AES_GCM_authenticated_decryption_test_case_5),
16565 		TEST_CASE_ST(ut_setup, ut_teardown,
16566 			test_AES_GCM_authenticated_decryption_test_case_6),
16567 		TEST_CASE_ST(ut_setup, ut_teardown,
16568 			test_AES_GCM_authenticated_decryption_test_case_7),
16569 		TEST_CASE_ST(ut_setup, ut_teardown,
16570 			test_AES_GCM_authenticated_decryption_test_case_8),
16571 		TEST_CASE_ST(ut_setup, ut_teardown,
16572 			test_AES_GCM_J0_authenticated_decryption_test_case_1),
16573 
16574 		/** AES GCM Authenticated Encryption 192 bits key */
16575 		TEST_CASE_ST(ut_setup, ut_teardown,
16576 			test_AES_GCM_auth_encryption_test_case_192_1),
16577 		TEST_CASE_ST(ut_setup, ut_teardown,
16578 			test_AES_GCM_auth_encryption_test_case_192_2),
16579 		TEST_CASE_ST(ut_setup, ut_teardown,
16580 			test_AES_GCM_auth_encryption_test_case_192_3),
16581 		TEST_CASE_ST(ut_setup, ut_teardown,
16582 			test_AES_GCM_auth_encryption_test_case_192_4),
16583 		TEST_CASE_ST(ut_setup, ut_teardown,
16584 			test_AES_GCM_auth_encryption_test_case_192_5),
16585 		TEST_CASE_ST(ut_setup, ut_teardown,
16586 			test_AES_GCM_auth_encryption_test_case_192_6),
16587 		TEST_CASE_ST(ut_setup, ut_teardown,
16588 			test_AES_GCM_auth_encryption_test_case_192_7),
16589 
16590 		/** AES GCM Authenticated Decryption 192 bits key */
16591 		TEST_CASE_ST(ut_setup, ut_teardown,
16592 			test_AES_GCM_auth_decryption_test_case_192_1),
16593 		TEST_CASE_ST(ut_setup, ut_teardown,
16594 			test_AES_GCM_auth_decryption_test_case_192_2),
16595 		TEST_CASE_ST(ut_setup, ut_teardown,
16596 			test_AES_GCM_auth_decryption_test_case_192_3),
16597 		TEST_CASE_ST(ut_setup, ut_teardown,
16598 			test_AES_GCM_auth_decryption_test_case_192_4),
16599 		TEST_CASE_ST(ut_setup, ut_teardown,
16600 			test_AES_GCM_auth_decryption_test_case_192_5),
16601 		TEST_CASE_ST(ut_setup, ut_teardown,
16602 			test_AES_GCM_auth_decryption_test_case_192_6),
16603 		TEST_CASE_ST(ut_setup, ut_teardown,
16604 			test_AES_GCM_auth_decryption_test_case_192_7),
16605 
16606 		/** AES GCM Authenticated Encryption 256 bits key */
16607 		TEST_CASE_ST(ut_setup, ut_teardown,
16608 			test_AES_GCM_auth_encryption_test_case_256_1),
16609 		TEST_CASE_ST(ut_setup, ut_teardown,
16610 			test_AES_GCM_auth_encryption_test_case_256_2),
16611 		TEST_CASE_ST(ut_setup, ut_teardown,
16612 			test_AES_GCM_auth_encryption_test_case_256_3),
16613 		TEST_CASE_ST(ut_setup, ut_teardown,
16614 			test_AES_GCM_auth_encryption_test_case_256_4),
16615 		TEST_CASE_ST(ut_setup, ut_teardown,
16616 			test_AES_GCM_auth_encryption_test_case_256_5),
16617 		TEST_CASE_ST(ut_setup, ut_teardown,
16618 			test_AES_GCM_auth_encryption_test_case_256_6),
16619 		TEST_CASE_ST(ut_setup, ut_teardown,
16620 			test_AES_GCM_auth_encryption_test_case_256_7),
16621 
16622 		/** AES GCM Authenticated Decryption 256 bits key */
16623 		TEST_CASE_ST(ut_setup, ut_teardown,
16624 			test_AES_GCM_auth_decryption_test_case_256_1),
16625 		TEST_CASE_ST(ut_setup, ut_teardown,
16626 			test_AES_GCM_auth_decryption_test_case_256_2),
16627 		TEST_CASE_ST(ut_setup, ut_teardown,
16628 			test_AES_GCM_auth_decryption_test_case_256_3),
16629 		TEST_CASE_ST(ut_setup, ut_teardown,
16630 			test_AES_GCM_auth_decryption_test_case_256_4),
16631 		TEST_CASE_ST(ut_setup, ut_teardown,
16632 			test_AES_GCM_auth_decryption_test_case_256_5),
16633 		TEST_CASE_ST(ut_setup, ut_teardown,
16634 			test_AES_GCM_auth_decryption_test_case_256_6),
16635 		TEST_CASE_ST(ut_setup, ut_teardown,
16636 			test_AES_GCM_auth_decryption_test_case_256_7),
16637 
16638 		/** AES GCM Authenticated Encryption big aad size */
16639 		TEST_CASE_ST(ut_setup, ut_teardown,
16640 			test_AES_GCM_auth_encryption_test_case_aad_1),
16641 		TEST_CASE_ST(ut_setup, ut_teardown,
16642 			test_AES_GCM_auth_encryption_test_case_aad_2),
16643 
16644 		/** AES GCM Authenticated Decryption big aad size */
16645 		TEST_CASE_ST(ut_setup, ut_teardown,
16646 			test_AES_GCM_auth_decryption_test_case_aad_1),
16647 		TEST_CASE_ST(ut_setup, ut_teardown,
16648 			test_AES_GCM_auth_decryption_test_case_aad_2),
16649 
16650 		/** Out of place tests */
16651 		TEST_CASE_ST(ut_setup, ut_teardown,
16652 			test_AES_GCM_authenticated_encryption_oop_test_case_1),
16653 		TEST_CASE_ST(ut_setup, ut_teardown,
16654 			test_AES_GCM_authenticated_decryption_oop_test_case_1),
16655 
16656 		/** Session-less tests */
16657 		TEST_CASE_ST(ut_setup, ut_teardown,
16658 			test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
16659 		TEST_CASE_ST(ut_setup, ut_teardown,
16660 			test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
16661 
16662 		TEST_CASES_END()
16663 	}
16664 };
16665 
16666 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite  = {
16667 	.suite_name = "AES GMAC Authentication Test Suite",
16668 	.setup = aes_gmac_auth_testsuite_setup,
16669 	.unit_test_cases = {
16670 		TEST_CASE_ST(ut_setup, ut_teardown,
16671 			test_AES_GMAC_authentication_test_case_1),
16672 		TEST_CASE_ST(ut_setup, ut_teardown,
16673 			test_AES_GMAC_authentication_verify_test_case_1),
16674 		TEST_CASE_ST(ut_setup, ut_teardown,
16675 			test_AES_GMAC_authentication_test_case_2),
16676 		TEST_CASE_ST(ut_setup, ut_teardown,
16677 			test_AES_GMAC_authentication_verify_test_case_2),
16678 		TEST_CASE_ST(ut_setup, ut_teardown,
16679 			test_AES_GMAC_authentication_test_case_3),
16680 		TEST_CASE_ST(ut_setup, ut_teardown,
16681 			test_AES_GMAC_authentication_verify_test_case_3),
16682 		TEST_CASE_ST(ut_setup, ut_teardown,
16683 			test_AES_GMAC_authentication_test_case_4),
16684 		TEST_CASE_ST(ut_setup, ut_teardown,
16685 			test_AES_GMAC_authentication_verify_test_case_4),
16686 		TEST_CASE_ST(ut_setup, ut_teardown,
16687 			test_AES_GMAC_authentication_SGL_40B),
16688 		TEST_CASE_ST(ut_setup, ut_teardown,
16689 			test_AES_GMAC_authentication_SGL_80B),
16690 		TEST_CASE_ST(ut_setup, ut_teardown,
16691 			test_AES_GMAC_authentication_SGL_2048B),
16692 		TEST_CASE_ST(ut_setup, ut_teardown,
16693 			test_AES_GMAC_authentication_SGL_2047B),
16694 
16695 		TEST_CASES_END()
16696 	}
16697 };
16698 
16699 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite  = {
16700 	.suite_name = "Chacha20-Poly1305 Test Suite",
16701 	.setup = chacha20_poly1305_testsuite_setup,
16702 	.unit_test_cases = {
16703 		TEST_CASE_ST(ut_setup, ut_teardown,
16704 			test_chacha20_poly1305_encrypt_test_case_rfc8439),
16705 		TEST_CASE_ST(ut_setup, ut_teardown,
16706 			test_chacha20_poly1305_decrypt_test_case_rfc8439),
16707 		TEST_CASE_ST(ut_setup, ut_teardown,
16708 			test_chacha20_poly1305_encrypt_SGL_out_of_place),
16709 		TEST_CASES_END()
16710 	}
16711 };
16712 
16713 static struct unit_test_suite cryptodev_snow3g_testsuite  = {
16714 	.suite_name = "SNOW 3G Test Suite",
16715 	.setup = snow3g_testsuite_setup,
16716 	.unit_test_cases = {
16717 		/** SNOW 3G encrypt only (UEA2) */
16718 		TEST_CASE_ST(ut_setup, ut_teardown,
16719 			test_snow3g_encryption_test_case_1),
16720 		TEST_CASE_ST(ut_setup, ut_teardown,
16721 			test_snow3g_encryption_test_case_2),
16722 		TEST_CASE_ST(ut_setup, ut_teardown,
16723 			test_snow3g_encryption_test_case_3),
16724 		TEST_CASE_ST(ut_setup, ut_teardown,
16725 			test_snow3g_encryption_test_case_4),
16726 		TEST_CASE_ST(ut_setup, ut_teardown,
16727 			test_snow3g_encryption_test_case_5),
16728 
16729 		TEST_CASE_ST(ut_setup, ut_teardown,
16730 			test_snow3g_encryption_test_case_1_oop),
16731 		TEST_CASE_ST(ut_setup, ut_teardown,
16732 			test_snow3g_encryption_test_case_1_oop_sgl),
16733 		TEST_CASE_ST(ut_setup, ut_teardown,
16734 			test_snow3g_encryption_test_case_1_oop_lb_in_sgl_out),
16735 		TEST_CASE_ST(ut_setup, ut_teardown,
16736 			test_snow3g_encryption_test_case_1_oop_sgl_in_lb_out),
16737 		TEST_CASE_ST(ut_setup, ut_teardown,
16738 			test_snow3g_encryption_test_case_1_offset_oop),
16739 		TEST_CASE_ST(ut_setup, ut_teardown,
16740 			test_snow3g_decryption_test_case_1_oop),
16741 
16742 		/** SNOW 3G generate auth, then encrypt (UEA2) */
16743 		TEST_CASE_ST(ut_setup, ut_teardown,
16744 			test_snow3g_auth_cipher_test_case_1),
16745 		TEST_CASE_ST(ut_setup, ut_teardown,
16746 			test_snow3g_auth_cipher_test_case_2),
16747 		TEST_CASE_ST(ut_setup, ut_teardown,
16748 			test_snow3g_auth_cipher_test_case_2_oop),
16749 		TEST_CASE_ST(ut_setup, ut_teardown,
16750 			test_snow3g_auth_cipher_part_digest_enc),
16751 		TEST_CASE_ST(ut_setup, ut_teardown,
16752 			test_snow3g_auth_cipher_part_digest_enc_oop),
16753 		TEST_CASE_ST(ut_setup, ut_teardown,
16754 			test_snow3g_auth_cipher_test_case_3_sgl),
16755 		TEST_CASE_ST(ut_setup, ut_teardown,
16756 			test_snow3g_auth_cipher_test_case_3_oop_sgl),
16757 		TEST_CASE_ST(ut_setup, ut_teardown,
16758 			test_snow3g_auth_cipher_part_digest_enc_sgl),
16759 		TEST_CASE_ST(ut_setup, ut_teardown,
16760 			test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
16761 		TEST_CASE_ST(ut_setup, ut_teardown,
16762 			test_snow3g_auth_cipher_total_digest_enc_1),
16763 		TEST_CASE_ST(ut_setup, ut_teardown,
16764 			test_snow3g_auth_cipher_total_digest_enc_1_oop),
16765 		TEST_CASE_ST(ut_setup, ut_teardown,
16766 			test_snow3g_auth_cipher_total_digest_enc_1_sgl),
16767 		TEST_CASE_ST(ut_setup, ut_teardown,
16768 			test_snow3g_auth_cipher_total_digest_enc_1_oop_sgl),
16769 
16770 		/** SNOW 3G decrypt (UEA2), then verify auth */
16771 		TEST_CASE_ST(ut_setup, ut_teardown,
16772 			test_snow3g_auth_cipher_verify_test_case_1),
16773 		TEST_CASE_ST(ut_setup, ut_teardown,
16774 			test_snow3g_auth_cipher_verify_test_case_2),
16775 		TEST_CASE_ST(ut_setup, ut_teardown,
16776 			test_snow3g_auth_cipher_verify_test_case_2_oop),
16777 		TEST_CASE_ST(ut_setup, ut_teardown,
16778 			test_snow3g_auth_cipher_verify_part_digest_enc),
16779 		TEST_CASE_ST(ut_setup, ut_teardown,
16780 			test_snow3g_auth_cipher_verify_part_digest_enc_oop),
16781 		TEST_CASE_ST(ut_setup, ut_teardown,
16782 			test_snow3g_auth_cipher_verify_test_case_3_sgl),
16783 		TEST_CASE_ST(ut_setup, ut_teardown,
16784 			test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
16785 		TEST_CASE_ST(ut_setup, ut_teardown,
16786 			test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
16787 		TEST_CASE_ST(ut_setup, ut_teardown,
16788 			test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
16789 		TEST_CASE_ST(ut_setup, ut_teardown,
16790 			test_snow3g_auth_cipher_verify_total_digest_enc_1),
16791 		TEST_CASE_ST(ut_setup, ut_teardown,
16792 			test_snow3g_auth_cipher_verify_total_digest_enc_1_oop),
16793 		TEST_CASE_ST(ut_setup, ut_teardown,
16794 			test_snow3g_auth_cipher_verify_total_digest_enc_1_sgl),
16795 		TEST_CASE_ST(ut_setup, ut_teardown,
16796 			test_snow3g_auth_cipher_verify_total_digest_enc_1_oop_sgl),
16797 
16798 		/** SNOW 3G decrypt only (UEA2) */
16799 		TEST_CASE_ST(ut_setup, ut_teardown,
16800 			test_snow3g_decryption_test_case_1),
16801 		TEST_CASE_ST(ut_setup, ut_teardown,
16802 			test_snow3g_decryption_test_case_2),
16803 		TEST_CASE_ST(ut_setup, ut_teardown,
16804 			test_snow3g_decryption_test_case_3),
16805 		TEST_CASE_ST(ut_setup, ut_teardown,
16806 			test_snow3g_decryption_test_case_4),
16807 		TEST_CASE_ST(ut_setup, ut_teardown,
16808 			test_snow3g_decryption_test_case_5),
16809 		TEST_CASE_ST(ut_setup, ut_teardown,
16810 			test_snow3g_decryption_with_digest_test_case_1),
16811 		TEST_CASE_ST(ut_setup, ut_teardown,
16812 			test_snow3g_hash_generate_test_case_1),
16813 		TEST_CASE_ST(ut_setup, ut_teardown,
16814 			test_snow3g_hash_generate_test_case_2),
16815 		TEST_CASE_ST(ut_setup, ut_teardown,
16816 			test_snow3g_hash_generate_test_case_3),
16817 
16818 		/* Tests with buffers which length is not byte-aligned */
16819 		TEST_CASE_ST(ut_setup, ut_teardown,
16820 			test_snow3g_hash_generate_test_case_4),
16821 		TEST_CASE_ST(ut_setup, ut_teardown,
16822 			test_snow3g_hash_generate_test_case_5),
16823 		TEST_CASE_ST(ut_setup, ut_teardown,
16824 			test_snow3g_hash_generate_test_case_6),
16825 		TEST_CASE_ST(ut_setup, ut_teardown,
16826 			test_snow3g_hash_verify_test_case_1),
16827 		TEST_CASE_ST(ut_setup, ut_teardown,
16828 			test_snow3g_hash_verify_test_case_2),
16829 		TEST_CASE_ST(ut_setup, ut_teardown,
16830 			test_snow3g_hash_verify_test_case_3),
16831 
16832 		/* Tests with buffers which length is not byte-aligned */
16833 		TEST_CASE_ST(ut_setup, ut_teardown,
16834 			test_snow3g_hash_verify_test_case_4),
16835 		TEST_CASE_ST(ut_setup, ut_teardown,
16836 			test_snow3g_hash_verify_test_case_5),
16837 		TEST_CASE_ST(ut_setup, ut_teardown,
16838 			test_snow3g_hash_verify_test_case_6),
16839 		TEST_CASE_ST(ut_setup, ut_teardown,
16840 			test_snow3g_cipher_auth_test_case_1),
16841 		TEST_CASE_ST(ut_setup, ut_teardown,
16842 			test_snow3g_auth_cipher_with_digest_test_case_1),
16843 		TEST_CASES_END()
16844 	}
16845 };
16846 
16847 static struct unit_test_suite cryptodev_zuc_testsuite  = {
16848 	.suite_name = "ZUC Test Suite",
16849 	.setup = zuc_testsuite_setup,
16850 	.unit_test_cases = {
16851 		/** ZUC encrypt only (EEA3) */
16852 		TEST_CASE_ST(ut_setup, ut_teardown,
16853 			test_zuc_encryption_test_case_1),
16854 		TEST_CASE_ST(ut_setup, ut_teardown,
16855 			test_zuc_encryption_test_case_2),
16856 		TEST_CASE_ST(ut_setup, ut_teardown,
16857 			test_zuc_encryption_test_case_3),
16858 		TEST_CASE_ST(ut_setup, ut_teardown,
16859 			test_zuc_encryption_test_case_4),
16860 		TEST_CASE_ST(ut_setup, ut_teardown,
16861 			test_zuc_encryption_test_case_5),
16862 		TEST_CASE_ST(ut_setup, ut_teardown,
16863 			test_zuc_encryption_test_case_6_sgl),
16864 
16865 		/** ZUC decrypt only (EEA3) */
16866 		TEST_CASE_ST(ut_setup, ut_teardown,
16867 			test_zuc_decryption_test_case_1),
16868 		TEST_CASE_ST(ut_setup, ut_teardown,
16869 			test_zuc_decryption_test_case_2),
16870 		TEST_CASE_ST(ut_setup, ut_teardown,
16871 			test_zuc_decryption_test_case_3),
16872 		TEST_CASE_ST(ut_setup, ut_teardown,
16873 			test_zuc_decryption_test_case_4),
16874 		TEST_CASE_ST(ut_setup, ut_teardown,
16875 			test_zuc_decryption_test_case_5),
16876 		TEST_CASE_ST(ut_setup, ut_teardown,
16877 			test_zuc_decryption_test_case_6_sgl),
16878 
16879 		/** ZUC authenticate (EIA3) */
16880 		TEST_CASE_ST(ut_setup, ut_teardown,
16881 			test_zuc_hash_generate_test_case_1),
16882 		TEST_CASE_ST(ut_setup, ut_teardown,
16883 			test_zuc_hash_generate_test_case_2),
16884 		TEST_CASE_ST(ut_setup, ut_teardown,
16885 			test_zuc_hash_generate_test_case_3),
16886 		TEST_CASE_ST(ut_setup, ut_teardown,
16887 			test_zuc_hash_generate_test_case_4),
16888 		TEST_CASE_ST(ut_setup, ut_teardown,
16889 			test_zuc_hash_generate_test_case_5),
16890 		TEST_CASE_ST(ut_setup, ut_teardown,
16891 			test_zuc_hash_generate_test_case_6),
16892 		TEST_CASE_ST(ut_setup, ut_teardown,
16893 			test_zuc_hash_generate_test_case_7),
16894 		TEST_CASE_ST(ut_setup, ut_teardown,
16895 			test_zuc_hash_generate_test_case_8),
16896 
16897 		/** ZUC verify (EIA3) */
16898 		TEST_CASE_ST(ut_setup, ut_teardown,
16899 			test_zuc_hash_verify_test_case_1),
16900 		TEST_CASE_ST(ut_setup, ut_teardown,
16901 			test_zuc_hash_verify_test_case_2),
16902 		TEST_CASE_ST(ut_setup, ut_teardown,
16903 			test_zuc_hash_verify_test_case_3),
16904 		TEST_CASE_ST(ut_setup, ut_teardown,
16905 			test_zuc_hash_verify_test_case_4),
16906 		TEST_CASE_ST(ut_setup, ut_teardown,
16907 			test_zuc_hash_verify_test_case_5),
16908 		TEST_CASE_ST(ut_setup, ut_teardown,
16909 			test_zuc_hash_verify_test_case_6),
16910 		TEST_CASE_ST(ut_setup, ut_teardown,
16911 			test_zuc_hash_verify_test_case_7),
16912 		TEST_CASE_ST(ut_setup, ut_teardown,
16913 			test_zuc_hash_verify_test_case_8),
16914 
16915 		/** ZUC alg-chain (EEA3/EIA3) */
16916 		TEST_CASE_ST(ut_setup, ut_teardown,
16917 			test_zuc_cipher_auth_test_case_1),
16918 		TEST_CASE_ST(ut_setup, ut_teardown,
16919 			test_zuc_cipher_auth_test_case_2),
16920 
16921 		/** ZUC generate auth, then encrypt (EEA3) */
16922 		TEST_CASE_ST(ut_setup, ut_teardown,
16923 			test_zuc_auth_cipher_test_case_1),
16924 		TEST_CASE_ST(ut_setup, ut_teardown,
16925 			test_zuc_auth_cipher_test_case_1_oop),
16926 		TEST_CASE_ST(ut_setup, ut_teardown,
16927 			test_zuc_auth_cipher_test_case_1_sgl),
16928 		TEST_CASE_ST(ut_setup, ut_teardown,
16929 			test_zuc_auth_cipher_test_case_1_oop_sgl),
16930 		TEST_CASE_ST(ut_setup, ut_teardown,
16931 			test_zuc_auth_cipher_test_case_2),
16932 		TEST_CASE_ST(ut_setup, ut_teardown,
16933 			test_zuc_auth_cipher_test_case_2_oop),
16934 
16935 		/** ZUC decrypt (EEA3), then verify auth */
16936 		TEST_CASE_ST(ut_setup, ut_teardown,
16937 			test_zuc_auth_cipher_verify_test_case_1),
16938 		TEST_CASE_ST(ut_setup, ut_teardown,
16939 			test_zuc_auth_cipher_verify_test_case_1_oop),
16940 		TEST_CASE_ST(ut_setup, ut_teardown,
16941 			test_zuc_auth_cipher_verify_test_case_1_sgl),
16942 		TEST_CASE_ST(ut_setup, ut_teardown,
16943 			test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
16944 		TEST_CASE_ST(ut_setup, ut_teardown,
16945 			test_zuc_auth_cipher_verify_test_case_2),
16946 		TEST_CASE_ST(ut_setup, ut_teardown,
16947 			test_zuc_auth_cipher_verify_test_case_2_oop),
16948 
16949 		/** ZUC-256 encrypt only **/
16950 		TEST_CASE_ST(ut_setup, ut_teardown,
16951 			test_zuc256_encryption_test_case_1),
16952 		TEST_CASE_ST(ut_setup, ut_teardown,
16953 			test_zuc256_encryption_test_case_2),
16954 
16955 		/** ZUC-256 decrypt only **/
16956 		TEST_CASE_ST(ut_setup, ut_teardown,
16957 			test_zuc256_decryption_test_case_1),
16958 		TEST_CASE_ST(ut_setup, ut_teardown,
16959 			test_zuc256_decryption_test_case_2),
16960 
16961 		/** ZUC-256 authentication only **/
16962 		TEST_CASE_ST(ut_setup, ut_teardown,
16963 			test_zuc256_hash_generate_4b_tag_test_case_1),
16964 		TEST_CASE_ST(ut_setup, ut_teardown,
16965 			test_zuc256_hash_generate_4b_tag_test_case_2),
16966 		TEST_CASE_ST(ut_setup, ut_teardown,
16967 			test_zuc256_hash_generate_4b_tag_test_case_3),
16968 		TEST_CASE_ST(ut_setup, ut_teardown,
16969 			test_zuc256_hash_generate_8b_tag_test_case_1),
16970 		TEST_CASE_ST(ut_setup, ut_teardown,
16971 			test_zuc256_hash_generate_16b_tag_test_case_1),
16972 
16973 		/** ZUC-256 authentication verify only **/
16974 		TEST_CASE_ST(ut_setup, ut_teardown,
16975 			test_zuc256_hash_verify_4b_tag_test_case_1),
16976 		TEST_CASE_ST(ut_setup, ut_teardown,
16977 			test_zuc256_hash_verify_4b_tag_test_case_2),
16978 		TEST_CASE_ST(ut_setup, ut_teardown,
16979 			test_zuc256_hash_verify_4b_tag_test_case_3),
16980 		TEST_CASE_ST(ut_setup, ut_teardown,
16981 			test_zuc256_hash_verify_8b_tag_test_case_1),
16982 		TEST_CASE_ST(ut_setup, ut_teardown,
16983 			test_zuc256_hash_verify_16b_tag_test_case_1),
16984 
16985 		/** ZUC-256 encrypt and authenticate **/
16986 		TEST_CASE_ST(ut_setup, ut_teardown,
16987 			test_zuc256_cipher_auth_4b_tag_test_case_1),
16988 		TEST_CASE_ST(ut_setup, ut_teardown,
16989 			test_zuc256_cipher_auth_4b_tag_test_case_2),
16990 		TEST_CASE_ST(ut_setup, ut_teardown,
16991 			test_zuc256_cipher_auth_8b_tag_test_case_1),
16992 		TEST_CASE_ST(ut_setup, ut_teardown,
16993 			test_zuc256_cipher_auth_16b_tag_test_case_1),
16994 
16995 		/** ZUC-256 generate auth, then encrypt */
16996 		TEST_CASE_ST(ut_setup, ut_teardown,
16997 			test_zuc256_auth_cipher_4b_tag_test_case_1),
16998 		TEST_CASE_ST(ut_setup, ut_teardown,
16999 			test_zuc256_auth_cipher_4b_tag_test_case_2),
17000 		TEST_CASE_ST(ut_setup, ut_teardown,
17001 			test_zuc256_auth_cipher_8b_tag_test_case_1),
17002 		TEST_CASE_ST(ut_setup, ut_teardown,
17003 			test_zuc256_auth_cipher_16b_tag_test_case_1),
17004 
17005 		/** ZUC-256 decrypt, then verify auth */
17006 		TEST_CASE_ST(ut_setup, ut_teardown,
17007 			test_zuc256_auth_cipher_verify_4b_tag_test_case_1),
17008 		TEST_CASE_ST(ut_setup, ut_teardown,
17009 			test_zuc256_auth_cipher_verify_4b_tag_test_case_2),
17010 		TEST_CASE_ST(ut_setup, ut_teardown,
17011 			test_zuc256_auth_cipher_verify_8b_tag_test_case_1),
17012 		TEST_CASE_ST(ut_setup, ut_teardown,
17013 			test_zuc256_auth_cipher_verify_16b_tag_test_case_1),
17014 
17015 		TEST_CASES_END()
17016 	}
17017 };
17018 
17019 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite  = {
17020 	.suite_name = "HMAC_MD5 Authentication Test Suite",
17021 	.setup = hmac_md5_auth_testsuite_setup,
17022 	.unit_test_cases = {
17023 		TEST_CASE_ST(ut_setup, ut_teardown,
17024 			test_MD5_HMAC_generate_case_1),
17025 		TEST_CASE_ST(ut_setup, ut_teardown,
17026 			test_MD5_HMAC_verify_case_1),
17027 		TEST_CASE_ST(ut_setup, ut_teardown,
17028 			test_MD5_HMAC_generate_case_2),
17029 		TEST_CASE_ST(ut_setup, ut_teardown,
17030 			test_MD5_HMAC_verify_case_2),
17031 		TEST_CASES_END()
17032 	}
17033 };
17034 
17035 static struct unit_test_suite cryptodev_kasumi_testsuite  = {
17036 	.suite_name = "Kasumi Test Suite",
17037 	.setup = kasumi_testsuite_setup,
17038 	.unit_test_cases = {
17039 		/** KASUMI hash only (UIA1) */
17040 		TEST_CASE_ST(ut_setup, ut_teardown,
17041 			test_kasumi_hash_generate_test_case_1),
17042 		TEST_CASE_ST(ut_setup, ut_teardown,
17043 			test_kasumi_hash_generate_test_case_2),
17044 		TEST_CASE_ST(ut_setup, ut_teardown,
17045 			test_kasumi_hash_generate_test_case_3),
17046 		TEST_CASE_ST(ut_setup, ut_teardown,
17047 			test_kasumi_hash_generate_test_case_4),
17048 		TEST_CASE_ST(ut_setup, ut_teardown,
17049 			test_kasumi_hash_generate_test_case_5),
17050 		TEST_CASE_ST(ut_setup, ut_teardown,
17051 			test_kasumi_hash_generate_test_case_6),
17052 
17053 		TEST_CASE_ST(ut_setup, ut_teardown,
17054 			test_kasumi_hash_verify_test_case_1),
17055 		TEST_CASE_ST(ut_setup, ut_teardown,
17056 			test_kasumi_hash_verify_test_case_2),
17057 		TEST_CASE_ST(ut_setup, ut_teardown,
17058 			test_kasumi_hash_verify_test_case_3),
17059 		TEST_CASE_ST(ut_setup, ut_teardown,
17060 			test_kasumi_hash_verify_test_case_4),
17061 		TEST_CASE_ST(ut_setup, ut_teardown,
17062 			test_kasumi_hash_verify_test_case_5),
17063 
17064 		/** KASUMI encrypt only (UEA1) */
17065 		TEST_CASE_ST(ut_setup, ut_teardown,
17066 			test_kasumi_encryption_test_case_1),
17067 		TEST_CASE_ST(ut_setup, ut_teardown,
17068 			test_kasumi_encryption_test_case_1_sgl),
17069 		TEST_CASE_ST(ut_setup, ut_teardown,
17070 			test_kasumi_encryption_test_case_1_oop),
17071 		TEST_CASE_ST(ut_setup, ut_teardown,
17072 			test_kasumi_encryption_test_case_1_oop_sgl),
17073 		TEST_CASE_ST(ut_setup, ut_teardown,
17074 			test_kasumi_encryption_test_case_2),
17075 		TEST_CASE_ST(ut_setup, ut_teardown,
17076 			test_kasumi_encryption_test_case_3),
17077 		TEST_CASE_ST(ut_setup, ut_teardown,
17078 			test_kasumi_encryption_test_case_4),
17079 		TEST_CASE_ST(ut_setup, ut_teardown,
17080 			test_kasumi_encryption_test_case_5),
17081 
17082 		/** KASUMI decrypt only (UEA1) */
17083 		TEST_CASE_ST(ut_setup, ut_teardown,
17084 			test_kasumi_decryption_test_case_1),
17085 		TEST_CASE_ST(ut_setup, ut_teardown,
17086 			test_kasumi_decryption_test_case_2),
17087 		TEST_CASE_ST(ut_setup, ut_teardown,
17088 			test_kasumi_decryption_test_case_3),
17089 		TEST_CASE_ST(ut_setup, ut_teardown,
17090 			test_kasumi_decryption_test_case_4),
17091 		TEST_CASE_ST(ut_setup, ut_teardown,
17092 			test_kasumi_decryption_test_case_5),
17093 		TEST_CASE_ST(ut_setup, ut_teardown,
17094 			test_kasumi_decryption_test_case_1_oop),
17095 		TEST_CASE_ST(ut_setup, ut_teardown,
17096 			test_kasumi_cipher_auth_test_case_1),
17097 
17098 		/** KASUMI generate auth, then encrypt (F8) */
17099 		TEST_CASE_ST(ut_setup, ut_teardown,
17100 			test_kasumi_auth_cipher_test_case_1),
17101 		TEST_CASE_ST(ut_setup, ut_teardown,
17102 			test_kasumi_auth_cipher_test_case_2),
17103 		TEST_CASE_ST(ut_setup, ut_teardown,
17104 			test_kasumi_auth_cipher_test_case_2_oop),
17105 		TEST_CASE_ST(ut_setup, ut_teardown,
17106 			test_kasumi_auth_cipher_test_case_2_sgl),
17107 		TEST_CASE_ST(ut_setup, ut_teardown,
17108 			test_kasumi_auth_cipher_test_case_2_oop_sgl),
17109 
17110 		/** KASUMI decrypt (F8), then verify auth */
17111 		TEST_CASE_ST(ut_setup, ut_teardown,
17112 			test_kasumi_auth_cipher_verify_test_case_1),
17113 		TEST_CASE_ST(ut_setup, ut_teardown,
17114 			test_kasumi_auth_cipher_verify_test_case_2),
17115 		TEST_CASE_ST(ut_setup, ut_teardown,
17116 			test_kasumi_auth_cipher_verify_test_case_2_oop),
17117 		TEST_CASE_ST(ut_setup, ut_teardown,
17118 			test_kasumi_auth_cipher_verify_test_case_2_sgl),
17119 		TEST_CASE_ST(ut_setup, ut_teardown,
17120 			test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
17121 
17122 		TEST_CASES_END()
17123 	}
17124 };
17125 
17126 static struct unit_test_suite cryptodev_esn_testsuite  = {
17127 	.suite_name = "ESN Test Suite",
17128 	.setup = esn_testsuite_setup,
17129 	.unit_test_cases = {
17130 		TEST_CASE_ST(ut_setup, ut_teardown,
17131 			auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
17132 		TEST_CASE_ST(ut_setup, ut_teardown,
17133 			auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
17134 		TEST_CASES_END()
17135 	}
17136 };
17137 
17138 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite  = {
17139 	.suite_name = "Negative AES GCM Test Suite",
17140 	.setup = negative_aes_gcm_testsuite_setup,
17141 	.unit_test_cases = {
17142 		TEST_CASE_ST(ut_setup, ut_teardown,
17143 			test_AES_GCM_auth_encryption_fail_iv_corrupt),
17144 		TEST_CASE_ST(ut_setup, ut_teardown,
17145 			test_AES_GCM_auth_encryption_fail_in_data_corrupt),
17146 		TEST_CASE_ST(ut_setup, ut_teardown,
17147 			test_AES_GCM_auth_encryption_fail_out_data_corrupt),
17148 		TEST_CASE_ST(ut_setup, ut_teardown,
17149 			test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
17150 		TEST_CASE_ST(ut_setup, ut_teardown,
17151 			test_AES_GCM_auth_encryption_fail_aad_corrupt),
17152 		TEST_CASE_ST(ut_setup, ut_teardown,
17153 			test_AES_GCM_auth_encryption_fail_tag_corrupt),
17154 		TEST_CASE_ST(ut_setup, ut_teardown,
17155 			test_AES_GCM_auth_decryption_fail_iv_corrupt),
17156 		TEST_CASE_ST(ut_setup, ut_teardown,
17157 			test_AES_GCM_auth_decryption_fail_in_data_corrupt),
17158 		TEST_CASE_ST(ut_setup, ut_teardown,
17159 			test_AES_GCM_auth_decryption_fail_out_data_corrupt),
17160 		TEST_CASE_ST(ut_setup, ut_teardown,
17161 			test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
17162 		TEST_CASE_ST(ut_setup, ut_teardown,
17163 			test_AES_GCM_auth_decryption_fail_aad_corrupt),
17164 		TEST_CASE_ST(ut_setup, ut_teardown,
17165 			test_AES_GCM_auth_decryption_fail_tag_corrupt),
17166 
17167 		TEST_CASES_END()
17168 	}
17169 };
17170 
17171 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite  = {
17172 	.suite_name = "Negative AES GMAC Test Suite",
17173 	.setup = negative_aes_gmac_testsuite_setup,
17174 	.unit_test_cases = {
17175 		TEST_CASE_ST(ut_setup, ut_teardown,
17176 			authentication_verify_AES128_GMAC_fail_data_corrupt),
17177 		TEST_CASE_ST(ut_setup, ut_teardown,
17178 			authentication_verify_AES128_GMAC_fail_tag_corrupt),
17179 
17180 		TEST_CASES_END()
17181 	}
17182 };
17183 
17184 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite  = {
17185 	.suite_name = "Mixed CIPHER + HASH algorithms Test Suite",
17186 	.setup = mixed_cipher_hash_testsuite_setup,
17187 	.unit_test_cases = {
17188 		/** AUTH AES CMAC + CIPHER AES CTR */
17189 		TEST_CASE_ST(ut_setup, ut_teardown,
17190 			test_aes_cmac_aes_ctr_digest_enc_test_case_1),
17191 		TEST_CASE_ST(ut_setup, ut_teardown,
17192 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
17193 		TEST_CASE_ST(ut_setup, ut_teardown,
17194 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
17195 		TEST_CASE_ST(ut_setup, ut_teardown,
17196 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
17197 		TEST_CASE_ST(ut_setup, ut_teardown,
17198 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
17199 		TEST_CASE_ST(ut_setup, ut_teardown,
17200 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
17201 		TEST_CASE_ST(ut_setup, ut_teardown,
17202 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
17203 		TEST_CASE_ST(ut_setup, ut_teardown,
17204 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
17205 		TEST_CASE_ST(ut_setup, ut_teardown,
17206 			test_aes_cmac_aes_ctr_digest_enc_test_case_2),
17207 		TEST_CASE_ST(ut_setup, ut_teardown,
17208 			test_aes_cmac_aes_ctr_digest_enc_test_case_2_oop),
17209 		TEST_CASE_ST(ut_setup, ut_teardown,
17210 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2),
17211 		TEST_CASE_ST(ut_setup, ut_teardown,
17212 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2_oop),
17213 
17214 		/** AUTH ZUC + CIPHER SNOW3G */
17215 		TEST_CASE_ST(ut_setup, ut_teardown,
17216 			test_auth_zuc_cipher_snow_test_case_1),
17217 		TEST_CASE_ST(ut_setup, ut_teardown,
17218 			test_verify_auth_zuc_cipher_snow_test_case_1),
17219 		TEST_CASE_ST(ut_setup, ut_teardown,
17220 			test_auth_zuc_cipher_snow_test_case_1_inplace),
17221 		TEST_CASE_ST(ut_setup, ut_teardown,
17222 			test_verify_auth_zuc_cipher_snow_test_case_1_inplace),
17223 		/** AUTH AES CMAC + CIPHER SNOW3G */
17224 		TEST_CASE_ST(ut_setup, ut_teardown,
17225 			test_auth_aes_cmac_cipher_snow_test_case_1),
17226 		TEST_CASE_ST(ut_setup, ut_teardown,
17227 			test_verify_auth_aes_cmac_cipher_snow_test_case_1),
17228 		TEST_CASE_ST(ut_setup, ut_teardown,
17229 			test_auth_aes_cmac_cipher_snow_test_case_1_inplace),
17230 		TEST_CASE_ST(ut_setup, ut_teardown,
17231 			test_verify_auth_aes_cmac_cipher_snow_test_case_1_inplace),
17232 		/** AUTH ZUC + CIPHER AES CTR */
17233 		TEST_CASE_ST(ut_setup, ut_teardown,
17234 			test_auth_zuc_cipher_aes_ctr_test_case_1),
17235 		TEST_CASE_ST(ut_setup, ut_teardown,
17236 			test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
17237 		TEST_CASE_ST(ut_setup, ut_teardown,
17238 			test_auth_zuc_cipher_aes_ctr_test_case_1_inplace),
17239 		TEST_CASE_ST(ut_setup, ut_teardown,
17240 			test_verify_auth_zuc_cipher_aes_ctr_test_case_1_inplace),
17241 		/** AUTH SNOW3G + CIPHER AES CTR */
17242 		TEST_CASE_ST(ut_setup, ut_teardown,
17243 			test_auth_snow_cipher_aes_ctr_test_case_1),
17244 		TEST_CASE_ST(ut_setup, ut_teardown,
17245 			test_verify_auth_snow_cipher_aes_ctr_test_case_1),
17246 		TEST_CASE_ST(ut_setup, ut_teardown,
17247 			test_auth_snow_cipher_aes_ctr_test_case_1_inplace),
17248 		TEST_CASE_ST(ut_setup, ut_teardown,
17249 			test_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl),
17250 		TEST_CASE_ST(ut_setup, ut_teardown,
17251 			test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace),
17252 		TEST_CASE_ST(ut_setup, ut_teardown,
17253 			test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl),
17254 		/** AUTH SNOW3G + CIPHER ZUC */
17255 		TEST_CASE_ST(ut_setup, ut_teardown,
17256 			test_auth_snow_cipher_zuc_test_case_1),
17257 		TEST_CASE_ST(ut_setup, ut_teardown,
17258 			test_verify_auth_snow_cipher_zuc_test_case_1),
17259 		TEST_CASE_ST(ut_setup, ut_teardown,
17260 			test_auth_snow_cipher_zuc_test_case_1_inplace),
17261 		TEST_CASE_ST(ut_setup, ut_teardown,
17262 			test_verify_auth_snow_cipher_zuc_test_case_1_inplace),
17263 		/** AUTH AES CMAC + CIPHER ZUC */
17264 		TEST_CASE_ST(ut_setup, ut_teardown,
17265 			test_auth_aes_cmac_cipher_zuc_test_case_1),
17266 		TEST_CASE_ST(ut_setup, ut_teardown,
17267 			test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
17268 		TEST_CASE_ST(ut_setup, ut_teardown,
17269 			test_auth_aes_cmac_cipher_zuc_test_case_1_inplace),
17270 		TEST_CASE_ST(ut_setup, ut_teardown,
17271 			test_verify_auth_aes_cmac_cipher_zuc_test_case_1_inplace),
17272 
17273 		/** AUTH NULL + CIPHER SNOW3G */
17274 		TEST_CASE_ST(ut_setup, ut_teardown,
17275 			test_auth_null_cipher_snow_test_case_1),
17276 		TEST_CASE_ST(ut_setup, ut_teardown,
17277 			test_verify_auth_null_cipher_snow_test_case_1),
17278 		/** AUTH NULL + CIPHER ZUC */
17279 		TEST_CASE_ST(ut_setup, ut_teardown,
17280 			test_auth_null_cipher_zuc_test_case_1),
17281 		TEST_CASE_ST(ut_setup, ut_teardown,
17282 			test_verify_auth_null_cipher_zuc_test_case_1),
17283 		/** AUTH SNOW3G + CIPHER NULL */
17284 		TEST_CASE_ST(ut_setup, ut_teardown,
17285 			test_auth_snow_cipher_null_test_case_1),
17286 		TEST_CASE_ST(ut_setup, ut_teardown,
17287 			test_verify_auth_snow_cipher_null_test_case_1),
17288 		/** AUTH ZUC + CIPHER NULL */
17289 		TEST_CASE_ST(ut_setup, ut_teardown,
17290 			test_auth_zuc_cipher_null_test_case_1),
17291 		TEST_CASE_ST(ut_setup, ut_teardown,
17292 			test_verify_auth_zuc_cipher_null_test_case_1),
17293 		/** AUTH NULL + CIPHER AES CTR */
17294 		TEST_CASE_ST(ut_setup, ut_teardown,
17295 			test_auth_null_cipher_aes_ctr_test_case_1),
17296 		TEST_CASE_ST(ut_setup, ut_teardown,
17297 			test_verify_auth_null_cipher_aes_ctr_test_case_1),
17298 		/** AUTH AES CMAC + CIPHER NULL */
17299 		TEST_CASE_ST(ut_setup, ut_teardown,
17300 			test_auth_aes_cmac_cipher_null_test_case_1),
17301 		TEST_CASE_ST(ut_setup, ut_teardown,
17302 			test_verify_auth_aes_cmac_cipher_null_test_case_1),
17303 		TEST_CASES_END()
17304 	}
17305 };
17306 
17307 static int
17308 run_cryptodev_testsuite(const char *pmd_name)
17309 {
17310 	uint8_t ret, j, i = 0, blk_start_idx = 0;
17311 	const enum blockcipher_test_type blk_suites[] = {
17312 		BLKCIPHER_AES_CHAIN_TYPE,
17313 		BLKCIPHER_AES_CIPHERONLY_TYPE,
17314 		BLKCIPHER_AES_DOCSIS_TYPE,
17315 		BLKCIPHER_3DES_CHAIN_TYPE,
17316 		BLKCIPHER_3DES_CIPHERONLY_TYPE,
17317 		BLKCIPHER_DES_CIPHERONLY_TYPE,
17318 		BLKCIPHER_DES_DOCSIS_TYPE,
17319 		BLKCIPHER_SM4_CHAIN_TYPE,
17320 		BLKCIPHER_SM4_CIPHERONLY_TYPE,
17321 		BLKCIPHER_AUTHONLY_TYPE};
17322 	struct unit_test_suite *static_suites[] = {
17323 		&cryptodev_multi_session_testsuite,
17324 		&cryptodev_null_testsuite,
17325 		&cryptodev_aes_ccm_auth_testsuite,
17326 		&cryptodev_aes_gcm_auth_testsuite,
17327 		&cryptodev_aes_gmac_auth_testsuite,
17328 		&cryptodev_snow3g_testsuite,
17329 		&cryptodev_chacha20_poly1305_testsuite,
17330 		&cryptodev_zuc_testsuite,
17331 		&cryptodev_hmac_md5_auth_testsuite,
17332 		&cryptodev_kasumi_testsuite,
17333 		&cryptodev_esn_testsuite,
17334 		&cryptodev_negative_aes_gcm_testsuite,
17335 		&cryptodev_negative_aes_gmac_testsuite,
17336 		&cryptodev_mixed_cipher_hash_testsuite,
17337 		&cryptodev_negative_hmac_sha1_testsuite,
17338 		&cryptodev_gen_testsuite,
17339 #ifdef RTE_LIB_SECURITY
17340 		&ipsec_proto_testsuite,
17341 		&pdcp_proto_testsuite,
17342 		&docsis_proto_testsuite,
17343 #endif
17344 		&end_testsuite
17345 	};
17346 	static struct unit_test_suite ts = {
17347 		.suite_name = "Cryptodev Unit Test Suite",
17348 		.setup = testsuite_setup,
17349 		.teardown = testsuite_teardown,
17350 		.unit_test_cases = {TEST_CASES_END()}
17351 	};
17352 
17353 	gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name);
17354 
17355 	if (gbl_driver_id == -1) {
17356 		RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name);
17357 		return TEST_SKIPPED;
17358 	}
17359 
17360 	ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
17361 			(RTE_DIM(blk_suites) + RTE_DIM(static_suites)));
17362 
17363 	ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites));
17364 	ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
17365 	ret = unit_test_suite_runner(&ts);
17366 
17367 	FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites));
17368 	free(ts.unit_test_suites);
17369 	return ret;
17370 }
17371 
17372 static int
17373 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name)
17374 {
17375 	struct rte_cryptodev_info dev_info;
17376 	uint8_t i, nb_devs;
17377 	int driver_id;
17378 
17379 	driver_id = rte_cryptodev_driver_id_get(pmd_name);
17380 	if (driver_id == -1) {
17381 		RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name);
17382 		return TEST_SKIPPED;
17383 	}
17384 
17385 	nb_devs = rte_cryptodev_count();
17386 	if (nb_devs < 1) {
17387 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
17388 		return TEST_SKIPPED;
17389 	}
17390 
17391 	for (i = 0; i < nb_devs; i++) {
17392 		rte_cryptodev_info_get(i, &dev_info);
17393 		if (dev_info.driver_id == driver_id) {
17394 			if (!(dev_info.feature_flags & flag)) {
17395 				RTE_LOG(INFO, USER1, "%s not supported\n",
17396 						flag_name);
17397 				return TEST_SKIPPED;
17398 			}
17399 			return 0; /* found */
17400 		}
17401 	}
17402 
17403 	RTE_LOG(INFO, USER1, "%s not supported\n", flag_name);
17404 	return TEST_SKIPPED;
17405 }
17406 
17407 static int
17408 test_cryptodev_qat(void)
17409 {
17410 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
17411 }
17412 
17413 static int
17414 test_cryptodev_uadk(void)
17415 {
17416 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_UADK_PMD));
17417 }
17418 
17419 static int
17420 test_cryptodev_virtio(void)
17421 {
17422 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
17423 }
17424 
17425 static int
17426 test_cryptodev_aesni_mb(void)
17427 {
17428 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
17429 }
17430 
17431 static int
17432 test_cryptodev_cpu_aesni_mb(void)
17433 {
17434 	int32_t rc;
17435 	enum rte_security_session_action_type at = gbl_action_type;
17436 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
17437 	rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
17438 	gbl_action_type = at;
17439 	return rc;
17440 }
17441 
17442 static int
17443 test_cryptodev_chacha_poly_mb(void)
17444 {
17445 	int32_t rc;
17446 	enum rte_security_session_action_type at = gbl_action_type;
17447 	rc = run_cryptodev_testsuite(
17448 			RTE_STR(CRYPTODEV_NAME_CHACHA20_POLY1305_PMD));
17449 	gbl_action_type = at;
17450 	return rc;
17451 }
17452 
17453 static int
17454 test_cryptodev_openssl(void)
17455 {
17456 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
17457 }
17458 
17459 static int
17460 test_cryptodev_aesni_gcm(void)
17461 {
17462 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
17463 }
17464 
17465 static int
17466 test_cryptodev_cpu_aesni_gcm(void)
17467 {
17468 	int32_t rc;
17469 	enum rte_security_session_action_type at = gbl_action_type;
17470 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
17471 	rc  = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
17472 	gbl_action_type = at;
17473 	return rc;
17474 }
17475 
17476 static int
17477 test_cryptodev_mlx5(void)
17478 {
17479 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD));
17480 }
17481 
17482 static int
17483 test_cryptodev_null(void)
17484 {
17485 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD));
17486 }
17487 
17488 static int
17489 test_cryptodev_sw_snow3g(void)
17490 {
17491 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
17492 }
17493 
17494 static int
17495 test_cryptodev_sw_kasumi(void)
17496 {
17497 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
17498 }
17499 
17500 static int
17501 test_cryptodev_sw_zuc(void)
17502 {
17503 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
17504 }
17505 
17506 static int
17507 test_cryptodev_armv8(void)
17508 {
17509 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
17510 }
17511 
17512 static int
17513 test_cryptodev_mrvl(void)
17514 {
17515 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
17516 }
17517 
17518 #ifdef RTE_CRYPTO_SCHEDULER
17519 
17520 static int
17521 test_cryptodev_scheduler(void)
17522 {
17523 	uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0;
17524 	const enum blockcipher_test_type blk_suites[] = {
17525 		BLKCIPHER_AES_CHAIN_TYPE,
17526 		BLKCIPHER_AES_CIPHERONLY_TYPE,
17527 		BLKCIPHER_AUTHONLY_TYPE
17528 	};
17529 	static struct unit_test_suite scheduler_multicore = {
17530 		.suite_name = "Scheduler Multicore Unit Test Suite",
17531 		.setup = scheduler_multicore_testsuite_setup,
17532 		.teardown = scheduler_mode_testsuite_teardown,
17533 		.unit_test_cases = {TEST_CASES_END()}
17534 	};
17535 	static struct unit_test_suite scheduler_round_robin = {
17536 		.suite_name = "Scheduler Round Robin Unit Test Suite",
17537 		.setup = scheduler_roundrobin_testsuite_setup,
17538 		.teardown = scheduler_mode_testsuite_teardown,
17539 		.unit_test_cases = {TEST_CASES_END()}
17540 	};
17541 	static struct unit_test_suite scheduler_failover = {
17542 		.suite_name = "Scheduler Failover Unit Test Suite",
17543 		.setup = scheduler_failover_testsuite_setup,
17544 		.teardown = scheduler_mode_testsuite_teardown,
17545 		.unit_test_cases = {TEST_CASES_END()}
17546 	};
17547 	static struct unit_test_suite scheduler_pkt_size_distr = {
17548 		.suite_name = "Scheduler Pkt Size Distr Unit Test Suite",
17549 		.setup = scheduler_pkt_size_distr_testsuite_setup,
17550 		.teardown = scheduler_mode_testsuite_teardown,
17551 		.unit_test_cases = {TEST_CASES_END()}
17552 	};
17553 	struct unit_test_suite *sched_mode_suites[] = {
17554 		&scheduler_multicore,
17555 		&scheduler_round_robin,
17556 		&scheduler_failover,
17557 		&scheduler_pkt_size_distr
17558 	};
17559 	static struct unit_test_suite scheduler_config = {
17560 		.suite_name = "Crypto Device Scheduler Config Unit Test Suite",
17561 		.unit_test_cases = {
17562 			TEST_CASE(test_scheduler_attach_worker_op),
17563 			TEST_CASE(test_scheduler_mode_multicore_op),
17564 			TEST_CASE(test_scheduler_mode_roundrobin_op),
17565 			TEST_CASE(test_scheduler_mode_failover_op),
17566 			TEST_CASE(test_scheduler_mode_pkt_size_distr_op),
17567 			TEST_CASE(test_scheduler_detach_worker_op),
17568 
17569 			TEST_CASES_END() /**< NULL terminate array */
17570 		}
17571 	};
17572 	struct unit_test_suite *static_suites[] = {
17573 		&scheduler_config,
17574 		&end_testsuite
17575 	};
17576 	struct unit_test_suite *sched_mode_static_suites[] = {
17577 #ifdef RTE_LIB_SECURITY
17578 		&docsis_proto_testsuite,
17579 #endif
17580 		&end_testsuite
17581 	};
17582 	static struct unit_test_suite ts = {
17583 		.suite_name = "Scheduler Unit Test Suite",
17584 		.setup = scheduler_testsuite_setup,
17585 		.teardown = testsuite_teardown,
17586 		.unit_test_cases = {TEST_CASES_END()}
17587 	};
17588 
17589 	gbl_driver_id =	rte_cryptodev_driver_id_get(
17590 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
17591 
17592 	if (gbl_driver_id == -1) {
17593 		RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
17594 		return TEST_SKIPPED;
17595 	}
17596 
17597 	if (rte_cryptodev_driver_id_get(
17598 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
17599 		RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
17600 		return TEST_SKIPPED;
17601 	}
17602 
17603 	for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
17604 		uint8_t blk_i = 0;
17605 		sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof
17606 				(struct unit_test_suite *) *
17607 				(RTE_DIM(blk_suites) +
17608 				RTE_DIM(sched_mode_static_suites) + 1));
17609 		ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]),
17610 				blk_suites, RTE_DIM(blk_suites));
17611 		ADD_STATIC_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]),
17612 				sched_mode_static_suites,
17613 				RTE_DIM(sched_mode_static_suites));
17614 		sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite;
17615 	}
17616 
17617 	ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
17618 			(RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites)));
17619 	ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites,
17620 			RTE_DIM(sched_mode_suites));
17621 	ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
17622 	ret = unit_test_suite_runner(&ts);
17623 
17624 	for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
17625 		FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx,
17626 				(*sched_mode_suites[sched_i]),
17627 				RTE_DIM(blk_suites));
17628 		free(sched_mode_suites[sched_i]->unit_test_suites);
17629 	}
17630 	free(ts.unit_test_suites);
17631 	return ret;
17632 }
17633 
17634 REGISTER_DRIVER_TEST(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
17635 
17636 #endif
17637 
17638 static int
17639 test_cryptodev_dpaa2_sec(void)
17640 {
17641 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
17642 }
17643 
17644 static int
17645 test_cryptodev_dpaa_sec(void)
17646 {
17647 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
17648 }
17649 
17650 static int
17651 test_cryptodev_ccp(void)
17652 {
17653 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD));
17654 }
17655 
17656 static int
17657 test_cryptodev_octeontx(void)
17658 {
17659 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
17660 }
17661 
17662 static int
17663 test_cryptodev_caam_jr(void)
17664 {
17665 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
17666 }
17667 
17668 static int
17669 test_cryptodev_nitrox(void)
17670 {
17671 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
17672 }
17673 
17674 static int
17675 test_cryptodev_bcmfs(void)
17676 {
17677 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
17678 }
17679 
17680 static int
17681 run_cryptodev_raw_testsuite(const char *pmd_name)
17682 {
17683 	int ret;
17684 
17685 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, "RAW API");
17686 	if (ret)
17687 		return ret;
17688 
17689 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
17690 	ret = run_cryptodev_testsuite(pmd_name);
17691 	global_api_test_type = CRYPTODEV_API_TEST;
17692 
17693 	return ret;
17694 }
17695 
17696 static int
17697 test_cryptodev_qat_raw_api(void)
17698 {
17699 	return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
17700 }
17701 
17702 static int
17703 test_cryptodev_cn9k(void)
17704 {
17705 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
17706 }
17707 
17708 static int
17709 test_cryptodev_cn10k(void)
17710 {
17711 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
17712 }
17713 
17714 static int
17715 test_cryptodev_cn10k_raw_api(void)
17716 {
17717 	return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
17718 }
17719 
17720 static int
17721 test_cryptodev_dpaa2_sec_raw_api(void)
17722 {
17723 	return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
17724 }
17725 
17726 static int
17727 test_cryptodev_dpaa_sec_raw_api(void)
17728 {
17729 	return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
17730 }
17731 
17732 REGISTER_TEST_COMMAND(cryptodev_cn10k_raw_api_autotest,
17733 		test_cryptodev_cn10k_raw_api);
17734 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_raw_api_autotest,
17735 		test_cryptodev_dpaa2_sec_raw_api);
17736 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_raw_api_autotest,
17737 		test_cryptodev_dpaa_sec_raw_api);
17738 REGISTER_DRIVER_TEST(cryptodev_qat_raw_api_autotest,
17739 		test_cryptodev_qat_raw_api);
17740 REGISTER_DRIVER_TEST(cryptodev_qat_autotest, test_cryptodev_qat);
17741 REGISTER_DRIVER_TEST(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
17742 REGISTER_DRIVER_TEST(cryptodev_cpu_aesni_mb_autotest,
17743 	test_cryptodev_cpu_aesni_mb);
17744 REGISTER_DRIVER_TEST(cryptodev_chacha_poly_mb_autotest,
17745 	test_cryptodev_chacha_poly_mb);
17746 REGISTER_DRIVER_TEST(cryptodev_openssl_autotest, test_cryptodev_openssl);
17747 REGISTER_DRIVER_TEST(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
17748 REGISTER_DRIVER_TEST(cryptodev_cpu_aesni_gcm_autotest,
17749 	test_cryptodev_cpu_aesni_gcm);
17750 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5);
17751 REGISTER_DRIVER_TEST(cryptodev_null_autotest, test_cryptodev_null);
17752 REGISTER_DRIVER_TEST(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
17753 REGISTER_DRIVER_TEST(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
17754 REGISTER_DRIVER_TEST(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
17755 REGISTER_DRIVER_TEST(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
17756 REGISTER_DRIVER_TEST(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
17757 REGISTER_DRIVER_TEST(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
17758 REGISTER_DRIVER_TEST(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
17759 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
17760 REGISTER_DRIVER_TEST(cryptodev_uadk_autotest, test_cryptodev_uadk);
17761 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
17762 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
17763 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
17764 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
17765 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);
17766 REGISTER_DRIVER_TEST(cryptodev_cn9k_autotest, test_cryptodev_cn9k);
17767 REGISTER_DRIVER_TEST(cryptodev_cn10k_autotest, test_cryptodev_cn10k);
17768