xref: /dpdk/app/test/test_cryptodev.c (revision a64571fd8ff6f1bff29b2beaeffd35fffd370b8b)
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_ethdev.h>
21 #include <rte_ip.h>
22 #include <rte_string_fns.h>
23 #include <rte_tcp.h>
24 #include <rte_tls.h>
25 #include <rte_udp.h>
26 
27 #ifdef RTE_CRYPTO_SCHEDULER
28 #include <rte_cryptodev_scheduler.h>
29 #include <rte_cryptodev_scheduler_operations.h>
30 #endif
31 
32 #include <rte_lcore.h>
33 
34 #include "test.h"
35 #include "test_cryptodev.h"
36 
37 #include "test_cryptodev_blockcipher.h"
38 #include "test_cryptodev_aes_test_vectors.h"
39 #include "test_cryptodev_des_test_vectors.h"
40 #include "test_cryptodev_hash_test_vectors.h"
41 #include "test_cryptodev_kasumi_test_vectors.h"
42 #include "test_cryptodev_kasumi_hash_test_vectors.h"
43 #include "test_cryptodev_snow3g_test_vectors.h"
44 #include "test_cryptodev_snow3g_hash_test_vectors.h"
45 #include "test_cryptodev_zuc_test_vectors.h"
46 #include "test_cryptodev_aead_test_vectors.h"
47 #include "test_cryptodev_hmac_test_vectors.h"
48 #include "test_cryptodev_mixed_test_vectors.h"
49 #include "test_cryptodev_sm4_test_vectors.h"
50 #ifdef RTE_LIB_SECURITY
51 #include "test_cryptodev_security_ipsec.h"
52 #include "test_cryptodev_security_ipsec_test_vectors.h"
53 #include "test_cryptodev_security_pdcp_test_vectors.h"
54 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h"
55 #include "test_cryptodev_security_pdcp_test_func.h"
56 #include "test_cryptodev_security_docsis_test_vectors.h"
57 #include "test_cryptodev_security_tls_record.h"
58 #include "test_security_proto.h"
59 
60 #define SDAP_DISABLED	0
61 #define SDAP_ENABLED	1
62 #endif
63 
64 #define VDEV_ARGS_SIZE 100
65 #define MAX_NB_SESSIONS 4
66 
67 #define MAX_DRV_SERVICE_CTX_SIZE 256
68 
69 #define MAX_RAW_DEQUEUE_COUNT	65535
70 
71 #define IN_PLACE 0
72 #define OUT_OF_PLACE 1
73 
74 static int gbl_driver_id;
75 
76 static enum rte_security_session_action_type gbl_action_type =
77 	RTE_SECURITY_ACTION_TYPE_NONE;
78 
79 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST;
80 
81 struct crypto_unittest_params {
82 	struct rte_crypto_sym_xform cipher_xform;
83 	struct rte_crypto_sym_xform auth_xform;
84 	struct rte_crypto_sym_xform aead_xform;
85 #ifdef RTE_LIB_SECURITY
86 	struct rte_security_docsis_xform docsis_xform;
87 #endif
88 
89 	union {
90 		void *sess;
91 #ifdef RTE_LIB_SECURITY
92 		void *sec_session;
93 #endif
94 	};
95 #ifdef RTE_LIB_SECURITY
96 	enum rte_security_session_action_type type;
97 #endif
98 	struct rte_crypto_op *op;
99 
100 	struct rte_mbuf *obuf, *ibuf;
101 
102 	uint8_t *digest;
103 };
104 
105 #define ALIGN_POW2_ROUNDUP(num, align) \
106 	(((num) + (align) - 1) & ~((align) - 1))
107 
108 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts)	\
109 	for (j = 0; j < num_child_ts; index++, j++)			\
110 		parent_ts.unit_test_suites[index] = child_ts[j]
111 
112 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types)	\
113 	for (j = 0; j < num_blk_types; index++, j++)				\
114 		parent_ts.unit_test_suites[index] =				\
115 				build_blockcipher_test_suite(blk_types[j])
116 
117 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types)		\
118 	for (j = index; j < index + num_blk_types; j++)				\
119 		free_blockcipher_test_suite(parent_ts.unit_test_suites[j])
120 
121 /*
122  * Forward declarations.
123  */
124 static int
125 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
126 		struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
127 		uint8_t *hmac_key);
128 
129 static int
130 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess,
131 		struct crypto_unittest_params *ut_params,
132 		struct crypto_testsuite_params *ts_param,
133 		const uint8_t *cipher,
134 		const uint8_t *digest,
135 		const uint8_t *iv);
136 
137 static int
138 security_proto_supported(enum rte_security_session_action_type action,
139 	enum rte_security_session_protocol proto);
140 
141 static int
142 dev_configure_and_start(uint64_t ff_disable);
143 
144 static int
145 check_cipher_capability(const struct crypto_testsuite_params *ts_params,
146 			const enum rte_crypto_cipher_algorithm cipher_algo,
147 			const uint16_t key_size, const uint16_t iv_size);
148 
149 static int
150 check_auth_capability(const struct crypto_testsuite_params *ts_params,
151 			const enum rte_crypto_auth_algorithm auth_algo,
152 			const uint16_t key_size, const uint16_t iv_size,
153 			const uint16_t tag_size);
154 
155 static struct rte_mbuf *
156 setup_test_string(struct rte_mempool *mpool,
157 		const char *string, size_t len, uint8_t blocksize)
158 {
159 	struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
160 	size_t t_len = len - (blocksize ? (len % blocksize) : 0);
161 
162 	if (m) {
163 		char *dst;
164 
165 		memset(m->buf_addr, 0, m->buf_len);
166 		dst = rte_pktmbuf_append(m, t_len);
167 		if (!dst) {
168 			rte_pktmbuf_free(m);
169 			return NULL;
170 		}
171 		if (string != NULL)
172 			rte_memcpy(dst, string, t_len);
173 		else
174 			memset(dst, 0, t_len);
175 	}
176 
177 	return m;
178 }
179 
180 /* Get number of bytes in X bits (rounding up) */
181 static uint32_t
182 ceil_byte_length(uint32_t num_bits)
183 {
184 	if (num_bits % 8)
185 		return ((num_bits >> 3) + 1);
186 	else
187 		return (num_bits >> 3);
188 }
189 
190 static void
191 post_process_raw_dp_op(void *user_data,	uint32_t index __rte_unused,
192 		uint8_t is_op_success)
193 {
194 	struct rte_crypto_op *op = user_data;
195 	op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS :
196 			RTE_CRYPTO_OP_STATUS_ERROR;
197 }
198 
199 static struct crypto_testsuite_params testsuite_params = { NULL };
200 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params;
201 static struct crypto_unittest_params unittest_params;
202 static bool enq_cb_called;
203 static bool deq_cb_called;
204 
205 int
206 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
207 		struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
208 		uint8_t len_in_bits, uint8_t cipher_iv_len)
209 {
210 	struct rte_crypto_sym_op *sop = op->sym;
211 	struct rte_crypto_op *ret_op = NULL;
212 	struct rte_crypto_vec data_vec[UINT8_MAX], dest_data_vec[UINT8_MAX];
213 	struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv;
214 	union rte_crypto_sym_ofs ofs;
215 	struct rte_crypto_sym_vec vec;
216 	struct rte_crypto_sgl sgl, dest_sgl;
217 	uint32_t max_len;
218 	union rte_cryptodev_session_ctx sess;
219 	uint64_t auth_end_iova;
220 	uint32_t count = 0;
221 	struct rte_crypto_raw_dp_ctx *ctx;
222 	uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0,
223 			auth_len = 0;
224 	int32_t n;
225 	uint32_t n_success;
226 	int ctx_service_size;
227 	int32_t status = 0;
228 	int enqueue_status, dequeue_status;
229 	struct crypto_unittest_params *ut_params = &unittest_params;
230 	int is_sgl = sop->m_src->nb_segs > 1;
231 	int ret = TEST_SUCCESS, is_oop = 0;
232 
233 	ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
234 	if (ctx_service_size < 0)
235 		return TEST_SKIPPED;
236 
237 	ctx = malloc(ctx_service_size);
238 	if (ctx == NULL)
239 		return TEST_FAILED;
240 
241 	/* Both are enums, setting crypto_sess will suit any session type */
242 	sess.crypto_sess = op->sym->session;
243 
244 	ret = rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx, op->sess_type, sess, 0);
245 	if (ret == -ENOTSUP) {
246 		ret = TEST_SKIPPED;
247 		goto exit;
248 	} else if (ret) {
249 		ret = TEST_FAILED;
250 		goto exit;
251 	}
252 
253 	cipher_iv.iova = 0;
254 	cipher_iv.va = NULL;
255 	aad_auth_iv.iova = 0;
256 	aad_auth_iv.va = NULL;
257 	digest.iova = 0;
258 	digest.va = NULL;
259 	sgl.vec = data_vec;
260 	vec.num = 1;
261 	vec.src_sgl = &sgl;
262 	vec.iv = &cipher_iv;
263 	vec.digest = &digest;
264 	vec.aad = &aad_auth_iv;
265 	vec.status = &status;
266 
267 	ofs.raw = 0;
268 
269 	if ((sop->m_dst != NULL) && (sop->m_dst != sop->m_src))
270 		is_oop = 1;
271 
272 	if (is_cipher && is_auth) {
273 		cipher_offset = sop->cipher.data.offset;
274 		cipher_len = sop->cipher.data.length;
275 		auth_offset = sop->auth.data.offset;
276 		auth_len = sop->auth.data.length;
277 		max_len = RTE_MAX(cipher_offset + cipher_len,
278 				auth_offset + auth_len);
279 		if (len_in_bits) {
280 			max_len = max_len >> 3;
281 			cipher_offset = cipher_offset >> 3;
282 			auth_offset = auth_offset >> 3;
283 			cipher_len = cipher_len >> 3;
284 			auth_len = auth_len >> 3;
285 		}
286 		ofs.ofs.cipher.head = cipher_offset;
287 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
288 		ofs.ofs.auth.head = auth_offset;
289 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
290 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
291 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
292 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
293 				op, void *, IV_OFFSET + cipher_iv_len);
294 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
295 				cipher_iv_len);
296 		digest.va = (void *)sop->auth.digest.data;
297 		digest.iova = sop->auth.digest.phys_addr;
298 
299 		if (is_sgl) {
300 			uint32_t remaining_off = auth_offset + auth_len;
301 			struct rte_mbuf *sgl_buf = sop->m_src;
302 			if (is_oop)
303 				sgl_buf = sop->m_dst;
304 
305 			while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)
306 					&& sgl_buf->next != NULL) {
307 				remaining_off -= rte_pktmbuf_data_len(sgl_buf);
308 				sgl_buf = sgl_buf->next;
309 			}
310 
311 			auth_end_iova = (uint64_t)rte_pktmbuf_iova_offset(
312 				sgl_buf, remaining_off);
313 		} else {
314 			auth_end_iova = rte_pktmbuf_iova(op->sym->m_src) +
315 							 auth_offset + auth_len;
316 		}
317 		/* Then check if digest-encrypted conditions are met */
318 		if ((auth_offset + auth_len < cipher_offset + cipher_len) &&
319 				(digest.iova == auth_end_iova) && is_sgl)
320 			max_len = RTE_MAX(max_len,
321 				auth_offset + auth_len +
322 				ut_params->auth_xform.auth.digest_length);
323 
324 	} else if (is_cipher) {
325 		cipher_offset = sop->cipher.data.offset;
326 		cipher_len = sop->cipher.data.length;
327 		max_len = cipher_len + cipher_offset;
328 		if (len_in_bits) {
329 			max_len = max_len >> 3;
330 			cipher_offset = cipher_offset >> 3;
331 			cipher_len = cipher_len >> 3;
332 		}
333 		ofs.ofs.cipher.head = cipher_offset;
334 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
335 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
336 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
337 
338 	} else if (is_auth) {
339 		auth_offset = sop->auth.data.offset;
340 		auth_len = sop->auth.data.length;
341 		max_len = auth_len + auth_offset;
342 		if (len_in_bits) {
343 			max_len = max_len >> 3;
344 			auth_offset = auth_offset >> 3;
345 			auth_len = auth_len >> 3;
346 		}
347 		ofs.ofs.auth.head = auth_offset;
348 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
349 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
350 				op, void *, IV_OFFSET + cipher_iv_len);
351 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
352 				cipher_iv_len);
353 		digest.va = (void *)sop->auth.digest.data;
354 		digest.iova = sop->auth.digest.phys_addr;
355 
356 	} else { /* aead */
357 		cipher_offset = sop->aead.data.offset;
358 		cipher_len = sop->aead.data.length;
359 		max_len = cipher_len + cipher_offset;
360 		if (len_in_bits) {
361 			max_len = max_len >> 3;
362 			cipher_offset = cipher_offset >> 3;
363 			cipher_len = cipher_len >> 3;
364 		}
365 		ofs.ofs.cipher.head = cipher_offset;
366 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
367 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
368 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
369 		aad_auth_iv.va = (void *)sop->aead.aad.data;
370 		aad_auth_iv.iova = sop->aead.aad.phys_addr;
371 		digest.va = (void *)sop->aead.digest.data;
372 		digest.iova = sop->aead.digest.phys_addr;
373 	}
374 
375 	n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
376 			data_vec, RTE_DIM(data_vec));
377 	if (n < 0 || n > sop->m_src->nb_segs) {
378 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
379 		goto exit;
380 	}
381 
382 	sgl.num = n;
383 	/* Out of place */
384 	if (is_oop) {
385 		dest_sgl.vec = dest_data_vec;
386 		vec.dest_sgl = &dest_sgl;
387 		n = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len,
388 				dest_data_vec, RTE_DIM(dest_data_vec));
389 		if (n < 0 || n > sop->m_dst->nb_segs) {
390 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
391 			goto exit;
392 		}
393 		dest_sgl.num = n;
394 	} else
395 		vec.dest_sgl = NULL;
396 
397 	if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op,
398 			&enqueue_status) < 1) {
399 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
400 		goto exit;
401 	}
402 
403 	if (enqueue_status == 0) {
404 		status = rte_cryptodev_raw_enqueue_done(ctx, 1);
405 		if (status < 0) {
406 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
407 			goto exit;
408 		}
409 	} else if (enqueue_status < 0) {
410 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
411 		goto exit;
412 	}
413 
414 	n = n_success = 0;
415 	while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) {
416 		n = rte_cryptodev_raw_dequeue_burst(ctx,
417 			NULL, 1, post_process_raw_dp_op,
418 				(void **)&ret_op, 0, &n_success,
419 				&dequeue_status);
420 		if (dequeue_status < 0) {
421 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
422 			goto exit;
423 		}
424 		if (n == 0)
425 			rte_pause();
426 	}
427 
428 	if (n == 1 && dequeue_status == 0) {
429 		if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) {
430 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
431 			goto exit;
432 		}
433 	}
434 
435 	op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op ||
436 			ret_op->status == RTE_CRYPTO_OP_STATUS_ERROR ||
437 			n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
438 					RTE_CRYPTO_OP_STATUS_SUCCESS;
439 
440 exit:
441 	free(ctx);
442 	return ret;
443 }
444 
445 static void
446 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
447 {
448 	int32_t n, st;
449 	struct rte_crypto_sym_op *sop;
450 	union rte_crypto_sym_ofs ofs;
451 	struct rte_crypto_sgl sgl;
452 	struct rte_crypto_sym_vec symvec;
453 	struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
454 	struct rte_crypto_vec vec[UINT8_MAX];
455 
456 	sop = op->sym;
457 
458 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
459 		sop->aead.data.length, vec, RTE_DIM(vec));
460 
461 	if (n < 0 || n != sop->m_src->nb_segs) {
462 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
463 		return;
464 	}
465 
466 	sgl.vec = vec;
467 	sgl.num = n;
468 	symvec.src_sgl = &sgl;
469 	symvec.iv = &iv_ptr;
470 	symvec.digest = &digest_ptr;
471 	symvec.aad = &aad_ptr;
472 	symvec.status = &st;
473 	symvec.num = 1;
474 
475 	/* for CPU crypto the IOVA address is not required */
476 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
477 	digest_ptr.va = (void *)sop->aead.digest.data;
478 	aad_ptr.va = (void *)sop->aead.aad.data;
479 
480 	ofs.raw = 0;
481 
482 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
483 		&symvec);
484 
485 	if (n != 1)
486 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
487 	else
488 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
489 }
490 
491 static void
492 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
493 {
494 	int32_t n, st;
495 	struct rte_crypto_sym_op *sop;
496 	union rte_crypto_sym_ofs ofs;
497 	struct rte_crypto_sgl sgl;
498 	struct rte_crypto_sym_vec symvec;
499 	struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
500 	struct rte_crypto_vec vec[UINT8_MAX];
501 
502 	sop = op->sym;
503 
504 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
505 		sop->auth.data.length, vec, RTE_DIM(vec));
506 
507 	if (n < 0 || n != sop->m_src->nb_segs) {
508 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
509 		return;
510 	}
511 
512 	sgl.vec = vec;
513 	sgl.num = n;
514 	symvec.src_sgl = &sgl;
515 	symvec.iv = &iv_ptr;
516 	symvec.digest = &digest_ptr;
517 	symvec.status = &st;
518 	symvec.num = 1;
519 
520 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
521 	digest_ptr.va = (void *)sop->auth.digest.data;
522 
523 	ofs.raw = 0;
524 	ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
525 	ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
526 		(sop->cipher.data.offset + sop->cipher.data.length);
527 
528 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
529 		&symvec);
530 
531 	if (n != 1)
532 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
533 	else
534 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
535 }
536 
537 static struct rte_crypto_op *
538 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
539 {
540 
541 	RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
542 
543 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
544 		RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
545 		return NULL;
546 	}
547 
548 	op = NULL;
549 
550 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
551 		rte_pause();
552 
553 	if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
554 		RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
555 		return NULL;
556 	}
557 
558 	return op;
559 }
560 
561 static int
562 testsuite_setup(void)
563 {
564 	struct crypto_testsuite_params *ts_params = &testsuite_params;
565 	struct rte_cryptodev_info info;
566 	uint32_t i = 0, nb_devs, dev_id;
567 	uint16_t qp_id;
568 
569 	memset(ts_params, 0, sizeof(*ts_params));
570 
571 	ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
572 	if (ts_params->mbuf_pool == NULL) {
573 		/* Not already created so create */
574 		ts_params->mbuf_pool = rte_pktmbuf_pool_create(
575 				"CRYPTO_MBUFPOOL",
576 				NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
577 				rte_socket_id());
578 		if (ts_params->mbuf_pool == NULL) {
579 			RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
580 			return TEST_FAILED;
581 		}
582 	}
583 
584 	ts_params->large_mbuf_pool = rte_mempool_lookup(
585 			"CRYPTO_LARGE_MBUFPOOL");
586 	if (ts_params->large_mbuf_pool == NULL) {
587 		/* Not already created so create */
588 		ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
589 				"CRYPTO_LARGE_MBUFPOOL",
590 				1, 0, 0, UINT16_MAX,
591 				rte_socket_id());
592 		if (ts_params->large_mbuf_pool == NULL) {
593 			RTE_LOG(ERR, USER1,
594 				"Can't create CRYPTO_LARGE_MBUFPOOL\n");
595 			return TEST_FAILED;
596 		}
597 	}
598 
599 	ts_params->op_mpool = rte_crypto_op_pool_create(
600 			"MBUF_CRYPTO_SYM_OP_POOL",
601 			RTE_CRYPTO_OP_TYPE_SYMMETRIC,
602 			NUM_MBUFS, MBUF_CACHE_SIZE,
603 			DEFAULT_NUM_XFORMS *
604 			sizeof(struct rte_crypto_sym_xform) +
605 			MAXIMUM_IV_LENGTH,
606 			rte_socket_id());
607 	if (ts_params->op_mpool == NULL) {
608 		RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
609 		return TEST_FAILED;
610 	}
611 
612 	nb_devs = rte_cryptodev_count();
613 	if (nb_devs < 1) {
614 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
615 		return TEST_SKIPPED;
616 	}
617 
618 	if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) {
619 		RTE_LOG(WARNING, USER1, "No %s devices found?\n",
620 				rte_cryptodev_driver_name_get(gbl_driver_id));
621 		return TEST_SKIPPED;
622 	}
623 
624 	/* Create list of valid crypto devs */
625 	for (i = 0; i < nb_devs; i++) {
626 		rte_cryptodev_info_get(i, &info);
627 		if (info.driver_id == gbl_driver_id)
628 			ts_params->valid_devs[ts_params->valid_dev_count++] = i;
629 	}
630 
631 	if (ts_params->valid_dev_count < 1)
632 		return TEST_FAILED;
633 
634 	/* Set up all the qps on the first of the valid devices found */
635 
636 	dev_id = ts_params->valid_devs[0];
637 
638 	rte_cryptodev_info_get(dev_id, &info);
639 
640 	ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
641 	ts_params->conf.socket_id = SOCKET_ID_ANY;
642 	ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
643 
644 	unsigned int session_size =
645 		rte_cryptodev_sym_get_private_session_size(dev_id);
646 
647 #ifdef RTE_LIB_SECURITY
648 	unsigned int security_session_size = rte_security_session_get_size(
649 			rte_cryptodev_get_sec_ctx(dev_id));
650 
651 	if (session_size < security_session_size)
652 		session_size = security_session_size;
653 #endif
654 	/*
655 	 * Create mempool with maximum number of sessions.
656 	 */
657 	if (info.sym.max_nb_sessions != 0 &&
658 			info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
659 		RTE_LOG(ERR, USER1, "Device does not support "
660 				"at least %u sessions\n",
661 				MAX_NB_SESSIONS);
662 		return TEST_FAILED;
663 	}
664 
665 	ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
666 			"test_sess_mp", MAX_NB_SESSIONS, session_size, 0, 0,
667 			SOCKET_ID_ANY);
668 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
669 			"session mempool allocation failed");
670 
671 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
672 			&ts_params->conf),
673 			"Failed to configure cryptodev %u with %u qps",
674 			dev_id, ts_params->conf.nb_queue_pairs);
675 
676 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
677 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
678 
679 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
680 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
681 			dev_id, qp_id, &ts_params->qp_conf,
682 			rte_cryptodev_socket_id(dev_id)),
683 			"Failed to setup queue pair %u on cryptodev %u",
684 			qp_id, dev_id);
685 	}
686 
687 	return TEST_SUCCESS;
688 }
689 
690 static void
691 testsuite_teardown(void)
692 {
693 	struct crypto_testsuite_params *ts_params = &testsuite_params;
694 	int res;
695 
696 	if (ts_params->mbuf_pool != NULL) {
697 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
698 		rte_mempool_avail_count(ts_params->mbuf_pool));
699 	}
700 
701 	if (ts_params->op_mpool != NULL) {
702 		RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
703 		rte_mempool_avail_count(ts_params->op_mpool));
704 	}
705 
706 	if (ts_params->session_mpool != NULL) {
707 		rte_mempool_free(ts_params->session_mpool);
708 		ts_params->session_mpool = NULL;
709 	}
710 
711 	res = rte_cryptodev_close(ts_params->valid_devs[0]);
712 	if (res)
713 		RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res);
714 }
715 
716 static int
717 check_capabilities_supported(enum rte_crypto_sym_xform_type type,
718 		const int *algs, uint16_t num_algs)
719 {
720 	uint8_t dev_id = testsuite_params.valid_devs[0];
721 	bool some_alg_supported = FALSE;
722 	uint16_t i;
723 
724 	for (i = 0; i < num_algs && !some_alg_supported; i++) {
725 		struct rte_cryptodev_sym_capability_idx alg = {
726 			type, {algs[i]}
727 		};
728 		if (rte_cryptodev_sym_capability_get(dev_id,
729 				&alg) != NULL)
730 			some_alg_supported = TRUE;
731 	}
732 	if (!some_alg_supported)
733 		return TEST_SKIPPED;
734 
735 	return 0;
736 }
737 
738 int
739 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
740 		uint16_t num_ciphers)
741 {
742 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER,
743 			(const int *) ciphers, num_ciphers);
744 }
745 
746 int
747 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
748 		uint16_t num_auths)
749 {
750 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH,
751 			(const int *) auths, num_auths);
752 }
753 
754 int
755 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
756 		uint16_t num_aeads)
757 {
758 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD,
759 			(const int *) aeads, num_aeads);
760 }
761 
762 static int
763 null_testsuite_setup(void)
764 {
765 	struct crypto_testsuite_params *ts_params = &testsuite_params;
766 	uint8_t dev_id = ts_params->valid_devs[0];
767 	struct rte_cryptodev_info dev_info;
768 	const enum rte_crypto_cipher_algorithm ciphers[] = {
769 		RTE_CRYPTO_CIPHER_NULL
770 	};
771 	const enum rte_crypto_auth_algorithm auths[] = {
772 		RTE_CRYPTO_AUTH_NULL
773 	};
774 
775 	rte_cryptodev_info_get(dev_id, &dev_info);
776 
777 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
778 		RTE_LOG(INFO, USER1, "Feature flag requirements for NULL "
779 				"testsuite not met\n");
780 		return TEST_SKIPPED;
781 	}
782 
783 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
784 			&& check_auth_capabilities_supported(auths,
785 			RTE_DIM(auths)) != 0) {
786 		RTE_LOG(INFO, USER1, "Capability requirements for NULL "
787 				"testsuite not met\n");
788 		return TEST_SKIPPED;
789 	}
790 
791 	return 0;
792 }
793 
794 static int
795 crypto_gen_testsuite_setup(void)
796 {
797 	struct crypto_testsuite_params *ts_params = &testsuite_params;
798 	uint8_t dev_id = ts_params->valid_devs[0];
799 	struct rte_cryptodev_info dev_info;
800 
801 	rte_cryptodev_info_get(dev_id, &dev_info);
802 
803 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
804 		RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen "
805 				"testsuite not met\n");
806 		return TEST_SKIPPED;
807 	}
808 
809 	return 0;
810 }
811 
812 #ifdef RTE_LIB_SECURITY
813 static int
814 sec_proto_testsuite_setup(enum rte_security_session_protocol protocol)
815 {
816 	struct crypto_testsuite_params *ts_params = &testsuite_params;
817 	struct crypto_unittest_params *ut_params = &unittest_params;
818 	struct rte_cryptodev_info dev_info;
819 	int ret = 0;
820 
821 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
822 
823 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) {
824 		RTE_LOG(INFO, USER1,
825 			"Feature flag requirements for security protocol testsuite not met\n");
826 		return TEST_SKIPPED;
827 	}
828 
829 	/* Reconfigure to enable security */
830 	ret = dev_configure_and_start(0);
831 	if (ret != TEST_SUCCESS)
832 		return ret;
833 
834 	/* Set action type */
835 	ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
836 
837 	if (security_proto_supported(RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, protocol) < 0) {
838 		RTE_LOG(INFO, USER1,
839 			"Capability requirements for security protocol test not met\n");
840 		ret = TEST_SKIPPED;
841 	}
842 
843 	test_sec_alg_list_populate();
844 	test_sec_auth_only_alg_list_populate();
845 
846 	/*
847 	 * Stop the device. Device would be started again by individual test
848 	 * case setup routine.
849 	 */
850 	rte_cryptodev_stop(ts_params->valid_devs[0]);
851 
852 	return ret;
853 }
854 
855 static int
856 ipsec_proto_testsuite_setup(void)
857 {
858 	return sec_proto_testsuite_setup(RTE_SECURITY_PROTOCOL_IPSEC);
859 }
860 
861 static int
862 tls_record_proto_testsuite_setup(void)
863 {
864 	test_sec_proto_pattern_generate();
865 
866 	return sec_proto_testsuite_setup(RTE_SECURITY_PROTOCOL_TLS_RECORD);
867 }
868 
869 static int
870 pdcp_proto_testsuite_setup(void)
871 {
872 	struct crypto_testsuite_params *ts_params = &testsuite_params;
873 	uint8_t dev_id = ts_params->valid_devs[0];
874 	struct rte_cryptodev_info dev_info;
875 	const enum rte_crypto_cipher_algorithm ciphers[] = {
876 		RTE_CRYPTO_CIPHER_NULL,
877 		RTE_CRYPTO_CIPHER_AES_CTR,
878 		RTE_CRYPTO_CIPHER_ZUC_EEA3,
879 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
880 	};
881 	const enum rte_crypto_auth_algorithm auths[] = {
882 		RTE_CRYPTO_AUTH_NULL,
883 		RTE_CRYPTO_AUTH_SNOW3G_UIA2,
884 		RTE_CRYPTO_AUTH_AES_CMAC,
885 		RTE_CRYPTO_AUTH_ZUC_EIA3
886 	};
887 
888 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_auth_key));
889 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_bearer));
890 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_crypto_key));
891 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_in));
892 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_in_len));
893 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_out));
894 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_sn_size));
895 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_hfn));
896 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_hfn_threshold));
897 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_packet_direction));
898 
899 	rte_cryptodev_info_get(dev_id, &dev_info);
900 
901 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
902 			!(dev_info.feature_flags &
903 			RTE_CRYPTODEV_FF_SECURITY)) {
904 		RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto "
905 				"testsuite not met\n");
906 		return TEST_SKIPPED;
907 	}
908 
909 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
910 			&& check_auth_capabilities_supported(auths,
911 			RTE_DIM(auths)) != 0) {
912 		RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto "
913 				"testsuite not met\n");
914 		return TEST_SKIPPED;
915 	}
916 
917 	return 0;
918 }
919 
920 static int
921 docsis_proto_testsuite_setup(void)
922 {
923 	struct crypto_testsuite_params *ts_params = &testsuite_params;
924 	uint8_t dev_id = ts_params->valid_devs[0];
925 	struct rte_cryptodev_info dev_info;
926 	const enum rte_crypto_cipher_algorithm ciphers[] = {
927 		RTE_CRYPTO_CIPHER_AES_DOCSISBPI
928 	};
929 
930 	rte_cryptodev_info_get(dev_id, &dev_info);
931 
932 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
933 			!(dev_info.feature_flags &
934 			RTE_CRYPTODEV_FF_SECURITY)) {
935 		RTE_LOG(INFO, USER1, "Feature flag requirements for DOCSIS "
936 				"Proto testsuite not met\n");
937 		return TEST_SKIPPED;
938 	}
939 
940 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
941 		RTE_LOG(INFO, USER1, "Capability requirements for DOCSIS Proto "
942 				"testsuite not met\n");
943 		return TEST_SKIPPED;
944 	}
945 
946 	return 0;
947 }
948 #endif
949 
950 static int
951 aes_ccm_auth_testsuite_setup(void)
952 {
953 	struct crypto_testsuite_params *ts_params = &testsuite_params;
954 	uint8_t dev_id = ts_params->valid_devs[0];
955 	struct rte_cryptodev_info dev_info;
956 	const enum rte_crypto_aead_algorithm aeads[] = {
957 		RTE_CRYPTO_AEAD_AES_CCM
958 	};
959 
960 	rte_cryptodev_info_get(dev_id, &dev_info);
961 
962 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
963 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
964 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
965 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM "
966 				"testsuite not met\n");
967 		return TEST_SKIPPED;
968 	}
969 
970 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
971 		RTE_LOG(INFO, USER1, "Capability requirements for AES CCM "
972 				"testsuite not met\n");
973 		return TEST_SKIPPED;
974 	}
975 
976 	return 0;
977 }
978 
979 static int
980 aes_gcm_auth_testsuite_setup(void)
981 {
982 	struct crypto_testsuite_params *ts_params = &testsuite_params;
983 	uint8_t dev_id = ts_params->valid_devs[0];
984 	struct rte_cryptodev_info dev_info;
985 	const enum rte_crypto_aead_algorithm aeads[] = {
986 		RTE_CRYPTO_AEAD_AES_GCM
987 	};
988 
989 	rte_cryptodev_info_get(dev_id, &dev_info);
990 
991 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
992 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM "
993 				"testsuite not met\n");
994 		return TEST_SKIPPED;
995 	}
996 
997 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
998 		RTE_LOG(INFO, USER1, "Capability requirements for AES GCM "
999 				"testsuite not met\n");
1000 		return TEST_SKIPPED;
1001 	}
1002 
1003 	return 0;
1004 }
1005 
1006 static int
1007 aes_gmac_auth_testsuite_setup(void)
1008 {
1009 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1010 	uint8_t dev_id = ts_params->valid_devs[0];
1011 	struct rte_cryptodev_info dev_info;
1012 	const enum rte_crypto_auth_algorithm auths[] = {
1013 		RTE_CRYPTO_AUTH_AES_GMAC
1014 	};
1015 
1016 	rte_cryptodev_info_get(dev_id, &dev_info);
1017 
1018 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1019 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1020 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1021 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC "
1022 				"testsuite not met\n");
1023 		return TEST_SKIPPED;
1024 	}
1025 
1026 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1027 		RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC "
1028 				"testsuite not met\n");
1029 		return TEST_SKIPPED;
1030 	}
1031 
1032 	return 0;
1033 }
1034 
1035 static int
1036 chacha20_poly1305_testsuite_setup(void)
1037 {
1038 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1039 	uint8_t dev_id = ts_params->valid_devs[0];
1040 	struct rte_cryptodev_info dev_info;
1041 	const enum rte_crypto_aead_algorithm aeads[] = {
1042 		RTE_CRYPTO_AEAD_CHACHA20_POLY1305
1043 	};
1044 
1045 	rte_cryptodev_info_get(dev_id, &dev_info);
1046 
1047 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1048 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1049 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1050 		RTE_LOG(INFO, USER1, "Feature flag requirements for "
1051 				"Chacha20-Poly1305 testsuite not met\n");
1052 		return TEST_SKIPPED;
1053 	}
1054 
1055 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1056 		RTE_LOG(INFO, USER1, "Capability requirements for "
1057 				"Chacha20-Poly1305 testsuite not met\n");
1058 		return TEST_SKIPPED;
1059 	}
1060 
1061 	return 0;
1062 }
1063 
1064 static int
1065 snow3g_testsuite_setup(void)
1066 {
1067 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1068 	uint8_t dev_id = ts_params->valid_devs[0];
1069 	struct rte_cryptodev_info dev_info;
1070 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1071 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1072 
1073 	};
1074 	const enum rte_crypto_auth_algorithm auths[] = {
1075 		RTE_CRYPTO_AUTH_SNOW3G_UIA2
1076 	};
1077 
1078 	rte_cryptodev_info_get(dev_id, &dev_info);
1079 
1080 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1081 		RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G "
1082 				"testsuite not met\n");
1083 		return TEST_SKIPPED;
1084 	}
1085 
1086 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1087 			&& check_auth_capabilities_supported(auths,
1088 			RTE_DIM(auths)) != 0) {
1089 		RTE_LOG(INFO, USER1, "Capability requirements for Snow3G "
1090 				"testsuite not met\n");
1091 		return TEST_SKIPPED;
1092 	}
1093 
1094 	return 0;
1095 }
1096 
1097 static int
1098 zuc_testsuite_setup(void)
1099 {
1100 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1101 	uint8_t dev_id = ts_params->valid_devs[0];
1102 	struct rte_cryptodev_info dev_info;
1103 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1104 		RTE_CRYPTO_CIPHER_ZUC_EEA3
1105 	};
1106 	const enum rte_crypto_auth_algorithm auths[] = {
1107 		RTE_CRYPTO_AUTH_ZUC_EIA3
1108 	};
1109 
1110 	rte_cryptodev_info_get(dev_id, &dev_info);
1111 
1112 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1113 		RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC "
1114 				"testsuite not met\n");
1115 		return TEST_SKIPPED;
1116 	}
1117 
1118 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1119 			&& check_auth_capabilities_supported(auths,
1120 			RTE_DIM(auths)) != 0) {
1121 		RTE_LOG(INFO, USER1, "Capability requirements for ZUC "
1122 				"testsuite not met\n");
1123 		return TEST_SKIPPED;
1124 	}
1125 
1126 	return 0;
1127 }
1128 
1129 static int
1130 hmac_md5_auth_testsuite_setup(void)
1131 {
1132 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1133 	uint8_t dev_id = ts_params->valid_devs[0];
1134 	struct rte_cryptodev_info dev_info;
1135 	const enum rte_crypto_auth_algorithm auths[] = {
1136 		RTE_CRYPTO_AUTH_MD5_HMAC
1137 	};
1138 
1139 	rte_cryptodev_info_get(dev_id, &dev_info);
1140 
1141 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1142 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1143 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1144 		RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 "
1145 				"Auth testsuite not met\n");
1146 		return TEST_SKIPPED;
1147 	}
1148 
1149 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1150 		RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 "
1151 				"testsuite not met\n");
1152 		return TEST_SKIPPED;
1153 	}
1154 
1155 	return 0;
1156 }
1157 
1158 static int
1159 kasumi_testsuite_setup(void)
1160 {
1161 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1162 	uint8_t dev_id = ts_params->valid_devs[0];
1163 	struct rte_cryptodev_info dev_info;
1164 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1165 		RTE_CRYPTO_CIPHER_KASUMI_F8
1166 	};
1167 	const enum rte_crypto_auth_algorithm auths[] = {
1168 		RTE_CRYPTO_AUTH_KASUMI_F9
1169 	};
1170 
1171 	rte_cryptodev_info_get(dev_id, &dev_info);
1172 
1173 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1174 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1175 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1176 		RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi "
1177 				"testsuite not met\n");
1178 		return TEST_SKIPPED;
1179 	}
1180 
1181 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1182 			&& check_auth_capabilities_supported(auths,
1183 			RTE_DIM(auths)) != 0) {
1184 		RTE_LOG(INFO, USER1, "Capability requirements for Kasumi "
1185 				"testsuite not met\n");
1186 		return TEST_SKIPPED;
1187 	}
1188 
1189 	return 0;
1190 }
1191 
1192 static int
1193 negative_aes_gcm_testsuite_setup(void)
1194 {
1195 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1196 	uint8_t dev_id = ts_params->valid_devs[0];
1197 	struct rte_cryptodev_info dev_info;
1198 	const enum rte_crypto_aead_algorithm aeads[] = {
1199 		RTE_CRYPTO_AEAD_AES_GCM
1200 	};
1201 
1202 	rte_cryptodev_info_get(dev_id, &dev_info);
1203 
1204 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1205 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1206 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1207 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1208 				"AES GCM testsuite not met\n");
1209 		return TEST_SKIPPED;
1210 	}
1211 
1212 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1213 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1214 				"AES GCM testsuite not met\n");
1215 		return TEST_SKIPPED;
1216 	}
1217 
1218 	return 0;
1219 }
1220 
1221 static int
1222 negative_aes_gmac_testsuite_setup(void)
1223 {
1224 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1225 	uint8_t dev_id = ts_params->valid_devs[0];
1226 	struct rte_cryptodev_info dev_info;
1227 	const enum rte_crypto_auth_algorithm auths[] = {
1228 		RTE_CRYPTO_AUTH_AES_GMAC
1229 	};
1230 
1231 	rte_cryptodev_info_get(dev_id, &dev_info);
1232 
1233 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1234 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1235 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1236 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1237 				"AES GMAC testsuite not met\n");
1238 		return TEST_SKIPPED;
1239 	}
1240 
1241 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1242 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1243 				"AES GMAC testsuite not met\n");
1244 		return TEST_SKIPPED;
1245 	}
1246 
1247 	return 0;
1248 }
1249 
1250 static int
1251 mixed_cipher_hash_testsuite_setup(void)
1252 {
1253 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1254 	uint8_t dev_id = ts_params->valid_devs[0];
1255 	struct rte_cryptodev_info dev_info;
1256 	uint64_t feat_flags;
1257 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1258 		RTE_CRYPTO_CIPHER_NULL,
1259 		RTE_CRYPTO_CIPHER_AES_CTR,
1260 		RTE_CRYPTO_CIPHER_ZUC_EEA3,
1261 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1262 	};
1263 	const enum rte_crypto_auth_algorithm auths[] = {
1264 		RTE_CRYPTO_AUTH_NULL,
1265 		RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1266 		RTE_CRYPTO_AUTH_AES_CMAC,
1267 		RTE_CRYPTO_AUTH_ZUC_EIA3
1268 	};
1269 
1270 	rte_cryptodev_info_get(dev_id, &dev_info);
1271 	feat_flags = dev_info.feature_flags;
1272 
1273 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1274 			(global_api_test_type == CRYPTODEV_RAW_API_TEST)) {
1275 		RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed "
1276 				"Cipher Hash testsuite not met\n");
1277 		return TEST_SKIPPED;
1278 	}
1279 
1280 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1281 			&& check_auth_capabilities_supported(auths,
1282 			RTE_DIM(auths)) != 0) {
1283 		RTE_LOG(INFO, USER1, "Capability requirements for Mixed "
1284 				"Cipher Hash testsuite not met\n");
1285 		return TEST_SKIPPED;
1286 	}
1287 
1288 	return 0;
1289 }
1290 
1291 static int
1292 esn_testsuite_setup(void)
1293 {
1294 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1295 	uint8_t dev_id = ts_params->valid_devs[0];
1296 	struct rte_cryptodev_info dev_info;
1297 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1298 		RTE_CRYPTO_CIPHER_AES_CBC
1299 	};
1300 	const enum rte_crypto_auth_algorithm auths[] = {
1301 		RTE_CRYPTO_AUTH_SHA1_HMAC
1302 	};
1303 
1304 	rte_cryptodev_info_get(dev_id, &dev_info);
1305 
1306 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1307 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1308 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1309 		RTE_LOG(INFO, USER1, "Feature flag requirements for ESN "
1310 				"testsuite not met\n");
1311 		return TEST_SKIPPED;
1312 	}
1313 
1314 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1315 			&& check_auth_capabilities_supported(auths,
1316 			RTE_DIM(auths)) != 0) {
1317 		RTE_LOG(INFO, USER1, "Capability requirements for ESN "
1318 				"testsuite not met\n");
1319 		return TEST_SKIPPED;
1320 	}
1321 
1322 	return 0;
1323 }
1324 
1325 static int
1326 multi_session_testsuite_setup(void)
1327 {
1328 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1329 	uint8_t dev_id = ts_params->valid_devs[0];
1330 	struct rte_cryptodev_info dev_info;
1331 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1332 		RTE_CRYPTO_CIPHER_AES_CBC
1333 	};
1334 	const enum rte_crypto_auth_algorithm auths[] = {
1335 		RTE_CRYPTO_AUTH_SHA512_HMAC
1336 	};
1337 
1338 	rte_cryptodev_info_get(dev_id, &dev_info);
1339 
1340 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1341 		RTE_LOG(INFO, USER1, "Feature flag requirements for Multi "
1342 				"Session testsuite not met\n");
1343 		return TEST_SKIPPED;
1344 	}
1345 
1346 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1347 			&& check_auth_capabilities_supported(auths,
1348 			RTE_DIM(auths)) != 0) {
1349 		RTE_LOG(INFO, USER1, "Capability requirements for Multi "
1350 				"Session testsuite not met\n");
1351 		return TEST_SKIPPED;
1352 	}
1353 
1354 	return 0;
1355 }
1356 
1357 static int
1358 negative_hmac_sha1_testsuite_setup(void)
1359 {
1360 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1361 	uint8_t dev_id = ts_params->valid_devs[0];
1362 	struct rte_cryptodev_info dev_info;
1363 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1364 		RTE_CRYPTO_CIPHER_AES_CBC
1365 	};
1366 	const enum rte_crypto_auth_algorithm auths[] = {
1367 		RTE_CRYPTO_AUTH_SHA1_HMAC
1368 	};
1369 
1370 	rte_cryptodev_info_get(dev_id, &dev_info);
1371 
1372 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1373 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1374 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1375 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1376 				"HMAC SHA1 testsuite not met\n");
1377 		return TEST_SKIPPED;
1378 	}
1379 
1380 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1381 			&& check_auth_capabilities_supported(auths,
1382 			RTE_DIM(auths)) != 0) {
1383 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1384 				"HMAC SHA1 testsuite not met\n");
1385 		return TEST_SKIPPED;
1386 	}
1387 
1388 	return 0;
1389 }
1390 
1391 static int
1392 dev_configure_and_start(uint64_t ff_disable)
1393 {
1394 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1395 	struct crypto_unittest_params *ut_params = &unittest_params;
1396 
1397 	uint16_t qp_id;
1398 
1399 	/* Clear unit test parameters before running test */
1400 	memset(ut_params, 0, sizeof(*ut_params));
1401 
1402 	/* Reconfigure device to default parameters */
1403 	ts_params->conf.socket_id = SOCKET_ID_ANY;
1404 	ts_params->conf.ff_disable = ff_disable;
1405 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
1406 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
1407 
1408 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1409 			&ts_params->conf),
1410 			"Failed to configure cryptodev %u",
1411 			ts_params->valid_devs[0]);
1412 
1413 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
1414 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1415 			ts_params->valid_devs[0], qp_id,
1416 			&ts_params->qp_conf,
1417 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1418 			"Failed to setup queue pair %u on cryptodev %u",
1419 			qp_id, ts_params->valid_devs[0]);
1420 	}
1421 
1422 
1423 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1424 
1425 	/* Start the device */
1426 	TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1427 			"Failed to start cryptodev %u",
1428 			ts_params->valid_devs[0]);
1429 
1430 	return TEST_SUCCESS;
1431 }
1432 
1433 int
1434 ut_setup(void)
1435 {
1436 	/* Configure and start the device with security feature disabled */
1437 	return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
1438 }
1439 
1440 static int
1441 ut_setup_security(void)
1442 {
1443 	/* Configure and start the device with no features disabled */
1444 	return dev_configure_and_start(0);
1445 }
1446 
1447 static int
1448 ut_setup_security_rx_inject(void)
1449 {
1450 	struct rte_mempool *mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
1451 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1452 	struct rte_eth_conf port_conf = {
1453 		.rxmode = {
1454 			.offloads = RTE_ETH_RX_OFFLOAD_CHECKSUM |
1455 				    RTE_ETH_RX_OFFLOAD_SECURITY,
1456 		},
1457 		.txmode = {
1458 			.offloads = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE,
1459 		},
1460 		.lpbk_mode = 1,  /* Enable loopback */
1461 	};
1462 	struct rte_cryptodev_info dev_info;
1463 	struct rte_eth_rxconf rx_conf = {
1464 		.rx_thresh = {
1465 			.pthresh = 8,
1466 			.hthresh = 8,
1467 			.wthresh = 8,
1468 		},
1469 		.rx_free_thresh = 32,
1470 	};
1471 	uint16_t nb_ports;
1472 	void *sec_ctx;
1473 	int ret;
1474 
1475 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
1476 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY_RX_INJECT) ||
1477 	    !(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) {
1478 		RTE_LOG(INFO, USER1,
1479 			"Feature requirements for IPsec Rx inject test case not met\n");
1480 		return TEST_SKIPPED;
1481 	}
1482 
1483 	sec_ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]);
1484 	if (sec_ctx == NULL)
1485 		return TEST_SKIPPED;
1486 
1487 	nb_ports = rte_eth_dev_count_avail();
1488 	if (nb_ports == 0)
1489 		return TEST_SKIPPED;
1490 
1491 	ret = rte_eth_dev_configure(0 /* port_id */,
1492 				    1 /* nb_rx_queue */,
1493 				    0 /* nb_tx_queue */,
1494 				    &port_conf);
1495 	if (ret) {
1496 		printf("Could not configure ethdev port 0 [err=%d]\n", ret);
1497 		return TEST_SKIPPED;
1498 	}
1499 
1500 	/* Rx queue setup */
1501 	ret = rte_eth_rx_queue_setup(0 /* port_id */,
1502 				     0 /* rx_queue_id */,
1503 				     1024 /* nb_rx_desc */,
1504 				     SOCKET_ID_ANY,
1505 				     &rx_conf,
1506 				     mbuf_pool);
1507 	if (ret) {
1508 		printf("Could not setup eth port 0 queue 0\n");
1509 		return TEST_SKIPPED;
1510 	}
1511 
1512 	ret = rte_security_rx_inject_configure(sec_ctx, 0, true);
1513 	if (ret) {
1514 		printf("Could not enable Rx inject offload");
1515 		return TEST_SKIPPED;
1516 	}
1517 
1518 	ret = rte_eth_dev_start(0);
1519 	if (ret) {
1520 		printf("Could not start ethdev");
1521 		return TEST_SKIPPED;
1522 	}
1523 
1524 	ret = rte_eth_promiscuous_enable(0);
1525 	if (ret) {
1526 		printf("Could not enable promiscuous mode");
1527 		return TEST_SKIPPED;
1528 	}
1529 
1530 	/* Configure and start cryptodev with no features disabled */
1531 	return dev_configure_and_start(0);
1532 }
1533 
1534 static inline void
1535 ext_mbuf_callback_fn_free(void *addr __rte_unused, void *opaque __rte_unused)
1536 {
1537 }
1538 
1539 static inline void
1540 ext_mbuf_memzone_free(int nb_segs)
1541 {
1542 	int i;
1543 
1544 	for (i = 0; i <= nb_segs; i++) {
1545 		char mz_name[RTE_MEMZONE_NAMESIZE];
1546 		const struct rte_memzone *memzone;
1547 		snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "ext_buf_%d", i);
1548 		memzone = rte_memzone_lookup(mz_name);
1549 		if (memzone != NULL) {
1550 			rte_memzone_free(memzone);
1551 			memzone = NULL;
1552 		}
1553 	}
1554 }
1555 
1556 static inline struct rte_mbuf *
1557 ext_mbuf_create(struct rte_mempool *mbuf_pool, int pkt_len,
1558 		int nb_segs, const void *input_text)
1559 {
1560 	struct rte_mbuf *m = NULL, *mbuf = NULL;
1561 	size_t data_off = 0;
1562 	uint8_t *dst;
1563 	int i, size;
1564 	int t_len;
1565 
1566 	if (pkt_len < 1) {
1567 		printf("Packet size must be 1 or more (is %d)\n", pkt_len);
1568 		return NULL;
1569 	}
1570 
1571 	if (nb_segs < 1) {
1572 		printf("Number of segments must be 1 or more (is %d)\n",
1573 				nb_segs);
1574 		return NULL;
1575 	}
1576 
1577 	t_len = pkt_len >= nb_segs ? pkt_len / nb_segs : 1;
1578 	size = pkt_len;
1579 
1580 	/* Create chained mbuf_src with external buffer */
1581 	for (i = 0; size > 0; i++) {
1582 		struct rte_mbuf_ext_shared_info *ret_shinfo = NULL;
1583 		uint16_t data_len = RTE_MIN(size, t_len);
1584 		char mz_name[RTE_MEMZONE_NAMESIZE];
1585 		const struct rte_memzone *memzone;
1586 		void *ext_buf_addr = NULL;
1587 		rte_iova_t buf_iova;
1588 		bool freed = false;
1589 		uint16_t buf_len;
1590 
1591 		buf_len = RTE_ALIGN_CEIL(data_len + 1024 +
1592 			sizeof(struct rte_mbuf_ext_shared_info), 8);
1593 
1594 		snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "ext_buf_%d", i);
1595 		memzone = rte_memzone_lookup(mz_name);
1596 		if (memzone != NULL && memzone->len != buf_len) {
1597 			rte_memzone_free(memzone);
1598 			memzone = NULL;
1599 		}
1600 		if (memzone == NULL) {
1601 			memzone = rte_memzone_reserve_aligned(mz_name, buf_len, SOCKET_ID_ANY,
1602 				RTE_MEMZONE_IOVA_CONTIG, RTE_CACHE_LINE_SIZE);
1603 			if (memzone == NULL) {
1604 				printf("Can't allocate memory zone %s\n", mz_name);
1605 				return NULL;
1606 			}
1607 		}
1608 
1609 		ext_buf_addr = memzone->addr;
1610 		if (input_text)
1611 			memcpy(ext_buf_addr, RTE_PTR_ADD(input_text, data_off), data_len);
1612 
1613 		/* Create buffer to hold rte_mbuf header */
1614 		m = rte_pktmbuf_alloc(mbuf_pool);
1615 		if (i == 0)
1616 			mbuf = m;
1617 
1618 		if (m == NULL) {
1619 			printf("Cannot create segment for source mbuf");
1620 			goto fail;
1621 		}
1622 
1623 		/* Save shared data (like callback function) in external buffer's end */
1624 		ret_shinfo = rte_pktmbuf_ext_shinfo_init_helper(ext_buf_addr, &buf_len,
1625 			ext_mbuf_callback_fn_free, &freed);
1626 		if (ret_shinfo == NULL) {
1627 			printf("Shared mem initialization failed!\n");
1628 			goto fail;
1629 		}
1630 
1631 		buf_iova = rte_mem_virt2iova(ext_buf_addr);
1632 
1633 		/* Attach external buffer to mbuf */
1634 		rte_pktmbuf_attach_extbuf(m, ext_buf_addr, buf_iova, buf_len,
1635 			ret_shinfo);
1636 		if (m->ol_flags != RTE_MBUF_F_EXTERNAL) {
1637 			printf("External buffer is not attached to mbuf\n");
1638 			goto fail;
1639 		}
1640 
1641 		if (input_text) {
1642 			dst = (uint8_t *)rte_pktmbuf_append(m, data_len);
1643 			if (dst == NULL) {
1644 				printf("Cannot append %d bytes to the mbuf\n", data_len);
1645 				goto fail;
1646 			}
1647 		}
1648 
1649 		if (mbuf != m)
1650 			rte_pktmbuf_chain(mbuf, m);
1651 
1652 		size -= data_len;
1653 		data_off += data_len;
1654 	}
1655 
1656 	return mbuf;
1657 
1658 fail:
1659 	rte_pktmbuf_free(mbuf);
1660 	ext_mbuf_memzone_free(nb_segs);
1661 	return NULL;
1662 }
1663 
1664 void
1665 ut_teardown(void)
1666 {
1667 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1668 	struct crypto_unittest_params *ut_params = &unittest_params;
1669 
1670 	/* free crypto session structure */
1671 #ifdef RTE_LIB_SECURITY
1672 	if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
1673 		if (ut_params->sec_session) {
1674 			rte_security_session_destroy(rte_cryptodev_get_sec_ctx
1675 						(ts_params->valid_devs[0]),
1676 						ut_params->sec_session);
1677 			ut_params->sec_session = NULL;
1678 		}
1679 	} else
1680 #endif
1681 	{
1682 		if (ut_params->sess) {
1683 			rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
1684 					ut_params->sess);
1685 			ut_params->sess = NULL;
1686 		}
1687 	}
1688 
1689 	/* free crypto operation structure */
1690 	rte_crypto_op_free(ut_params->op);
1691 
1692 	/*
1693 	 * free mbuf - both obuf and ibuf are usually the same,
1694 	 * so check if they point at the same address is necessary,
1695 	 * to avoid freeing the mbuf twice.
1696 	 */
1697 	if (ut_params->obuf) {
1698 		rte_pktmbuf_free(ut_params->obuf);
1699 		if (ut_params->ibuf == ut_params->obuf)
1700 			ut_params->ibuf = 0;
1701 		ut_params->obuf = 0;
1702 	}
1703 	if (ut_params->ibuf) {
1704 		ext_mbuf_memzone_free(1);
1705 		rte_pktmbuf_free(ut_params->ibuf);
1706 		ut_params->ibuf = 0;
1707 	}
1708 
1709 	if (ts_params->mbuf_pool != NULL)
1710 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
1711 			rte_mempool_avail_count(ts_params->mbuf_pool));
1712 
1713 	/* Stop the device */
1714 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1715 }
1716 
1717 static void
1718 ut_teardown_rx_inject(void)
1719 {
1720 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1721 	void *sec_ctx;
1722 	int ret;
1723 
1724 	if  (rte_eth_dev_count_avail() != 0) {
1725 		ret = rte_eth_dev_reset(0);
1726 		if (ret)
1727 			printf("Could not reset eth port 0");
1728 
1729 	}
1730 
1731 	ut_teardown();
1732 
1733 	sec_ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]);
1734 	if (sec_ctx == NULL)
1735 		return;
1736 
1737 	ret = rte_security_rx_inject_configure(sec_ctx, 0, false);
1738 	if (ret) {
1739 		printf("Could not disable Rx inject offload");
1740 		return;
1741 	}
1742 }
1743 
1744 static int
1745 test_device_configure_invalid_dev_id(void)
1746 {
1747 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1748 	uint16_t dev_id, num_devs = 0;
1749 
1750 	TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
1751 			"Need at least %d devices for test", 1);
1752 
1753 	/* valid dev_id values */
1754 	dev_id = ts_params->valid_devs[0];
1755 
1756 	/* Stop the device in case it's started so it can be configured */
1757 	rte_cryptodev_stop(dev_id);
1758 
1759 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
1760 			"Failed test for rte_cryptodev_configure: "
1761 			"invalid dev_num %u", dev_id);
1762 
1763 	/* invalid dev_id values */
1764 	dev_id = num_devs;
1765 
1766 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1767 			"Failed test for rte_cryptodev_configure: "
1768 			"invalid dev_num %u", dev_id);
1769 
1770 	dev_id = 0xff;
1771 
1772 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1773 			"Failed test for rte_cryptodev_configure:"
1774 			"invalid dev_num %u", dev_id);
1775 
1776 	return TEST_SUCCESS;
1777 }
1778 
1779 static int
1780 test_device_configure_invalid_queue_pair_ids(void)
1781 {
1782 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1783 	uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1784 
1785 	/* Stop the device in case it's started so it can be configured */
1786 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1787 
1788 	/* valid - max value queue pairs */
1789 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1790 
1791 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1792 			&ts_params->conf),
1793 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1794 			ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1795 
1796 	/* valid - one queue pairs */
1797 	ts_params->conf.nb_queue_pairs = 1;
1798 
1799 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1800 			&ts_params->conf),
1801 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1802 			ts_params->valid_devs[0],
1803 			ts_params->conf.nb_queue_pairs);
1804 
1805 
1806 	/* invalid - zero queue pairs */
1807 	ts_params->conf.nb_queue_pairs = 0;
1808 
1809 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1810 			&ts_params->conf),
1811 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1812 			" invalid qps: %u",
1813 			ts_params->valid_devs[0],
1814 			ts_params->conf.nb_queue_pairs);
1815 
1816 
1817 	/* invalid - max value supported by field queue pairs */
1818 	ts_params->conf.nb_queue_pairs = UINT16_MAX;
1819 
1820 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1821 			&ts_params->conf),
1822 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1823 			" invalid qps: %u",
1824 			ts_params->valid_devs[0],
1825 			ts_params->conf.nb_queue_pairs);
1826 
1827 
1828 	/* invalid - max value + 1 queue pairs */
1829 	ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1830 
1831 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1832 			&ts_params->conf),
1833 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1834 			" invalid qps: %u",
1835 			ts_params->valid_devs[0],
1836 			ts_params->conf.nb_queue_pairs);
1837 
1838 	/* revert to original testsuite value */
1839 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1840 
1841 	return TEST_SUCCESS;
1842 }
1843 
1844 static int
1845 test_queue_pair_descriptor_setup(void)
1846 {
1847 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1848 	struct rte_cryptodev_qp_conf qp_conf = {
1849 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
1850 	};
1851 	uint16_t qp_id;
1852 
1853 	/* Stop the device in case it's started so it can be configured */
1854 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1855 
1856 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1857 			&ts_params->conf),
1858 			"Failed to configure cryptodev %u",
1859 			ts_params->valid_devs[0]);
1860 
1861 	/*
1862 	 * Test various ring sizes on this device. memzones can't be
1863 	 * freed so are re-used if ring is released and re-created.
1864 	 */
1865 	qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1866 	qp_conf.mp_session = ts_params->session_mpool;
1867 
1868 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1869 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1870 				ts_params->valid_devs[0], qp_id, &qp_conf,
1871 				rte_cryptodev_socket_id(
1872 						ts_params->valid_devs[0])),
1873 				"Failed test for "
1874 				"rte_cryptodev_queue_pair_setup: num_inflights "
1875 				"%u on qp %u on cryptodev %u",
1876 				qp_conf.nb_descriptors, qp_id,
1877 				ts_params->valid_devs[0]);
1878 	}
1879 
1880 	qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1881 
1882 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1883 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1884 				ts_params->valid_devs[0], qp_id, &qp_conf,
1885 				rte_cryptodev_socket_id(
1886 						ts_params->valid_devs[0])),
1887 				"Failed test for"
1888 				" rte_cryptodev_queue_pair_setup: num_inflights"
1889 				" %u on qp %u on cryptodev %u",
1890 				qp_conf.nb_descriptors, qp_id,
1891 				ts_params->valid_devs[0]);
1892 	}
1893 
1894 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
1895 
1896 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1897 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1898 				ts_params->valid_devs[0], qp_id, &qp_conf,
1899 				rte_cryptodev_socket_id(
1900 						ts_params->valid_devs[0])),
1901 				"Failed test for "
1902 				"rte_cryptodev_queue_pair_setup: num_inflights"
1903 				" %u on qp %u on cryptodev %u",
1904 				qp_conf.nb_descriptors, qp_id,
1905 				ts_params->valid_devs[0]);
1906 	}
1907 
1908 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1909 
1910 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1911 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1912 				ts_params->valid_devs[0], qp_id, &qp_conf,
1913 				rte_cryptodev_socket_id(
1914 						ts_params->valid_devs[0])),
1915 				"Failed test for"
1916 				" rte_cryptodev_queue_pair_setup:"
1917 				"num_inflights %u on qp %u on cryptodev %u",
1918 				qp_conf.nb_descriptors, qp_id,
1919 				ts_params->valid_devs[0]);
1920 	}
1921 
1922 	/* test invalid queue pair id */
1923 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;	/*valid */
1924 
1925 	qp_id = ts_params->conf.nb_queue_pairs;		/*invalid */
1926 
1927 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1928 			ts_params->valid_devs[0],
1929 			qp_id, &qp_conf,
1930 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1931 			"Failed test for rte_cryptodev_queue_pair_setup:"
1932 			"invalid qp %u on cryptodev %u",
1933 			qp_id, ts_params->valid_devs[0]);
1934 
1935 	qp_id = 0xffff; /*invalid*/
1936 
1937 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1938 			ts_params->valid_devs[0],
1939 			qp_id, &qp_conf,
1940 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1941 			"Failed test for rte_cryptodev_queue_pair_setup:"
1942 			"invalid qp %u on cryptodev %u",
1943 			qp_id, ts_params->valid_devs[0]);
1944 
1945 	return TEST_SUCCESS;
1946 }
1947 
1948 /* ***** Plaintext data for tests ***** */
1949 
1950 const char catch_22_quote_1[] =
1951 		"There was only one catch and that was Catch-22, which "
1952 		"specified that a concern for one's safety in the face of "
1953 		"dangers that were real and immediate was the process of a "
1954 		"rational mind. Orr was crazy and could be grounded. All he "
1955 		"had to do was ask; and as soon as he did, he would no longer "
1956 		"be crazy and would have to fly more missions. Orr would be "
1957 		"crazy to fly more missions and sane if he didn't, but if he "
1958 		"was sane he had to fly them. If he flew them he was crazy "
1959 		"and didn't have to; but if he didn't want to he was sane and "
1960 		"had to. Yossarian was moved very deeply by the absolute "
1961 		"simplicity of this clause of Catch-22 and let out a "
1962 		"respectful whistle. \"That's some catch, that Catch-22\", he "
1963 		"observed. \"It's the best there is,\" Doc Daneeka agreed.";
1964 
1965 const char catch_22_quote[] =
1966 		"What a lousy earth! He wondered how many people were "
1967 		"destitute that same night even in his own prosperous country, "
1968 		"how many homes were shanties, how many husbands were drunk "
1969 		"and wives socked, and how many children were bullied, abused, "
1970 		"or abandoned. How many families hungered for food they could "
1971 		"not afford to buy? How many hearts were broken? How many "
1972 		"suicides would take place that same night, how many people "
1973 		"would go insane? How many cockroaches and landlords would "
1974 		"triumph? How many winners were losers, successes failures, "
1975 		"and rich men poor men? How many wise guys were stupid? How "
1976 		"many happy endings were unhappy endings? How many honest men "
1977 		"were liars, brave men cowards, loyal men traitors, how many "
1978 		"sainted men were corrupt, how many people in positions of "
1979 		"trust had sold their souls to bodyguards, how many had never "
1980 		"had souls? How many straight-and-narrow paths were crooked "
1981 		"paths? How many best families were worst families and how "
1982 		"many good people were bad people? When you added them all up "
1983 		"and then subtracted, you might be left with only the children, "
1984 		"and perhaps with Albert Einstein and an old violinist or "
1985 		"sculptor somewhere.";
1986 
1987 #define QUOTE_480_BYTES		(480)
1988 #define QUOTE_512_BYTES		(512)
1989 #define QUOTE_768_BYTES		(768)
1990 #define QUOTE_1024_BYTES	(1024)
1991 
1992 
1993 
1994 /* ***** SHA1 Hash Tests ***** */
1995 
1996 #define HMAC_KEY_LENGTH_SHA1	(DIGEST_BYTE_LENGTH_SHA1)
1997 
1998 static uint8_t hmac_sha1_key[] = {
1999 	0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
2000 	0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
2001 	0xDE, 0xF4, 0xDE, 0xAD };
2002 
2003 /* ***** SHA224 Hash Tests ***** */
2004 
2005 #define HMAC_KEY_LENGTH_SHA224	(DIGEST_BYTE_LENGTH_SHA224)
2006 
2007 
2008 /* ***** AES-CBC Cipher Tests ***** */
2009 
2010 #define CIPHER_KEY_LENGTH_AES_CBC	(16)
2011 #define CIPHER_IV_LENGTH_AES_CBC	(CIPHER_KEY_LENGTH_AES_CBC)
2012 
2013 static uint8_t aes_cbc_key[] = {
2014 	0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
2015 	0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
2016 
2017 static uint8_t aes_cbc_iv[] = {
2018 	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2019 	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
2020 
2021 
2022 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
2023 
2024 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
2025 	0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
2026 	0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
2027 	0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
2028 	0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
2029 	0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
2030 	0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
2031 	0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
2032 	0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
2033 	0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
2034 	0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
2035 	0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
2036 	0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
2037 	0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
2038 	0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
2039 	0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
2040 	0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
2041 	0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
2042 	0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
2043 	0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
2044 	0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
2045 	0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
2046 	0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
2047 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2048 	0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
2049 	0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
2050 	0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
2051 	0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
2052 	0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
2053 	0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
2054 	0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
2055 	0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
2056 	0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
2057 	0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
2058 	0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
2059 	0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
2060 	0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
2061 	0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
2062 	0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
2063 	0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
2064 	0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
2065 	0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
2066 	0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
2067 	0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
2068 	0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
2069 	0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
2070 	0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
2071 	0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
2072 	0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
2073 	0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
2074 	0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
2075 	0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
2076 	0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
2077 	0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
2078 	0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
2079 	0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
2080 	0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
2081 	0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
2082 	0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
2083 	0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
2084 	0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
2085 	0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
2086 	0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
2087 	0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
2088 	0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
2089 };
2090 
2091 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
2092 	0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
2093 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
2094 	0x18, 0x8c, 0x1d, 0x32
2095 };
2096 
2097 
2098 /* Multisession Vector context Test */
2099 /*Begin Session 0 */
2100 static uint8_t ms_aes_cbc_key0[] = {
2101 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2102 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2103 };
2104 
2105 static uint8_t ms_aes_cbc_iv0[] = {
2106 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2107 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2108 };
2109 
2110 static const uint8_t ms_aes_cbc_cipher0[] = {
2111 		0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
2112 		0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
2113 		0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
2114 		0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
2115 		0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
2116 		0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
2117 		0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
2118 		0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
2119 		0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
2120 		0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
2121 		0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
2122 		0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
2123 		0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
2124 		0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
2125 		0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
2126 		0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
2127 		0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
2128 		0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
2129 		0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
2130 		0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
2131 		0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
2132 		0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
2133 		0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
2134 		0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
2135 		0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
2136 		0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
2137 		0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
2138 		0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
2139 		0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
2140 		0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
2141 		0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
2142 		0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
2143 		0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
2144 		0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
2145 		0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
2146 		0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
2147 		0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
2148 		0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
2149 		0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
2150 		0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
2151 		0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
2152 		0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
2153 		0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
2154 		0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
2155 		0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
2156 		0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
2157 		0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
2158 		0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
2159 		0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
2160 		0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
2161 		0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
2162 		0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
2163 		0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
2164 		0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
2165 		0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
2166 		0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
2167 		0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
2168 		0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
2169 		0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
2170 		0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
2171 		0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
2172 		0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
2173 		0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
2174 		0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
2175 };
2176 
2177 
2178 static  uint8_t ms_hmac_key0[] = {
2179 		0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2180 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2181 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2182 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2183 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2184 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2185 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2186 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2187 };
2188 
2189 static const uint8_t ms_hmac_digest0[] = {
2190 		0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
2191 		0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
2192 		0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
2193 		0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
2194 		0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
2195 		0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
2196 		0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
2197 		0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
2198 		};
2199 
2200 /* End Session 0 */
2201 /* Begin session 1 */
2202 
2203 static  uint8_t ms_aes_cbc_key1[] = {
2204 		0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2205 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2206 };
2207 
2208 static  uint8_t ms_aes_cbc_iv1[] = {
2209 	0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2210 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2211 };
2212 
2213 static const uint8_t ms_aes_cbc_cipher1[] = {
2214 		0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
2215 		0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
2216 		0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
2217 		0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
2218 		0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
2219 		0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
2220 		0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
2221 		0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
2222 		0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
2223 		0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
2224 		0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
2225 		0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
2226 		0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
2227 		0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
2228 		0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
2229 		0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
2230 		0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
2231 		0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
2232 		0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
2233 		0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
2234 		0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
2235 		0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
2236 		0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
2237 		0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
2238 		0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
2239 		0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
2240 		0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
2241 		0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
2242 		0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
2243 		0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
2244 		0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
2245 		0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
2246 		0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
2247 		0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
2248 		0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
2249 		0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
2250 		0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
2251 		0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
2252 		0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
2253 		0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
2254 		0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
2255 		0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
2256 		0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
2257 		0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
2258 		0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
2259 		0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
2260 		0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
2261 		0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
2262 		0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
2263 		0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
2264 		0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
2265 		0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
2266 		0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
2267 		0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
2268 		0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
2269 		0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
2270 		0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
2271 		0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
2272 		0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
2273 		0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
2274 		0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
2275 		0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
2276 		0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
2277 		0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
2278 
2279 };
2280 
2281 static uint8_t ms_hmac_key1[] = {
2282 		0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2283 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2284 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2285 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2286 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2287 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2288 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2289 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2290 };
2291 
2292 static const uint8_t ms_hmac_digest1[] = {
2293 		0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
2294 		0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
2295 		0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
2296 		0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
2297 		0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
2298 		0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
2299 		0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
2300 		0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
2301 };
2302 /* End Session 1  */
2303 /* Begin Session 2 */
2304 static  uint8_t ms_aes_cbc_key2[] = {
2305 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2306 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2307 };
2308 
2309 static  uint8_t ms_aes_cbc_iv2[] = {
2310 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2311 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2312 };
2313 
2314 static const uint8_t ms_aes_cbc_cipher2[] = {
2315 		0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
2316 		0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
2317 		0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
2318 		0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
2319 		0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
2320 		0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
2321 		0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
2322 		0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
2323 		0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
2324 		0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
2325 		0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
2326 		0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
2327 		0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
2328 		0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
2329 		0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
2330 		0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
2331 		0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
2332 		0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
2333 		0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
2334 		0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
2335 		0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
2336 		0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
2337 		0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
2338 		0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
2339 		0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
2340 		0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
2341 		0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
2342 		0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
2343 		0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
2344 		0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
2345 		0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
2346 		0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
2347 		0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
2348 		0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
2349 		0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
2350 		0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
2351 		0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
2352 		0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
2353 		0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
2354 		0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
2355 		0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
2356 		0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
2357 		0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
2358 		0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
2359 		0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
2360 		0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
2361 		0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
2362 		0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
2363 		0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
2364 		0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
2365 		0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
2366 		0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
2367 		0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
2368 		0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
2369 		0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
2370 		0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
2371 		0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
2372 		0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
2373 		0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
2374 		0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
2375 		0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
2376 		0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
2377 		0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
2378 		0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
2379 };
2380 
2381 static  uint8_t ms_hmac_key2[] = {
2382 		0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2383 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2384 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2385 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2386 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2387 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2388 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2389 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2390 };
2391 
2392 static const uint8_t ms_hmac_digest2[] = {
2393 		0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
2394 		0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
2395 		0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
2396 		0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
2397 		0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
2398 		0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
2399 		0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
2400 		0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
2401 };
2402 
2403 /* End Session 2 */
2404 
2405 #define MAX_OPS_PROCESSED (MAX_NUM_OPS_INFLIGHT - 1)
2406 static int
2407 test_queue_pair_descriptor_count(void)
2408 {
2409 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2410 	struct crypto_unittest_params *ut_params = &unittest_params;
2411 	struct rte_crypto_op *ops_deq[MAX_OPS_PROCESSED] = { NULL };
2412 	struct rte_crypto_op *ops[MAX_OPS_PROCESSED] = { NULL };
2413 	struct rte_cryptodev_sym_capability_idx cap_idx;
2414 	int qp_depth = 0;
2415 	int i;
2416 
2417 	RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
2418 
2419 	/* Verify if the queue pair depth API is supported by driver */
2420 	qp_depth = rte_cryptodev_qp_depth_used(ts_params->valid_devs[0], 0);
2421 	if (qp_depth == -ENOTSUP)
2422 		return TEST_SKIPPED;
2423 
2424 	/* Verify the capabilities */
2425 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2426 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
2427 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], &cap_idx) == NULL)
2428 		return TEST_SKIPPED;
2429 
2430 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2431 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
2432 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], &cap_idx) == NULL)
2433 		return TEST_SKIPPED;
2434 
2435 	/* Setup Cipher Parameters */
2436 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2437 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2438 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2439 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2440 	ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2441 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2442 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2443 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2444 
2445 	/* Setup HMAC Parameters */
2446 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2447 	ut_params->auth_xform.next = NULL;
2448 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2449 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
2450 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
2451 	ut_params->auth_xform.auth.key.data = hmac_sha1_key;
2452 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
2453 
2454 	rte_errno = 0;
2455 	ut_params->sess = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
2456 			&ut_params->cipher_xform, ts_params->session_mpool);
2457 	if (rte_errno == ENOTSUP)
2458 		return TEST_SKIPPED;
2459 
2460 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2461 
2462 	TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
2463 			RTE_CRYPTO_OP_TYPE_SYMMETRIC, ops, MAX_OPS_PROCESSED),
2464 			MAX_OPS_PROCESSED, "failed to generate burst of crypto ops");
2465 
2466 	/* Generate crypto op data structure */
2467 	for (i = 0; i < MAX_OPS_PROCESSED; i++) {
2468 		struct rte_mbuf *m;
2469 		uint8_t *digest;
2470 
2471 		/* Generate test mbuf data and space for digest */
2472 		m = setup_test_string(ts_params->mbuf_pool, catch_22_quote, QUOTE_512_BYTES, 0);
2473 		TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
2474 
2475 		digest = (uint8_t *)rte_pktmbuf_append(m, DIGEST_BYTE_LENGTH_SHA1);
2476 		TEST_ASSERT_NOT_NULL(digest, "no room to append digest");
2477 
2478 		rte_crypto_op_attach_sym_session(ops[i], ut_params->sess);
2479 
2480 		/* set crypto operation source mbuf */
2481 		ops[i]->sym->m_src = m;
2482 
2483 		/* Set crypto operation authentication parameters */
2484 		ops[i]->sym->auth.digest.data = digest;
2485 		ops[i]->sym->auth.digest.phys_addr = rte_pktmbuf_iova_offset(m, QUOTE_512_BYTES);
2486 
2487 		ops[i]->sym->auth.data.offset = 0;
2488 		ops[i]->sym->auth.data.length = QUOTE_512_BYTES;
2489 
2490 		/* Copy IV at the end of the crypto operation */
2491 		memcpy(rte_crypto_op_ctod_offset(ops[i], uint8_t *, IV_OFFSET), aes_cbc_iv,
2492 				CIPHER_IV_LENGTH_AES_CBC);
2493 
2494 		/* Set crypto operation cipher parameters */
2495 		ops[i]->sym->cipher.data.offset = 0;
2496 		ops[i]->sym->cipher.data.length = QUOTE_512_BYTES;
2497 
2498 		TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0], 0,
2499 					&ops[i], 1), 1, "Error enqueuing");
2500 	}
2501 
2502 	for (i = 0; i < MAX_OPS_PROCESSED; i++) {
2503 		qp_depth = rte_cryptodev_qp_depth_used(ts_params->valid_devs[0], 0);
2504 		TEST_ASSERT_EQUAL(qp_depth, MAX_OPS_PROCESSED - i,
2505 			"Crypto queue pair depth used does not match with inflight ops");
2506 
2507 		while (rte_cryptodev_dequeue_burst(ts_params->valid_devs[0], 0,
2508 					&ops_deq[i], 1) == 0)
2509 			rte_pause();
2510 
2511 		TEST_ASSERT_EQUAL(ops_deq[i]->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2512 				"crypto op processing failed");
2513 
2514 		rte_pktmbuf_free(ops_deq[i]->sym->m_src);
2515 		rte_crypto_op_free(ops_deq[i]);
2516 	}
2517 
2518 	return TEST_SUCCESS;
2519 }
2520 
2521 static int
2522 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
2523 {
2524 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2525 	struct crypto_unittest_params *ut_params = &unittest_params;
2526 	/* Verify the capabilities */
2527 	struct rte_cryptodev_sym_capability_idx cap_idx;
2528 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2529 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
2530 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2531 			&cap_idx) == NULL)
2532 		return TEST_SKIPPED;
2533 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2534 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
2535 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2536 			&cap_idx) == NULL)
2537 		return TEST_SKIPPED;
2538 
2539 	/* Generate test mbuf data and space for digest */
2540 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2541 			catch_22_quote,	QUOTE_512_BYTES, 0);
2542 
2543 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2544 			DIGEST_BYTE_LENGTH_SHA1);
2545 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2546 
2547 	/* Setup Cipher Parameters */
2548 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2549 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2550 
2551 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2552 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2553 	ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2554 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2555 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2556 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2557 
2558 	/* Setup HMAC Parameters */
2559 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2560 
2561 	ut_params->auth_xform.next = NULL;
2562 
2563 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2564 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
2565 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
2566 	ut_params->auth_xform.auth.key.data = hmac_sha1_key;
2567 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
2568 
2569 	rte_errno = 0;
2570 	ut_params->sess = rte_cryptodev_sym_session_create(
2571 			ts_params->valid_devs[0], &ut_params->cipher_xform,
2572 			ts_params->session_mpool);
2573 	if (rte_errno == ENOTSUP)
2574 		return TEST_SKIPPED;
2575 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2576 
2577 	/* Generate crypto op data structure */
2578 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2579 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2580 	TEST_ASSERT_NOT_NULL(ut_params->op,
2581 			"Failed to allocate symmetric crypto operation struct");
2582 
2583 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2584 
2585 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2586 
2587 	/* set crypto operation source mbuf */
2588 	sym_op->m_src = ut_params->ibuf;
2589 
2590 	/* Set crypto operation authentication parameters */
2591 	sym_op->auth.digest.data = ut_params->digest;
2592 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2593 			ut_params->ibuf, QUOTE_512_BYTES);
2594 
2595 	sym_op->auth.data.offset = 0;
2596 	sym_op->auth.data.length = QUOTE_512_BYTES;
2597 
2598 	/* Copy IV at the end of the crypto operation */
2599 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2600 			aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
2601 
2602 	/* Set crypto operation cipher parameters */
2603 	sym_op->cipher.data.offset = 0;
2604 	sym_op->cipher.data.length = QUOTE_512_BYTES;
2605 
2606 	/* Process crypto operation */
2607 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2608 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2609 			ut_params->op);
2610 	else
2611 		TEST_ASSERT_NOT_NULL(
2612 			process_crypto_request(ts_params->valid_devs[0],
2613 				ut_params->op),
2614 				"failed to process sym crypto op");
2615 
2616 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2617 			"crypto op processing failed");
2618 
2619 	/* Validate obuf */
2620 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
2621 			uint8_t *);
2622 
2623 	TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
2624 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2625 			QUOTE_512_BYTES,
2626 			"ciphertext data not as expected");
2627 
2628 	uint8_t *digest = ciphertext + QUOTE_512_BYTES;
2629 
2630 	TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
2631 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
2632 			gbl_driver_id == rte_cryptodev_driver_id_get(
2633 					RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
2634 					TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
2635 					DIGEST_BYTE_LENGTH_SHA1,
2636 			"Generated digest data not as expected");
2637 
2638 	return TEST_SUCCESS;
2639 }
2640 
2641 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
2642 
2643 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
2644 
2645 static uint8_t hmac_sha512_key[] = {
2646 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
2647 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2648 	0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2649 	0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
2650 	0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
2651 	0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2652 	0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
2653 	0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
2654 
2655 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
2656 	0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
2657 	0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
2658 	0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
2659 	0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
2660 	0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
2661 	0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
2662 	0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
2663 	0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
2664 
2665 
2666 
2667 static int
2668 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2669 		struct crypto_unittest_params *ut_params,
2670 		uint8_t *cipher_key,
2671 		uint8_t *hmac_key);
2672 
2673 static int
2674 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess,
2675 		struct crypto_unittest_params *ut_params,
2676 		struct crypto_testsuite_params *ts_params,
2677 		const uint8_t *cipher,
2678 		const uint8_t *digest,
2679 		const uint8_t *iv);
2680 
2681 
2682 static int
2683 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2684 		struct crypto_unittest_params *ut_params,
2685 		uint8_t *cipher_key,
2686 		uint8_t *hmac_key)
2687 {
2688 
2689 	/* Setup Cipher Parameters */
2690 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2691 	ut_params->cipher_xform.next = NULL;
2692 
2693 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2694 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
2695 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2696 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2697 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2698 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2699 
2700 	/* Setup HMAC Parameters */
2701 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2702 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2703 
2704 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
2705 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
2706 	ut_params->auth_xform.auth.key.data = hmac_key;
2707 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
2708 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
2709 
2710 	return TEST_SUCCESS;
2711 }
2712 
2713 
2714 static int
2715 test_AES_CBC_HMAC_SHA512_decrypt_perform(void *sess,
2716 		struct crypto_unittest_params *ut_params,
2717 		struct crypto_testsuite_params *ts_params,
2718 		const uint8_t *cipher,
2719 		const uint8_t *digest,
2720 		const uint8_t *iv)
2721 {
2722 	int ret;
2723 
2724 	/* Generate test mbuf data and digest */
2725 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2726 			(const char *)
2727 			cipher,
2728 			QUOTE_512_BYTES, 0);
2729 
2730 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2731 			DIGEST_BYTE_LENGTH_SHA512);
2732 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2733 
2734 	rte_memcpy(ut_params->digest,
2735 			digest,
2736 			DIGEST_BYTE_LENGTH_SHA512);
2737 
2738 	/* Generate Crypto op data structure */
2739 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2740 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2741 	TEST_ASSERT_NOT_NULL(ut_params->op,
2742 			"Failed to allocate symmetric crypto operation struct");
2743 
2744 	rte_crypto_op_attach_sym_session(ut_params->op, sess);
2745 
2746 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2747 
2748 	/* set crypto operation source mbuf */
2749 	sym_op->m_src = ut_params->ibuf;
2750 
2751 	sym_op->auth.digest.data = ut_params->digest;
2752 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2753 			ut_params->ibuf, QUOTE_512_BYTES);
2754 
2755 	sym_op->auth.data.offset = 0;
2756 	sym_op->auth.data.length = QUOTE_512_BYTES;
2757 
2758 	/* Copy IV at the end of the crypto operation */
2759 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2760 			iv, CIPHER_IV_LENGTH_AES_CBC);
2761 
2762 	sym_op->cipher.data.offset = 0;
2763 	sym_op->cipher.data.length = QUOTE_512_BYTES;
2764 
2765 	/* Process crypto operation */
2766 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2767 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2768 			ut_params->op);
2769 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
2770 		ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 0);
2771 		if (ret != TEST_SUCCESS)
2772 			return ret;
2773 	} else
2774 		TEST_ASSERT_NOT_NULL(
2775 				process_crypto_request(ts_params->valid_devs[0],
2776 					ut_params->op),
2777 					"failed to process sym crypto op");
2778 
2779 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2780 			"crypto op processing failed");
2781 
2782 	ut_params->obuf = ut_params->op->sym->m_src;
2783 
2784 	/* Validate obuf */
2785 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
2786 			rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
2787 			catch_22_quote,
2788 			QUOTE_512_BYTES,
2789 			"Plaintext data not as expected");
2790 
2791 	/* Validate obuf */
2792 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2793 			"Digest verification failed");
2794 
2795 	return TEST_SUCCESS;
2796 }
2797 
2798 /* ***** SNOW 3G Tests ***** */
2799 static int
2800 create_wireless_algo_hash_session(uint8_t dev_id,
2801 	const uint8_t *key, const uint8_t key_len,
2802 	const uint8_t iv_len, const uint8_t auth_len,
2803 	enum rte_crypto_auth_operation op,
2804 	enum rte_crypto_auth_algorithm algo)
2805 {
2806 	uint8_t hash_key[key_len];
2807 
2808 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2809 	struct crypto_unittest_params *ut_params = &unittest_params;
2810 
2811 	memcpy(hash_key, key, key_len);
2812 
2813 	debug_hexdump(stdout, "key:", key, key_len);
2814 
2815 	/* Setup Authentication Parameters */
2816 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2817 	ut_params->auth_xform.next = NULL;
2818 
2819 	ut_params->auth_xform.auth.op = op;
2820 	ut_params->auth_xform.auth.algo = algo;
2821 	ut_params->auth_xform.auth.key.length = key_len;
2822 	ut_params->auth_xform.auth.key.data = hash_key;
2823 	ut_params->auth_xform.auth.digest_length = auth_len;
2824 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2825 	ut_params->auth_xform.auth.iv.length = iv_len;
2826 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2827 			&ut_params->auth_xform, ts_params->session_mpool);
2828 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
2829 		return TEST_SKIPPED;
2830 
2831 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2832 	return 0;
2833 }
2834 
2835 static int
2836 create_wireless_algo_cipher_session(uint8_t dev_id,
2837 			enum rte_crypto_cipher_operation op,
2838 			enum rte_crypto_cipher_algorithm algo,
2839 			const uint8_t *key, const uint8_t key_len,
2840 			uint8_t iv_len)
2841 {
2842 	uint8_t cipher_key[key_len];
2843 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2844 	struct crypto_unittest_params *ut_params = &unittest_params;
2845 
2846 	memcpy(cipher_key, key, key_len);
2847 
2848 	/* Setup Cipher Parameters */
2849 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2850 	ut_params->cipher_xform.next = NULL;
2851 
2852 	ut_params->cipher_xform.cipher.algo = algo;
2853 	ut_params->cipher_xform.cipher.op = op;
2854 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2855 	ut_params->cipher_xform.cipher.key.length = key_len;
2856 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2857 	ut_params->cipher_xform.cipher.iv.length = iv_len;
2858 
2859 	debug_hexdump(stdout, "key:", key, key_len);
2860 
2861 	/* Create Crypto session */
2862 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2863 			&ut_params->cipher_xform, ts_params->session_mpool);
2864 
2865 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
2866 		return TEST_SKIPPED;
2867 
2868 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2869 	return 0;
2870 }
2871 
2872 static int
2873 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2874 			unsigned int cipher_len,
2875 			unsigned int cipher_offset)
2876 {
2877 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2878 	struct crypto_unittest_params *ut_params = &unittest_params;
2879 
2880 	/* Generate Crypto op data structure */
2881 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2882 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2883 	TEST_ASSERT_NOT_NULL(ut_params->op,
2884 				"Failed to allocate pktmbuf offload");
2885 
2886 	/* Set crypto operation data parameters */
2887 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2888 
2889 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2890 
2891 	/* set crypto operation source mbuf */
2892 	sym_op->m_src = ut_params->ibuf;
2893 
2894 	/* iv */
2895 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2896 			iv, iv_len);
2897 	sym_op->cipher.data.length = cipher_len;
2898 	sym_op->cipher.data.offset = cipher_offset;
2899 	return 0;
2900 }
2901 
2902 static int
2903 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2904 			unsigned int cipher_len,
2905 			unsigned int cipher_offset)
2906 {
2907 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2908 	struct crypto_unittest_params *ut_params = &unittest_params;
2909 
2910 	/* Generate Crypto op data structure */
2911 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2912 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2913 	TEST_ASSERT_NOT_NULL(ut_params->op,
2914 				"Failed to allocate pktmbuf offload");
2915 
2916 	/* Set crypto operation data parameters */
2917 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2918 
2919 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2920 
2921 	/* set crypto operation source mbuf */
2922 	sym_op->m_src = ut_params->ibuf;
2923 	sym_op->m_dst = ut_params->obuf;
2924 
2925 	/* iv */
2926 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2927 			iv, iv_len);
2928 	sym_op->cipher.data.length = cipher_len;
2929 	sym_op->cipher.data.offset = cipher_offset;
2930 	return 0;
2931 }
2932 
2933 static int
2934 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2935 		enum rte_crypto_cipher_operation cipher_op,
2936 		enum rte_crypto_auth_operation auth_op,
2937 		enum rte_crypto_auth_algorithm auth_algo,
2938 		enum rte_crypto_cipher_algorithm cipher_algo,
2939 		const uint8_t *a_key, uint8_t a_key_len,
2940 		const uint8_t *c_key, uint8_t c_key_len,
2941 		uint8_t auth_iv_len, uint8_t auth_len,
2942 		uint8_t cipher_iv_len)
2943 
2944 {
2945 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2946 	struct crypto_unittest_params *ut_params = &unittest_params;
2947 
2948 	/* Setup Authentication Parameters */
2949 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2950 	ut_params->auth_xform.next = NULL;
2951 
2952 	ut_params->auth_xform.auth.op = auth_op;
2953 	ut_params->auth_xform.auth.algo = auth_algo;
2954 	ut_params->auth_xform.auth.key.length = a_key_len;
2955 	ut_params->auth_xform.auth.key.data = a_key;
2956 	ut_params->auth_xform.auth.digest_length = auth_len;
2957 	/* Auth IV will be after cipher IV */
2958 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2959 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2960 
2961 	/* Setup Cipher Parameters */
2962 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2963 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2964 
2965 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2966 	ut_params->cipher_xform.cipher.op = cipher_op;
2967 	ut_params->cipher_xform.cipher.key.data = c_key;
2968 	ut_params->cipher_xform.cipher.key.length = c_key_len;
2969 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2970 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2971 
2972 	debug_hexdump(stdout, "Auth key:", a_key, c_key_len);
2973 	debug_hexdump(stdout, "Cipher key:", c_key, c_key_len);
2974 
2975 	/* Create Crypto session*/
2976 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2977 			&ut_params->cipher_xform, ts_params->session_mpool);
2978 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
2979 		return TEST_SKIPPED;
2980 
2981 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2982 	return 0;
2983 }
2984 
2985 static int
2986 create_wireless_cipher_auth_session(uint8_t dev_id,
2987 		enum rte_crypto_cipher_operation cipher_op,
2988 		enum rte_crypto_auth_operation auth_op,
2989 		enum rte_crypto_auth_algorithm auth_algo,
2990 		enum rte_crypto_cipher_algorithm cipher_algo,
2991 		const struct wireless_test_data *tdata)
2992 {
2993 	const uint8_t key_len = tdata->key.len;
2994 	uint8_t cipher_auth_key[key_len];
2995 
2996 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2997 	struct crypto_unittest_params *ut_params = &unittest_params;
2998 	const uint8_t *key = tdata->key.data;
2999 	const uint8_t auth_len = tdata->digest.len;
3000 	uint8_t cipher_iv_len = tdata->cipher_iv.len;
3001 	uint8_t auth_iv_len = tdata->auth_iv.len;
3002 
3003 	memcpy(cipher_auth_key, key, key_len);
3004 
3005 	/* Setup Authentication Parameters */
3006 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3007 	ut_params->auth_xform.next = NULL;
3008 
3009 	ut_params->auth_xform.auth.op = auth_op;
3010 	ut_params->auth_xform.auth.algo = auth_algo;
3011 	ut_params->auth_xform.auth.key.length = key_len;
3012 	/* Hash key = cipher key */
3013 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
3014 	ut_params->auth_xform.auth.digest_length = auth_len;
3015 	/* Auth IV will be after cipher IV */
3016 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
3017 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
3018 
3019 	/* Setup Cipher Parameters */
3020 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3021 	ut_params->cipher_xform.next = &ut_params->auth_xform;
3022 
3023 	ut_params->cipher_xform.cipher.algo = cipher_algo;
3024 	ut_params->cipher_xform.cipher.op = cipher_op;
3025 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
3026 	ut_params->cipher_xform.cipher.key.length = key_len;
3027 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
3028 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
3029 
3030 
3031 	debug_hexdump(stdout, "key:", key, key_len);
3032 
3033 	/* Create Crypto session*/
3034 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3035 			&ut_params->cipher_xform, ts_params->session_mpool);
3036 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
3037 		return TEST_SKIPPED;
3038 
3039 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3040 	return 0;
3041 }
3042 
3043 static int
3044 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
3045 		const struct wireless_test_data *tdata)
3046 {
3047 	return create_wireless_cipher_auth_session(dev_id,
3048 		RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3049 		RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
3050 		RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
3051 }
3052 
3053 static int
3054 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
3055 		enum rte_crypto_cipher_operation cipher_op,
3056 		enum rte_crypto_auth_operation auth_op,
3057 		enum rte_crypto_auth_algorithm auth_algo,
3058 		enum rte_crypto_cipher_algorithm cipher_algo,
3059 		const uint8_t *a_key, const uint8_t a_key_len,
3060 		const uint8_t *c_key, const uint8_t c_key_len,
3061 		uint8_t auth_iv_len, uint8_t auth_len,
3062 		uint8_t cipher_iv_len)
3063 {
3064 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3065 	struct crypto_unittest_params *ut_params = &unittest_params;
3066 
3067 	/* Setup Authentication Parameters */
3068 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3069 	ut_params->auth_xform.auth.op = auth_op;
3070 	ut_params->auth_xform.next = &ut_params->cipher_xform;
3071 	ut_params->auth_xform.auth.algo = auth_algo;
3072 	ut_params->auth_xform.auth.key.length = a_key_len;
3073 	ut_params->auth_xform.auth.key.data = a_key;
3074 	ut_params->auth_xform.auth.digest_length = auth_len;
3075 	/* Auth IV will be after cipher IV */
3076 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
3077 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
3078 
3079 	/* Setup Cipher Parameters */
3080 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3081 	ut_params->cipher_xform.next = NULL;
3082 	ut_params->cipher_xform.cipher.algo = cipher_algo;
3083 	ut_params->cipher_xform.cipher.op = cipher_op;
3084 	ut_params->cipher_xform.cipher.key.data = c_key;
3085 	ut_params->cipher_xform.cipher.key.length = c_key_len;
3086 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
3087 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
3088 
3089 	debug_hexdump(stdout, "Auth key:", a_key, a_key_len);
3090 	debug_hexdump(stdout, "Cipher key:", c_key, c_key_len);
3091 
3092 	/* Create Crypto session*/
3093 	if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
3094 		ut_params->auth_xform.next = NULL;
3095 		ut_params->cipher_xform.next = &ut_params->auth_xform;
3096 		ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3097 			&ut_params->cipher_xform, ts_params->session_mpool);
3098 	} else
3099 		ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3100 			&ut_params->auth_xform, ts_params->session_mpool);
3101 
3102 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
3103 		return TEST_SKIPPED;
3104 
3105 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3106 
3107 	return 0;
3108 }
3109 
3110 static int
3111 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
3112 		unsigned int auth_tag_len,
3113 		const uint8_t *iv, unsigned int iv_len,
3114 		unsigned int data_pad_len,
3115 		enum rte_crypto_auth_operation op,
3116 		unsigned int auth_len, unsigned int auth_offset)
3117 {
3118 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3119 
3120 	struct crypto_unittest_params *ut_params = &unittest_params;
3121 
3122 	/* Generate Crypto op data structure */
3123 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3124 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3125 	TEST_ASSERT_NOT_NULL(ut_params->op,
3126 		"Failed to allocate pktmbuf offload");
3127 
3128 	/* Set crypto operation data parameters */
3129 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3130 
3131 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3132 
3133 	/* set crypto operation source mbuf */
3134 	sym_op->m_src = ut_params->ibuf;
3135 
3136 	/* iv */
3137 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
3138 			iv, iv_len);
3139 	/* digest */
3140 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
3141 					ut_params->ibuf, auth_tag_len);
3142 
3143 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
3144 				"no room to append auth tag");
3145 	ut_params->digest = sym_op->auth.digest.data;
3146 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
3147 			ut_params->ibuf, data_pad_len);
3148 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
3149 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
3150 	else
3151 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3152 
3153 	debug_hexdump(stdout, "digest:",
3154 		sym_op->auth.digest.data,
3155 		auth_tag_len);
3156 
3157 	sym_op->auth.data.length = auth_len;
3158 	sym_op->auth.data.offset = auth_offset;
3159 
3160 	return 0;
3161 }
3162 
3163 static int
3164 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
3165 	enum rte_crypto_auth_operation op)
3166 {
3167 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3168 	struct crypto_unittest_params *ut_params = &unittest_params;
3169 
3170 	const uint8_t *auth_tag = tdata->digest.data;
3171 	const unsigned int auth_tag_len = tdata->digest.len;
3172 	unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
3173 	unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3174 
3175 	const uint8_t *cipher_iv = tdata->cipher_iv.data;
3176 	const uint8_t cipher_iv_len = tdata->cipher_iv.len;
3177 	const uint8_t *auth_iv = tdata->auth_iv.data;
3178 	const uint8_t auth_iv_len = tdata->auth_iv.len;
3179 	const unsigned int cipher_len = tdata->validCipherLenInBits.len;
3180 	const unsigned int auth_len = tdata->validAuthLenInBits.len;
3181 
3182 	/* Generate Crypto op data structure */
3183 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3184 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3185 	TEST_ASSERT_NOT_NULL(ut_params->op,
3186 			"Failed to allocate pktmbuf offload");
3187 	/* Set crypto operation data parameters */
3188 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3189 
3190 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3191 
3192 	/* set crypto operation source mbuf */
3193 	sym_op->m_src = ut_params->ibuf;
3194 
3195 	/* digest */
3196 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
3197 			ut_params->ibuf, auth_tag_len);
3198 
3199 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
3200 			"no room to append auth tag");
3201 	ut_params->digest = sym_op->auth.digest.data;
3202 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
3203 			ut_params->ibuf, data_pad_len);
3204 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
3205 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
3206 	else
3207 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3208 
3209 	debug_hexdump(stdout, "digest:",
3210 		sym_op->auth.digest.data,
3211 		auth_tag_len);
3212 
3213 	/* Copy cipher and auth IVs at the end of the crypto operation */
3214 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
3215 						IV_OFFSET);
3216 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
3217 	iv_ptr += cipher_iv_len;
3218 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
3219 
3220 	sym_op->cipher.data.length = cipher_len;
3221 	sym_op->cipher.data.offset = 0;
3222 	sym_op->auth.data.length = auth_len;
3223 	sym_op->auth.data.offset = 0;
3224 
3225 	return 0;
3226 }
3227 
3228 static int
3229 create_zuc_cipher_hash_generate_operation(
3230 		const struct wireless_test_data *tdata)
3231 {
3232 	return create_wireless_cipher_hash_operation(tdata,
3233 		RTE_CRYPTO_AUTH_OP_GENERATE);
3234 }
3235 
3236 static int
3237 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
3238 		const unsigned auth_tag_len,
3239 		const uint8_t *auth_iv, uint8_t auth_iv_len,
3240 		unsigned data_pad_len,
3241 		enum rte_crypto_auth_operation op,
3242 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
3243 		const unsigned cipher_len, const unsigned cipher_offset,
3244 		const unsigned auth_len, const unsigned auth_offset)
3245 {
3246 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3247 	struct crypto_unittest_params *ut_params = &unittest_params;
3248 
3249 	enum rte_crypto_cipher_algorithm cipher_algo =
3250 			ut_params->cipher_xform.cipher.algo;
3251 	enum rte_crypto_auth_algorithm auth_algo =
3252 			ut_params->auth_xform.auth.algo;
3253 
3254 	/* Generate Crypto op data structure */
3255 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3256 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3257 	TEST_ASSERT_NOT_NULL(ut_params->op,
3258 			"Failed to allocate pktmbuf offload");
3259 	/* Set crypto operation data parameters */
3260 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3261 
3262 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3263 
3264 	/* set crypto operation source mbuf */
3265 	sym_op->m_src = ut_params->ibuf;
3266 
3267 	/* digest */
3268 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
3269 			ut_params->ibuf, auth_tag_len);
3270 
3271 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
3272 			"no room to append auth tag");
3273 	ut_params->digest = sym_op->auth.digest.data;
3274 
3275 	if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
3276 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
3277 				ut_params->ibuf, data_pad_len);
3278 	} else {
3279 		struct rte_mbuf *m = ut_params->ibuf;
3280 		unsigned int offset = data_pad_len;
3281 
3282 		while (offset > m->data_len && m->next != NULL) {
3283 			offset -= m->data_len;
3284 			m = m->next;
3285 		}
3286 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
3287 			m, offset);
3288 	}
3289 
3290 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
3291 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
3292 	else
3293 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3294 
3295 	debug_hexdump(stdout, "digest:",
3296 		sym_op->auth.digest.data,
3297 		auth_tag_len);
3298 
3299 	/* Copy cipher and auth IVs at the end of the crypto operation */
3300 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
3301 						IV_OFFSET);
3302 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
3303 	iv_ptr += cipher_iv_len;
3304 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
3305 
3306 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
3307 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
3308 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
3309 		sym_op->cipher.data.length = cipher_len;
3310 		sym_op->cipher.data.offset = cipher_offset;
3311 	} else {
3312 		sym_op->cipher.data.length = cipher_len >> 3;
3313 		sym_op->cipher.data.offset = cipher_offset >> 3;
3314 	}
3315 
3316 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
3317 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
3318 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
3319 		sym_op->auth.data.length = auth_len;
3320 		sym_op->auth.data.offset = auth_offset;
3321 	} else {
3322 		sym_op->auth.data.length = auth_len >> 3;
3323 		sym_op->auth.data.offset = auth_offset >> 3;
3324 	}
3325 
3326 	return 0;
3327 }
3328 
3329 static int
3330 create_wireless_algo_auth_cipher_operation(
3331 		const uint8_t *auth_tag, unsigned int auth_tag_len,
3332 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
3333 		const uint8_t *auth_iv, uint8_t auth_iv_len,
3334 		unsigned int data_pad_len,
3335 		unsigned int cipher_len, unsigned int cipher_offset,
3336 		unsigned int auth_len, unsigned int auth_offset,
3337 		uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
3338 {
3339 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3340 	struct crypto_unittest_params *ut_params = &unittest_params;
3341 
3342 	enum rte_crypto_cipher_algorithm cipher_algo =
3343 			ut_params->cipher_xform.cipher.algo;
3344 	enum rte_crypto_auth_algorithm auth_algo =
3345 			ut_params->auth_xform.auth.algo;
3346 
3347 	/* Generate Crypto op data structure */
3348 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3349 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3350 	TEST_ASSERT_NOT_NULL(ut_params->op,
3351 			"Failed to allocate pktmbuf offload");
3352 
3353 	/* Set crypto operation data parameters */
3354 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3355 
3356 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3357 
3358 	/* set crypto operation mbufs */
3359 	sym_op->m_src = ut_params->ibuf;
3360 	if (op_mode == OUT_OF_PLACE)
3361 		sym_op->m_dst = ut_params->obuf;
3362 
3363 	/* digest */
3364 	if (!do_sgl) {
3365 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
3366 			(op_mode == IN_PLACE ?
3367 				ut_params->ibuf : ut_params->obuf),
3368 			uint8_t *, data_pad_len);
3369 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
3370 			(op_mode == IN_PLACE ?
3371 				ut_params->ibuf : ut_params->obuf),
3372 			data_pad_len);
3373 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
3374 	} else {
3375 		uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
3376 		struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
3377 				sym_op->m_src : sym_op->m_dst);
3378 		while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
3379 			remaining_off -= rte_pktmbuf_data_len(sgl_buf);
3380 			sgl_buf = sgl_buf->next;
3381 		}
3382 
3383 		/* The last segment should be large enough to hold full digest */
3384 		if (sgl_buf->data_len < auth_tag_len) {
3385 			rte_pktmbuf_free(sgl_buf->next);
3386 			sgl_buf->next = NULL;
3387 			TEST_ASSERT_NOT_NULL(rte_pktmbuf_append(sgl_buf,
3388 					auth_tag_len - sgl_buf->data_len),
3389 					"No room to append auth tag");
3390 		}
3391 
3392 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
3393 				uint8_t *, remaining_off);
3394 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
3395 				remaining_off);
3396 		memset(sym_op->auth.digest.data, 0, remaining_off);
3397 		while (sgl_buf->next != NULL) {
3398 			memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
3399 				0, rte_pktmbuf_data_len(sgl_buf));
3400 			sgl_buf = sgl_buf->next;
3401 		}
3402 	}
3403 
3404 	/* Copy digest for the verification */
3405 	if (verify)
3406 		memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3407 
3408 	/* Copy cipher and auth IVs at the end of the crypto operation */
3409 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
3410 			ut_params->op, uint8_t *, IV_OFFSET);
3411 
3412 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
3413 	iv_ptr += cipher_iv_len;
3414 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
3415 
3416 	/* Only copy over the offset data needed from src to dst in OOP,
3417 	 * if the auth and cipher offsets are not aligned
3418 	 */
3419 	if (op_mode == OUT_OF_PLACE) {
3420 		if (cipher_offset > auth_offset)
3421 			rte_memcpy(
3422 				rte_pktmbuf_mtod_offset(
3423 					sym_op->m_dst,
3424 					uint8_t *, auth_offset >> 3),
3425 				rte_pktmbuf_mtod_offset(
3426 					sym_op->m_src,
3427 					uint8_t *, auth_offset >> 3),
3428 				((cipher_offset >> 3) - (auth_offset >> 3)));
3429 	}
3430 
3431 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
3432 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
3433 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
3434 		sym_op->cipher.data.length = cipher_len;
3435 		sym_op->cipher.data.offset = cipher_offset;
3436 	} else {
3437 		sym_op->cipher.data.length = cipher_len >> 3;
3438 		sym_op->cipher.data.offset = cipher_offset >> 3;
3439 	}
3440 
3441 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
3442 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
3443 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
3444 		sym_op->auth.data.length = auth_len;
3445 		sym_op->auth.data.offset = auth_offset;
3446 	} else {
3447 		sym_op->auth.data.length = auth_len >> 3;
3448 		sym_op->auth.data.offset = auth_offset >> 3;
3449 	}
3450 
3451 	return 0;
3452 }
3453 
3454 static int
3455 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
3456 {
3457 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3458 	struct crypto_unittest_params *ut_params = &unittest_params;
3459 
3460 	int retval;
3461 	unsigned plaintext_pad_len;
3462 	unsigned plaintext_len;
3463 	uint8_t *plaintext;
3464 	struct rte_cryptodev_info dev_info;
3465 
3466 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3467 	uint64_t feat_flags = dev_info.feature_flags;
3468 
3469 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3470 			((tdata->validAuthLenInBits.len % 8) != 0)) {
3471 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3472 		return TEST_SKIPPED;
3473 	}
3474 
3475 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3476 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3477 		printf("Device doesn't support RAW data-path APIs.\n");
3478 		return TEST_SKIPPED;
3479 	}
3480 
3481 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3482 		return TEST_SKIPPED;
3483 
3484 	/* Verify the capabilities */
3485 	struct rte_cryptodev_sym_capability_idx cap_idx;
3486 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3487 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3488 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3489 			&cap_idx) == NULL)
3490 		return TEST_SKIPPED;
3491 
3492 	/* Create SNOW 3G session */
3493 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3494 			tdata->key.data, tdata->key.len,
3495 			tdata->auth_iv.len, tdata->digest.len,
3496 			RTE_CRYPTO_AUTH_OP_GENERATE,
3497 			RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3498 	if (retval < 0)
3499 		return retval;
3500 
3501 	/* alloc mbuf and set payload */
3502 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3503 
3504 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3505 	rte_pktmbuf_tailroom(ut_params->ibuf));
3506 
3507 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3508 	/* Append data which is padded to a multiple of */
3509 	/* the algorithms block size */
3510 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3511 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3512 				plaintext_pad_len);
3513 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3514 
3515 	/* Create SNOW 3G operation */
3516 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3517 			tdata->auth_iv.data, tdata->auth_iv.len,
3518 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3519 			tdata->validAuthLenInBits.len,
3520 			0);
3521 	if (retval < 0)
3522 		return retval;
3523 
3524 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
3525 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1,
3526 					       0);
3527 		if (retval != TEST_SUCCESS)
3528 			return retval;
3529 	} else
3530 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3531 				ut_params->op);
3532 	ut_params->obuf = ut_params->op->sym->m_src;
3533 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3534 	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
3535 						    uint8_t *,
3536 						    plaintext_pad_len);
3537 
3538 	/* Validate obuf */
3539 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3540 	ut_params->digest,
3541 	tdata->digest.data,
3542 	DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3543 	"SNOW 3G Generated auth tag not as expected");
3544 
3545 	return 0;
3546 }
3547 
3548 static int
3549 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
3550 {
3551 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3552 	struct crypto_unittest_params *ut_params = &unittest_params;
3553 
3554 	int retval;
3555 	unsigned plaintext_pad_len;
3556 	unsigned plaintext_len;
3557 	uint8_t *plaintext;
3558 	struct rte_cryptodev_info dev_info;
3559 
3560 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3561 	uint64_t feat_flags = dev_info.feature_flags;
3562 
3563 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3564 			((tdata->validAuthLenInBits.len % 8) != 0)) {
3565 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3566 		return TEST_SKIPPED;
3567 	}
3568 
3569 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3570 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3571 		printf("Device doesn't support RAW data-path APIs.\n");
3572 		return TEST_SKIPPED;
3573 	}
3574 
3575 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3576 		return TEST_SKIPPED;
3577 
3578 	/* Verify the capabilities */
3579 	struct rte_cryptodev_sym_capability_idx cap_idx;
3580 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3581 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3582 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3583 			&cap_idx) == NULL)
3584 		return TEST_SKIPPED;
3585 
3586 	/* Create SNOW 3G session */
3587 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3588 				tdata->key.data, tdata->key.len,
3589 				tdata->auth_iv.len, tdata->digest.len,
3590 				RTE_CRYPTO_AUTH_OP_VERIFY,
3591 				RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3592 	if (retval < 0)
3593 		return retval;
3594 	/* alloc mbuf and set payload */
3595 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3596 
3597 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3598 	rte_pktmbuf_tailroom(ut_params->ibuf));
3599 
3600 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3601 	/* Append data which is padded to a multiple of */
3602 	/* the algorithms block size */
3603 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3604 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3605 				plaintext_pad_len);
3606 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3607 
3608 	/* Create SNOW 3G operation */
3609 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
3610 			tdata->digest.len,
3611 			tdata->auth_iv.data, tdata->auth_iv.len,
3612 			plaintext_pad_len,
3613 			RTE_CRYPTO_AUTH_OP_VERIFY,
3614 			tdata->validAuthLenInBits.len,
3615 			0);
3616 	if (retval < 0)
3617 		return retval;
3618 
3619 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
3620 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1,
3621 					       0);
3622 		if (retval != TEST_SUCCESS)
3623 			return retval;
3624 	} else
3625 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3626 				ut_params->op);
3627 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3628 	ut_params->obuf = ut_params->op->sym->m_src;
3629 	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
3630 						    uint8_t *,
3631 						    plaintext_pad_len);
3632 
3633 	/* Validate obuf */
3634 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3635 		return 0;
3636 	else
3637 		return -1;
3638 
3639 	return 0;
3640 }
3641 
3642 static int
3643 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
3644 {
3645 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3646 	struct crypto_unittest_params *ut_params = &unittest_params;
3647 
3648 	int retval;
3649 	unsigned plaintext_pad_len;
3650 	unsigned plaintext_len;
3651 	uint8_t *plaintext;
3652 	struct rte_cryptodev_info dev_info;
3653 
3654 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3655 	uint64_t feat_flags = dev_info.feature_flags;
3656 
3657 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3658 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3659 		printf("Device doesn't support RAW data-path APIs.\n");
3660 		return TEST_SKIPPED;
3661 	}
3662 
3663 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3664 		return TEST_SKIPPED;
3665 
3666 	/* Verify the capabilities */
3667 	struct rte_cryptodev_sym_capability_idx cap_idx;
3668 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3669 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3670 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3671 			&cap_idx) == NULL)
3672 		return TEST_SKIPPED;
3673 
3674 	/* Create KASUMI session */
3675 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3676 			tdata->key.data, tdata->key.len,
3677 			0, tdata->digest.len,
3678 			RTE_CRYPTO_AUTH_OP_GENERATE,
3679 			RTE_CRYPTO_AUTH_KASUMI_F9);
3680 	if (retval < 0)
3681 		return retval;
3682 
3683 	/* alloc mbuf and set payload */
3684 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3685 
3686 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3687 	rte_pktmbuf_tailroom(ut_params->ibuf));
3688 
3689 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3690 	/* Append data which is padded to a multiple of */
3691 	/* the algorithms block size */
3692 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3693 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3694 				plaintext_pad_len);
3695 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3696 
3697 	/* Create KASUMI operation */
3698 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3699 			NULL, 0,
3700 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3701 			tdata->plaintext.len,
3702 			0);
3703 	if (retval < 0)
3704 		return retval;
3705 
3706 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3707 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
3708 			ut_params->op);
3709 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
3710 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1,
3711 					       0);
3712 		if (retval != TEST_SUCCESS)
3713 			return retval;
3714 	} else
3715 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3716 			ut_params->op);
3717 
3718 	ut_params->obuf = ut_params->op->sym->m_src;
3719 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3720 	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
3721 						    uint8_t *,
3722 						    plaintext_pad_len);
3723 
3724 	/* Validate obuf */
3725 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3726 	ut_params->digest,
3727 	tdata->digest.data,
3728 	DIGEST_BYTE_LENGTH_KASUMI_F9,
3729 	"KASUMI Generated auth tag not as expected");
3730 
3731 	return 0;
3732 }
3733 
3734 static int
3735 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
3736 {
3737 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3738 	struct crypto_unittest_params *ut_params = &unittest_params;
3739 
3740 	int retval;
3741 	unsigned plaintext_pad_len;
3742 	unsigned plaintext_len;
3743 	uint8_t *plaintext;
3744 	struct rte_cryptodev_info dev_info;
3745 
3746 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3747 	uint64_t feat_flags = dev_info.feature_flags;
3748 
3749 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3750 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3751 		printf("Device doesn't support RAW data-path APIs.\n");
3752 		return TEST_SKIPPED;
3753 	}
3754 
3755 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3756 		return TEST_SKIPPED;
3757 
3758 	/* Verify the capabilities */
3759 	struct rte_cryptodev_sym_capability_idx cap_idx;
3760 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3761 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3762 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3763 			&cap_idx) == NULL)
3764 		return TEST_SKIPPED;
3765 
3766 	/* Create KASUMI session */
3767 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3768 				tdata->key.data, tdata->key.len,
3769 				0, tdata->digest.len,
3770 				RTE_CRYPTO_AUTH_OP_VERIFY,
3771 				RTE_CRYPTO_AUTH_KASUMI_F9);
3772 	if (retval < 0)
3773 		return retval;
3774 	/* alloc mbuf and set payload */
3775 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3776 
3777 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3778 	rte_pktmbuf_tailroom(ut_params->ibuf));
3779 
3780 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3781 	/* Append data which is padded to a multiple */
3782 	/* of the algorithms block size */
3783 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3784 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3785 				plaintext_pad_len);
3786 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3787 
3788 	/* Create KASUMI operation */
3789 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
3790 			tdata->digest.len,
3791 			NULL, 0,
3792 			plaintext_pad_len,
3793 			RTE_CRYPTO_AUTH_OP_VERIFY,
3794 			tdata->plaintext.len,
3795 			0);
3796 	if (retval < 0)
3797 		return retval;
3798 
3799 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
3800 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1,
3801 					       0);
3802 		if (retval != TEST_SUCCESS)
3803 			return retval;
3804 	} else
3805 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3806 				ut_params->op);
3807 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3808 	ut_params->obuf = ut_params->op->sym->m_src;
3809 	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
3810 						    uint8_t *,
3811 						    plaintext_pad_len);
3812 
3813 	/* Validate obuf */
3814 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3815 		return 0;
3816 	else
3817 		return -1;
3818 
3819 	return 0;
3820 }
3821 
3822 static int
3823 test_snow3g_hash_generate_test_case_1(void)
3824 {
3825 	return test_snow3g_authentication(&snow3g_hash_test_case_1);
3826 }
3827 
3828 static int
3829 test_snow3g_hash_generate_test_case_2(void)
3830 {
3831 	return test_snow3g_authentication(&snow3g_hash_test_case_2);
3832 }
3833 
3834 static int
3835 test_snow3g_hash_generate_test_case_3(void)
3836 {
3837 	return test_snow3g_authentication(&snow3g_hash_test_case_3);
3838 }
3839 
3840 static int
3841 test_snow3g_hash_generate_test_case_4(void)
3842 {
3843 	return test_snow3g_authentication(&snow3g_hash_test_case_4);
3844 }
3845 
3846 static int
3847 test_snow3g_hash_generate_test_case_5(void)
3848 {
3849 	return test_snow3g_authentication(&snow3g_hash_test_case_5);
3850 }
3851 
3852 static int
3853 test_snow3g_hash_generate_test_case_6(void)
3854 {
3855 	return test_snow3g_authentication(&snow3g_hash_test_case_6);
3856 }
3857 
3858 static int
3859 test_snow3g_hash_verify_test_case_1(void)
3860 {
3861 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3862 
3863 }
3864 
3865 static int
3866 test_snow3g_hash_verify_test_case_2(void)
3867 {
3868 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3869 }
3870 
3871 static int
3872 test_snow3g_hash_verify_test_case_3(void)
3873 {
3874 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3875 }
3876 
3877 static int
3878 test_snow3g_hash_verify_test_case_4(void)
3879 {
3880 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3881 }
3882 
3883 static int
3884 test_snow3g_hash_verify_test_case_5(void)
3885 {
3886 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3887 }
3888 
3889 static int
3890 test_snow3g_hash_verify_test_case_6(void)
3891 {
3892 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3893 }
3894 
3895 static int
3896 test_kasumi_hash_generate_test_case_1(void)
3897 {
3898 	return test_kasumi_authentication(&kasumi_hash_test_case_1);
3899 }
3900 
3901 static int
3902 test_kasumi_hash_generate_test_case_2(void)
3903 {
3904 	return test_kasumi_authentication(&kasumi_hash_test_case_2);
3905 }
3906 
3907 static int
3908 test_kasumi_hash_generate_test_case_3(void)
3909 {
3910 	return test_kasumi_authentication(&kasumi_hash_test_case_3);
3911 }
3912 
3913 static int
3914 test_kasumi_hash_generate_test_case_4(void)
3915 {
3916 	return test_kasumi_authentication(&kasumi_hash_test_case_4);
3917 }
3918 
3919 static int
3920 test_kasumi_hash_generate_test_case_5(void)
3921 {
3922 	return test_kasumi_authentication(&kasumi_hash_test_case_5);
3923 }
3924 
3925 static int
3926 test_kasumi_hash_generate_test_case_6(void)
3927 {
3928 	return test_kasumi_authentication(&kasumi_hash_test_case_6);
3929 }
3930 
3931 static int
3932 test_kasumi_hash_verify_test_case_1(void)
3933 {
3934 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3935 }
3936 
3937 static int
3938 test_kasumi_hash_verify_test_case_2(void)
3939 {
3940 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3941 }
3942 
3943 static int
3944 test_kasumi_hash_verify_test_case_3(void)
3945 {
3946 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3947 }
3948 
3949 static int
3950 test_kasumi_hash_verify_test_case_4(void)
3951 {
3952 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3953 }
3954 
3955 static int
3956 test_kasumi_hash_verify_test_case_5(void)
3957 {
3958 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3959 }
3960 
3961 static int
3962 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3963 {
3964 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3965 	struct crypto_unittest_params *ut_params = &unittest_params;
3966 
3967 	int retval;
3968 	uint8_t *plaintext, *ciphertext;
3969 	unsigned plaintext_pad_len;
3970 	unsigned plaintext_len;
3971 	struct rte_cryptodev_info dev_info;
3972 
3973 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3974 	uint64_t feat_flags = dev_info.feature_flags;
3975 
3976 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3977 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3978 		printf("Device doesn't support RAW data-path APIs.\n");
3979 		return TEST_SKIPPED;
3980 	}
3981 
3982 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3983 		return TEST_SKIPPED;
3984 
3985 	/* Verify the capabilities */
3986 	struct rte_cryptodev_sym_capability_idx cap_idx;
3987 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3988 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3989 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3990 			&cap_idx) == NULL)
3991 		return TEST_SKIPPED;
3992 
3993 	/* Create KASUMI session */
3994 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3995 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3996 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3997 					tdata->key.data, tdata->key.len,
3998 					tdata->cipher_iv.len);
3999 	if (retval < 0)
4000 		return retval;
4001 
4002 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4003 
4004 	/* Clear mbuf payload */
4005 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4006 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4007 
4008 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4009 	/* Append data which is padded to a multiple */
4010 	/* of the algorithms block size */
4011 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
4012 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4013 				plaintext_pad_len);
4014 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4015 
4016 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4017 
4018 	/* Create KASUMI operation */
4019 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4020 				tdata->cipher_iv.len,
4021 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
4022 				tdata->validCipherOffsetInBits.len);
4023 	if (retval < 0)
4024 		return retval;
4025 
4026 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
4027 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
4028 					       tdata->cipher_iv.len);
4029 		if (retval != TEST_SUCCESS)
4030 			return retval;
4031 	} else
4032 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4033 				ut_params->op);
4034 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4035 
4036 	ut_params->obuf = ut_params->op->sym->m_dst;
4037 	if (ut_params->obuf)
4038 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4039 	else
4040 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
4041 
4042 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4043 
4044 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
4045 				(tdata->validCipherOffsetInBits.len >> 3);
4046 	/* Validate obuf */
4047 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4048 		ciphertext,
4049 		reference_ciphertext,
4050 		tdata->validCipherLenInBits.len,
4051 		"KASUMI Ciphertext data not as expected");
4052 	return 0;
4053 }
4054 
4055 static int
4056 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
4057 {
4058 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4059 	struct crypto_unittest_params *ut_params = &unittest_params;
4060 
4061 	int retval;
4062 
4063 	unsigned int plaintext_pad_len;
4064 	unsigned int plaintext_len;
4065 
4066 	uint8_t buffer[10000];
4067 	const uint8_t *ciphertext;
4068 
4069 	struct rte_cryptodev_info dev_info;
4070 
4071 	/* Verify the capabilities */
4072 	struct rte_cryptodev_sym_capability_idx cap_idx;
4073 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4074 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4075 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4076 			&cap_idx) == NULL)
4077 		return TEST_SKIPPED;
4078 
4079 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4080 
4081 	uint64_t feat_flags = dev_info.feature_flags;
4082 
4083 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
4084 		printf("Device doesn't support in-place scatter-gather. "
4085 				"Test Skipped.\n");
4086 		return TEST_SKIPPED;
4087 	}
4088 
4089 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4090 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4091 		printf("Device doesn't support RAW data-path APIs.\n");
4092 		return TEST_SKIPPED;
4093 	}
4094 
4095 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4096 		return TEST_SKIPPED;
4097 
4098 	/* Create KASUMI session */
4099 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4100 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4101 					RTE_CRYPTO_CIPHER_KASUMI_F8,
4102 					tdata->key.data, tdata->key.len,
4103 					tdata->cipher_iv.len);
4104 	if (retval < 0)
4105 		return retval;
4106 
4107 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4108 
4109 
4110 	/* Append data which is padded to a multiple */
4111 	/* of the algorithms block size */
4112 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
4113 
4114 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4115 			plaintext_pad_len, 10, 0);
4116 
4117 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4118 
4119 	/* Create KASUMI operation */
4120 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4121 				tdata->cipher_iv.len,
4122 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
4123 				tdata->validCipherOffsetInBits.len);
4124 	if (retval < 0)
4125 		return retval;
4126 
4127 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
4128 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
4129 					       tdata->cipher_iv.len);
4130 		if (retval != TEST_SUCCESS)
4131 			return retval;
4132 	} else
4133 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4134 						ut_params->op);
4135 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4136 
4137 	ut_params->obuf = ut_params->op->sym->m_dst;
4138 
4139 	if (ut_params->obuf)
4140 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4141 				plaintext_len, buffer);
4142 	else
4143 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
4144 				tdata->validCipherOffsetInBits.len >> 3,
4145 				plaintext_len, buffer);
4146 
4147 	/* Validate obuf */
4148 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4149 
4150 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
4151 				(tdata->validCipherOffsetInBits.len >> 3);
4152 	/* Validate obuf */
4153 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4154 		ciphertext,
4155 		reference_ciphertext,
4156 		tdata->validCipherLenInBits.len,
4157 		"KASUMI Ciphertext data not as expected");
4158 	return 0;
4159 }
4160 
4161 static int
4162 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
4163 {
4164 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4165 	struct crypto_unittest_params *ut_params = &unittest_params;
4166 
4167 	int retval;
4168 	uint8_t *plaintext, *ciphertext;
4169 	unsigned plaintext_pad_len;
4170 	unsigned plaintext_len;
4171 
4172 	/* Verify the capabilities */
4173 	struct rte_cryptodev_sym_capability_idx cap_idx;
4174 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4175 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4176 	/* Data-path service does not support OOP */
4177 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4178 			&cap_idx) == NULL)
4179 		return TEST_SKIPPED;
4180 
4181 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4182 		return TEST_SKIPPED;
4183 
4184 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4185 		return TEST_SKIPPED;
4186 
4187 	/* Create KASUMI session */
4188 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4189 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4190 					RTE_CRYPTO_CIPHER_KASUMI_F8,
4191 					tdata->key.data, tdata->key.len,
4192 					tdata->cipher_iv.len);
4193 	if (retval < 0)
4194 		return retval;
4195 
4196 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4197 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4198 
4199 	/* Clear mbuf payload */
4200 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4201 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4202 
4203 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4204 	/* Append data which is padded to a multiple */
4205 	/* of the algorithms block size */
4206 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
4207 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4208 				plaintext_pad_len);
4209 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4210 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4211 
4212 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4213 
4214 	/* Create KASUMI operation */
4215 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4216 				tdata->cipher_iv.len,
4217 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
4218 				tdata->validCipherOffsetInBits.len);
4219 	if (retval < 0)
4220 		return retval;
4221 
4222 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4223 						ut_params->op);
4224 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4225 
4226 	ut_params->obuf = ut_params->op->sym->m_dst;
4227 	if (ut_params->obuf)
4228 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4229 	else
4230 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
4231 
4232 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4233 
4234 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
4235 				(tdata->validCipherOffsetInBits.len >> 3);
4236 	/* Validate obuf */
4237 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4238 		ciphertext,
4239 		reference_ciphertext,
4240 		tdata->validCipherLenInBits.len,
4241 		"KASUMI Ciphertext data not as expected");
4242 	return 0;
4243 }
4244 
4245 static int
4246 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
4247 {
4248 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4249 	struct crypto_unittest_params *ut_params = &unittest_params;
4250 
4251 	int retval;
4252 	unsigned int plaintext_pad_len;
4253 	unsigned int plaintext_len;
4254 
4255 	const uint8_t *ciphertext;
4256 	uint8_t buffer[2048];
4257 
4258 	struct rte_cryptodev_info dev_info;
4259 
4260 	/* Verify the capabilities */
4261 	struct rte_cryptodev_sym_capability_idx cap_idx;
4262 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4263 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4264 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4265 			&cap_idx) == NULL)
4266 		return TEST_SKIPPED;
4267 
4268 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4269 		return TEST_SKIPPED;
4270 
4271 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4272 		return TEST_SKIPPED;
4273 
4274 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4275 
4276 	uint64_t feat_flags = dev_info.feature_flags;
4277 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4278 		printf("Device doesn't support out-of-place scatter-gather "
4279 				"in both input and output mbufs. "
4280 				"Test Skipped.\n");
4281 		return TEST_SKIPPED;
4282 	}
4283 
4284 	/* Create KASUMI session */
4285 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4286 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4287 					RTE_CRYPTO_CIPHER_KASUMI_F8,
4288 					tdata->key.data, tdata->key.len,
4289 					tdata->cipher_iv.len);
4290 	if (retval < 0)
4291 		return retval;
4292 
4293 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4294 	/* Append data which is padded to a multiple */
4295 	/* of the algorithms block size */
4296 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
4297 
4298 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4299 			plaintext_pad_len, 10, 0);
4300 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4301 			plaintext_pad_len, 3, 0);
4302 
4303 	/* Append data which is padded to a multiple */
4304 	/* of the algorithms block size */
4305 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4306 
4307 	/* Create KASUMI operation */
4308 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4309 				tdata->cipher_iv.len,
4310 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
4311 				tdata->validCipherOffsetInBits.len);
4312 	if (retval < 0)
4313 		return retval;
4314 
4315 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4316 						ut_params->op);
4317 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4318 
4319 	ut_params->obuf = ut_params->op->sym->m_dst;
4320 	if (ut_params->obuf)
4321 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4322 				plaintext_pad_len, buffer);
4323 	else
4324 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
4325 				tdata->validCipherOffsetInBits.len >> 3,
4326 				plaintext_pad_len, buffer);
4327 
4328 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
4329 				(tdata->validCipherOffsetInBits.len >> 3);
4330 	/* Validate obuf */
4331 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4332 		ciphertext,
4333 		reference_ciphertext,
4334 		tdata->validCipherLenInBits.len,
4335 		"KASUMI Ciphertext data not as expected");
4336 	return 0;
4337 }
4338 
4339 
4340 static int
4341 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
4342 {
4343 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4344 	struct crypto_unittest_params *ut_params = &unittest_params;
4345 
4346 	int retval;
4347 	uint8_t *ciphertext, *plaintext;
4348 	unsigned ciphertext_pad_len;
4349 	unsigned ciphertext_len;
4350 
4351 	/* Verify the capabilities */
4352 	struct rte_cryptodev_sym_capability_idx cap_idx;
4353 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4354 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4355 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4356 			&cap_idx) == NULL)
4357 		return TEST_SKIPPED;
4358 
4359 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4360 		return TEST_SKIPPED;
4361 
4362 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4363 		return TEST_SKIPPED;
4364 
4365 	/* Create KASUMI session */
4366 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4367 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4368 					RTE_CRYPTO_CIPHER_KASUMI_F8,
4369 					tdata->key.data, tdata->key.len,
4370 					tdata->cipher_iv.len);
4371 	if (retval < 0)
4372 		return retval;
4373 
4374 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4375 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4376 
4377 	/* Clear mbuf payload */
4378 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4379 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4380 
4381 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4382 	/* Append data which is padded to a multiple */
4383 	/* of the algorithms block size */
4384 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4385 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4386 				ciphertext_pad_len);
4387 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4388 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4389 
4390 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4391 
4392 	/* Create KASUMI operation */
4393 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4394 				tdata->cipher_iv.len,
4395 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
4396 				tdata->validCipherOffsetInBits.len);
4397 	if (retval < 0)
4398 		return retval;
4399 
4400 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4401 						ut_params->op);
4402 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4403 
4404 	ut_params->obuf = ut_params->op->sym->m_dst;
4405 	if (ut_params->obuf)
4406 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4407 	else
4408 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4409 
4410 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4411 
4412 	const uint8_t *reference_plaintext = tdata->plaintext.data +
4413 				(tdata->validCipherOffsetInBits.len >> 3);
4414 	/* Validate obuf */
4415 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4416 		plaintext,
4417 		reference_plaintext,
4418 		tdata->validCipherLenInBits.len,
4419 		"KASUMI Plaintext data not as expected");
4420 	return 0;
4421 }
4422 
4423 static int
4424 test_kasumi_decryption(const struct kasumi_test_data *tdata)
4425 {
4426 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4427 	struct crypto_unittest_params *ut_params = &unittest_params;
4428 
4429 	int retval;
4430 	uint8_t *ciphertext, *plaintext;
4431 	unsigned ciphertext_pad_len;
4432 	unsigned ciphertext_len;
4433 	struct rte_cryptodev_info dev_info;
4434 
4435 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4436 	uint64_t feat_flags = dev_info.feature_flags;
4437 
4438 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4439 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4440 		printf("Device doesn't support RAW data-path APIs.\n");
4441 		return TEST_SKIPPED;
4442 	}
4443 
4444 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4445 		return TEST_SKIPPED;
4446 
4447 	/* Verify the capabilities */
4448 	struct rte_cryptodev_sym_capability_idx cap_idx;
4449 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4450 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4451 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4452 			&cap_idx) == NULL)
4453 		return TEST_SKIPPED;
4454 
4455 	/* Create KASUMI session */
4456 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4457 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4458 					RTE_CRYPTO_CIPHER_KASUMI_F8,
4459 					tdata->key.data, tdata->key.len,
4460 					tdata->cipher_iv.len);
4461 	if (retval < 0)
4462 		return retval;
4463 
4464 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4465 
4466 	/* Clear mbuf payload */
4467 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4468 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4469 
4470 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4471 	/* Append data which is padded to a multiple */
4472 	/* of the algorithms block size */
4473 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4474 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4475 				ciphertext_pad_len);
4476 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4477 
4478 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4479 
4480 	/* Create KASUMI operation */
4481 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4482 			tdata->cipher_iv.len,
4483 			RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
4484 			tdata->validCipherOffsetInBits.len);
4485 	if (retval < 0)
4486 		return retval;
4487 
4488 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
4489 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
4490 					       0);
4491 		if (retval != TEST_SUCCESS)
4492 			return retval;
4493 	} else
4494 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4495 						ut_params->op);
4496 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4497 
4498 	ut_params->obuf = ut_params->op->sym->m_dst;
4499 	if (ut_params->obuf)
4500 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4501 	else
4502 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4503 
4504 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4505 
4506 	const uint8_t *reference_plaintext = tdata->plaintext.data +
4507 				(tdata->validCipherOffsetInBits.len >> 3);
4508 	/* Validate obuf */
4509 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4510 		plaintext,
4511 		reference_plaintext,
4512 		tdata->validCipherLenInBits.len,
4513 		"KASUMI Plaintext data not as expected");
4514 	return 0;
4515 }
4516 
4517 static int
4518 test_snow3g_encryption(const struct snow3g_test_data *tdata)
4519 {
4520 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4521 	struct crypto_unittest_params *ut_params = &unittest_params;
4522 
4523 	int retval;
4524 	uint8_t *plaintext, *ciphertext;
4525 	unsigned plaintext_pad_len;
4526 	unsigned plaintext_len;
4527 	struct rte_cryptodev_info dev_info;
4528 
4529 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4530 	uint64_t feat_flags = dev_info.feature_flags;
4531 
4532 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4533 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4534 		printf("Device doesn't support RAW data-path APIs.\n");
4535 		return TEST_SKIPPED;
4536 	}
4537 
4538 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4539 		return TEST_SKIPPED;
4540 
4541 	/* Verify the capabilities */
4542 	struct rte_cryptodev_sym_capability_idx cap_idx;
4543 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4544 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4545 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4546 			&cap_idx) == NULL)
4547 		return TEST_SKIPPED;
4548 
4549 	/* Create SNOW 3G session */
4550 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4551 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4552 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4553 					tdata->key.data, tdata->key.len,
4554 					tdata->cipher_iv.len);
4555 	if (retval < 0)
4556 		return retval;
4557 
4558 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4559 
4560 	/* Clear mbuf payload */
4561 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4562 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4563 
4564 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4565 	/* Append data which is padded to a multiple of */
4566 	/* the algorithms block size */
4567 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4568 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4569 				plaintext_pad_len);
4570 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4571 
4572 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4573 
4574 	/* Create SNOW 3G operation */
4575 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4576 					tdata->cipher_iv.len,
4577 					tdata->validCipherLenInBits.len,
4578 					0);
4579 	if (retval < 0)
4580 		return retval;
4581 
4582 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
4583 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
4584 					       tdata->cipher_iv.len);
4585 		if (retval != TEST_SUCCESS)
4586 			return retval;
4587 	} else
4588 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4589 						ut_params->op);
4590 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4591 
4592 	ut_params->obuf = ut_params->op->sym->m_dst;
4593 	if (ut_params->obuf)
4594 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4595 	else
4596 		ciphertext = plaintext;
4597 
4598 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4599 
4600 	/* Validate obuf */
4601 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4602 		ciphertext,
4603 		tdata->ciphertext.data,
4604 		tdata->validDataLenInBits.len,
4605 		"SNOW 3G Ciphertext data not as expected");
4606 	return 0;
4607 }
4608 
4609 
4610 static int
4611 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
4612 {
4613 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4614 	struct crypto_unittest_params *ut_params = &unittest_params;
4615 	uint8_t *plaintext, *ciphertext;
4616 
4617 	int retval;
4618 	unsigned plaintext_pad_len;
4619 	unsigned plaintext_len;
4620 	struct rte_cryptodev_info dev_info;
4621 
4622 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4623 	uint64_t feat_flags = dev_info.feature_flags;
4624 
4625 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4626 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4627 		printf("Device does not support RAW data-path APIs.\n");
4628 		return -ENOTSUP;
4629 	}
4630 
4631 	/* Verify the capabilities */
4632 	struct rte_cryptodev_sym_capability_idx cap_idx;
4633 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4634 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4635 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4636 			&cap_idx) == NULL)
4637 		return TEST_SKIPPED;
4638 
4639 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4640 		return TEST_SKIPPED;
4641 
4642 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4643 		return TEST_SKIPPED;
4644 
4645 	/* Create SNOW 3G session */
4646 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4647 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4648 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4649 					tdata->key.data, tdata->key.len,
4650 					tdata->cipher_iv.len);
4651 	if (retval < 0)
4652 		return retval;
4653 
4654 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4655 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4656 
4657 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4658 			"Failed to allocate input buffer in mempool");
4659 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4660 			"Failed to allocate output buffer in mempool");
4661 
4662 	/* Clear mbuf payload */
4663 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4664 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4665 
4666 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4667 	/* Append data which is padded to a multiple of */
4668 	/* the algorithms block size */
4669 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4670 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4671 				plaintext_pad_len);
4672 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4673 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4674 
4675 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4676 
4677 	/* Create SNOW 3G operation */
4678 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4679 					tdata->cipher_iv.len,
4680 					tdata->validCipherLenInBits.len,
4681 					0);
4682 	if (retval < 0)
4683 		return retval;
4684 
4685 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
4686 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
4687 					       tdata->cipher_iv.len);
4688 		if (retval != TEST_SUCCESS)
4689 			return retval;
4690 	} else
4691 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4692 						ut_params->op);
4693 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4694 
4695 	ut_params->obuf = ut_params->op->sym->m_dst;
4696 	if (ut_params->obuf)
4697 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4698 	else
4699 		ciphertext = plaintext;
4700 
4701 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4702 
4703 	/* Validate obuf */
4704 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4705 		ciphertext,
4706 		tdata->ciphertext.data,
4707 		tdata->validDataLenInBits.len,
4708 		"SNOW 3G Ciphertext data not as expected");
4709 	return 0;
4710 }
4711 
4712 static int
4713 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata,
4714 		uint8_t sgl_in, uint8_t sgl_out)
4715 {
4716 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4717 	struct crypto_unittest_params *ut_params = &unittest_params;
4718 
4719 	int retval;
4720 	unsigned int plaintext_pad_len;
4721 	unsigned int plaintext_len;
4722 	uint8_t buffer[10000];
4723 	const uint8_t *ciphertext;
4724 
4725 	struct rte_cryptodev_info dev_info;
4726 
4727 	/* Verify the capabilities */
4728 	struct rte_cryptodev_sym_capability_idx cap_idx;
4729 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4730 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4731 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4732 			&cap_idx) == NULL)
4733 		return TEST_SKIPPED;
4734 
4735 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4736 		return TEST_SKIPPED;
4737 
4738 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4739 		return TEST_SKIPPED;
4740 
4741 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4742 
4743 	uint64_t feat_flags = dev_info.feature_flags;
4744 
4745 	if (((sgl_in && sgl_out) && !(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
4746 			|| ((!sgl_in && sgl_out) &&
4747 			!(feat_flags & RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
4748 			|| ((sgl_in && !sgl_out) &&
4749 			!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))) {
4750 		printf("Device doesn't support out-of-place scatter gather type. "
4751 				"Test Skipped.\n");
4752 		return TEST_SKIPPED;
4753 	}
4754 
4755 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4756 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4757 		printf("Device does not support RAW data-path APIs.\n");
4758 		return -ENOTSUP;
4759 	}
4760 
4761 	/* Create SNOW 3G session */
4762 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4763 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4764 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4765 					tdata->key.data, tdata->key.len,
4766 					tdata->cipher_iv.len);
4767 	if (retval < 0)
4768 		return retval;
4769 
4770 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4771 	/* Append data which is padded to a multiple of */
4772 	/* the algorithms block size */
4773 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4774 
4775 	if (sgl_in)
4776 		ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4777 				plaintext_pad_len, 10, 0);
4778 	else {
4779 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4780 		rte_pktmbuf_append(ut_params->ibuf, plaintext_pad_len);
4781 	}
4782 
4783 	if (sgl_out)
4784 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4785 				plaintext_pad_len, 3, 0);
4786 	else {
4787 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4788 		rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4789 	}
4790 
4791 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4792 			"Failed to allocate input buffer in mempool");
4793 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4794 			"Failed to allocate output buffer in mempool");
4795 
4796 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4797 
4798 	/* Create SNOW 3G operation */
4799 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4800 					tdata->cipher_iv.len,
4801 					tdata->validCipherLenInBits.len,
4802 					0);
4803 	if (retval < 0)
4804 		return retval;
4805 
4806 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
4807 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
4808 					       tdata->cipher_iv.len);
4809 		if (retval != TEST_SUCCESS)
4810 			return retval;
4811 	} else
4812 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4813 						ut_params->op);
4814 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4815 
4816 	ut_params->obuf = ut_params->op->sym->m_dst;
4817 	if (ut_params->obuf)
4818 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4819 				plaintext_len, buffer);
4820 	else
4821 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4822 				plaintext_len, buffer);
4823 
4824 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4825 
4826 	/* Validate obuf */
4827 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4828 		ciphertext,
4829 		tdata->ciphertext.data,
4830 		tdata->validDataLenInBits.len,
4831 		"SNOW 3G Ciphertext data not as expected");
4832 
4833 	return 0;
4834 }
4835 
4836 /* Shift right a buffer by "offset" bits, "offset" < 8 */
4837 static void
4838 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
4839 {
4840 	uint8_t curr_byte, prev_byte;
4841 	uint32_t length_in_bytes = ceil_byte_length(length + offset);
4842 	uint8_t lower_byte_mask = (1 << offset) - 1;
4843 	unsigned i;
4844 
4845 	prev_byte = buffer[0];
4846 	buffer[0] >>= offset;
4847 
4848 	for (i = 1; i < length_in_bytes; i++) {
4849 		curr_byte = buffer[i];
4850 		buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
4851 				(curr_byte >> offset);
4852 		prev_byte = curr_byte;
4853 	}
4854 }
4855 
4856 static int
4857 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
4858 {
4859 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4860 	struct crypto_unittest_params *ut_params = &unittest_params;
4861 	uint8_t *plaintext, *ciphertext;
4862 	int retval;
4863 	uint32_t plaintext_len;
4864 	uint32_t plaintext_pad_len;
4865 	uint8_t extra_offset = 4;
4866 	uint8_t *expected_ciphertext_shifted;
4867 	struct rte_cryptodev_info dev_info;
4868 
4869 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4870 	uint64_t feat_flags = dev_info.feature_flags;
4871 
4872 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4873 			((tdata->validDataLenInBits.len % 8) != 0)) {
4874 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4875 		return TEST_SKIPPED;
4876 	}
4877 
4878 	/* Verify the capabilities */
4879 	struct rte_cryptodev_sym_capability_idx cap_idx;
4880 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4881 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4882 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4883 			&cap_idx) == NULL)
4884 		return TEST_SKIPPED;
4885 
4886 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4887 		return TEST_SKIPPED;
4888 
4889 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4890 		return TEST_SKIPPED;
4891 
4892 	/* Create SNOW 3G session */
4893 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4894 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4895 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4896 					tdata->key.data, tdata->key.len,
4897 					tdata->cipher_iv.len);
4898 	if (retval < 0)
4899 		return retval;
4900 
4901 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4902 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4903 
4904 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4905 			"Failed to allocate input buffer in mempool");
4906 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4907 			"Failed to allocate output buffer in mempool");
4908 
4909 	/* Clear mbuf payload */
4910 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4911 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4912 
4913 	plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4914 	/*
4915 	 * Append data which is padded to a
4916 	 * multiple of the algorithms block size
4917 	 */
4918 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4919 
4920 	plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4921 						plaintext_pad_len);
4922 
4923 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4924 
4925 	memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4926 	buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4927 
4928 #ifdef RTE_APP_TEST_DEBUG
4929 	rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4930 #endif
4931 	/* Create SNOW 3G operation */
4932 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4933 					tdata->cipher_iv.len,
4934 					tdata->validCipherLenInBits.len,
4935 					extra_offset);
4936 	if (retval < 0)
4937 		return retval;
4938 
4939 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
4940 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
4941 					       tdata->cipher_iv.len);
4942 		if (retval != TEST_SUCCESS)
4943 			return retval;
4944 	} else
4945 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4946 						ut_params->op);
4947 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4948 
4949 	ut_params->obuf = ut_params->op->sym->m_dst;
4950 	if (ut_params->obuf)
4951 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4952 	else
4953 		ciphertext = plaintext;
4954 
4955 #ifdef RTE_APP_TEST_DEBUG
4956 	rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4957 #endif
4958 
4959 	expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4960 
4961 	TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4962 			"failed to reserve memory for ciphertext shifted\n");
4963 
4964 	memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4965 			ceil_byte_length(tdata->ciphertext.len));
4966 	buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4967 			extra_offset);
4968 	/* Validate obuf */
4969 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4970 		ciphertext,
4971 		expected_ciphertext_shifted,
4972 		tdata->validDataLenInBits.len,
4973 		extra_offset,
4974 		"SNOW 3G Ciphertext data not as expected");
4975 	return 0;
4976 }
4977 
4978 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4979 {
4980 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4981 	struct crypto_unittest_params *ut_params = &unittest_params;
4982 
4983 	int retval;
4984 
4985 	uint8_t *plaintext, *ciphertext;
4986 	unsigned ciphertext_pad_len;
4987 	unsigned ciphertext_len;
4988 	struct rte_cryptodev_info dev_info;
4989 
4990 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4991 	uint64_t feat_flags = dev_info.feature_flags;
4992 
4993 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4994 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4995 		printf("Device doesn't support RAW data-path APIs.\n");
4996 		return TEST_SKIPPED;
4997 	}
4998 
4999 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5000 		return TEST_SKIPPED;
5001 
5002 	/* Verify the capabilities */
5003 	struct rte_cryptodev_sym_capability_idx cap_idx;
5004 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5005 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5006 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5007 			&cap_idx) == NULL)
5008 		return TEST_SKIPPED;
5009 
5010 	/* Create SNOW 3G session */
5011 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5012 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
5013 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5014 					tdata->key.data, tdata->key.len,
5015 					tdata->cipher_iv.len);
5016 	if (retval < 0)
5017 		return retval;
5018 
5019 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5020 
5021 	/* Clear mbuf payload */
5022 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5023 	       rte_pktmbuf_tailroom(ut_params->ibuf));
5024 
5025 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5026 	/* Append data which is padded to a multiple of */
5027 	/* the algorithms block size */
5028 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5029 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5030 				ciphertext_pad_len);
5031 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5032 
5033 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
5034 
5035 	/* Create SNOW 3G operation */
5036 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5037 					tdata->cipher_iv.len,
5038 					tdata->validCipherLenInBits.len,
5039 					tdata->cipher.offset_bits);
5040 	if (retval < 0)
5041 		return retval;
5042 
5043 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
5044 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
5045 					       tdata->cipher_iv.len);
5046 		if (retval != TEST_SUCCESS)
5047 			return retval;
5048 	} else
5049 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5050 						ut_params->op);
5051 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5052 	ut_params->obuf = ut_params->op->sym->m_dst;
5053 	if (ut_params->obuf)
5054 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5055 	else
5056 		plaintext = ciphertext;
5057 
5058 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
5059 
5060 	/* Validate obuf */
5061 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
5062 				tdata->plaintext.data,
5063 				tdata->validDataLenInBits.len,
5064 				"SNOW 3G Plaintext data not as expected");
5065 	return 0;
5066 }
5067 
5068 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
5069 {
5070 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5071 	struct crypto_unittest_params *ut_params = &unittest_params;
5072 
5073 	int retval;
5074 
5075 	uint8_t *plaintext, *ciphertext;
5076 	unsigned ciphertext_pad_len;
5077 	unsigned ciphertext_len;
5078 	struct rte_cryptodev_info dev_info;
5079 
5080 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5081 	uint64_t feat_flags = dev_info.feature_flags;
5082 
5083 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5084 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5085 		printf("Device does not support RAW data-path APIs.\n");
5086 		return -ENOTSUP;
5087 	}
5088 	/* Verify the capabilities */
5089 	struct rte_cryptodev_sym_capability_idx cap_idx;
5090 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5091 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5092 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5093 			&cap_idx) == NULL)
5094 		return TEST_SKIPPED;
5095 
5096 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5097 		return TEST_SKIPPED;
5098 
5099 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5100 		return TEST_SKIPPED;
5101 
5102 	/* Create SNOW 3G session */
5103 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5104 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
5105 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5106 					tdata->key.data, tdata->key.len,
5107 					tdata->cipher_iv.len);
5108 	if (retval < 0)
5109 		return retval;
5110 
5111 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5112 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5113 
5114 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5115 			"Failed to allocate input buffer");
5116 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
5117 			"Failed to allocate output buffer");
5118 
5119 	/* Clear mbuf payload */
5120 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5121 	       rte_pktmbuf_tailroom(ut_params->ibuf));
5122 
5123 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5124 		       rte_pktmbuf_tailroom(ut_params->obuf));
5125 
5126 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5127 	/* Append data which is padded to a multiple of */
5128 	/* the algorithms block size */
5129 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5130 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5131 				ciphertext_pad_len);
5132 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5133 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5134 
5135 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
5136 
5137 	/* Create SNOW 3G operation */
5138 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
5139 					tdata->cipher_iv.len,
5140 					tdata->validCipherLenInBits.len,
5141 					0);
5142 	if (retval < 0)
5143 		return retval;
5144 
5145 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
5146 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
5147 					       tdata->cipher_iv.len);
5148 		if (retval != TEST_SUCCESS)
5149 			return retval;
5150 	} else
5151 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5152 						ut_params->op);
5153 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5154 	ut_params->obuf = ut_params->op->sym->m_dst;
5155 	if (ut_params->obuf)
5156 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5157 	else
5158 		plaintext = ciphertext;
5159 
5160 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
5161 
5162 	/* Validate obuf */
5163 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
5164 				tdata->plaintext.data,
5165 				tdata->validDataLenInBits.len,
5166 				"SNOW 3G Plaintext data not as expected");
5167 	return 0;
5168 }
5169 
5170 static int
5171 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
5172 {
5173 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5174 	struct crypto_unittest_params *ut_params = &unittest_params;
5175 
5176 	int retval;
5177 
5178 	uint8_t *plaintext, *ciphertext;
5179 	unsigned int plaintext_pad_len;
5180 	unsigned int plaintext_len;
5181 
5182 	struct rte_cryptodev_info dev_info;
5183 
5184 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5185 	uint64_t feat_flags = dev_info.feature_flags;
5186 
5187 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
5188 			((tdata->validAuthLenInBits.len % 8 != 0) ||
5189 			(tdata->validDataLenInBits.len % 8 != 0))) {
5190 		printf("Device doesn't support NON-Byte Aligned Data.\n");
5191 		return TEST_SKIPPED;
5192 	}
5193 
5194 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5195 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5196 		printf("Device doesn't support RAW data-path APIs.\n");
5197 		return TEST_SKIPPED;
5198 	}
5199 
5200 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5201 		return TEST_SKIPPED;
5202 
5203 	/* Check if device supports ZUC EEA3 */
5204 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
5205 			tdata->key.len, tdata->cipher_iv.len) < 0)
5206 		return TEST_SKIPPED;
5207 
5208 	/* Check if device supports ZUC EIA3 */
5209 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
5210 			tdata->key.len, tdata->auth_iv.len,
5211 			tdata->digest.len) < 0)
5212 		return TEST_SKIPPED;
5213 
5214 	/* Create ZUC session */
5215 	retval = create_zuc_cipher_auth_encrypt_generate_session(
5216 			ts_params->valid_devs[0],
5217 			tdata);
5218 	if (retval != 0)
5219 		return retval;
5220 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5221 
5222 	/* clear mbuf payload */
5223 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5224 			rte_pktmbuf_tailroom(ut_params->ibuf));
5225 
5226 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5227 	/* Append data which is padded to a multiple of */
5228 	/* the algorithms block size */
5229 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5230 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5231 				plaintext_pad_len);
5232 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5233 
5234 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5235 
5236 	/* Create ZUC operation */
5237 	retval = create_zuc_cipher_hash_generate_operation(tdata);
5238 	if (retval < 0)
5239 		return retval;
5240 
5241 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
5242 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1,
5243 					       tdata->cipher_iv.len);
5244 		if (retval != TEST_SUCCESS)
5245 			return retval;
5246 	} else
5247 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5248 			ut_params->op);
5249 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5250 	ut_params->obuf = ut_params->op->sym->m_src;
5251 	if (ut_params->obuf)
5252 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5253 	else
5254 		ciphertext = plaintext;
5255 
5256 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5257 	/* Validate obuf */
5258 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5259 			ciphertext,
5260 			tdata->ciphertext.data,
5261 			tdata->validDataLenInBits.len,
5262 			"ZUC Ciphertext data not as expected");
5263 
5264 	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
5265 						    uint8_t *,
5266 						    plaintext_pad_len);
5267 
5268 	/* Validate obuf */
5269 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
5270 			ut_params->digest,
5271 			tdata->digest.data,
5272 			tdata->digest.len,
5273 			"ZUC Generated auth tag not as expected");
5274 	return 0;
5275 }
5276 
5277 static int
5278 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
5279 {
5280 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5281 	struct crypto_unittest_params *ut_params = &unittest_params;
5282 
5283 	int retval;
5284 
5285 	uint8_t *plaintext, *ciphertext;
5286 	unsigned plaintext_pad_len;
5287 	unsigned plaintext_len;
5288 	struct rte_cryptodev_info dev_info;
5289 
5290 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5291 	uint64_t feat_flags = dev_info.feature_flags;
5292 
5293 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5294 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5295 		printf("Device doesn't support RAW data-path APIs.\n");
5296 		return TEST_SKIPPED;
5297 	}
5298 
5299 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5300 		return TEST_SKIPPED;
5301 
5302 	/* Verify the capabilities */
5303 	struct rte_cryptodev_sym_capability_idx cap_idx;
5304 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5305 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5306 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5307 			&cap_idx) == NULL)
5308 		return TEST_SKIPPED;
5309 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5310 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5311 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5312 			&cap_idx) == NULL)
5313 		return TEST_SKIPPED;
5314 
5315 	/* Create SNOW 3G session */
5316 	retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
5317 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5318 			RTE_CRYPTO_AUTH_OP_GENERATE,
5319 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5320 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5321 			tdata->key.data, tdata->key.len,
5322 			tdata->key.data, tdata->key.len,
5323 			tdata->auth_iv.len, tdata->digest.len,
5324 			tdata->cipher_iv.len);
5325 	if (retval != 0)
5326 		return retval;
5327 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5328 
5329 	/* clear mbuf payload */
5330 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5331 			rte_pktmbuf_tailroom(ut_params->ibuf));
5332 
5333 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5334 	/* Append data which is padded to a multiple of */
5335 	/* the algorithms block size */
5336 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5337 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5338 				plaintext_pad_len);
5339 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5340 
5341 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5342 
5343 	/* Create SNOW 3G operation */
5344 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5345 			tdata->digest.len, tdata->auth_iv.data,
5346 			tdata->auth_iv.len,
5347 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5348 			tdata->cipher_iv.data, tdata->cipher_iv.len,
5349 			tdata->validCipherLenInBits.len,
5350 			0,
5351 			tdata->validAuthLenInBits.len,
5352 			0
5353 			);
5354 	if (retval < 0)
5355 		return retval;
5356 
5357 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
5358 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1,
5359 					       tdata->cipher_iv.len);
5360 		if (retval != TEST_SUCCESS)
5361 			return retval;
5362 	} else
5363 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5364 			ut_params->op);
5365 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5366 	ut_params->obuf = ut_params->op->sym->m_src;
5367 	if (ut_params->obuf)
5368 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5369 	else
5370 		ciphertext = plaintext;
5371 
5372 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5373 	/* Validate obuf */
5374 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5375 			ciphertext,
5376 			tdata->ciphertext.data,
5377 			tdata->validDataLenInBits.len,
5378 			"SNOW 3G Ciphertext data not as expected");
5379 
5380 	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
5381 						    uint8_t *,
5382 						    plaintext_pad_len);
5383 
5384 	/* Validate obuf */
5385 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
5386 			ut_params->digest,
5387 			tdata->digest.data,
5388 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5389 			"SNOW 3G Generated auth tag not as expected");
5390 	return 0;
5391 }
5392 
5393 static int
5394 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
5395 	uint8_t op_mode, uint8_t verify)
5396 {
5397 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5398 	struct crypto_unittest_params *ut_params = &unittest_params;
5399 
5400 	int retval;
5401 
5402 	uint8_t *plaintext = NULL, *ciphertext = NULL;
5403 	unsigned int plaintext_pad_len;
5404 	unsigned int plaintext_len;
5405 	unsigned int ciphertext_pad_len;
5406 	unsigned int ciphertext_len;
5407 	unsigned int digest_offset;
5408 
5409 	struct rte_cryptodev_info dev_info;
5410 
5411 	/* Verify the capabilities */
5412 	struct rte_cryptodev_sym_capability_idx cap_idx;
5413 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5414 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5415 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5416 			&cap_idx) == NULL)
5417 		return TEST_SKIPPED;
5418 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5419 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5420 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5421 			&cap_idx) == NULL)
5422 		return TEST_SKIPPED;
5423 
5424 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5425 		return TEST_SKIPPED;
5426 
5427 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5428 
5429 	uint64_t feat_flags = dev_info.feature_flags;
5430 
5431 	if (op_mode == OUT_OF_PLACE) {
5432 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5433 			printf("Device doesn't support digest encrypted.\n");
5434 			return TEST_SKIPPED;
5435 		}
5436 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5437 			return TEST_SKIPPED;
5438 	}
5439 
5440 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5441 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5442 		printf("Device doesn't support RAW data-path APIs.\n");
5443 		return TEST_SKIPPED;
5444 	}
5445 
5446 	/* Create SNOW 3G session */
5447 	retval = create_wireless_algo_auth_cipher_session(
5448 			ts_params->valid_devs[0],
5449 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5450 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5451 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5452 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5453 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5454 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5455 			tdata->key.data, tdata->key.len,
5456 			tdata->key.data, tdata->key.len,
5457 			tdata->auth_iv.len, tdata->digest.len,
5458 			tdata->cipher_iv.len);
5459 	if (retval != 0)
5460 		return retval;
5461 
5462 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5463 	if (op_mode == OUT_OF_PLACE)
5464 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5465 
5466 	/* clear mbuf payload */
5467 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5468 		rte_pktmbuf_tailroom(ut_params->ibuf));
5469 	if (op_mode == OUT_OF_PLACE)
5470 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5471 			rte_pktmbuf_tailroom(ut_params->obuf));
5472 
5473 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5474 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5475 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5476 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5477 
5478 	if (verify) {
5479 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5480 					ciphertext_pad_len);
5481 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5482 		if (op_mode == OUT_OF_PLACE)
5483 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5484 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5485 			ciphertext_len);
5486 	} else {
5487 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5488 					plaintext_pad_len);
5489 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5490 		if (op_mode == OUT_OF_PLACE)
5491 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5492 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5493 	}
5494 
5495 	/* Create SNOW 3G operation */
5496 	retval = create_wireless_algo_auth_cipher_operation(
5497 		tdata->digest.data, tdata->digest.len,
5498 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5499 		tdata->auth_iv.data, tdata->auth_iv.len,
5500 		(tdata->digest.offset_bytes == 0 ?
5501 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5502 			: tdata->digest.offset_bytes),
5503 		tdata->validCipherLenInBits.len,
5504 		tdata->cipher.offset_bits,
5505 		tdata->validAuthLenInBits.len,
5506 		tdata->auth.offset_bits,
5507 		op_mode, 0, verify);
5508 
5509 	if (retval < 0)
5510 		return retval;
5511 
5512 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
5513 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1,
5514 					       tdata->cipher_iv.len);
5515 		if (retval != TEST_SUCCESS)
5516 			return retval;
5517 	} else
5518 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5519 			ut_params->op);
5520 
5521 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5522 
5523 	ut_params->obuf = (op_mode == IN_PLACE ?
5524 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5525 
5526 	if (verify) {
5527 		if (ut_params->obuf)
5528 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5529 							uint8_t *);
5530 		else
5531 			plaintext = ciphertext +
5532 				(tdata->cipher.offset_bits >> 3);
5533 
5534 		debug_hexdump(stdout, "plaintext:", plaintext,
5535 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5536 		debug_hexdump(stdout, "plaintext expected:",
5537 			tdata->plaintext.data,
5538 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5539 	} else {
5540 		if (ut_params->obuf)
5541 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5542 							uint8_t *);
5543 		else
5544 			ciphertext = plaintext;
5545 
5546 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5547 			ciphertext_len);
5548 		debug_hexdump(stdout, "ciphertext expected:",
5549 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5550 
5551 		if (tdata->digest.offset_bytes == 0)
5552 			digest_offset = plaintext_pad_len;
5553 		else
5554 			digest_offset = tdata->digest.offset_bytes;
5555 		ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
5556 						    uint8_t *, digest_offset);
5557 
5558 		debug_hexdump(stdout, "digest:", ut_params->digest,
5559 			tdata->digest.len);
5560 		debug_hexdump(stdout, "digest expected:", tdata->digest.data,
5561 				tdata->digest.len);
5562 	}
5563 
5564 	/* Validate obuf */
5565 	if (verify) {
5566 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5567 			plaintext,
5568 			tdata->plaintext.data,
5569 			(tdata->plaintext.len - tdata->cipher.offset_bits -
5570 			 (tdata->digest.len << 3)),
5571 			tdata->cipher.offset_bits,
5572 			"SNOW 3G Plaintext data not as expected");
5573 	} else {
5574 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5575 			ciphertext,
5576 			tdata->ciphertext.data,
5577 			(tdata->validDataLenInBits.len -
5578 			 tdata->cipher.offset_bits),
5579 			tdata->cipher.offset_bits,
5580 			"SNOW 3G Ciphertext data not as expected");
5581 
5582 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5583 			ut_params->digest,
5584 			tdata->digest.data,
5585 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5586 			"SNOW 3G Generated auth tag not as expected");
5587 	}
5588 	return 0;
5589 }
5590 
5591 static int
5592 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
5593 	uint8_t op_mode, uint8_t verify)
5594 {
5595 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5596 	struct crypto_unittest_params *ut_params = &unittest_params;
5597 
5598 	int retval;
5599 
5600 	const uint8_t *plaintext = NULL;
5601 	const uint8_t *ciphertext = NULL;
5602 	const uint8_t *digest = NULL;
5603 	unsigned int plaintext_pad_len;
5604 	unsigned int plaintext_len;
5605 	unsigned int ciphertext_pad_len;
5606 	unsigned int ciphertext_len;
5607 	uint8_t buffer[10000];
5608 	uint8_t digest_buffer[10000];
5609 
5610 	struct rte_cryptodev_info dev_info;
5611 
5612 	/* Verify the capabilities */
5613 	struct rte_cryptodev_sym_capability_idx cap_idx;
5614 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5615 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5616 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5617 			&cap_idx) == NULL)
5618 		return TEST_SKIPPED;
5619 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5620 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5621 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5622 			&cap_idx) == NULL)
5623 		return TEST_SKIPPED;
5624 
5625 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5626 		return TEST_SKIPPED;
5627 
5628 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5629 
5630 	uint64_t feat_flags = dev_info.feature_flags;
5631 
5632 	if (op_mode == IN_PLACE) {
5633 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5634 			printf("Device doesn't support in-place scatter-gather "
5635 					"in both input and output mbufs.\n");
5636 			return TEST_SKIPPED;
5637 		}
5638 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5639 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5640 			printf("Device doesn't support RAW data-path APIs.\n");
5641 			return TEST_SKIPPED;
5642 		}
5643 	} else {
5644 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5645 			return TEST_SKIPPED;
5646 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5647 			printf("Device doesn't support out-of-place scatter-gather "
5648 					"in both input and output mbufs.\n");
5649 			return TEST_SKIPPED;
5650 		}
5651 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5652 			printf("Device doesn't support digest encrypted.\n");
5653 			return TEST_SKIPPED;
5654 		}
5655 	}
5656 
5657 	/* Create SNOW 3G session */
5658 	retval = create_wireless_algo_auth_cipher_session(
5659 			ts_params->valid_devs[0],
5660 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5661 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5662 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5663 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5664 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5665 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5666 			tdata->key.data, tdata->key.len,
5667 			tdata->key.data, tdata->key.len,
5668 			tdata->auth_iv.len, tdata->digest.len,
5669 			tdata->cipher_iv.len);
5670 
5671 	if (retval != 0)
5672 		return retval;
5673 
5674 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5675 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5676 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5677 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5678 
5679 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5680 			plaintext_pad_len, 15, 0);
5681 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5682 			"Failed to allocate input buffer in mempool");
5683 
5684 	if (op_mode == OUT_OF_PLACE) {
5685 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5686 				plaintext_pad_len, 15, 0);
5687 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5688 				"Failed to allocate output buffer in mempool");
5689 	}
5690 
5691 	if (verify) {
5692 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5693 			tdata->ciphertext.data);
5694 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5695 					ciphertext_len, buffer);
5696 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5697 			ciphertext_len);
5698 	} else {
5699 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5700 			tdata->plaintext.data);
5701 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5702 					plaintext_len, buffer);
5703 		debug_hexdump(stdout, "plaintext:", plaintext,
5704 			plaintext_len);
5705 	}
5706 	memset(buffer, 0, sizeof(buffer));
5707 
5708 	/* Create SNOW 3G operation */
5709 	retval = create_wireless_algo_auth_cipher_operation(
5710 		tdata->digest.data, tdata->digest.len,
5711 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5712 		tdata->auth_iv.data, tdata->auth_iv.len,
5713 		(tdata->digest.offset_bytes == 0 ?
5714 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5715 			: tdata->digest.offset_bytes),
5716 		tdata->validCipherLenInBits.len,
5717 		tdata->cipher.offset_bits,
5718 		tdata->validAuthLenInBits.len,
5719 		tdata->auth.offset_bits,
5720 		op_mode, 1, verify);
5721 
5722 	if (retval < 0)
5723 		return retval;
5724 
5725 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
5726 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1,
5727 					       tdata->cipher_iv.len);
5728 		if (retval != TEST_SUCCESS)
5729 			return retval;
5730 	} else
5731 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5732 			ut_params->op);
5733 
5734 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5735 
5736 	ut_params->obuf = (op_mode == IN_PLACE ?
5737 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5738 
5739 	if (verify) {
5740 		if (ut_params->obuf)
5741 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5742 					plaintext_len, buffer);
5743 		else
5744 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5745 					plaintext_len, buffer);
5746 
5747 		debug_hexdump(stdout, "plaintext:", plaintext,
5748 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5749 		debug_hexdump(stdout, "plaintext expected:",
5750 			tdata->plaintext.data,
5751 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5752 	} else {
5753 		if (ut_params->obuf)
5754 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5755 					ciphertext_len, buffer);
5756 		else
5757 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5758 					ciphertext_len, buffer);
5759 
5760 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5761 			ciphertext_len);
5762 		debug_hexdump(stdout, "ciphertext expected:",
5763 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5764 
5765 		if (ut_params->obuf)
5766 			digest = rte_pktmbuf_read(ut_params->obuf,
5767 				(tdata->digest.offset_bytes == 0 ?
5768 				plaintext_pad_len : tdata->digest.offset_bytes),
5769 				tdata->digest.len, digest_buffer);
5770 		else
5771 			digest = rte_pktmbuf_read(ut_params->ibuf,
5772 				(tdata->digest.offset_bytes == 0 ?
5773 				plaintext_pad_len : tdata->digest.offset_bytes),
5774 				tdata->digest.len, digest_buffer);
5775 
5776 		debug_hexdump(stdout, "digest:", digest,
5777 			tdata->digest.len);
5778 		debug_hexdump(stdout, "digest expected:",
5779 			tdata->digest.data, tdata->digest.len);
5780 	}
5781 
5782 	/* Validate obuf */
5783 	if (verify) {
5784 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5785 			plaintext,
5786 			tdata->plaintext.data,
5787 			(tdata->plaintext.len - tdata->cipher.offset_bits -
5788 			 (tdata->digest.len << 3)),
5789 			tdata->cipher.offset_bits,
5790 			"SNOW 3G Plaintext data not as expected");
5791 	} else {
5792 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5793 			ciphertext,
5794 			tdata->ciphertext.data,
5795 			(tdata->validDataLenInBits.len -
5796 			 tdata->cipher.offset_bits),
5797 			tdata->cipher.offset_bits,
5798 			"SNOW 3G Ciphertext data not as expected");
5799 
5800 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5801 			digest,
5802 			tdata->digest.data,
5803 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5804 			"SNOW 3G Generated auth tag not as expected");
5805 	}
5806 	return 0;
5807 }
5808 
5809 static int
5810 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
5811 	uint8_t op_mode, uint8_t verify)
5812 {
5813 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5814 	struct crypto_unittest_params *ut_params = &unittest_params;
5815 
5816 	int retval;
5817 
5818 	uint8_t *plaintext = NULL, *ciphertext = NULL;
5819 	unsigned int plaintext_pad_len;
5820 	unsigned int plaintext_len;
5821 	unsigned int ciphertext_pad_len;
5822 	unsigned int ciphertext_len;
5823 	unsigned int digest_offset;
5824 
5825 	struct rte_cryptodev_info dev_info;
5826 
5827 	/* Verify the capabilities */
5828 	struct rte_cryptodev_sym_capability_idx cap_idx;
5829 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5830 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5831 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5832 			&cap_idx) == NULL)
5833 		return TEST_SKIPPED;
5834 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5835 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5836 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5837 			&cap_idx) == NULL)
5838 		return TEST_SKIPPED;
5839 
5840 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5841 
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 	if (op_mode == OUT_OF_PLACE) {
5854 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5855 			return TEST_SKIPPED;
5856 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5857 			printf("Device doesn't support digest encrypted.\n");
5858 			return TEST_SKIPPED;
5859 		}
5860 	}
5861 
5862 	/* Create KASUMI session */
5863 	retval = create_wireless_algo_auth_cipher_session(
5864 			ts_params->valid_devs[0],
5865 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5866 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5867 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5868 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5869 			RTE_CRYPTO_AUTH_KASUMI_F9,
5870 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5871 			tdata->key.data, tdata->key.len,
5872 			tdata->key.data, tdata->key.len,
5873 			0, tdata->digest.len,
5874 			tdata->cipher_iv.len);
5875 
5876 	if (retval != 0)
5877 		return retval;
5878 
5879 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5880 	if (op_mode == OUT_OF_PLACE)
5881 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5882 
5883 	/* clear mbuf payload */
5884 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5885 		rte_pktmbuf_tailroom(ut_params->ibuf));
5886 	if (op_mode == OUT_OF_PLACE)
5887 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5888 			rte_pktmbuf_tailroom(ut_params->obuf));
5889 
5890 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5891 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5892 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5893 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5894 
5895 	if (verify) {
5896 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5897 					ciphertext_pad_len);
5898 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5899 		if (op_mode == OUT_OF_PLACE)
5900 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5901 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5902 			ciphertext_len);
5903 	} else {
5904 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5905 					plaintext_pad_len);
5906 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5907 		if (op_mode == OUT_OF_PLACE)
5908 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5909 		debug_hexdump(stdout, "plaintext:", plaintext,
5910 			plaintext_len);
5911 	}
5912 
5913 	/* Create KASUMI operation */
5914 	retval = create_wireless_algo_auth_cipher_operation(
5915 		tdata->digest.data, tdata->digest.len,
5916 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5917 		NULL, 0,
5918 		(tdata->digest.offset_bytes == 0 ?
5919 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5920 			: tdata->digest.offset_bytes),
5921 		tdata->validCipherLenInBits.len,
5922 		tdata->validCipherOffsetInBits.len,
5923 		tdata->validAuthLenInBits.len,
5924 		0,
5925 		op_mode, 0, verify);
5926 
5927 	if (retval < 0)
5928 		return retval;
5929 
5930 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
5931 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1,
5932 					       tdata->cipher_iv.len);
5933 		if (retval != TEST_SUCCESS)
5934 			return retval;
5935 	} else
5936 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5937 			ut_params->op);
5938 
5939 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5940 
5941 	ut_params->obuf = (op_mode == IN_PLACE ?
5942 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5943 
5944 
5945 	if (verify) {
5946 		if (ut_params->obuf)
5947 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5948 							uint8_t *);
5949 		else
5950 			plaintext = ciphertext;
5951 
5952 		debug_hexdump(stdout, "plaintext:", plaintext,
5953 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5954 		debug_hexdump(stdout, "plaintext expected:",
5955 			tdata->plaintext.data,
5956 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5957 	} else {
5958 		if (ut_params->obuf)
5959 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5960 							uint8_t *);
5961 		else
5962 			ciphertext = plaintext;
5963 
5964 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5965 			ciphertext_len);
5966 		debug_hexdump(stdout, "ciphertext expected:",
5967 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5968 
5969 		if (tdata->digest.offset_bytes == 0)
5970 			digest_offset = plaintext_pad_len;
5971 		else
5972 			digest_offset = tdata->digest.offset_bytes;
5973 		ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
5974 						    uint8_t *, digest_offset);
5975 
5976 		debug_hexdump(stdout, "digest:", ut_params->digest,
5977 			tdata->digest.len);
5978 		debug_hexdump(stdout, "digest expected:",
5979 			tdata->digest.data, tdata->digest.len);
5980 	}
5981 
5982 	/* Validate obuf */
5983 	if (verify) {
5984 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5985 			plaintext,
5986 			tdata->plaintext.data,
5987 			tdata->plaintext.len >> 3,
5988 			"KASUMI Plaintext data not as expected");
5989 	} else {
5990 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5991 			ciphertext,
5992 			tdata->ciphertext.data,
5993 			tdata->ciphertext.len >> 3,
5994 			"KASUMI Ciphertext data not as expected");
5995 
5996 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5997 			ut_params->digest,
5998 			tdata->digest.data,
5999 			DIGEST_BYTE_LENGTH_KASUMI_F9,
6000 			"KASUMI Generated auth tag not as expected");
6001 	}
6002 	return 0;
6003 }
6004 
6005 static int
6006 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
6007 	uint8_t op_mode, uint8_t verify)
6008 {
6009 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6010 	struct crypto_unittest_params *ut_params = &unittest_params;
6011 
6012 	int retval;
6013 
6014 	const uint8_t *plaintext = NULL;
6015 	const uint8_t *ciphertext = NULL;
6016 	const uint8_t *digest = NULL;
6017 	unsigned int plaintext_pad_len;
6018 	unsigned int plaintext_len;
6019 	unsigned int ciphertext_pad_len;
6020 	unsigned int ciphertext_len;
6021 	uint8_t buffer[10000];
6022 	uint8_t digest_buffer[10000];
6023 
6024 	struct rte_cryptodev_info dev_info;
6025 
6026 	/* Verify the capabilities */
6027 	struct rte_cryptodev_sym_capability_idx cap_idx;
6028 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6029 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
6030 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6031 			&cap_idx) == NULL)
6032 		return TEST_SKIPPED;
6033 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6034 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
6035 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6036 			&cap_idx) == NULL)
6037 		return TEST_SKIPPED;
6038 
6039 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6040 		return TEST_SKIPPED;
6041 
6042 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6043 
6044 	uint64_t feat_flags = dev_info.feature_flags;
6045 
6046 	if (op_mode == IN_PLACE) {
6047 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6048 			printf("Device doesn't support in-place scatter-gather "
6049 					"in both input and output mbufs.\n");
6050 			return TEST_SKIPPED;
6051 		}
6052 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6053 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6054 			printf("Device doesn't support RAW data-path APIs.\n");
6055 			return TEST_SKIPPED;
6056 		}
6057 	} else {
6058 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6059 			return TEST_SKIPPED;
6060 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6061 			printf("Device doesn't support out-of-place scatter-gather "
6062 					"in both input and output mbufs.\n");
6063 			return TEST_SKIPPED;
6064 		}
6065 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6066 			printf("Device doesn't support digest encrypted.\n");
6067 			return TEST_SKIPPED;
6068 		}
6069 	}
6070 
6071 	/* Create KASUMI session */
6072 	retval = create_wireless_algo_auth_cipher_session(
6073 			ts_params->valid_devs[0],
6074 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6075 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6076 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6077 					: RTE_CRYPTO_AUTH_OP_GENERATE),
6078 			RTE_CRYPTO_AUTH_KASUMI_F9,
6079 			RTE_CRYPTO_CIPHER_KASUMI_F8,
6080 			tdata->key.data, tdata->key.len,
6081 			tdata->key.data, tdata->key.len,
6082 			0, tdata->digest.len,
6083 			tdata->cipher_iv.len);
6084 
6085 	if (retval != 0)
6086 		return retval;
6087 
6088 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6089 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6090 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6091 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6092 
6093 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6094 			plaintext_pad_len, 15, 0);
6095 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6096 			"Failed to allocate input buffer in mempool");
6097 
6098 	if (op_mode == OUT_OF_PLACE) {
6099 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6100 				plaintext_pad_len, 15, 0);
6101 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
6102 				"Failed to allocate output buffer in mempool");
6103 	}
6104 
6105 	if (verify) {
6106 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6107 			tdata->ciphertext.data);
6108 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6109 					ciphertext_len, buffer);
6110 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6111 			ciphertext_len);
6112 	} else {
6113 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6114 			tdata->plaintext.data);
6115 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6116 					plaintext_len, buffer);
6117 		debug_hexdump(stdout, "plaintext:", plaintext,
6118 			plaintext_len);
6119 	}
6120 	memset(buffer, 0, sizeof(buffer));
6121 
6122 	/* Create KASUMI operation */
6123 	retval = create_wireless_algo_auth_cipher_operation(
6124 		tdata->digest.data, tdata->digest.len,
6125 		tdata->cipher_iv.data, tdata->cipher_iv.len,
6126 		NULL, 0,
6127 		(tdata->digest.offset_bytes == 0 ?
6128 		(verify ? ciphertext_pad_len : plaintext_pad_len)
6129 			: tdata->digest.offset_bytes),
6130 		tdata->validCipherLenInBits.len,
6131 		tdata->validCipherOffsetInBits.len,
6132 		tdata->validAuthLenInBits.len,
6133 		0,
6134 		op_mode, 1, verify);
6135 
6136 	if (retval < 0)
6137 		return retval;
6138 
6139 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
6140 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1,
6141 					       tdata->cipher_iv.len);
6142 		if (retval != TEST_SUCCESS)
6143 			return retval;
6144 	} else
6145 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6146 			ut_params->op);
6147 
6148 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6149 
6150 	ut_params->obuf = (op_mode == IN_PLACE ?
6151 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6152 
6153 	if (verify) {
6154 		if (ut_params->obuf)
6155 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6156 					plaintext_len, buffer);
6157 		else
6158 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6159 					plaintext_len, buffer);
6160 
6161 		debug_hexdump(stdout, "plaintext:", plaintext,
6162 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6163 		debug_hexdump(stdout, "plaintext expected:",
6164 			tdata->plaintext.data,
6165 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6166 	} else {
6167 		if (ut_params->obuf)
6168 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6169 					ciphertext_len, buffer);
6170 		else
6171 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6172 					ciphertext_len, buffer);
6173 
6174 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6175 			ciphertext_len);
6176 		debug_hexdump(stdout, "ciphertext expected:",
6177 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6178 
6179 		if (ut_params->obuf)
6180 			digest = rte_pktmbuf_read(ut_params->obuf,
6181 				(tdata->digest.offset_bytes == 0 ?
6182 				plaintext_pad_len : tdata->digest.offset_bytes),
6183 				tdata->digest.len, digest_buffer);
6184 		else
6185 			digest = rte_pktmbuf_read(ut_params->ibuf,
6186 				(tdata->digest.offset_bytes == 0 ?
6187 				plaintext_pad_len : tdata->digest.offset_bytes),
6188 				tdata->digest.len, digest_buffer);
6189 
6190 		debug_hexdump(stdout, "digest:", digest,
6191 			tdata->digest.len);
6192 		debug_hexdump(stdout, "digest expected:",
6193 			tdata->digest.data, tdata->digest.len);
6194 	}
6195 
6196 	/* Validate obuf */
6197 	if (verify) {
6198 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6199 			plaintext,
6200 			tdata->plaintext.data,
6201 			tdata->plaintext.len >> 3,
6202 			"KASUMI Plaintext data not as expected");
6203 	} else {
6204 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6205 			ciphertext,
6206 			tdata->ciphertext.data,
6207 			tdata->validDataLenInBits.len,
6208 			"KASUMI Ciphertext data not as expected");
6209 
6210 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6211 			digest,
6212 			tdata->digest.data,
6213 			DIGEST_BYTE_LENGTH_KASUMI_F9,
6214 			"KASUMI Generated auth tag not as expected");
6215 	}
6216 	return 0;
6217 }
6218 
6219 static int
6220 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
6221 {
6222 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6223 	struct crypto_unittest_params *ut_params = &unittest_params;
6224 
6225 	int retval;
6226 
6227 	uint8_t *plaintext, *ciphertext;
6228 	unsigned plaintext_pad_len;
6229 	unsigned plaintext_len;
6230 	struct rte_cryptodev_info dev_info;
6231 
6232 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6233 	uint64_t feat_flags = dev_info.feature_flags;
6234 
6235 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6236 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6237 		printf("Device doesn't support RAW data-path APIs.\n");
6238 		return TEST_SKIPPED;
6239 	}
6240 
6241 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6242 		return TEST_SKIPPED;
6243 
6244 	/* Verify the capabilities */
6245 	struct rte_cryptodev_sym_capability_idx cap_idx;
6246 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6247 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
6248 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6249 			&cap_idx) == NULL)
6250 		return TEST_SKIPPED;
6251 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6252 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
6253 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6254 			&cap_idx) == NULL)
6255 		return TEST_SKIPPED;
6256 
6257 	/* Create KASUMI session */
6258 	retval = create_wireless_algo_cipher_auth_session(
6259 			ts_params->valid_devs[0],
6260 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6261 			RTE_CRYPTO_AUTH_OP_GENERATE,
6262 			RTE_CRYPTO_AUTH_KASUMI_F9,
6263 			RTE_CRYPTO_CIPHER_KASUMI_F8,
6264 			tdata->key.data, tdata->key.len,
6265 			tdata->key.data, tdata->key.len,
6266 			0, tdata->digest.len,
6267 			tdata->cipher_iv.len);
6268 	if (retval != 0)
6269 		return retval;
6270 
6271 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6272 
6273 	/* clear mbuf payload */
6274 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6275 			rte_pktmbuf_tailroom(ut_params->ibuf));
6276 
6277 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6278 	/* Append data which is padded to a multiple of */
6279 	/* the algorithms block size */
6280 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6281 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6282 				plaintext_pad_len);
6283 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6284 
6285 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
6286 
6287 	/* Create KASUMI operation */
6288 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
6289 				tdata->digest.len, NULL, 0,
6290 				plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
6291 				tdata->cipher_iv.data, tdata->cipher_iv.len,
6292 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
6293 				tdata->validCipherOffsetInBits.len,
6294 				tdata->validAuthLenInBits.len,
6295 				0
6296 				);
6297 	if (retval < 0)
6298 		return retval;
6299 
6300 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
6301 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1,
6302 					       tdata->cipher_iv.len);
6303 		if (retval != TEST_SUCCESS)
6304 			return retval;
6305 	} else
6306 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6307 			ut_params->op);
6308 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6309 
6310 	if (ut_params->op->sym->m_dst)
6311 		ut_params->obuf = ut_params->op->sym->m_dst;
6312 	else
6313 		ut_params->obuf = ut_params->op->sym->m_src;
6314 
6315 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
6316 				tdata->validCipherOffsetInBits.len >> 3);
6317 
6318 	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
6319 						    uint8_t *,
6320 						    plaintext_pad_len);
6321 
6322 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
6323 				(tdata->validCipherOffsetInBits.len >> 3);
6324 	/* Validate obuf */
6325 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6326 		ciphertext,
6327 		reference_ciphertext,
6328 		tdata->validCipherLenInBits.len,
6329 		"KASUMI Ciphertext data not as expected");
6330 
6331 	/* Validate obuf */
6332 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
6333 		ut_params->digest,
6334 		tdata->digest.data,
6335 		DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
6336 		"KASUMI Generated auth tag not as expected");
6337 	return 0;
6338 }
6339 
6340 static int
6341 check_cipher_capability(const struct crypto_testsuite_params *ts_params,
6342 			const enum rte_crypto_cipher_algorithm cipher_algo,
6343 			const uint16_t key_size, const uint16_t iv_size)
6344 {
6345 	struct rte_cryptodev_sym_capability_idx cap_idx;
6346 	const struct rte_cryptodev_symmetric_capability *cap;
6347 
6348 	/* Check if device supports the algorithm */
6349 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6350 	cap_idx.algo.cipher = cipher_algo;
6351 
6352 	cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6353 			&cap_idx);
6354 
6355 	if (cap == NULL)
6356 		return -1;
6357 
6358 	/* Check if device supports key size and IV size */
6359 	if (rte_cryptodev_sym_capability_check_cipher(cap, key_size,
6360 			iv_size) < 0) {
6361 		return -1;
6362 	}
6363 
6364 	return 0;
6365 }
6366 
6367 static int
6368 check_auth_capability(const struct crypto_testsuite_params *ts_params,
6369 			const enum rte_crypto_auth_algorithm auth_algo,
6370 			const uint16_t key_size, const uint16_t iv_size,
6371 			const uint16_t tag_size)
6372 {
6373 	struct rte_cryptodev_sym_capability_idx cap_idx;
6374 	const struct rte_cryptodev_symmetric_capability *cap;
6375 
6376 	/* Check if device supports the algorithm */
6377 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6378 	cap_idx.algo.auth = auth_algo;
6379 
6380 	cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6381 			&cap_idx);
6382 
6383 	if (cap == NULL)
6384 		return -1;
6385 
6386 	/* Check if device supports key size and IV size */
6387 	if (rte_cryptodev_sym_capability_check_auth(cap, key_size,
6388 			tag_size, iv_size) < 0) {
6389 		return -1;
6390 	}
6391 
6392 	return 0;
6393 }
6394 
6395 static int
6396 test_zuc_cipher(const struct wireless_test_data *tdata,
6397 		enum rte_crypto_cipher_operation direction)
6398 {
6399 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6400 	struct crypto_unittest_params *ut_params = &unittest_params;
6401 
6402 	int retval;
6403 	uint8_t *plaintext = NULL;
6404 	uint8_t *ciphertext = NULL;
6405 	unsigned int plaintext_pad_len, ciphertext_pad_len;
6406 	unsigned int plaintext_len = 0;
6407 	unsigned int ciphertext_len = 0;
6408 	struct rte_cryptodev_info dev_info;
6409 
6410 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6411 	uint64_t feat_flags = dev_info.feature_flags;
6412 
6413 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6414 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6415 		printf("Device doesn't support RAW data-path APIs.\n");
6416 		return TEST_SKIPPED;
6417 	}
6418 
6419 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6420 		return TEST_SKIPPED;
6421 
6422 	/* Check if device supports ZUC EEA3 */
6423 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6424 			tdata->key.len, tdata->cipher_iv.len) < 0)
6425 		return TEST_SKIPPED;
6426 
6427 	/* Create ZUC session */
6428 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
6429 					direction,
6430 					RTE_CRYPTO_CIPHER_ZUC_EEA3,
6431 					tdata->key.data, tdata->key.len,
6432 					tdata->cipher_iv.len);
6433 	if (retval != 0)
6434 		return retval;
6435 
6436 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6437 
6438 	/* Clear mbuf payload */
6439 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6440 	       rte_pktmbuf_tailroom(ut_params->ibuf));
6441 
6442 	if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
6443 		plaintext_len = ceil_byte_length(tdata->plaintext.len);
6444 		/* Append data which is padded to a multiple */
6445 		/* of the algorithms block size */
6446 		plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6447 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6448 				plaintext_pad_len);
6449 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6450 
6451 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
6452 	} else {
6453 		ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6454 		/* Append data which is padded to a multiple */
6455 		/* of the algorithms block size */
6456 		ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
6457 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6458 				ciphertext_pad_len);
6459 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6460 
6461 		debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
6462 	}
6463 
6464 	/* Create ZUC operation */
6465 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
6466 					tdata->cipher_iv.len,
6467 					tdata->plaintext.len,
6468 					tdata->validCipherOffsetInBits.len);
6469 	if (retval < 0)
6470 		return retval;
6471 
6472 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
6473 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
6474 					       tdata->cipher_iv.len);
6475 		if (retval != TEST_SUCCESS)
6476 			return retval;
6477 	} else
6478 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6479 						ut_params->op);
6480 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6481 
6482 	ut_params->obuf = ut_params->op->sym->m_dst;
6483 
6484 	if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
6485 		if (ut_params->obuf)
6486 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
6487 		else
6488 			ciphertext = plaintext;
6489 
6490 		debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6491 
6492 		/* Validate obuf */
6493 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6494 				ciphertext,
6495 				tdata->ciphertext.data,
6496 				tdata->validCipherLenInBits.len,
6497 				"ZUC Ciphertext data not as expected");
6498 	} else {
6499 		if (ut_params->obuf)
6500 			plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
6501 		else
6502 			plaintext = ciphertext;
6503 
6504 		debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
6505 
6506 		const uint8_t *reference_plaintext = tdata->plaintext.data +
6507 				(tdata->validCipherOffsetInBits.len >> 3);
6508 
6509 		/* Validate obuf */
6510 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6511 				plaintext,
6512 				reference_plaintext,
6513 				tdata->validCipherLenInBits.len,
6514 				"ZUC Plaintext data not as expected");
6515 	}
6516 
6517 	return 0;
6518 }
6519 
6520 static int
6521 test_zuc_cipher_sgl(const struct wireless_test_data *tdata,
6522 		enum rte_crypto_cipher_operation direction)
6523 {
6524 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6525 	struct crypto_unittest_params *ut_params = &unittest_params;
6526 
6527 	int retval;
6528 
6529 	unsigned int plaintext_pad_len, ciphertext_pad_len;
6530 	unsigned int plaintext_len = 0;
6531 	unsigned int ciphertext_len = 0;
6532 	const uint8_t *ciphertext, *plaintext;
6533 	uint8_t buffer[2048];
6534 	struct rte_cryptodev_info dev_info;
6535 
6536 	/* Check if device supports ZUC EEA3 */
6537 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6538 			tdata->key.len, tdata->cipher_iv.len) < 0)
6539 		return TEST_SKIPPED;
6540 
6541 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6542 		return TEST_SKIPPED;
6543 
6544 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6545 
6546 	uint64_t feat_flags = dev_info.feature_flags;
6547 
6548 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6549 		printf("Device doesn't support in-place scatter-gather. "
6550 				"Test Skipped.\n");
6551 		return TEST_SKIPPED;
6552 	}
6553 
6554 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6555 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6556 		printf("Device doesn't support RAW data-path APIs.\n");
6557 		return TEST_SKIPPED;
6558 	}
6559 
6560 	if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
6561 		plaintext_len = ceil_byte_length(tdata->plaintext.len);
6562 
6563 		/* Append data which is padded to a multiple */
6564 		/* of the algorithms block size */
6565 		plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6566 
6567 		ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6568 				plaintext_pad_len, 10, 0);
6569 
6570 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6571 				tdata->plaintext.data);
6572 	} else {
6573 		ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6574 
6575 		/* Append data which is padded to a multiple */
6576 		/* of the algorithms block size */
6577 		ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
6578 
6579 		ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6580 				ciphertext_pad_len, 10, 0);
6581 
6582 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6583 				tdata->ciphertext.data);
6584 
6585 	}
6586 
6587 	/* Create ZUC session */
6588 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
6589 			direction,
6590 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6591 			tdata->key.data, tdata->key.len,
6592 			tdata->cipher_iv.len);
6593 	if (retval < 0)
6594 		return retval;
6595 
6596 	/* Clear mbuf payload */
6597 	if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
6598 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
6599 	else
6600 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len, tdata->ciphertext.data);
6601 
6602 	/* Create ZUC operation */
6603 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
6604 			tdata->cipher_iv.len, tdata->plaintext.len,
6605 			tdata->validCipherOffsetInBits.len);
6606 	if (retval < 0)
6607 		return retval;
6608 
6609 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
6610 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 0, 1,
6611 					       tdata->cipher_iv.len);
6612 		if (retval != TEST_SUCCESS)
6613 			return retval;
6614 	} else
6615 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6616 						ut_params->op);
6617 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6618 
6619 	ut_params->obuf = ut_params->op->sym->m_dst;
6620 
6621 	if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
6622 		if (ut_params->obuf)
6623 			ciphertext = rte_pktmbuf_read(ut_params->obuf,
6624 				0, plaintext_len, buffer);
6625 		else
6626 			ciphertext = rte_pktmbuf_read(ut_params->ibuf,
6627 				0, plaintext_len, buffer);
6628 
6629 		/* Validate obuf */
6630 		debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6631 
6632 		/* Validate obuf */
6633 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6634 			ciphertext,
6635 			tdata->ciphertext.data,
6636 			tdata->validCipherLenInBits.len,
6637 			"ZUC Ciphertext data not as expected");
6638 	} else {
6639 		if (ut_params->obuf)
6640 			plaintext = rte_pktmbuf_read(ut_params->obuf,
6641 				0, ciphertext_len, buffer);
6642 		else
6643 			plaintext = rte_pktmbuf_read(ut_params->ibuf,
6644 				0, ciphertext_len, buffer);
6645 
6646 		/* Validate obuf */
6647 		debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
6648 
6649 		/* Validate obuf */
6650 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6651 			plaintext,
6652 			tdata->plaintext.data,
6653 			tdata->validCipherLenInBits.len,
6654 			"ZUC Plaintext data not as expected");
6655 		}
6656 
6657 	return 0;
6658 }
6659 
6660 static int
6661 test_zuc_authentication(const struct wireless_test_data *tdata,
6662 		enum rte_crypto_auth_operation auth_op)
6663 {
6664 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6665 	struct crypto_unittest_params *ut_params = &unittest_params;
6666 
6667 	int retval;
6668 	unsigned plaintext_pad_len;
6669 	unsigned plaintext_len;
6670 	uint8_t *plaintext;
6671 
6672 	struct rte_cryptodev_info dev_info;
6673 
6674 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6675 	uint64_t feat_flags = dev_info.feature_flags;
6676 
6677 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
6678 			(tdata->validAuthLenInBits.len % 8 != 0)) {
6679 		printf("Device doesn't support NON-Byte Aligned Data.\n");
6680 		return TEST_SKIPPED;
6681 	}
6682 
6683 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6684 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6685 		printf("Device doesn't support RAW data-path APIs.\n");
6686 		return TEST_SKIPPED;
6687 	}
6688 
6689 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6690 		return TEST_SKIPPED;
6691 
6692 	/* Check if device supports ZUC EIA3 */
6693 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6694 			tdata->key.len, tdata->auth_iv.len,
6695 			tdata->digest.len) < 0)
6696 		return TEST_SKIPPED;
6697 
6698 	/* Create ZUC session */
6699 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
6700 			tdata->key.data, tdata->key.len,
6701 			tdata->auth_iv.len, tdata->digest.len,
6702 			auth_op, RTE_CRYPTO_AUTH_ZUC_EIA3);
6703 	if (retval != 0)
6704 		return retval;
6705 
6706 	/* alloc mbuf and set payload */
6707 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6708 
6709 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6710 	rte_pktmbuf_tailroom(ut_params->ibuf));
6711 
6712 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6713 	/* Append data which is padded to a multiple of */
6714 	/* the algorithms block size */
6715 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6716 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6717 				plaintext_pad_len);
6718 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6719 
6720 	/* Create ZUC operation */
6721 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
6722 			tdata->digest.len,
6723 			tdata->auth_iv.data, tdata->auth_iv.len,
6724 			plaintext_pad_len,
6725 			auth_op, tdata->validAuthLenInBits.len, 0);
6726 	if (retval < 0)
6727 		return retval;
6728 
6729 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
6730 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 1,
6731 					       0);
6732 		if (retval != TEST_SUCCESS)
6733 			return retval;
6734 	} else
6735 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6736 				ut_params->op);
6737 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6738 	ut_params->obuf = ut_params->op->sym->m_src;
6739 	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
6740 						    uint8_t *,
6741 						    plaintext_pad_len);
6742 
6743 	if (auth_op != RTE_CRYPTO_AUTH_OP_VERIFY) {
6744 		/* Validate obuf */
6745 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6746 				ut_params->digest,
6747 				tdata->digest.data,
6748 				tdata->digest.len,
6749 				"ZUC Generated auth tag not as expected");
6750 		return 0;
6751 	}
6752 
6753 	/* Validate obuf */
6754 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
6755 		return 0;
6756 	else
6757 		return -1;
6758 
6759 	return 0;
6760 }
6761 
6762 static int
6763 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
6764 	uint8_t op_mode, uint8_t verify)
6765 {
6766 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6767 	struct crypto_unittest_params *ut_params = &unittest_params;
6768 
6769 	int retval;
6770 
6771 	uint8_t *plaintext = NULL, *ciphertext = NULL;
6772 	unsigned int plaintext_pad_len;
6773 	unsigned int plaintext_len;
6774 	unsigned int ciphertext_pad_len;
6775 	unsigned int ciphertext_len;
6776 	unsigned int digest_offset;
6777 
6778 	struct rte_cryptodev_info dev_info;
6779 
6780 	/* Check if device supports ZUC EEA3 */
6781 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6782 			tdata->key.len, tdata->cipher_iv.len) < 0)
6783 		return TEST_SKIPPED;
6784 
6785 	/* Check if device supports ZUC EIA3 */
6786 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6787 			tdata->key.len, tdata->auth_iv.len,
6788 			tdata->digest.len) < 0)
6789 		return TEST_SKIPPED;
6790 
6791 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6792 		return TEST_SKIPPED;
6793 
6794 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6795 
6796 	uint64_t feat_flags = dev_info.feature_flags;
6797 
6798 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6799 		printf("Device doesn't support digest encrypted.\n");
6800 		return TEST_SKIPPED;
6801 	}
6802 	if (op_mode == IN_PLACE) {
6803 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6804 			printf("Device doesn't support in-place scatter-gather "
6805 					"in both input and output mbufs.\n");
6806 			return TEST_SKIPPED;
6807 		}
6808 
6809 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6810 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6811 			printf("Device doesn't support RAW data-path APIs.\n");
6812 			return TEST_SKIPPED;
6813 		}
6814 	} else {
6815 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6816 			return TEST_SKIPPED;
6817 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6818 			printf("Device doesn't support out-of-place scatter-gather "
6819 					"in both input and output mbufs.\n");
6820 			return TEST_SKIPPED;
6821 		}
6822 	}
6823 
6824 	/* Create ZUC session */
6825 	retval = create_wireless_algo_auth_cipher_session(
6826 			ts_params->valid_devs[0],
6827 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6828 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6829 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6830 					: RTE_CRYPTO_AUTH_OP_GENERATE),
6831 			RTE_CRYPTO_AUTH_ZUC_EIA3,
6832 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6833 			tdata->key.data, tdata->key.len,
6834 			tdata->key.data, tdata->key.len,
6835 			tdata->auth_iv.len, tdata->digest.len,
6836 			tdata->cipher_iv.len);
6837 
6838 	if (retval != 0)
6839 		return retval;
6840 
6841 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6842 	if (op_mode == OUT_OF_PLACE)
6843 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6844 
6845 	/* clear mbuf payload */
6846 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6847 		rte_pktmbuf_tailroom(ut_params->ibuf));
6848 	if (op_mode == OUT_OF_PLACE)
6849 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6850 			rte_pktmbuf_tailroom(ut_params->obuf));
6851 
6852 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6853 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6854 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6855 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6856 
6857 	if (verify) {
6858 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6859 					ciphertext_pad_len);
6860 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6861 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6862 			ciphertext_len);
6863 	} else {
6864 		/* make sure enough space to cover partial digest verify case */
6865 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6866 					ciphertext_pad_len);
6867 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6868 		debug_hexdump(stdout, "plaintext:", plaintext,
6869 			plaintext_len);
6870 	}
6871 
6872 	if (op_mode == OUT_OF_PLACE)
6873 		rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6874 
6875 	/* Create ZUC operation */
6876 	retval = create_wireless_algo_auth_cipher_operation(
6877 		tdata->digest.data, tdata->digest.len,
6878 		tdata->cipher_iv.data, tdata->cipher_iv.len,
6879 		tdata->auth_iv.data, tdata->auth_iv.len,
6880 		(tdata->digest.offset_bytes == 0 ?
6881 		(verify ? ciphertext_pad_len : plaintext_pad_len)
6882 			: tdata->digest.offset_bytes),
6883 		tdata->validCipherLenInBits.len,
6884 		tdata->validCipherOffsetInBits.len,
6885 		tdata->validAuthLenInBits.len,
6886 		0,
6887 		op_mode, 0, verify);
6888 
6889 	if (retval < 0)
6890 		return retval;
6891 
6892 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
6893 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1,
6894 					       tdata->cipher_iv.len);
6895 		if (retval != TEST_SUCCESS)
6896 			return retval;
6897 	} else
6898 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6899 			ut_params->op);
6900 
6901 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6902 
6903 	ut_params->obuf = (op_mode == IN_PLACE ?
6904 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6905 
6906 
6907 	if (verify) {
6908 		if (ut_params->obuf)
6909 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6910 							uint8_t *);
6911 		else
6912 			plaintext = ciphertext;
6913 
6914 		debug_hexdump(stdout, "plaintext:", plaintext,
6915 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6916 		debug_hexdump(stdout, "plaintext expected:",
6917 			tdata->plaintext.data,
6918 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6919 	} else {
6920 		if (ut_params->obuf)
6921 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6922 							uint8_t *);
6923 		else
6924 			ciphertext = plaintext;
6925 
6926 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6927 			ciphertext_len);
6928 		debug_hexdump(stdout, "ciphertext expected:",
6929 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6930 
6931 		if (tdata->digest.offset_bytes == 0)
6932 			digest_offset = plaintext_pad_len;
6933 		else
6934 			digest_offset =  tdata->digest.offset_bytes;
6935 		ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
6936 					    uint8_t *, digest_offset);
6937 
6938 		debug_hexdump(stdout, "digest:", ut_params->digest,
6939 			tdata->digest.len);
6940 		debug_hexdump(stdout, "digest expected:",
6941 			tdata->digest.data, tdata->digest.len);
6942 	}
6943 
6944 	/* Validate obuf */
6945 	if (verify) {
6946 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6947 			plaintext,
6948 			tdata->plaintext.data,
6949 			tdata->plaintext.len >> 3,
6950 			"ZUC Plaintext data not as expected");
6951 	} else {
6952 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6953 			ciphertext,
6954 			tdata->ciphertext.data,
6955 			tdata->ciphertext.len >> 3,
6956 			"ZUC Ciphertext data not as expected");
6957 
6958 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6959 			ut_params->digest,
6960 			tdata->digest.data,
6961 			tdata->digest.len,
6962 			"ZUC Generated auth tag not as expected");
6963 	}
6964 	return 0;
6965 }
6966 
6967 static int
6968 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
6969 	uint8_t op_mode, uint8_t verify)
6970 {
6971 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6972 	struct crypto_unittest_params *ut_params = &unittest_params;
6973 
6974 	int retval;
6975 
6976 	const uint8_t *plaintext = NULL;
6977 	const uint8_t *ciphertext = NULL;
6978 	const uint8_t *digest = NULL;
6979 	unsigned int plaintext_pad_len;
6980 	unsigned int plaintext_len;
6981 	unsigned int ciphertext_pad_len;
6982 	unsigned int ciphertext_len;
6983 	uint8_t buffer[10000];
6984 	uint8_t digest_buffer[10000];
6985 
6986 	struct rte_cryptodev_info dev_info;
6987 
6988 	/* Check if device supports ZUC EEA3 */
6989 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6990 			tdata->key.len, tdata->cipher_iv.len) < 0)
6991 		return TEST_SKIPPED;
6992 
6993 	/* Check if device supports ZUC EIA3 */
6994 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6995 			tdata->key.len, tdata->auth_iv.len,
6996 			tdata->digest.len) < 0)
6997 		return TEST_SKIPPED;
6998 
6999 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
7000 		return TEST_SKIPPED;
7001 
7002 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7003 
7004 	uint64_t feat_flags = dev_info.feature_flags;
7005 
7006 	if (op_mode == IN_PLACE) {
7007 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
7008 			printf("Device doesn't support in-place scatter-gather "
7009 					"in both input and output mbufs.\n");
7010 			return TEST_SKIPPED;
7011 		}
7012 
7013 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
7014 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
7015 			printf("Device doesn't support RAW data-path APIs.\n");
7016 			return TEST_SKIPPED;
7017 		}
7018 	} else {
7019 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7020 			return TEST_SKIPPED;
7021 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
7022 			printf("Device doesn't support out-of-place scatter-gather "
7023 					"in both input and output mbufs.\n");
7024 			return TEST_SKIPPED;
7025 		}
7026 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7027 			printf("Device doesn't support digest encrypted.\n");
7028 			return TEST_SKIPPED;
7029 		}
7030 	}
7031 
7032 	/* Create ZUC session */
7033 	retval = create_wireless_algo_auth_cipher_session(
7034 			ts_params->valid_devs[0],
7035 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
7036 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
7037 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
7038 					: RTE_CRYPTO_AUTH_OP_GENERATE),
7039 			RTE_CRYPTO_AUTH_ZUC_EIA3,
7040 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
7041 			tdata->key.data, tdata->key.len,
7042 			tdata->key.data, tdata->key.len,
7043 			tdata->auth_iv.len, tdata->digest.len,
7044 			tdata->cipher_iv.len);
7045 
7046 	if (retval != 0)
7047 		return retval;
7048 
7049 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
7050 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
7051 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7052 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7053 
7054 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
7055 			plaintext_pad_len, 15, 0);
7056 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7057 			"Failed to allocate input buffer in mempool");
7058 
7059 	if (op_mode == OUT_OF_PLACE) {
7060 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
7061 				plaintext_pad_len, 15, 0);
7062 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
7063 				"Failed to allocate output buffer in mempool");
7064 	}
7065 
7066 	if (verify) {
7067 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
7068 			tdata->ciphertext.data);
7069 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7070 					ciphertext_len, buffer);
7071 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7072 			ciphertext_len);
7073 	} else {
7074 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
7075 			tdata->plaintext.data);
7076 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7077 					plaintext_len, buffer);
7078 		debug_hexdump(stdout, "plaintext:", plaintext,
7079 			plaintext_len);
7080 	}
7081 	memset(buffer, 0, sizeof(buffer));
7082 
7083 	/* Create ZUC operation */
7084 	retval = create_wireless_algo_auth_cipher_operation(
7085 		tdata->digest.data, tdata->digest.len,
7086 		tdata->cipher_iv.data, tdata->cipher_iv.len,
7087 		tdata->auth_iv.data, tdata->auth_iv.len,
7088 		(tdata->digest.offset_bytes == 0 ?
7089 		(verify ? ciphertext_pad_len : plaintext_pad_len)
7090 			: tdata->digest.offset_bytes),
7091 		tdata->validCipherLenInBits.len,
7092 		tdata->validCipherOffsetInBits.len,
7093 		tdata->validAuthLenInBits.len,
7094 		0,
7095 		op_mode, 1, verify);
7096 
7097 	if (retval < 0)
7098 		return retval;
7099 
7100 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
7101 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 1,
7102 					       tdata->cipher_iv.len);
7103 		if (retval != TEST_SUCCESS)
7104 			return retval;
7105 	} else
7106 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
7107 			ut_params->op);
7108 
7109 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7110 
7111 	ut_params->obuf = (op_mode == IN_PLACE ?
7112 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7113 
7114 	if (verify) {
7115 		if (ut_params->obuf)
7116 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
7117 					plaintext_len, buffer);
7118 		else
7119 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7120 					plaintext_len, buffer);
7121 
7122 		debug_hexdump(stdout, "plaintext:", plaintext,
7123 			(tdata->plaintext.len >> 3) - tdata->digest.len);
7124 		debug_hexdump(stdout, "plaintext expected:",
7125 			tdata->plaintext.data,
7126 			(tdata->plaintext.len >> 3) - tdata->digest.len);
7127 	} else {
7128 		if (ut_params->obuf)
7129 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7130 					ciphertext_len, buffer);
7131 		else
7132 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7133 					ciphertext_len, buffer);
7134 
7135 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7136 			ciphertext_len);
7137 		debug_hexdump(stdout, "ciphertext expected:",
7138 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
7139 
7140 		if (ut_params->obuf)
7141 			digest = rte_pktmbuf_read(ut_params->obuf,
7142 				(tdata->digest.offset_bytes == 0 ?
7143 				plaintext_pad_len : tdata->digest.offset_bytes),
7144 				tdata->digest.len, digest_buffer);
7145 		else
7146 			digest = rte_pktmbuf_read(ut_params->ibuf,
7147 				(tdata->digest.offset_bytes == 0 ?
7148 				plaintext_pad_len : tdata->digest.offset_bytes),
7149 				tdata->digest.len, digest_buffer);
7150 
7151 		debug_hexdump(stdout, "digest:", digest,
7152 			tdata->digest.len);
7153 		debug_hexdump(stdout, "digest expected:",
7154 			tdata->digest.data, tdata->digest.len);
7155 	}
7156 
7157 	/* Validate obuf */
7158 	if (verify) {
7159 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7160 			plaintext,
7161 			tdata->plaintext.data,
7162 			tdata->plaintext.len >> 3,
7163 			"ZUC Plaintext data not as expected");
7164 	} else {
7165 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7166 			ciphertext,
7167 			tdata->ciphertext.data,
7168 			tdata->validDataLenInBits.len,
7169 			"ZUC Ciphertext data not as expected");
7170 
7171 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
7172 			digest,
7173 			tdata->digest.data,
7174 			tdata->digest.len,
7175 			"ZUC Generated auth tag not as expected");
7176 	}
7177 	return 0;
7178 }
7179 
7180 static int
7181 test_kasumi_encryption_test_case_1(void)
7182 {
7183 	return test_kasumi_encryption(&kasumi_test_case_1);
7184 }
7185 
7186 static int
7187 test_kasumi_encryption_test_case_1_sgl(void)
7188 {
7189 	return test_kasumi_encryption_sgl(&kasumi_test_case_1);
7190 }
7191 
7192 static int
7193 test_kasumi_encryption_test_case_1_oop(void)
7194 {
7195 	return test_kasumi_encryption_oop(&kasumi_test_case_1);
7196 }
7197 
7198 static int
7199 test_kasumi_encryption_test_case_1_oop_sgl(void)
7200 {
7201 	return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
7202 }
7203 
7204 static int
7205 test_kasumi_encryption_test_case_2(void)
7206 {
7207 	return test_kasumi_encryption(&kasumi_test_case_2);
7208 }
7209 
7210 static int
7211 test_kasumi_encryption_test_case_3(void)
7212 {
7213 	return test_kasumi_encryption(&kasumi_test_case_3);
7214 }
7215 
7216 static int
7217 test_kasumi_encryption_test_case_4(void)
7218 {
7219 	return test_kasumi_encryption(&kasumi_test_case_4);
7220 }
7221 
7222 static int
7223 test_kasumi_encryption_test_case_5(void)
7224 {
7225 	return test_kasumi_encryption(&kasumi_test_case_5);
7226 }
7227 
7228 static int
7229 test_kasumi_decryption_test_case_1(void)
7230 {
7231 	return test_kasumi_decryption(&kasumi_test_case_1);
7232 }
7233 
7234 static int
7235 test_kasumi_decryption_test_case_1_oop(void)
7236 {
7237 	return test_kasumi_decryption_oop(&kasumi_test_case_1);
7238 }
7239 
7240 static int
7241 test_kasumi_decryption_test_case_2(void)
7242 {
7243 	return test_kasumi_decryption(&kasumi_test_case_2);
7244 }
7245 
7246 static int
7247 test_kasumi_decryption_test_case_3(void)
7248 {
7249 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
7250 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7251 		return TEST_SKIPPED;
7252 	return test_kasumi_decryption(&kasumi_test_case_3);
7253 }
7254 
7255 static int
7256 test_kasumi_decryption_test_case_4(void)
7257 {
7258 	return test_kasumi_decryption(&kasumi_test_case_4);
7259 }
7260 
7261 static int
7262 test_kasumi_decryption_test_case_5(void)
7263 {
7264 	return test_kasumi_decryption(&kasumi_test_case_5);
7265 }
7266 static int
7267 test_snow3g_encryption_test_case_1(void)
7268 {
7269 	return test_snow3g_encryption(&snow3g_test_case_1);
7270 }
7271 
7272 static int
7273 test_snow3g_encryption_test_case_1_oop(void)
7274 {
7275 	return test_snow3g_encryption_oop(&snow3g_test_case_1);
7276 }
7277 
7278 static int
7279 test_snow3g_encryption_test_case_1_oop_sgl(void)
7280 {
7281 	return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 1, 1);
7282 }
7283 
7284 static int
7285 test_snow3g_encryption_test_case_1_oop_lb_in_sgl_out(void)
7286 {
7287 	return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 0, 1);
7288 }
7289 
7290 static int
7291 test_snow3g_encryption_test_case_1_oop_sgl_in_lb_out(void)
7292 {
7293 	return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1, 1, 0);
7294 }
7295 
7296 static int
7297 test_snow3g_encryption_test_case_1_offset_oop(void)
7298 {
7299 	return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
7300 }
7301 
7302 static int
7303 test_snow3g_encryption_test_case_2(void)
7304 {
7305 	return test_snow3g_encryption(&snow3g_test_case_2);
7306 }
7307 
7308 static int
7309 test_snow3g_encryption_test_case_3(void)
7310 {
7311 	return test_snow3g_encryption(&snow3g_test_case_3);
7312 }
7313 
7314 static int
7315 test_snow3g_encryption_test_case_4(void)
7316 {
7317 	return test_snow3g_encryption(&snow3g_test_case_4);
7318 }
7319 
7320 static int
7321 test_snow3g_encryption_test_case_5(void)
7322 {
7323 	return test_snow3g_encryption(&snow3g_test_case_5);
7324 }
7325 
7326 static int
7327 test_snow3g_decryption_test_case_1(void)
7328 {
7329 	return test_snow3g_decryption(&snow3g_test_case_1);
7330 }
7331 
7332 static int
7333 test_snow3g_decryption_test_case_1_oop(void)
7334 {
7335 	return test_snow3g_decryption_oop(&snow3g_test_case_1);
7336 }
7337 
7338 static int
7339 test_snow3g_decryption_test_case_2(void)
7340 {
7341 	return test_snow3g_decryption(&snow3g_test_case_2);
7342 }
7343 
7344 static int
7345 test_snow3g_decryption_test_case_3(void)
7346 {
7347 	return test_snow3g_decryption(&snow3g_test_case_3);
7348 }
7349 
7350 static int
7351 test_snow3g_decryption_test_case_4(void)
7352 {
7353 	return test_snow3g_decryption(&snow3g_test_case_4);
7354 }
7355 
7356 static int
7357 test_snow3g_decryption_test_case_5(void)
7358 {
7359 	return test_snow3g_decryption(&snow3g_test_case_5);
7360 }
7361 
7362 /*
7363  * Function prepares snow3g_hash_test_data from snow3g_test_data.
7364  * Pattern digest from snow3g_test_data must be allocated as
7365  * 4 last bytes in plaintext.
7366  */
7367 static void
7368 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
7369 		struct snow3g_hash_test_data *output)
7370 {
7371 	if ((pattern != NULL) && (output != NULL)) {
7372 		output->key.len = pattern->key.len;
7373 
7374 		memcpy(output->key.data,
7375 		pattern->key.data, pattern->key.len);
7376 
7377 		output->auth_iv.len = pattern->auth_iv.len;
7378 
7379 		memcpy(output->auth_iv.data,
7380 		pattern->auth_iv.data, pattern->auth_iv.len);
7381 
7382 		output->plaintext.len = pattern->plaintext.len;
7383 
7384 		memcpy(output->plaintext.data,
7385 		pattern->plaintext.data, pattern->plaintext.len >> 3);
7386 
7387 		output->digest.len = pattern->digest.len;
7388 
7389 		memcpy(output->digest.data,
7390 		&pattern->plaintext.data[pattern->digest.offset_bytes],
7391 		pattern->digest.len);
7392 
7393 		output->validAuthLenInBits.len =
7394 		pattern->validAuthLenInBits.len;
7395 	}
7396 }
7397 
7398 /*
7399  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
7400  */
7401 static int
7402 test_snow3g_decryption_with_digest_test_case_1(void)
7403 {
7404 	int ret;
7405 	struct snow3g_hash_test_data snow3g_hash_data;
7406 	struct rte_cryptodev_info dev_info;
7407 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7408 
7409 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7410 	uint64_t feat_flags = dev_info.feature_flags;
7411 
7412 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7413 		printf("Device doesn't support encrypted digest operations.\n");
7414 		return TEST_SKIPPED;
7415 	}
7416 
7417 	/*
7418 	 * Function prepare data for hash verification test case.
7419 	 * Digest is allocated in 4 last bytes in plaintext, pattern.
7420 	 */
7421 	snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
7422 
7423 	ret = test_snow3g_decryption(&snow3g_test_case_7);
7424 	if (ret != 0)
7425 		return ret;
7426 
7427 	return test_snow3g_authentication_verify(&snow3g_hash_data);
7428 }
7429 
7430 static int
7431 test_snow3g_cipher_auth_test_case_1(void)
7432 {
7433 	return test_snow3g_cipher_auth(&snow3g_test_case_3);
7434 }
7435 
7436 static int
7437 test_snow3g_auth_cipher_test_case_1(void)
7438 {
7439 	return test_snow3g_auth_cipher(
7440 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
7441 }
7442 
7443 static int
7444 test_snow3g_auth_cipher_test_case_2(void)
7445 {
7446 	return test_snow3g_auth_cipher(
7447 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
7448 }
7449 
7450 static int
7451 test_snow3g_auth_cipher_test_case_2_oop(void)
7452 {
7453 	return test_snow3g_auth_cipher(
7454 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7455 }
7456 
7457 static int
7458 test_snow3g_auth_cipher_part_digest_enc(void)
7459 {
7460 	return test_snow3g_auth_cipher(
7461 		&snow3g_auth_cipher_partial_digest_encryption,
7462 			IN_PLACE, 0);
7463 }
7464 
7465 static int
7466 test_snow3g_auth_cipher_part_digest_enc_oop(void)
7467 {
7468 	return test_snow3g_auth_cipher(
7469 		&snow3g_auth_cipher_partial_digest_encryption,
7470 			OUT_OF_PLACE, 0);
7471 }
7472 
7473 static int
7474 test_snow3g_auth_cipher_test_case_3_sgl(void)
7475 {
7476 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
7477 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7478 		return TEST_SKIPPED;
7479 	return test_snow3g_auth_cipher_sgl(
7480 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
7481 }
7482 
7483 static int
7484 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
7485 {
7486 	return test_snow3g_auth_cipher_sgl(
7487 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
7488 }
7489 
7490 static int
7491 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
7492 {
7493 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
7494 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7495 		return TEST_SKIPPED;
7496 	return test_snow3g_auth_cipher_sgl(
7497 		&snow3g_auth_cipher_partial_digest_encryption,
7498 			IN_PLACE, 0);
7499 }
7500 
7501 static int
7502 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
7503 {
7504 	return test_snow3g_auth_cipher_sgl(
7505 		&snow3g_auth_cipher_partial_digest_encryption,
7506 			OUT_OF_PLACE, 0);
7507 }
7508 
7509 static int
7510 test_snow3g_auth_cipher_total_digest_enc_1(void)
7511 {
7512 	return test_snow3g_auth_cipher(
7513 		&snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 0);
7514 }
7515 
7516 static int
7517 test_snow3g_auth_cipher_total_digest_enc_1_oop(void)
7518 {
7519 	return test_snow3g_auth_cipher(
7520 		&snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 0);
7521 }
7522 
7523 static int
7524 test_snow3g_auth_cipher_total_digest_enc_1_sgl(void)
7525 {
7526 	return test_snow3g_auth_cipher_sgl(
7527 		&snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 0);
7528 }
7529 
7530 static int
7531 test_snow3g_auth_cipher_total_digest_enc_1_oop_sgl(void)
7532 {
7533 	return test_snow3g_auth_cipher_sgl(
7534 		&snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 0);
7535 }
7536 
7537 static int
7538 test_snow3g_auth_cipher_verify_test_case_1(void)
7539 {
7540 	return test_snow3g_auth_cipher(
7541 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
7542 }
7543 
7544 static int
7545 test_snow3g_auth_cipher_verify_test_case_2(void)
7546 {
7547 	return test_snow3g_auth_cipher(
7548 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
7549 }
7550 
7551 static int
7552 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
7553 {
7554 	return test_snow3g_auth_cipher(
7555 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7556 }
7557 
7558 static int
7559 test_snow3g_auth_cipher_verify_part_digest_enc(void)
7560 {
7561 	return test_snow3g_auth_cipher(
7562 		&snow3g_auth_cipher_partial_digest_encryption,
7563 			IN_PLACE, 1);
7564 }
7565 
7566 static int
7567 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
7568 {
7569 	return test_snow3g_auth_cipher(
7570 		&snow3g_auth_cipher_partial_digest_encryption,
7571 			OUT_OF_PLACE, 1);
7572 }
7573 
7574 static int
7575 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
7576 {
7577 	return test_snow3g_auth_cipher_sgl(
7578 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
7579 }
7580 
7581 static int
7582 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
7583 {
7584 	return test_snow3g_auth_cipher_sgl(
7585 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
7586 }
7587 
7588 static int
7589 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
7590 {
7591 	return test_snow3g_auth_cipher_sgl(
7592 		&snow3g_auth_cipher_partial_digest_encryption,
7593 			IN_PLACE, 1);
7594 }
7595 
7596 static int
7597 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
7598 {
7599 	return test_snow3g_auth_cipher_sgl(
7600 		&snow3g_auth_cipher_partial_digest_encryption,
7601 			OUT_OF_PLACE, 1);
7602 }
7603 
7604 static int
7605 test_snow3g_auth_cipher_verify_total_digest_enc_1(void)
7606 {
7607 	return test_snow3g_auth_cipher(
7608 		&snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 1);
7609 }
7610 
7611 static int
7612 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop(void)
7613 {
7614 	return test_snow3g_auth_cipher(
7615 		&snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 1);
7616 }
7617 
7618 static int
7619 test_snow3g_auth_cipher_verify_total_digest_enc_1_sgl(void)
7620 {
7621 	return test_snow3g_auth_cipher_sgl(
7622 		&snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 1);
7623 }
7624 
7625 static int
7626 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop_sgl(void)
7627 {
7628 	return test_snow3g_auth_cipher_sgl(
7629 		&snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 1);
7630 }
7631 
7632 static int
7633 test_snow3g_auth_cipher_with_digest_test_case_1(void)
7634 {
7635 	return test_snow3g_auth_cipher(
7636 		&snow3g_test_case_7, IN_PLACE, 0);
7637 }
7638 
7639 static int
7640 test_kasumi_auth_cipher_test_case_1(void)
7641 {
7642 	return test_kasumi_auth_cipher(
7643 		&kasumi_test_case_3, IN_PLACE, 0);
7644 }
7645 
7646 static int
7647 test_kasumi_auth_cipher_test_case_2(void)
7648 {
7649 	return test_kasumi_auth_cipher(
7650 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
7651 }
7652 
7653 static int
7654 test_kasumi_auth_cipher_test_case_2_oop(void)
7655 {
7656 	return test_kasumi_auth_cipher(
7657 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7658 }
7659 
7660 static int
7661 test_kasumi_auth_cipher_test_case_2_sgl(void)
7662 {
7663 	return test_kasumi_auth_cipher_sgl(
7664 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
7665 }
7666 
7667 static int
7668 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
7669 {
7670 	return test_kasumi_auth_cipher_sgl(
7671 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7672 }
7673 
7674 static int
7675 test_kasumi_auth_cipher_verify_test_case_1(void)
7676 {
7677 	return test_kasumi_auth_cipher(
7678 		&kasumi_test_case_3, IN_PLACE, 1);
7679 }
7680 
7681 static int
7682 test_kasumi_auth_cipher_verify_test_case_2(void)
7683 {
7684 	return test_kasumi_auth_cipher(
7685 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
7686 }
7687 
7688 static int
7689 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
7690 {
7691 	return test_kasumi_auth_cipher(
7692 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7693 }
7694 
7695 static int
7696 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
7697 {
7698 	return test_kasumi_auth_cipher_sgl(
7699 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
7700 }
7701 
7702 static int
7703 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
7704 {
7705 	return test_kasumi_auth_cipher_sgl(
7706 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7707 }
7708 
7709 static int
7710 test_kasumi_cipher_auth_test_case_1(void)
7711 {
7712 	return test_kasumi_cipher_auth(&kasumi_test_case_6);
7713 }
7714 
7715 static int
7716 test_zuc_encryption_test_case_1(void)
7717 {
7718 	return test_zuc_cipher(&zuc_test_case_cipher_193b,
7719 			RTE_CRYPTO_CIPHER_OP_ENCRYPT);
7720 }
7721 
7722 static int
7723 test_zuc_encryption_test_case_2(void)
7724 {
7725 	return test_zuc_cipher(&zuc_test_case_cipher_800b,
7726 			RTE_CRYPTO_CIPHER_OP_ENCRYPT);
7727 }
7728 
7729 static int
7730 test_zuc_encryption_test_case_3(void)
7731 {
7732 	return test_zuc_cipher(&zuc_test_case_cipher_1570b,
7733 			RTE_CRYPTO_CIPHER_OP_ENCRYPT);
7734 }
7735 
7736 static int
7737 test_zuc_encryption_test_case_4(void)
7738 {
7739 	return test_zuc_cipher(&zuc_test_case_cipher_2798b,
7740 			RTE_CRYPTO_CIPHER_OP_ENCRYPT);
7741 }
7742 
7743 static int
7744 test_zuc_encryption_test_case_5(void)
7745 {
7746 	return test_zuc_cipher(&zuc_test_case_cipher_4019b,
7747 			RTE_CRYPTO_CIPHER_OP_ENCRYPT);
7748 }
7749 
7750 static int
7751 test_zuc_encryption_test_case_6_sgl(void)
7752 {
7753 	return test_zuc_cipher_sgl(&zuc_test_case_cipher_193b,
7754 			RTE_CRYPTO_CIPHER_OP_ENCRYPT);
7755 }
7756 
7757 static int
7758 test_zuc_decryption_test_case_1(void)
7759 {
7760 	return test_zuc_cipher(&zuc_test_case_cipher_193b,
7761 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
7762 }
7763 
7764 static int
7765 test_zuc_decryption_test_case_2(void)
7766 {
7767 	return test_zuc_cipher(&zuc_test_case_cipher_800b,
7768 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
7769 }
7770 
7771 static int
7772 test_zuc_decryption_test_case_3(void)
7773 {
7774 	return test_zuc_cipher(&zuc_test_case_cipher_1570b,
7775 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
7776 }
7777 
7778 static int
7779 test_zuc_decryption_test_case_4(void)
7780 {
7781 	return test_zuc_cipher(&zuc_test_case_cipher_2798b,
7782 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
7783 }
7784 
7785 static int
7786 test_zuc_decryption_test_case_5(void)
7787 {
7788 	return test_zuc_cipher(&zuc_test_case_cipher_4019b,
7789 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
7790 }
7791 
7792 static int
7793 test_zuc_decryption_test_case_6_sgl(void)
7794 {
7795 	return test_zuc_cipher_sgl(&zuc_test_case_cipher_193b,
7796 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
7797 }
7798 
7799 static int
7800 test_zuc_hash_generate_test_case_1(void)
7801 {
7802 	return test_zuc_authentication(&zuc_test_case_auth_1b,
7803 			RTE_CRYPTO_AUTH_OP_GENERATE);
7804 }
7805 
7806 static int
7807 test_zuc_hash_generate_test_case_2(void)
7808 {
7809 	return test_zuc_authentication(&zuc_test_case_auth_90b,
7810 			RTE_CRYPTO_AUTH_OP_GENERATE);
7811 }
7812 
7813 static int
7814 test_zuc_hash_generate_test_case_3(void)
7815 {
7816 	return test_zuc_authentication(&zuc_test_case_auth_577b,
7817 			RTE_CRYPTO_AUTH_OP_GENERATE);
7818 }
7819 
7820 static int
7821 test_zuc_hash_generate_test_case_4(void)
7822 {
7823 	return test_zuc_authentication(&zuc_test_case_auth_2079b,
7824 			RTE_CRYPTO_AUTH_OP_GENERATE);
7825 }
7826 
7827 static int
7828 test_zuc_hash_generate_test_case_5(void)
7829 {
7830 	return test_zuc_authentication(&zuc_test_auth_5670b,
7831 			RTE_CRYPTO_AUTH_OP_GENERATE);
7832 }
7833 
7834 static int
7835 test_zuc_hash_generate_test_case_6(void)
7836 {
7837 	return test_zuc_authentication(&zuc_test_case_auth_128b,
7838 			RTE_CRYPTO_AUTH_OP_GENERATE);
7839 }
7840 
7841 static int
7842 test_zuc_hash_generate_test_case_7(void)
7843 {
7844 	return test_zuc_authentication(&zuc_test_case_auth_2080b,
7845 			RTE_CRYPTO_AUTH_OP_GENERATE);
7846 }
7847 
7848 static int
7849 test_zuc_hash_generate_test_case_8(void)
7850 {
7851 	return test_zuc_authentication(&zuc_test_case_auth_584b,
7852 			RTE_CRYPTO_AUTH_OP_GENERATE);
7853 }
7854 
7855 static int
7856 test_zuc_hash_verify_test_case_1(void)
7857 {
7858 	return test_zuc_authentication(&zuc_test_case_auth_1b,
7859 			RTE_CRYPTO_AUTH_OP_VERIFY);
7860 }
7861 
7862 static int
7863 test_zuc_hash_verify_test_case_2(void)
7864 {
7865 	return test_zuc_authentication(&zuc_test_case_auth_90b,
7866 			RTE_CRYPTO_AUTH_OP_VERIFY);
7867 }
7868 
7869 static int
7870 test_zuc_hash_verify_test_case_3(void)
7871 {
7872 	return test_zuc_authentication(&zuc_test_case_auth_577b,
7873 			RTE_CRYPTO_AUTH_OP_VERIFY);
7874 }
7875 
7876 static int
7877 test_zuc_hash_verify_test_case_4(void)
7878 {
7879 	return test_zuc_authentication(&zuc_test_case_auth_2079b,
7880 			RTE_CRYPTO_AUTH_OP_VERIFY);
7881 }
7882 
7883 static int
7884 test_zuc_hash_verify_test_case_5(void)
7885 {
7886 	return test_zuc_authentication(&zuc_test_auth_5670b,
7887 			RTE_CRYPTO_AUTH_OP_VERIFY);
7888 }
7889 
7890 static int
7891 test_zuc_hash_verify_test_case_6(void)
7892 {
7893 	return test_zuc_authentication(&zuc_test_case_auth_128b,
7894 			RTE_CRYPTO_AUTH_OP_VERIFY);
7895 }
7896 
7897 static int
7898 test_zuc_hash_verify_test_case_7(void)
7899 {
7900 	return test_zuc_authentication(&zuc_test_case_auth_2080b,
7901 			RTE_CRYPTO_AUTH_OP_VERIFY);
7902 }
7903 
7904 static int
7905 test_zuc_hash_verify_test_case_8(void)
7906 {
7907 	return test_zuc_authentication(&zuc_test_case_auth_584b,
7908 			RTE_CRYPTO_AUTH_OP_VERIFY);
7909 }
7910 
7911 static int
7912 test_zuc_cipher_auth_test_case_1(void)
7913 {
7914 	return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
7915 }
7916 
7917 static int
7918 test_zuc_cipher_auth_test_case_2(void)
7919 {
7920 	return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
7921 }
7922 
7923 static int
7924 test_zuc_auth_cipher_test_case_1(void)
7925 {
7926 	return test_zuc_auth_cipher(
7927 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7928 }
7929 
7930 static int
7931 test_zuc_auth_cipher_test_case_1_oop(void)
7932 {
7933 	return test_zuc_auth_cipher(
7934 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7935 }
7936 
7937 static int
7938 test_zuc_auth_cipher_test_case_1_sgl(void)
7939 {
7940 	return test_zuc_auth_cipher_sgl(
7941 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7942 }
7943 
7944 static int
7945 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
7946 {
7947 	return test_zuc_auth_cipher_sgl(
7948 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7949 }
7950 
7951 static int
7952 test_zuc_auth_cipher_test_case_2(void)
7953 {
7954 	return test_zuc_auth_cipher(
7955 		&zuc_auth_cipher_test_case_2, IN_PLACE, 0);
7956 }
7957 
7958 static int
7959 test_zuc_auth_cipher_test_case_2_oop(void)
7960 {
7961 	return test_zuc_auth_cipher(
7962 		&zuc_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7963 }
7964 
7965 static int
7966 test_zuc_auth_cipher_verify_test_case_1(void)
7967 {
7968 	return test_zuc_auth_cipher(
7969 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7970 }
7971 
7972 static int
7973 test_zuc_auth_cipher_verify_test_case_1_oop(void)
7974 {
7975 	return test_zuc_auth_cipher(
7976 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7977 }
7978 
7979 static int
7980 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
7981 {
7982 	return test_zuc_auth_cipher_sgl(
7983 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7984 }
7985 
7986 static int
7987 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
7988 {
7989 	return test_zuc_auth_cipher_sgl(
7990 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7991 }
7992 
7993 static int
7994 test_zuc_auth_cipher_verify_test_case_2(void)
7995 {
7996 	return test_zuc_auth_cipher(
7997 		&zuc_auth_cipher_test_case_2, IN_PLACE, 1);
7998 }
7999 
8000 static int
8001 test_zuc_auth_cipher_verify_test_case_2_oop(void)
8002 {
8003 	return test_zuc_auth_cipher(
8004 		&zuc_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
8005 }
8006 
8007 static int
8008 test_zuc256_encryption_test_case_1(void)
8009 {
8010 	return test_zuc_cipher(&zuc256_test_case_cipher_1,
8011 			RTE_CRYPTO_CIPHER_OP_ENCRYPT);
8012 }
8013 
8014 static int
8015 test_zuc256_encryption_test_case_2(void)
8016 {
8017 	return test_zuc_cipher(&zuc256_test_case_cipher_2,
8018 			RTE_CRYPTO_CIPHER_OP_ENCRYPT);
8019 }
8020 
8021 static int
8022 test_zuc256_decryption_test_case_1(void)
8023 {
8024 	return test_zuc_cipher(&zuc256_test_case_cipher_1,
8025 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
8026 }
8027 
8028 static int
8029 test_zuc256_decryption_test_case_2(void)
8030 {
8031 	return test_zuc_cipher(&zuc256_test_case_cipher_2,
8032 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
8033 }
8034 
8035 static int
8036 test_zuc256_hash_generate_4b_tag_test_case_1(void)
8037 {
8038 	return test_zuc_authentication(&zuc256_test_case_auth_1,
8039 			RTE_CRYPTO_AUTH_OP_GENERATE);
8040 }
8041 
8042 static int
8043 test_zuc256_hash_generate_4b_tag_test_case_2(void)
8044 {
8045 	return test_zuc_authentication(&zuc256_test_case_auth_2,
8046 			RTE_CRYPTO_AUTH_OP_GENERATE);
8047 }
8048 
8049 static int
8050 test_zuc256_hash_generate_4b_tag_test_case_3(void)
8051 {
8052 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b,
8053 			RTE_CRYPTO_AUTH_OP_GENERATE);
8054 }
8055 
8056 static int
8057 test_zuc256_hash_generate_8b_tag_test_case_1(void)
8058 {
8059 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b,
8060 			RTE_CRYPTO_AUTH_OP_GENERATE);
8061 }
8062 
8063 static int
8064 test_zuc256_hash_generate_16b_tag_test_case_1(void)
8065 {
8066 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b,
8067 			RTE_CRYPTO_AUTH_OP_GENERATE);
8068 }
8069 
8070 static int
8071 test_zuc256_hash_verify_4b_tag_test_case_1(void)
8072 {
8073 	return test_zuc_authentication(&zuc256_test_case_auth_1,
8074 			RTE_CRYPTO_AUTH_OP_VERIFY);
8075 }
8076 
8077 static int
8078 test_zuc256_hash_verify_4b_tag_test_case_2(void)
8079 {
8080 	return test_zuc_authentication(&zuc256_test_case_auth_2,
8081 			RTE_CRYPTO_AUTH_OP_VERIFY);
8082 }
8083 
8084 static int
8085 test_zuc256_hash_verify_4b_tag_test_case_3(void)
8086 {
8087 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b,
8088 			RTE_CRYPTO_AUTH_OP_VERIFY);
8089 }
8090 
8091 static int
8092 test_zuc256_hash_verify_8b_tag_test_case_1(void)
8093 {
8094 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b,
8095 			RTE_CRYPTO_AUTH_OP_VERIFY);
8096 }
8097 
8098 static int
8099 test_zuc256_hash_verify_16b_tag_test_case_1(void)
8100 {
8101 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b,
8102 			RTE_CRYPTO_AUTH_OP_VERIFY);
8103 }
8104 
8105 static int
8106 test_zuc256_cipher_auth_4b_tag_test_case_1(void)
8107 {
8108 	return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_1);
8109 }
8110 
8111 static int
8112 test_zuc256_cipher_auth_4b_tag_test_case_2(void)
8113 {
8114 	return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_2);
8115 }
8116 
8117 static int
8118 test_zuc256_cipher_auth_8b_tag_test_case_1(void)
8119 {
8120 	return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_3);
8121 }
8122 
8123 static int
8124 test_zuc256_cipher_auth_16b_tag_test_case_1(void)
8125 {
8126 	return test_zuc_cipher_auth(&zuc256_test_case_cipher_auth_4);
8127 }
8128 
8129 static int
8130 test_zuc256_auth_cipher_4b_tag_test_case_1(void)
8131 {
8132 	return test_zuc_auth_cipher(
8133 		&zuc256_auth_cipher_test_case_1, IN_PLACE, 0);
8134 }
8135 
8136 static int
8137 test_zuc256_auth_cipher_4b_tag_test_case_2(void)
8138 {
8139 	return test_zuc_auth_cipher(
8140 		&zuc256_auth_cipher_test_case_2, IN_PLACE, 0);
8141 }
8142 
8143 static int
8144 test_zuc256_auth_cipher_8b_tag_test_case_1(void)
8145 {
8146 	return test_zuc_auth_cipher(
8147 		&zuc256_auth_cipher_test_case_3, IN_PLACE, 0);
8148 }
8149 
8150 static int
8151 test_zuc256_auth_cipher_16b_tag_test_case_1(void)
8152 {
8153 	return test_zuc_auth_cipher(
8154 		&zuc256_auth_cipher_test_case_4, IN_PLACE, 0);
8155 }
8156 
8157 static int
8158 test_zuc256_auth_cipher_verify_4b_tag_test_case_1(void)
8159 {
8160 	return test_zuc_auth_cipher(
8161 		&zuc256_auth_cipher_test_case_1, IN_PLACE, 1);
8162 }
8163 
8164 static int
8165 test_zuc256_auth_cipher_verify_4b_tag_test_case_2(void)
8166 {
8167 	return test_zuc_auth_cipher(
8168 		&zuc256_auth_cipher_test_case_2, IN_PLACE, 1);
8169 }
8170 
8171 static int
8172 test_zuc256_auth_cipher_verify_8b_tag_test_case_1(void)
8173 {
8174 	return test_zuc_auth_cipher(
8175 		&zuc256_auth_cipher_test_case_3, IN_PLACE, 1);
8176 }
8177 
8178 static int
8179 test_zuc256_auth_cipher_verify_16b_tag_test_case_1(void)
8180 {
8181 	return test_zuc_auth_cipher(
8182 		&zuc256_auth_cipher_test_case_4, IN_PLACE, 1);
8183 }
8184 
8185 static int
8186 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
8187 {
8188 	uint8_t dev_id = testsuite_params.valid_devs[0];
8189 
8190 	struct rte_cryptodev_sym_capability_idx cap_idx;
8191 
8192 	/* Check if device supports particular cipher algorithm */
8193 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8194 	cap_idx.algo.cipher = tdata->cipher_algo;
8195 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
8196 		return TEST_SKIPPED;
8197 
8198 	/* Check if device supports particular hash algorithm */
8199 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8200 	cap_idx.algo.auth = tdata->auth_algo;
8201 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
8202 		return TEST_SKIPPED;
8203 
8204 	return 0;
8205 }
8206 
8207 static int
8208 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
8209 	uint8_t op_mode, uint8_t verify)
8210 {
8211 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8212 	struct crypto_unittest_params *ut_params = &unittest_params;
8213 
8214 	int retval;
8215 
8216 	uint8_t *plaintext = NULL, *ciphertext = NULL;
8217 	unsigned int plaintext_pad_len;
8218 	unsigned int plaintext_len;
8219 	unsigned int ciphertext_pad_len;
8220 	unsigned int ciphertext_len;
8221 	unsigned int digest_offset;
8222 
8223 	struct rte_cryptodev_info dev_info;
8224 	struct rte_crypto_op *op;
8225 
8226 	/* Check if device supports particular algorithms separately */
8227 	if (test_mixed_check_if_unsupported(tdata))
8228 		return TEST_SKIPPED;
8229 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
8230 		return TEST_SKIPPED;
8231 
8232 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8233 		return TEST_SKIPPED;
8234 
8235 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8236 
8237 	uint64_t feat_flags = dev_info.feature_flags;
8238 
8239 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
8240 		printf("Device doesn't support digest encrypted.\n");
8241 		return TEST_SKIPPED;
8242 	}
8243 
8244 	/* Create the session */
8245 	if (verify)
8246 		retval = create_wireless_algo_cipher_auth_session(
8247 				ts_params->valid_devs[0],
8248 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
8249 				RTE_CRYPTO_AUTH_OP_VERIFY,
8250 				tdata->auth_algo,
8251 				tdata->cipher_algo,
8252 				tdata->auth_key.data, tdata->auth_key.len,
8253 				tdata->cipher_key.data, tdata->cipher_key.len,
8254 				tdata->auth_iv.len, tdata->digest_enc.len,
8255 				tdata->cipher_iv.len);
8256 	else
8257 		retval = create_wireless_algo_auth_cipher_session(
8258 				ts_params->valid_devs[0],
8259 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8260 				RTE_CRYPTO_AUTH_OP_GENERATE,
8261 				tdata->auth_algo,
8262 				tdata->cipher_algo,
8263 				tdata->auth_key.data, tdata->auth_key.len,
8264 				tdata->cipher_key.data, tdata->cipher_key.len,
8265 				tdata->auth_iv.len, tdata->digest_enc.len,
8266 				tdata->cipher_iv.len);
8267 	if (retval != 0)
8268 		return retval;
8269 
8270 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8271 	if (op_mode == OUT_OF_PLACE)
8272 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8273 
8274 	/* clear mbuf payload */
8275 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8276 		rte_pktmbuf_tailroom(ut_params->ibuf));
8277 	if (op_mode == OUT_OF_PLACE) {
8278 
8279 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
8280 				rte_pktmbuf_tailroom(ut_params->obuf));
8281 	}
8282 
8283 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
8284 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
8285 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
8286 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
8287 
8288 	if (verify) {
8289 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8290 				ciphertext_pad_len);
8291 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
8292 		debug_hexdump(stdout, "ciphertext:", ciphertext,
8293 				ciphertext_len);
8294 	} else {
8295 		/* make sure enough space to cover partial digest verify case */
8296 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8297 				ciphertext_pad_len);
8298 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
8299 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
8300 	}
8301 
8302 	if (op_mode == OUT_OF_PLACE)
8303 		rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
8304 
8305 	/* Create the operation */
8306 	retval = create_wireless_algo_auth_cipher_operation(
8307 			tdata->digest_enc.data, tdata->digest_enc.len,
8308 			tdata->cipher_iv.data, tdata->cipher_iv.len,
8309 			tdata->auth_iv.data, tdata->auth_iv.len,
8310 			(tdata->digest_enc.offset == 0 ?
8311 				plaintext_pad_len
8312 				: tdata->digest_enc.offset),
8313 			tdata->validCipherLen.len_bits,
8314 			tdata->cipher.offset_bits,
8315 			tdata->validAuthLen.len_bits,
8316 			tdata->auth.offset_bits,
8317 			op_mode, 0, verify);
8318 
8319 	if (retval < 0)
8320 		return retval;
8321 
8322 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
8323 
8324 	/* Check if the op failed because the device doesn't */
8325 	/* support this particular combination of algorithms */
8326 	if (op == NULL && ut_params->op->status ==
8327 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
8328 		printf("Device doesn't support this mixed combination. "
8329 				"Test Skipped.\n");
8330 		return TEST_SKIPPED;
8331 	}
8332 	ut_params->op = op;
8333 
8334 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
8335 
8336 	ut_params->obuf = (op_mode == IN_PLACE ?
8337 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
8338 
8339 	if (verify) {
8340 		if (ut_params->obuf)
8341 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
8342 							uint8_t *);
8343 		else
8344 			plaintext = ciphertext +
8345 					(tdata->cipher.offset_bits >> 3);
8346 
8347 		debug_hexdump(stdout, "plaintext:", plaintext,
8348 				tdata->plaintext.len_bits >> 3);
8349 		debug_hexdump(stdout, "plaintext expected:",
8350 				tdata->plaintext.data,
8351 				tdata->plaintext.len_bits >> 3);
8352 	} else {
8353 		if (ut_params->obuf)
8354 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
8355 					uint8_t *);
8356 		else
8357 			ciphertext = plaintext;
8358 
8359 		debug_hexdump(stdout, "ciphertext:", ciphertext,
8360 				ciphertext_len);
8361 		debug_hexdump(stdout, "ciphertext expected:",
8362 				tdata->ciphertext.data,
8363 				tdata->ciphertext.len_bits >> 3);
8364 
8365 		if (tdata->digest_enc.offset == 0)
8366 			digest_offset = plaintext_pad_len;
8367 		else
8368 			digest_offset = tdata->digest_enc.offset;
8369 
8370 		ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
8371 					    uint8_t *, digest_offset);
8372 
8373 		debug_hexdump(stdout, "digest:", ut_params->digest,
8374 				tdata->digest_enc.len);
8375 		debug_hexdump(stdout, "digest expected:",
8376 				tdata->digest_enc.data,
8377 				tdata->digest_enc.len);
8378 	}
8379 
8380 	if (!verify) {
8381 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
8382 				ut_params->digest,
8383 				tdata->digest_enc.data,
8384 				tdata->digest_enc.len,
8385 				"Generated auth tag not as expected");
8386 	}
8387 
8388 	if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
8389 		if (verify) {
8390 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
8391 					plaintext,
8392 					tdata->plaintext.data,
8393 					tdata->plaintext.len_bits >> 3,
8394 					"Plaintext data not as expected");
8395 		} else {
8396 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
8397 					ciphertext,
8398 					tdata->ciphertext.data,
8399 					tdata->validDataLen.len_bits,
8400 					"Ciphertext data not as expected");
8401 		}
8402 	}
8403 
8404 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8405 			"crypto op processing failed");
8406 
8407 	return 0;
8408 }
8409 
8410 static int
8411 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
8412 	uint8_t op_mode, uint8_t verify)
8413 {
8414 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8415 	struct crypto_unittest_params *ut_params = &unittest_params;
8416 
8417 	int retval;
8418 
8419 	const uint8_t *plaintext = NULL;
8420 	const uint8_t *ciphertext = NULL;
8421 	const uint8_t *digest = NULL;
8422 	unsigned int plaintext_pad_len;
8423 	unsigned int plaintext_len;
8424 	unsigned int ciphertext_pad_len;
8425 	unsigned int ciphertext_len;
8426 	uint8_t buffer[10000];
8427 	uint8_t digest_buffer[10000];
8428 
8429 	struct rte_cryptodev_info dev_info;
8430 	struct rte_crypto_op *op;
8431 
8432 	/* Check if device supports particular algorithms */
8433 	if (test_mixed_check_if_unsupported(tdata))
8434 		return TEST_SKIPPED;
8435 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
8436 		return TEST_SKIPPED;
8437 
8438 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8439 
8440 	uint64_t feat_flags = dev_info.feature_flags;
8441 
8442 	if (op_mode == IN_PLACE) {
8443 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
8444 			printf("Device doesn't support in-place scatter-gather "
8445 					"in both input and output mbufs.\n");
8446 			return TEST_SKIPPED;
8447 		}
8448 	} else {
8449 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
8450 			printf("Device doesn't support out-of-place scatter-gather "
8451 					"in both input and output mbufs.\n");
8452 			return TEST_SKIPPED;
8453 		}
8454 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
8455 			printf("Device doesn't support digest encrypted.\n");
8456 			return TEST_SKIPPED;
8457 		}
8458 	}
8459 
8460 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8461 		return TEST_SKIPPED;
8462 
8463 	/* Create the session */
8464 	if (verify)
8465 		retval = create_wireless_algo_cipher_auth_session(
8466 				ts_params->valid_devs[0],
8467 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
8468 				RTE_CRYPTO_AUTH_OP_VERIFY,
8469 				tdata->auth_algo,
8470 				tdata->cipher_algo,
8471 				tdata->auth_key.data, tdata->auth_key.len,
8472 				tdata->cipher_key.data, tdata->cipher_key.len,
8473 				tdata->auth_iv.len, tdata->digest_enc.len,
8474 				tdata->cipher_iv.len);
8475 	else
8476 		retval = create_wireless_algo_auth_cipher_session(
8477 				ts_params->valid_devs[0],
8478 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8479 				RTE_CRYPTO_AUTH_OP_GENERATE,
8480 				tdata->auth_algo,
8481 				tdata->cipher_algo,
8482 				tdata->auth_key.data, tdata->auth_key.len,
8483 				tdata->cipher_key.data, tdata->cipher_key.len,
8484 				tdata->auth_iv.len, tdata->digest_enc.len,
8485 				tdata->cipher_iv.len);
8486 	if (retval != 0)
8487 		return retval;
8488 
8489 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
8490 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
8491 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
8492 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
8493 
8494 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
8495 			ciphertext_pad_len, 15, 0);
8496 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
8497 			"Failed to allocate input buffer in mempool");
8498 
8499 	if (op_mode == OUT_OF_PLACE) {
8500 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
8501 				plaintext_pad_len, 15, 0);
8502 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
8503 				"Failed to allocate output buffer in mempool");
8504 	}
8505 
8506 	if (verify) {
8507 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
8508 			tdata->ciphertext.data);
8509 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
8510 					ciphertext_len, buffer);
8511 		debug_hexdump(stdout, "ciphertext:", ciphertext,
8512 			ciphertext_len);
8513 	} else {
8514 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
8515 			tdata->plaintext.data);
8516 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
8517 					plaintext_len, buffer);
8518 		debug_hexdump(stdout, "plaintext:", plaintext,
8519 			plaintext_len);
8520 	}
8521 	memset(buffer, 0, sizeof(buffer));
8522 
8523 	/* Create the operation */
8524 	retval = create_wireless_algo_auth_cipher_operation(
8525 			tdata->digest_enc.data, tdata->digest_enc.len,
8526 			tdata->cipher_iv.data, tdata->cipher_iv.len,
8527 			tdata->auth_iv.data, tdata->auth_iv.len,
8528 			(tdata->digest_enc.offset == 0 ?
8529 				plaintext_pad_len
8530 				: tdata->digest_enc.offset),
8531 			tdata->validCipherLen.len_bits,
8532 			tdata->cipher.offset_bits,
8533 			tdata->validAuthLen.len_bits,
8534 			tdata->auth.offset_bits,
8535 			op_mode, 1, verify);
8536 
8537 	if (retval < 0)
8538 		return retval;
8539 
8540 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
8541 
8542 	/* Check if the op failed because the device doesn't */
8543 	/* support this particular combination of algorithms */
8544 	if (op == NULL && ut_params->op->status ==
8545 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
8546 		printf("Device doesn't support this mixed combination. "
8547 				"Test Skipped.\n");
8548 		return TEST_SKIPPED;
8549 	}
8550 	ut_params->op = op;
8551 
8552 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
8553 
8554 	ut_params->obuf = (op_mode == IN_PLACE ?
8555 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
8556 
8557 	if (verify) {
8558 		if (ut_params->obuf)
8559 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
8560 					plaintext_len, buffer);
8561 		else
8562 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
8563 					plaintext_len, buffer);
8564 
8565 		debug_hexdump(stdout, "plaintext:", plaintext,
8566 				(tdata->plaintext.len_bits >> 3) -
8567 				tdata->digest_enc.len);
8568 		debug_hexdump(stdout, "plaintext expected:",
8569 				tdata->plaintext.data,
8570 				(tdata->plaintext.len_bits >> 3) -
8571 				tdata->digest_enc.len);
8572 	} else {
8573 		if (ut_params->obuf)
8574 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
8575 					ciphertext_len, buffer);
8576 		else
8577 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
8578 					ciphertext_len, buffer);
8579 
8580 		debug_hexdump(stdout, "ciphertext:", ciphertext,
8581 			ciphertext_len);
8582 		debug_hexdump(stdout, "ciphertext expected:",
8583 			tdata->ciphertext.data,
8584 			tdata->ciphertext.len_bits >> 3);
8585 
8586 		if (ut_params->obuf)
8587 			digest = rte_pktmbuf_read(ut_params->obuf,
8588 					(tdata->digest_enc.offset == 0 ?
8589 						plaintext_pad_len :
8590 						tdata->digest_enc.offset),
8591 					tdata->digest_enc.len, digest_buffer);
8592 		else
8593 			digest = rte_pktmbuf_read(ut_params->ibuf,
8594 					(tdata->digest_enc.offset == 0 ?
8595 						plaintext_pad_len :
8596 						tdata->digest_enc.offset),
8597 					tdata->digest_enc.len, digest_buffer);
8598 
8599 		debug_hexdump(stdout, "digest:", digest,
8600 				tdata->digest_enc.len);
8601 		debug_hexdump(stdout, "digest expected:",
8602 				tdata->digest_enc.data, tdata->digest_enc.len);
8603 	}
8604 
8605 	if (!verify) {
8606 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
8607 				digest,
8608 				tdata->digest_enc.data,
8609 				tdata->digest_enc.len,
8610 				"Generated auth tag not as expected");
8611 	}
8612 
8613 	if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
8614 		if (verify) {
8615 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
8616 					plaintext,
8617 					tdata->plaintext.data,
8618 					tdata->plaintext.len_bits >> 3,
8619 					"Plaintext data not as expected");
8620 		} else {
8621 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
8622 					ciphertext,
8623 					tdata->ciphertext.data,
8624 					tdata->validDataLen.len_bits,
8625 					"Ciphertext data not as expected");
8626 		}
8627 	}
8628 
8629 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8630 			"crypto op processing failed");
8631 
8632 	return 0;
8633 }
8634 
8635 /** AUTH AES CMAC + CIPHER AES CTR */
8636 
8637 static int
8638 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
8639 {
8640 	return test_mixed_auth_cipher(
8641 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
8642 }
8643 
8644 static int
8645 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
8646 {
8647 	return test_mixed_auth_cipher(
8648 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
8649 }
8650 
8651 static int
8652 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
8653 {
8654 	return test_mixed_auth_cipher_sgl(
8655 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
8656 }
8657 
8658 static int
8659 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
8660 {
8661 	return test_mixed_auth_cipher_sgl(
8662 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
8663 }
8664 
8665 static int
8666 test_aes_cmac_aes_ctr_digest_enc_test_case_2(void)
8667 {
8668 	return test_mixed_auth_cipher(
8669 		&auth_aes_cmac_cipher_aes_ctr_test_case_2, IN_PLACE, 0);
8670 }
8671 
8672 static int
8673 test_aes_cmac_aes_ctr_digest_enc_test_case_2_oop(void)
8674 {
8675 	return test_mixed_auth_cipher(
8676 		&auth_aes_cmac_cipher_aes_ctr_test_case_2, OUT_OF_PLACE, 0);
8677 }
8678 
8679 static int
8680 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
8681 {
8682 	return test_mixed_auth_cipher(
8683 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
8684 }
8685 
8686 static int
8687 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2(void)
8688 {
8689 	return test_mixed_auth_cipher(
8690 		&auth_aes_cmac_cipher_aes_ctr_test_case_2, IN_PLACE, 1);
8691 }
8692 
8693 static int
8694 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
8695 {
8696 	return test_mixed_auth_cipher(
8697 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
8698 }
8699 
8700 static int
8701 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
8702 {
8703 	return test_mixed_auth_cipher_sgl(
8704 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
8705 }
8706 
8707 static int
8708 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
8709 {
8710 	return test_mixed_auth_cipher_sgl(
8711 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
8712 }
8713 
8714 static int
8715 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2_oop(void)
8716 {
8717 	return test_mixed_auth_cipher(
8718 		&auth_aes_cmac_cipher_aes_ctr_test_case_2, OUT_OF_PLACE, 1);
8719 }
8720 
8721 /** MIXED AUTH + CIPHER */
8722 
8723 static int
8724 test_auth_zuc_cipher_snow_test_case_1(void)
8725 {
8726 	return test_mixed_auth_cipher(
8727 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
8728 }
8729 
8730 static int
8731 test_verify_auth_zuc_cipher_snow_test_case_1(void)
8732 {
8733 	return test_mixed_auth_cipher(
8734 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
8735 }
8736 
8737 static int
8738 test_auth_zuc_cipher_snow_test_case_1_inplace(void)
8739 {
8740 	return test_mixed_auth_cipher(
8741 		&auth_zuc_cipher_snow_test_case_1, IN_PLACE, 0);
8742 }
8743 
8744 static int
8745 test_verify_auth_zuc_cipher_snow_test_case_1_inplace(void)
8746 {
8747 	return test_mixed_auth_cipher(
8748 		&auth_zuc_cipher_snow_test_case_1, IN_PLACE, 1);
8749 }
8750 
8751 
8752 static int
8753 test_auth_aes_cmac_cipher_snow_test_case_1(void)
8754 {
8755 	return test_mixed_auth_cipher(
8756 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
8757 }
8758 
8759 static int
8760 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
8761 {
8762 	return test_mixed_auth_cipher(
8763 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
8764 }
8765 
8766 static int
8767 test_auth_aes_cmac_cipher_snow_test_case_1_inplace(void)
8768 {
8769 	return test_mixed_auth_cipher(
8770 		&auth_aes_cmac_cipher_snow_test_case_1, IN_PLACE, 0);
8771 }
8772 
8773 static int
8774 test_verify_auth_aes_cmac_cipher_snow_test_case_1_inplace(void)
8775 {
8776 	return test_mixed_auth_cipher(
8777 		&auth_aes_cmac_cipher_snow_test_case_1, IN_PLACE, 1);
8778 }
8779 
8780 static int
8781 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
8782 {
8783 	return test_mixed_auth_cipher(
8784 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
8785 }
8786 
8787 static int
8788 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
8789 {
8790 	return test_mixed_auth_cipher(
8791 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
8792 }
8793 
8794 static int
8795 test_auth_zuc_cipher_aes_ctr_test_case_1_inplace(void)
8796 {
8797 	return test_mixed_auth_cipher(
8798 		&auth_zuc_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
8799 }
8800 
8801 static int
8802 test_verify_auth_zuc_cipher_aes_ctr_test_case_1_inplace(void)
8803 {
8804 	return test_mixed_auth_cipher(
8805 		&auth_zuc_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
8806 }
8807 
8808 static int
8809 test_auth_snow_cipher_aes_ctr_test_case_1(void)
8810 {
8811 	return test_mixed_auth_cipher(
8812 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
8813 }
8814 
8815 static int
8816 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
8817 {
8818 	return test_mixed_auth_cipher(
8819 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
8820 }
8821 
8822 static int
8823 test_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl(void)
8824 {
8825 	return test_mixed_auth_cipher_sgl(
8826 		&auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
8827 }
8828 
8829 static int
8830 test_auth_snow_cipher_aes_ctr_test_case_1_inplace(void)
8831 {
8832 	return test_mixed_auth_cipher(
8833 		&auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
8834 }
8835 
8836 static int
8837 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl(void)
8838 {
8839 	return test_mixed_auth_cipher_sgl(
8840 		&auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
8841 }
8842 
8843 static int
8844 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace(void)
8845 {
8846 	return test_mixed_auth_cipher(
8847 		&auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
8848 }
8849 
8850 static int
8851 test_auth_snow_cipher_zuc_test_case_1(void)
8852 {
8853 	return test_mixed_auth_cipher(
8854 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
8855 }
8856 
8857 static int
8858 test_verify_auth_snow_cipher_zuc_test_case_1(void)
8859 {
8860 	return test_mixed_auth_cipher(
8861 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
8862 }
8863 
8864 static int
8865 test_auth_snow_cipher_zuc_test_case_1_inplace(void)
8866 {
8867 	return test_mixed_auth_cipher(
8868 		&auth_snow_cipher_zuc_test_case_1, IN_PLACE, 0);
8869 }
8870 
8871 static int
8872 test_verify_auth_snow_cipher_zuc_test_case_1_inplace(void)
8873 {
8874 	return test_mixed_auth_cipher(
8875 		&auth_snow_cipher_zuc_test_case_1, IN_PLACE, 1);
8876 }
8877 
8878 static int
8879 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
8880 {
8881 	return test_mixed_auth_cipher(
8882 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
8883 }
8884 
8885 static int
8886 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
8887 {
8888 	return test_mixed_auth_cipher(
8889 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
8890 }
8891 static int
8892 test_auth_aes_cmac_cipher_zuc_test_case_1_inplace(void)
8893 {
8894 	return test_mixed_auth_cipher(
8895 		&auth_aes_cmac_cipher_zuc_test_case_1, IN_PLACE, 0);
8896 }
8897 
8898 static int
8899 test_verify_auth_aes_cmac_cipher_zuc_test_case_1_inplace(void)
8900 {
8901 	return test_mixed_auth_cipher(
8902 		&auth_aes_cmac_cipher_zuc_test_case_1, IN_PLACE, 1);
8903 }
8904 
8905 static int
8906 test_auth_null_cipher_snow_test_case_1(void)
8907 {
8908 	return test_mixed_auth_cipher(
8909 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
8910 }
8911 
8912 static int
8913 test_verify_auth_null_cipher_snow_test_case_1(void)
8914 {
8915 	return test_mixed_auth_cipher(
8916 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
8917 }
8918 
8919 static int
8920 test_auth_null_cipher_zuc_test_case_1(void)
8921 {
8922 	return test_mixed_auth_cipher(
8923 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
8924 }
8925 
8926 static int
8927 test_verify_auth_null_cipher_zuc_test_case_1(void)
8928 {
8929 	return test_mixed_auth_cipher(
8930 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
8931 }
8932 
8933 static int
8934 test_auth_snow_cipher_null_test_case_1(void)
8935 {
8936 	return test_mixed_auth_cipher(
8937 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
8938 }
8939 
8940 static int
8941 test_verify_auth_snow_cipher_null_test_case_1(void)
8942 {
8943 	return test_mixed_auth_cipher(
8944 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
8945 }
8946 
8947 static int
8948 test_auth_zuc_cipher_null_test_case_1(void)
8949 {
8950 	return test_mixed_auth_cipher(
8951 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
8952 }
8953 
8954 static int
8955 test_verify_auth_zuc_cipher_null_test_case_1(void)
8956 {
8957 	return test_mixed_auth_cipher(
8958 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
8959 }
8960 
8961 static int
8962 test_auth_null_cipher_aes_ctr_test_case_1(void)
8963 {
8964 	return test_mixed_auth_cipher(
8965 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
8966 }
8967 
8968 static int
8969 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
8970 {
8971 	return test_mixed_auth_cipher(
8972 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
8973 }
8974 
8975 static int
8976 test_auth_aes_cmac_cipher_null_test_case_1(void)
8977 {
8978 	return test_mixed_auth_cipher(
8979 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
8980 }
8981 
8982 static int
8983 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
8984 {
8985 	return test_mixed_auth_cipher(
8986 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
8987 }
8988 
8989 /* ***** AEAD algorithm Tests ***** */
8990 
8991 static int
8992 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
8993 		enum rte_crypto_aead_operation op,
8994 		const uint8_t *key, const uint8_t key_len,
8995 		const uint16_t aad_len, const uint8_t auth_len,
8996 		uint8_t iv_len)
8997 {
8998 	uint8_t aead_key[key_len];
8999 
9000 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9001 	struct crypto_unittest_params *ut_params = &unittest_params;
9002 
9003 	memcpy(aead_key, key, key_len);
9004 
9005 	/* Setup AEAD Parameters */
9006 	ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9007 	ut_params->aead_xform.next = NULL;
9008 	ut_params->aead_xform.aead.algo = algo;
9009 	ut_params->aead_xform.aead.op = op;
9010 	ut_params->aead_xform.aead.key.data = aead_key;
9011 	ut_params->aead_xform.aead.key.length = key_len;
9012 	ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
9013 	ut_params->aead_xform.aead.iv.length = iv_len;
9014 	ut_params->aead_xform.aead.digest_length = auth_len;
9015 	ut_params->aead_xform.aead.aad_length = aad_len;
9016 
9017 	debug_hexdump(stdout, "key:", key, key_len);
9018 
9019 	/* Create Crypto session*/
9020 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
9021 			&ut_params->aead_xform, ts_params->session_mpool);
9022 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
9023 		return TEST_SKIPPED;
9024 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
9025 	return 0;
9026 }
9027 
9028 static int
9029 create_aead_xform(struct rte_crypto_op *op,
9030 		enum rte_crypto_aead_algorithm algo,
9031 		enum rte_crypto_aead_operation aead_op,
9032 		uint8_t *key, const uint8_t key_len,
9033 		const uint8_t aad_len, const uint8_t auth_len,
9034 		uint8_t iv_len)
9035 {
9036 	TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
9037 			"failed to allocate space for crypto transform");
9038 
9039 	struct rte_crypto_sym_op *sym_op = op->sym;
9040 
9041 	/* Setup AEAD Parameters */
9042 	sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
9043 	sym_op->xform->next = NULL;
9044 	sym_op->xform->aead.algo = algo;
9045 	sym_op->xform->aead.op = aead_op;
9046 	sym_op->xform->aead.key.data = key;
9047 	sym_op->xform->aead.key.length = key_len;
9048 	sym_op->xform->aead.iv.offset = IV_OFFSET;
9049 	sym_op->xform->aead.iv.length = iv_len;
9050 	sym_op->xform->aead.digest_length = auth_len;
9051 	sym_op->xform->aead.aad_length = aad_len;
9052 
9053 	debug_hexdump(stdout, "key:", key, key_len);
9054 
9055 	return 0;
9056 }
9057 
9058 static int
9059 create_aead_operation(enum rte_crypto_aead_operation op,
9060 		const struct aead_test_data *tdata)
9061 {
9062 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9063 	struct crypto_unittest_params *ut_params = &unittest_params;
9064 
9065 	uint8_t *plaintext, *ciphertext;
9066 	unsigned int aad_pad_len, plaintext_pad_len;
9067 
9068 	/* Generate Crypto op data structure */
9069 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9070 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9071 	TEST_ASSERT_NOT_NULL(ut_params->op,
9072 			"Failed to allocate symmetric crypto operation struct");
9073 
9074 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
9075 
9076 	/* Append aad data */
9077 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
9078 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
9079 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9080 				aad_pad_len);
9081 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
9082 				"no room to append aad");
9083 
9084 		sym_op->aead.aad.phys_addr =
9085 				rte_pktmbuf_iova(ut_params->ibuf);
9086 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
9087 		memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
9088 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data + 18,
9089 			tdata->aad.len);
9090 
9091 		/* Append IV at the end of the crypto operation*/
9092 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
9093 				uint8_t *, IV_OFFSET);
9094 
9095 		/* Copy IV 1 byte after the IV pointer, according to the API */
9096 		rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
9097 		debug_hexdump(stdout, "iv:", iv_ptr + 1,
9098 			tdata->iv.len);
9099 	} else {
9100 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
9101 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9102 				aad_pad_len);
9103 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
9104 				"no room to append aad");
9105 
9106 		sym_op->aead.aad.phys_addr =
9107 				rte_pktmbuf_iova(ut_params->ibuf);
9108 		memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
9109 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
9110 			tdata->aad.len);
9111 
9112 		/* Append IV at the end of the crypto operation*/
9113 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
9114 				uint8_t *, IV_OFFSET);
9115 
9116 		if (tdata->iv.len == 0) {
9117 			rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
9118 			debug_hexdump(stdout, "iv:", iv_ptr,
9119 				AES_GCM_J0_LENGTH);
9120 		} else {
9121 			rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
9122 			debug_hexdump(stdout, "iv:", iv_ptr,
9123 				tdata->iv.len);
9124 		}
9125 	}
9126 
9127 	/* Append plaintext/ciphertext */
9128 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
9129 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9130 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9131 				plaintext_pad_len);
9132 		TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
9133 
9134 		memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
9135 		debug_hexdump(stdout, "plaintext:", plaintext,
9136 				tdata->plaintext.len);
9137 
9138 		if (ut_params->obuf) {
9139 			ciphertext = (uint8_t *)rte_pktmbuf_append(
9140 					ut_params->obuf,
9141 					plaintext_pad_len + aad_pad_len);
9142 			TEST_ASSERT_NOT_NULL(ciphertext,
9143 					"no room to append ciphertext");
9144 
9145 			memset(ciphertext + aad_pad_len, 0,
9146 					tdata->ciphertext.len);
9147 		}
9148 	} else {
9149 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
9150 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9151 				plaintext_pad_len);
9152 		TEST_ASSERT_NOT_NULL(ciphertext,
9153 				"no room to append ciphertext");
9154 
9155 		memcpy(ciphertext, tdata->ciphertext.data,
9156 				tdata->ciphertext.len);
9157 		debug_hexdump(stdout, "ciphertext:", ciphertext,
9158 				tdata->ciphertext.len);
9159 
9160 		if (ut_params->obuf) {
9161 			plaintext = (uint8_t *)rte_pktmbuf_append(
9162 					ut_params->obuf,
9163 					plaintext_pad_len + aad_pad_len);
9164 			TEST_ASSERT_NOT_NULL(plaintext,
9165 					"no room to append plaintext");
9166 
9167 			memset(plaintext + aad_pad_len, 0,
9168 					tdata->plaintext.len);
9169 		}
9170 	}
9171 
9172 	/* Append digest data */
9173 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
9174 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
9175 				ut_params->obuf ? ut_params->obuf :
9176 						ut_params->ibuf,
9177 						tdata->auth_tag.len);
9178 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
9179 				"no room to append digest");
9180 		memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
9181 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
9182 				ut_params->obuf ? ut_params->obuf :
9183 						ut_params->ibuf,
9184 						plaintext_pad_len +
9185 						aad_pad_len);
9186 	} else {
9187 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
9188 				ut_params->ibuf, tdata->auth_tag.len);
9189 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
9190 				"no room to append digest");
9191 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
9192 				ut_params->ibuf,
9193 				plaintext_pad_len + aad_pad_len);
9194 
9195 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
9196 			tdata->auth_tag.len);
9197 		debug_hexdump(stdout, "digest:",
9198 			sym_op->aead.digest.data,
9199 			tdata->auth_tag.len);
9200 	}
9201 
9202 	sym_op->aead.data.length = tdata->plaintext.len;
9203 	sym_op->aead.data.offset = aad_pad_len;
9204 
9205 	return 0;
9206 }
9207 
9208 static int
9209 test_authenticated_encryption_helper(const struct aead_test_data *tdata, bool use_ext_mbuf)
9210 {
9211 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9212 	struct crypto_unittest_params *ut_params = &unittest_params;
9213 
9214 	int retval;
9215 	uint8_t *ciphertext, *auth_tag;
9216 	uint16_t plaintext_pad_len;
9217 	uint32_t i;
9218 	struct rte_cryptodev_info dev_info;
9219 
9220 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9221 	uint64_t feat_flags = dev_info.feature_flags;
9222 
9223 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
9224 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
9225 		printf("Device doesn't support RAW data-path APIs.\n");
9226 		return TEST_SKIPPED;
9227 	}
9228 
9229 	/* Verify the capabilities */
9230 	struct rte_cryptodev_sym_capability_idx cap_idx;
9231 	const struct rte_cryptodev_symmetric_capability *capability;
9232 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9233 	cap_idx.algo.aead = tdata->algo;
9234 	capability = rte_cryptodev_sym_capability_get(
9235 			ts_params->valid_devs[0], &cap_idx);
9236 	if (capability == NULL)
9237 		return TEST_SKIPPED;
9238 	if (rte_cryptodev_sym_capability_check_aead(
9239 			capability, tdata->key.len, tdata->auth_tag.len,
9240 			tdata->aad.len, tdata->iv.len))
9241 		return TEST_SKIPPED;
9242 
9243 	/* Create AEAD session */
9244 	retval = create_aead_session(ts_params->valid_devs[0],
9245 			tdata->algo,
9246 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
9247 			tdata->key.data, tdata->key.len,
9248 			tdata->aad.len, tdata->auth_tag.len,
9249 			tdata->iv.len);
9250 	if (retval != TEST_SUCCESS)
9251 		return retval;
9252 
9253 	if (tdata->aad.len > MBUF_SIZE) {
9254 		if (use_ext_mbuf) {
9255 			ut_params->ibuf = ext_mbuf_create(ts_params->large_mbuf_pool,
9256 							  AEAD_TEXT_MAX_LENGTH,
9257 							  1 /* nb_segs */,
9258 							  NULL);
9259 		} else {
9260 			ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
9261 		}
9262 		/* Populate full size of add data */
9263 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
9264 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
9265 	} else {
9266 		if (use_ext_mbuf) {
9267 			ut_params->ibuf = ext_mbuf_create(ts_params->mbuf_pool,
9268 							  AEAD_TEXT_MAX_LENGTH,
9269 							  1 /* nb_segs */,
9270 							  NULL);
9271 		} else {
9272 			ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9273 		}
9274 	}
9275 
9276 	/* clear mbuf payload */
9277 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9278 			rte_pktmbuf_tailroom(ut_params->ibuf));
9279 
9280 	/* Create AEAD operation */
9281 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
9282 	if (retval < 0)
9283 		return retval;
9284 
9285 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9286 
9287 	ut_params->op->sym->m_src = ut_params->ibuf;
9288 
9289 	/* Process crypto operation */
9290 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9291 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
9292 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
9293 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0,
9294 					       0);
9295 		if (retval != TEST_SUCCESS)
9296 			return retval;
9297 	} else
9298 		TEST_ASSERT_NOT_NULL(
9299 			process_crypto_request(ts_params->valid_devs[0],
9300 			ut_params->op), "failed to process sym crypto op");
9301 
9302 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9303 			"crypto op processing failed");
9304 
9305 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9306 
9307 	if (ut_params->op->sym->m_dst) {
9308 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
9309 				uint8_t *);
9310 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
9311 				uint8_t *, plaintext_pad_len);
9312 	} else {
9313 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
9314 				uint8_t *,
9315 				ut_params->op->sym->cipher.data.offset);
9316 		auth_tag = ciphertext + plaintext_pad_len;
9317 	}
9318 
9319 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
9320 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
9321 
9322 	/* Validate obuf */
9323 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
9324 			ciphertext,
9325 			tdata->ciphertext.data,
9326 			tdata->ciphertext.len,
9327 			"Ciphertext data not as expected");
9328 
9329 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
9330 			auth_tag,
9331 			tdata->auth_tag.data,
9332 			tdata->auth_tag.len,
9333 			"Generated auth tag not as expected");
9334 
9335 	return 0;
9336 
9337 }
9338 
9339 static int
9340 test_authenticated_encryption(const struct aead_test_data *tdata)
9341 {
9342 	return test_authenticated_encryption_helper(tdata, false);
9343 }
9344 
9345 #ifdef RTE_LIB_SECURITY
9346 static int
9347 security_proto_supported(enum rte_security_session_action_type action,
9348 	enum rte_security_session_protocol proto)
9349 {
9350 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9351 
9352 	const struct rte_security_capability *capabilities;
9353 	const struct rte_security_capability *capability;
9354 	uint16_t i = 0;
9355 
9356 	void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]);
9357 
9358 
9359 	capabilities = rte_security_capabilities_get(ctx);
9360 
9361 	if (capabilities == NULL)
9362 		return -ENOTSUP;
9363 
9364 	while ((capability = &capabilities[i++])->action !=
9365 			RTE_SECURITY_ACTION_TYPE_NONE) {
9366 		if (capability->action == action &&
9367 				capability->protocol == proto)
9368 			return 0;
9369 	}
9370 
9371 	return -ENOTSUP;
9372 }
9373 
9374 /* Basic algorithm run function for async inplace mode.
9375  * Creates a session from input parameters and runs one operation
9376  * on input_vec. Checks the output of the crypto operation against
9377  * output_vec.
9378  */
9379 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
9380 			   enum rte_crypto_auth_operation opa,
9381 			   const uint8_t *input_vec, unsigned int input_vec_len,
9382 			   const uint8_t *output_vec,
9383 			   unsigned int output_vec_len,
9384 			   enum rte_crypto_cipher_algorithm cipher_alg,
9385 			   const uint8_t *cipher_key, uint32_t cipher_key_len,
9386 			   enum rte_crypto_auth_algorithm auth_alg,
9387 			   const uint8_t *auth_key, uint32_t auth_key_len,
9388 			   uint8_t bearer, enum rte_security_pdcp_domain domain,
9389 			   uint8_t packet_direction, uint8_t sn_size,
9390 			   uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
9391 {
9392 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9393 	struct crypto_unittest_params *ut_params = &unittest_params;
9394 	uint8_t *plaintext;
9395 	int ret = TEST_SUCCESS;
9396 	void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]);
9397 	struct rte_cryptodev_info dev_info;
9398 	uint64_t feat_flags;
9399 
9400 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9401 	feat_flags = dev_info.feature_flags;
9402 
9403 	/* Verify the capabilities */
9404 	struct rte_security_capability_idx sec_cap_idx;
9405 
9406 	sec_cap_idx.action = ut_params->type;
9407 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
9408 	sec_cap_idx.pdcp.domain = domain;
9409 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
9410 		return TEST_SKIPPED;
9411 
9412 	/* Generate test mbuf data */
9413 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9414 
9415 	/* clear mbuf payload */
9416 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9417 			rte_pktmbuf_tailroom(ut_params->ibuf));
9418 
9419 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9420 						  input_vec_len);
9421 	memcpy(plaintext, input_vec, input_vec_len);
9422 
9423 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
9424 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
9425 		printf("Device does not support RAW data-path APIs.\n");
9426 		return TEST_SKIPPED;
9427 	}
9428 	/* Out of place support */
9429 	if (oop) {
9430 		/*
9431 		 * For out-op-place we need to alloc another mbuf
9432 		 */
9433 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9434 		rte_pktmbuf_append(ut_params->obuf, output_vec_len);
9435 	}
9436 
9437 	/* Setup Cipher Parameters */
9438 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9439 	ut_params->cipher_xform.cipher.algo = cipher_alg;
9440 	ut_params->cipher_xform.cipher.op = opc;
9441 	ut_params->cipher_xform.cipher.key.data = cipher_key;
9442 	ut_params->cipher_xform.cipher.key.length = cipher_key_len;
9443 	ut_params->cipher_xform.cipher.iv.length =
9444 				packet_direction ? 4 : 0;
9445 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9446 
9447 	/* Setup HMAC Parameters if ICV header is required */
9448 	if (auth_alg != 0) {
9449 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9450 		ut_params->auth_xform.next = NULL;
9451 		ut_params->auth_xform.auth.algo = auth_alg;
9452 		ut_params->auth_xform.auth.op = opa;
9453 		ut_params->auth_xform.auth.key.data = auth_key;
9454 		ut_params->auth_xform.auth.key.length = auth_key_len;
9455 
9456 		ut_params->cipher_xform.next = &ut_params->auth_xform;
9457 	} else {
9458 		ut_params->cipher_xform.next = NULL;
9459 	}
9460 
9461 	struct rte_security_session_conf sess_conf = {
9462 		.action_type = ut_params->type,
9463 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
9464 		{.pdcp = {
9465 			.bearer = bearer,
9466 			.domain = domain,
9467 			.pkt_dir = packet_direction,
9468 			.sn_size = sn_size,
9469 			.hfn = packet_direction ? 0 : hfn,
9470 			/**
9471 			 * hfn can be set as pdcp_test_hfn[i]
9472 			 * if hfn_ovrd is not set. Here, PDCP
9473 			 * packet direction is just used to
9474 			 * run half of the cases with session
9475 			 * HFN and other half with per packet
9476 			 * HFN.
9477 			 */
9478 			.hfn_threshold = hfn_threshold,
9479 			.hfn_ovrd = packet_direction ? 1 : 0,
9480 			.sdap_enabled = sdap,
9481 		} },
9482 		.crypto_xform = &ut_params->cipher_xform
9483 	};
9484 
9485 	/* Create security session */
9486 	ut_params->sec_session = rte_security_session_create(ctx,
9487 				&sess_conf, ts_params->session_mpool);
9488 
9489 	if (!ut_params->sec_session) {
9490 		printf("TestCase %s()-%d line %d failed %s: ",
9491 			__func__, i, __LINE__, "Failed to allocate session");
9492 		ret = TEST_FAILED;
9493 		goto on_err;
9494 	}
9495 
9496 	/* Generate crypto op data structure */
9497 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9498 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9499 	if (!ut_params->op) {
9500 		printf("TestCase %s()-%d line %d failed %s: ",
9501 			__func__, i, __LINE__,
9502 			"Failed to allocate symmetric crypto operation struct");
9503 		ret = TEST_FAILED;
9504 		goto on_err;
9505 	}
9506 
9507 	uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
9508 					uint32_t *, IV_OFFSET);
9509 	*per_pkt_hfn = packet_direction ? hfn : 0;
9510 
9511 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
9512 
9513 	/* set crypto operation source mbuf */
9514 	ut_params->op->sym->m_src = ut_params->ibuf;
9515 	if (oop)
9516 		ut_params->op->sym->m_dst = ut_params->obuf;
9517 
9518 	/* Process crypto operation */
9519 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
9520 		/* filling lengths */
9521 		ut_params->op->sym->cipher.data.length = ut_params->op->sym->m_src->pkt_len;
9522 		ut_params->op->sym->auth.data.length = ut_params->op->sym->m_src->pkt_len;
9523 
9524 		ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 0);
9525 		if (ret != TEST_SUCCESS)
9526 			return ret;
9527 	} else {
9528 		ut_params->op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
9529 	}
9530 	if (ut_params->op == NULL) {
9531 		printf("TestCase %s()-%d line %d failed %s: ",
9532 			__func__, i, __LINE__,
9533 			"failed to process sym crypto op");
9534 		ret = TEST_FAILED;
9535 		goto on_err;
9536 	}
9537 
9538 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9539 		printf("TestCase %s()-%d line %d failed %s: ",
9540 			__func__, i, __LINE__, "crypto op processing failed");
9541 		ret = TEST_FAILED;
9542 		goto on_err;
9543 	}
9544 
9545 	/* Validate obuf */
9546 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
9547 			uint8_t *);
9548 	if (oop) {
9549 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
9550 				uint8_t *);
9551 	}
9552 
9553 	if (memcmp(ciphertext, output_vec, output_vec_len)) {
9554 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
9555 		rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
9556 		rte_hexdump(stdout, "reference", output_vec, output_vec_len);
9557 		ret = TEST_FAILED;
9558 		goto on_err;
9559 	}
9560 
9561 on_err:
9562 	rte_crypto_op_free(ut_params->op);
9563 	ut_params->op = NULL;
9564 
9565 	if (ut_params->sec_session)
9566 		rte_security_session_destroy(ctx, ut_params->sec_session);
9567 	ut_params->sec_session = NULL;
9568 
9569 	rte_pktmbuf_free(ut_params->ibuf);
9570 	ut_params->ibuf = NULL;
9571 	if (oop) {
9572 		rte_pktmbuf_free(ut_params->obuf);
9573 		ut_params->obuf = NULL;
9574 	}
9575 
9576 	return ret;
9577 }
9578 
9579 static int
9580 test_pdcp_proto_SGL(int i, int oop,
9581 	enum rte_crypto_cipher_operation opc,
9582 	enum rte_crypto_auth_operation opa,
9583 	uint8_t *input_vec,
9584 	unsigned int input_vec_len,
9585 	uint8_t *output_vec,
9586 	unsigned int output_vec_len,
9587 	uint32_t fragsz,
9588 	uint32_t fragsz_oop)
9589 {
9590 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9591 	struct crypto_unittest_params *ut_params = &unittest_params;
9592 	uint8_t *plaintext;
9593 	struct rte_mbuf *buf, *buf_oop = NULL;
9594 	int ret = TEST_SUCCESS;
9595 	int to_trn = 0;
9596 	int to_trn_tbl[16];
9597 	int segs = 1;
9598 	unsigned int trn_data = 0;
9599 	struct rte_cryptodev_info dev_info;
9600 	uint64_t feat_flags;
9601 	void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]);
9602 	struct rte_mbuf *temp_mbuf;
9603 
9604 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9605 	feat_flags = dev_info.feature_flags;
9606 
9607 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
9608 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
9609 		printf("Device does not support RAW data-path APIs.\n");
9610 		return -ENOTSUP;
9611 	}
9612 	/* Verify the capabilities */
9613 	struct rte_security_capability_idx sec_cap_idx;
9614 
9615 	sec_cap_idx.action = ut_params->type;
9616 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
9617 	sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
9618 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
9619 		return TEST_SKIPPED;
9620 
9621 	if (fragsz > input_vec_len)
9622 		fragsz = input_vec_len;
9623 
9624 	uint16_t plaintext_len = fragsz;
9625 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
9626 
9627 	if (fragsz_oop > output_vec_len)
9628 		frag_size_oop = output_vec_len;
9629 
9630 	int ecx = 0;
9631 	if (input_vec_len % fragsz != 0) {
9632 		if (input_vec_len / fragsz + 1 > 16)
9633 			return 1;
9634 	} else if (input_vec_len / fragsz > 16)
9635 		return 1;
9636 
9637 	/* Out of place support */
9638 	if (oop) {
9639 		/*
9640 		 * For out-op-place we need to alloc another mbuf
9641 		 */
9642 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9643 		rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
9644 		buf_oop = ut_params->obuf;
9645 	}
9646 
9647 	/* Generate test mbuf data */
9648 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9649 
9650 	/* clear mbuf payload */
9651 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9652 			rte_pktmbuf_tailroom(ut_params->ibuf));
9653 
9654 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9655 						  plaintext_len);
9656 	memcpy(plaintext, input_vec, plaintext_len);
9657 	trn_data += plaintext_len;
9658 
9659 	buf = ut_params->ibuf;
9660 
9661 	/*
9662 	 * Loop until no more fragments
9663 	 */
9664 
9665 	while (trn_data < input_vec_len) {
9666 		++segs;
9667 		to_trn = (input_vec_len - trn_data < fragsz) ?
9668 				(input_vec_len - trn_data) : fragsz;
9669 
9670 		to_trn_tbl[ecx++] = to_trn;
9671 
9672 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9673 		buf = buf->next;
9674 
9675 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
9676 				rte_pktmbuf_tailroom(buf));
9677 
9678 		/* OOP */
9679 		if (oop && !fragsz_oop) {
9680 			buf_oop->next =
9681 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
9682 			buf_oop = buf_oop->next;
9683 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
9684 					0, rte_pktmbuf_tailroom(buf_oop));
9685 			rte_pktmbuf_append(buf_oop, to_trn);
9686 		}
9687 
9688 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
9689 				to_trn);
9690 
9691 		memcpy(plaintext, input_vec + trn_data, to_trn);
9692 		trn_data += to_trn;
9693 	}
9694 
9695 	ut_params->ibuf->nb_segs = segs;
9696 
9697 	segs = 1;
9698 	if (fragsz_oop && oop) {
9699 		to_trn = 0;
9700 		ecx = 0;
9701 
9702 		trn_data = frag_size_oop;
9703 		while (trn_data < output_vec_len) {
9704 			++segs;
9705 			to_trn =
9706 				(output_vec_len - trn_data <
9707 						frag_size_oop) ?
9708 				(output_vec_len - trn_data) :
9709 						frag_size_oop;
9710 
9711 			to_trn_tbl[ecx++] = to_trn;
9712 
9713 			buf_oop->next =
9714 				rte_pktmbuf_alloc(ts_params->mbuf_pool);
9715 			buf_oop = buf_oop->next;
9716 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
9717 					0, rte_pktmbuf_tailroom(buf_oop));
9718 			rte_pktmbuf_append(buf_oop, to_trn);
9719 
9720 			trn_data += to_trn;
9721 		}
9722 		ut_params->obuf->nb_segs = segs;
9723 	}
9724 
9725 	/* Setup Cipher Parameters */
9726 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9727 	ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
9728 	ut_params->cipher_xform.cipher.op = opc;
9729 	ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
9730 	ut_params->cipher_xform.cipher.key.length =
9731 					pdcp_test_params[i].cipher_key_len;
9732 	ut_params->cipher_xform.cipher.iv.length = 0;
9733 
9734 	/* Setup HMAC Parameters if ICV header is required */
9735 	if (pdcp_test_params[i].auth_alg != 0) {
9736 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9737 		ut_params->auth_xform.next = NULL;
9738 		ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
9739 		ut_params->auth_xform.auth.op = opa;
9740 		ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
9741 		ut_params->auth_xform.auth.key.length =
9742 					pdcp_test_params[i].auth_key_len;
9743 
9744 		ut_params->cipher_xform.next = &ut_params->auth_xform;
9745 	} else {
9746 		ut_params->cipher_xform.next = NULL;
9747 	}
9748 
9749 	struct rte_security_session_conf sess_conf = {
9750 		.action_type = ut_params->type,
9751 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
9752 		{.pdcp = {
9753 			.bearer = pdcp_test_bearer[i],
9754 			.domain = pdcp_test_params[i].domain,
9755 			.pkt_dir = pdcp_test_packet_direction[i],
9756 			.sn_size = pdcp_test_data_sn_size[i],
9757 			.hfn = pdcp_test_hfn[i],
9758 			.hfn_threshold = pdcp_test_hfn_threshold[i],
9759 			.hfn_ovrd = 0,
9760 		} },
9761 		.crypto_xform = &ut_params->cipher_xform
9762 	};
9763 
9764 	/* Create security session */
9765 	ut_params->sec_session = rte_security_session_create(ctx,
9766 				&sess_conf, ts_params->session_mpool);
9767 
9768 	if (!ut_params->sec_session) {
9769 		printf("TestCase %s()-%d line %d failed %s: ",
9770 			__func__, i, __LINE__, "Failed to allocate session");
9771 		ret = TEST_FAILED;
9772 		goto on_err;
9773 	}
9774 
9775 	/* Generate crypto op data structure */
9776 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9777 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9778 	if (!ut_params->op) {
9779 		printf("TestCase %s()-%d line %d failed %s: ",
9780 			__func__, i, __LINE__,
9781 			"Failed to allocate symmetric crypto operation struct");
9782 		ret = TEST_FAILED;
9783 		goto on_err;
9784 	}
9785 
9786 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
9787 
9788 	/* set crypto operation source mbuf */
9789 	ut_params->op->sym->m_src = ut_params->ibuf;
9790 	if (oop)
9791 		ut_params->op->sym->m_dst = ut_params->obuf;
9792 
9793 	/* Process crypto operation */
9794 	temp_mbuf = ut_params->op->sym->m_src;
9795 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
9796 		/* filling lengths */
9797 		while (temp_mbuf) {
9798 			ut_params->op->sym->cipher.data.length
9799 				+= temp_mbuf->pkt_len;
9800 			ut_params->op->sym->auth.data.length
9801 				+= temp_mbuf->pkt_len;
9802 			temp_mbuf = temp_mbuf->next;
9803 		}
9804 
9805 		ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0, 0);
9806 		if (ret != TEST_SUCCESS)
9807 			return ret;
9808 	} else {
9809 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
9810 							ut_params->op);
9811 	}
9812 	if (ut_params->op == NULL) {
9813 		printf("TestCase %s()-%d line %d failed %s: ",
9814 			__func__, i, __LINE__,
9815 			"failed to process sym crypto op");
9816 		ret = TEST_FAILED;
9817 		goto on_err;
9818 	}
9819 
9820 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9821 		printf("TestCase %s()-%d line %d failed %s: ",
9822 			__func__, i, __LINE__, "crypto op processing failed");
9823 		ret = TEST_FAILED;
9824 		goto on_err;
9825 	}
9826 
9827 	/* Validate obuf */
9828 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
9829 			uint8_t *);
9830 	if (oop) {
9831 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
9832 				uint8_t *);
9833 	}
9834 	if (fragsz_oop)
9835 		fragsz = frag_size_oop;
9836 	if (memcmp(ciphertext, output_vec, fragsz)) {
9837 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
9838 		rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
9839 		rte_hexdump(stdout, "reference", output_vec, fragsz);
9840 		ret = TEST_FAILED;
9841 		goto on_err;
9842 	}
9843 
9844 	buf = ut_params->op->sym->m_src->next;
9845 	if (oop)
9846 		buf = ut_params->op->sym->m_dst->next;
9847 
9848 	unsigned int off = fragsz;
9849 
9850 	ecx = 0;
9851 	while (buf) {
9852 		ciphertext = rte_pktmbuf_mtod(buf,
9853 				uint8_t *);
9854 		if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
9855 			printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
9856 			rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
9857 			rte_hexdump(stdout, "reference", output_vec + off,
9858 					to_trn_tbl[ecx]);
9859 			ret = TEST_FAILED;
9860 			goto on_err;
9861 		}
9862 		off += to_trn_tbl[ecx++];
9863 		buf = buf->next;
9864 	}
9865 on_err:
9866 	rte_crypto_op_free(ut_params->op);
9867 	ut_params->op = NULL;
9868 
9869 	if (ut_params->sec_session)
9870 		rte_security_session_destroy(ctx, ut_params->sec_session);
9871 	ut_params->sec_session = NULL;
9872 
9873 	rte_pktmbuf_free(ut_params->ibuf);
9874 	ut_params->ibuf = NULL;
9875 	if (oop) {
9876 		rte_pktmbuf_free(ut_params->obuf);
9877 		ut_params->obuf = NULL;
9878 	}
9879 
9880 	return ret;
9881 }
9882 
9883 int
9884 test_pdcp_proto_cplane_encap(int i)
9885 {
9886 	return test_pdcp_proto(
9887 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
9888 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
9889 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
9890 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
9891 		pdcp_test_params[i].cipher_key_len,
9892 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
9893 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
9894 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
9895 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
9896 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
9897 }
9898 
9899 int
9900 test_pdcp_proto_uplane_encap(int i)
9901 {
9902 	return test_pdcp_proto(
9903 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
9904 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
9905 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
9906 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
9907 		pdcp_test_params[i].cipher_key_len,
9908 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
9909 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
9910 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
9911 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
9912 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
9913 }
9914 
9915 int
9916 test_pdcp_proto_uplane_encap_with_int(int i)
9917 {
9918 	return test_pdcp_proto(
9919 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
9920 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
9921 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
9922 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
9923 		pdcp_test_params[i].cipher_key_len,
9924 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
9925 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
9926 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
9927 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
9928 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
9929 }
9930 
9931 int
9932 test_pdcp_proto_cplane_decap(int i)
9933 {
9934 	return test_pdcp_proto(
9935 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
9936 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
9937 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
9938 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
9939 		pdcp_test_params[i].cipher_key_len,
9940 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
9941 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
9942 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
9943 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
9944 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
9945 }
9946 
9947 int
9948 test_pdcp_proto_uplane_decap(int i)
9949 {
9950 	return test_pdcp_proto(
9951 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
9952 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
9953 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
9954 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
9955 		pdcp_test_params[i].cipher_key_len,
9956 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
9957 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
9958 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
9959 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
9960 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
9961 }
9962 
9963 int
9964 test_pdcp_proto_uplane_decap_with_int(int i)
9965 {
9966 	return test_pdcp_proto(
9967 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
9968 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
9969 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
9970 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
9971 		pdcp_test_params[i].cipher_key_len,
9972 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
9973 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
9974 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
9975 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
9976 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
9977 }
9978 
9979 static int
9980 test_PDCP_PROTO_SGL_in_place_32B(void)
9981 {
9982 	/* i can be used for running any PDCP case
9983 	 * In this case it is uplane 12-bit AES-SNOW DL encap
9984 	 */
9985 	int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
9986 	return test_pdcp_proto_SGL(i, IN_PLACE,
9987 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
9988 			RTE_CRYPTO_AUTH_OP_GENERATE,
9989 			pdcp_test_data_in[i],
9990 			pdcp_test_data_in_len[i],
9991 			pdcp_test_data_out[i],
9992 			pdcp_test_data_in_len[i]+4,
9993 			32, 0);
9994 }
9995 static int
9996 test_PDCP_PROTO_SGL_oop_32B_128B(void)
9997 {
9998 	/* i can be used for running any PDCP case
9999 	 * In this case it is uplane 18-bit NULL-NULL DL encap
10000 	 */
10001 	int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
10002 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
10003 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
10004 			RTE_CRYPTO_AUTH_OP_GENERATE,
10005 			pdcp_test_data_in[i],
10006 			pdcp_test_data_in_len[i],
10007 			pdcp_test_data_out[i],
10008 			pdcp_test_data_in_len[i]+4,
10009 			32, 128);
10010 }
10011 static int
10012 test_PDCP_PROTO_SGL_oop_32B_40B(void)
10013 {
10014 	/* i can be used for running any PDCP case
10015 	 * In this case it is uplane 18-bit AES DL encap
10016 	 */
10017 	int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
10018 			+ DOWNLINK;
10019 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
10020 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
10021 			RTE_CRYPTO_AUTH_OP_GENERATE,
10022 			pdcp_test_data_in[i],
10023 			pdcp_test_data_in_len[i],
10024 			pdcp_test_data_out[i],
10025 			pdcp_test_data_in_len[i],
10026 			32, 40);
10027 }
10028 static int
10029 test_PDCP_PROTO_SGL_oop_128B_32B(void)
10030 {
10031 	/* i can be used for running any PDCP case
10032 	 * In this case it is cplane 12-bit AES-ZUC DL encap
10033 	 */
10034 	int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
10035 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
10036 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
10037 			RTE_CRYPTO_AUTH_OP_GENERATE,
10038 			pdcp_test_data_in[i],
10039 			pdcp_test_data_in_len[i],
10040 			pdcp_test_data_out[i],
10041 			pdcp_test_data_in_len[i]+4,
10042 			128, 32);
10043 }
10044 
10045 static int
10046 test_PDCP_SDAP_PROTO_encap_all(void)
10047 {
10048 	int i = 0, size = 0;
10049 	int err, all_err = TEST_SUCCESS;
10050 	const struct pdcp_sdap_test *cur_test;
10051 
10052 	size = RTE_DIM(list_pdcp_sdap_tests);
10053 
10054 	for (i = 0; i < size; i++) {
10055 		cur_test = &list_pdcp_sdap_tests[i];
10056 		err = test_pdcp_proto(
10057 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
10058 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
10059 			cur_test->in_len, cur_test->data_out,
10060 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
10061 			cur_test->param.cipher_alg, cur_test->cipher_key,
10062 			cur_test->param.cipher_key_len,
10063 			cur_test->param.auth_alg,
10064 			cur_test->auth_key, cur_test->param.auth_key_len,
10065 			cur_test->bearer, cur_test->param.domain,
10066 			cur_test->packet_direction, cur_test->sn_size,
10067 			cur_test->hfn,
10068 			cur_test->hfn_threshold, SDAP_ENABLED);
10069 		if (err) {
10070 			printf("\t%d) %s: Encapsulation failed\n",
10071 					cur_test->test_idx,
10072 					cur_test->param.name);
10073 			err = TEST_FAILED;
10074 		} else {
10075 			printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
10076 					cur_test->param.name);
10077 			err = TEST_SUCCESS;
10078 		}
10079 		all_err += err;
10080 	}
10081 
10082 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
10083 
10084 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
10085 }
10086 
10087 static int
10088 test_PDCP_PROTO_short_mac(void)
10089 {
10090 	int i = 0, size = 0;
10091 	int err, all_err = TEST_SUCCESS;
10092 	const struct pdcp_short_mac_test *cur_test;
10093 
10094 	size = RTE_DIM(list_pdcp_smac_tests);
10095 
10096 	for (i = 0; i < size; i++) {
10097 		cur_test = &list_pdcp_smac_tests[i];
10098 		err = test_pdcp_proto(
10099 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
10100 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
10101 			cur_test->in_len, cur_test->data_out,
10102 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
10103 			RTE_CRYPTO_CIPHER_NULL, NULL,
10104 			0, cur_test->param.auth_alg,
10105 			cur_test->auth_key, cur_test->param.auth_key_len,
10106 			0, cur_test->param.domain, 0, 0,
10107 			0, 0, 0);
10108 		if (err) {
10109 			printf("\t%d) %s: Short MAC test failed\n",
10110 					cur_test->test_idx,
10111 					cur_test->param.name);
10112 			err = TEST_FAILED;
10113 		} else {
10114 			printf("\t%d) %s: Short MAC test PASS\n",
10115 					cur_test->test_idx,
10116 					cur_test->param.name);
10117 			rte_hexdump(stdout, "MAC I",
10118 				    cur_test->data_out + cur_test->in_len + 2,
10119 				    2);
10120 			err = TEST_SUCCESS;
10121 		}
10122 		all_err += err;
10123 	}
10124 
10125 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
10126 
10127 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
10128 
10129 }
10130 
10131 static int
10132 test_PDCP_SDAP_PROTO_decap_all(void)
10133 {
10134 	int i = 0, size = 0;
10135 	int err, all_err = TEST_SUCCESS;
10136 	const struct pdcp_sdap_test *cur_test;
10137 
10138 	size = RTE_DIM(list_pdcp_sdap_tests);
10139 
10140 	for (i = 0; i < size; i++) {
10141 		cur_test = &list_pdcp_sdap_tests[i];
10142 		err = test_pdcp_proto(
10143 			i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
10144 			RTE_CRYPTO_AUTH_OP_VERIFY,
10145 			cur_test->data_out,
10146 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
10147 			cur_test->data_in, cur_test->in_len,
10148 			cur_test->param.cipher_alg,
10149 			cur_test->cipher_key, cur_test->param.cipher_key_len,
10150 			cur_test->param.auth_alg, cur_test->auth_key,
10151 			cur_test->param.auth_key_len, cur_test->bearer,
10152 			cur_test->param.domain, cur_test->packet_direction,
10153 			cur_test->sn_size, cur_test->hfn,
10154 			cur_test->hfn_threshold, SDAP_ENABLED);
10155 		if (err) {
10156 			printf("\t%d) %s: Decapsulation failed\n",
10157 					cur_test->test_idx,
10158 					cur_test->param.name);
10159 			err = TEST_FAILED;
10160 		} else {
10161 			printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
10162 					cur_test->param.name);
10163 			err = TEST_SUCCESS;
10164 		}
10165 		all_err += err;
10166 	}
10167 
10168 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
10169 
10170 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
10171 }
10172 
10173 static int
10174 test_ipsec_proto_crypto_op_enq(struct crypto_testsuite_params *ts_params,
10175 			       struct crypto_unittest_params *ut_params,
10176 			       struct rte_security_ipsec_xform *ipsec_xform,
10177 			       const struct ipsec_test_data *td,
10178 			       const struct ipsec_test_flags *flags,
10179 			       int pkt_num)
10180 {
10181 	uint8_t dev_id = ts_params->valid_devs[0];
10182 	enum rte_security_ipsec_sa_direction dir;
10183 	int ret;
10184 
10185 	dir = ipsec_xform->direction;
10186 
10187 	/* Generate crypto op data structure */
10188 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10189 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10190 	if (!ut_params->op) {
10191 		printf("Could not allocate crypto op");
10192 		return TEST_FAILED;
10193 	}
10194 
10195 	/* Attach session to operation */
10196 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
10197 
10198 	/* Set crypto operation mbufs */
10199 	ut_params->op->sym->m_src = ut_params->ibuf;
10200 	ut_params->op->sym->m_dst = NULL;
10201 
10202 	/* Copy IV in crypto operation when IV generation is disabled */
10203 	if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS &&
10204 	    ipsec_xform->options.iv_gen_disable == 1) {
10205 		uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op,
10206 							uint8_t *,
10207 							IV_OFFSET);
10208 		int len;
10209 
10210 		if (td->aead)
10211 			len = td->xform.aead.aead.iv.length;
10212 		else if (td->aes_gmac)
10213 			len = td->xform.chain.auth.auth.iv.length;
10214 		else
10215 			len = td->xform.chain.cipher.cipher.iv.length;
10216 
10217 		memcpy(iv, td->iv.data, len);
10218 	}
10219 
10220 	/* Process crypto operation */
10221 	process_crypto_request(dev_id, ut_params->op);
10222 
10223 	ret = test_ipsec_status_check(td, ut_params->op, flags, dir, pkt_num);
10224 
10225 	rte_crypto_op_free(ut_params->op);
10226 	ut_params->op = NULL;
10227 
10228 	return ret;
10229 }
10230 
10231 static int
10232 test_ipsec_proto_mbuf_enq(struct crypto_testsuite_params *ts_params,
10233 			  struct crypto_unittest_params *ut_params,
10234 			  void *ctx)
10235 {
10236 	uint64_t timeout, userdata;
10237 	struct rte_ether_hdr *hdr;
10238 	struct rte_mbuf *m;
10239 	void **sec_sess;
10240 	int ret;
10241 
10242 	RTE_SET_USED(ts_params);
10243 
10244 	hdr = (void *)rte_pktmbuf_prepend(ut_params->ibuf, sizeof(struct rte_ether_hdr));
10245 	hdr->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
10246 
10247 	ut_params->ibuf->l2_len = sizeof(struct rte_ether_hdr);
10248 	ut_params->ibuf->port = 0;
10249 
10250 	sec_sess = &ut_params->sec_session;
10251 	ret = rte_security_inb_pkt_rx_inject(ctx, &ut_params->ibuf, sec_sess, 1);
10252 
10253 	if (ret != 1)
10254 		return TEST_FAILED;
10255 
10256 	ut_params->ibuf = NULL;
10257 
10258 	/* Add a timeout for 1 s */
10259 	timeout = rte_get_tsc_cycles() + rte_get_tsc_hz();
10260 
10261 	do {
10262 		/* Get packet from port 0, queue 0 */
10263 		ret = rte_eth_rx_burst(0, 0, &m, 1);
10264 	} while ((ret == 0) && (rte_get_tsc_cycles() < timeout));
10265 
10266 	if (ret == 0) {
10267 		printf("Could not receive packets from ethdev\n");
10268 		return TEST_FAILED;
10269 	}
10270 
10271 	if (m == NULL) {
10272 		printf("Received mbuf is NULL\n");
10273 		return TEST_FAILED;
10274 	}
10275 
10276 	ut_params->ibuf = m;
10277 
10278 	if (!(m->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD)) {
10279 		printf("Received packet is not Rx security processed\n");
10280 		return TEST_FAILED;
10281 	}
10282 
10283 	if (m->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED) {
10284 		printf("Received packet has failed Rx security processing\n");
10285 		return TEST_FAILED;
10286 	}
10287 
10288 	/*
10289 	 * 'ut_params' is set as userdata. Verify that the field is returned
10290 	 * correctly.
10291 	 */
10292 	userdata = *(uint64_t *)rte_security_dynfield(m);
10293 	if (userdata != (uint64_t)ut_params) {
10294 		printf("Userdata retrieved not matching expected\n");
10295 		return TEST_FAILED;
10296 	}
10297 
10298 	/* Trim L2 header */
10299 	rte_pktmbuf_adj(m, sizeof(struct rte_ether_hdr));
10300 
10301 	return TEST_SUCCESS;
10302 }
10303 
10304 static int
10305 test_ipsec_proto_process(const struct ipsec_test_data td[],
10306 			 struct ipsec_test_data res_d[],
10307 			 int nb_td,
10308 			 bool silent,
10309 			 const struct ipsec_test_flags *flags)
10310 {
10311 	uint16_t v6_src[8] = {0x2607, 0xf8b0, 0x400c, 0x0c03, 0x0000, 0x0000,
10312 				0x0000, 0x001a};
10313 	uint16_t v6_dst[8] = {0x2001, 0x0470, 0xe5bf, 0xdead, 0x4957, 0x2174,
10314 				0xe82c, 0x4887};
10315 	const struct rte_ipv4_hdr *ipv4 =
10316 			(const struct rte_ipv4_hdr *)td[0].output_text.data;
10317 	int nb_segs = flags->nb_segs_in_mbuf ? flags->nb_segs_in_mbuf : 1;
10318 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10319 	struct crypto_unittest_params *ut_params = &unittest_params;
10320 	struct rte_security_capability_idx sec_cap_idx;
10321 	const struct rte_security_capability *sec_cap;
10322 	struct rte_security_ipsec_xform ipsec_xform;
10323 	uint8_t dev_id = ts_params->valid_devs[0];
10324 	enum rte_security_ipsec_sa_direction dir;
10325 	struct ipsec_test_data *res_d_tmp = NULL;
10326 	uint8_t input_text[IPSEC_TEXT_MAX_LEN];
10327 	int salt_len, i, ret = TEST_SUCCESS;
10328 	void *ctx;
10329 	uint32_t src, dst;
10330 	uint32_t verify;
10331 
10332 	ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
10333 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
10334 
10335 	/* Use first test data to create session */
10336 
10337 	/* Copy IPsec xform */
10338 	memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform));
10339 
10340 	dir = ipsec_xform.direction;
10341 	verify = flags->tunnel_hdr_verify;
10342 
10343 	memcpy(&src, &ipv4->src_addr, sizeof(ipv4->src_addr));
10344 	memcpy(&dst, &ipv4->dst_addr, sizeof(ipv4->dst_addr));
10345 
10346 	if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) {
10347 		if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR)
10348 			src += 1;
10349 		else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR)
10350 			dst += 1;
10351 	}
10352 
10353 	if (td->ipsec_xform.mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) {
10354 		if (td->ipsec_xform.tunnel.type ==
10355 				RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
10356 			memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src,
10357 			       sizeof(src));
10358 			memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst,
10359 			       sizeof(dst));
10360 
10361 			if (flags->df == TEST_IPSEC_SET_DF_0_INNER_1)
10362 				ipsec_xform.tunnel.ipv4.df = 0;
10363 
10364 			if (flags->df == TEST_IPSEC_SET_DF_1_INNER_0)
10365 				ipsec_xform.tunnel.ipv4.df = 1;
10366 
10367 			if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1)
10368 				ipsec_xform.tunnel.ipv4.dscp = 0;
10369 
10370 			if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0)
10371 				ipsec_xform.tunnel.ipv4.dscp =
10372 						TEST_IPSEC_DSCP_VAL;
10373 
10374 		} else {
10375 			if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1)
10376 				ipsec_xform.tunnel.ipv6.dscp = 0;
10377 
10378 			if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0)
10379 				ipsec_xform.tunnel.ipv6.dscp =
10380 						TEST_IPSEC_DSCP_VAL;
10381 
10382 			memcpy(&ipsec_xform.tunnel.ipv6.src_addr, &v6_src,
10383 			       sizeof(v6_src));
10384 			memcpy(&ipsec_xform.tunnel.ipv6.dst_addr, &v6_dst,
10385 			       sizeof(v6_dst));
10386 		}
10387 	}
10388 
10389 	ctx = rte_cryptodev_get_sec_ctx(dev_id);
10390 
10391 	sec_cap_idx.action = ut_params->type;
10392 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC;
10393 	sec_cap_idx.ipsec.proto = ipsec_xform.proto;
10394 	sec_cap_idx.ipsec.mode = ipsec_xform.mode;
10395 	sec_cap_idx.ipsec.direction = ipsec_xform.direction;
10396 
10397 	if (flags->udp_encap)
10398 		ipsec_xform.options.udp_encap = 1;
10399 
10400 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
10401 	if (sec_cap == NULL)
10402 		return TEST_SKIPPED;
10403 
10404 	/* Copy cipher session parameters */
10405 	if (td[0].aead) {
10406 		memcpy(&ut_params->aead_xform, &td[0].xform.aead,
10407 		       sizeof(ut_params->aead_xform));
10408 		ut_params->aead_xform.aead.key.data = td[0].key.data;
10409 		ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
10410 
10411 		/* Verify crypto capabilities */
10412 		if (test_sec_crypto_caps_aead_verify(sec_cap, &ut_params->aead_xform) != 0) {
10413 			if (!silent)
10414 				RTE_LOG(INFO, USER1,
10415 					"Crypto capabilities not supported\n");
10416 			return TEST_SKIPPED;
10417 		}
10418 	} else if (td[0].auth_only) {
10419 		memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth,
10420 		       sizeof(ut_params->auth_xform));
10421 		ut_params->auth_xform.auth.key.data = td[0].auth_key.data;
10422 
10423 		if (test_sec_crypto_caps_auth_verify(sec_cap, &ut_params->auth_xform) != 0) {
10424 			if (!silent)
10425 				RTE_LOG(INFO, USER1,
10426 					"Auth crypto capabilities not supported\n");
10427 			return TEST_SKIPPED;
10428 		}
10429 	} else {
10430 		memcpy(&ut_params->cipher_xform, &td[0].xform.chain.cipher,
10431 		       sizeof(ut_params->cipher_xform));
10432 		memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth,
10433 		       sizeof(ut_params->auth_xform));
10434 		ut_params->cipher_xform.cipher.key.data = td[0].key.data;
10435 		ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
10436 		ut_params->auth_xform.auth.key.data = td[0].auth_key.data;
10437 
10438 		/* Verify crypto capabilities */
10439 
10440 		if (test_sec_crypto_caps_cipher_verify(sec_cap, &ut_params->cipher_xform) != 0) {
10441 			if (!silent)
10442 				RTE_LOG(INFO, USER1,
10443 					"Cipher crypto capabilities not supported\n");
10444 			return TEST_SKIPPED;
10445 		}
10446 
10447 		if (test_sec_crypto_caps_auth_verify(sec_cap, &ut_params->auth_xform) != 0) {
10448 			if (!silent)
10449 				RTE_LOG(INFO, USER1,
10450 					"Auth crypto capabilities not supported\n");
10451 			return TEST_SKIPPED;
10452 		}
10453 	}
10454 
10455 	if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0)
10456 		return TEST_SKIPPED;
10457 
10458 	struct rte_security_session_conf sess_conf = {
10459 		.action_type = ut_params->type,
10460 		.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
10461 	};
10462 
10463 	if (td[0].aead || td[0].aes_gmac) {
10464 		salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len);
10465 		memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len);
10466 	}
10467 
10468 	if (td[0].aead) {
10469 		sess_conf.ipsec = ipsec_xform;
10470 		sess_conf.crypto_xform = &ut_params->aead_xform;
10471 	} else if (td[0].auth_only) {
10472 		sess_conf.ipsec = ipsec_xform;
10473 		sess_conf.crypto_xform = &ut_params->auth_xform;
10474 	} else {
10475 		sess_conf.ipsec = ipsec_xform;
10476 		if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
10477 			sess_conf.crypto_xform = &ut_params->cipher_xform;
10478 			ut_params->cipher_xform.next = &ut_params->auth_xform;
10479 		} else {
10480 			sess_conf.crypto_xform = &ut_params->auth_xform;
10481 			ut_params->auth_xform.next = &ut_params->cipher_xform;
10482 		}
10483 	}
10484 
10485 	if (dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS && flags->rx_inject)
10486 		sess_conf.userdata = ut_params;
10487 
10488 	/* Create security session */
10489 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
10490 					ts_params->session_mpool);
10491 
10492 	if (ut_params->sec_session == NULL)
10493 		return TEST_SKIPPED;
10494 
10495 	for (i = 0; i < nb_td; i++) {
10496 		if (flags->antireplay &&
10497 		    (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)) {
10498 			sess_conf.ipsec.esn.value = td[i].ipsec_xform.esn.value;
10499 			ret = rte_security_session_update(ctx,
10500 				ut_params->sec_session, &sess_conf);
10501 			if (ret) {
10502 				printf("Could not update sequence number in "
10503 				       "session\n");
10504 				return TEST_SKIPPED;
10505 			}
10506 		}
10507 
10508 		/* Copy test data before modification */
10509 		memcpy(input_text, td[i].input_text.data, td[i].input_text.len);
10510 		if (test_ipsec_pkt_update(input_text, flags)) {
10511 			ret = TEST_FAILED;
10512 			goto mbuf_free;
10513 		}
10514 
10515 		/* Setup source mbuf payload */
10516 		if (flags->use_ext_mbuf) {
10517 			ut_params->ibuf = ext_mbuf_create(ts_params->mbuf_pool,
10518 					td[i].input_text.len, nb_segs, input_text);
10519 		} else {
10520 			ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
10521 					td[i].input_text.len, nb_segs, 0);
10522 			pktmbuf_write(ut_params->ibuf, 0, td[i].input_text.len, input_text);
10523 		}
10524 
10525 		if (dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS && flags->rx_inject)
10526 			ret = test_ipsec_proto_mbuf_enq(ts_params, ut_params,
10527 							ctx);
10528 		else
10529 			ret = test_ipsec_proto_crypto_op_enq(ts_params,
10530 							     ut_params,
10531 							     &ipsec_xform,
10532 							     &td[i], flags,
10533 							     i + 1);
10534 
10535 		if (ret != TEST_SUCCESS)
10536 			goto mbuf_free;
10537 
10538 		if (res_d != NULL)
10539 			res_d_tmp = &res_d[i];
10540 
10541 		ret = test_ipsec_post_process(ut_params->ibuf, &td[i],
10542 					      res_d_tmp, silent, flags);
10543 		if (ret != TEST_SUCCESS)
10544 			goto mbuf_free;
10545 
10546 		ret = test_ipsec_stats_verify(ctx, ut_params->sec_session,
10547 					      flags, dir);
10548 		if (ret != TEST_SUCCESS)
10549 			goto mbuf_free;
10550 
10551 		rte_pktmbuf_free(ut_params->ibuf);
10552 		ut_params->ibuf = NULL;
10553 	}
10554 
10555 mbuf_free:
10556 	if (flags->use_ext_mbuf)
10557 		ext_mbuf_memzone_free(nb_segs);
10558 
10559 	rte_pktmbuf_free(ut_params->ibuf);
10560 	ut_params->ibuf = NULL;
10561 
10562 	if (ut_params->sec_session)
10563 		rte_security_session_destroy(ctx, ut_params->sec_session);
10564 	ut_params->sec_session = NULL;
10565 
10566 	return ret;
10567 }
10568 
10569 static int
10570 test_ipsec_proto_known_vec(const void *test_data)
10571 {
10572 	struct ipsec_test_data td_outb;
10573 	struct ipsec_test_flags flags;
10574 
10575 	memset(&flags, 0, sizeof(flags));
10576 
10577 	memcpy(&td_outb, test_data, sizeof(td_outb));
10578 
10579 	if (td_outb.aes_gmac || td_outb.aead ||
10580 	    ((td_outb.ipsec_xform.proto != RTE_SECURITY_IPSEC_SA_PROTO_AH) &&
10581 	     (td_outb.xform.chain.cipher.cipher.algo != RTE_CRYPTO_CIPHER_NULL))) {
10582 		/* Disable IV gen to be able to test with known vectors */
10583 		td_outb.ipsec_xform.options.iv_gen_disable = 1;
10584 	}
10585 
10586 	return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
10587 }
10588 
10589 static int
10590 test_ipsec_proto_known_vec_ext_mbuf(const void *test_data)
10591 {
10592 	struct ipsec_test_data td_outb;
10593 	struct ipsec_test_flags flags;
10594 
10595 	memset(&flags, 0, sizeof(flags));
10596 	flags.use_ext_mbuf = true;
10597 
10598 	memcpy(&td_outb, test_data, sizeof(td_outb));
10599 
10600 	if (td_outb.aes_gmac || td_outb.aead ||
10601 	    ((td_outb.ipsec_xform.proto != RTE_SECURITY_IPSEC_SA_PROTO_AH) &&
10602 	     (td_outb.xform.chain.cipher.cipher.algo != RTE_CRYPTO_CIPHER_NULL))) {
10603 		/* Disable IV gen to be able to test with known vectors */
10604 		td_outb.ipsec_xform.options.iv_gen_disable = 1;
10605 	}
10606 
10607 	return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
10608 }
10609 
10610 static int
10611 test_ipsec_proto_known_vec_inb(const void *test_data)
10612 {
10613 	const struct ipsec_test_data *td = test_data;
10614 	struct ipsec_test_flags flags;
10615 	struct ipsec_test_data td_inb;
10616 
10617 	memset(&flags, 0, sizeof(flags));
10618 
10619 	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)
10620 		test_ipsec_td_in_from_out(td, &td_inb);
10621 	else
10622 		memcpy(&td_inb, td, sizeof(td_inb));
10623 
10624 	return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags);
10625 }
10626 
10627 static int
10628 test_ipsec_proto_known_vec_fragmented(const void *test_data)
10629 {
10630 	struct ipsec_test_data td_outb;
10631 	struct ipsec_test_flags flags;
10632 
10633 	memset(&flags, 0, sizeof(flags));
10634 	flags.fragment = true;
10635 
10636 	memcpy(&td_outb, test_data, sizeof(td_outb));
10637 
10638 	/* Disable IV gen to be able to test with known vectors */
10639 	td_outb.ipsec_xform.options.iv_gen_disable = 1;
10640 
10641 	return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
10642 }
10643 
10644 static int
10645 test_ipsec_proto_known_vec_inb_rx_inject(const void *test_data)
10646 {
10647 	const struct ipsec_test_data *td = test_data;
10648 	struct ipsec_test_flags flags;
10649 	struct ipsec_test_data td_inb;
10650 
10651 	memset(&flags, 0, sizeof(flags));
10652 	flags.rx_inject = true;
10653 
10654 	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)
10655 		test_ipsec_td_in_from_out(td, &td_inb);
10656 	else
10657 		memcpy(&td_inb, td, sizeof(td_inb));
10658 
10659 	return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags);
10660 }
10661 
10662 static int
10663 test_ipsec_proto_all(const struct ipsec_test_flags *flags)
10664 {
10665 	struct ipsec_test_data td_outb[TEST_SEC_PKTS_MAX];
10666 	struct ipsec_test_data td_inb[TEST_SEC_PKTS_MAX];
10667 	unsigned int i, nb_pkts = 1, pass_cnt = 0;
10668 	int ret;
10669 
10670 	if (flags->iv_gen ||
10671 	    flags->sa_expiry_pkts_soft ||
10672 	    flags->sa_expiry_pkts_hard)
10673 		nb_pkts = TEST_SEC_PKTS_MAX;
10674 
10675 	for (i = 0; i < RTE_DIM(sec_alg_list); i++) {
10676 		test_ipsec_td_prepare(sec_alg_list[i].param1,
10677 				      sec_alg_list[i].param2,
10678 				      flags,
10679 				      td_outb,
10680 				      nb_pkts);
10681 
10682 		if (!td_outb->aead) {
10683 			enum rte_crypto_cipher_algorithm cipher_alg;
10684 			enum rte_crypto_auth_algorithm auth_alg;
10685 
10686 			cipher_alg = td_outb->xform.chain.cipher.cipher.algo;
10687 			auth_alg = td_outb->xform.chain.auth.auth.algo;
10688 
10689 			if (td_outb->aes_gmac && cipher_alg != RTE_CRYPTO_CIPHER_NULL)
10690 				continue;
10691 
10692 			/* ICV is not applicable for NULL auth */
10693 			if (flags->icv_corrupt &&
10694 			    auth_alg == RTE_CRYPTO_AUTH_NULL)
10695 				continue;
10696 
10697 			/* IV is not applicable for NULL cipher */
10698 			if (flags->iv_gen &&
10699 			    cipher_alg == RTE_CRYPTO_CIPHER_NULL)
10700 				continue;
10701 		}
10702 
10703 		ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
10704 					       flags);
10705 		if (ret == TEST_SKIPPED)
10706 			continue;
10707 
10708 		if (ret == TEST_FAILED)
10709 			return TEST_FAILED;
10710 
10711 		test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags);
10712 
10713 		ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
10714 					       flags);
10715 		if (ret == TEST_SKIPPED)
10716 			continue;
10717 
10718 		if (ret == TEST_FAILED)
10719 			return TEST_FAILED;
10720 
10721 		if (flags->display_alg)
10722 			test_sec_alg_display(sec_alg_list[i].param1, sec_alg_list[i].param2);
10723 
10724 		pass_cnt++;
10725 	}
10726 
10727 	if (pass_cnt > 0)
10728 		return TEST_SUCCESS;
10729 	else
10730 		return TEST_SKIPPED;
10731 }
10732 
10733 static int
10734 test_ipsec_ah_proto_all(const struct ipsec_test_flags *flags)
10735 {
10736 	struct ipsec_test_data td_outb[TEST_SEC_PKTS_MAX];
10737 	struct ipsec_test_data td_inb[TEST_SEC_PKTS_MAX];
10738 	unsigned int i, nb_pkts = 1, pass_cnt = 0;
10739 	int ret;
10740 
10741 	for (i = 0; i < RTE_DIM(sec_auth_only_alg_list); i++) {
10742 		test_ipsec_td_prepare(sec_auth_only_alg_list[i].param1,
10743 				      sec_auth_only_alg_list[i].param2,
10744 				      flags,
10745 				      td_outb,
10746 				      nb_pkts);
10747 
10748 		ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
10749 					       flags);
10750 		if (ret == TEST_SKIPPED)
10751 			continue;
10752 
10753 		if (ret == TEST_FAILED)
10754 			return TEST_FAILED;
10755 
10756 		test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags);
10757 
10758 		ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
10759 					       flags);
10760 		if (ret == TEST_SKIPPED)
10761 			continue;
10762 
10763 		if (ret == TEST_FAILED)
10764 			return TEST_FAILED;
10765 
10766 		if (flags->display_alg)
10767 			test_sec_alg_display(sec_auth_only_alg_list[i].param1,
10768 					     sec_auth_only_alg_list[i].param2);
10769 
10770 		pass_cnt++;
10771 	}
10772 
10773 	if (pass_cnt > 0)
10774 		return TEST_SUCCESS;
10775 	else
10776 		return TEST_SKIPPED;
10777 }
10778 
10779 static int
10780 test_ipsec_proto_display_list(void)
10781 {
10782 	struct ipsec_test_flags flags;
10783 
10784 	memset(&flags, 0, sizeof(flags));
10785 
10786 	flags.display_alg = true;
10787 
10788 	return test_ipsec_proto_all(&flags);
10789 }
10790 
10791 static int
10792 test_ipsec_proto_ah_tunnel_ipv4(void)
10793 {
10794 	struct ipsec_test_flags flags;
10795 
10796 	memset(&flags, 0, sizeof(flags));
10797 
10798 	flags.ah = true;
10799 	flags.display_alg = true;
10800 
10801 	return test_ipsec_ah_proto_all(&flags);
10802 }
10803 
10804 static int
10805 test_ipsec_proto_ah_transport_ipv4(void)
10806 {
10807 	struct ipsec_test_flags flags;
10808 
10809 	memset(&flags, 0, sizeof(flags));
10810 
10811 	flags.ah = true;
10812 	flags.transport = true;
10813 
10814 	return test_ipsec_ah_proto_all(&flags);
10815 }
10816 
10817 static int
10818 test_ipsec_proto_iv_gen(void)
10819 {
10820 	struct ipsec_test_flags flags;
10821 
10822 	memset(&flags, 0, sizeof(flags));
10823 
10824 	flags.iv_gen = true;
10825 
10826 	return test_ipsec_proto_all(&flags);
10827 }
10828 
10829 static int
10830 test_ipsec_proto_sa_exp_pkts_soft(void)
10831 {
10832 	struct ipsec_test_flags flags;
10833 
10834 	memset(&flags, 0, sizeof(flags));
10835 
10836 	flags.sa_expiry_pkts_soft = true;
10837 
10838 	return test_ipsec_proto_all(&flags);
10839 }
10840 
10841 static int
10842 test_ipsec_proto_sa_exp_pkts_hard(void)
10843 {
10844 	struct ipsec_test_flags flags;
10845 
10846 	memset(&flags, 0, sizeof(flags));
10847 
10848 	flags.sa_expiry_pkts_hard = true;
10849 
10850 	return test_ipsec_proto_all(&flags);
10851 }
10852 
10853 static int
10854 test_ipsec_proto_err_icv_corrupt(void)
10855 {
10856 	struct ipsec_test_flags flags;
10857 
10858 	memset(&flags, 0, sizeof(flags));
10859 
10860 	flags.icv_corrupt = true;
10861 
10862 	return test_ipsec_proto_all(&flags);
10863 }
10864 
10865 static int
10866 test_ipsec_proto_udp_encap_custom_ports(void)
10867 {
10868 	struct ipsec_test_flags flags;
10869 
10870 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
10871 			RTE_STR(CRYPTODEV_NAME_CN10K_PMD)))
10872 		return TEST_SKIPPED;
10873 
10874 	memset(&flags, 0, sizeof(flags));
10875 
10876 	flags.udp_encap = true;
10877 	flags.udp_encap_custom_ports = true;
10878 
10879 	return test_ipsec_proto_all(&flags);
10880 }
10881 
10882 static int
10883 test_ipsec_proto_udp_encap(void)
10884 {
10885 	struct ipsec_test_flags flags;
10886 
10887 	memset(&flags, 0, sizeof(flags));
10888 
10889 	flags.udp_encap = true;
10890 
10891 	return test_ipsec_proto_all(&flags);
10892 }
10893 
10894 static int
10895 test_ipsec_proto_tunnel_src_dst_addr_verify(void)
10896 {
10897 	struct ipsec_test_flags flags;
10898 
10899 	memset(&flags, 0, sizeof(flags));
10900 
10901 	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
10902 
10903 	return test_ipsec_proto_all(&flags);
10904 }
10905 
10906 static int
10907 test_ipsec_proto_tunnel_dst_addr_verify(void)
10908 {
10909 	struct ipsec_test_flags flags;
10910 
10911 	memset(&flags, 0, sizeof(flags));
10912 
10913 	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR;
10914 
10915 	return test_ipsec_proto_all(&flags);
10916 }
10917 
10918 static int
10919 test_ipsec_proto_udp_ports_verify(void)
10920 {
10921 	struct ipsec_test_flags flags;
10922 
10923 	memset(&flags, 0, sizeof(flags));
10924 
10925 	flags.udp_encap = true;
10926 	flags.udp_ports_verify = true;
10927 
10928 	return test_ipsec_proto_all(&flags);
10929 }
10930 
10931 static int
10932 test_ipsec_proto_inner_ip_csum(void)
10933 {
10934 	struct ipsec_test_flags flags;
10935 
10936 	memset(&flags, 0, sizeof(flags));
10937 
10938 	flags.ip_csum = true;
10939 
10940 	return test_ipsec_proto_all(&flags);
10941 }
10942 
10943 static int
10944 test_ipsec_proto_inner_l4_csum(void)
10945 {
10946 	struct ipsec_test_flags flags;
10947 
10948 	memset(&flags, 0, sizeof(flags));
10949 
10950 	flags.l4_csum = true;
10951 
10952 	return test_ipsec_proto_all(&flags);
10953 }
10954 
10955 static int
10956 test_ipsec_proto_tunnel_v4_in_v4(void)
10957 {
10958 	struct ipsec_test_flags flags;
10959 
10960 	memset(&flags, 0, sizeof(flags));
10961 
10962 	flags.ipv6 = false;
10963 	flags.tunnel_ipv6 = false;
10964 
10965 	return test_ipsec_proto_all(&flags);
10966 }
10967 
10968 static int
10969 test_ipsec_proto_tunnel_v6_in_v6(void)
10970 {
10971 	struct ipsec_test_flags flags;
10972 
10973 	memset(&flags, 0, sizeof(flags));
10974 
10975 	flags.ipv6 = true;
10976 	flags.tunnel_ipv6 = true;
10977 
10978 	return test_ipsec_proto_all(&flags);
10979 }
10980 
10981 static int
10982 test_ipsec_proto_tunnel_v4_in_v6(void)
10983 {
10984 	struct ipsec_test_flags flags;
10985 
10986 	memset(&flags, 0, sizeof(flags));
10987 
10988 	flags.ipv6 = false;
10989 	flags.tunnel_ipv6 = true;
10990 
10991 	return test_ipsec_proto_all(&flags);
10992 }
10993 
10994 static int
10995 test_ipsec_proto_tunnel_v6_in_v4(void)
10996 {
10997 	struct ipsec_test_flags flags;
10998 
10999 	memset(&flags, 0, sizeof(flags));
11000 
11001 	flags.ipv6 = true;
11002 	flags.tunnel_ipv6 = false;
11003 
11004 	return test_ipsec_proto_all(&flags);
11005 }
11006 
11007 static int
11008 test_ipsec_proto_transport_v4(void)
11009 {
11010 	struct ipsec_test_flags flags;
11011 
11012 	memset(&flags, 0, sizeof(flags));
11013 
11014 	flags.ipv6 = false;
11015 	flags.transport = true;
11016 
11017 	return test_ipsec_proto_all(&flags);
11018 }
11019 
11020 static int
11021 test_ipsec_proto_transport_l4_csum(void)
11022 {
11023 	struct ipsec_test_flags flags = {
11024 		.l4_csum = true,
11025 		.transport = true,
11026 	};
11027 
11028 	return test_ipsec_proto_all(&flags);
11029 }
11030 
11031 static int
11032 test_ipsec_proto_stats(void)
11033 {
11034 	struct ipsec_test_flags flags;
11035 
11036 	memset(&flags, 0, sizeof(flags));
11037 
11038 	flags.stats_success = true;
11039 
11040 	return test_ipsec_proto_all(&flags);
11041 }
11042 
11043 static int
11044 test_ipsec_proto_pkt_fragment(void)
11045 {
11046 	struct ipsec_test_flags flags;
11047 
11048 	memset(&flags, 0, sizeof(flags));
11049 
11050 	flags.fragment = true;
11051 
11052 	return test_ipsec_proto_all(&flags);
11053 
11054 }
11055 
11056 static int
11057 test_ipsec_proto_copy_df_inner_0(void)
11058 {
11059 	struct ipsec_test_flags flags;
11060 
11061 	memset(&flags, 0, sizeof(flags));
11062 
11063 	flags.df = TEST_IPSEC_COPY_DF_INNER_0;
11064 
11065 	return test_ipsec_proto_all(&flags);
11066 }
11067 
11068 static int
11069 test_ipsec_proto_copy_df_inner_1(void)
11070 {
11071 	struct ipsec_test_flags flags;
11072 
11073 	memset(&flags, 0, sizeof(flags));
11074 
11075 	flags.df = TEST_IPSEC_COPY_DF_INNER_1;
11076 
11077 	return test_ipsec_proto_all(&flags);
11078 }
11079 
11080 static int
11081 test_ipsec_proto_set_df_0_inner_1(void)
11082 {
11083 	struct ipsec_test_flags flags;
11084 
11085 	memset(&flags, 0, sizeof(flags));
11086 
11087 	flags.df = TEST_IPSEC_SET_DF_0_INNER_1;
11088 
11089 	return test_ipsec_proto_all(&flags);
11090 }
11091 
11092 static int
11093 test_ipsec_proto_set_df_1_inner_0(void)
11094 {
11095 	struct ipsec_test_flags flags;
11096 
11097 	memset(&flags, 0, sizeof(flags));
11098 
11099 	flags.df = TEST_IPSEC_SET_DF_1_INNER_0;
11100 
11101 	return test_ipsec_proto_all(&flags);
11102 }
11103 
11104 static int
11105 test_ipsec_proto_ipv4_copy_dscp_inner_0(void)
11106 {
11107 	struct ipsec_test_flags flags;
11108 
11109 	memset(&flags, 0, sizeof(flags));
11110 
11111 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0;
11112 
11113 	return test_ipsec_proto_all(&flags);
11114 }
11115 
11116 static int
11117 test_ipsec_proto_ipv4_copy_dscp_inner_1(void)
11118 {
11119 	struct ipsec_test_flags flags;
11120 
11121 	memset(&flags, 0, sizeof(flags));
11122 
11123 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1;
11124 
11125 	return test_ipsec_proto_all(&flags);
11126 }
11127 
11128 static int
11129 test_ipsec_proto_ipv4_set_dscp_0_inner_1(void)
11130 {
11131 	struct ipsec_test_flags flags;
11132 
11133 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
11134 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD)))
11135 		return TEST_SKIPPED;
11136 
11137 	memset(&flags, 0, sizeof(flags));
11138 
11139 	flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1;
11140 
11141 	return test_ipsec_proto_all(&flags);
11142 }
11143 
11144 static int
11145 test_ipsec_proto_ipv4_set_dscp_1_inner_0(void)
11146 {
11147 	struct ipsec_test_flags flags;
11148 
11149 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
11150 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD)))
11151 		return TEST_SKIPPED;
11152 
11153 	memset(&flags, 0, sizeof(flags));
11154 
11155 	flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0;
11156 
11157 	return test_ipsec_proto_all(&flags);
11158 }
11159 
11160 static int
11161 test_ipsec_proto_ipv6_copy_dscp_inner_0(void)
11162 {
11163 	struct ipsec_test_flags flags;
11164 
11165 	memset(&flags, 0, sizeof(flags));
11166 
11167 	flags.ipv6 = true;
11168 	flags.tunnel_ipv6 = true;
11169 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0;
11170 
11171 	return test_ipsec_proto_all(&flags);
11172 }
11173 
11174 static int
11175 test_ipsec_proto_ipv6_copy_dscp_inner_1(void)
11176 {
11177 	struct ipsec_test_flags flags;
11178 
11179 	memset(&flags, 0, sizeof(flags));
11180 
11181 	flags.ipv6 = true;
11182 	flags.tunnel_ipv6 = true;
11183 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1;
11184 
11185 	return test_ipsec_proto_all(&flags);
11186 }
11187 
11188 static int
11189 test_ipsec_proto_ipv6_set_dscp_0_inner_1(void)
11190 {
11191 	struct ipsec_test_flags flags;
11192 
11193 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
11194 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD)))
11195 		return TEST_SKIPPED;
11196 
11197 	memset(&flags, 0, sizeof(flags));
11198 
11199 	flags.ipv6 = true;
11200 	flags.tunnel_ipv6 = true;
11201 	flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1;
11202 
11203 	return test_ipsec_proto_all(&flags);
11204 }
11205 
11206 static int
11207 test_ipsec_proto_ipv6_set_dscp_1_inner_0(void)
11208 {
11209 	struct ipsec_test_flags flags;
11210 
11211 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
11212 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD)))
11213 		return TEST_SKIPPED;
11214 
11215 	memset(&flags, 0, sizeof(flags));
11216 
11217 	flags.ipv6 = true;
11218 	flags.tunnel_ipv6 = true;
11219 	flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0;
11220 
11221 	return test_ipsec_proto_all(&flags);
11222 }
11223 
11224 static int
11225 test_ipsec_proto_sgl(void)
11226 {
11227 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11228 	struct rte_cryptodev_info dev_info;
11229 
11230 	struct ipsec_test_flags flags = {
11231 		.nb_segs_in_mbuf = 5
11232 	};
11233 
11234 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11235 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
11236 		printf("Device doesn't support in-place scatter-gather. "
11237 				"Test Skipped.\n");
11238 		return TEST_SKIPPED;
11239 	}
11240 
11241 	return test_ipsec_proto_all(&flags);
11242 }
11243 
11244 static int
11245 test_ipsec_proto_sgl_ext_mbuf(void)
11246 {
11247 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11248 	struct rte_cryptodev_info dev_info;
11249 
11250 	struct ipsec_test_flags flags = {
11251 		.nb_segs_in_mbuf = 5,
11252 		.use_ext_mbuf = 1
11253 	};
11254 
11255 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11256 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
11257 		printf("Device doesn't support in-place scatter-gather. "
11258 				"Test Skipped.\n");
11259 		return TEST_SKIPPED;
11260 	}
11261 
11262 	return test_ipsec_proto_all(&flags);
11263 }
11264 
11265 static int
11266 test_ipsec_pkt_replay(const void *test_data, const uint64_t esn[],
11267 		      bool replayed_pkt[], uint32_t nb_pkts, bool esn_en,
11268 		      uint64_t winsz)
11269 {
11270 	struct ipsec_test_data td_outb[TEST_SEC_PKTS_MAX];
11271 	struct ipsec_test_data td_inb[TEST_SEC_PKTS_MAX];
11272 	struct ipsec_test_flags flags;
11273 	uint32_t i = 0, ret = 0;
11274 
11275 	if (nb_pkts == 0)
11276 		return TEST_FAILED;
11277 
11278 	memset(&flags, 0, sizeof(flags));
11279 	flags.antireplay = true;
11280 
11281 	for (i = 0; i < nb_pkts; i++) {
11282 		memcpy(&td_outb[i], test_data, sizeof(td_outb[i]));
11283 		td_outb[i].ipsec_xform.options.iv_gen_disable = 1;
11284 		td_outb[i].ipsec_xform.replay_win_sz = winsz;
11285 		td_outb[i].ipsec_xform.options.esn = esn_en;
11286 	}
11287 
11288 	for (i = 0; i < nb_pkts; i++)
11289 		td_outb[i].ipsec_xform.esn.value = esn[i];
11290 
11291 	ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
11292 				       &flags);
11293 	if (ret != TEST_SUCCESS)
11294 		return ret;
11295 
11296 	test_ipsec_td_update(td_inb, td_outb, nb_pkts, &flags);
11297 
11298 	for (i = 0; i < nb_pkts; i++) {
11299 		td_inb[i].ipsec_xform.options.esn = esn_en;
11300 		/* Set antireplay flag for packets to be dropped */
11301 		td_inb[i].ar_packet = replayed_pkt[i];
11302 	}
11303 
11304 	ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
11305 				       &flags);
11306 
11307 	return ret;
11308 }
11309 
11310 static int
11311 test_ipsec_proto_pkt_antireplay(const void *test_data, uint64_t winsz)
11312 {
11313 
11314 	uint32_t nb_pkts = 5;
11315 	bool replayed_pkt[5];
11316 	uint64_t esn[5];
11317 
11318 	/* 1. Advance the TOP of the window to WS * 2 */
11319 	esn[0] = winsz * 2;
11320 	/* 2. Test sequence number within the new window(WS + 1) */
11321 	esn[1] = winsz + 1;
11322 	/* 3. Test sequence number less than the window BOTTOM */
11323 	esn[2] = winsz;
11324 	/* 4. Test sequence number in the middle of the window */
11325 	esn[3] = winsz + (winsz / 2);
11326 	/* 5. Test replay of the packet in the middle of the window */
11327 	esn[4] = winsz + (winsz / 2);
11328 
11329 	replayed_pkt[0] = false;
11330 	replayed_pkt[1] = false;
11331 	replayed_pkt[2] = true;
11332 	replayed_pkt[3] = false;
11333 	replayed_pkt[4] = true;
11334 
11335 	return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts,
11336 				     false, winsz);
11337 }
11338 
11339 static int
11340 test_ipsec_proto_pkt_antireplay1024(const void *test_data)
11341 {
11342 	return test_ipsec_proto_pkt_antireplay(test_data, 1024);
11343 }
11344 
11345 static int
11346 test_ipsec_proto_pkt_antireplay2048(const void *test_data)
11347 {
11348 	return test_ipsec_proto_pkt_antireplay(test_data, 2048);
11349 }
11350 
11351 static int
11352 test_ipsec_proto_pkt_antireplay4096(const void *test_data)
11353 {
11354 	return test_ipsec_proto_pkt_antireplay(test_data, 4096);
11355 }
11356 
11357 static int
11358 test_ipsec_proto_pkt_esn_antireplay(const void *test_data, uint64_t winsz)
11359 {
11360 
11361 	uint32_t nb_pkts = 7;
11362 	bool replayed_pkt[7];
11363 	uint64_t esn[7];
11364 
11365 	/* Set the initial sequence number */
11366 	esn[0] = (uint64_t)(0xFFFFFFFF - winsz);
11367 	/* 1. Advance the TOP of the window to (1<<32 + WS/2) */
11368 	esn[1] = (uint64_t)((1ULL << 32) + (winsz / 2));
11369 	/* 2. Test sequence number within new window (1<<32 + WS/2 + 1) */
11370 	esn[2] = (uint64_t)((1ULL << 32) - (winsz / 2) + 1);
11371 	/* 3. Test with sequence number within window (1<<32 - 1) */
11372 	esn[3] = (uint64_t)((1ULL << 32) - 1);
11373 	/* 4. Test with sequence number within window (1<<32 - 1) */
11374 	esn[4] = (uint64_t)(1ULL << 32);
11375 	/* 5. Test with duplicate sequence number within
11376 	 * new window (1<<32 - 1)
11377 	 */
11378 	esn[5] = (uint64_t)((1ULL << 32) - 1);
11379 	/* 6. Test with duplicate sequence number within new window (1<<32) */
11380 	esn[6] = (uint64_t)(1ULL << 32);
11381 
11382 	replayed_pkt[0] = false;
11383 	replayed_pkt[1] = false;
11384 	replayed_pkt[2] = false;
11385 	replayed_pkt[3] = false;
11386 	replayed_pkt[4] = false;
11387 	replayed_pkt[5] = true;
11388 	replayed_pkt[6] = true;
11389 
11390 	return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts,
11391 				     true, winsz);
11392 }
11393 
11394 static int
11395 test_ipsec_proto_pkt_esn_antireplay1024(const void *test_data)
11396 {
11397 	return test_ipsec_proto_pkt_esn_antireplay(test_data, 1024);
11398 }
11399 
11400 static int
11401 test_ipsec_proto_pkt_esn_antireplay2048(const void *test_data)
11402 {
11403 	return test_ipsec_proto_pkt_esn_antireplay(test_data, 2048);
11404 }
11405 
11406 static int
11407 test_ipsec_proto_pkt_esn_antireplay4096(const void *test_data)
11408 {
11409 	return test_ipsec_proto_pkt_esn_antireplay(test_data, 4096);
11410 }
11411 
11412 static int
11413 test_PDCP_PROTO_all(void)
11414 {
11415 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11416 	struct crypto_unittest_params *ut_params = &unittest_params;
11417 	struct rte_cryptodev_info dev_info;
11418 	int status;
11419 
11420 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11421 	uint64_t feat_flags = dev_info.feature_flags;
11422 
11423 	if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
11424 		return TEST_SKIPPED;
11425 
11426 	/* Set action type */
11427 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
11428 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
11429 		gbl_action_type;
11430 
11431 	if (security_proto_supported(ut_params->type,
11432 			RTE_SECURITY_PROTOCOL_PDCP) < 0)
11433 		return TEST_SKIPPED;
11434 
11435 	status = test_PDCP_PROTO_cplane_encap_all();
11436 	status += test_PDCP_PROTO_cplane_decap_all();
11437 	status += test_PDCP_PROTO_uplane_encap_all();
11438 	status += test_PDCP_PROTO_uplane_decap_all();
11439 	status += test_PDCP_PROTO_SGL_in_place_32B();
11440 	status += test_PDCP_PROTO_SGL_oop_32B_128B();
11441 	status += test_PDCP_PROTO_SGL_oop_32B_40B();
11442 	status += test_PDCP_PROTO_SGL_oop_128B_32B();
11443 	status += test_PDCP_SDAP_PROTO_encap_all();
11444 	status += test_PDCP_SDAP_PROTO_decap_all();
11445 	status += test_PDCP_PROTO_short_mac();
11446 
11447 	if (status)
11448 		return TEST_FAILED;
11449 	else
11450 		return TEST_SUCCESS;
11451 }
11452 
11453 static int
11454 test_ipsec_proto_ipv4_ttl_decrement(void)
11455 {
11456 	struct ipsec_test_flags flags = {
11457 		.dec_ttl_or_hop_limit = true
11458 	};
11459 
11460 	return test_ipsec_proto_all(&flags);
11461 }
11462 
11463 static int
11464 test_ipsec_proto_ipv6_hop_limit_decrement(void)
11465 {
11466 	struct ipsec_test_flags flags = {
11467 		.ipv6 = true,
11468 		.dec_ttl_or_hop_limit = true
11469 	};
11470 
11471 	return test_ipsec_proto_all(&flags);
11472 }
11473 
11474 static int
11475 test_docsis_proto_uplink(const void *data)
11476 {
11477 	const struct docsis_test_data *d_td = data;
11478 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11479 	struct crypto_unittest_params *ut_params = &unittest_params;
11480 	uint8_t *plaintext = NULL;
11481 	uint8_t *ciphertext = NULL;
11482 	uint8_t *iv_ptr;
11483 	int32_t cipher_len, crc_len;
11484 	uint32_t crc_data_len;
11485 	int ret = TEST_SUCCESS;
11486 
11487 	void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]);
11488 
11489 	/* Verify the capabilities */
11490 	struct rte_security_capability_idx sec_cap_idx;
11491 	const struct rte_security_capability *sec_cap;
11492 	const struct rte_cryptodev_capabilities *crypto_cap;
11493 	const struct rte_cryptodev_symmetric_capability *sym_cap;
11494 	int j = 0;
11495 
11496 	/* Set action type */
11497 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
11498 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
11499 		gbl_action_type;
11500 
11501 	if (security_proto_supported(ut_params->type,
11502 			RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
11503 		return TEST_SKIPPED;
11504 
11505 	sec_cap_idx.action = ut_params->type;
11506 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
11507 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
11508 
11509 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
11510 	if (sec_cap == NULL)
11511 		return TEST_SKIPPED;
11512 
11513 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
11514 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
11515 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
11516 				crypto_cap->sym.xform_type ==
11517 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
11518 				crypto_cap->sym.cipher.algo ==
11519 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
11520 			sym_cap = &crypto_cap->sym;
11521 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
11522 						d_td->key.len,
11523 						d_td->iv.len) == 0)
11524 				break;
11525 		}
11526 	}
11527 
11528 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
11529 		return TEST_SKIPPED;
11530 
11531 	/* Setup source mbuf payload */
11532 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11533 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11534 			rte_pktmbuf_tailroom(ut_params->ibuf));
11535 
11536 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11537 			d_td->ciphertext.len);
11538 
11539 	memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
11540 
11541 	/* Setup cipher session parameters */
11542 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11543 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
11544 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
11545 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
11546 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
11547 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
11548 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
11549 	ut_params->cipher_xform.next = NULL;
11550 
11551 	/* Setup DOCSIS session parameters */
11552 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
11553 
11554 	struct rte_security_session_conf sess_conf = {
11555 		.action_type = ut_params->type,
11556 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
11557 		.docsis = ut_params->docsis_xform,
11558 		.crypto_xform = &ut_params->cipher_xform,
11559 	};
11560 
11561 	/* Create security session */
11562 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
11563 					ts_params->session_mpool);
11564 
11565 	if (!ut_params->sec_session) {
11566 		printf("Test function %s line %u: failed to allocate session\n",
11567 			__func__, __LINE__);
11568 		ret = TEST_FAILED;
11569 		goto on_err;
11570 	}
11571 
11572 	/* Generate crypto op data structure */
11573 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11574 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11575 	if (!ut_params->op) {
11576 		printf("Test function %s line %u: failed to allocate symmetric "
11577 			"crypto operation\n", __func__, __LINE__);
11578 		ret = TEST_FAILED;
11579 		goto on_err;
11580 	}
11581 
11582 	/* Setup CRC operation parameters */
11583 	crc_len = d_td->ciphertext.no_crc == false ?
11584 			(d_td->ciphertext.len -
11585 				d_td->ciphertext.crc_offset -
11586 				RTE_ETHER_CRC_LEN) :
11587 			0;
11588 	crc_len = crc_len > 0 ? crc_len : 0;
11589 	crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
11590 	ut_params->op->sym->auth.data.length = crc_len;
11591 	ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
11592 
11593 	/* Setup cipher operation parameters */
11594 	cipher_len = d_td->ciphertext.no_cipher == false ?
11595 			(d_td->ciphertext.len -
11596 				d_td->ciphertext.cipher_offset) :
11597 			0;
11598 	cipher_len = cipher_len > 0 ? cipher_len : 0;
11599 	ut_params->op->sym->cipher.data.length = cipher_len;
11600 	ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
11601 
11602 	/* Setup cipher IV */
11603 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
11604 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
11605 
11606 	/* Attach session to operation */
11607 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
11608 
11609 	/* Set crypto operation mbufs */
11610 	ut_params->op->sym->m_src = ut_params->ibuf;
11611 	ut_params->op->sym->m_dst = NULL;
11612 
11613 	/* Process crypto operation */
11614 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
11615 			NULL) {
11616 		printf("Test function %s line %u: failed to process security "
11617 			"crypto op\n", __func__, __LINE__);
11618 		ret = TEST_FAILED;
11619 		goto on_err;
11620 	}
11621 
11622 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
11623 		printf("Test function %s line %u: failed to process crypto op\n",
11624 			__func__, __LINE__);
11625 		ret = TEST_FAILED;
11626 		goto on_err;
11627 	}
11628 
11629 	/* Validate plaintext */
11630 	plaintext = ciphertext;
11631 
11632 	if (memcmp(plaintext, d_td->plaintext.data,
11633 			d_td->plaintext.len - crc_data_len)) {
11634 		printf("Test function %s line %u: plaintext not as expected\n",
11635 			__func__, __LINE__);
11636 		rte_hexdump(stdout, "expected", d_td->plaintext.data,
11637 				d_td->plaintext.len);
11638 		rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
11639 		ret = TEST_FAILED;
11640 		goto on_err;
11641 	}
11642 
11643 on_err:
11644 	rte_crypto_op_free(ut_params->op);
11645 	ut_params->op = NULL;
11646 
11647 	if (ut_params->sec_session)
11648 		rte_security_session_destroy(ctx, ut_params->sec_session);
11649 	ut_params->sec_session = NULL;
11650 
11651 	rte_pktmbuf_free(ut_params->ibuf);
11652 	ut_params->ibuf = NULL;
11653 
11654 	return ret;
11655 }
11656 
11657 static int
11658 test_docsis_proto_downlink(const void *data)
11659 {
11660 	const struct docsis_test_data *d_td = data;
11661 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11662 	struct crypto_unittest_params *ut_params = &unittest_params;
11663 	uint8_t *plaintext = NULL;
11664 	uint8_t *ciphertext = NULL;
11665 	uint8_t *iv_ptr;
11666 	int32_t cipher_len, crc_len;
11667 	int ret = TEST_SUCCESS;
11668 
11669 	void *ctx = rte_cryptodev_get_sec_ctx(ts_params->valid_devs[0]);
11670 
11671 	/* Verify the capabilities */
11672 	struct rte_security_capability_idx sec_cap_idx;
11673 	const struct rte_security_capability *sec_cap;
11674 	const struct rte_cryptodev_capabilities *crypto_cap;
11675 	const struct rte_cryptodev_symmetric_capability *sym_cap;
11676 	int j = 0;
11677 
11678 	/* Set action type */
11679 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
11680 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
11681 		gbl_action_type;
11682 
11683 	if (security_proto_supported(ut_params->type,
11684 			RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
11685 		return TEST_SKIPPED;
11686 
11687 	sec_cap_idx.action = ut_params->type;
11688 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
11689 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
11690 
11691 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
11692 	if (sec_cap == NULL)
11693 		return TEST_SKIPPED;
11694 
11695 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
11696 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
11697 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
11698 				crypto_cap->sym.xform_type ==
11699 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
11700 				crypto_cap->sym.cipher.algo ==
11701 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
11702 			sym_cap = &crypto_cap->sym;
11703 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
11704 						d_td->key.len,
11705 						d_td->iv.len) == 0)
11706 				break;
11707 		}
11708 	}
11709 
11710 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
11711 		return TEST_SKIPPED;
11712 
11713 	/* Setup source mbuf payload */
11714 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11715 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11716 			rte_pktmbuf_tailroom(ut_params->ibuf));
11717 
11718 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11719 			d_td->plaintext.len);
11720 
11721 	memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
11722 
11723 	/* Setup cipher session parameters */
11724 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11725 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
11726 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11727 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
11728 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
11729 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
11730 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
11731 	ut_params->cipher_xform.next = NULL;
11732 
11733 	/* Setup DOCSIS session parameters */
11734 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
11735 
11736 	struct rte_security_session_conf sess_conf = {
11737 		.action_type = ut_params->type,
11738 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
11739 		.docsis = ut_params->docsis_xform,
11740 		.crypto_xform = &ut_params->cipher_xform,
11741 	};
11742 
11743 	/* Create security session */
11744 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
11745 					ts_params->session_mpool);
11746 
11747 	if (!ut_params->sec_session) {
11748 		printf("Test function %s line %u: failed to allocate session\n",
11749 			__func__, __LINE__);
11750 		ret = TEST_FAILED;
11751 		goto on_err;
11752 	}
11753 
11754 	/* Generate crypto op data structure */
11755 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11756 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11757 	if (!ut_params->op) {
11758 		printf("Test function %s line %u: failed to allocate symmetric "
11759 			"crypto operation\n", __func__, __LINE__);
11760 		ret = TEST_FAILED;
11761 		goto on_err;
11762 	}
11763 
11764 	/* Setup CRC operation parameters */
11765 	crc_len = d_td->plaintext.no_crc == false ?
11766 			(d_td->plaintext.len -
11767 				d_td->plaintext.crc_offset -
11768 				RTE_ETHER_CRC_LEN) :
11769 			0;
11770 	crc_len = crc_len > 0 ? crc_len : 0;
11771 	ut_params->op->sym->auth.data.length = crc_len;
11772 	ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
11773 
11774 	/* Setup cipher operation parameters */
11775 	cipher_len = d_td->plaintext.no_cipher == false ?
11776 			(d_td->plaintext.len -
11777 				d_td->plaintext.cipher_offset) :
11778 			0;
11779 	cipher_len = cipher_len > 0 ? cipher_len : 0;
11780 	ut_params->op->sym->cipher.data.length = cipher_len;
11781 	ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
11782 
11783 	/* Setup cipher IV */
11784 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
11785 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
11786 
11787 	/* Attach session to operation */
11788 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
11789 
11790 	/* Set crypto operation mbufs */
11791 	ut_params->op->sym->m_src = ut_params->ibuf;
11792 	ut_params->op->sym->m_dst = NULL;
11793 
11794 	/* Process crypto operation */
11795 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
11796 			NULL) {
11797 		printf("Test function %s line %u: failed to process crypto op\n",
11798 			__func__, __LINE__);
11799 		ret = TEST_FAILED;
11800 		goto on_err;
11801 	}
11802 
11803 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
11804 		printf("Test function %s line %u: crypto op processing failed\n",
11805 			__func__, __LINE__);
11806 		ret = TEST_FAILED;
11807 		goto on_err;
11808 	}
11809 
11810 	/* Validate ciphertext */
11811 	ciphertext = plaintext;
11812 
11813 	if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
11814 		printf("Test function %s line %u: plaintext not as expected\n",
11815 			__func__, __LINE__);
11816 		rte_hexdump(stdout, "expected", d_td->ciphertext.data,
11817 				d_td->ciphertext.len);
11818 		rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
11819 		ret = TEST_FAILED;
11820 		goto on_err;
11821 	}
11822 
11823 on_err:
11824 	rte_crypto_op_free(ut_params->op);
11825 	ut_params->op = NULL;
11826 
11827 	if (ut_params->sec_session)
11828 		rte_security_session_destroy(ctx, ut_params->sec_session);
11829 	ut_params->sec_session = NULL;
11830 
11831 	rte_pktmbuf_free(ut_params->ibuf);
11832 	ut_params->ibuf = NULL;
11833 
11834 	return ret;
11835 }
11836 
11837 static void
11838 test_tls_record_imp_nonce_update(const struct tls_record_test_data *td,
11839 				 struct rte_security_tls_record_xform *tls_record_xform)
11840 {
11841 	unsigned int imp_nonce_len;
11842 	uint8_t *imp_nonce;
11843 
11844 	switch (tls_record_xform->ver) {
11845 	case RTE_SECURITY_VERSION_TLS_1_2:
11846 		imp_nonce_len = RTE_SECURITY_TLS_1_2_IMP_NONCE_LEN;
11847 		imp_nonce = tls_record_xform->tls_1_2.imp_nonce;
11848 		break;
11849 	case RTE_SECURITY_VERSION_DTLS_1_2:
11850 		imp_nonce_len = RTE_SECURITY_DTLS_1_2_IMP_NONCE_LEN;
11851 		imp_nonce = tls_record_xform->dtls_1_2.imp_nonce;
11852 		break;
11853 	case RTE_SECURITY_VERSION_TLS_1_3:
11854 		imp_nonce_len = RTE_SECURITY_TLS_1_3_IMP_NONCE_LEN;
11855 		imp_nonce = tls_record_xform->tls_1_3.imp_nonce;
11856 		break;
11857 	default:
11858 		return;
11859 	}
11860 
11861 	imp_nonce_len = RTE_MIN(imp_nonce_len, td[0].imp_nonce.len);
11862 	memcpy(imp_nonce, td[0].imp_nonce.data, imp_nonce_len);
11863 }
11864 
11865 static int
11866 test_tls_record_proto_process(const struct tls_record_test_data td[],
11867 			      struct tls_record_test_data res_d[], int nb_td, bool silent,
11868 			      const struct tls_record_test_flags *flags)
11869 {
11870 	int nb_segs = flags->nb_segs_in_mbuf ? flags->nb_segs_in_mbuf : 1;
11871 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11872 	struct crypto_unittest_params *ut_params = &unittest_params;
11873 	struct rte_security_tls_record_xform tls_record_xform;
11874 	struct rte_security_capability_idx sec_cap_idx;
11875 	const struct rte_security_capability *sec_cap;
11876 	struct tls_record_test_data *res_d_tmp = NULL;
11877 	enum rte_security_tls_sess_type sess_type;
11878 	uint8_t dev_id = ts_params->valid_devs[0];
11879 	struct rte_security_ctx *ctx;
11880 	int i, ret = TEST_SUCCESS;
11881 
11882 	ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
11883 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
11884 
11885 	/* Use first test data to create session */
11886 
11887 	/* Copy TLS record xform */
11888 	memcpy(&tls_record_xform, &td[0].tls_record_xform, sizeof(tls_record_xform));
11889 
11890 	sess_type = tls_record_xform.type;
11891 
11892 	ctx = rte_cryptodev_get_sec_ctx(dev_id);
11893 
11894 	sec_cap_idx.action = ut_params->type;
11895 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_TLS_RECORD;
11896 	sec_cap_idx.tls_record.type = tls_record_xform.type;
11897 	sec_cap_idx.tls_record.ver = tls_record_xform.ver;
11898 
11899 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
11900 	if (sec_cap == NULL)
11901 		return TEST_SKIPPED;
11902 
11903 	/* Copy cipher session parameters */
11904 	if (td[0].aead) {
11905 		memcpy(&ut_params->aead_xform, &td[0].xform.aead, sizeof(ut_params->aead_xform));
11906 		ut_params->aead_xform.aead.key.data = td[0].key.data;
11907 		ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
11908 
11909 		/* Verify crypto capabilities */
11910 		if (test_sec_crypto_caps_aead_verify(sec_cap, &ut_params->aead_xform) != 0) {
11911 			if (!silent)
11912 				RTE_LOG(INFO, USER1, "Crypto capabilities not supported\n");
11913 			return TEST_SKIPPED;
11914 		}
11915 	} else {
11916 		memcpy(&ut_params->cipher_xform, &td[0].xform.chain.cipher,
11917 		       sizeof(ut_params->cipher_xform));
11918 		memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth,
11919 		       sizeof(ut_params->auth_xform));
11920 		ut_params->cipher_xform.cipher.key.data = td[0].key.data;
11921 		ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
11922 		ut_params->auth_xform.auth.key.data = td[0].auth_key.data;
11923 
11924 		/* Verify crypto capabilities */
11925 
11926 		if (test_sec_crypto_caps_cipher_verify(sec_cap, &ut_params->cipher_xform) != 0) {
11927 			if (!silent)
11928 				RTE_LOG(INFO, USER1, "Cipher crypto capabilities not supported\n");
11929 			return TEST_SKIPPED;
11930 		}
11931 
11932 		if (test_sec_crypto_caps_auth_verify(sec_cap, &ut_params->auth_xform) != 0) {
11933 			if (!silent)
11934 				RTE_LOG(INFO, USER1, "Auth crypto capabilities not supported\n");
11935 			return TEST_SKIPPED;
11936 		}
11937 	}
11938 
11939 	if (test_tls_record_sec_caps_verify(&tls_record_xform, sec_cap, silent) != 0)
11940 		return TEST_SKIPPED;
11941 
11942 	struct rte_security_session_conf sess_conf = {
11943 		.action_type = ut_params->type,
11944 		.protocol = RTE_SECURITY_PROTOCOL_TLS_RECORD,
11945 	};
11946 
11947 	if ((tls_record_xform.ver == RTE_SECURITY_VERSION_DTLS_1_2) &&
11948 	    (sess_type == RTE_SECURITY_TLS_SESS_TYPE_READ))
11949 		sess_conf.tls_record.dtls_1_2.ar_win_sz = flags->ar_win_size;
11950 
11951 	if (td[0].aead)
11952 		test_tls_record_imp_nonce_update(&td[0], &tls_record_xform);
11953 
11954 	if (flags->opt_padding)
11955 		tls_record_xform.options.extra_padding_enable = 1;
11956 
11957 	sess_conf.tls_record = tls_record_xform;
11958 
11959 	if (td[0].aead) {
11960 		sess_conf.crypto_xform = &ut_params->aead_xform;
11961 	} else {
11962 		if (sess_type == RTE_SECURITY_TLS_SESS_TYPE_READ) {
11963 			sess_conf.crypto_xform = &ut_params->cipher_xform;
11964 			ut_params->cipher_xform.next = &ut_params->auth_xform;
11965 		} else {
11966 			sess_conf.crypto_xform = &ut_params->auth_xform;
11967 			ut_params->auth_xform.next = &ut_params->cipher_xform;
11968 		}
11969 	}
11970 
11971 	/* Create security session */
11972 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
11973 					ts_params->session_mpool);
11974 	if (ut_params->sec_session == NULL)
11975 		return TEST_SKIPPED;
11976 
11977 	for (i = 0; i < nb_td; i++) {
11978 		if (flags->ar_win_size &&
11979 			(sess_type == RTE_SECURITY_TLS_SESS_TYPE_WRITE)) {
11980 			sess_conf.tls_record.dtls_1_2.seq_no =
11981 				td[i].tls_record_xform.dtls_1_2.seq_no;
11982 			ret = rte_security_session_update(ctx, ut_params->sec_session, &sess_conf);
11983 			if (ret) {
11984 				printf("Could not update sequence number in session\n");
11985 				return TEST_SKIPPED;
11986 			}
11987 		}
11988 
11989 		/* Setup source mbuf payload */
11990 		ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, td[i].input_text.len,
11991 				nb_segs, 0);
11992 		pktmbuf_write(ut_params->ibuf, 0, td[i].input_text.len, td[i].input_text.data);
11993 		if (flags->out_of_place)
11994 			ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
11995 					td[i].output_text.len, nb_segs, 0);
11996 		else
11997 			ut_params->obuf = NULL;
11998 
11999 		/* Generate crypto op data structure */
12000 		ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12001 						    RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12002 		if (ut_params->op == NULL) {
12003 			printf("Could not allocate crypto op");
12004 			ret = TEST_FAILED;
12005 			goto crypto_op_free;
12006 		}
12007 
12008 		/* Attach session to operation */
12009 		rte_security_attach_session(ut_params->op, ut_params->sec_session);
12010 
12011 		/* Set crypto operation mbufs */
12012 		ut_params->op->sym->m_src = ut_params->ibuf;
12013 		ut_params->op->sym->m_dst = ut_params->obuf;
12014 		ut_params->op->param1.tls_record.content_type = td[i].app_type;
12015 
12016 		if (flags->opt_padding)
12017 			ut_params->op->aux_flags = flags->opt_padding;
12018 
12019 		/* Copy IV in crypto operation when IV generation is disabled */
12020 		if ((sess_type == RTE_SECURITY_TLS_SESS_TYPE_WRITE) &&
12021 		    (tls_record_xform.ver != RTE_SECURITY_VERSION_TLS_1_3) &&
12022 		    (tls_record_xform.options.iv_gen_disable == 1)) {
12023 			uint8_t *iv;
12024 			int len;
12025 
12026 			iv = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET);
12027 			if (td[i].aead)
12028 				len = td[i].xform.aead.aead.iv.length - 4;
12029 			else
12030 				len = td[i].xform.chain.cipher.cipher.iv.length;
12031 			memcpy(iv, td[i].iv.data, len);
12032 		}
12033 
12034 		/* Process crypto operation */
12035 		process_crypto_request(dev_id, ut_params->op);
12036 
12037 		ret = test_tls_record_status_check(ut_params->op, &td[i]);
12038 		if (ret != TEST_SUCCESS)
12039 			goto crypto_op_free;
12040 
12041 		if (res_d != NULL)
12042 			res_d_tmp = &res_d[i];
12043 
12044 		if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) {
12045 			struct rte_mbuf *buf = flags->out_of_place ? ut_params->obuf :
12046 						ut_params->ibuf;
12047 
12048 			ret = test_tls_record_post_process(buf, &td[i], res_d_tmp,
12049 							   silent, flags);
12050 			if (ret != TEST_SUCCESS)
12051 				goto crypto_op_free;
12052 		}
12053 
12054 		rte_crypto_op_free(ut_params->op);
12055 		ut_params->op = NULL;
12056 
12057 		if (flags->out_of_place) {
12058 			rte_pktmbuf_free(ut_params->obuf);
12059 			ut_params->obuf = NULL;
12060 		}
12061 
12062 		rte_pktmbuf_free(ut_params->ibuf);
12063 		ut_params->ibuf = NULL;
12064 	}
12065 
12066 crypto_op_free:
12067 	rte_crypto_op_free(ut_params->op);
12068 	ut_params->op = NULL;
12069 
12070 	if (flags->out_of_place) {
12071 		rte_pktmbuf_free(ut_params->obuf);
12072 		ut_params->obuf = NULL;
12073 	}
12074 
12075 	rte_pktmbuf_free(ut_params->ibuf);
12076 	ut_params->ibuf = NULL;
12077 
12078 	if (ut_params->sec_session)
12079 		rte_security_session_destroy(ctx, ut_params->sec_session);
12080 	ut_params->sec_session = NULL;
12081 
12082 	RTE_SET_USED(flags);
12083 
12084 	return ret;
12085 }
12086 
12087 static int
12088 test_tls_record_proto_known_vec(const void *test_data)
12089 {
12090 	struct tls_record_test_data td_write;
12091 	struct tls_record_test_flags flags;
12092 
12093 	memset(&flags, 0, sizeof(flags));
12094 
12095 	memcpy(&td_write, test_data, sizeof(td_write));
12096 
12097 	/* Disable IV gen to be able to test with known vectors */
12098 	td_write.tls_record_xform.options.iv_gen_disable = 1;
12099 
12100 	return test_tls_record_proto_process(&td_write, NULL, 1, false, &flags);
12101 }
12102 
12103 static int
12104 test_tls_record_proto_known_vec_read(const void *test_data)
12105 {
12106 	const struct tls_record_test_data *td = test_data;
12107 	struct tls_record_test_flags flags;
12108 	struct tls_record_test_data td_inb;
12109 
12110 	memset(&flags, 0, sizeof(flags));
12111 
12112 	if (td->tls_record_xform.type == RTE_SECURITY_TLS_SESS_TYPE_WRITE)
12113 		test_tls_record_td_read_from_write(td, &td_inb);
12114 	else
12115 		memcpy(&td_inb, td, sizeof(td_inb));
12116 
12117 	return test_tls_record_proto_process(&td_inb, NULL, 1, false, &flags);
12118 }
12119 
12120 static int
12121 test_tls_record_proto_all(const struct tls_record_test_flags *flags)
12122 {
12123 	unsigned int i, nb_pkts = 1, pass_cnt = 0, payload_len, max_payload_len;
12124 	struct tls_record_test_data td_outb[TEST_SEC_PKTS_MAX];
12125 	struct tls_record_test_data td_inb[TEST_SEC_PKTS_MAX];
12126 	int ret;
12127 
12128 	switch (flags->tls_version) {
12129 	case RTE_SECURITY_VERSION_TLS_1_2:
12130 		max_payload_len = TLS_1_2_RECORD_PLAINTEXT_MAX_LEN;
12131 		break;
12132 	case RTE_SECURITY_VERSION_TLS_1_3:
12133 		max_payload_len = TLS_1_3_RECORD_PLAINTEXT_MAX_LEN;
12134 		break;
12135 	case RTE_SECURITY_VERSION_DTLS_1_2:
12136 		max_payload_len = DTLS_1_2_RECORD_PLAINTEXT_MAX_LEN;
12137 		break;
12138 	default:
12139 		max_payload_len = 0;
12140 	}
12141 
12142 	for (i = 0; i < RTE_DIM(sec_alg_list); i++) {
12143 		payload_len = TLS_RECORD_PLAINTEXT_MIN_LEN;
12144 		if (flags->nb_segs_in_mbuf)
12145 			payload_len = RTE_MAX(payload_len, flags->nb_segs_in_mbuf);
12146 
12147 		if (flags->zero_len)
12148 			payload_len = 0;
12149 again:
12150 		ret = test_tls_record_td_prepare(sec_alg_list[i].param1, sec_alg_list[i].param2,
12151 						 flags, td_outb, nb_pkts, payload_len);
12152 		if (ret == TEST_SKIPPED)
12153 			continue;
12154 
12155 		ret = test_tls_record_proto_process(td_outb, td_inb, nb_pkts, true, flags);
12156 		if (ret == TEST_SKIPPED)
12157 			continue;
12158 
12159 		if (flags->zero_len &&
12160 		    ((flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE) ||
12161 		    (flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE) ||
12162 		    (flags->content_type == TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE))) {
12163 			if (ret == TEST_SUCCESS)
12164 				return TEST_FAILED;
12165 			goto skip_decrypt;
12166 		} else if (ret == TEST_FAILED) {
12167 			return TEST_FAILED;
12168 		}
12169 
12170 		test_tls_record_td_update(td_inb, td_outb, nb_pkts, flags);
12171 
12172 		ret = test_tls_record_proto_process(td_inb, NULL, nb_pkts, true, flags);
12173 		if (ret == TEST_SKIPPED)
12174 			continue;
12175 
12176 		if (flags->pkt_corruption || flags->padding_corruption) {
12177 			if (ret == TEST_SUCCESS)
12178 				return TEST_FAILED;
12179 		} else {
12180 			if (ret == TEST_FAILED)
12181 				return TEST_FAILED;
12182 		}
12183 
12184 skip_decrypt:
12185 		if (flags->data_walkthrough && (++payload_len <= max_payload_len))
12186 			goto again;
12187 
12188 		if (flags->display_alg)
12189 			test_sec_alg_display(sec_alg_list[i].param1, sec_alg_list[i].param2);
12190 
12191 		pass_cnt++;
12192 	}
12193 
12194 	if (pass_cnt > 0)
12195 		return TEST_SUCCESS;
12196 	else
12197 		return TEST_SKIPPED;
12198 }
12199 
12200 static int
12201 test_tls_1_2_record_proto_data_walkthrough(void)
12202 {
12203 	struct tls_record_test_flags flags;
12204 
12205 	memset(&flags, 0, sizeof(flags));
12206 
12207 	flags.data_walkthrough = true;
12208 	flags.tls_version = RTE_SECURITY_VERSION_TLS_1_2;
12209 
12210 	return test_tls_record_proto_all(&flags);
12211 }
12212 
12213 static int
12214 test_tls_1_2_record_proto_display_list(void)
12215 {
12216 	struct tls_record_test_flags flags;
12217 
12218 	memset(&flags, 0, sizeof(flags));
12219 
12220 	flags.display_alg = true;
12221 	flags.tls_version = RTE_SECURITY_VERSION_TLS_1_2;
12222 
12223 	return test_tls_record_proto_all(&flags);
12224 }
12225 
12226 static int
12227 test_tls_1_2_record_proto_sgl(void)
12228 {
12229 	struct tls_record_test_flags flags = {
12230 		.nb_segs_in_mbuf = 5,
12231 		.tls_version = RTE_SECURITY_VERSION_TLS_1_2
12232 	};
12233 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12234 	struct rte_cryptodev_info dev_info;
12235 
12236 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12237 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
12238 		printf("Device doesn't support in-place scatter-gather. Test Skipped.\n");
12239 		return TEST_SKIPPED;
12240 	}
12241 
12242 	return test_tls_record_proto_all(&flags);
12243 }
12244 
12245 static int
12246 test_tls_record_proto_sgl_data_walkthrough(enum rte_security_tls_version tls_version)
12247 {
12248 	struct tls_record_test_flags flags = {
12249 		.nb_segs_in_mbuf = 5,
12250 		.tls_version = tls_version,
12251 		.data_walkthrough = true
12252 	};
12253 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12254 	struct rte_cryptodev_info dev_info;
12255 
12256 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12257 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
12258 		printf("Device doesn't support in-place scatter-gather. Test Skipped.\n");
12259 		return TEST_SKIPPED;
12260 	}
12261 
12262 	return test_tls_record_proto_all(&flags);
12263 }
12264 
12265 static int
12266 test_tls_record_proto_sgl_oop(enum rte_security_tls_version tls_version)
12267 {
12268 	struct tls_record_test_flags flags = {
12269 		.nb_segs_in_mbuf = 5,
12270 		.out_of_place = true,
12271 		.tls_version = tls_version
12272 	};
12273 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12274 	struct rte_cryptodev_info dev_info;
12275 
12276 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12277 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
12278 		printf("Device doesn't support in-place scatter-gather. Test Skipped.\n");
12279 		return TEST_SKIPPED;
12280 	}
12281 
12282 	return test_tls_record_proto_all(&flags);
12283 }
12284 
12285 static int
12286 test_tls_1_2_record_proto_sgl_oop(void)
12287 {
12288 	return test_tls_record_proto_sgl_oop(RTE_SECURITY_VERSION_TLS_1_2);
12289 }
12290 
12291 static int
12292 test_tls_1_2_record_proto_sgl_data_walkthrough(void)
12293 {
12294 	return test_tls_record_proto_sgl_data_walkthrough(RTE_SECURITY_VERSION_TLS_1_2);
12295 }
12296 
12297 static int
12298 test_tls_record_proto_corrupt_pkt(void)
12299 {
12300 	struct tls_record_test_flags flags = {
12301 		.pkt_corruption = 1
12302 	};
12303 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12304 	struct rte_cryptodev_info dev_info;
12305 
12306 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12307 
12308 	return test_tls_record_proto_all(&flags);
12309 }
12310 
12311 static int
12312 test_tls_record_proto_custom_content_type(void)
12313 {
12314 	struct tls_record_test_flags flags = {
12315 		.content_type = TLS_RECORD_TEST_CONTENT_TYPE_CUSTOM
12316 	};
12317 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12318 	struct rte_cryptodev_info dev_info;
12319 
12320 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12321 
12322 	return test_tls_record_proto_all(&flags);
12323 }
12324 
12325 static int
12326 test_tls_record_proto_zero_len(void)
12327 {
12328 	struct tls_record_test_flags flags = {
12329 		.zero_len = 1
12330 	};
12331 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12332 	struct rte_cryptodev_info dev_info;
12333 
12334 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12335 
12336 	return test_tls_record_proto_all(&flags);
12337 }
12338 
12339 static int
12340 test_tls_record_proto_zero_len_non_app(void)
12341 {
12342 	struct tls_record_test_flags flags = {
12343 		.zero_len = 1,
12344 		.content_type = TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE,
12345 	};
12346 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12347 	struct rte_cryptodev_info dev_info;
12348 
12349 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12350 
12351 	return test_tls_record_proto_all(&flags);
12352 }
12353 
12354 static int
12355 test_tls_record_proto_opt_padding(uint8_t padding, uint8_t num_segs,
12356 				  enum rte_security_tls_version tls_version)
12357 {
12358 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12359 	struct rte_cryptodev_info dev_info;
12360 	struct tls_record_test_flags flags = {
12361 		.nb_segs_in_mbuf = num_segs,
12362 		.tls_version = tls_version,
12363 		.opt_padding = padding
12364 	};
12365 
12366 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12367 
12368 	return test_tls_record_proto_all(&flags);
12369 }
12370 
12371 static int
12372 test_tls_record_proto_dm_opt_padding(void)
12373 {
12374 	return test_tls_record_proto_opt_padding(1, 0, RTE_SECURITY_VERSION_TLS_1_2);
12375 }
12376 
12377 static int
12378 test_tls_record_proto_dm_opt_padding_1(void)
12379 {
12380 	return test_tls_record_proto_opt_padding(25, 0, RTE_SECURITY_VERSION_TLS_1_2);
12381 }
12382 
12383 static int
12384 test_tls_record_proto_sg_opt_padding(void)
12385 {
12386 	return test_tls_record_proto_opt_padding(1, 2, RTE_SECURITY_VERSION_TLS_1_2);
12387 }
12388 
12389 static int
12390 test_tls_record_proto_sg_opt_padding_1(void)
12391 {
12392 	return test_tls_record_proto_opt_padding(8, 4, RTE_SECURITY_VERSION_TLS_1_2);
12393 }
12394 
12395 static int
12396 test_tls_record_proto_sg_opt_padding_2(void)
12397 {
12398 	return test_tls_record_proto_opt_padding(8, 5, RTE_SECURITY_VERSION_TLS_1_2);
12399 }
12400 
12401 static int
12402 test_tls_record_proto_sg_opt_padding_max(void)
12403 {
12404 	return test_tls_record_proto_opt_padding(33, 4, RTE_SECURITY_VERSION_TLS_1_2);
12405 }
12406 
12407 static int
12408 test_tls_record_proto_sg_opt_padding_corrupt(void)
12409 {
12410 	struct tls_record_test_flags flags = {
12411 		.opt_padding = 8,
12412 		.padding_corruption = true,
12413 		.nb_segs_in_mbuf = 4,
12414 	};
12415 
12416 	return test_tls_record_proto_all(&flags);
12417 }
12418 
12419 static int
12420 test_dtls_1_2_record_proto_data_walkthrough(void)
12421 {
12422 	struct tls_record_test_flags flags;
12423 
12424 	memset(&flags, 0, sizeof(flags));
12425 
12426 	flags.data_walkthrough = true;
12427 	flags.tls_version = RTE_SECURITY_VERSION_DTLS_1_2;
12428 
12429 	return test_tls_record_proto_all(&flags);
12430 }
12431 
12432 static int
12433 test_dtls_1_2_record_proto_display_list(void)
12434 {
12435 	struct tls_record_test_flags flags;
12436 
12437 	memset(&flags, 0, sizeof(flags));
12438 
12439 	flags.display_alg = true;
12440 	flags.tls_version = RTE_SECURITY_VERSION_DTLS_1_2;
12441 
12442 	return test_tls_record_proto_all(&flags);
12443 }
12444 
12445 static int
12446 test_dtls_pkt_replay(const uint64_t seq_no[],
12447 		      bool replayed_pkt[], uint32_t nb_pkts,
12448 		      struct tls_record_test_flags *flags)
12449 {
12450 	struct tls_record_test_data td_outb[TEST_SEC_PKTS_MAX];
12451 	struct tls_record_test_data td_inb[TEST_SEC_PKTS_MAX];
12452 	unsigned int i, idx, pass_cnt = 0;
12453 	int ret;
12454 
12455 	for (i = 0; i < RTE_DIM(sec_alg_list); i++) {
12456 		ret = test_tls_record_td_prepare(sec_alg_list[i].param1, sec_alg_list[i].param2,
12457 						 flags, td_outb, nb_pkts, 0);
12458 		if (ret == TEST_SKIPPED)
12459 			continue;
12460 
12461 		for (idx = 0; idx < nb_pkts; idx++)
12462 			td_outb[idx].tls_record_xform.dtls_1_2.seq_no = seq_no[idx];
12463 
12464 		ret = test_tls_record_proto_process(td_outb, td_inb, nb_pkts, true, flags);
12465 		if (ret == TEST_SKIPPED)
12466 			continue;
12467 
12468 		if (ret == TEST_FAILED)
12469 			return TEST_FAILED;
12470 
12471 		test_tls_record_td_update(td_inb, td_outb, nb_pkts, flags);
12472 
12473 		for (idx = 0; idx < nb_pkts; idx++) {
12474 			td_inb[idx].tls_record_xform.dtls_1_2.ar_win_sz = flags->ar_win_size;
12475 			/* Set antireplay flag for packets to be dropped */
12476 			td_inb[idx].ar_packet = replayed_pkt[idx];
12477 		}
12478 
12479 		ret = test_tls_record_proto_process(td_inb, NULL, nb_pkts, true, flags);
12480 		if (ret == TEST_SKIPPED)
12481 			continue;
12482 
12483 		if (ret == TEST_FAILED)
12484 			return TEST_FAILED;
12485 
12486 		if (flags->display_alg)
12487 			test_sec_alg_display(sec_alg_list[i].param1, sec_alg_list[i].param2);
12488 
12489 		pass_cnt++;
12490 	}
12491 
12492 	if (pass_cnt > 0)
12493 		return TEST_SUCCESS;
12494 	else
12495 		return TEST_SKIPPED;
12496 }
12497 
12498 static int
12499 test_dtls_1_2_record_proto_antireplay(uint64_t winsz)
12500 {
12501 	struct tls_record_test_flags flags;
12502 	uint32_t nb_pkts = 5;
12503 	bool replayed_pkt[5];
12504 	uint64_t seq_no[5];
12505 
12506 	memset(&flags, 0, sizeof(flags));
12507 
12508 	flags.tls_version = RTE_SECURITY_VERSION_DTLS_1_2;
12509 	flags.ar_win_size = winsz;
12510 
12511 	/* 1. Advance the TOP of the window to WS * 2 */
12512 	seq_no[0] = winsz * 2;
12513 	/* 2. Test sequence number within the new window(WS + 1) */
12514 	seq_no[1] = winsz + 1;
12515 	/* 3. Test sequence number less than the window BOTTOM */
12516 	seq_no[2] = winsz;
12517 	/* 4. Test sequence number in the middle of the window */
12518 	seq_no[3] = winsz + (winsz / 2);
12519 	/* 5. Test replay of the packet in the middle of the window */
12520 	seq_no[4] = winsz + (winsz / 2);
12521 
12522 	replayed_pkt[0] = false;
12523 	replayed_pkt[1] = false;
12524 	replayed_pkt[2] = true;
12525 	replayed_pkt[3] = false;
12526 	replayed_pkt[4] = true;
12527 
12528 	return test_dtls_pkt_replay(seq_no, replayed_pkt, nb_pkts, &flags);
12529 }
12530 
12531 static int
12532 test_dtls_1_2_record_proto_antireplay64(void)
12533 {
12534 	return test_dtls_1_2_record_proto_antireplay(64);
12535 }
12536 
12537 static int
12538 test_dtls_1_2_record_proto_antireplay128(void)
12539 {
12540 	return test_dtls_1_2_record_proto_antireplay(128);
12541 }
12542 
12543 static int
12544 test_dtls_1_2_record_proto_antireplay256(void)
12545 {
12546 	return test_dtls_1_2_record_proto_antireplay(256);
12547 }
12548 
12549 static int
12550 test_dtls_1_2_record_proto_antireplay512(void)
12551 {
12552 	return test_dtls_1_2_record_proto_antireplay(512);
12553 }
12554 
12555 static int
12556 test_dtls_1_2_record_proto_antireplay1024(void)
12557 {
12558 	return test_dtls_1_2_record_proto_antireplay(1024);
12559 }
12560 
12561 static int
12562 test_dtls_1_2_record_proto_antireplay2048(void)
12563 {
12564 	return test_dtls_1_2_record_proto_antireplay(2048);
12565 }
12566 
12567 static int
12568 test_dtls_1_2_record_proto_antireplay4096(void)
12569 {
12570 	return test_dtls_1_2_record_proto_antireplay(4096);
12571 }
12572 
12573 static int
12574 test_dtls_1_2_record_proto_sgl(void)
12575 {
12576 	struct tls_record_test_flags flags = {
12577 		.nb_segs_in_mbuf = 5,
12578 		.tls_version = RTE_SECURITY_VERSION_DTLS_1_2
12579 	};
12580 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12581 	struct rte_cryptodev_info dev_info;
12582 
12583 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12584 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
12585 		printf("Device doesn't support in-place scatter-gather. Test Skipped.\n");
12586 		return TEST_SKIPPED;
12587 	}
12588 
12589 	return test_tls_record_proto_all(&flags);
12590 }
12591 
12592 static int
12593 test_dtls_1_2_record_proto_sgl_data_walkthrough(void)
12594 {
12595 	return test_tls_record_proto_sgl_data_walkthrough(RTE_SECURITY_VERSION_DTLS_1_2);
12596 }
12597 
12598 static int
12599 test_dtls_1_2_record_proto_corrupt_pkt(void)
12600 {
12601 	struct tls_record_test_flags flags = {
12602 		.pkt_corruption = 1,
12603 		.tls_version = RTE_SECURITY_VERSION_DTLS_1_2
12604 	};
12605 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12606 	struct rte_cryptodev_info dev_info;
12607 
12608 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12609 
12610 	return test_tls_record_proto_all(&flags);
12611 }
12612 
12613 static int
12614 test_dtls_1_2_record_proto_custom_content_type(void)
12615 {
12616 	struct tls_record_test_flags flags = {
12617 		.content_type = TLS_RECORD_TEST_CONTENT_TYPE_CUSTOM,
12618 		.tls_version = RTE_SECURITY_VERSION_DTLS_1_2
12619 	};
12620 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12621 	struct rte_cryptodev_info dev_info;
12622 
12623 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12624 
12625 	return test_tls_record_proto_all(&flags);
12626 }
12627 
12628 static int
12629 test_dtls_1_2_record_proto_zero_len(void)
12630 {
12631 	struct tls_record_test_flags flags = {
12632 		.zero_len = 1,
12633 		.tls_version = RTE_SECURITY_VERSION_DTLS_1_2
12634 	};
12635 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12636 	struct rte_cryptodev_info dev_info;
12637 
12638 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12639 
12640 	return test_tls_record_proto_all(&flags);
12641 }
12642 
12643 static int
12644 test_dtls_1_2_record_proto_zero_len_non_app(void)
12645 {
12646 	struct tls_record_test_flags flags = {
12647 		.zero_len = 1,
12648 		.content_type = TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE,
12649 		.tls_version = RTE_SECURITY_VERSION_DTLS_1_2
12650 	};
12651 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12652 	struct rte_cryptodev_info dev_info;
12653 
12654 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12655 
12656 	return test_tls_record_proto_all(&flags);
12657 }
12658 
12659 static int
12660 test_dtls_1_2_record_proto_dm_opt_padding(void)
12661 {
12662 	return test_tls_record_proto_opt_padding(1, 0, RTE_SECURITY_VERSION_DTLS_1_2);
12663 }
12664 
12665 static int
12666 test_dtls_1_2_record_proto_dm_opt_padding_1(void)
12667 {
12668 	return test_tls_record_proto_opt_padding(25, 0, RTE_SECURITY_VERSION_DTLS_1_2);
12669 }
12670 
12671 static int
12672 test_dtls_1_2_record_proto_sg_opt_padding(void)
12673 {
12674 	return test_tls_record_proto_opt_padding(1, 5, RTE_SECURITY_VERSION_DTLS_1_2);
12675 }
12676 
12677 static int
12678 test_dtls_1_2_record_proto_sg_opt_padding_1(void)
12679 {
12680 	return test_tls_record_proto_opt_padding(8, 4, RTE_SECURITY_VERSION_DTLS_1_2);
12681 }
12682 
12683 static int
12684 test_dtls_1_2_record_proto_sg_opt_padding_2(void)
12685 {
12686 	return test_tls_record_proto_opt_padding(8, 5, RTE_SECURITY_VERSION_DTLS_1_2);
12687 }
12688 
12689 static int
12690 test_dtls_1_2_record_proto_sg_opt_padding_max(void)
12691 {
12692 	return test_tls_record_proto_opt_padding(33, 4, RTE_SECURITY_VERSION_DTLS_1_2);
12693 }
12694 
12695 static int
12696 test_tls_1_3_record_proto_display_list(void)
12697 {
12698 	struct tls_record_test_flags flags;
12699 
12700 	memset(&flags, 0, sizeof(flags));
12701 
12702 	flags.display_alg = true;
12703 	flags.tls_version = RTE_SECURITY_VERSION_TLS_1_3;
12704 
12705 	return test_tls_record_proto_all(&flags);
12706 }
12707 
12708 static int
12709 test_dtls_1_2_record_proto_sg_opt_padding_corrupt(void)
12710 {
12711 	struct tls_record_test_flags flags = {
12712 		.opt_padding = 8,
12713 		.padding_corruption = true,
12714 		.nb_segs_in_mbuf = 4,
12715 		.tls_version = RTE_SECURITY_VERSION_DTLS_1_2
12716 	};
12717 
12718 	return test_tls_record_proto_all(&flags);
12719 }
12720 
12721 static int
12722 test_tls_1_3_record_proto_corrupt_pkt(void)
12723 {
12724 	struct tls_record_test_flags flags = {
12725 		.pkt_corruption = 1,
12726 		.tls_version = RTE_SECURITY_VERSION_TLS_1_3
12727 	};
12728 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12729 	struct rte_cryptodev_info dev_info;
12730 
12731 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12732 
12733 	return test_tls_record_proto_all(&flags);
12734 }
12735 
12736 static int
12737 test_tls_1_3_record_proto_custom_content_type(void)
12738 {
12739 	struct tls_record_test_flags flags = {
12740 		.content_type = TLS_RECORD_TEST_CONTENT_TYPE_CUSTOM,
12741 		.tls_version = RTE_SECURITY_VERSION_TLS_1_3
12742 	};
12743 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12744 	struct rte_cryptodev_info dev_info;
12745 
12746 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12747 
12748 	return test_tls_record_proto_all(&flags);
12749 }
12750 
12751 static int
12752 test_tls_1_3_record_proto_zero_len(void)
12753 {
12754 	struct tls_record_test_flags flags = {
12755 		.zero_len = 1,
12756 		.tls_version = RTE_SECURITY_VERSION_TLS_1_3
12757 	};
12758 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12759 	struct rte_cryptodev_info dev_info;
12760 
12761 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12762 
12763 	return test_tls_record_proto_all(&flags);
12764 }
12765 
12766 static int
12767 test_tls_1_3_record_proto_zero_len_non_app(void)
12768 {
12769 	struct tls_record_test_flags flags = {
12770 		.zero_len = 1,
12771 		.content_type = TLS_RECORD_TEST_CONTENT_TYPE_HANDSHAKE,
12772 		.tls_version = RTE_SECURITY_VERSION_TLS_1_3
12773 	};
12774 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12775 	struct rte_cryptodev_info dev_info;
12776 
12777 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12778 
12779 	return test_tls_record_proto_all(&flags);
12780 }
12781 
12782 static int
12783 test_tls_1_3_record_proto_dm_opt_padding(void)
12784 {
12785 	return test_tls_record_proto_opt_padding(6, 0, RTE_SECURITY_VERSION_TLS_1_3);
12786 }
12787 
12788 static int
12789 test_tls_1_3_record_proto_sg_opt_padding(void)
12790 {
12791 	return test_tls_record_proto_opt_padding(25, 5, RTE_SECURITY_VERSION_TLS_1_3);
12792 }
12793 
12794 static int
12795 test_tls_1_3_record_proto_sg_opt_padding_1(void)
12796 {
12797 	return test_tls_record_proto_opt_padding(25, 4, RTE_SECURITY_VERSION_TLS_1_3);
12798 }
12799 
12800 static int
12801 test_tls_1_3_record_proto_data_walkthrough(void)
12802 {
12803 	struct tls_record_test_flags flags;
12804 
12805 	memset(&flags, 0, sizeof(flags));
12806 
12807 	flags.data_walkthrough = true;
12808 	flags.tls_version = RTE_SECURITY_VERSION_TLS_1_3;
12809 
12810 	return test_tls_record_proto_all(&flags);
12811 }
12812 
12813 static int
12814 test_tls_1_3_record_proto_sgl_data_walkthrough(void)
12815 {
12816 	struct tls_record_test_flags flags = {
12817 		.nb_segs_in_mbuf = 5,
12818 		.tls_version = RTE_SECURITY_VERSION_TLS_1_3,
12819 		.data_walkthrough = true
12820 	};
12821 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12822 	struct rte_cryptodev_info dev_info;
12823 
12824 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12825 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
12826 		printf("Device doesn't support in-place scatter-gather. Test Skipped.\n");
12827 		return TEST_SKIPPED;
12828 	}
12829 
12830 	return test_tls_record_proto_all(&flags);
12831 }
12832 
12833 #endif
12834 
12835 static int
12836 test_AES_GCM_authenticated_encryption_test_case_1(void)
12837 {
12838 	return test_authenticated_encryption(&gcm_test_case_1);
12839 }
12840 
12841 static int
12842 test_AES_GCM_authenticated_encryption_test_case_2(void)
12843 {
12844 	return test_authenticated_encryption(&gcm_test_case_2);
12845 }
12846 
12847 static int
12848 test_AES_GCM_authenticated_encryption_test_case_3(void)
12849 {
12850 	return test_authenticated_encryption(&gcm_test_case_3);
12851 }
12852 
12853 static int
12854 test_AES_GCM_authenticated_encryption_test_case_3_ext_mbuf(void)
12855 {
12856 	return test_authenticated_encryption_helper(&gcm_test_case_3, true);
12857 }
12858 
12859 static int
12860 test_AES_GCM_authenticated_encryption_test_case_4(void)
12861 {
12862 	return test_authenticated_encryption(&gcm_test_case_4);
12863 }
12864 
12865 static int
12866 test_AES_GCM_authenticated_encryption_test_case_5(void)
12867 {
12868 	return test_authenticated_encryption(&gcm_test_case_5);
12869 }
12870 
12871 static int
12872 test_AES_GCM_authenticated_encryption_test_case_6(void)
12873 {
12874 	return test_authenticated_encryption(&gcm_test_case_6);
12875 }
12876 
12877 static int
12878 test_AES_GCM_authenticated_encryption_test_case_7(void)
12879 {
12880 	return test_authenticated_encryption(&gcm_test_case_7);
12881 }
12882 
12883 static int
12884 test_AES_GCM_authenticated_encryption_test_case_8(void)
12885 {
12886 	return test_authenticated_encryption(&gcm_test_case_8);
12887 }
12888 
12889 static int
12890 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
12891 {
12892 	return test_authenticated_encryption(&gcm_J0_test_case_1);
12893 }
12894 
12895 static int
12896 test_AES_GCM_auth_encryption_test_case_192_1(void)
12897 {
12898 	return test_authenticated_encryption(&gcm_test_case_192_1);
12899 }
12900 
12901 static int
12902 test_AES_GCM_auth_encryption_test_case_192_2(void)
12903 {
12904 	return test_authenticated_encryption(&gcm_test_case_192_2);
12905 }
12906 
12907 static int
12908 test_AES_GCM_auth_encryption_test_case_192_3(void)
12909 {
12910 	return test_authenticated_encryption(&gcm_test_case_192_3);
12911 }
12912 
12913 static int
12914 test_AES_GCM_auth_encryption_test_case_192_4(void)
12915 {
12916 	return test_authenticated_encryption(&gcm_test_case_192_4);
12917 }
12918 
12919 static int
12920 test_AES_GCM_auth_encryption_test_case_192_5(void)
12921 {
12922 	return test_authenticated_encryption(&gcm_test_case_192_5);
12923 }
12924 
12925 static int
12926 test_AES_GCM_auth_encryption_test_case_192_6(void)
12927 {
12928 	return test_authenticated_encryption(&gcm_test_case_192_6);
12929 }
12930 
12931 static int
12932 test_AES_GCM_auth_encryption_test_case_192_7(void)
12933 {
12934 	return test_authenticated_encryption(&gcm_test_case_192_7);
12935 }
12936 
12937 static int
12938 test_AES_GCM_auth_encryption_test_case_256_1(void)
12939 {
12940 	return test_authenticated_encryption(&gcm_test_case_256_1);
12941 }
12942 
12943 static int
12944 test_AES_GCM_auth_encryption_test_case_256_2(void)
12945 {
12946 	return test_authenticated_encryption(&gcm_test_case_256_2);
12947 }
12948 
12949 static int
12950 test_AES_GCM_auth_encryption_test_case_256_3(void)
12951 {
12952 	return test_authenticated_encryption(&gcm_test_case_256_3);
12953 }
12954 
12955 static int
12956 test_AES_GCM_auth_encryption_test_case_256_4(void)
12957 {
12958 	return test_authenticated_encryption(&gcm_test_case_256_4);
12959 }
12960 
12961 static int
12962 test_AES_GCM_auth_encryption_test_case_256_5(void)
12963 {
12964 	return test_authenticated_encryption(&gcm_test_case_256_5);
12965 }
12966 
12967 static int
12968 test_AES_GCM_auth_encryption_test_case_256_6(void)
12969 {
12970 	return test_authenticated_encryption(&gcm_test_case_256_6);
12971 }
12972 
12973 static int
12974 test_AES_GCM_auth_encryption_test_case_256_7(void)
12975 {
12976 	return test_authenticated_encryption(&gcm_test_case_256_7);
12977 }
12978 
12979 static int
12980 test_AES_GCM_auth_encryption_test_case_aad_1(void)
12981 {
12982 	return test_authenticated_encryption(&gcm_test_case_aad_1);
12983 }
12984 
12985 static int
12986 test_AES_GCM_auth_encryption_test_case_aad_2(void)
12987 {
12988 	return test_authenticated_encryption(&gcm_test_case_aad_2);
12989 }
12990 
12991 static int
12992 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
12993 {
12994 	struct aead_test_data tdata;
12995 	int res;
12996 
12997 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
12998 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
12999 	tdata.iv.data[0] += 1;
13000 	res = test_authenticated_encryption(&tdata);
13001 	if (res == TEST_SKIPPED)
13002 		return res;
13003 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
13004 	return TEST_SUCCESS;
13005 }
13006 
13007 static int
13008 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
13009 {
13010 	struct aead_test_data tdata;
13011 	int res;
13012 
13013 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
13014 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
13015 	tdata.plaintext.data[0] += 1;
13016 	res = test_authenticated_encryption(&tdata);
13017 	if (res == TEST_SKIPPED)
13018 		return res;
13019 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
13020 	return TEST_SUCCESS;
13021 }
13022 
13023 static int
13024 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
13025 {
13026 	struct aead_test_data tdata;
13027 	int res;
13028 
13029 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
13030 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
13031 	tdata.ciphertext.data[0] += 1;
13032 	res = test_authenticated_encryption(&tdata);
13033 	if (res == TEST_SKIPPED)
13034 		return res;
13035 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
13036 	return TEST_SUCCESS;
13037 }
13038 
13039 static int
13040 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
13041 {
13042 	struct aead_test_data tdata;
13043 	int res;
13044 
13045 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
13046 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
13047 	tdata.aad.len += 1;
13048 	res = test_authenticated_encryption(&tdata);
13049 	if (res == TEST_SKIPPED)
13050 		return res;
13051 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
13052 	return TEST_SUCCESS;
13053 }
13054 
13055 static int
13056 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
13057 {
13058 	struct aead_test_data tdata;
13059 	uint8_t aad[gcm_test_case_7.aad.len];
13060 	int res;
13061 
13062 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
13063 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
13064 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
13065 	aad[0] += 1;
13066 	tdata.aad.data = aad;
13067 	res = test_authenticated_encryption(&tdata);
13068 	if (res == TEST_SKIPPED)
13069 		return res;
13070 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
13071 	return TEST_SUCCESS;
13072 }
13073 
13074 static int
13075 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
13076 {
13077 	struct aead_test_data tdata;
13078 	int res;
13079 
13080 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
13081 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
13082 	tdata.auth_tag.data[0] += 1;
13083 	res = test_authenticated_encryption(&tdata);
13084 	if (res == TEST_SKIPPED)
13085 		return res;
13086 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
13087 	return TEST_SUCCESS;
13088 }
13089 
13090 static int
13091 test_authenticated_decryption_helper(const struct aead_test_data *tdata, bool use_ext_mbuf)
13092 {
13093 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13094 	struct crypto_unittest_params *ut_params = &unittest_params;
13095 
13096 	int retval;
13097 	uint8_t *plaintext;
13098 	uint32_t i;
13099 	struct rte_cryptodev_info dev_info;
13100 
13101 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13102 	uint64_t feat_flags = dev_info.feature_flags;
13103 
13104 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13105 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13106 		printf("Device doesn't support RAW data-path APIs.\n");
13107 		return TEST_SKIPPED;
13108 	}
13109 
13110 	/* Verify the capabilities */
13111 	struct rte_cryptodev_sym_capability_idx cap_idx;
13112 	const struct rte_cryptodev_symmetric_capability *capability;
13113 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
13114 	cap_idx.algo.aead = tdata->algo;
13115 	capability = rte_cryptodev_sym_capability_get(
13116 			ts_params->valid_devs[0], &cap_idx);
13117 	if (capability == NULL)
13118 		return TEST_SKIPPED;
13119 	if (rte_cryptodev_sym_capability_check_aead(
13120 			capability, tdata->key.len, tdata->auth_tag.len,
13121 			tdata->aad.len, tdata->iv.len))
13122 		return TEST_SKIPPED;
13123 
13124 	/* Create AEAD session */
13125 	retval = create_aead_session(ts_params->valid_devs[0],
13126 			tdata->algo,
13127 			RTE_CRYPTO_AEAD_OP_DECRYPT,
13128 			tdata->key.data, tdata->key.len,
13129 			tdata->aad.len, tdata->auth_tag.len,
13130 			tdata->iv.len);
13131 	if (retval != TEST_SUCCESS)
13132 		return retval;
13133 
13134 	/* alloc mbuf and set payload */
13135 	if (tdata->aad.len > MBUF_SIZE) {
13136 		if (use_ext_mbuf) {
13137 			ut_params->ibuf = ext_mbuf_create(ts_params->large_mbuf_pool,
13138 							  AEAD_TEXT_MAX_LENGTH,
13139 							  1 /* nb_segs */,
13140 							  NULL);
13141 		} else {
13142 			ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
13143 		}
13144 		/* Populate full size of add data */
13145 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
13146 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
13147 	} else {
13148 		if (use_ext_mbuf) {
13149 			ut_params->ibuf = ext_mbuf_create(ts_params->mbuf_pool,
13150 							  AEAD_TEXT_MAX_LENGTH,
13151 							  1 /* nb_segs */,
13152 							  NULL);
13153 		} else {
13154 			ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13155 		}
13156 	}
13157 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13158 			rte_pktmbuf_tailroom(ut_params->ibuf));
13159 
13160 	/* Create AEAD operation */
13161 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
13162 	if (retval < 0)
13163 		return retval;
13164 
13165 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13166 
13167 	ut_params->op->sym->m_src = ut_params->ibuf;
13168 
13169 	/* Process crypto operation */
13170 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13171 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
13172 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
13173 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0,
13174 					       0);
13175 		if (retval != TEST_SUCCESS)
13176 			return retval;
13177 	} else
13178 		TEST_ASSERT_NOT_NULL(
13179 			process_crypto_request(ts_params->valid_devs[0],
13180 			ut_params->op), "failed to process sym crypto op");
13181 
13182 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13183 			"crypto op processing failed");
13184 
13185 	if (ut_params->op->sym->m_dst)
13186 		plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
13187 				uint8_t *);
13188 	else
13189 		plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
13190 				uint8_t *,
13191 				ut_params->op->sym->cipher.data.offset);
13192 
13193 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
13194 
13195 	/* Validate obuf */
13196 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13197 			plaintext,
13198 			tdata->plaintext.data,
13199 			tdata->plaintext.len,
13200 			"Plaintext data not as expected");
13201 
13202 	TEST_ASSERT_EQUAL(ut_params->op->status,
13203 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13204 			"Authentication failed");
13205 
13206 	return 0;
13207 }
13208 
13209 static int
13210 test_authenticated_decryption(const struct aead_test_data *tdata)
13211 {
13212 	return test_authenticated_decryption_helper(tdata, false);
13213 }
13214 
13215 static int
13216 test_AES_GCM_authenticated_decryption_test_case_1(void)
13217 {
13218 	return test_authenticated_decryption(&gcm_test_case_1);
13219 }
13220 
13221 static int
13222 test_AES_GCM_authenticated_decryption_test_case_2(void)
13223 {
13224 	return test_authenticated_decryption(&gcm_test_case_2);
13225 }
13226 
13227 static int
13228 test_AES_GCM_authenticated_decryption_test_case_3(void)
13229 {
13230 	return test_authenticated_decryption(&gcm_test_case_3);
13231 }
13232 
13233 static int
13234 test_AES_GCM_authenticated_decryption_test_case_3_ext_mbuf(void)
13235 {
13236 	return test_authenticated_decryption_helper(&gcm_test_case_3, true);
13237 }
13238 
13239 static int
13240 test_AES_GCM_authenticated_decryption_test_case_4(void)
13241 {
13242 	return test_authenticated_decryption(&gcm_test_case_4);
13243 }
13244 
13245 static int
13246 test_AES_GCM_authenticated_decryption_test_case_5(void)
13247 {
13248 	return test_authenticated_decryption(&gcm_test_case_5);
13249 }
13250 
13251 static int
13252 test_AES_GCM_authenticated_decryption_test_case_6(void)
13253 {
13254 	return test_authenticated_decryption(&gcm_test_case_6);
13255 }
13256 
13257 static int
13258 test_AES_GCM_authenticated_decryption_test_case_7(void)
13259 {
13260 	return test_authenticated_decryption(&gcm_test_case_7);
13261 }
13262 
13263 static int
13264 test_AES_GCM_authenticated_decryption_test_case_8(void)
13265 {
13266 	return test_authenticated_decryption(&gcm_test_case_8);
13267 }
13268 
13269 static int
13270 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
13271 {
13272 	return test_authenticated_decryption(&gcm_J0_test_case_1);
13273 }
13274 
13275 static int
13276 test_AES_GCM_auth_decryption_test_case_192_1(void)
13277 {
13278 	return test_authenticated_decryption(&gcm_test_case_192_1);
13279 }
13280 
13281 static int
13282 test_AES_GCM_auth_decryption_test_case_192_2(void)
13283 {
13284 	return test_authenticated_decryption(&gcm_test_case_192_2);
13285 }
13286 
13287 static int
13288 test_AES_GCM_auth_decryption_test_case_192_3(void)
13289 {
13290 	return test_authenticated_decryption(&gcm_test_case_192_3);
13291 }
13292 
13293 static int
13294 test_AES_GCM_auth_decryption_test_case_192_4(void)
13295 {
13296 	return test_authenticated_decryption(&gcm_test_case_192_4);
13297 }
13298 
13299 static int
13300 test_AES_GCM_auth_decryption_test_case_192_5(void)
13301 {
13302 	return test_authenticated_decryption(&gcm_test_case_192_5);
13303 }
13304 
13305 static int
13306 test_AES_GCM_auth_decryption_test_case_192_6(void)
13307 {
13308 	return test_authenticated_decryption(&gcm_test_case_192_6);
13309 }
13310 
13311 static int
13312 test_AES_GCM_auth_decryption_test_case_192_7(void)
13313 {
13314 	return test_authenticated_decryption(&gcm_test_case_192_7);
13315 }
13316 
13317 static int
13318 test_AES_GCM_auth_decryption_test_case_256_1(void)
13319 {
13320 	return test_authenticated_decryption(&gcm_test_case_256_1);
13321 }
13322 
13323 static int
13324 test_AES_GCM_auth_decryption_test_case_256_2(void)
13325 {
13326 	return test_authenticated_decryption(&gcm_test_case_256_2);
13327 }
13328 
13329 static int
13330 test_AES_GCM_auth_decryption_test_case_256_3(void)
13331 {
13332 	return test_authenticated_decryption(&gcm_test_case_256_3);
13333 }
13334 
13335 static int
13336 test_AES_GCM_auth_decryption_test_case_256_4(void)
13337 {
13338 	return test_authenticated_decryption(&gcm_test_case_256_4);
13339 }
13340 
13341 static int
13342 test_AES_GCM_auth_decryption_test_case_256_5(void)
13343 {
13344 	return test_authenticated_decryption(&gcm_test_case_256_5);
13345 }
13346 
13347 static int
13348 test_AES_GCM_auth_decryption_test_case_256_6(void)
13349 {
13350 	return test_authenticated_decryption(&gcm_test_case_256_6);
13351 }
13352 
13353 static int
13354 test_AES_GCM_auth_decryption_test_case_256_7(void)
13355 {
13356 	return test_authenticated_decryption(&gcm_test_case_256_7);
13357 }
13358 
13359 static int
13360 test_AES_GCM_auth_decryption_test_case_256_8(void)
13361 {
13362 	return test_authenticated_decryption(&gcm_test_case_256_8);
13363 }
13364 
13365 static int
13366 test_AES_GCM_auth_encryption_test_case_256_8(void)
13367 {
13368 	return test_authenticated_encryption(&gcm_test_case_256_8);
13369 }
13370 
13371 static int
13372 test_AES_GCM_auth_decryption_test_case_aad_1(void)
13373 {
13374 	return test_authenticated_decryption(&gcm_test_case_aad_1);
13375 }
13376 
13377 static int
13378 test_AES_GCM_auth_decryption_test_case_aad_2(void)
13379 {
13380 	return test_authenticated_decryption(&gcm_test_case_aad_2);
13381 }
13382 
13383 static int
13384 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
13385 {
13386 	struct aead_test_data tdata;
13387 	int res;
13388 
13389 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
13390 	tdata.iv.data[0] += 1;
13391 	res = test_authenticated_decryption(&tdata);
13392 	if (res == TEST_SKIPPED)
13393 		return res;
13394 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
13395 	return TEST_SUCCESS;
13396 }
13397 
13398 static int
13399 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
13400 {
13401 	struct aead_test_data tdata;
13402 	int res;
13403 
13404 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
13405 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
13406 	tdata.plaintext.data[0] += 1;
13407 	res = test_authenticated_decryption(&tdata);
13408 	if (res == TEST_SKIPPED)
13409 		return res;
13410 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
13411 	return TEST_SUCCESS;
13412 }
13413 
13414 static int
13415 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
13416 {
13417 	struct aead_test_data tdata;
13418 	int res;
13419 
13420 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
13421 	tdata.ciphertext.data[0] += 1;
13422 	res = test_authenticated_decryption(&tdata);
13423 	if (res == TEST_SKIPPED)
13424 		return res;
13425 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
13426 	return TEST_SUCCESS;
13427 }
13428 
13429 static int
13430 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
13431 {
13432 	struct aead_test_data tdata;
13433 	int res;
13434 
13435 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
13436 	tdata.aad.len += 1;
13437 	res = test_authenticated_decryption(&tdata);
13438 	if (res == TEST_SKIPPED)
13439 		return res;
13440 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
13441 	return TEST_SUCCESS;
13442 }
13443 
13444 static int
13445 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
13446 {
13447 	struct aead_test_data tdata;
13448 	uint8_t aad[gcm_test_case_7.aad.len];
13449 	int res;
13450 
13451 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
13452 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
13453 	aad[0] += 1;
13454 	tdata.aad.data = aad;
13455 	res = test_authenticated_decryption(&tdata);
13456 	if (res == TEST_SKIPPED)
13457 		return res;
13458 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
13459 	return TEST_SUCCESS;
13460 }
13461 
13462 static int
13463 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
13464 {
13465 	struct aead_test_data tdata;
13466 	int res;
13467 
13468 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
13469 	tdata.auth_tag.data[0] += 1;
13470 	res = test_authenticated_decryption(&tdata);
13471 	if (res == TEST_SKIPPED)
13472 		return res;
13473 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
13474 	return TEST_SUCCESS;
13475 }
13476 
13477 static int
13478 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
13479 {
13480 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13481 	struct crypto_unittest_params *ut_params = &unittest_params;
13482 
13483 	int retval;
13484 	uint8_t *ciphertext, *auth_tag;
13485 	uint16_t plaintext_pad_len;
13486 	struct rte_cryptodev_info dev_info;
13487 
13488 	/* Verify the capabilities */
13489 	struct rte_cryptodev_sym_capability_idx cap_idx;
13490 	const struct rte_cryptodev_symmetric_capability *capability;
13491 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
13492 	cap_idx.algo.aead = tdata->algo;
13493 	capability = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], &cap_idx);
13494 	if (capability == NULL)
13495 		return TEST_SKIPPED;
13496 	if (rte_cryptodev_sym_capability_check_aead(
13497 		capability, tdata->key.len, tdata->auth_tag.len,
13498 		tdata->aad.len, tdata->iv.len))
13499 		return TEST_SKIPPED;
13500 
13501 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13502 	uint64_t feat_flags = dev_info.feature_flags;
13503 
13504 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13505 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP)))
13506 		return TEST_SKIPPED;
13507 
13508 	/* not supported with CPU crypto */
13509 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13510 		return TEST_SKIPPED;
13511 
13512 	/* Create AEAD session */
13513 	retval = create_aead_session(ts_params->valid_devs[0],
13514 			tdata->algo,
13515 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
13516 			tdata->key.data, tdata->key.len,
13517 			tdata->aad.len, tdata->auth_tag.len,
13518 			tdata->iv.len);
13519 	if (retval < 0)
13520 		return retval;
13521 
13522 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13523 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13524 
13525 	/* clear mbuf payload */
13526 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13527 			rte_pktmbuf_tailroom(ut_params->ibuf));
13528 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
13529 			rte_pktmbuf_tailroom(ut_params->obuf));
13530 
13531 	/* Create AEAD operation */
13532 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
13533 	if (retval < 0)
13534 		return retval;
13535 
13536 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13537 
13538 	ut_params->op->sym->m_src = ut_params->ibuf;
13539 	ut_params->op->sym->m_dst = ut_params->obuf;
13540 
13541 	/* Process crypto operation */
13542 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
13543 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0,
13544 					       0);
13545 		if (retval != TEST_SUCCESS)
13546 			return retval;
13547 	} else
13548 		TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
13549 			ut_params->op), "failed to process sym crypto op");
13550 
13551 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13552 			"crypto op processing failed");
13553 
13554 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
13555 
13556 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
13557 			ut_params->op->sym->cipher.data.offset);
13558 	auth_tag = ciphertext + plaintext_pad_len;
13559 
13560 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
13561 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
13562 
13563 	/* Validate obuf */
13564 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13565 			ciphertext,
13566 			tdata->ciphertext.data,
13567 			tdata->ciphertext.len,
13568 			"Ciphertext data not as expected");
13569 
13570 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13571 			auth_tag,
13572 			tdata->auth_tag.data,
13573 			tdata->auth_tag.len,
13574 			"Generated auth tag not as expected");
13575 
13576 	return 0;
13577 
13578 }
13579 
13580 static int
13581 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
13582 {
13583 	return test_authenticated_encryption_oop(&gcm_test_case_5);
13584 }
13585 
13586 static int
13587 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
13588 {
13589 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13590 	struct crypto_unittest_params *ut_params = &unittest_params;
13591 
13592 	int retval;
13593 	uint8_t *plaintext;
13594 	struct rte_cryptodev_info dev_info;
13595 
13596 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13597 	uint64_t feat_flags = dev_info.feature_flags;
13598 
13599 	/* Verify the capabilities */
13600 	struct rte_cryptodev_sym_capability_idx cap_idx;
13601 	const struct rte_cryptodev_symmetric_capability *capability;
13602 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
13603 	cap_idx.algo.aead = tdata->algo;
13604 	capability = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], &cap_idx);
13605 
13606 	if (capability == NULL)
13607 		return TEST_SKIPPED;
13608 
13609 	if (rte_cryptodev_sym_capability_check_aead(capability, tdata->key.len,
13610 			tdata->auth_tag.len, tdata->aad.len, tdata->iv.len))
13611 		return TEST_SKIPPED;
13612 
13613 	/* not supported with CPU crypto and raw data-path APIs*/
13614 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
13615 			global_api_test_type == CRYPTODEV_RAW_API_TEST)
13616 		return TEST_SKIPPED;
13617 
13618 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13619 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13620 		printf("Device does not support RAW data-path APIs.\n");
13621 		return TEST_SKIPPED;
13622 	}
13623 
13624 	/* Create AEAD session */
13625 	retval = create_aead_session(ts_params->valid_devs[0],
13626 			tdata->algo,
13627 			RTE_CRYPTO_AEAD_OP_DECRYPT,
13628 			tdata->key.data, tdata->key.len,
13629 			tdata->aad.len, tdata->auth_tag.len,
13630 			tdata->iv.len);
13631 	if (retval < 0)
13632 		return retval;
13633 
13634 	/* alloc mbuf and set payload */
13635 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13636 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13637 
13638 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13639 			rte_pktmbuf_tailroom(ut_params->ibuf));
13640 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
13641 			rte_pktmbuf_tailroom(ut_params->obuf));
13642 
13643 	/* Create AEAD operation */
13644 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
13645 	if (retval < 0)
13646 		return retval;
13647 
13648 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13649 
13650 	ut_params->op->sym->m_src = ut_params->ibuf;
13651 	ut_params->op->sym->m_dst = ut_params->obuf;
13652 
13653 	/* Process crypto operation */
13654 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
13655 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0,
13656 					       0);
13657 		if (retval != TEST_SUCCESS)
13658 			return retval;
13659 	} else
13660 		TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
13661 			ut_params->op), "failed to process sym crypto op");
13662 
13663 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13664 			"crypto op processing failed");
13665 
13666 	plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
13667 			ut_params->op->sym->cipher.data.offset);
13668 
13669 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
13670 
13671 	/* Validate obuf */
13672 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13673 			plaintext,
13674 			tdata->plaintext.data,
13675 			tdata->plaintext.len,
13676 			"Plaintext data not as expected");
13677 
13678 	TEST_ASSERT_EQUAL(ut_params->op->status,
13679 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13680 			"Authentication failed");
13681 	return 0;
13682 }
13683 
13684 static int
13685 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
13686 {
13687 	return test_authenticated_decryption_oop(&gcm_test_case_5);
13688 }
13689 
13690 static int
13691 test_authenticated_encryption_sessionless(
13692 		const struct aead_test_data *tdata)
13693 {
13694 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13695 	struct crypto_unittest_params *ut_params = &unittest_params;
13696 
13697 	int retval;
13698 	uint8_t *ciphertext, *auth_tag;
13699 	uint16_t plaintext_pad_len;
13700 	uint8_t key[tdata->key.len + 1];
13701 	struct rte_cryptodev_info dev_info;
13702 
13703 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13704 	uint64_t feat_flags = dev_info.feature_flags;
13705 
13706 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
13707 		printf("Device doesn't support Sessionless ops.\n");
13708 		return TEST_SKIPPED;
13709 	}
13710 
13711 	/* not supported with CPU crypto */
13712 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13713 		return TEST_SKIPPED;
13714 
13715 	/* Verify the capabilities */
13716 	struct rte_cryptodev_sym_capability_idx cap_idx;
13717 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
13718 	cap_idx.algo.aead = tdata->algo;
13719 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13720 			&cap_idx) == NULL)
13721 		return TEST_SKIPPED;
13722 
13723 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13724 
13725 	/* clear mbuf payload */
13726 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13727 			rte_pktmbuf_tailroom(ut_params->ibuf));
13728 
13729 	/* Create AEAD operation */
13730 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
13731 	if (retval < 0)
13732 		return retval;
13733 
13734 	/* Create GCM xform */
13735 	memcpy(key, tdata->key.data, tdata->key.len);
13736 	retval = create_aead_xform(ut_params->op,
13737 			tdata->algo,
13738 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
13739 			key, tdata->key.len,
13740 			tdata->aad.len, tdata->auth_tag.len,
13741 			tdata->iv.len);
13742 	if (retval < 0)
13743 		return retval;
13744 
13745 	ut_params->op->sym->m_src = ut_params->ibuf;
13746 
13747 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
13748 			RTE_CRYPTO_OP_SESSIONLESS,
13749 			"crypto op session type not sessionless");
13750 
13751 	/* Process crypto operation */
13752 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
13753 			ut_params->op), "failed to process sym crypto op");
13754 
13755 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
13756 
13757 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13758 			"crypto op status not success");
13759 
13760 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
13761 
13762 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
13763 			ut_params->op->sym->cipher.data.offset);
13764 	auth_tag = ciphertext + plaintext_pad_len;
13765 
13766 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
13767 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
13768 
13769 	/* Validate obuf */
13770 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13771 			ciphertext,
13772 			tdata->ciphertext.data,
13773 			tdata->ciphertext.len,
13774 			"Ciphertext data not as expected");
13775 
13776 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13777 			auth_tag,
13778 			tdata->auth_tag.data,
13779 			tdata->auth_tag.len,
13780 			"Generated auth tag not as expected");
13781 
13782 	return 0;
13783 
13784 }
13785 
13786 static int
13787 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
13788 {
13789 	return test_authenticated_encryption_sessionless(
13790 			&gcm_test_case_5);
13791 }
13792 
13793 static int
13794 test_authenticated_decryption_sessionless(
13795 		const struct aead_test_data *tdata)
13796 {
13797 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13798 	struct crypto_unittest_params *ut_params = &unittest_params;
13799 
13800 	int retval;
13801 	uint8_t *plaintext;
13802 	uint8_t key[tdata->key.len + 1];
13803 	struct rte_cryptodev_info dev_info;
13804 
13805 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13806 	uint64_t feat_flags = dev_info.feature_flags;
13807 
13808 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
13809 		printf("Device doesn't support Sessionless ops.\n");
13810 		return TEST_SKIPPED;
13811 	}
13812 
13813 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13814 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13815 		printf("Device doesn't support RAW data-path APIs.\n");
13816 		return TEST_SKIPPED;
13817 	}
13818 
13819 	/* not supported with CPU crypto */
13820 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13821 		return TEST_SKIPPED;
13822 
13823 	/* Verify the capabilities */
13824 	struct rte_cryptodev_sym_capability_idx cap_idx;
13825 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
13826 	cap_idx.algo.aead = tdata->algo;
13827 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13828 			&cap_idx) == NULL)
13829 		return TEST_SKIPPED;
13830 
13831 	/* alloc mbuf and set payload */
13832 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13833 
13834 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13835 			rte_pktmbuf_tailroom(ut_params->ibuf));
13836 
13837 	/* Create AEAD operation */
13838 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
13839 	if (retval < 0)
13840 		return retval;
13841 
13842 	/* Create AEAD xform */
13843 	memcpy(key, tdata->key.data, tdata->key.len);
13844 	retval = create_aead_xform(ut_params->op,
13845 			tdata->algo,
13846 			RTE_CRYPTO_AEAD_OP_DECRYPT,
13847 			key, tdata->key.len,
13848 			tdata->aad.len, tdata->auth_tag.len,
13849 			tdata->iv.len);
13850 	if (retval < 0)
13851 		return retval;
13852 
13853 	ut_params->op->sym->m_src = ut_params->ibuf;
13854 
13855 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
13856 			RTE_CRYPTO_OP_SESSIONLESS,
13857 			"crypto op session type not sessionless");
13858 
13859 	/* Process crypto operation */
13860 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
13861 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0,
13862 					       0);
13863 		if (retval != TEST_SUCCESS)
13864 			return retval;
13865 	} else
13866 		TEST_ASSERT_NOT_NULL(process_crypto_request(
13867 			ts_params->valid_devs[0], ut_params->op),
13868 				"failed to process sym crypto op");
13869 
13870 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
13871 
13872 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13873 			"crypto op status not success");
13874 
13875 	plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
13876 			ut_params->op->sym->cipher.data.offset);
13877 
13878 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
13879 
13880 	/* Validate obuf */
13881 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13882 			plaintext,
13883 			tdata->plaintext.data,
13884 			tdata->plaintext.len,
13885 			"Plaintext data not as expected");
13886 
13887 	TEST_ASSERT_EQUAL(ut_params->op->status,
13888 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13889 			"Authentication failed");
13890 	return 0;
13891 }
13892 
13893 static int
13894 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
13895 {
13896 	return test_authenticated_decryption_sessionless(
13897 			&gcm_test_case_5);
13898 }
13899 
13900 static int
13901 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
13902 {
13903 	return test_authenticated_encryption(&ccm_test_case_128_1);
13904 }
13905 
13906 static int
13907 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
13908 {
13909 	return test_authenticated_encryption(&ccm_test_case_128_2);
13910 }
13911 
13912 static int
13913 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
13914 {
13915 	return test_authenticated_encryption(&ccm_test_case_128_3);
13916 }
13917 
13918 static int
13919 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
13920 {
13921 	return test_authenticated_decryption(&ccm_test_case_128_1);
13922 }
13923 
13924 static int
13925 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
13926 {
13927 	return test_authenticated_decryption(&ccm_test_case_128_2);
13928 }
13929 
13930 static int
13931 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
13932 {
13933 	return test_authenticated_decryption(&ccm_test_case_128_3);
13934 }
13935 
13936 static int
13937 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
13938 {
13939 	return test_authenticated_encryption(&ccm_test_case_192_1);
13940 }
13941 
13942 static int
13943 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
13944 {
13945 	return test_authenticated_encryption(&ccm_test_case_192_2);
13946 }
13947 
13948 static int
13949 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
13950 {
13951 	return test_authenticated_encryption(&ccm_test_case_192_3);
13952 }
13953 
13954 static int
13955 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
13956 {
13957 	return test_authenticated_decryption(&ccm_test_case_192_1);
13958 }
13959 
13960 static int
13961 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
13962 {
13963 	return test_authenticated_decryption(&ccm_test_case_192_2);
13964 }
13965 
13966 static int
13967 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
13968 {
13969 	return test_authenticated_decryption(&ccm_test_case_192_3);
13970 }
13971 
13972 static int
13973 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
13974 {
13975 	return test_authenticated_encryption(&ccm_test_case_256_1);
13976 }
13977 
13978 static int
13979 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
13980 {
13981 	return test_authenticated_encryption(&ccm_test_case_256_2);
13982 }
13983 
13984 static int
13985 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
13986 {
13987 	return test_authenticated_encryption(&ccm_test_case_256_3);
13988 }
13989 
13990 static int
13991 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
13992 {
13993 	return test_authenticated_decryption(&ccm_test_case_256_1);
13994 }
13995 
13996 static int
13997 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
13998 {
13999 	return test_authenticated_decryption(&ccm_test_case_256_2);
14000 }
14001 
14002 static int
14003 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
14004 {
14005 	return test_authenticated_decryption(&ccm_test_case_256_3);
14006 }
14007 
14008 static int
14009 test_stats(void)
14010 {
14011 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14012 	struct rte_cryptodev_stats stats;
14013 
14014 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
14015 		return TEST_SKIPPED;
14016 
14017 	/* Verify the capabilities */
14018 	struct rte_cryptodev_sym_capability_idx cap_idx;
14019 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14020 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
14021 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14022 			&cap_idx) == NULL)
14023 		return TEST_SKIPPED;
14024 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
14025 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
14026 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14027 			&cap_idx) == NULL)
14028 		return TEST_SKIPPED;
14029 
14030 	if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
14031 			== -ENOTSUP)
14032 		return TEST_SKIPPED;
14033 
14034 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
14035 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
14036 			&stats) == -ENODEV),
14037 		"rte_cryptodev_stats_get invalid dev failed");
14038 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
14039 		"rte_cryptodev_stats_get invalid Param failed");
14040 
14041 	/* Test expected values */
14042 	test_AES_CBC_HMAC_SHA1_encrypt_digest();
14043 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
14044 			&stats),
14045 		"rte_cryptodev_stats_get failed");
14046 	TEST_ASSERT((stats.enqueued_count == 1),
14047 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
14048 	TEST_ASSERT((stats.dequeued_count == 1),
14049 		"rte_cryptodev_stats_get returned unexpected dequeued stat");
14050 	TEST_ASSERT((stats.enqueue_err_count == 0),
14051 		"rte_cryptodev_stats_get returned unexpected enqueued error count stat");
14052 	TEST_ASSERT((stats.dequeue_err_count == 0),
14053 		"rte_cryptodev_stats_get returned unexpected dequeued error count stat");
14054 
14055 	/* invalid device but should ignore and not reset device stats*/
14056 	rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
14057 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
14058 			&stats),
14059 		"rte_cryptodev_stats_get failed");
14060 	TEST_ASSERT((stats.enqueued_count == 1),
14061 		"rte_cryptodev_stats_get returned unexpected enqueued stat after invalid reset");
14062 
14063 	/* check that a valid reset clears stats */
14064 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
14065 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
14066 			&stats),
14067 					  "rte_cryptodev_stats_get failed");
14068 	TEST_ASSERT((stats.enqueued_count == 0),
14069 		"rte_cryptodev_stats_get returned unexpected enqueued stat after valid reset");
14070 	TEST_ASSERT((stats.dequeued_count == 0),
14071 		"rte_cryptodev_stats_get returned unexpected dequeued stat after valid reset");
14072 
14073 	return TEST_SUCCESS;
14074 }
14075 
14076 static int
14077 test_device_reconfigure(void)
14078 {
14079 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14080 	uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
14081 	struct rte_cryptodev_qp_conf qp_conf = {
14082 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT,
14083 		.mp_session = ts_params->session_mpool
14084 	};
14085 	uint16_t qp_id, dev_id, num_devs = 0;
14086 
14087 	TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
14088 			"Need at least %d devices for test", 1);
14089 
14090 	dev_id = ts_params->valid_devs[0];
14091 
14092 	/* Stop the device in case it's started so it can be configured */
14093 	rte_cryptodev_stop(dev_id);
14094 
14095 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
14096 			"Failed test for rte_cryptodev_configure: "
14097 			"dev_num %u", dev_id);
14098 
14099 	/* Reconfigure with same configure params */
14100 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
14101 			"Failed test for rte_cryptodev_configure: "
14102 			"dev_num %u", dev_id);
14103 
14104 	/* Reconfigure with just one queue pair */
14105 	ts_params->conf.nb_queue_pairs = 1;
14106 
14107 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
14108 			&ts_params->conf),
14109 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
14110 			ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
14111 
14112 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
14113 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
14114 				ts_params->valid_devs[0], qp_id, &qp_conf,
14115 				rte_cryptodev_socket_id(
14116 						ts_params->valid_devs[0])),
14117 				"Failed test for "
14118 				"rte_cryptodev_queue_pair_setup: num_inflights "
14119 				"%u on qp %u on cryptodev %u",
14120 				qp_conf.nb_descriptors, qp_id,
14121 				ts_params->valid_devs[0]);
14122 	}
14123 
14124 	/* Reconfigure with max number of queue pairs */
14125 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
14126 
14127 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
14128 			&ts_params->conf),
14129 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
14130 			ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
14131 
14132 	qp_conf.mp_session = ts_params->session_mpool;
14133 
14134 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
14135 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
14136 				ts_params->valid_devs[0], qp_id, &qp_conf,
14137 				rte_cryptodev_socket_id(
14138 						ts_params->valid_devs[0])),
14139 				"Failed test for "
14140 				"rte_cryptodev_queue_pair_setup: num_inflights "
14141 				"%u on qp %u on cryptodev %u",
14142 				qp_conf.nb_descriptors, qp_id,
14143 				ts_params->valid_devs[0]);
14144 	}
14145 
14146 	/* Start the device */
14147 	TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
14148 			"Failed to start cryptodev %u",
14149 			ts_params->valid_devs[0]);
14150 
14151 	/* Test expected values */
14152 	return test_AES_CBC_HMAC_SHA1_encrypt_digest();
14153 }
14154 
14155 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
14156 				   struct crypto_unittest_params *ut_params,
14157 				   enum rte_crypto_auth_operation op,
14158 				   const struct HMAC_MD5_vector *test_case)
14159 {
14160 	uint8_t key[64];
14161 
14162 	memcpy(key, test_case->key.data, test_case->key.len);
14163 
14164 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14165 	ut_params->auth_xform.next = NULL;
14166 	ut_params->auth_xform.auth.op = op;
14167 
14168 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
14169 
14170 	ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
14171 	ut_params->auth_xform.auth.key.length = test_case->key.len;
14172 	ut_params->auth_xform.auth.key.data = key;
14173 
14174 	ut_params->sess = rte_cryptodev_sym_session_create(
14175 		ts_params->valid_devs[0], &ut_params->auth_xform,
14176 			ts_params->session_mpool);
14177 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
14178 		return TEST_SKIPPED;
14179 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
14180 
14181 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14182 
14183 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
14184 			rte_pktmbuf_tailroom(ut_params->ibuf));
14185 
14186 	return 0;
14187 }
14188 
14189 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
14190 			      const struct HMAC_MD5_vector *test_case,
14191 			      uint8_t **plaintext)
14192 {
14193 	uint16_t plaintext_pad_len;
14194 
14195 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
14196 
14197 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
14198 				16);
14199 
14200 	*plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
14201 			plaintext_pad_len);
14202 	memcpy(*plaintext, test_case->plaintext.data,
14203 			test_case->plaintext.len);
14204 
14205 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
14206 			ut_params->ibuf, MD5_DIGEST_LEN);
14207 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
14208 			"no room to append digest");
14209 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
14210 			ut_params->ibuf, plaintext_pad_len);
14211 
14212 	if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
14213 		rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
14214 			   test_case->auth_tag.len);
14215 	}
14216 
14217 	sym_op->auth.data.offset = 0;
14218 	sym_op->auth.data.length = test_case->plaintext.len;
14219 
14220 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
14221 	ut_params->op->sym->m_src = ut_params->ibuf;
14222 
14223 	return 0;
14224 }
14225 
14226 static int
14227 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
14228 {
14229 	uint16_t plaintext_pad_len;
14230 	uint8_t *plaintext, *auth_tag;
14231 	int ret;
14232 
14233 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14234 	struct crypto_unittest_params *ut_params = &unittest_params;
14235 	struct rte_cryptodev_info dev_info;
14236 
14237 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
14238 	uint64_t feat_flags = dev_info.feature_flags;
14239 
14240 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
14241 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
14242 		printf("Device doesn't support RAW data-path APIs.\n");
14243 		return TEST_SKIPPED;
14244 	}
14245 
14246 	/* Verify the capabilities */
14247 	struct rte_cryptodev_sym_capability_idx cap_idx;
14248 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14249 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
14250 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14251 			&cap_idx) == NULL)
14252 		return TEST_SKIPPED;
14253 
14254 	if (MD5_HMAC_create_session(ts_params, ut_params,
14255 			RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
14256 		return TEST_FAILED;
14257 
14258 	/* Generate Crypto op data structure */
14259 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
14260 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
14261 	TEST_ASSERT_NOT_NULL(ut_params->op,
14262 			"Failed to allocate symmetric crypto operation struct");
14263 
14264 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
14265 				16);
14266 
14267 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
14268 		return TEST_FAILED;
14269 
14270 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
14271 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
14272 			ut_params->op);
14273 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
14274 		ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 0);
14275 		if (ret != TEST_SUCCESS)
14276 			return ret;
14277 	} else
14278 		TEST_ASSERT_NOT_NULL(
14279 			process_crypto_request(ts_params->valid_devs[0],
14280 				ut_params->op),
14281 				"failed to process sym crypto op");
14282 
14283 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
14284 			"crypto op processing failed");
14285 
14286 	if (ut_params->op->sym->m_dst) {
14287 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
14288 				uint8_t *, plaintext_pad_len);
14289 	} else {
14290 		auth_tag = plaintext + plaintext_pad_len;
14291 	}
14292 
14293 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
14294 			auth_tag,
14295 			test_case->auth_tag.data,
14296 			test_case->auth_tag.len,
14297 			"HMAC_MD5 generated tag not as expected");
14298 
14299 	return TEST_SUCCESS;
14300 }
14301 
14302 static int
14303 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
14304 {
14305 	uint8_t *plaintext;
14306 	int ret;
14307 
14308 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14309 	struct crypto_unittest_params *ut_params = &unittest_params;
14310 	struct rte_cryptodev_info dev_info;
14311 
14312 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
14313 	uint64_t feat_flags = dev_info.feature_flags;
14314 
14315 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
14316 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
14317 		printf("Device doesn't support RAW data-path APIs.\n");
14318 		return TEST_SKIPPED;
14319 	}
14320 
14321 	/* Verify the capabilities */
14322 	struct rte_cryptodev_sym_capability_idx cap_idx;
14323 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14324 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
14325 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14326 			&cap_idx) == NULL)
14327 		return TEST_SKIPPED;
14328 
14329 	if (MD5_HMAC_create_session(ts_params, ut_params,
14330 			RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
14331 		return TEST_FAILED;
14332 	}
14333 
14334 	/* Generate Crypto op data structure */
14335 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
14336 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
14337 	TEST_ASSERT_NOT_NULL(ut_params->op,
14338 			"Failed to allocate symmetric crypto operation struct");
14339 
14340 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
14341 		return TEST_FAILED;
14342 
14343 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
14344 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
14345 			ut_params->op);
14346 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
14347 		ret = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0, 0);
14348 		if (ret != TEST_SUCCESS)
14349 			return ret;
14350 	} else
14351 		TEST_ASSERT_NOT_NULL(
14352 			process_crypto_request(ts_params->valid_devs[0],
14353 				ut_params->op),
14354 				"failed to process sym crypto op");
14355 
14356 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
14357 			"HMAC_MD5 crypto op processing failed");
14358 
14359 	return TEST_SUCCESS;
14360 }
14361 
14362 static int
14363 test_MD5_HMAC_generate_case_1(void)
14364 {
14365 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
14366 }
14367 
14368 static int
14369 test_MD5_HMAC_verify_case_1(void)
14370 {
14371 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
14372 }
14373 
14374 static int
14375 test_MD5_HMAC_generate_case_2(void)
14376 {
14377 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
14378 }
14379 
14380 static int
14381 test_MD5_HMAC_verify_case_2(void)
14382 {
14383 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
14384 }
14385 
14386 static int
14387 test_multi_session(void)
14388 {
14389 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14390 	struct crypto_unittest_params *ut_params = &unittest_params;
14391 	struct rte_cryptodev_info dev_info;
14392 	int i, nb_sess, ret = TEST_SUCCESS;
14393 	void **sessions;
14394 
14395 	/* Verify the capabilities */
14396 	struct rte_cryptodev_sym_capability_idx cap_idx;
14397 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14398 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
14399 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14400 			&cap_idx) == NULL)
14401 		return TEST_SKIPPED;
14402 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
14403 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
14404 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14405 			&cap_idx) == NULL)
14406 		return TEST_SKIPPED;
14407 
14408 	test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
14409 			aes_cbc_key, hmac_sha512_key);
14410 
14411 
14412 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
14413 
14414 	sessions = rte_malloc(NULL,
14415 			sizeof(void *) *
14416 			(MAX_NB_SESSIONS + 1), 0);
14417 
14418 	/* Create multiple crypto sessions*/
14419 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
14420 		sessions[i] = rte_cryptodev_sym_session_create(
14421 			ts_params->valid_devs[0], &ut_params->auth_xform,
14422 				ts_params->session_mpool);
14423 		if (sessions[i] == NULL && rte_errno == ENOTSUP) {
14424 			nb_sess = i;
14425 			ret = TEST_SKIPPED;
14426 			break;
14427 		}
14428 
14429 		TEST_ASSERT_NOT_NULL(sessions[i],
14430 				"Session creation failed at session number %u",
14431 				i);
14432 
14433 		/* Attempt to send a request on each session */
14434 		ret = test_AES_CBC_HMAC_SHA512_decrypt_perform(
14435 			sessions[i],
14436 			ut_params,
14437 			ts_params,
14438 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
14439 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
14440 			aes_cbc_iv);
14441 
14442 		/* free crypto operation structure */
14443 		rte_crypto_op_free(ut_params->op);
14444 
14445 		/*
14446 		 * free mbuf - both obuf and ibuf are usually the same,
14447 		 * so check if they point at the same address is necessary,
14448 		 * to avoid freeing the mbuf twice.
14449 		 */
14450 		if (ut_params->obuf) {
14451 			rte_pktmbuf_free(ut_params->obuf);
14452 			if (ut_params->ibuf == ut_params->obuf)
14453 				ut_params->ibuf = 0;
14454 			ut_params->obuf = 0;
14455 		}
14456 		if (ut_params->ibuf) {
14457 			rte_pktmbuf_free(ut_params->ibuf);
14458 			ut_params->ibuf = 0;
14459 		}
14460 
14461 		if (ret != TEST_SUCCESS) {
14462 			i++;
14463 			break;
14464 		}
14465 	}
14466 
14467 	nb_sess = i;
14468 
14469 	for (i = 0; i < nb_sess; i++) {
14470 		rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
14471 				sessions[i]);
14472 	}
14473 
14474 	rte_free(sessions);
14475 
14476 	if (ret != TEST_SKIPPED)
14477 		TEST_ASSERT_SUCCESS(ret, "Failed to perform decrypt on request number %u.", i - 1);
14478 
14479 	return ret;
14480 }
14481 
14482 struct multi_session_params {
14483 	struct crypto_unittest_params ut_params;
14484 	uint8_t *cipher_key;
14485 	uint8_t *hmac_key;
14486 	const uint8_t *cipher;
14487 	const uint8_t *digest;
14488 	uint8_t *iv;
14489 };
14490 
14491 #define MB_SESSION_NUMBER 3
14492 
14493 static int
14494 test_multi_session_random_usage(void)
14495 {
14496 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14497 	struct rte_cryptodev_info dev_info;
14498 	int index = 0, ret = TEST_SUCCESS;
14499 	uint32_t nb_sess, i, j;
14500 	void **sessions;
14501 	struct multi_session_params ut_paramz[] = {
14502 
14503 		{
14504 			.cipher_key = ms_aes_cbc_key0,
14505 			.hmac_key = ms_hmac_key0,
14506 			.cipher = ms_aes_cbc_cipher0,
14507 			.digest = ms_hmac_digest0,
14508 			.iv = ms_aes_cbc_iv0
14509 		},
14510 		{
14511 			.cipher_key = ms_aes_cbc_key1,
14512 			.hmac_key = ms_hmac_key1,
14513 			.cipher = ms_aes_cbc_cipher1,
14514 			.digest = ms_hmac_digest1,
14515 			.iv = ms_aes_cbc_iv1
14516 		},
14517 		{
14518 			.cipher_key = ms_aes_cbc_key2,
14519 			.hmac_key = ms_hmac_key2,
14520 			.cipher = ms_aes_cbc_cipher2,
14521 			.digest = ms_hmac_digest2,
14522 			.iv = ms_aes_cbc_iv2
14523 		},
14524 
14525 	};
14526 
14527 	/* Verify the capabilities */
14528 	struct rte_cryptodev_sym_capability_idx cap_idx;
14529 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14530 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
14531 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14532 			&cap_idx) == NULL)
14533 		return TEST_SKIPPED;
14534 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
14535 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
14536 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14537 			&cap_idx) == NULL)
14538 		return TEST_SKIPPED;
14539 
14540 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
14541 
14542 	sessions = rte_malloc(NULL, (sizeof(void *)
14543 					* MAX_NB_SESSIONS) + 1, 0);
14544 
14545 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
14546 
14547 		rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
14548 				sizeof(struct crypto_unittest_params));
14549 
14550 		test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
14551 				&ut_paramz[i].ut_params,
14552 				ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
14553 
14554 		/* Create multiple crypto sessions*/
14555 		sessions[i] = rte_cryptodev_sym_session_create(
14556 				ts_params->valid_devs[0],
14557 				&ut_paramz[i].ut_params.auth_xform,
14558 				ts_params->session_mpool);
14559 		if (sessions[i] == NULL && rte_errno == ENOTSUP) {
14560 			nb_sess = i;
14561 			ret = TEST_SKIPPED;
14562 			goto session_clear;
14563 		}
14564 
14565 		TEST_ASSERT_NOT_NULL(sessions[i],
14566 				"Session creation failed at session number %u",
14567 				i);
14568 	}
14569 
14570 	nb_sess = i;
14571 
14572 	srand(time(NULL));
14573 	for (i = 0; i < 40000; i++) {
14574 
14575 		j = rand() % MB_SESSION_NUMBER;
14576 
14577 		ret = test_AES_CBC_HMAC_SHA512_decrypt_perform(
14578 					sessions[j],
14579 					&ut_paramz[j].ut_params,
14580 					ts_params, ut_paramz[j].cipher,
14581 					ut_paramz[j].digest,
14582 					ut_paramz[j].iv);
14583 
14584 		rte_crypto_op_free(ut_paramz[j].ut_params.op);
14585 
14586 		/*
14587 		 * free mbuf - both obuf and ibuf are usually the same,
14588 		 * so check if they point at the same address is necessary,
14589 		 * to avoid freeing the mbuf twice.
14590 		 */
14591 		if (ut_paramz[j].ut_params.obuf) {
14592 			rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
14593 			if (ut_paramz[j].ut_params.ibuf
14594 					== ut_paramz[j].ut_params.obuf)
14595 				ut_paramz[j].ut_params.ibuf = 0;
14596 			ut_paramz[j].ut_params.obuf = 0;
14597 		}
14598 		if (ut_paramz[j].ut_params.ibuf) {
14599 			rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
14600 			ut_paramz[j].ut_params.ibuf = 0;
14601 		}
14602 
14603 		if (ret != TEST_SKIPPED) {
14604 			index = i;
14605 			break;
14606 		}
14607 	}
14608 
14609 session_clear:
14610 	for (i = 0; i < nb_sess; i++) {
14611 		rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
14612 				sessions[i]);
14613 	}
14614 
14615 	rte_free(sessions);
14616 
14617 	if (ret != TEST_SKIPPED)
14618 		TEST_ASSERT_SUCCESS(ret, "Failed to perform decrypt on request number %u.", index);
14619 
14620 	return TEST_SUCCESS;
14621 }
14622 
14623 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
14624 			0xab, 0xab, 0xab, 0xab,
14625 			0xab, 0xab, 0xab, 0xab,
14626 			0xab, 0xab, 0xab, 0xab};
14627 
14628 static int
14629 test_null_invalid_operation(void)
14630 {
14631 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14632 	struct crypto_unittest_params *ut_params = &unittest_params;
14633 
14634 	/* This test is for NULL PMD only */
14635 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
14636 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
14637 		return TEST_SKIPPED;
14638 
14639 	/* Setup Cipher Parameters */
14640 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
14641 	ut_params->cipher_xform.next = NULL;
14642 
14643 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
14644 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
14645 
14646 	/* Create Crypto session*/
14647 	ut_params->sess = rte_cryptodev_sym_session_create(
14648 			ts_params->valid_devs[0], &ut_params->cipher_xform,
14649 			ts_params->session_mpool);
14650 	TEST_ASSERT(ut_params->sess == NULL,
14651 			"Session creation succeeded unexpectedly");
14652 
14653 	/* Setup HMAC Parameters */
14654 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14655 	ut_params->auth_xform.next = NULL;
14656 
14657 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
14658 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
14659 
14660 	/* Create Crypto session*/
14661 	ut_params->sess = rte_cryptodev_sym_session_create(
14662 			ts_params->valid_devs[0], &ut_params->auth_xform,
14663 			ts_params->session_mpool);
14664 	TEST_ASSERT(ut_params->sess == NULL,
14665 			"Session creation succeeded unexpectedly");
14666 
14667 	return TEST_SUCCESS;
14668 }
14669 
14670 
14671 #define NULL_BURST_LENGTH (32)
14672 
14673 static int
14674 test_null_burst_operation(void)
14675 {
14676 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14677 	struct crypto_unittest_params *ut_params = &unittest_params;
14678 
14679 	unsigned i, burst_len = NULL_BURST_LENGTH;
14680 
14681 	struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
14682 	struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
14683 
14684 	/* This test is for NULL PMD only */
14685 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
14686 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
14687 		return TEST_SKIPPED;
14688 
14689 	/* Setup Cipher Parameters */
14690 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
14691 	ut_params->cipher_xform.next = &ut_params->auth_xform;
14692 
14693 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
14694 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
14695 
14696 	/* Setup HMAC Parameters */
14697 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14698 	ut_params->auth_xform.next = NULL;
14699 
14700 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
14701 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
14702 
14703 	/* Create Crypto session*/
14704 	ut_params->sess = rte_cryptodev_sym_session_create(
14705 				ts_params->valid_devs[0],
14706 				&ut_params->auth_xform,
14707 				ts_params->session_mpool);
14708 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
14709 		return TEST_SKIPPED;
14710 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
14711 
14712 	TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
14713 			RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
14714 			burst_len, "failed to generate burst of crypto ops");
14715 
14716 	/* Generate an operation for each mbuf in burst */
14717 	for (i = 0; i < burst_len; i++) {
14718 		struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14719 
14720 		TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
14721 
14722 		unsigned *data = (unsigned *)rte_pktmbuf_append(m,
14723 				sizeof(unsigned));
14724 		*data = i;
14725 
14726 		rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
14727 
14728 		burst[i]->sym->m_src = m;
14729 	}
14730 
14731 	/* Process crypto operation */
14732 	TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
14733 			0, burst, burst_len),
14734 			burst_len,
14735 			"Error enqueuing burst");
14736 
14737 	TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
14738 			0, burst_dequeued, burst_len),
14739 			burst_len,
14740 			"Error dequeuing burst");
14741 
14742 
14743 	for (i = 0; i < burst_len; i++) {
14744 		TEST_ASSERT_EQUAL(
14745 			*rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
14746 			*rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
14747 					uint32_t *),
14748 			"data not as expected");
14749 
14750 		rte_pktmbuf_free(burst[i]->sym->m_src);
14751 		rte_crypto_op_free(burst[i]);
14752 	}
14753 
14754 	return TEST_SUCCESS;
14755 }
14756 
14757 static uint16_t
14758 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
14759 		  uint16_t nb_ops, void *user_param)
14760 {
14761 	RTE_SET_USED(dev_id);
14762 	RTE_SET_USED(qp_id);
14763 	RTE_SET_USED(ops);
14764 	RTE_SET_USED(user_param);
14765 
14766 	enq_cb_called = true;
14767 	printf("crypto enqueue callback called\n");
14768 	return nb_ops;
14769 }
14770 
14771 static uint16_t
14772 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
14773 		  uint16_t nb_ops, void *user_param)
14774 {
14775 	RTE_SET_USED(dev_id);
14776 	RTE_SET_USED(qp_id);
14777 	RTE_SET_USED(ops);
14778 	RTE_SET_USED(user_param);
14779 
14780 	deq_cb_called = true;
14781 	printf("crypto dequeue callback called\n");
14782 	return nb_ops;
14783 }
14784 
14785 /*
14786  * Process enqueue/dequeue NULL crypto request to verify callback with RCU.
14787  */
14788 static int
14789 test_enqdeq_callback_null_cipher(void)
14790 {
14791 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14792 	struct crypto_unittest_params *ut_params = &unittest_params;
14793 
14794 	/* Setup Cipher Parameters */
14795 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
14796 	ut_params->cipher_xform.next = &ut_params->auth_xform;
14797 
14798 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
14799 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
14800 
14801 	/* Setup Auth Parameters */
14802 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14803 	ut_params->auth_xform.next = NULL;
14804 
14805 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
14806 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
14807 
14808 	/* Create Crypto session */
14809 	ut_params->sess = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
14810 				&ut_params->auth_xform, ts_params->session_mpool);
14811 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
14812 
14813 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, RTE_CRYPTO_OP_TYPE_SYMMETRIC);
14814 	TEST_ASSERT_NOT_NULL(ut_params->op, "Failed to allocate symmetric crypto op");
14815 
14816 	/* Allocate mbuf */
14817 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14818 	TEST_ASSERT_NOT_NULL(ut_params->ibuf, "Failed to allocate mbuf");
14819 
14820 	/* Append some random data */
14821 	TEST_ASSERT_NOT_NULL(rte_pktmbuf_append(ut_params->ibuf, sizeof(unsigned int)),
14822 			"no room to append data");
14823 
14824 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
14825 
14826 	ut_params->op->sym->m_src = ut_params->ibuf;
14827 
14828 	/* Process crypto operation */
14829 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0], ut_params->op),
14830 			"failed to process sym crypto op");
14831 
14832 	return 0;
14833 }
14834 
14835 static int
14836 test_enq_callback_setup(void)
14837 {
14838 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14839 	struct rte_cryptodev_sym_capability_idx cap_idx;
14840 	struct rte_cryptodev_info dev_info;
14841 	struct rte_cryptodev_qp_conf qp_conf = {
14842 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
14843 	};
14844 
14845 	struct rte_cryptodev_cb *cb;
14846 	uint16_t qp_id = 0;
14847 	int j = 0;
14848 
14849 	/* Verify the crypto capabilities for which enqueue/dequeue is done. */
14850 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14851 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_NULL;
14852 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14853 			&cap_idx) == NULL)
14854 		return TEST_SKIPPED;
14855 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
14856 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_NULL;
14857 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14858 			&cap_idx) == NULL)
14859 		return TEST_SKIPPED;
14860 
14861 	/* Stop the device in case it's started so it can be configured */
14862 	rte_cryptodev_stop(ts_params->valid_devs[0]);
14863 
14864 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
14865 
14866 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
14867 			&ts_params->conf),
14868 			"Failed to configure cryptodev %u",
14869 			ts_params->valid_devs[0]);
14870 
14871 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
14872 	qp_conf.mp_session = ts_params->session_mpool;
14873 
14874 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
14875 			ts_params->valid_devs[0], qp_id, &qp_conf,
14876 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
14877 			"Failed test for "
14878 			"rte_cryptodev_queue_pair_setup: num_inflights "
14879 			"%u on qp %u on cryptodev %u",
14880 			qp_conf.nb_descriptors, qp_id,
14881 			ts_params->valid_devs[0]);
14882 
14883 	enq_cb_called = false;
14884 	/* Test with invalid crypto device */
14885 	cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
14886 			qp_id, test_enq_callback, NULL);
14887 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
14888 			"cryptodev %u did not fail",
14889 			qp_id, RTE_CRYPTO_MAX_DEVS);
14890 
14891 	/* Test with invalid queue pair */
14892 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
14893 			dev_info.max_nb_queue_pairs + 1,
14894 			test_enq_callback, NULL);
14895 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
14896 			"cryptodev %u did not fail",
14897 			dev_info.max_nb_queue_pairs + 1,
14898 			ts_params->valid_devs[0]);
14899 
14900 	/* Test with NULL callback */
14901 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
14902 			qp_id, NULL, NULL);
14903 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
14904 			"cryptodev %u did not fail",
14905 			qp_id, ts_params->valid_devs[0]);
14906 
14907 	/* Test with valid configuration */
14908 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
14909 			qp_id, test_enq_callback, NULL);
14910 	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
14911 			"qp %u on cryptodev %u",
14912 			qp_id, ts_params->valid_devs[0]);
14913 
14914 	rte_cryptodev_start(ts_params->valid_devs[0]);
14915 
14916 	TEST_ASSERT_SUCCESS(test_enqdeq_callback_null_cipher(), "Crypto Processing failed");
14917 
14918 	/* Wait until callback not called. */
14919 	while (!enq_cb_called && (j++ < 10))
14920 		rte_delay_ms(10);
14921 
14922 	/* Test with invalid crypto device */
14923 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
14924 			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
14925 			"Expected call to fail as crypto device is invalid");
14926 
14927 	/* Test with invalid queue pair */
14928 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
14929 			ts_params->valid_devs[0],
14930 			dev_info.max_nb_queue_pairs + 1, cb),
14931 			"Expected call to fail as queue pair is invalid");
14932 
14933 	/* Test with NULL callback */
14934 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
14935 			ts_params->valid_devs[0], qp_id, NULL),
14936 			"Expected call to fail as callback is NULL");
14937 
14938 	/* Test with valid configuration */
14939 	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
14940 			ts_params->valid_devs[0], qp_id, cb),
14941 			"Failed test to remove callback on "
14942 			"qp %u on cryptodev %u",
14943 			qp_id, ts_params->valid_devs[0]);
14944 
14945 	TEST_ASSERT(enq_cb_called == true, "Crypto enqueue callback not called");
14946 
14947 	return TEST_SUCCESS;
14948 }
14949 
14950 static int
14951 test_deq_callback_setup(void)
14952 {
14953 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14954 	struct rte_cryptodev_sym_capability_idx cap_idx;
14955 	struct rte_cryptodev_info dev_info;
14956 	struct rte_cryptodev_qp_conf qp_conf = {
14957 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
14958 	};
14959 
14960 	struct rte_cryptodev_cb *cb;
14961 	uint16_t qp_id = 0;
14962 	int j = 0;
14963 
14964 	/* Verify the crypto capabilities for which enqueue/dequeue is done. */
14965 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14966 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_NULL;
14967 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14968 			&cap_idx) == NULL)
14969 		return TEST_SKIPPED;
14970 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
14971 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_NULL;
14972 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14973 			&cap_idx) == NULL)
14974 		return TEST_SKIPPED;
14975 
14976 	/* Stop the device in case it's started so it can be configured */
14977 	rte_cryptodev_stop(ts_params->valid_devs[0]);
14978 
14979 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
14980 
14981 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
14982 			&ts_params->conf),
14983 			"Failed to configure cryptodev %u",
14984 			ts_params->valid_devs[0]);
14985 
14986 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
14987 	qp_conf.mp_session = ts_params->session_mpool;
14988 
14989 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
14990 			ts_params->valid_devs[0], qp_id, &qp_conf,
14991 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
14992 			"Failed test for "
14993 			"rte_cryptodev_queue_pair_setup: num_inflights "
14994 			"%u on qp %u on cryptodev %u",
14995 			qp_conf.nb_descriptors, qp_id,
14996 			ts_params->valid_devs[0]);
14997 
14998 	deq_cb_called = false;
14999 	/* Test with invalid crypto device */
15000 	cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
15001 			qp_id, test_deq_callback, NULL);
15002 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
15003 			"cryptodev %u did not fail",
15004 			qp_id, RTE_CRYPTO_MAX_DEVS);
15005 
15006 	/* Test with invalid queue pair */
15007 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
15008 			dev_info.max_nb_queue_pairs + 1,
15009 			test_deq_callback, NULL);
15010 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
15011 			"cryptodev %u did not fail",
15012 			dev_info.max_nb_queue_pairs + 1,
15013 			ts_params->valid_devs[0]);
15014 
15015 	/* Test with NULL callback */
15016 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
15017 			qp_id, NULL, NULL);
15018 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
15019 			"cryptodev %u did not fail",
15020 			qp_id, ts_params->valid_devs[0]);
15021 
15022 	/* Test with valid configuration */
15023 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
15024 			qp_id, test_deq_callback, NULL);
15025 	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
15026 			"qp %u on cryptodev %u",
15027 			qp_id, ts_params->valid_devs[0]);
15028 
15029 	rte_cryptodev_start(ts_params->valid_devs[0]);
15030 
15031 	TEST_ASSERT_SUCCESS(test_enqdeq_callback_null_cipher(), "Crypto processing failed");
15032 
15033 	/* Wait until callback not called. */
15034 	while (!deq_cb_called && (j++ < 10))
15035 		rte_delay_ms(10);
15036 
15037 	/* Test with invalid crypto device */
15038 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
15039 			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
15040 			"Expected call to fail as crypto device is invalid");
15041 
15042 	/* Test with invalid queue pair */
15043 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
15044 			ts_params->valid_devs[0],
15045 			dev_info.max_nb_queue_pairs + 1, cb),
15046 			"Expected call to fail as queue pair is invalid");
15047 
15048 	/* Test with NULL callback */
15049 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
15050 			ts_params->valid_devs[0], qp_id, NULL),
15051 			"Expected call to fail as callback is NULL");
15052 
15053 	/* Test with valid configuration */
15054 	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
15055 			ts_params->valid_devs[0], qp_id, cb),
15056 			"Failed test to remove callback on "
15057 			"qp %u on cryptodev %u",
15058 			qp_id, ts_params->valid_devs[0]);
15059 
15060 	TEST_ASSERT(deq_cb_called == true, "Crypto dequeue callback not called");
15061 
15062 	return TEST_SUCCESS;
15063 }
15064 
15065 static void
15066 generate_gmac_large_plaintext(uint8_t *data)
15067 {
15068 	uint16_t i;
15069 
15070 	for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
15071 		memcpy(&data[i], &data[0], 32);
15072 }
15073 
15074 static int
15075 create_gmac_operation(enum rte_crypto_auth_operation op,
15076 		const struct gmac_test_data *tdata)
15077 {
15078 	struct crypto_testsuite_params *ts_params = &testsuite_params;
15079 	struct crypto_unittest_params *ut_params = &unittest_params;
15080 	struct rte_crypto_sym_op *sym_op;
15081 
15082 	uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
15083 
15084 	/* Generate Crypto op data structure */
15085 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
15086 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
15087 	TEST_ASSERT_NOT_NULL(ut_params->op,
15088 			"Failed to allocate symmetric crypto operation struct");
15089 
15090 	sym_op = ut_params->op->sym;
15091 
15092 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
15093 			ut_params->ibuf, tdata->gmac_tag.len);
15094 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
15095 			"no room to append digest");
15096 
15097 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
15098 			ut_params->ibuf, plaintext_pad_len);
15099 
15100 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
15101 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
15102 				tdata->gmac_tag.len);
15103 		debug_hexdump(stdout, "digest:",
15104 				sym_op->auth.digest.data,
15105 				tdata->gmac_tag.len);
15106 	}
15107 
15108 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
15109 			uint8_t *, IV_OFFSET);
15110 
15111 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
15112 
15113 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
15114 
15115 	sym_op->cipher.data.length = 0;
15116 	sym_op->cipher.data.offset = 0;
15117 
15118 	sym_op->auth.data.offset = 0;
15119 	sym_op->auth.data.length = tdata->plaintext.len;
15120 
15121 	return 0;
15122 }
15123 
15124 static int
15125 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
15126 		const struct gmac_test_data *tdata,
15127 		void *digest_mem, uint64_t digest_phys)
15128 {
15129 	struct crypto_testsuite_params *ts_params = &testsuite_params;
15130 	struct crypto_unittest_params *ut_params = &unittest_params;
15131 	struct rte_crypto_sym_op *sym_op;
15132 
15133 	/* Generate Crypto op data structure */
15134 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
15135 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
15136 	TEST_ASSERT_NOT_NULL(ut_params->op,
15137 			"Failed to allocate symmetric crypto operation struct");
15138 
15139 	sym_op = ut_params->op->sym;
15140 
15141 	sym_op->auth.digest.data = digest_mem;
15142 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
15143 			"no room to append digest");
15144 
15145 	sym_op->auth.digest.phys_addr = digest_phys;
15146 
15147 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
15148 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
15149 				tdata->gmac_tag.len);
15150 		debug_hexdump(stdout, "digest:",
15151 				sym_op->auth.digest.data,
15152 				tdata->gmac_tag.len);
15153 	}
15154 
15155 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
15156 			uint8_t *, IV_OFFSET);
15157 
15158 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
15159 
15160 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
15161 
15162 	sym_op->cipher.data.length = 0;
15163 	sym_op->cipher.data.offset = 0;
15164 
15165 	sym_op->auth.data.offset = 0;
15166 	sym_op->auth.data.length = tdata->plaintext.len;
15167 
15168 	return 0;
15169 }
15170 
15171 static int create_gmac_session(uint8_t dev_id,
15172 		const struct gmac_test_data *tdata,
15173 		enum rte_crypto_auth_operation auth_op)
15174 {
15175 	uint8_t auth_key[tdata->key.len];
15176 
15177 	struct crypto_testsuite_params *ts_params = &testsuite_params;
15178 	struct crypto_unittest_params *ut_params = &unittest_params;
15179 
15180 	memcpy(auth_key, tdata->key.data, tdata->key.len);
15181 
15182 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
15183 	ut_params->auth_xform.next = NULL;
15184 
15185 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
15186 	ut_params->auth_xform.auth.op = auth_op;
15187 	ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
15188 	ut_params->auth_xform.auth.key.length = tdata->key.len;
15189 	ut_params->auth_xform.auth.key.data = auth_key;
15190 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
15191 	ut_params->auth_xform.auth.iv.length = tdata->iv.len;
15192 
15193 
15194 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
15195 			&ut_params->auth_xform, ts_params->session_mpool);
15196 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
15197 		return TEST_SKIPPED;
15198 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
15199 
15200 	return 0;
15201 }
15202 
15203 static int
15204 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
15205 {
15206 	struct crypto_testsuite_params *ts_params = &testsuite_params;
15207 	struct crypto_unittest_params *ut_params = &unittest_params;
15208 	struct rte_cryptodev_info dev_info;
15209 
15210 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
15211 	uint64_t feat_flags = dev_info.feature_flags;
15212 
15213 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
15214 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
15215 		printf("Device doesn't support RAW data-path APIs.\n");
15216 		return TEST_SKIPPED;
15217 	}
15218 
15219 	int retval;
15220 
15221 	uint8_t *auth_tag, *plaintext;
15222 	uint16_t plaintext_pad_len;
15223 
15224 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
15225 			      "No GMAC length in the source data");
15226 
15227 	/* Verify the capabilities */
15228 	struct rte_cryptodev_sym_capability_idx cap_idx;
15229 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
15230 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
15231 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
15232 			&cap_idx) == NULL)
15233 		return TEST_SKIPPED;
15234 
15235 	retval = create_gmac_session(ts_params->valid_devs[0],
15236 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
15237 
15238 	if (retval == TEST_SKIPPED)
15239 		return TEST_SKIPPED;
15240 	if (retval < 0)
15241 		return retval;
15242 
15243 	if (tdata->plaintext.len > MBUF_SIZE)
15244 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
15245 	else
15246 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
15247 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
15248 			"Failed to allocate input buffer in mempool");
15249 
15250 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
15251 			rte_pktmbuf_tailroom(ut_params->ibuf));
15252 
15253 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
15254 	/*
15255 	 * Runtime generate the large plain text instead of use hard code
15256 	 * plain text vector. It is done to avoid create huge source file
15257 	 * with the test vector.
15258 	 */
15259 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
15260 		generate_gmac_large_plaintext(tdata->plaintext.data);
15261 
15262 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
15263 				plaintext_pad_len);
15264 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
15265 
15266 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
15267 	debug_hexdump(stdout, "plaintext:", plaintext,
15268 			tdata->plaintext.len);
15269 
15270 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
15271 			tdata);
15272 
15273 	if (retval < 0)
15274 		return retval;
15275 
15276 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
15277 
15278 	ut_params->op->sym->m_src = ut_params->ibuf;
15279 
15280 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
15281 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
15282 			ut_params->op);
15283 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
15284 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0,
15285 					       0);
15286 		if (retval != TEST_SUCCESS)
15287 			return retval;
15288 	} else
15289 		TEST_ASSERT_NOT_NULL(
15290 			process_crypto_request(ts_params->valid_devs[0],
15291 			ut_params->op), "failed to process sym crypto op");
15292 
15293 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
15294 			"crypto op processing failed");
15295 
15296 	if (ut_params->op->sym->m_dst) {
15297 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
15298 				uint8_t *, plaintext_pad_len);
15299 	} else {
15300 		auth_tag = plaintext + plaintext_pad_len;
15301 	}
15302 
15303 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
15304 
15305 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
15306 			auth_tag,
15307 			tdata->gmac_tag.data,
15308 			tdata->gmac_tag.len,
15309 			"GMAC Generated auth tag not as expected");
15310 
15311 	return 0;
15312 }
15313 
15314 static int
15315 test_AES_GMAC_authentication_test_case_1(void)
15316 {
15317 	return test_AES_GMAC_authentication(&gmac_test_case_1);
15318 }
15319 
15320 static int
15321 test_AES_GMAC_authentication_test_case_2(void)
15322 {
15323 	return test_AES_GMAC_authentication(&gmac_test_case_2);
15324 }
15325 
15326 static int
15327 test_AES_GMAC_authentication_test_case_3(void)
15328 {
15329 	return test_AES_GMAC_authentication(&gmac_test_case_3);
15330 }
15331 
15332 static int
15333 test_AES_GMAC_authentication_test_case_4(void)
15334 {
15335 	return test_AES_GMAC_authentication(&gmac_test_case_4);
15336 }
15337 
15338 static int
15339 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
15340 {
15341 	struct crypto_testsuite_params *ts_params = &testsuite_params;
15342 	struct crypto_unittest_params *ut_params = &unittest_params;
15343 	int retval;
15344 	uint32_t plaintext_pad_len;
15345 	uint8_t *plaintext;
15346 	struct rte_cryptodev_info dev_info;
15347 
15348 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
15349 	uint64_t feat_flags = dev_info.feature_flags;
15350 
15351 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
15352 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
15353 		printf("Device doesn't support RAW data-path APIs.\n");
15354 		return TEST_SKIPPED;
15355 	}
15356 
15357 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
15358 			      "No GMAC length in the source data");
15359 
15360 	/* Verify the capabilities */
15361 	struct rte_cryptodev_sym_capability_idx cap_idx;
15362 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
15363 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
15364 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
15365 			&cap_idx) == NULL)
15366 		return TEST_SKIPPED;
15367 
15368 	retval = create_gmac_session(ts_params->valid_devs[0],
15369 			tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
15370 
15371 	if (retval == TEST_SKIPPED)
15372 		return TEST_SKIPPED;
15373 	if (retval < 0)
15374 		return retval;
15375 
15376 	if (tdata->plaintext.len > MBUF_SIZE)
15377 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
15378 	else
15379 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
15380 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
15381 			"Failed to allocate input buffer in mempool");
15382 
15383 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
15384 			rte_pktmbuf_tailroom(ut_params->ibuf));
15385 
15386 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
15387 
15388 	/*
15389 	 * Runtime generate the large plain text instead of use hard code
15390 	 * plain text vector. It is done to avoid create huge source file
15391 	 * with the test vector.
15392 	 */
15393 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
15394 		generate_gmac_large_plaintext(tdata->plaintext.data);
15395 
15396 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
15397 				plaintext_pad_len);
15398 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
15399 
15400 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
15401 	debug_hexdump(stdout, "plaintext:", plaintext,
15402 			tdata->plaintext.len);
15403 
15404 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
15405 			tdata);
15406 
15407 	if (retval < 0)
15408 		return retval;
15409 
15410 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
15411 
15412 	ut_params->op->sym->m_src = ut_params->ibuf;
15413 
15414 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
15415 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
15416 			ut_params->op);
15417 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
15418 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0,
15419 					       0);
15420 		if (retval != TEST_SUCCESS)
15421 			return retval;
15422 	} else
15423 		TEST_ASSERT_NOT_NULL(
15424 			process_crypto_request(ts_params->valid_devs[0],
15425 			ut_params->op), "failed to process sym crypto op");
15426 
15427 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
15428 			"crypto op processing failed");
15429 
15430 	return 0;
15431 
15432 }
15433 
15434 static int
15435 test_AES_GMAC_authentication_verify_test_case_1(void)
15436 {
15437 	return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
15438 }
15439 
15440 static int
15441 test_AES_GMAC_authentication_verify_test_case_2(void)
15442 {
15443 	return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
15444 }
15445 
15446 static int
15447 test_AES_GMAC_authentication_verify_test_case_3(void)
15448 {
15449 	return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
15450 }
15451 
15452 static int
15453 test_AES_GMAC_authentication_verify_test_case_4(void)
15454 {
15455 	return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
15456 }
15457 
15458 static int
15459 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
15460 				uint32_t fragsz)
15461 {
15462 	struct crypto_testsuite_params *ts_params = &testsuite_params;
15463 	struct crypto_unittest_params *ut_params = &unittest_params;
15464 	struct rte_cryptodev_info dev_info;
15465 	uint64_t feature_flags;
15466 	unsigned int trn_data = 0;
15467 	void *digest_mem = NULL;
15468 	uint32_t segs = 1;
15469 	unsigned int to_trn = 0;
15470 	struct rte_mbuf *buf = NULL;
15471 	uint8_t *auth_tag, *plaintext;
15472 	int retval;
15473 
15474 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
15475 			      "No GMAC length in the source data");
15476 
15477 	/* Verify the capabilities */
15478 	struct rte_cryptodev_sym_capability_idx cap_idx;
15479 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
15480 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
15481 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
15482 			&cap_idx) == NULL)
15483 		return TEST_SKIPPED;
15484 
15485 	/* Check for any input SGL support */
15486 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
15487 	feature_flags = dev_info.feature_flags;
15488 
15489 	if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
15490 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
15491 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
15492 		return TEST_SKIPPED;
15493 
15494 	if (fragsz > tdata->plaintext.len)
15495 		fragsz = tdata->plaintext.len;
15496 
15497 	uint16_t plaintext_len = fragsz;
15498 
15499 	retval = create_gmac_session(ts_params->valid_devs[0],
15500 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
15501 
15502 	if (retval == TEST_SKIPPED)
15503 		return TEST_SKIPPED;
15504 	if (retval < 0)
15505 		return retval;
15506 
15507 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
15508 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
15509 			"Failed to allocate input buffer in mempool");
15510 
15511 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
15512 			rte_pktmbuf_tailroom(ut_params->ibuf));
15513 
15514 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
15515 				plaintext_len);
15516 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
15517 
15518 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
15519 
15520 	trn_data += plaintext_len;
15521 
15522 	buf = ut_params->ibuf;
15523 
15524 	/*
15525 	 * Loop until no more fragments
15526 	 */
15527 
15528 	while (trn_data < tdata->plaintext.len) {
15529 		++segs;
15530 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
15531 				(tdata->plaintext.len - trn_data) : fragsz;
15532 
15533 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
15534 		buf = buf->next;
15535 
15536 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
15537 				rte_pktmbuf_tailroom(buf));
15538 
15539 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
15540 				to_trn);
15541 
15542 		memcpy(plaintext, tdata->plaintext.data + trn_data,
15543 				to_trn);
15544 		trn_data += to_trn;
15545 		if (trn_data  == tdata->plaintext.len)
15546 			digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
15547 					tdata->gmac_tag.len);
15548 	}
15549 	ut_params->ibuf->nb_segs = segs;
15550 
15551 	/*
15552 	 * Place digest at the end of the last buffer
15553 	 */
15554 	uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
15555 
15556 	if (!digest_mem) {
15557 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
15558 				+ tdata->gmac_tag.len);
15559 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
15560 				tdata->plaintext.len);
15561 	}
15562 
15563 	retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
15564 			tdata, digest_mem, digest_phys);
15565 
15566 	if (retval < 0)
15567 		return retval;
15568 
15569 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
15570 
15571 	ut_params->op->sym->m_src = ut_params->ibuf;
15572 
15573 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
15574 		return TEST_SKIPPED;
15575 
15576 	TEST_ASSERT_NOT_NULL(
15577 		process_crypto_request(ts_params->valid_devs[0],
15578 		ut_params->op), "failed to process sym crypto op");
15579 
15580 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
15581 			"crypto op processing failed");
15582 
15583 	auth_tag = digest_mem;
15584 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
15585 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
15586 			auth_tag,
15587 			tdata->gmac_tag.data,
15588 			tdata->gmac_tag.len,
15589 			"GMAC Generated auth tag not as expected");
15590 
15591 	return 0;
15592 }
15593 
15594 /* Segment size not multiple of block size (16B) */
15595 static int
15596 test_AES_GMAC_authentication_SGL_40B(void)
15597 {
15598 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
15599 }
15600 
15601 static int
15602 test_AES_GMAC_authentication_SGL_80B(void)
15603 {
15604 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
15605 }
15606 
15607 static int
15608 test_AES_GMAC_authentication_SGL_2048B(void)
15609 {
15610 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
15611 }
15612 
15613 /* Segment size not multiple of block size (16B) */
15614 static int
15615 test_AES_GMAC_authentication_SGL_2047B(void)
15616 {
15617 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
15618 }
15619 
15620 struct test_crypto_vector {
15621 	enum rte_crypto_cipher_algorithm crypto_algo;
15622 	unsigned int cipher_offset;
15623 	unsigned int cipher_len;
15624 
15625 	struct {
15626 		uint8_t data[64];
15627 		unsigned int len;
15628 	} cipher_key;
15629 
15630 	struct {
15631 		uint8_t data[64];
15632 		unsigned int len;
15633 	} iv;
15634 
15635 	struct {
15636 		const uint8_t *data;
15637 		unsigned int len;
15638 	} plaintext;
15639 
15640 	struct {
15641 		const uint8_t *data;
15642 		unsigned int len;
15643 	} ciphertext;
15644 
15645 	enum rte_crypto_auth_algorithm auth_algo;
15646 	unsigned int auth_offset;
15647 
15648 	struct {
15649 		uint8_t data[128];
15650 		unsigned int len;
15651 	} auth_key;
15652 
15653 	struct {
15654 		const uint8_t *data;
15655 		unsigned int len;
15656 	} aad;
15657 
15658 	struct {
15659 		uint8_t data[128];
15660 		unsigned int len;
15661 	} digest;
15662 };
15663 
15664 static const struct test_crypto_vector
15665 hmac_sha1_test_crypto_vector = {
15666 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
15667 	.plaintext = {
15668 		.data = plaintext_hash,
15669 		.len = 512
15670 	},
15671 	.auth_key = {
15672 		.data = {
15673 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
15674 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
15675 			0xDE, 0xF4, 0xDE, 0xAD
15676 		},
15677 		.len = 20
15678 	},
15679 	.digest = {
15680 		.data = {
15681 			0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
15682 			0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
15683 			0x3F, 0x91, 0x64, 0x59
15684 		},
15685 		.len = 20
15686 	}
15687 };
15688 
15689 static const struct test_crypto_vector
15690 aes128_gmac_test_vector = {
15691 	.auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
15692 	.plaintext = {
15693 		.data = plaintext_hash,
15694 		.len = 512
15695 	},
15696 	.iv = {
15697 		.data = {
15698 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
15699 			0x08, 0x09, 0x0A, 0x0B
15700 		},
15701 		.len = 12
15702 	},
15703 	.auth_key = {
15704 		.data = {
15705 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
15706 			0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
15707 		},
15708 		.len = 16
15709 	},
15710 	.digest = {
15711 		.data = {
15712 			0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
15713 			0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
15714 		},
15715 		.len = 16
15716 	}
15717 };
15718 
15719 static const struct test_crypto_vector
15720 aes128cbc_hmac_sha1_test_vector = {
15721 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
15722 	.cipher_offset = 0,
15723 	.cipher_len = 512,
15724 	.cipher_key = {
15725 		.data = {
15726 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
15727 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
15728 		},
15729 		.len = 16
15730 	},
15731 	.iv = {
15732 		.data = {
15733 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
15734 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
15735 		},
15736 		.len = 16
15737 	},
15738 	.plaintext = {
15739 		.data = plaintext_hash,
15740 		.len = 512
15741 	},
15742 	.ciphertext = {
15743 		.data = ciphertext512_aes128cbc,
15744 		.len = 512
15745 	},
15746 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
15747 	.auth_offset = 0,
15748 	.auth_key = {
15749 		.data = {
15750 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
15751 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
15752 			0xDE, 0xF4, 0xDE, 0xAD
15753 		},
15754 		.len = 20
15755 	},
15756 	.digest = {
15757 		.data = {
15758 			0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
15759 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
15760 			0x18, 0x8C, 0x1D, 0x32
15761 		},
15762 		.len = 20
15763 	}
15764 };
15765 
15766 static const struct test_crypto_vector
15767 aes128cbc_hmac_sha1_aad_test_vector = {
15768 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
15769 	.cipher_offset = 8,
15770 	.cipher_len = 496,
15771 	.cipher_key = {
15772 		.data = {
15773 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
15774 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
15775 		},
15776 		.len = 16
15777 	},
15778 	.iv = {
15779 		.data = {
15780 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
15781 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
15782 		},
15783 		.len = 16
15784 	},
15785 	.plaintext = {
15786 		.data = plaintext_hash,
15787 		.len = 512
15788 	},
15789 	.ciphertext = {
15790 		.data = ciphertext512_aes128cbc_aad,
15791 		.len = 512
15792 	},
15793 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
15794 	.auth_offset = 0,
15795 	.auth_key = {
15796 		.data = {
15797 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
15798 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
15799 			0xDE, 0xF4, 0xDE, 0xAD
15800 		},
15801 		.len = 20
15802 	},
15803 	.digest = {
15804 		.data = {
15805 			0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
15806 			0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
15807 			0x62, 0x0F, 0xFB, 0x10
15808 		},
15809 		.len = 20
15810 	}
15811 };
15812 
15813 static void
15814 data_corruption(uint8_t *data)
15815 {
15816 	data[0] += 1;
15817 }
15818 
15819 static void
15820 tag_corruption(uint8_t *data, unsigned int tag_offset)
15821 {
15822 	data[tag_offset] += 1;
15823 }
15824 
15825 static int
15826 create_auth_session(struct crypto_unittest_params *ut_params,
15827 		uint8_t dev_id,
15828 		const struct test_crypto_vector *reference,
15829 		enum rte_crypto_auth_operation auth_op)
15830 {
15831 	struct crypto_testsuite_params *ts_params = &testsuite_params;
15832 	uint8_t auth_key[reference->auth_key.len + 1];
15833 
15834 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
15835 
15836 	/* Setup Authentication Parameters */
15837 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
15838 	ut_params->auth_xform.auth.op = auth_op;
15839 	ut_params->auth_xform.next = NULL;
15840 	ut_params->auth_xform.auth.algo = reference->auth_algo;
15841 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
15842 	ut_params->auth_xform.auth.key.data = auth_key;
15843 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
15844 
15845 	/* Create Crypto session*/
15846 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
15847 				&ut_params->auth_xform,
15848 				ts_params->session_mpool);
15849 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
15850 		return TEST_SKIPPED;
15851 
15852 	return 0;
15853 }
15854 
15855 static int
15856 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
15857 		uint8_t dev_id,
15858 		const struct test_crypto_vector *reference,
15859 		enum rte_crypto_auth_operation auth_op,
15860 		enum rte_crypto_cipher_operation cipher_op)
15861 {
15862 	struct crypto_testsuite_params *ts_params = &testsuite_params;
15863 	uint8_t cipher_key[reference->cipher_key.len + 1];
15864 	uint8_t auth_key[reference->auth_key.len + 1];
15865 
15866 	memcpy(cipher_key, reference->cipher_key.data,
15867 			reference->cipher_key.len);
15868 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
15869 
15870 	/* Setup Authentication Parameters */
15871 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
15872 	ut_params->auth_xform.auth.op = auth_op;
15873 	ut_params->auth_xform.auth.algo = reference->auth_algo;
15874 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
15875 	ut_params->auth_xform.auth.key.data = auth_key;
15876 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
15877 
15878 	if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
15879 		ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
15880 		ut_params->auth_xform.auth.iv.length = reference->iv.len;
15881 	} else {
15882 		ut_params->auth_xform.next = &ut_params->cipher_xform;
15883 
15884 		/* Setup Cipher Parameters */
15885 		ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
15886 		ut_params->cipher_xform.next = NULL;
15887 		ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
15888 		ut_params->cipher_xform.cipher.op = cipher_op;
15889 		ut_params->cipher_xform.cipher.key.data = cipher_key;
15890 		ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
15891 		ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
15892 		ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
15893 	}
15894 
15895 	/* Create Crypto session*/
15896 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
15897 				&ut_params->auth_xform,
15898 				ts_params->session_mpool);
15899 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
15900 		return TEST_SKIPPED;
15901 
15902 	return 0;
15903 }
15904 
15905 static int
15906 create_auth_operation(struct crypto_testsuite_params *ts_params,
15907 		struct crypto_unittest_params *ut_params,
15908 		const struct test_crypto_vector *reference,
15909 		unsigned int auth_generate)
15910 {
15911 	/* Generate Crypto op data structure */
15912 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
15913 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
15914 	TEST_ASSERT_NOT_NULL(ut_params->op,
15915 			"Failed to allocate pktmbuf offload");
15916 
15917 	/* Set crypto operation data parameters */
15918 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
15919 
15920 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
15921 
15922 	/* set crypto operation source mbuf */
15923 	sym_op->m_src = ut_params->ibuf;
15924 
15925 	/* digest */
15926 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
15927 			ut_params->ibuf, reference->digest.len);
15928 
15929 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
15930 			"no room to append auth tag");
15931 
15932 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
15933 			ut_params->ibuf, reference->plaintext.len);
15934 
15935 	if (auth_generate)
15936 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
15937 	else
15938 		memcpy(sym_op->auth.digest.data,
15939 				reference->digest.data,
15940 				reference->digest.len);
15941 
15942 	debug_hexdump(stdout, "digest:",
15943 			sym_op->auth.digest.data,
15944 			reference->digest.len);
15945 
15946 	sym_op->auth.data.length = reference->plaintext.len;
15947 	sym_op->auth.data.offset = 0;
15948 
15949 	return 0;
15950 }
15951 
15952 static int
15953 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
15954 		struct crypto_unittest_params *ut_params,
15955 		const struct test_crypto_vector *reference,
15956 		unsigned int auth_generate)
15957 {
15958 	/* Generate Crypto op data structure */
15959 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
15960 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
15961 	TEST_ASSERT_NOT_NULL(ut_params->op,
15962 			"Failed to allocate pktmbuf offload");
15963 
15964 	/* Set crypto operation data parameters */
15965 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
15966 
15967 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
15968 
15969 	/* set crypto operation source mbuf */
15970 	sym_op->m_src = ut_params->ibuf;
15971 
15972 	/* digest */
15973 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
15974 			ut_params->ibuf, reference->digest.len);
15975 
15976 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
15977 			"no room to append auth tag");
15978 
15979 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
15980 			ut_params->ibuf, reference->ciphertext.len);
15981 
15982 	if (auth_generate)
15983 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
15984 	else
15985 		memcpy(sym_op->auth.digest.data,
15986 				reference->digest.data,
15987 				reference->digest.len);
15988 
15989 	debug_hexdump(stdout, "digest:",
15990 			sym_op->auth.digest.data,
15991 			reference->digest.len);
15992 
15993 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
15994 			reference->iv.data, reference->iv.len);
15995 
15996 	sym_op->cipher.data.length = 0;
15997 	sym_op->cipher.data.offset = 0;
15998 
15999 	sym_op->auth.data.length = reference->plaintext.len;
16000 	sym_op->auth.data.offset = 0;
16001 
16002 	return 0;
16003 }
16004 
16005 static int
16006 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
16007 		struct crypto_unittest_params *ut_params,
16008 		const struct test_crypto_vector *reference,
16009 		unsigned int auth_generate)
16010 {
16011 	/* Generate Crypto op data structure */
16012 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
16013 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
16014 	TEST_ASSERT_NOT_NULL(ut_params->op,
16015 			"Failed to allocate pktmbuf offload");
16016 
16017 	/* Set crypto operation data parameters */
16018 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
16019 
16020 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
16021 
16022 	/* set crypto operation source mbuf */
16023 	sym_op->m_src = ut_params->ibuf;
16024 
16025 	/* digest */
16026 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
16027 			ut_params->ibuf, reference->digest.len);
16028 
16029 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
16030 			"no room to append auth tag");
16031 
16032 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
16033 			ut_params->ibuf, reference->ciphertext.len);
16034 
16035 	if (auth_generate)
16036 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
16037 	else
16038 		memcpy(sym_op->auth.digest.data,
16039 				reference->digest.data,
16040 				reference->digest.len);
16041 
16042 	debug_hexdump(stdout, "digest:",
16043 			sym_op->auth.digest.data,
16044 			reference->digest.len);
16045 
16046 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
16047 			reference->iv.data, reference->iv.len);
16048 
16049 	sym_op->cipher.data.length = reference->cipher_len;
16050 	sym_op->cipher.data.offset = reference->cipher_offset;
16051 
16052 	sym_op->auth.data.length = reference->plaintext.len;
16053 	sym_op->auth.data.offset = reference->auth_offset;
16054 
16055 	return 0;
16056 }
16057 
16058 static int
16059 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
16060 		struct crypto_unittest_params *ut_params,
16061 		const struct test_crypto_vector *reference)
16062 {
16063 	return create_auth_operation(ts_params, ut_params, reference, 0);
16064 }
16065 
16066 static int
16067 create_auth_verify_GMAC_operation(
16068 		struct crypto_testsuite_params *ts_params,
16069 		struct crypto_unittest_params *ut_params,
16070 		const struct test_crypto_vector *reference)
16071 {
16072 	return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
16073 }
16074 
16075 static int
16076 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
16077 		struct crypto_unittest_params *ut_params,
16078 		const struct test_crypto_vector *reference)
16079 {
16080 	return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
16081 }
16082 
16083 static int
16084 test_authentication_verify_fail_when_data_corruption(
16085 		struct crypto_testsuite_params *ts_params,
16086 		struct crypto_unittest_params *ut_params,
16087 		const struct test_crypto_vector *reference,
16088 		unsigned int data_corrupted)
16089 {
16090 	int retval;
16091 
16092 	uint8_t *plaintext;
16093 	struct rte_cryptodev_info dev_info;
16094 
16095 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
16096 	uint64_t feat_flags = dev_info.feature_flags;
16097 
16098 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
16099 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
16100 		printf("Device doesn't support RAW data-path APIs.\n");
16101 		return TEST_SKIPPED;
16102 	}
16103 
16104 	/* Verify the capabilities */
16105 	struct rte_cryptodev_sym_capability_idx cap_idx;
16106 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
16107 	cap_idx.algo.auth = reference->auth_algo;
16108 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
16109 			&cap_idx) == NULL)
16110 		return TEST_SKIPPED;
16111 
16112 
16113 	/* Create session */
16114 	retval = create_auth_session(ut_params,
16115 			ts_params->valid_devs[0],
16116 			reference,
16117 			RTE_CRYPTO_AUTH_OP_VERIFY);
16118 
16119 	if (retval == TEST_SKIPPED)
16120 		return TEST_SKIPPED;
16121 	if (retval < 0)
16122 		return retval;
16123 
16124 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
16125 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
16126 			"Failed to allocate input buffer in mempool");
16127 
16128 	/* clear mbuf payload */
16129 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
16130 			rte_pktmbuf_tailroom(ut_params->ibuf));
16131 
16132 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
16133 			reference->plaintext.len);
16134 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
16135 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
16136 
16137 	debug_hexdump(stdout, "plaintext:", plaintext,
16138 		reference->plaintext.len);
16139 
16140 	/* Create operation */
16141 	retval = create_auth_verify_operation(ts_params, ut_params, reference);
16142 
16143 	if (retval < 0)
16144 		return retval;
16145 
16146 	if (data_corrupted)
16147 		data_corruption(plaintext);
16148 	else
16149 		tag_corruption(plaintext, reference->plaintext.len);
16150 
16151 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
16152 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
16153 			ut_params->op);
16154 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
16155 			RTE_CRYPTO_OP_STATUS_SUCCESS,
16156 			"authentication not failed");
16157 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
16158 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0,
16159 					       0);
16160 		if (retval != TEST_SUCCESS)
16161 			return retval;
16162 	} else {
16163 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
16164 			ut_params->op);
16165 	}
16166 	if (ut_params->op == NULL)
16167 		return 0;
16168 	else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS)
16169 		return 0;
16170 
16171 	return -1;
16172 }
16173 
16174 static int
16175 test_authentication_verify_GMAC_fail_when_corruption(
16176 		struct crypto_testsuite_params *ts_params,
16177 		struct crypto_unittest_params *ut_params,
16178 		const struct test_crypto_vector *reference,
16179 		unsigned int data_corrupted)
16180 {
16181 	int retval;
16182 	uint8_t *plaintext;
16183 	struct rte_cryptodev_info dev_info;
16184 
16185 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
16186 	uint64_t feat_flags = dev_info.feature_flags;
16187 
16188 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
16189 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
16190 		printf("Device doesn't support RAW data-path APIs.\n");
16191 		return TEST_SKIPPED;
16192 	}
16193 
16194 	/* Verify the capabilities */
16195 	struct rte_cryptodev_sym_capability_idx cap_idx;
16196 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
16197 	cap_idx.algo.auth = reference->auth_algo;
16198 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
16199 			&cap_idx) == NULL)
16200 		return TEST_SKIPPED;
16201 
16202 	/* Create session */
16203 	retval = create_auth_cipher_session(ut_params,
16204 			ts_params->valid_devs[0],
16205 			reference,
16206 			RTE_CRYPTO_AUTH_OP_VERIFY,
16207 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
16208 	if (retval == TEST_SKIPPED)
16209 		return TEST_SKIPPED;
16210 	if (retval < 0)
16211 		return retval;
16212 
16213 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
16214 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
16215 			"Failed to allocate input buffer in mempool");
16216 
16217 	/* clear mbuf payload */
16218 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
16219 			rte_pktmbuf_tailroom(ut_params->ibuf));
16220 
16221 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
16222 			reference->plaintext.len);
16223 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
16224 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
16225 
16226 	debug_hexdump(stdout, "plaintext:", plaintext,
16227 		reference->plaintext.len);
16228 
16229 	/* Create operation */
16230 	retval = create_auth_verify_GMAC_operation(ts_params,
16231 			ut_params,
16232 			reference);
16233 
16234 	if (retval < 0)
16235 		return retval;
16236 
16237 	if (data_corrupted)
16238 		data_corruption(plaintext);
16239 	else
16240 		tag_corruption(plaintext, reference->aad.len);
16241 
16242 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
16243 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
16244 			ut_params->op);
16245 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
16246 			RTE_CRYPTO_OP_STATUS_SUCCESS,
16247 			"authentication not failed");
16248 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
16249 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 1, 0,
16250 					       0);
16251 		if (retval != TEST_SUCCESS)
16252 			return retval;
16253 	} else {
16254 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
16255 			ut_params->op);
16256 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
16257 	}
16258 
16259 	return 0;
16260 }
16261 
16262 static int
16263 test_authenticated_decryption_fail_when_corruption(
16264 		struct crypto_testsuite_params *ts_params,
16265 		struct crypto_unittest_params *ut_params,
16266 		const struct test_crypto_vector *reference,
16267 		unsigned int data_corrupted)
16268 {
16269 	int retval;
16270 
16271 	uint8_t *ciphertext;
16272 	struct rte_cryptodev_info dev_info;
16273 
16274 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
16275 	uint64_t feat_flags = dev_info.feature_flags;
16276 
16277 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
16278 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
16279 		printf("Device doesn't support RAW data-path APIs.\n");
16280 		return TEST_SKIPPED;
16281 	}
16282 
16283 	/* Verify the capabilities */
16284 	struct rte_cryptodev_sym_capability_idx cap_idx;
16285 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
16286 	cap_idx.algo.auth = reference->auth_algo;
16287 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
16288 			&cap_idx) == NULL)
16289 		return TEST_SKIPPED;
16290 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
16291 	cap_idx.algo.cipher = reference->crypto_algo;
16292 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
16293 			&cap_idx) == NULL)
16294 		return TEST_SKIPPED;
16295 
16296 	/* Create session */
16297 	retval = create_auth_cipher_session(ut_params,
16298 			ts_params->valid_devs[0],
16299 			reference,
16300 			RTE_CRYPTO_AUTH_OP_VERIFY,
16301 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
16302 	if (retval == TEST_SKIPPED)
16303 		return TEST_SKIPPED;
16304 	if (retval < 0)
16305 		return retval;
16306 
16307 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
16308 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
16309 			"Failed to allocate input buffer in mempool");
16310 
16311 	/* clear mbuf payload */
16312 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
16313 			rte_pktmbuf_tailroom(ut_params->ibuf));
16314 
16315 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
16316 			reference->ciphertext.len);
16317 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
16318 	memcpy(ciphertext, reference->ciphertext.data,
16319 			reference->ciphertext.len);
16320 
16321 	/* Create operation */
16322 	retval = create_cipher_auth_verify_operation(ts_params,
16323 			ut_params,
16324 			reference);
16325 
16326 	if (retval < 0)
16327 		return retval;
16328 
16329 	if (data_corrupted)
16330 		data_corruption(ciphertext);
16331 	else
16332 		tag_corruption(ciphertext, reference->ciphertext.len);
16333 
16334 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
16335 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
16336 			ut_params->op);
16337 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
16338 			RTE_CRYPTO_OP_STATUS_SUCCESS,
16339 			"authentication not failed");
16340 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
16341 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0,
16342 					       0);
16343 		if (retval != TEST_SUCCESS)
16344 			return retval;
16345 	} else {
16346 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
16347 			ut_params->op);
16348 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
16349 	}
16350 
16351 	return 0;
16352 }
16353 
16354 static int
16355 test_authenticated_encrypt_with_esn(
16356 		struct crypto_testsuite_params *ts_params,
16357 		struct crypto_unittest_params *ut_params,
16358 		const struct test_crypto_vector *reference)
16359 {
16360 	int retval;
16361 
16362 	uint8_t *authciphertext, *plaintext, *auth_tag;
16363 	uint16_t plaintext_pad_len;
16364 	uint8_t cipher_key[reference->cipher_key.len + 1];
16365 	uint8_t auth_key[reference->auth_key.len + 1];
16366 	struct rte_cryptodev_info dev_info;
16367 
16368 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
16369 	uint64_t feat_flags = dev_info.feature_flags;
16370 
16371 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
16372 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
16373 		printf("Device doesn't support RAW data-path APIs.\n");
16374 		return TEST_SKIPPED;
16375 	}
16376 
16377 	/* Verify the capabilities */
16378 	struct rte_cryptodev_sym_capability_idx cap_idx;
16379 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
16380 	cap_idx.algo.auth = reference->auth_algo;
16381 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
16382 			&cap_idx) == NULL)
16383 		return TEST_SKIPPED;
16384 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
16385 	cap_idx.algo.cipher = reference->crypto_algo;
16386 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
16387 			&cap_idx) == NULL)
16388 		return TEST_SKIPPED;
16389 
16390 	/* Create session */
16391 	memcpy(cipher_key, reference->cipher_key.data,
16392 			reference->cipher_key.len);
16393 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
16394 
16395 	/* Setup Cipher Parameters */
16396 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
16397 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
16398 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
16399 	ut_params->cipher_xform.cipher.key.data = cipher_key;
16400 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
16401 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
16402 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
16403 
16404 	ut_params->cipher_xform.next = &ut_params->auth_xform;
16405 
16406 	/* Setup Authentication Parameters */
16407 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
16408 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
16409 	ut_params->auth_xform.auth.algo = reference->auth_algo;
16410 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
16411 	ut_params->auth_xform.auth.key.data = auth_key;
16412 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
16413 	ut_params->auth_xform.next = NULL;
16414 
16415 	/* Create Crypto session*/
16416 	ut_params->sess = rte_cryptodev_sym_session_create(
16417 			ts_params->valid_devs[0], &ut_params->cipher_xform,
16418 			ts_params->session_mpool);
16419 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
16420 		return TEST_SKIPPED;
16421 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
16422 
16423 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
16424 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
16425 			"Failed to allocate input buffer in mempool");
16426 
16427 	/* clear mbuf payload */
16428 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
16429 			rte_pktmbuf_tailroom(ut_params->ibuf));
16430 
16431 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
16432 			reference->plaintext.len);
16433 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
16434 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
16435 
16436 	/* Create operation */
16437 	retval = create_cipher_auth_operation(ts_params,
16438 			ut_params,
16439 			reference, 0);
16440 
16441 	if (retval < 0)
16442 		return retval;
16443 
16444 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
16445 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
16446 			ut_params->op);
16447 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
16448 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0,
16449 					       0);
16450 		if (retval != TEST_SUCCESS)
16451 			return retval;
16452 	} else
16453 		ut_params->op = process_crypto_request(
16454 			ts_params->valid_devs[0], ut_params->op);
16455 
16456 	TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
16457 
16458 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
16459 			"crypto op processing failed");
16460 
16461 	plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
16462 
16463 	authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
16464 			ut_params->op->sym->auth.data.offset);
16465 	auth_tag = authciphertext + plaintext_pad_len;
16466 	debug_hexdump(stdout, "ciphertext:", authciphertext,
16467 			reference->ciphertext.len);
16468 	debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
16469 
16470 	/* Validate obuf */
16471 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
16472 			authciphertext,
16473 			reference->ciphertext.data,
16474 			reference->ciphertext.len,
16475 			"Ciphertext data not as expected");
16476 
16477 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
16478 			auth_tag,
16479 			reference->digest.data,
16480 			reference->digest.len,
16481 			"Generated digest not as expected");
16482 
16483 	return TEST_SUCCESS;
16484 
16485 }
16486 
16487 static int
16488 test_authenticated_decrypt_with_esn(
16489 		struct crypto_testsuite_params *ts_params,
16490 		struct crypto_unittest_params *ut_params,
16491 		const struct test_crypto_vector *reference)
16492 {
16493 	int retval;
16494 
16495 	uint8_t *ciphertext;
16496 	uint8_t cipher_key[reference->cipher_key.len + 1];
16497 	uint8_t auth_key[reference->auth_key.len + 1];
16498 	struct rte_cryptodev_info dev_info;
16499 
16500 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
16501 	uint64_t feat_flags = dev_info.feature_flags;
16502 
16503 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
16504 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
16505 		printf("Device doesn't support RAW data-path APIs.\n");
16506 		return TEST_SKIPPED;
16507 	}
16508 
16509 	/* Verify the capabilities */
16510 	struct rte_cryptodev_sym_capability_idx cap_idx;
16511 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
16512 	cap_idx.algo.auth = reference->auth_algo;
16513 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
16514 			&cap_idx) == NULL)
16515 		return TEST_SKIPPED;
16516 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
16517 	cap_idx.algo.cipher = reference->crypto_algo;
16518 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
16519 			&cap_idx) == NULL)
16520 		return TEST_SKIPPED;
16521 
16522 	/* Create session */
16523 	memcpy(cipher_key, reference->cipher_key.data,
16524 			reference->cipher_key.len);
16525 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
16526 
16527 	/* Setup Authentication Parameters */
16528 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
16529 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
16530 	ut_params->auth_xform.auth.algo = reference->auth_algo;
16531 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
16532 	ut_params->auth_xform.auth.key.data = auth_key;
16533 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
16534 	ut_params->auth_xform.next = &ut_params->cipher_xform;
16535 
16536 	/* Setup Cipher Parameters */
16537 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
16538 	ut_params->cipher_xform.next = NULL;
16539 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
16540 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
16541 	ut_params->cipher_xform.cipher.key.data = cipher_key;
16542 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
16543 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
16544 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
16545 
16546 	/* Create Crypto session*/
16547 	ut_params->sess = rte_cryptodev_sym_session_create(
16548 			ts_params->valid_devs[0], &ut_params->auth_xform,
16549 			ts_params->session_mpool);
16550 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
16551 		return TEST_SKIPPED;
16552 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
16553 
16554 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
16555 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
16556 			"Failed to allocate input buffer in mempool");
16557 
16558 	/* clear mbuf payload */
16559 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
16560 			rte_pktmbuf_tailroom(ut_params->ibuf));
16561 
16562 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
16563 			reference->ciphertext.len);
16564 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
16565 	memcpy(ciphertext, reference->ciphertext.data,
16566 			reference->ciphertext.len);
16567 
16568 	/* Create operation */
16569 	retval = create_cipher_auth_verify_operation(ts_params,
16570 			ut_params,
16571 			reference);
16572 
16573 	if (retval < 0)
16574 		return retval;
16575 
16576 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
16577 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
16578 			ut_params->op);
16579 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
16580 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 1, 1, 0,
16581 					       0);
16582 		if (retval != TEST_SUCCESS)
16583 			return retval;
16584 	} else
16585 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
16586 			ut_params->op);
16587 
16588 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
16589 	TEST_ASSERT_EQUAL(ut_params->op->status,
16590 			RTE_CRYPTO_OP_STATUS_SUCCESS,
16591 			"crypto op processing passed");
16592 
16593 	ut_params->obuf = ut_params->op->sym->m_src;
16594 	TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
16595 
16596 	return 0;
16597 }
16598 
16599 static int
16600 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
16601 		const struct aead_test_data *tdata,
16602 		void *digest_mem, uint64_t digest_phys)
16603 {
16604 	struct crypto_testsuite_params *ts_params = &testsuite_params;
16605 	struct crypto_unittest_params *ut_params = &unittest_params;
16606 
16607 	const unsigned int auth_tag_len = tdata->auth_tag.len;
16608 	const unsigned int iv_len = tdata->iv.len;
16609 	unsigned int aad_len = tdata->aad.len;
16610 	unsigned int aad_len_pad = 0;
16611 
16612 	/* Generate Crypto op data structure */
16613 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
16614 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
16615 	TEST_ASSERT_NOT_NULL(ut_params->op,
16616 		"Failed to allocate symmetric crypto operation struct");
16617 
16618 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
16619 
16620 	sym_op->aead.digest.data = digest_mem;
16621 
16622 	TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
16623 			"no room to append digest");
16624 
16625 	sym_op->aead.digest.phys_addr = digest_phys;
16626 
16627 	if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
16628 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
16629 				auth_tag_len);
16630 		debug_hexdump(stdout, "digest:",
16631 				sym_op->aead.digest.data,
16632 				auth_tag_len);
16633 	}
16634 
16635 	/* Append aad data */
16636 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
16637 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
16638 				uint8_t *, IV_OFFSET);
16639 
16640 		/* Copy IV 1 byte after the IV pointer, according to the API */
16641 		rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
16642 
16643 		aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
16644 
16645 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
16646 				ut_params->ibuf, aad_len);
16647 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
16648 				"no room to prepend aad");
16649 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
16650 				ut_params->ibuf);
16651 
16652 		memset(sym_op->aead.aad.data, 0, aad_len);
16653 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
16654 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
16655 
16656 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
16657 		debug_hexdump(stdout, "aad:",
16658 				sym_op->aead.aad.data, aad_len);
16659 	} else {
16660 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
16661 				uint8_t *, IV_OFFSET);
16662 
16663 		rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
16664 
16665 		aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
16666 
16667 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
16668 				ut_params->ibuf, aad_len_pad);
16669 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
16670 				"no room to prepend aad");
16671 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
16672 				ut_params->ibuf);
16673 
16674 		memset(sym_op->aead.aad.data, 0, aad_len);
16675 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
16676 
16677 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
16678 		debug_hexdump(stdout, "aad:",
16679 				sym_op->aead.aad.data, aad_len);
16680 	}
16681 
16682 	sym_op->aead.data.length = tdata->plaintext.len;
16683 	sym_op->aead.data.offset = aad_len_pad;
16684 
16685 	return 0;
16686 }
16687 
16688 #define SGL_MAX_NO	16
16689 
16690 static int
16691 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
16692 		const int oop, uint32_t fragsz, uint32_t fragsz_oop)
16693 {
16694 	struct crypto_testsuite_params *ts_params = &testsuite_params;
16695 	struct crypto_unittest_params *ut_params = &unittest_params;
16696 	struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
16697 	int retval;
16698 	int to_trn = 0;
16699 	int to_trn_tbl[SGL_MAX_NO];
16700 	int segs = 1;
16701 	unsigned int trn_data = 0;
16702 	uint8_t *plaintext, *ciphertext, *auth_tag;
16703 	struct rte_cryptodev_info dev_info;
16704 
16705 	/* Verify the capabilities */
16706 	struct rte_cryptodev_sym_capability_idx cap_idx;
16707 	const struct rte_cryptodev_symmetric_capability *capability;
16708 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
16709 	cap_idx.algo.aead = tdata->algo;
16710 	capability = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], &cap_idx);
16711 	if (capability == NULL)
16712 		return TEST_SKIPPED;
16713 	if (rte_cryptodev_sym_capability_check_aead(capability, tdata->key.len,
16714 			tdata->auth_tag.len, tdata->aad.len, tdata->iv.len))
16715 		return TEST_SKIPPED;
16716 
16717 	/*
16718 	 * SGL not supported on AESNI_MB PMD CPU crypto,
16719 	 * OOP not supported on AESNI_GCM CPU crypto
16720 	 */
16721 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO &&
16722 			(gbl_driver_id == rte_cryptodev_driver_id_get(
16723 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) || oop))
16724 		return TEST_SKIPPED;
16725 
16726 	/* Detailed check for the particular SGL support flag */
16727 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
16728 	if (!oop) {
16729 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
16730 		if (sgl_in && (!(dev_info.feature_flags &
16731 				RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
16732 			return TEST_SKIPPED;
16733 
16734 		uint64_t feat_flags = dev_info.feature_flags;
16735 
16736 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
16737 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
16738 			printf("Device doesn't support RAW data-path APIs.\n");
16739 			return TEST_SKIPPED;
16740 		}
16741 	} else {
16742 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
16743 		unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
16744 				tdata->plaintext.len;
16745 		/* Raw data path API does not support OOP */
16746 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
16747 			return TEST_SKIPPED;
16748 		if (sgl_in && !sgl_out) {
16749 			if (!(dev_info.feature_flags &
16750 					RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
16751 				return TEST_SKIPPED;
16752 		} else if (!sgl_in && sgl_out) {
16753 			if (!(dev_info.feature_flags &
16754 					RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
16755 				return TEST_SKIPPED;
16756 		} else if (sgl_in && sgl_out) {
16757 			if (!(dev_info.feature_flags &
16758 					RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
16759 				return TEST_SKIPPED;
16760 		}
16761 	}
16762 
16763 	if (fragsz > tdata->plaintext.len)
16764 		fragsz = tdata->plaintext.len;
16765 
16766 	uint16_t plaintext_len = fragsz;
16767 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
16768 
16769 	if (fragsz_oop > tdata->plaintext.len)
16770 		frag_size_oop = tdata->plaintext.len;
16771 
16772 	int ecx = 0;
16773 	void *digest_mem = NULL;
16774 
16775 	uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
16776 
16777 	if (tdata->plaintext.len % fragsz != 0) {
16778 		if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
16779 			return 1;
16780 	}	else {
16781 		if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
16782 			return 1;
16783 	}
16784 
16785 	/*
16786 	 * For out-op-place we need to alloc another mbuf
16787 	 */
16788 	if (oop) {
16789 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
16790 		rte_pktmbuf_append(ut_params->obuf,
16791 				frag_size_oop + prepend_len);
16792 		buf_oop = ut_params->obuf;
16793 	}
16794 
16795 	/* Create AEAD session */
16796 	retval = create_aead_session(ts_params->valid_devs[0],
16797 			tdata->algo,
16798 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
16799 			tdata->key.data, tdata->key.len,
16800 			tdata->aad.len, tdata->auth_tag.len,
16801 			tdata->iv.len);
16802 	if (retval < 0)
16803 		return retval;
16804 
16805 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
16806 
16807 	/* clear mbuf payload */
16808 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
16809 			rte_pktmbuf_tailroom(ut_params->ibuf));
16810 
16811 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
16812 			plaintext_len);
16813 
16814 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
16815 
16816 	trn_data += plaintext_len;
16817 
16818 	buf = ut_params->ibuf;
16819 
16820 	/*
16821 	 * Loop until no more fragments
16822 	 */
16823 
16824 	while (trn_data < tdata->plaintext.len) {
16825 		++segs;
16826 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
16827 				(tdata->plaintext.len - trn_data) : fragsz;
16828 
16829 		to_trn_tbl[ecx++] = to_trn;
16830 
16831 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
16832 		buf = buf->next;
16833 
16834 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
16835 				rte_pktmbuf_tailroom(buf));
16836 
16837 		/* OOP */
16838 		if (oop && !fragsz_oop) {
16839 			buf_last_oop = buf_oop->next =
16840 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
16841 			buf_oop = buf_oop->next;
16842 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
16843 					0, rte_pktmbuf_tailroom(buf_oop));
16844 			rte_pktmbuf_append(buf_oop, to_trn);
16845 		}
16846 
16847 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
16848 				to_trn);
16849 
16850 		memcpy(plaintext, tdata->plaintext.data + trn_data,
16851 				to_trn);
16852 		trn_data += to_trn;
16853 		if (trn_data  == tdata->plaintext.len) {
16854 			if (oop) {
16855 				if (!fragsz_oop)
16856 					digest_mem = rte_pktmbuf_append(buf_oop,
16857 						tdata->auth_tag.len);
16858 			} else
16859 				digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
16860 					tdata->auth_tag.len);
16861 		}
16862 	}
16863 
16864 	uint64_t digest_phys = 0;
16865 
16866 	ut_params->ibuf->nb_segs = segs;
16867 
16868 	segs = 1;
16869 	if (fragsz_oop && oop) {
16870 		to_trn = 0;
16871 		ecx = 0;
16872 
16873 		if (frag_size_oop == tdata->plaintext.len) {
16874 			digest_mem = rte_pktmbuf_append(ut_params->obuf,
16875 				tdata->auth_tag.len);
16876 
16877 			digest_phys = rte_pktmbuf_iova_offset(
16878 					ut_params->obuf,
16879 					tdata->plaintext.len + prepend_len);
16880 		}
16881 
16882 		trn_data = frag_size_oop;
16883 		while (trn_data < tdata->plaintext.len) {
16884 			++segs;
16885 			to_trn =
16886 				(tdata->plaintext.len - trn_data <
16887 						frag_size_oop) ?
16888 				(tdata->plaintext.len - trn_data) :
16889 						frag_size_oop;
16890 
16891 			to_trn_tbl[ecx++] = to_trn;
16892 
16893 			buf_last_oop = buf_oop->next =
16894 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
16895 			buf_oop = buf_oop->next;
16896 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
16897 					0, rte_pktmbuf_tailroom(buf_oop));
16898 			rte_pktmbuf_append(buf_oop, to_trn);
16899 
16900 			trn_data += to_trn;
16901 
16902 			if (trn_data  == tdata->plaintext.len) {
16903 				digest_mem = rte_pktmbuf_append(buf_oop,
16904 					tdata->auth_tag.len);
16905 			}
16906 		}
16907 
16908 		ut_params->obuf->nb_segs = segs;
16909 	}
16910 
16911 	/*
16912 	 * Place digest at the end of the last buffer
16913 	 */
16914 	if (!digest_phys)
16915 		digest_phys = rte_pktmbuf_iova(buf) + to_trn;
16916 	if (oop && buf_last_oop)
16917 		digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
16918 
16919 	if (!digest_mem && !oop) {
16920 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
16921 				+ tdata->auth_tag.len);
16922 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
16923 				tdata->plaintext.len);
16924 	}
16925 
16926 	/* Create AEAD operation */
16927 	retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
16928 			tdata, digest_mem, digest_phys);
16929 
16930 	if (retval < 0)
16931 		return retval;
16932 
16933 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
16934 
16935 	ut_params->op->sym->m_src = ut_params->ibuf;
16936 	if (oop)
16937 		ut_params->op->sym->m_dst = ut_params->obuf;
16938 
16939 	/* Process crypto operation */
16940 	if (oop == IN_PLACE &&
16941 			gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
16942 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
16943 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
16944 		retval = process_sym_raw_dp_op(ts_params->valid_devs[0], 0, ut_params->op, 0, 0, 0,
16945 					       0);
16946 		if (retval != TEST_SUCCESS)
16947 			return retval;
16948 	} else
16949 		TEST_ASSERT_NOT_NULL(
16950 			process_crypto_request(ts_params->valid_devs[0],
16951 			ut_params->op), "failed to process sym crypto op");
16952 
16953 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
16954 			"crypto op processing failed");
16955 
16956 
16957 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
16958 			uint8_t *, prepend_len);
16959 	if (oop) {
16960 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
16961 				uint8_t *, prepend_len);
16962 	}
16963 
16964 	if (fragsz_oop)
16965 		fragsz = fragsz_oop;
16966 
16967 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
16968 			ciphertext,
16969 			tdata->ciphertext.data,
16970 			fragsz,
16971 			"Ciphertext data not as expected");
16972 
16973 	buf = ut_params->op->sym->m_src->next;
16974 	if (oop)
16975 		buf = ut_params->op->sym->m_dst->next;
16976 
16977 	unsigned int off = fragsz;
16978 
16979 	ecx = 0;
16980 	while (buf) {
16981 		ciphertext = rte_pktmbuf_mtod(buf,
16982 				uint8_t *);
16983 
16984 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
16985 				ciphertext,
16986 				tdata->ciphertext.data + off,
16987 				to_trn_tbl[ecx],
16988 				"Ciphertext data not as expected");
16989 
16990 		off += to_trn_tbl[ecx++];
16991 		buf = buf->next;
16992 	}
16993 
16994 	auth_tag = digest_mem;
16995 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
16996 			auth_tag,
16997 			tdata->auth_tag.data,
16998 			tdata->auth_tag.len,
16999 			"Generated auth tag not as expected");
17000 
17001 	return 0;
17002 }
17003 
17004 static int
17005 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
17006 {
17007 	return test_authenticated_encryption_SGL(
17008 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
17009 }
17010 
17011 static int
17012 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
17013 {
17014 	return test_authenticated_encryption_SGL(
17015 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
17016 }
17017 
17018 static int
17019 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
17020 {
17021 	return test_authenticated_encryption_SGL(
17022 			&gcm_test_case_8, OUT_OF_PLACE, 400,
17023 			gcm_test_case_8.plaintext.len);
17024 }
17025 
17026 static int
17027 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
17028 {
17029 	/* This test is not for OPENSSL PMD */
17030 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
17031 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
17032 		return TEST_SKIPPED;
17033 
17034 	return test_authenticated_encryption_SGL(
17035 			&gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
17036 }
17037 
17038 static int
17039 test_authentication_verify_fail_when_data_corrupted(
17040 		struct crypto_testsuite_params *ts_params,
17041 		struct crypto_unittest_params *ut_params,
17042 		const struct test_crypto_vector *reference)
17043 {
17044 	return test_authentication_verify_fail_when_data_corruption(
17045 			ts_params, ut_params, reference, 1);
17046 }
17047 
17048 static int
17049 test_authentication_verify_fail_when_tag_corrupted(
17050 		struct crypto_testsuite_params *ts_params,
17051 		struct crypto_unittest_params *ut_params,
17052 		const struct test_crypto_vector *reference)
17053 {
17054 	return test_authentication_verify_fail_when_data_corruption(
17055 			ts_params, ut_params, reference, 0);
17056 }
17057 
17058 static int
17059 test_authentication_verify_GMAC_fail_when_data_corrupted(
17060 		struct crypto_testsuite_params *ts_params,
17061 		struct crypto_unittest_params *ut_params,
17062 		const struct test_crypto_vector *reference)
17063 {
17064 	return test_authentication_verify_GMAC_fail_when_corruption(
17065 			ts_params, ut_params, reference, 1);
17066 }
17067 
17068 static int
17069 test_authentication_verify_GMAC_fail_when_tag_corrupted(
17070 		struct crypto_testsuite_params *ts_params,
17071 		struct crypto_unittest_params *ut_params,
17072 		const struct test_crypto_vector *reference)
17073 {
17074 	return test_authentication_verify_GMAC_fail_when_corruption(
17075 			ts_params, ut_params, reference, 0);
17076 }
17077 
17078 static int
17079 test_authenticated_decryption_fail_when_data_corrupted(
17080 		struct crypto_testsuite_params *ts_params,
17081 		struct crypto_unittest_params *ut_params,
17082 		const struct test_crypto_vector *reference)
17083 {
17084 	return test_authenticated_decryption_fail_when_corruption(
17085 			ts_params, ut_params, reference, 1);
17086 }
17087 
17088 static int
17089 test_authenticated_decryption_fail_when_tag_corrupted(
17090 		struct crypto_testsuite_params *ts_params,
17091 		struct crypto_unittest_params *ut_params,
17092 		const struct test_crypto_vector *reference)
17093 {
17094 	return test_authenticated_decryption_fail_when_corruption(
17095 			ts_params, ut_params, reference, 0);
17096 }
17097 
17098 static int
17099 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
17100 {
17101 	return test_authentication_verify_fail_when_data_corrupted(
17102 			&testsuite_params, &unittest_params,
17103 			&hmac_sha1_test_crypto_vector);
17104 }
17105 
17106 static int
17107 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
17108 {
17109 	return test_authentication_verify_fail_when_tag_corrupted(
17110 			&testsuite_params, &unittest_params,
17111 			&hmac_sha1_test_crypto_vector);
17112 }
17113 
17114 static int
17115 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
17116 {
17117 	return test_authentication_verify_GMAC_fail_when_data_corrupted(
17118 			&testsuite_params, &unittest_params,
17119 			&aes128_gmac_test_vector);
17120 }
17121 
17122 static int
17123 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
17124 {
17125 	return test_authentication_verify_GMAC_fail_when_tag_corrupted(
17126 			&testsuite_params, &unittest_params,
17127 			&aes128_gmac_test_vector);
17128 }
17129 
17130 static int
17131 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
17132 {
17133 	return test_authenticated_decryption_fail_when_data_corrupted(
17134 			&testsuite_params,
17135 			&unittest_params,
17136 			&aes128cbc_hmac_sha1_test_vector);
17137 }
17138 
17139 static int
17140 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
17141 {
17142 	return test_authenticated_decryption_fail_when_tag_corrupted(
17143 			&testsuite_params,
17144 			&unittest_params,
17145 			&aes128cbc_hmac_sha1_test_vector);
17146 }
17147 
17148 static int
17149 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
17150 {
17151 	return test_authenticated_encrypt_with_esn(
17152 			&testsuite_params,
17153 			&unittest_params,
17154 			&aes128cbc_hmac_sha1_aad_test_vector);
17155 }
17156 
17157 static int
17158 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
17159 {
17160 	return test_authenticated_decrypt_with_esn(
17161 			&testsuite_params,
17162 			&unittest_params,
17163 			&aes128cbc_hmac_sha1_aad_test_vector);
17164 }
17165 
17166 static int
17167 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
17168 {
17169 	return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
17170 }
17171 
17172 static int
17173 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
17174 {
17175 	return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
17176 }
17177 
17178 static int
17179 test_chacha20_poly1305_encrypt_SGL_out_of_place(void)
17180 {
17181 	return test_authenticated_encryption_SGL(
17182 		&chacha20_poly1305_case_2, OUT_OF_PLACE, 32,
17183 		chacha20_poly1305_case_2.plaintext.len);
17184 }
17185 
17186 #ifdef RTE_CRYPTO_SCHEDULER
17187 
17188 /* global AESNI worker IDs for the scheduler test */
17189 uint8_t aesni_ids[2];
17190 
17191 static int
17192 scheduler_testsuite_setup(void)
17193 {
17194 	uint32_t i = 0;
17195 	int32_t nb_devs, ret;
17196 	char vdev_args[VDEV_ARGS_SIZE] = {""};
17197 	char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
17198 		"ordering=enable,name=cryptodev_test_scheduler,corelist="};
17199 	uint16_t worker_core_count = 0;
17200 	uint16_t socket_id = 0;
17201 
17202 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
17203 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
17204 
17205 		/* Identify the Worker Cores
17206 		 * Use 2 worker cores for the device args
17207 		 */
17208 		RTE_LCORE_FOREACH_WORKER(i) {
17209 			if (worker_core_count > 1)
17210 				break;
17211 			snprintf(vdev_args, sizeof(vdev_args),
17212 					"%s%d", temp_str, i);
17213 			strcpy(temp_str, vdev_args);
17214 			strlcat(temp_str, ";", sizeof(temp_str));
17215 			worker_core_count++;
17216 			socket_id = rte_lcore_to_socket_id(i);
17217 		}
17218 		if (worker_core_count != 2) {
17219 			RTE_LOG(ERR, USER1,
17220 				"Cryptodev scheduler test require at least "
17221 				"two worker cores to run. "
17222 				"Please use the correct coremask.\n");
17223 			return TEST_FAILED;
17224 		}
17225 		strcpy(temp_str, vdev_args);
17226 		snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
17227 				temp_str, socket_id);
17228 		RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
17229 		nb_devs = rte_cryptodev_device_count_by_driver(
17230 				rte_cryptodev_driver_id_get(
17231 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
17232 		if (nb_devs < 1) {
17233 			ret = rte_vdev_init(
17234 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
17235 					vdev_args);
17236 			TEST_ASSERT(ret == 0,
17237 				"Failed to create instance %u of pmd : %s",
17238 				i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
17239 		}
17240 	}
17241 	return testsuite_setup();
17242 }
17243 
17244 static int
17245 test_scheduler_attach_worker_op(void)
17246 {
17247 	struct crypto_testsuite_params *ts_params = &testsuite_params;
17248 	uint8_t sched_id = ts_params->valid_devs[0];
17249 	uint32_t i, nb_devs_attached = 0;
17250 	int ret;
17251 	char vdev_name[32];
17252 	unsigned int count = rte_cryptodev_count();
17253 
17254 	/* create 2 AESNI_MB vdevs on top of existing devices */
17255 	for (i = count; i < count + 2; i++) {
17256 		snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
17257 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
17258 				i);
17259 		ret = rte_vdev_init(vdev_name, NULL);
17260 
17261 		TEST_ASSERT(ret == 0,
17262 			"Failed to create instance %u of"
17263 			" pmd : %s",
17264 			i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
17265 
17266 		if (ret < 0) {
17267 			RTE_LOG(ERR, USER1,
17268 				"Failed to create 2 AESNI MB PMDs.\n");
17269 			return TEST_SKIPPED;
17270 		}
17271 	}
17272 
17273 	/* attach 2 AESNI_MB cdevs */
17274 	for (i = count; i < count + 2; i++) {
17275 		struct rte_cryptodev_info info;
17276 		unsigned int session_size;
17277 
17278 		rte_cryptodev_info_get(i, &info);
17279 		if (info.driver_id != rte_cryptodev_driver_id_get(
17280 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
17281 			continue;
17282 
17283 		session_size = rte_cryptodev_sym_get_private_session_size(i);
17284 		/*
17285 		 * Create the session mempool again, since now there are new devices
17286 		 * to use the mempool.
17287 		 */
17288 		if (ts_params->session_mpool) {
17289 			rte_mempool_free(ts_params->session_mpool);
17290 			ts_params->session_mpool = NULL;
17291 		}
17292 
17293 		if (info.sym.max_nb_sessions != 0 &&
17294 				info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
17295 			RTE_LOG(ERR, USER1,
17296 					"Device does not support "
17297 					"at least %u sessions\n",
17298 					MAX_NB_SESSIONS);
17299 			return TEST_FAILED;
17300 		}
17301 		/*
17302 		 * Create mempool with maximum number of sessions,
17303 		 * to include the session headers
17304 		 */
17305 		if (ts_params->session_mpool == NULL) {
17306 			ts_params->session_mpool =
17307 				rte_cryptodev_sym_session_pool_create(
17308 						"test_sess_mp",
17309 						MAX_NB_SESSIONS, session_size,
17310 						0, 0, SOCKET_ID_ANY);
17311 			TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
17312 					"session mempool allocation failed");
17313 		}
17314 
17315 		ts_params->qp_conf.mp_session = ts_params->session_mpool;
17316 
17317 		ret = rte_cryptodev_scheduler_worker_attach(sched_id,
17318 				(uint8_t)i);
17319 
17320 		TEST_ASSERT(ret == 0,
17321 			"Failed to attach device %u of pmd : %s", i,
17322 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
17323 
17324 		aesni_ids[nb_devs_attached] = (uint8_t)i;
17325 
17326 		nb_devs_attached++;
17327 	}
17328 
17329 	return 0;
17330 }
17331 
17332 static int
17333 test_scheduler_detach_worker_op(void)
17334 {
17335 	struct crypto_testsuite_params *ts_params = &testsuite_params;
17336 	uint8_t sched_id = ts_params->valid_devs[0];
17337 	uint32_t i;
17338 	int ret;
17339 
17340 	for (i = 0; i < 2; i++) {
17341 		ret = rte_cryptodev_scheduler_worker_detach(sched_id,
17342 				aesni_ids[i]);
17343 		TEST_ASSERT(ret == 0,
17344 			"Failed to detach device %u", aesni_ids[i]);
17345 	}
17346 
17347 	return 0;
17348 }
17349 
17350 static int
17351 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
17352 {
17353 	struct crypto_testsuite_params *ts_params = &testsuite_params;
17354 	uint8_t sched_id = ts_params->valid_devs[0];
17355 	/* set mode */
17356 	return rte_cryptodev_scheduler_mode_set(sched_id,
17357 		scheduler_mode);
17358 }
17359 
17360 static int
17361 test_scheduler_mode_roundrobin_op(void)
17362 {
17363 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
17364 			0, "Failed to set roundrobin mode");
17365 	return 0;
17366 
17367 }
17368 
17369 static int
17370 test_scheduler_mode_multicore_op(void)
17371 {
17372 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
17373 			0, "Failed to set multicore mode");
17374 
17375 	return 0;
17376 }
17377 
17378 static int
17379 test_scheduler_mode_failover_op(void)
17380 {
17381 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
17382 			0, "Failed to set failover mode");
17383 
17384 	return 0;
17385 }
17386 
17387 static int
17388 test_scheduler_mode_pkt_size_distr_op(void)
17389 {
17390 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
17391 			0, "Failed to set pktsize mode");
17392 
17393 	return 0;
17394 }
17395 
17396 static int
17397 scheduler_multicore_testsuite_setup(void)
17398 {
17399 	if (test_scheduler_attach_worker_op() < 0)
17400 		return TEST_SKIPPED;
17401 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0)
17402 		return TEST_SKIPPED;
17403 	return 0;
17404 }
17405 
17406 static int
17407 scheduler_roundrobin_testsuite_setup(void)
17408 {
17409 	if (test_scheduler_attach_worker_op() < 0)
17410 		return TEST_SKIPPED;
17411 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0)
17412 		return TEST_SKIPPED;
17413 	return 0;
17414 }
17415 
17416 static int
17417 scheduler_failover_testsuite_setup(void)
17418 {
17419 	if (test_scheduler_attach_worker_op() < 0)
17420 		return TEST_SKIPPED;
17421 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0)
17422 		return TEST_SKIPPED;
17423 	return 0;
17424 }
17425 
17426 static int
17427 scheduler_pkt_size_distr_testsuite_setup(void)
17428 {
17429 	if (test_scheduler_attach_worker_op() < 0)
17430 		return TEST_SKIPPED;
17431 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0)
17432 		return TEST_SKIPPED;
17433 	return 0;
17434 }
17435 
17436 static void
17437 scheduler_mode_testsuite_teardown(void)
17438 {
17439 	test_scheduler_detach_worker_op();
17440 }
17441 
17442 #endif /* RTE_CRYPTO_SCHEDULER */
17443 
17444 static struct unit_test_suite end_testsuite = {
17445 	.suite_name = NULL,
17446 	.setup = NULL,
17447 	.teardown = NULL,
17448 	.unit_test_suites = NULL
17449 };
17450 
17451 #ifdef RTE_LIB_SECURITY
17452 static struct unit_test_suite ipsec_proto_testsuite  = {
17453 	.suite_name = "IPsec Proto Unit Test Suite",
17454 	.setup = ipsec_proto_testsuite_setup,
17455 	.unit_test_cases = {
17456 		TEST_CASE_NAMED_WITH_DATA(
17457 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
17458 			ut_setup_security, ut_teardown,
17459 			test_ipsec_proto_known_vec, &pkt_aes_128_gcm),
17460 		TEST_CASE_NAMED_WITH_DATA(
17461 			"Outbound known vector ext_mbuf mode (ESP tunnel mode IPv4 AES-GCM 128)",
17462 			ut_setup_security, ut_teardown,
17463 			test_ipsec_proto_known_vec_ext_mbuf, &pkt_aes_128_gcm),
17464 		TEST_CASE_NAMED_WITH_DATA(
17465 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
17466 			ut_setup_security, ut_teardown,
17467 			test_ipsec_proto_known_vec, &pkt_aes_192_gcm),
17468 		TEST_CASE_NAMED_WITH_DATA(
17469 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
17470 			ut_setup_security, ut_teardown,
17471 			test_ipsec_proto_known_vec, &pkt_aes_256_gcm),
17472 		TEST_CASE_NAMED_WITH_DATA(
17473 			"Outbound known vector (ESP tunnel mode IPv4 AES-CCM 256)",
17474 			ut_setup_security, ut_teardown,
17475 			test_ipsec_proto_known_vec, &pkt_aes_256_ccm),
17476 		TEST_CASE_NAMED_WITH_DATA(
17477 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC MD5 [12B ICV])",
17478 			ut_setup_security, ut_teardown,
17479 			test_ipsec_proto_known_vec,
17480 			&pkt_aes_128_cbc_md5),
17481 		TEST_CASE_NAMED_WITH_DATA(
17482 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])",
17483 			ut_setup_security, ut_teardown,
17484 			test_ipsec_proto_known_vec,
17485 			&pkt_aes_128_cbc_hmac_sha256),
17486 		TEST_CASE_NAMED_WITH_DATA(
17487 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])",
17488 			ut_setup_security, ut_teardown,
17489 			test_ipsec_proto_known_vec,
17490 			&pkt_aes_128_cbc_hmac_sha384),
17491 		TEST_CASE_NAMED_WITH_DATA(
17492 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])",
17493 			ut_setup_security, ut_teardown,
17494 			test_ipsec_proto_known_vec,
17495 			&pkt_aes_128_cbc_hmac_sha512),
17496 		TEST_CASE_NAMED_WITH_DATA(
17497 			"Outbound known vector (ESP tunnel mode IPv6 AES-GCM 128)",
17498 			ut_setup_security, ut_teardown,
17499 			test_ipsec_proto_known_vec, &pkt_aes_256_gcm_v6),
17500 		TEST_CASE_NAMED_WITH_DATA(
17501 			"Outbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])",
17502 			ut_setup_security, ut_teardown,
17503 			test_ipsec_proto_known_vec,
17504 			&pkt_aes_128_cbc_hmac_sha256_v6),
17505 		TEST_CASE_NAMED_WITH_DATA(
17506 			"Outbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])",
17507 			ut_setup_security, ut_teardown,
17508 			test_ipsec_proto_known_vec,
17509 			&pkt_null_aes_xcbc),
17510 		TEST_CASE_NAMED_WITH_DATA(
17511 			"Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA256 [16B ICV])",
17512 			ut_setup_security, ut_teardown,
17513 			test_ipsec_proto_known_vec,
17514 			&pkt_des_cbc_hmac_sha256),
17515 		TEST_CASE_NAMED_WITH_DATA(
17516 			"Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA384 [24B ICV])",
17517 			ut_setup_security, ut_teardown,
17518 			test_ipsec_proto_known_vec,
17519 			&pkt_des_cbc_hmac_sha384),
17520 		TEST_CASE_NAMED_WITH_DATA(
17521 			"Outbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA512 [32B ICV])",
17522 			ut_setup_security, ut_teardown,
17523 			test_ipsec_proto_known_vec,
17524 			&pkt_des_cbc_hmac_sha512),
17525 		TEST_CASE_NAMED_WITH_DATA(
17526 			"Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA256 [16B ICV])",
17527 			ut_setup_security, ut_teardown,
17528 			test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha256),
17529 		TEST_CASE_NAMED_WITH_DATA(
17530 			"Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA384 [24B ICV])",
17531 			ut_setup_security, ut_teardown,
17532 			test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha384),
17533 		TEST_CASE_NAMED_WITH_DATA(
17534 			"Outbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA512 [32B ICV])",
17535 			ut_setup_security, ut_teardown,
17536 			test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha512),
17537 		TEST_CASE_NAMED_WITH_DATA(
17538 			"Outbound known vector (ESP tunnel mode IPv6 DES-CBC HMAC-SHA256 [16B ICV])",
17539 			ut_setup_security, ut_teardown,
17540 			test_ipsec_proto_known_vec,
17541 			&pkt_des_cbc_hmac_sha256_v6),
17542 		TEST_CASE_NAMED_WITH_DATA(
17543 			"Outbound known vector (ESP tunnel mode IPv6 3DES-CBC HMAC-SHA256 [16B ICV])",
17544 			ut_setup_security, ut_teardown,
17545 			test_ipsec_proto_known_vec, &pkt_3des_cbc_hmac_sha256_v6),
17546 		TEST_CASE_NAMED_WITH_DATA(
17547 			"Outbound known vector (AH tunnel mode IPv4 HMAC-SHA256)",
17548 			ut_setup_security, ut_teardown,
17549 			test_ipsec_proto_known_vec,
17550 			&pkt_ah_tunnel_sha256),
17551 		TEST_CASE_NAMED_WITH_DATA(
17552 			"Outbound known vector (AH transport mode IPv4 HMAC-SHA256)",
17553 			ut_setup_security, ut_teardown,
17554 			test_ipsec_proto_known_vec,
17555 			&pkt_ah_transport_sha256),
17556 		TEST_CASE_NAMED_WITH_DATA(
17557 			"Outbound known vector (AH transport mode IPv4 AES-GMAC 128)",
17558 			ut_setup_security, ut_teardown,
17559 			test_ipsec_proto_known_vec,
17560 			&pkt_ah_ipv4_aes_gmac_128),
17561 		TEST_CASE_NAMED_WITH_DATA(
17562 			"Outbound fragmented packet",
17563 			ut_setup_security, ut_teardown,
17564 			test_ipsec_proto_known_vec_fragmented,
17565 			&pkt_aes_128_gcm_frag),
17566 		TEST_CASE_NAMED_WITH_DATA(
17567 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
17568 			ut_setup_security, ut_teardown,
17569 			test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm),
17570 		TEST_CASE_NAMED_WITH_DATA(
17571 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
17572 			ut_setup_security, ut_teardown,
17573 			test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm),
17574 		TEST_CASE_NAMED_WITH_DATA(
17575 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
17576 			ut_setup_security, ut_teardown,
17577 			test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm),
17578 		TEST_CASE_NAMED_WITH_DATA(
17579 			"Inbound known vector (ESP tunnel mode IPv4 AES-CCM 256)",
17580 			ut_setup_security, ut_teardown,
17581 			test_ipsec_proto_known_vec_inb, &pkt_aes_256_ccm),
17582 		TEST_CASE_NAMED_WITH_DATA(
17583 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128)",
17584 			ut_setup_security, ut_teardown,
17585 			test_ipsec_proto_known_vec_inb, &pkt_aes_128_cbc_null),
17586 		TEST_CASE_NAMED_WITH_DATA(
17587 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC MD5 [12B ICV])",
17588 			ut_setup_security, ut_teardown,
17589 			test_ipsec_proto_known_vec_inb,
17590 			&pkt_aes_128_cbc_md5),
17591 		TEST_CASE_NAMED_WITH_DATA(
17592 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])",
17593 			ut_setup_security, ut_teardown,
17594 			test_ipsec_proto_known_vec_inb,
17595 			&pkt_aes_128_cbc_hmac_sha256),
17596 		TEST_CASE_NAMED_WITH_DATA(
17597 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])",
17598 			ut_setup_security, ut_teardown,
17599 			test_ipsec_proto_known_vec_inb,
17600 			&pkt_aes_128_cbc_hmac_sha384),
17601 		TEST_CASE_NAMED_WITH_DATA(
17602 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])",
17603 			ut_setup_security, ut_teardown,
17604 			test_ipsec_proto_known_vec_inb,
17605 			&pkt_aes_128_cbc_hmac_sha512),
17606 		TEST_CASE_NAMED_WITH_DATA(
17607 			"Inbound known vector (ESP tunnel mode IPv6 AES-GCM 128)",
17608 			ut_setup_security, ut_teardown,
17609 			test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm_v6),
17610 		TEST_CASE_NAMED_WITH_DATA(
17611 			"Inbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])",
17612 			ut_setup_security, ut_teardown,
17613 			test_ipsec_proto_known_vec_inb,
17614 			&pkt_aes_128_cbc_hmac_sha256_v6),
17615 		TEST_CASE_NAMED_WITH_DATA(
17616 			"Inbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])",
17617 			ut_setup_security, ut_teardown,
17618 			test_ipsec_proto_known_vec_inb,
17619 			&pkt_null_aes_xcbc),
17620 		TEST_CASE_NAMED_WITH_DATA(
17621 			"Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA256 [16B ICV])",
17622 			ut_setup_security, ut_teardown,
17623 			test_ipsec_proto_known_vec_inb,
17624 			&pkt_des_cbc_hmac_sha256),
17625 		TEST_CASE_NAMED_WITH_DATA(
17626 			"Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA384 [24B ICV])",
17627 			ut_setup_security, ut_teardown,
17628 			test_ipsec_proto_known_vec_inb,
17629 			&pkt_des_cbc_hmac_sha384),
17630 		TEST_CASE_NAMED_WITH_DATA(
17631 			"Inbound known vector (ESP tunnel mode IPv4 DES-CBC HMAC-SHA512 [32B ICV])",
17632 			ut_setup_security, ut_teardown,
17633 			test_ipsec_proto_known_vec_inb,
17634 			&pkt_des_cbc_hmac_sha512),
17635 		TEST_CASE_NAMED_WITH_DATA(
17636 			"Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA256 [16B ICV])",
17637 			ut_setup_security, ut_teardown,
17638 			test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha256),
17639 		TEST_CASE_NAMED_WITH_DATA(
17640 			"Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA384 [24B ICV])",
17641 			ut_setup_security, ut_teardown,
17642 			test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha384),
17643 		TEST_CASE_NAMED_WITH_DATA(
17644 			"Inbound known vector (ESP tunnel mode IPv4 3DES-CBC HMAC-SHA512 [32B ICV])",
17645 			ut_setup_security, ut_teardown,
17646 			test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha512),
17647 		TEST_CASE_NAMED_WITH_DATA(
17648 			"Inbound known vector (ESP tunnel mode IPv6 DES-CBC HMAC-SHA256 [16B ICV])",
17649 			ut_setup_security, ut_teardown,
17650 			test_ipsec_proto_known_vec_inb,
17651 			&pkt_des_cbc_hmac_sha256_v6),
17652 		TEST_CASE_NAMED_WITH_DATA(
17653 			"Inbound known vector (ESP tunnel mode IPv6 3DES-CBC HMAC-SHA256 [16B ICV])",
17654 			ut_setup_security, ut_teardown,
17655 			test_ipsec_proto_known_vec_inb, &pkt_3des_cbc_hmac_sha256_v6),
17656 		TEST_CASE_NAMED_WITH_DATA(
17657 			"Inbound known vector (AH tunnel mode IPv4 HMAC-SHA256)",
17658 			ut_setup_security, ut_teardown,
17659 			test_ipsec_proto_known_vec_inb,
17660 			&pkt_ah_tunnel_sha256),
17661 		TEST_CASE_NAMED_WITH_DATA(
17662 			"Inbound known vector (AH transport mode IPv4 HMAC-SHA256)",
17663 			ut_setup_security, ut_teardown,
17664 			test_ipsec_proto_known_vec_inb,
17665 			&pkt_ah_transport_sha256),
17666 		TEST_CASE_NAMED_WITH_DATA(
17667 			"Inbound known vector (AH transport mode IPv4 AES-GMAC 128)",
17668 			ut_setup_security, ut_teardown,
17669 			test_ipsec_proto_known_vec_inb,
17670 			&pkt_ah_ipv4_aes_gmac_128),
17671 		TEST_CASE_NAMED_ST(
17672 			"Combined test alg list",
17673 			ut_setup_security, ut_teardown,
17674 			test_ipsec_proto_display_list),
17675 		TEST_CASE_NAMED_ST(
17676 			"Combined test alg list (AH)",
17677 			ut_setup_security, ut_teardown,
17678 			test_ipsec_proto_ah_tunnel_ipv4),
17679 		TEST_CASE_NAMED_ST(
17680 			"IV generation",
17681 			ut_setup_security, ut_teardown,
17682 			test_ipsec_proto_iv_gen),
17683 		TEST_CASE_NAMED_ST(
17684 			"UDP encapsulation",
17685 			ut_setup_security, ut_teardown,
17686 			test_ipsec_proto_udp_encap),
17687 		TEST_CASE_NAMED_ST(
17688 			"UDP encapsulation with custom ports",
17689 			ut_setup_security, ut_teardown,
17690 			test_ipsec_proto_udp_encap_custom_ports),
17691 		TEST_CASE_NAMED_ST(
17692 			"UDP encapsulation ports verification test",
17693 			ut_setup_security, ut_teardown,
17694 			test_ipsec_proto_udp_ports_verify),
17695 		TEST_CASE_NAMED_ST(
17696 			"SA expiry packets soft",
17697 			ut_setup_security, ut_teardown,
17698 			test_ipsec_proto_sa_exp_pkts_soft),
17699 		TEST_CASE_NAMED_ST(
17700 			"SA expiry packets hard",
17701 			ut_setup_security, ut_teardown,
17702 			test_ipsec_proto_sa_exp_pkts_hard),
17703 		TEST_CASE_NAMED_ST(
17704 			"Negative test: ICV corruption",
17705 			ut_setup_security, ut_teardown,
17706 			test_ipsec_proto_err_icv_corrupt),
17707 		TEST_CASE_NAMED_ST(
17708 			"Tunnel dst addr verification",
17709 			ut_setup_security, ut_teardown,
17710 			test_ipsec_proto_tunnel_dst_addr_verify),
17711 		TEST_CASE_NAMED_ST(
17712 			"Tunnel src and dst addr verification",
17713 			ut_setup_security, ut_teardown,
17714 			test_ipsec_proto_tunnel_src_dst_addr_verify),
17715 		TEST_CASE_NAMED_ST(
17716 			"Inner IP checksum",
17717 			ut_setup_security, ut_teardown,
17718 			test_ipsec_proto_inner_ip_csum),
17719 		TEST_CASE_NAMED_ST(
17720 			"Inner L4 checksum",
17721 			ut_setup_security, ut_teardown,
17722 			test_ipsec_proto_inner_l4_csum),
17723 		TEST_CASE_NAMED_ST(
17724 			"Tunnel IPv4 in IPv4",
17725 			ut_setup_security, ut_teardown,
17726 			test_ipsec_proto_tunnel_v4_in_v4),
17727 		TEST_CASE_NAMED_ST(
17728 			"Tunnel IPv6 in IPv6",
17729 			ut_setup_security, ut_teardown,
17730 			test_ipsec_proto_tunnel_v6_in_v6),
17731 		TEST_CASE_NAMED_ST(
17732 			"Tunnel IPv4 in IPv6",
17733 			ut_setup_security, ut_teardown,
17734 			test_ipsec_proto_tunnel_v4_in_v6),
17735 		TEST_CASE_NAMED_ST(
17736 			"Tunnel IPv6 in IPv4",
17737 			ut_setup_security, ut_teardown,
17738 			test_ipsec_proto_tunnel_v6_in_v4),
17739 		TEST_CASE_NAMED_ST(
17740 			"Transport IPv4",
17741 			ut_setup_security, ut_teardown,
17742 			test_ipsec_proto_transport_v4),
17743 		TEST_CASE_NAMED_ST(
17744 			"AH transport IPv4",
17745 			ut_setup_security, ut_teardown,
17746 			test_ipsec_proto_ah_transport_ipv4),
17747 		TEST_CASE_NAMED_ST(
17748 			"Transport l4 checksum",
17749 			ut_setup_security, ut_teardown,
17750 			test_ipsec_proto_transport_l4_csum),
17751 		TEST_CASE_NAMED_ST(
17752 			"Statistics: success",
17753 			ut_setup_security, ut_teardown,
17754 			test_ipsec_proto_stats),
17755 		TEST_CASE_NAMED_ST(
17756 			"Fragmented packet",
17757 			ut_setup_security, ut_teardown,
17758 			test_ipsec_proto_pkt_fragment),
17759 		TEST_CASE_NAMED_ST(
17760 			"Tunnel header copy DF (inner 0)",
17761 			ut_setup_security, ut_teardown,
17762 			test_ipsec_proto_copy_df_inner_0),
17763 		TEST_CASE_NAMED_ST(
17764 			"Tunnel header copy DF (inner 1)",
17765 			ut_setup_security, ut_teardown,
17766 			test_ipsec_proto_copy_df_inner_1),
17767 		TEST_CASE_NAMED_ST(
17768 			"Tunnel header set DF 0 (inner 1)",
17769 			ut_setup_security, ut_teardown,
17770 			test_ipsec_proto_set_df_0_inner_1),
17771 		TEST_CASE_NAMED_ST(
17772 			"Tunnel header set DF 1 (inner 0)",
17773 			ut_setup_security, ut_teardown,
17774 			test_ipsec_proto_set_df_1_inner_0),
17775 		TEST_CASE_NAMED_ST(
17776 			"Tunnel header IPv4 copy DSCP (inner 0)",
17777 			ut_setup_security, ut_teardown,
17778 			test_ipsec_proto_ipv4_copy_dscp_inner_0),
17779 		TEST_CASE_NAMED_ST(
17780 			"Tunnel header IPv4 copy DSCP (inner 1)",
17781 			ut_setup_security, ut_teardown,
17782 			test_ipsec_proto_ipv4_copy_dscp_inner_1),
17783 		TEST_CASE_NAMED_ST(
17784 			"Tunnel header IPv4 set DSCP 0 (inner 1)",
17785 			ut_setup_security, ut_teardown,
17786 			test_ipsec_proto_ipv4_set_dscp_0_inner_1),
17787 		TEST_CASE_NAMED_ST(
17788 			"Tunnel header IPv4 set DSCP 1 (inner 0)",
17789 			ut_setup_security, ut_teardown,
17790 			test_ipsec_proto_ipv4_set_dscp_1_inner_0),
17791 		TEST_CASE_NAMED_ST(
17792 			"Tunnel header IPv6 copy DSCP (inner 0)",
17793 			ut_setup_security, ut_teardown,
17794 			test_ipsec_proto_ipv6_copy_dscp_inner_0),
17795 		TEST_CASE_NAMED_ST(
17796 			"Tunnel header IPv6 copy DSCP (inner 1)",
17797 			ut_setup_security, ut_teardown,
17798 			test_ipsec_proto_ipv6_copy_dscp_inner_1),
17799 		TEST_CASE_NAMED_ST(
17800 			"Tunnel header IPv6 set DSCP 0 (inner 1)",
17801 			ut_setup_security, ut_teardown,
17802 			test_ipsec_proto_ipv6_set_dscp_0_inner_1),
17803 		TEST_CASE_NAMED_ST(
17804 			"Tunnel header IPv6 set DSCP 1 (inner 0)",
17805 			ut_setup_security, ut_teardown,
17806 			test_ipsec_proto_ipv6_set_dscp_1_inner_0),
17807 		TEST_CASE_NAMED_WITH_DATA(
17808 			"Antireplay with window size 1024",
17809 			ut_setup_security, ut_teardown,
17810 			test_ipsec_proto_pkt_antireplay1024, &pkt_aes_128_gcm),
17811 		TEST_CASE_NAMED_WITH_DATA(
17812 			"Antireplay with window size 2048",
17813 			ut_setup_security, ut_teardown,
17814 			test_ipsec_proto_pkt_antireplay2048, &pkt_aes_128_gcm),
17815 		TEST_CASE_NAMED_WITH_DATA(
17816 			"Antireplay with window size 4096",
17817 			ut_setup_security, ut_teardown,
17818 			test_ipsec_proto_pkt_antireplay4096, &pkt_aes_128_gcm),
17819 		TEST_CASE_NAMED_WITH_DATA(
17820 			"ESN and Antireplay with window size 1024",
17821 			ut_setup_security, ut_teardown,
17822 			test_ipsec_proto_pkt_esn_antireplay1024,
17823 			&pkt_aes_128_gcm),
17824 		TEST_CASE_NAMED_WITH_DATA(
17825 			"ESN and Antireplay with window size 2048",
17826 			ut_setup_security, ut_teardown,
17827 			test_ipsec_proto_pkt_esn_antireplay2048,
17828 			&pkt_aes_128_gcm),
17829 		TEST_CASE_NAMED_WITH_DATA(
17830 			"ESN and Antireplay with window size 4096",
17831 			ut_setup_security, ut_teardown,
17832 			test_ipsec_proto_pkt_esn_antireplay4096,
17833 			&pkt_aes_128_gcm),
17834 		TEST_CASE_NAMED_ST(
17835 			"Tunnel header IPv4 decrement inner TTL",
17836 			ut_setup_security, ut_teardown,
17837 			test_ipsec_proto_ipv4_ttl_decrement),
17838 		TEST_CASE_NAMED_ST(
17839 			"Tunnel header IPv6 decrement inner hop limit",
17840 			ut_setup_security, ut_teardown,
17841 			test_ipsec_proto_ipv6_hop_limit_decrement),
17842 		TEST_CASE_NAMED_ST(
17843 			"Multi-segmented mode",
17844 			ut_setup_security, ut_teardown,
17845 			test_ipsec_proto_sgl),
17846 		TEST_CASE_NAMED_ST(
17847 			"Multi-segmented external mbuf mode",
17848 			ut_setup_security, ut_teardown,
17849 			test_ipsec_proto_sgl_ext_mbuf),
17850 		TEST_CASE_NAMED_WITH_DATA(
17851 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128) Rx inject",
17852 			ut_setup_security_rx_inject, ut_teardown_rx_inject,
17853 			test_ipsec_proto_known_vec_inb_rx_inject, &pkt_aes_128_gcm),
17854 		TEST_CASES_END() /**< NULL terminate unit test array */
17855 	}
17856 };
17857 
17858 static struct unit_test_suite pdcp_proto_testsuite  = {
17859 	.suite_name = "PDCP Proto Unit Test Suite",
17860 	.setup = pdcp_proto_testsuite_setup,
17861 	.unit_test_cases = {
17862 		TEST_CASE_ST(ut_setup_security, ut_teardown,
17863 			test_PDCP_PROTO_all),
17864 		TEST_CASES_END() /**< NULL terminate unit test array */
17865 	}
17866 };
17867 
17868 static struct unit_test_suite tls12_record_proto_testsuite  = {
17869 	.suite_name = "TLS 1.2 Record Protocol Unit Test Suite",
17870 	.setup = tls_record_proto_testsuite_setup,
17871 	.unit_test_cases = {
17872 		TEST_CASE_NAMED_WITH_DATA(
17873 			"Write record known vector AES-GCM-128 (vector 1)",
17874 			ut_setup_security, ut_teardown,
17875 			test_tls_record_proto_known_vec, &tls_test_data_aes_128_gcm_v1),
17876 		TEST_CASE_NAMED_WITH_DATA(
17877 			"Write record known vector AES-GCM-128 (vector 2)",
17878 			ut_setup_security, ut_teardown,
17879 			test_tls_record_proto_known_vec, &tls_test_data_aes_128_gcm_v2),
17880 		TEST_CASE_NAMED_WITH_DATA(
17881 			"Write record known vector AES-GCM-256",
17882 			ut_setup_security, ut_teardown,
17883 			test_tls_record_proto_known_vec, &tls_test_data_aes_256_gcm),
17884 		TEST_CASE_NAMED_WITH_DATA(
17885 			"Write record known vector AES-CBC-128-SHA1",
17886 			ut_setup_security, ut_teardown,
17887 			test_tls_record_proto_known_vec, &tls_test_data_aes_128_cbc_sha1_hmac),
17888 		TEST_CASE_NAMED_WITH_DATA(
17889 			"Write record known vector AES-128-CBC-SHA256",
17890 			ut_setup_security, ut_teardown,
17891 			test_tls_record_proto_known_vec, &tls_test_data_aes_128_cbc_sha256_hmac),
17892 		TEST_CASE_NAMED_WITH_DATA(
17893 			"Write record known vector AES-256-CBC-SHA1",
17894 			ut_setup_security, ut_teardown,
17895 			test_tls_record_proto_known_vec, &tls_test_data_aes_256_cbc_sha1_hmac),
17896 		TEST_CASE_NAMED_WITH_DATA(
17897 			"Write record known vector AES-256-CBC-SHA256",
17898 			ut_setup_security, ut_teardown,
17899 			test_tls_record_proto_known_vec, &tls_test_data_aes_256_cbc_sha256_hmac),
17900 		TEST_CASE_NAMED_WITH_DATA(
17901 			"Write record known vector AES-256-CBC-SHA384",
17902 			ut_setup_security, ut_teardown,
17903 			test_tls_record_proto_known_vec, &tls_test_data_aes_256_cbc_sha384_hmac),
17904 		TEST_CASE_NAMED_WITH_DATA(
17905 			"Write record known vector 3DES-CBC-SHA1-HMAC",
17906 			ut_setup_security, ut_teardown,
17907 			test_tls_record_proto_known_vec, &tls_test_data_3des_cbc_sha1_hmac),
17908 		TEST_CASE_NAMED_WITH_DATA(
17909 			"Write record known vector NULL-SHA1-HMAC",
17910 			ut_setup_security, ut_teardown,
17911 			test_tls_record_proto_known_vec, &tls_test_data_null_cipher_sha1_hmac),
17912 		TEST_CASE_NAMED_WITH_DATA(
17913 			"Write record known vector CHACHA20-POLY1305",
17914 			ut_setup_security, ut_teardown,
17915 			test_tls_record_proto_known_vec, &tls_test_data_chacha20_poly1305),
17916 
17917 		TEST_CASE_NAMED_WITH_DATA(
17918 			"Read record known vector AES-GCM-128 (vector 1)",
17919 			ut_setup_security, ut_teardown,
17920 			test_tls_record_proto_known_vec_read, &tls_test_data_aes_128_gcm_v1),
17921 		TEST_CASE_NAMED_WITH_DATA(
17922 			"Read record known vector AES-GCM-128 (vector 2)",
17923 			ut_setup_security, ut_teardown,
17924 			test_tls_record_proto_known_vec_read, &tls_test_data_aes_128_gcm_v2),
17925 		TEST_CASE_NAMED_WITH_DATA(
17926 			"Read record known vector AES-GCM-256",
17927 			ut_setup_security, ut_teardown,
17928 			test_tls_record_proto_known_vec_read, &tls_test_data_aes_256_gcm),
17929 		TEST_CASE_NAMED_WITH_DATA(
17930 			"Read record known vector AES-128-CBC-SHA1",
17931 			ut_setup_security, ut_teardown,
17932 			test_tls_record_proto_known_vec_read, &tls_test_data_aes_128_cbc_sha1_hmac),
17933 		TEST_CASE_NAMED_WITH_DATA(
17934 			"Read record known vector AES-128-CBC-SHA256",
17935 			ut_setup_security, ut_teardown,
17936 			test_tls_record_proto_known_vec_read,
17937 			&tls_test_data_aes_128_cbc_sha256_hmac),
17938 		TEST_CASE_NAMED_WITH_DATA(
17939 			"Read record known vector AES-256-CBC-SHA1",
17940 			ut_setup_security, ut_teardown,
17941 			test_tls_record_proto_known_vec_read, &tls_test_data_aes_256_cbc_sha1_hmac),
17942 		TEST_CASE_NAMED_WITH_DATA(
17943 			"Read record known vector AES-256-CBC-SHA256",
17944 			ut_setup_security, ut_teardown,
17945 			test_tls_record_proto_known_vec_read,
17946 			&tls_test_data_aes_256_cbc_sha256_hmac),
17947 		TEST_CASE_NAMED_WITH_DATA(
17948 			"Read record known vector AES-256-CBC-SHA384",
17949 			ut_setup_security, ut_teardown,
17950 			test_tls_record_proto_known_vec_read,
17951 			&tls_test_data_aes_256_cbc_sha384_hmac),
17952 		TEST_CASE_NAMED_WITH_DATA(
17953 			"Read record known vector 3DES-CBC-SHA1-HMAC",
17954 			ut_setup_security, ut_teardown,
17955 			test_tls_record_proto_known_vec_read, &tls_test_data_3des_cbc_sha1_hmac),
17956 		TEST_CASE_NAMED_WITH_DATA(
17957 			"Read record known vector NULL-SHA1-HMAC",
17958 			ut_setup_security, ut_teardown,
17959 			test_tls_record_proto_known_vec_read, &tls_test_data_null_cipher_sha1_hmac),
17960 		TEST_CASE_NAMED_WITH_DATA(
17961 			"Read record known vector CHACHA20-POLY1305",
17962 			ut_setup_security, ut_teardown,
17963 			test_tls_record_proto_known_vec_read, &tls_test_data_chacha20_poly1305),
17964 
17965 		TEST_CASE_NAMED_ST(
17966 			"Combined test alg list",
17967 			ut_setup_security, ut_teardown,
17968 			test_tls_1_2_record_proto_display_list),
17969 		TEST_CASE_NAMED_ST(
17970 			"Data walkthrough combined test alg list",
17971 			ut_setup_security, ut_teardown,
17972 			test_tls_1_2_record_proto_data_walkthrough),
17973 		TEST_CASE_NAMED_ST(
17974 			"Multi-segmented mode",
17975 			ut_setup_security, ut_teardown,
17976 			test_tls_1_2_record_proto_sgl),
17977 		TEST_CASE_NAMED_ST(
17978 			"Multi-segmented mode data walkthrough",
17979 			ut_setup_security, ut_teardown,
17980 			test_tls_1_2_record_proto_sgl_data_walkthrough),
17981 		TEST_CASE_NAMED_ST(
17982 			"Multi-segmented mode out of place",
17983 			ut_setup_security, ut_teardown,
17984 			test_tls_1_2_record_proto_sgl_oop),
17985 		TEST_CASE_NAMED_ST(
17986 			"TLS packet header corruption",
17987 			ut_setup_security, ut_teardown,
17988 			test_tls_record_proto_corrupt_pkt),
17989 		TEST_CASE_NAMED_ST(
17990 			"Custom content type",
17991 			ut_setup_security, ut_teardown,
17992 			test_tls_record_proto_custom_content_type),
17993 		TEST_CASE_NAMED_ST(
17994 			"Zero len TLS record with content type as app",
17995 			ut_setup_security, ut_teardown,
17996 			test_tls_record_proto_zero_len),
17997 		TEST_CASE_NAMED_ST(
17998 			"Zero len TLS record with content type as ctrl",
17999 			ut_setup_security, ut_teardown,
18000 			test_tls_record_proto_zero_len_non_app),
18001 		TEST_CASE_NAMED_ST(
18002 			"TLS record DM mode with optional padding < 2 blocks",
18003 			ut_setup_security, ut_teardown,
18004 			test_tls_record_proto_dm_opt_padding),
18005 		TEST_CASE_NAMED_ST(
18006 			"TLS record DM mode with optional padding > 2 blocks",
18007 			ut_setup_security, ut_teardown,
18008 			test_tls_record_proto_dm_opt_padding_1),
18009 		TEST_CASE_NAMED_ST(
18010 			"TLS record SG mode with optional padding < 2 blocks",
18011 			ut_setup_security, ut_teardown,
18012 			test_tls_record_proto_sg_opt_padding),
18013 		TEST_CASE_NAMED_ST(
18014 			"TLS record SG mode with optional padding > 2 blocks",
18015 			ut_setup_security, ut_teardown,
18016 			test_tls_record_proto_sg_opt_padding_1),
18017 		TEST_CASE_NAMED_ST(
18018 			"TLS record SG mode with optional padding > 2 blocks",
18019 			ut_setup_security, ut_teardown,
18020 			test_tls_record_proto_sg_opt_padding_2),
18021 		TEST_CASE_NAMED_ST(
18022 			"TLS record SG mode with optional padding > max range",
18023 			ut_setup_security, ut_teardown,
18024 			test_tls_record_proto_sg_opt_padding_max),
18025 		TEST_CASE_NAMED_ST(
18026 			"TLS record SG mode with padding corruption",
18027 			ut_setup_security, ut_teardown,
18028 			test_tls_record_proto_sg_opt_padding_corrupt),
18029 		TEST_CASES_END() /**< NULL terminate unit test array */
18030 	}
18031 };
18032 
18033 static struct unit_test_suite dtls12_record_proto_testsuite  = {
18034 	.suite_name = "DTLS 1.2 Record Protocol Unit Test Suite",
18035 	.setup = tls_record_proto_testsuite_setup,
18036 	.unit_test_cases = {
18037 		TEST_CASE_NAMED_WITH_DATA(
18038 			"Write record known vector AES-GCM-128",
18039 			ut_setup_security, ut_teardown,
18040 			test_tls_record_proto_known_vec, &dtls_test_data_aes_128_gcm),
18041 		TEST_CASE_NAMED_WITH_DATA(
18042 			"Write record known vector AES-GCM-256",
18043 			ut_setup_security, ut_teardown,
18044 			test_tls_record_proto_known_vec, &dtls_test_data_aes_256_gcm),
18045 		TEST_CASE_NAMED_WITH_DATA(
18046 			"Write record known vector AES-128-CBC-SHA1",
18047 			ut_setup_security, ut_teardown,
18048 			test_tls_record_proto_known_vec,
18049 			&dtls_test_data_aes_128_cbc_sha1_hmac),
18050 		TEST_CASE_NAMED_WITH_DATA(
18051 			"Write record known vector AES-128-CBC-SHA256",
18052 			ut_setup_security, ut_teardown,
18053 			test_tls_record_proto_known_vec,
18054 			&dtls_test_data_aes_128_cbc_sha256_hmac),
18055 		TEST_CASE_NAMED_WITH_DATA(
18056 			"Write record known vector AES-256-CBC-SHA1",
18057 			ut_setup_security, ut_teardown,
18058 			test_tls_record_proto_known_vec,
18059 			&dtls_test_data_aes_256_cbc_sha1_hmac),
18060 		TEST_CASE_NAMED_WITH_DATA(
18061 			"Write record known vector AES-256-CBC-SHA256",
18062 			ut_setup_security, ut_teardown,
18063 			test_tls_record_proto_known_vec,
18064 			&dtls_test_data_aes_256_cbc_sha256_hmac),
18065 		TEST_CASE_NAMED_WITH_DATA(
18066 			"Write record known vector AES-256-CBC-SHA384",
18067 			ut_setup_security, ut_teardown,
18068 			test_tls_record_proto_known_vec,
18069 			&dtls_test_data_aes_256_cbc_sha384_hmac),
18070 		TEST_CASE_NAMED_WITH_DATA(
18071 			"Write record known vector 3DES-CBC-SHA1-HMAC",
18072 			ut_setup_security, ut_teardown,
18073 			test_tls_record_proto_known_vec,
18074 			&dtls_test_data_3des_cbc_sha1_hmac),
18075 		TEST_CASE_NAMED_WITH_DATA(
18076 			"Write record known vector NULL-SHA1-HMAC",
18077 			ut_setup_security, ut_teardown,
18078 			test_tls_record_proto_known_vec,
18079 			&dtls_test_data_null_cipher_sha1_hmac),
18080 		TEST_CASE_NAMED_WITH_DATA(
18081 			"Write record known vector CHACHA20-POLY1305",
18082 			ut_setup_security, ut_teardown,
18083 			test_tls_record_proto_known_vec, &dtls_test_data_chacha20_poly1305),
18084 		TEST_CASE_NAMED_WITH_DATA(
18085 			"Read record known vector AES-GCM-128",
18086 			ut_setup_security, ut_teardown,
18087 			test_tls_record_proto_known_vec_read, &dtls_test_data_aes_128_gcm),
18088 		TEST_CASE_NAMED_WITH_DATA(
18089 			"Read record known vector AES-GCM-256",
18090 			ut_setup_security, ut_teardown,
18091 			test_tls_record_proto_known_vec_read, &dtls_test_data_aes_256_gcm),
18092 		TEST_CASE_NAMED_WITH_DATA(
18093 			"Read record known vector AES-128-CBC-SHA1",
18094 			ut_setup_security, ut_teardown,
18095 			test_tls_record_proto_known_vec_read,
18096 			&dtls_test_data_aes_128_cbc_sha1_hmac),
18097 		TEST_CASE_NAMED_WITH_DATA(
18098 			"Read record known vector AES-128-CBC-SHA256",
18099 			ut_setup_security, ut_teardown,
18100 			test_tls_record_proto_known_vec_read,
18101 			&dtls_test_data_aes_128_cbc_sha256_hmac),
18102 		TEST_CASE_NAMED_WITH_DATA(
18103 			"Read record known vector AES-256-CBC-SHA1",
18104 			ut_setup_security, ut_teardown,
18105 			test_tls_record_proto_known_vec_read,
18106 			&dtls_test_data_aes_256_cbc_sha1_hmac),
18107 		TEST_CASE_NAMED_WITH_DATA(
18108 			"Read record known vector AES-256-CBC-SHA256",
18109 			ut_setup_security, ut_teardown,
18110 			test_tls_record_proto_known_vec_read,
18111 			&dtls_test_data_aes_256_cbc_sha256_hmac),
18112 		TEST_CASE_NAMED_WITH_DATA(
18113 			"Read record known vector AES-256-CBC-SHA384",
18114 			ut_setup_security, ut_teardown,
18115 			test_tls_record_proto_known_vec_read,
18116 			&dtls_test_data_aes_256_cbc_sha384_hmac),
18117 		TEST_CASE_NAMED_WITH_DATA(
18118 			"Read record known vector 3DES-CBC-SHA1-HMAC",
18119 			ut_setup_security, ut_teardown,
18120 			test_tls_record_proto_known_vec_read,
18121 			&dtls_test_data_3des_cbc_sha1_hmac),
18122 		TEST_CASE_NAMED_WITH_DATA(
18123 			"Read record known vector NULL-SHA1-HMAC",
18124 			ut_setup_security, ut_teardown,
18125 			test_tls_record_proto_known_vec_read,
18126 			&dtls_test_data_null_cipher_sha1_hmac),
18127 		TEST_CASE_NAMED_WITH_DATA(
18128 			"Read record known vector CHACHA20-POLY1305",
18129 			ut_setup_security, ut_teardown,
18130 			test_tls_record_proto_known_vec_read, &dtls_test_data_chacha20_poly1305),
18131 
18132 		TEST_CASE_NAMED_ST(
18133 			"Combined test alg list",
18134 			ut_setup_security, ut_teardown,
18135 			test_dtls_1_2_record_proto_display_list),
18136 		TEST_CASE_NAMED_ST(
18137 			"Data walkthrough combined test alg list",
18138 			ut_setup_security, ut_teardown,
18139 			test_dtls_1_2_record_proto_data_walkthrough),
18140 		TEST_CASE_NAMED_ST(
18141 			"Multi-segmented mode",
18142 			ut_setup_security, ut_teardown,
18143 			test_dtls_1_2_record_proto_sgl),
18144 		TEST_CASE_NAMED_ST(
18145 			"Multi-segmented mode data walkthrough",
18146 			ut_setup_security, ut_teardown,
18147 			test_dtls_1_2_record_proto_sgl_data_walkthrough),
18148 		TEST_CASE_NAMED_ST(
18149 			"Packet corruption",
18150 			ut_setup_security, ut_teardown,
18151 			test_dtls_1_2_record_proto_corrupt_pkt),
18152 		TEST_CASE_NAMED_ST(
18153 			"Custom content type",
18154 			ut_setup_security, ut_teardown,
18155 			test_dtls_1_2_record_proto_custom_content_type),
18156 		TEST_CASE_NAMED_ST(
18157 			"Zero len DTLS record with content type as app",
18158 			ut_setup_security, ut_teardown,
18159 			test_dtls_1_2_record_proto_zero_len),
18160 		TEST_CASE_NAMED_ST(
18161 			"Zero len DTLS record with content type as ctrl",
18162 			ut_setup_security, ut_teardown,
18163 			test_dtls_1_2_record_proto_zero_len_non_app),
18164 		TEST_CASE_NAMED_ST(
18165 			"Antireplay with window size 64",
18166 			ut_setup_security, ut_teardown,
18167 			test_dtls_1_2_record_proto_antireplay64),
18168 		TEST_CASE_NAMED_ST(
18169 			"Antireplay with window size 128",
18170 			ut_setup_security, ut_teardown,
18171 			test_dtls_1_2_record_proto_antireplay128),
18172 		TEST_CASE_NAMED_ST(
18173 			"Antireplay with window size 256",
18174 			ut_setup_security, ut_teardown,
18175 			test_dtls_1_2_record_proto_antireplay256),
18176 		TEST_CASE_NAMED_ST(
18177 			"Antireplay with window size 512",
18178 			ut_setup_security, ut_teardown,
18179 			test_dtls_1_2_record_proto_antireplay512),
18180 		TEST_CASE_NAMED_ST(
18181 			"Antireplay with window size 1024",
18182 			ut_setup_security, ut_teardown,
18183 			test_dtls_1_2_record_proto_antireplay1024),
18184 		TEST_CASE_NAMED_ST(
18185 			"Antireplay with window size 2048",
18186 			ut_setup_security, ut_teardown,
18187 			test_dtls_1_2_record_proto_antireplay2048),
18188 		TEST_CASE_NAMED_ST(
18189 			"Antireplay with window size 4096",
18190 			ut_setup_security, ut_teardown,
18191 			test_dtls_1_2_record_proto_antireplay4096),
18192 		TEST_CASE_NAMED_ST(
18193 			"DTLS record DM mode with optional padding < 2 blocks",
18194 			ut_setup_security, ut_teardown,
18195 			test_dtls_1_2_record_proto_dm_opt_padding),
18196 		TEST_CASE_NAMED_ST(
18197 			"DTLS record DM mode with optional padding > 2 blocks",
18198 			ut_setup_security, ut_teardown,
18199 			test_dtls_1_2_record_proto_dm_opt_padding_1),
18200 		TEST_CASE_NAMED_ST(
18201 			"DTLS record SG mode with optional padding < 2 blocks",
18202 			ut_setup_security, ut_teardown,
18203 			test_dtls_1_2_record_proto_sg_opt_padding),
18204 		TEST_CASE_NAMED_ST(
18205 			"DTLS record SG mode with optional padding > 2 blocks",
18206 			ut_setup_security, ut_teardown,
18207 			test_dtls_1_2_record_proto_sg_opt_padding_1),
18208 		TEST_CASE_NAMED_ST(
18209 			"DTLS record SG mode with optional padding > 2 blocks",
18210 			ut_setup_security, ut_teardown,
18211 			test_dtls_1_2_record_proto_sg_opt_padding_2),
18212 		TEST_CASE_NAMED_ST(
18213 			"DTLS record SG mode with optional padding > max range",
18214 			ut_setup_security, ut_teardown,
18215 			test_dtls_1_2_record_proto_sg_opt_padding_max),
18216 		TEST_CASE_NAMED_ST(
18217 			"DTLS record SG mode with padding corruption",
18218 			ut_setup_security, ut_teardown,
18219 			test_dtls_1_2_record_proto_sg_opt_padding_corrupt),
18220 		TEST_CASES_END() /**< NULL terminate unit test array */
18221 	}
18222 };
18223 
18224 static struct unit_test_suite tls13_record_proto_testsuite  = {
18225 	.suite_name = "TLS 1.3 Record Protocol Unit Test Suite",
18226 	.setup = tls_record_proto_testsuite_setup,
18227 	.unit_test_cases = {
18228 		TEST_CASE_NAMED_WITH_DATA(
18229 			"Write record known vector AES-GCM-128",
18230 			ut_setup_security, ut_teardown,
18231 			test_tls_record_proto_known_vec, &tls13_test_data_aes_128_gcm),
18232 		TEST_CASE_NAMED_WITH_DATA(
18233 			"Write record known vector AES-GCM-256",
18234 			ut_setup_security, ut_teardown,
18235 			test_tls_record_proto_known_vec, &tls13_test_data_aes_256_gcm),
18236 		TEST_CASE_NAMED_WITH_DATA(
18237 			"Write record known vector CHACHA20-POLY1305",
18238 			ut_setup_security, ut_teardown,
18239 			test_tls_record_proto_known_vec, &tls13_test_data_chacha20_poly1305),
18240 
18241 		TEST_CASE_NAMED_WITH_DATA(
18242 			"Read record known vector AES-GCM-128",
18243 			ut_setup_security, ut_teardown,
18244 			test_tls_record_proto_known_vec_read, &tls13_test_data_aes_128_gcm),
18245 		TEST_CASE_NAMED_WITH_DATA(
18246 			"Read record known vector AES-GCM-256",
18247 			ut_setup_security, ut_teardown,
18248 			test_tls_record_proto_known_vec_read, &tls13_test_data_aes_256_gcm),
18249 		TEST_CASE_NAMED_WITH_DATA(
18250 			"Read record known vector CHACHA20-POLY1305",
18251 			ut_setup_security, ut_teardown,
18252 			test_tls_record_proto_known_vec_read, &tls13_test_data_chacha20_poly1305),
18253 		TEST_CASE_NAMED_ST(
18254 			"TLS-1.3 record header corruption",
18255 			ut_setup_security, ut_teardown,
18256 			test_tls_1_3_record_proto_corrupt_pkt),
18257 		TEST_CASE_NAMED_ST(
18258 			"TLS-1.3 record header with custom content type",
18259 			ut_setup_security, ut_teardown,
18260 			test_tls_1_3_record_proto_custom_content_type),
18261 		TEST_CASE_NAMED_ST(
18262 			"TLS-1.3 record with zero len and content type as app",
18263 			ut_setup_security, ut_teardown,
18264 			test_tls_1_3_record_proto_zero_len),
18265 		TEST_CASE_NAMED_ST(
18266 			"TLS-1.3 record with zero len and content type as ctrl",
18267 			ut_setup_security, ut_teardown,
18268 			test_tls_1_3_record_proto_zero_len_non_app),
18269 		TEST_CASE_NAMED_ST(
18270 			"TLS-1.3 record DM mode with optional padding",
18271 			ut_setup_security, ut_teardown,
18272 			test_tls_1_3_record_proto_dm_opt_padding),
18273 		TEST_CASE_NAMED_ST(
18274 			"TLS-1.3 record SG mode with optional padding - 1",
18275 			ut_setup_security, ut_teardown,
18276 			test_tls_1_3_record_proto_sg_opt_padding),
18277 		TEST_CASE_NAMED_ST(
18278 			"TLS-1.3 record SG mode with optional padding",
18279 			ut_setup_security, ut_teardown,
18280 			test_tls_1_3_record_proto_sg_opt_padding_1),
18281 		TEST_CASE_NAMED_ST(
18282 			"Combined test alg list",
18283 			ut_setup_security, ut_teardown,
18284 			test_tls_1_3_record_proto_display_list),
18285 		TEST_CASE_NAMED_ST(
18286 			"Data walkthrough combined test alg list",
18287 			ut_setup_security, ut_teardown,
18288 			test_tls_1_3_record_proto_data_walkthrough),
18289 		TEST_CASE_NAMED_ST(
18290 			"Multi-segmented mode data walkthrough",
18291 			ut_setup_security, ut_teardown,
18292 			test_tls_1_3_record_proto_sgl_data_walkthrough),
18293 		TEST_CASES_END() /**< NULL terminate unit test array */
18294 	}
18295 };
18296 
18297 #define ADD_UPLINK_TESTCASE(data)						\
18298 	TEST_CASE_NAMED_WITH_DATA(data.test_descr_uplink, ut_setup_security,	\
18299 	ut_teardown, test_docsis_proto_uplink, (const void *) &data),		\
18300 
18301 #define ADD_DOWNLINK_TESTCASE(data)						\
18302 	TEST_CASE_NAMED_WITH_DATA(data.test_descr_downlink, ut_setup_security,	\
18303 	ut_teardown, test_docsis_proto_downlink, (const void *) &data),		\
18304 
18305 static struct unit_test_suite docsis_proto_testsuite  = {
18306 	.suite_name = "DOCSIS Proto Unit Test Suite",
18307 	.setup = docsis_proto_testsuite_setup,
18308 	.unit_test_cases = {
18309 		/* Uplink */
18310 		ADD_UPLINK_TESTCASE(docsis_test_case_1)
18311 		ADD_UPLINK_TESTCASE(docsis_test_case_2)
18312 		ADD_UPLINK_TESTCASE(docsis_test_case_3)
18313 		ADD_UPLINK_TESTCASE(docsis_test_case_4)
18314 		ADD_UPLINK_TESTCASE(docsis_test_case_5)
18315 		ADD_UPLINK_TESTCASE(docsis_test_case_6)
18316 		ADD_UPLINK_TESTCASE(docsis_test_case_7)
18317 		ADD_UPLINK_TESTCASE(docsis_test_case_8)
18318 		ADD_UPLINK_TESTCASE(docsis_test_case_9)
18319 		ADD_UPLINK_TESTCASE(docsis_test_case_10)
18320 		ADD_UPLINK_TESTCASE(docsis_test_case_11)
18321 		ADD_UPLINK_TESTCASE(docsis_test_case_12)
18322 		ADD_UPLINK_TESTCASE(docsis_test_case_13)
18323 		ADD_UPLINK_TESTCASE(docsis_test_case_14)
18324 		ADD_UPLINK_TESTCASE(docsis_test_case_15)
18325 		ADD_UPLINK_TESTCASE(docsis_test_case_16)
18326 		ADD_UPLINK_TESTCASE(docsis_test_case_17)
18327 		ADD_UPLINK_TESTCASE(docsis_test_case_18)
18328 		ADD_UPLINK_TESTCASE(docsis_test_case_19)
18329 		ADD_UPLINK_TESTCASE(docsis_test_case_20)
18330 		ADD_UPLINK_TESTCASE(docsis_test_case_21)
18331 		ADD_UPLINK_TESTCASE(docsis_test_case_22)
18332 		ADD_UPLINK_TESTCASE(docsis_test_case_23)
18333 		ADD_UPLINK_TESTCASE(docsis_test_case_24)
18334 		ADD_UPLINK_TESTCASE(docsis_test_case_25)
18335 		ADD_UPLINK_TESTCASE(docsis_test_case_26)
18336 		/* Downlink */
18337 		ADD_DOWNLINK_TESTCASE(docsis_test_case_1)
18338 		ADD_DOWNLINK_TESTCASE(docsis_test_case_2)
18339 		ADD_DOWNLINK_TESTCASE(docsis_test_case_3)
18340 		ADD_DOWNLINK_TESTCASE(docsis_test_case_4)
18341 		ADD_DOWNLINK_TESTCASE(docsis_test_case_5)
18342 		ADD_DOWNLINK_TESTCASE(docsis_test_case_6)
18343 		ADD_DOWNLINK_TESTCASE(docsis_test_case_7)
18344 		ADD_DOWNLINK_TESTCASE(docsis_test_case_8)
18345 		ADD_DOWNLINK_TESTCASE(docsis_test_case_9)
18346 		ADD_DOWNLINK_TESTCASE(docsis_test_case_10)
18347 		ADD_DOWNLINK_TESTCASE(docsis_test_case_11)
18348 		ADD_DOWNLINK_TESTCASE(docsis_test_case_12)
18349 		ADD_DOWNLINK_TESTCASE(docsis_test_case_13)
18350 		ADD_DOWNLINK_TESTCASE(docsis_test_case_14)
18351 		ADD_DOWNLINK_TESTCASE(docsis_test_case_15)
18352 		ADD_DOWNLINK_TESTCASE(docsis_test_case_16)
18353 		ADD_DOWNLINK_TESTCASE(docsis_test_case_17)
18354 		ADD_DOWNLINK_TESTCASE(docsis_test_case_18)
18355 		ADD_DOWNLINK_TESTCASE(docsis_test_case_19)
18356 		ADD_DOWNLINK_TESTCASE(docsis_test_case_20)
18357 		ADD_DOWNLINK_TESTCASE(docsis_test_case_21)
18358 		ADD_DOWNLINK_TESTCASE(docsis_test_case_22)
18359 		ADD_DOWNLINK_TESTCASE(docsis_test_case_23)
18360 		ADD_DOWNLINK_TESTCASE(docsis_test_case_24)
18361 		ADD_DOWNLINK_TESTCASE(docsis_test_case_25)
18362 		ADD_DOWNLINK_TESTCASE(docsis_test_case_26)
18363 		TEST_CASES_END() /**< NULL terminate unit test array */
18364 	}
18365 };
18366 #endif
18367 
18368 static struct unit_test_suite cryptodev_gen_testsuite  = {
18369 	.suite_name = "Crypto General Unit Test Suite",
18370 	.setup = crypto_gen_testsuite_setup,
18371 	.unit_test_cases = {
18372 		TEST_CASE_ST(ut_setup, ut_teardown,
18373 				test_device_reconfigure),
18374 		TEST_CASE_ST(ut_setup, ut_teardown,
18375 				test_device_configure_invalid_dev_id),
18376 		TEST_CASE_ST(ut_setup, ut_teardown,
18377 				test_queue_pair_descriptor_setup),
18378 		TEST_CASE_ST(ut_setup, ut_teardown,
18379 				test_device_configure_invalid_queue_pair_ids),
18380 		TEST_CASE_ST(ut_setup, ut_teardown,
18381 				test_queue_pair_descriptor_count),
18382 		TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
18383 		TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup),
18384 		TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup),
18385 		TEST_CASES_END() /**< NULL terminate unit test array */
18386 	}
18387 };
18388 
18389 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = {
18390 	.suite_name = "Negative HMAC SHA1 Unit Test Suite",
18391 	.setup = negative_hmac_sha1_testsuite_setup,
18392 	.unit_test_cases = {
18393 		/** Negative tests */
18394 		TEST_CASE_ST(ut_setup, ut_teardown,
18395 			authentication_verify_HMAC_SHA1_fail_data_corrupt),
18396 		TEST_CASE_ST(ut_setup, ut_teardown,
18397 			authentication_verify_HMAC_SHA1_fail_tag_corrupt),
18398 		TEST_CASE_ST(ut_setup, ut_teardown,
18399 			auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
18400 		TEST_CASE_ST(ut_setup, ut_teardown,
18401 			auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
18402 
18403 		TEST_CASES_END() /**< NULL terminate unit test array */
18404 	}
18405 };
18406 
18407 static struct unit_test_suite cryptodev_multi_session_testsuite = {
18408 	.suite_name = "Multi Session Unit Test Suite",
18409 	.setup = multi_session_testsuite_setup,
18410 	.unit_test_cases = {
18411 		TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
18412 		TEST_CASE_ST(ut_setup, ut_teardown,
18413 				test_multi_session_random_usage),
18414 
18415 		TEST_CASES_END() /**< NULL terminate unit test array */
18416 	}
18417 };
18418 
18419 static struct unit_test_suite cryptodev_null_testsuite  = {
18420 	.suite_name = "NULL Test Suite",
18421 	.setup = null_testsuite_setup,
18422 	.unit_test_cases = {
18423 		TEST_CASE_ST(ut_setup, ut_teardown,
18424 			test_null_invalid_operation),
18425 		TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
18426 		TEST_CASES_END()
18427 	}
18428 };
18429 
18430 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite  = {
18431 	.suite_name = "AES CCM Authenticated Test Suite",
18432 	.setup = aes_ccm_auth_testsuite_setup,
18433 	.unit_test_cases = {
18434 		/** AES CCM Authenticated Encryption 128 bits key*/
18435 		TEST_CASE_ST(ut_setup, ut_teardown,
18436 			test_AES_CCM_authenticated_encryption_test_case_128_1),
18437 		TEST_CASE_ST(ut_setup, ut_teardown,
18438 			test_AES_CCM_authenticated_encryption_test_case_128_2),
18439 		TEST_CASE_ST(ut_setup, ut_teardown,
18440 			test_AES_CCM_authenticated_encryption_test_case_128_3),
18441 
18442 		/** AES CCM Authenticated Decryption 128 bits key*/
18443 		TEST_CASE_ST(ut_setup, ut_teardown,
18444 			test_AES_CCM_authenticated_decryption_test_case_128_1),
18445 		TEST_CASE_ST(ut_setup, ut_teardown,
18446 			test_AES_CCM_authenticated_decryption_test_case_128_2),
18447 		TEST_CASE_ST(ut_setup, ut_teardown,
18448 			test_AES_CCM_authenticated_decryption_test_case_128_3),
18449 
18450 		/** AES CCM Authenticated Encryption 192 bits key */
18451 		TEST_CASE_ST(ut_setup, ut_teardown,
18452 			test_AES_CCM_authenticated_encryption_test_case_192_1),
18453 		TEST_CASE_ST(ut_setup, ut_teardown,
18454 			test_AES_CCM_authenticated_encryption_test_case_192_2),
18455 		TEST_CASE_ST(ut_setup, ut_teardown,
18456 			test_AES_CCM_authenticated_encryption_test_case_192_3),
18457 
18458 		/** AES CCM Authenticated Decryption 192 bits key*/
18459 		TEST_CASE_ST(ut_setup, ut_teardown,
18460 			test_AES_CCM_authenticated_decryption_test_case_192_1),
18461 		TEST_CASE_ST(ut_setup, ut_teardown,
18462 			test_AES_CCM_authenticated_decryption_test_case_192_2),
18463 		TEST_CASE_ST(ut_setup, ut_teardown,
18464 			test_AES_CCM_authenticated_decryption_test_case_192_3),
18465 
18466 		/** AES CCM Authenticated Encryption 256 bits key */
18467 		TEST_CASE_ST(ut_setup, ut_teardown,
18468 			test_AES_CCM_authenticated_encryption_test_case_256_1),
18469 		TEST_CASE_ST(ut_setup, ut_teardown,
18470 			test_AES_CCM_authenticated_encryption_test_case_256_2),
18471 		TEST_CASE_ST(ut_setup, ut_teardown,
18472 			test_AES_CCM_authenticated_encryption_test_case_256_3),
18473 
18474 		/** AES CCM Authenticated Decryption 256 bits key*/
18475 		TEST_CASE_ST(ut_setup, ut_teardown,
18476 			test_AES_CCM_authenticated_decryption_test_case_256_1),
18477 		TEST_CASE_ST(ut_setup, ut_teardown,
18478 			test_AES_CCM_authenticated_decryption_test_case_256_2),
18479 		TEST_CASE_ST(ut_setup, ut_teardown,
18480 			test_AES_CCM_authenticated_decryption_test_case_256_3),
18481 		TEST_CASES_END()
18482 	}
18483 };
18484 
18485 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite  = {
18486 	.suite_name = "AES GCM Authenticated Test Suite",
18487 	.setup = aes_gcm_auth_testsuite_setup,
18488 	.unit_test_cases = {
18489 		/** AES GCM Authenticated Encryption */
18490 		TEST_CASE_ST(ut_setup, ut_teardown,
18491 			test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
18492 		TEST_CASE_ST(ut_setup, ut_teardown,
18493 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
18494 		TEST_CASE_ST(ut_setup, ut_teardown,
18495 			test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
18496 		TEST_CASE_ST(ut_setup, ut_teardown,
18497 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
18498 		TEST_CASE_ST(ut_setup, ut_teardown,
18499 			test_AES_GCM_authenticated_encryption_test_case_1),
18500 		TEST_CASE_ST(ut_setup, ut_teardown,
18501 			test_AES_GCM_authenticated_encryption_test_case_2),
18502 		TEST_CASE_ST(ut_setup, ut_teardown,
18503 			test_AES_GCM_authenticated_encryption_test_case_3),
18504 		TEST_CASE_ST(ut_setup, ut_teardown,
18505 			test_AES_GCM_authenticated_encryption_test_case_4),
18506 		TEST_CASE_ST(ut_setup, ut_teardown,
18507 			test_AES_GCM_authenticated_encryption_test_case_5),
18508 		TEST_CASE_ST(ut_setup, ut_teardown,
18509 			test_AES_GCM_authenticated_encryption_test_case_6),
18510 		TEST_CASE_ST(ut_setup, ut_teardown,
18511 			test_AES_GCM_authenticated_encryption_test_case_7),
18512 		TEST_CASE_ST(ut_setup, ut_teardown,
18513 			test_AES_GCM_authenticated_encryption_test_case_8),
18514 		TEST_CASE_ST(ut_setup, ut_teardown,
18515 			test_AES_GCM_J0_authenticated_encryption_test_case_1),
18516 
18517 		/** AES GCM Authenticated Decryption */
18518 		TEST_CASE_ST(ut_setup, ut_teardown,
18519 			test_AES_GCM_authenticated_decryption_test_case_1),
18520 		TEST_CASE_ST(ut_setup, ut_teardown,
18521 			test_AES_GCM_authenticated_decryption_test_case_2),
18522 		TEST_CASE_ST(ut_setup, ut_teardown,
18523 			test_AES_GCM_authenticated_decryption_test_case_3),
18524 		TEST_CASE_ST(ut_setup, ut_teardown,
18525 			test_AES_GCM_authenticated_decryption_test_case_4),
18526 		TEST_CASE_ST(ut_setup, ut_teardown,
18527 			test_AES_GCM_authenticated_decryption_test_case_5),
18528 		TEST_CASE_ST(ut_setup, ut_teardown,
18529 			test_AES_GCM_authenticated_decryption_test_case_6),
18530 		TEST_CASE_ST(ut_setup, ut_teardown,
18531 			test_AES_GCM_authenticated_decryption_test_case_7),
18532 		TEST_CASE_ST(ut_setup, ut_teardown,
18533 			test_AES_GCM_authenticated_decryption_test_case_8),
18534 		TEST_CASE_ST(ut_setup, ut_teardown,
18535 			test_AES_GCM_J0_authenticated_decryption_test_case_1),
18536 
18537 		/** AES GCM Authenticated Encryption 192 bits key */
18538 		TEST_CASE_ST(ut_setup, ut_teardown,
18539 			test_AES_GCM_auth_encryption_test_case_192_1),
18540 		TEST_CASE_ST(ut_setup, ut_teardown,
18541 			test_AES_GCM_auth_encryption_test_case_192_2),
18542 		TEST_CASE_ST(ut_setup, ut_teardown,
18543 			test_AES_GCM_auth_encryption_test_case_192_3),
18544 		TEST_CASE_ST(ut_setup, ut_teardown,
18545 			test_AES_GCM_auth_encryption_test_case_192_4),
18546 		TEST_CASE_ST(ut_setup, ut_teardown,
18547 			test_AES_GCM_auth_encryption_test_case_192_5),
18548 		TEST_CASE_ST(ut_setup, ut_teardown,
18549 			test_AES_GCM_auth_encryption_test_case_192_6),
18550 		TEST_CASE_ST(ut_setup, ut_teardown,
18551 			test_AES_GCM_auth_encryption_test_case_192_7),
18552 
18553 		/** AES GCM Authenticated Decryption 192 bits key */
18554 		TEST_CASE_ST(ut_setup, ut_teardown,
18555 			test_AES_GCM_auth_decryption_test_case_192_1),
18556 		TEST_CASE_ST(ut_setup, ut_teardown,
18557 			test_AES_GCM_auth_decryption_test_case_192_2),
18558 		TEST_CASE_ST(ut_setup, ut_teardown,
18559 			test_AES_GCM_auth_decryption_test_case_192_3),
18560 		TEST_CASE_ST(ut_setup, ut_teardown,
18561 			test_AES_GCM_auth_decryption_test_case_192_4),
18562 		TEST_CASE_ST(ut_setup, ut_teardown,
18563 			test_AES_GCM_auth_decryption_test_case_192_5),
18564 		TEST_CASE_ST(ut_setup, ut_teardown,
18565 			test_AES_GCM_auth_decryption_test_case_192_6),
18566 		TEST_CASE_ST(ut_setup, ut_teardown,
18567 			test_AES_GCM_auth_decryption_test_case_192_7),
18568 
18569 		/** AES GCM Authenticated Encryption 256 bits key */
18570 		TEST_CASE_ST(ut_setup, ut_teardown,
18571 			test_AES_GCM_auth_encryption_test_case_256_1),
18572 		TEST_CASE_ST(ut_setup, ut_teardown,
18573 			test_AES_GCM_auth_encryption_test_case_256_2),
18574 		TEST_CASE_ST(ut_setup, ut_teardown,
18575 			test_AES_GCM_auth_encryption_test_case_256_3),
18576 		TEST_CASE_ST(ut_setup, ut_teardown,
18577 			test_AES_GCM_auth_encryption_test_case_256_4),
18578 		TEST_CASE_ST(ut_setup, ut_teardown,
18579 			test_AES_GCM_auth_encryption_test_case_256_5),
18580 		TEST_CASE_ST(ut_setup, ut_teardown,
18581 			test_AES_GCM_auth_encryption_test_case_256_6),
18582 		TEST_CASE_ST(ut_setup, ut_teardown,
18583 			test_AES_GCM_auth_encryption_test_case_256_7),
18584 		TEST_CASE_ST(ut_setup, ut_teardown,
18585 			test_AES_GCM_auth_encryption_test_case_256_8),
18586 
18587 		/** AES GCM Authenticated Decryption 256 bits key */
18588 		TEST_CASE_ST(ut_setup, ut_teardown,
18589 			test_AES_GCM_auth_decryption_test_case_256_1),
18590 		TEST_CASE_ST(ut_setup, ut_teardown,
18591 			test_AES_GCM_auth_decryption_test_case_256_2),
18592 		TEST_CASE_ST(ut_setup, ut_teardown,
18593 			test_AES_GCM_auth_decryption_test_case_256_3),
18594 		TEST_CASE_ST(ut_setup, ut_teardown,
18595 			test_AES_GCM_auth_decryption_test_case_256_4),
18596 		TEST_CASE_ST(ut_setup, ut_teardown,
18597 			test_AES_GCM_auth_decryption_test_case_256_5),
18598 		TEST_CASE_ST(ut_setup, ut_teardown,
18599 			test_AES_GCM_auth_decryption_test_case_256_6),
18600 		TEST_CASE_ST(ut_setup, ut_teardown,
18601 			test_AES_GCM_auth_decryption_test_case_256_7),
18602 		TEST_CASE_ST(ut_setup, ut_teardown,
18603 			test_AES_GCM_auth_decryption_test_case_256_8),
18604 
18605 		/** AES GCM Authenticated Encryption big aad size */
18606 		TEST_CASE_ST(ut_setup, ut_teardown,
18607 			test_AES_GCM_auth_encryption_test_case_aad_1),
18608 		TEST_CASE_ST(ut_setup, ut_teardown,
18609 			test_AES_GCM_auth_encryption_test_case_aad_2),
18610 
18611 		/** AES GCM Authenticated Decryption big aad size */
18612 		TEST_CASE_ST(ut_setup, ut_teardown,
18613 			test_AES_GCM_auth_decryption_test_case_aad_1),
18614 		TEST_CASE_ST(ut_setup, ut_teardown,
18615 			test_AES_GCM_auth_decryption_test_case_aad_2),
18616 
18617 		/** Out of place tests */
18618 		TEST_CASE_ST(ut_setup, ut_teardown,
18619 			test_AES_GCM_authenticated_encryption_oop_test_case_1),
18620 		TEST_CASE_ST(ut_setup, ut_teardown,
18621 			test_AES_GCM_authenticated_decryption_oop_test_case_1),
18622 
18623 		/** Session-less tests */
18624 		TEST_CASE_ST(ut_setup, ut_teardown,
18625 			test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
18626 		TEST_CASE_ST(ut_setup, ut_teardown,
18627 			test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
18628 
18629 		/** AES GCM external mbuf tests */
18630 		TEST_CASE_ST(ut_setup, ut_teardown,
18631 			test_AES_GCM_authenticated_encryption_test_case_3_ext_mbuf),
18632 		TEST_CASE_ST(ut_setup, ut_teardown,
18633 			test_AES_GCM_authenticated_decryption_test_case_3_ext_mbuf),
18634 
18635 		TEST_CASES_END()
18636 	}
18637 };
18638 
18639 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite  = {
18640 	.suite_name = "AES GMAC Authentication Test Suite",
18641 	.setup = aes_gmac_auth_testsuite_setup,
18642 	.unit_test_cases = {
18643 		TEST_CASE_ST(ut_setup, ut_teardown,
18644 			test_AES_GMAC_authentication_test_case_1),
18645 		TEST_CASE_ST(ut_setup, ut_teardown,
18646 			test_AES_GMAC_authentication_verify_test_case_1),
18647 		TEST_CASE_ST(ut_setup, ut_teardown,
18648 			test_AES_GMAC_authentication_test_case_2),
18649 		TEST_CASE_ST(ut_setup, ut_teardown,
18650 			test_AES_GMAC_authentication_verify_test_case_2),
18651 		TEST_CASE_ST(ut_setup, ut_teardown,
18652 			test_AES_GMAC_authentication_test_case_3),
18653 		TEST_CASE_ST(ut_setup, ut_teardown,
18654 			test_AES_GMAC_authentication_verify_test_case_3),
18655 		TEST_CASE_ST(ut_setup, ut_teardown,
18656 			test_AES_GMAC_authentication_test_case_4),
18657 		TEST_CASE_ST(ut_setup, ut_teardown,
18658 			test_AES_GMAC_authentication_verify_test_case_4),
18659 		TEST_CASE_ST(ut_setup, ut_teardown,
18660 			test_AES_GMAC_authentication_SGL_40B),
18661 		TEST_CASE_ST(ut_setup, ut_teardown,
18662 			test_AES_GMAC_authentication_SGL_80B),
18663 		TEST_CASE_ST(ut_setup, ut_teardown,
18664 			test_AES_GMAC_authentication_SGL_2048B),
18665 		TEST_CASE_ST(ut_setup, ut_teardown,
18666 			test_AES_GMAC_authentication_SGL_2047B),
18667 
18668 		TEST_CASES_END()
18669 	}
18670 };
18671 
18672 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite  = {
18673 	.suite_name = "Chacha20-Poly1305 Test Suite",
18674 	.setup = chacha20_poly1305_testsuite_setup,
18675 	.unit_test_cases = {
18676 		TEST_CASE_ST(ut_setup, ut_teardown,
18677 			test_chacha20_poly1305_encrypt_test_case_rfc8439),
18678 		TEST_CASE_ST(ut_setup, ut_teardown,
18679 			test_chacha20_poly1305_decrypt_test_case_rfc8439),
18680 		TEST_CASE_ST(ut_setup, ut_teardown,
18681 			test_chacha20_poly1305_encrypt_SGL_out_of_place),
18682 		TEST_CASES_END()
18683 	}
18684 };
18685 
18686 static struct unit_test_suite cryptodev_snow3g_testsuite  = {
18687 	.suite_name = "SNOW 3G Test Suite",
18688 	.setup = snow3g_testsuite_setup,
18689 	.unit_test_cases = {
18690 		/** SNOW 3G encrypt only (UEA2) */
18691 		TEST_CASE_ST(ut_setup, ut_teardown,
18692 			test_snow3g_encryption_test_case_1),
18693 		TEST_CASE_ST(ut_setup, ut_teardown,
18694 			test_snow3g_encryption_test_case_2),
18695 		TEST_CASE_ST(ut_setup, ut_teardown,
18696 			test_snow3g_encryption_test_case_3),
18697 		TEST_CASE_ST(ut_setup, ut_teardown,
18698 			test_snow3g_encryption_test_case_4),
18699 		TEST_CASE_ST(ut_setup, ut_teardown,
18700 			test_snow3g_encryption_test_case_5),
18701 
18702 		TEST_CASE_ST(ut_setup, ut_teardown,
18703 			test_snow3g_encryption_test_case_1_oop),
18704 		TEST_CASE_ST(ut_setup, ut_teardown,
18705 			test_snow3g_encryption_test_case_1_oop_sgl),
18706 		TEST_CASE_ST(ut_setup, ut_teardown,
18707 			test_snow3g_encryption_test_case_1_oop_lb_in_sgl_out),
18708 		TEST_CASE_ST(ut_setup, ut_teardown,
18709 			test_snow3g_encryption_test_case_1_oop_sgl_in_lb_out),
18710 		TEST_CASE_ST(ut_setup, ut_teardown,
18711 			test_snow3g_encryption_test_case_1_offset_oop),
18712 		TEST_CASE_ST(ut_setup, ut_teardown,
18713 			test_snow3g_decryption_test_case_1_oop),
18714 
18715 		/** SNOW 3G generate auth, then encrypt (UEA2) */
18716 		TEST_CASE_ST(ut_setup, ut_teardown,
18717 			test_snow3g_auth_cipher_test_case_1),
18718 		TEST_CASE_ST(ut_setup, ut_teardown,
18719 			test_snow3g_auth_cipher_test_case_2),
18720 		TEST_CASE_ST(ut_setup, ut_teardown,
18721 			test_snow3g_auth_cipher_test_case_2_oop),
18722 		TEST_CASE_ST(ut_setup, ut_teardown,
18723 			test_snow3g_auth_cipher_part_digest_enc),
18724 		TEST_CASE_ST(ut_setup, ut_teardown,
18725 			test_snow3g_auth_cipher_part_digest_enc_oop),
18726 		TEST_CASE_ST(ut_setup, ut_teardown,
18727 			test_snow3g_auth_cipher_test_case_3_sgl),
18728 		TEST_CASE_ST(ut_setup, ut_teardown,
18729 			test_snow3g_auth_cipher_test_case_3_oop_sgl),
18730 		TEST_CASE_ST(ut_setup, ut_teardown,
18731 			test_snow3g_auth_cipher_part_digest_enc_sgl),
18732 		TEST_CASE_ST(ut_setup, ut_teardown,
18733 			test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
18734 		TEST_CASE_ST(ut_setup, ut_teardown,
18735 			test_snow3g_auth_cipher_total_digest_enc_1),
18736 		TEST_CASE_ST(ut_setup, ut_teardown,
18737 			test_snow3g_auth_cipher_total_digest_enc_1_oop),
18738 		TEST_CASE_ST(ut_setup, ut_teardown,
18739 			test_snow3g_auth_cipher_total_digest_enc_1_sgl),
18740 		TEST_CASE_ST(ut_setup, ut_teardown,
18741 			test_snow3g_auth_cipher_total_digest_enc_1_oop_sgl),
18742 
18743 		/** SNOW 3G decrypt (UEA2), then verify auth */
18744 		TEST_CASE_ST(ut_setup, ut_teardown,
18745 			test_snow3g_auth_cipher_verify_test_case_1),
18746 		TEST_CASE_ST(ut_setup, ut_teardown,
18747 			test_snow3g_auth_cipher_verify_test_case_2),
18748 		TEST_CASE_ST(ut_setup, ut_teardown,
18749 			test_snow3g_auth_cipher_verify_test_case_2_oop),
18750 		TEST_CASE_ST(ut_setup, ut_teardown,
18751 			test_snow3g_auth_cipher_verify_part_digest_enc),
18752 		TEST_CASE_ST(ut_setup, ut_teardown,
18753 			test_snow3g_auth_cipher_verify_part_digest_enc_oop),
18754 		TEST_CASE_ST(ut_setup, ut_teardown,
18755 			test_snow3g_auth_cipher_verify_test_case_3_sgl),
18756 		TEST_CASE_ST(ut_setup, ut_teardown,
18757 			test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
18758 		TEST_CASE_ST(ut_setup, ut_teardown,
18759 			test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
18760 		TEST_CASE_ST(ut_setup, ut_teardown,
18761 			test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
18762 		TEST_CASE_ST(ut_setup, ut_teardown,
18763 			test_snow3g_auth_cipher_verify_total_digest_enc_1),
18764 		TEST_CASE_ST(ut_setup, ut_teardown,
18765 			test_snow3g_auth_cipher_verify_total_digest_enc_1_oop),
18766 		TEST_CASE_ST(ut_setup, ut_teardown,
18767 			test_snow3g_auth_cipher_verify_total_digest_enc_1_sgl),
18768 		TEST_CASE_ST(ut_setup, ut_teardown,
18769 			test_snow3g_auth_cipher_verify_total_digest_enc_1_oop_sgl),
18770 
18771 		/** SNOW 3G decrypt only (UEA2) */
18772 		TEST_CASE_ST(ut_setup, ut_teardown,
18773 			test_snow3g_decryption_test_case_1),
18774 		TEST_CASE_ST(ut_setup, ut_teardown,
18775 			test_snow3g_decryption_test_case_2),
18776 		TEST_CASE_ST(ut_setup, ut_teardown,
18777 			test_snow3g_decryption_test_case_3),
18778 		TEST_CASE_ST(ut_setup, ut_teardown,
18779 			test_snow3g_decryption_test_case_4),
18780 		TEST_CASE_ST(ut_setup, ut_teardown,
18781 			test_snow3g_decryption_test_case_5),
18782 		TEST_CASE_ST(ut_setup, ut_teardown,
18783 			test_snow3g_decryption_with_digest_test_case_1),
18784 		TEST_CASE_ST(ut_setup, ut_teardown,
18785 			test_snow3g_hash_generate_test_case_1),
18786 		TEST_CASE_ST(ut_setup, ut_teardown,
18787 			test_snow3g_hash_generate_test_case_2),
18788 		TEST_CASE_ST(ut_setup, ut_teardown,
18789 			test_snow3g_hash_generate_test_case_3),
18790 
18791 		/* Tests with buffers which length is not byte-aligned */
18792 		TEST_CASE_ST(ut_setup, ut_teardown,
18793 			test_snow3g_hash_generate_test_case_4),
18794 		TEST_CASE_ST(ut_setup, ut_teardown,
18795 			test_snow3g_hash_generate_test_case_5),
18796 		TEST_CASE_ST(ut_setup, ut_teardown,
18797 			test_snow3g_hash_generate_test_case_6),
18798 		TEST_CASE_ST(ut_setup, ut_teardown,
18799 			test_snow3g_hash_verify_test_case_1),
18800 		TEST_CASE_ST(ut_setup, ut_teardown,
18801 			test_snow3g_hash_verify_test_case_2),
18802 		TEST_CASE_ST(ut_setup, ut_teardown,
18803 			test_snow3g_hash_verify_test_case_3),
18804 
18805 		/* Tests with buffers which length is not byte-aligned */
18806 		TEST_CASE_ST(ut_setup, ut_teardown,
18807 			test_snow3g_hash_verify_test_case_4),
18808 		TEST_CASE_ST(ut_setup, ut_teardown,
18809 			test_snow3g_hash_verify_test_case_5),
18810 		TEST_CASE_ST(ut_setup, ut_teardown,
18811 			test_snow3g_hash_verify_test_case_6),
18812 		TEST_CASE_ST(ut_setup, ut_teardown,
18813 			test_snow3g_cipher_auth_test_case_1),
18814 		TEST_CASE_ST(ut_setup, ut_teardown,
18815 			test_snow3g_auth_cipher_with_digest_test_case_1),
18816 		TEST_CASES_END()
18817 	}
18818 };
18819 
18820 static struct unit_test_suite cryptodev_zuc_testsuite  = {
18821 	.suite_name = "ZUC Test Suite",
18822 	.setup = zuc_testsuite_setup,
18823 	.unit_test_cases = {
18824 		/** ZUC encrypt only (EEA3) */
18825 		TEST_CASE_ST(ut_setup, ut_teardown,
18826 			test_zuc_encryption_test_case_1),
18827 		TEST_CASE_ST(ut_setup, ut_teardown,
18828 			test_zuc_encryption_test_case_2),
18829 		TEST_CASE_ST(ut_setup, ut_teardown,
18830 			test_zuc_encryption_test_case_3),
18831 		TEST_CASE_ST(ut_setup, ut_teardown,
18832 			test_zuc_encryption_test_case_4),
18833 		TEST_CASE_ST(ut_setup, ut_teardown,
18834 			test_zuc_encryption_test_case_5),
18835 		TEST_CASE_ST(ut_setup, ut_teardown,
18836 			test_zuc_encryption_test_case_6_sgl),
18837 
18838 		/** ZUC decrypt only (EEA3) */
18839 		TEST_CASE_ST(ut_setup, ut_teardown,
18840 			test_zuc_decryption_test_case_1),
18841 		TEST_CASE_ST(ut_setup, ut_teardown,
18842 			test_zuc_decryption_test_case_2),
18843 		TEST_CASE_ST(ut_setup, ut_teardown,
18844 			test_zuc_decryption_test_case_3),
18845 		TEST_CASE_ST(ut_setup, ut_teardown,
18846 			test_zuc_decryption_test_case_4),
18847 		TEST_CASE_ST(ut_setup, ut_teardown,
18848 			test_zuc_decryption_test_case_5),
18849 		TEST_CASE_ST(ut_setup, ut_teardown,
18850 			test_zuc_decryption_test_case_6_sgl),
18851 
18852 		/** ZUC authenticate (EIA3) */
18853 		TEST_CASE_ST(ut_setup, ut_teardown,
18854 			test_zuc_hash_generate_test_case_1),
18855 		TEST_CASE_ST(ut_setup, ut_teardown,
18856 			test_zuc_hash_generate_test_case_2),
18857 		TEST_CASE_ST(ut_setup, ut_teardown,
18858 			test_zuc_hash_generate_test_case_3),
18859 		TEST_CASE_ST(ut_setup, ut_teardown,
18860 			test_zuc_hash_generate_test_case_4),
18861 		TEST_CASE_ST(ut_setup, ut_teardown,
18862 			test_zuc_hash_generate_test_case_5),
18863 		TEST_CASE_ST(ut_setup, ut_teardown,
18864 			test_zuc_hash_generate_test_case_6),
18865 		TEST_CASE_ST(ut_setup, ut_teardown,
18866 			test_zuc_hash_generate_test_case_7),
18867 		TEST_CASE_ST(ut_setup, ut_teardown,
18868 			test_zuc_hash_generate_test_case_8),
18869 
18870 		/** ZUC verify (EIA3) */
18871 		TEST_CASE_ST(ut_setup, ut_teardown,
18872 			test_zuc_hash_verify_test_case_1),
18873 		TEST_CASE_ST(ut_setup, ut_teardown,
18874 			test_zuc_hash_verify_test_case_2),
18875 		TEST_CASE_ST(ut_setup, ut_teardown,
18876 			test_zuc_hash_verify_test_case_3),
18877 		TEST_CASE_ST(ut_setup, ut_teardown,
18878 			test_zuc_hash_verify_test_case_4),
18879 		TEST_CASE_ST(ut_setup, ut_teardown,
18880 			test_zuc_hash_verify_test_case_5),
18881 		TEST_CASE_ST(ut_setup, ut_teardown,
18882 			test_zuc_hash_verify_test_case_6),
18883 		TEST_CASE_ST(ut_setup, ut_teardown,
18884 			test_zuc_hash_verify_test_case_7),
18885 		TEST_CASE_ST(ut_setup, ut_teardown,
18886 			test_zuc_hash_verify_test_case_8),
18887 
18888 		/** ZUC alg-chain (EEA3/EIA3) */
18889 		TEST_CASE_ST(ut_setup, ut_teardown,
18890 			test_zuc_cipher_auth_test_case_1),
18891 		TEST_CASE_ST(ut_setup, ut_teardown,
18892 			test_zuc_cipher_auth_test_case_2),
18893 
18894 		/** ZUC generate auth, then encrypt (EEA3) */
18895 		TEST_CASE_ST(ut_setup, ut_teardown,
18896 			test_zuc_auth_cipher_test_case_1),
18897 		TEST_CASE_ST(ut_setup, ut_teardown,
18898 			test_zuc_auth_cipher_test_case_1_oop),
18899 		TEST_CASE_ST(ut_setup, ut_teardown,
18900 			test_zuc_auth_cipher_test_case_1_sgl),
18901 		TEST_CASE_ST(ut_setup, ut_teardown,
18902 			test_zuc_auth_cipher_test_case_1_oop_sgl),
18903 		TEST_CASE_ST(ut_setup, ut_teardown,
18904 			test_zuc_auth_cipher_test_case_2),
18905 		TEST_CASE_ST(ut_setup, ut_teardown,
18906 			test_zuc_auth_cipher_test_case_2_oop),
18907 
18908 		/** ZUC decrypt (EEA3), then verify auth */
18909 		TEST_CASE_ST(ut_setup, ut_teardown,
18910 			test_zuc_auth_cipher_verify_test_case_1),
18911 		TEST_CASE_ST(ut_setup, ut_teardown,
18912 			test_zuc_auth_cipher_verify_test_case_1_oop),
18913 		TEST_CASE_ST(ut_setup, ut_teardown,
18914 			test_zuc_auth_cipher_verify_test_case_1_sgl),
18915 		TEST_CASE_ST(ut_setup, ut_teardown,
18916 			test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
18917 		TEST_CASE_ST(ut_setup, ut_teardown,
18918 			test_zuc_auth_cipher_verify_test_case_2),
18919 		TEST_CASE_ST(ut_setup, ut_teardown,
18920 			test_zuc_auth_cipher_verify_test_case_2_oop),
18921 
18922 		/** ZUC-256 encrypt only **/
18923 		TEST_CASE_ST(ut_setup, ut_teardown,
18924 			test_zuc256_encryption_test_case_1),
18925 		TEST_CASE_ST(ut_setup, ut_teardown,
18926 			test_zuc256_encryption_test_case_2),
18927 
18928 		/** ZUC-256 decrypt only **/
18929 		TEST_CASE_ST(ut_setup, ut_teardown,
18930 			test_zuc256_decryption_test_case_1),
18931 		TEST_CASE_ST(ut_setup, ut_teardown,
18932 			test_zuc256_decryption_test_case_2),
18933 
18934 		/** ZUC-256 authentication only **/
18935 		TEST_CASE_ST(ut_setup, ut_teardown,
18936 			test_zuc256_hash_generate_4b_tag_test_case_1),
18937 		TEST_CASE_ST(ut_setup, ut_teardown,
18938 			test_zuc256_hash_generate_4b_tag_test_case_2),
18939 		TEST_CASE_ST(ut_setup, ut_teardown,
18940 			test_zuc256_hash_generate_4b_tag_test_case_3),
18941 		TEST_CASE_ST(ut_setup, ut_teardown,
18942 			test_zuc256_hash_generate_8b_tag_test_case_1),
18943 		TEST_CASE_ST(ut_setup, ut_teardown,
18944 			test_zuc256_hash_generate_16b_tag_test_case_1),
18945 
18946 		/** ZUC-256 authentication verify only **/
18947 		TEST_CASE_ST(ut_setup, ut_teardown,
18948 			test_zuc256_hash_verify_4b_tag_test_case_1),
18949 		TEST_CASE_ST(ut_setup, ut_teardown,
18950 			test_zuc256_hash_verify_4b_tag_test_case_2),
18951 		TEST_CASE_ST(ut_setup, ut_teardown,
18952 			test_zuc256_hash_verify_4b_tag_test_case_3),
18953 		TEST_CASE_ST(ut_setup, ut_teardown,
18954 			test_zuc256_hash_verify_8b_tag_test_case_1),
18955 		TEST_CASE_ST(ut_setup, ut_teardown,
18956 			test_zuc256_hash_verify_16b_tag_test_case_1),
18957 
18958 		/** ZUC-256 encrypt and authenticate **/
18959 		TEST_CASE_ST(ut_setup, ut_teardown,
18960 			test_zuc256_cipher_auth_4b_tag_test_case_1),
18961 		TEST_CASE_ST(ut_setup, ut_teardown,
18962 			test_zuc256_cipher_auth_4b_tag_test_case_2),
18963 		TEST_CASE_ST(ut_setup, ut_teardown,
18964 			test_zuc256_cipher_auth_8b_tag_test_case_1),
18965 		TEST_CASE_ST(ut_setup, ut_teardown,
18966 			test_zuc256_cipher_auth_16b_tag_test_case_1),
18967 
18968 		/** ZUC-256 generate auth, then encrypt */
18969 		TEST_CASE_ST(ut_setup, ut_teardown,
18970 			test_zuc256_auth_cipher_4b_tag_test_case_1),
18971 		TEST_CASE_ST(ut_setup, ut_teardown,
18972 			test_zuc256_auth_cipher_4b_tag_test_case_2),
18973 		TEST_CASE_ST(ut_setup, ut_teardown,
18974 			test_zuc256_auth_cipher_8b_tag_test_case_1),
18975 		TEST_CASE_ST(ut_setup, ut_teardown,
18976 			test_zuc256_auth_cipher_16b_tag_test_case_1),
18977 
18978 		/** ZUC-256 decrypt, then verify auth */
18979 		TEST_CASE_ST(ut_setup, ut_teardown,
18980 			test_zuc256_auth_cipher_verify_4b_tag_test_case_1),
18981 		TEST_CASE_ST(ut_setup, ut_teardown,
18982 			test_zuc256_auth_cipher_verify_4b_tag_test_case_2),
18983 		TEST_CASE_ST(ut_setup, ut_teardown,
18984 			test_zuc256_auth_cipher_verify_8b_tag_test_case_1),
18985 		TEST_CASE_ST(ut_setup, ut_teardown,
18986 			test_zuc256_auth_cipher_verify_16b_tag_test_case_1),
18987 
18988 		TEST_CASES_END()
18989 	}
18990 };
18991 
18992 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite  = {
18993 	.suite_name = "HMAC_MD5 Authentication Test Suite",
18994 	.setup = hmac_md5_auth_testsuite_setup,
18995 	.unit_test_cases = {
18996 		TEST_CASE_ST(ut_setup, ut_teardown,
18997 			test_MD5_HMAC_generate_case_1),
18998 		TEST_CASE_ST(ut_setup, ut_teardown,
18999 			test_MD5_HMAC_verify_case_1),
19000 		TEST_CASE_ST(ut_setup, ut_teardown,
19001 			test_MD5_HMAC_generate_case_2),
19002 		TEST_CASE_ST(ut_setup, ut_teardown,
19003 			test_MD5_HMAC_verify_case_2),
19004 		TEST_CASES_END()
19005 	}
19006 };
19007 
19008 static struct unit_test_suite cryptodev_kasumi_testsuite  = {
19009 	.suite_name = "Kasumi Test Suite",
19010 	.setup = kasumi_testsuite_setup,
19011 	.unit_test_cases = {
19012 		/** KASUMI hash only (UIA1) */
19013 		TEST_CASE_ST(ut_setup, ut_teardown,
19014 			test_kasumi_hash_generate_test_case_1),
19015 		TEST_CASE_ST(ut_setup, ut_teardown,
19016 			test_kasumi_hash_generate_test_case_2),
19017 		TEST_CASE_ST(ut_setup, ut_teardown,
19018 			test_kasumi_hash_generate_test_case_3),
19019 		TEST_CASE_ST(ut_setup, ut_teardown,
19020 			test_kasumi_hash_generate_test_case_4),
19021 		TEST_CASE_ST(ut_setup, ut_teardown,
19022 			test_kasumi_hash_generate_test_case_5),
19023 		TEST_CASE_ST(ut_setup, ut_teardown,
19024 			test_kasumi_hash_generate_test_case_6),
19025 
19026 		TEST_CASE_ST(ut_setup, ut_teardown,
19027 			test_kasumi_hash_verify_test_case_1),
19028 		TEST_CASE_ST(ut_setup, ut_teardown,
19029 			test_kasumi_hash_verify_test_case_2),
19030 		TEST_CASE_ST(ut_setup, ut_teardown,
19031 			test_kasumi_hash_verify_test_case_3),
19032 		TEST_CASE_ST(ut_setup, ut_teardown,
19033 			test_kasumi_hash_verify_test_case_4),
19034 		TEST_CASE_ST(ut_setup, ut_teardown,
19035 			test_kasumi_hash_verify_test_case_5),
19036 
19037 		/** KASUMI encrypt only (UEA1) */
19038 		TEST_CASE_ST(ut_setup, ut_teardown,
19039 			test_kasumi_encryption_test_case_1),
19040 		TEST_CASE_ST(ut_setup, ut_teardown,
19041 			test_kasumi_encryption_test_case_1_sgl),
19042 		TEST_CASE_ST(ut_setup, ut_teardown,
19043 			test_kasumi_encryption_test_case_1_oop),
19044 		TEST_CASE_ST(ut_setup, ut_teardown,
19045 			test_kasumi_encryption_test_case_1_oop_sgl),
19046 		TEST_CASE_ST(ut_setup, ut_teardown,
19047 			test_kasumi_encryption_test_case_2),
19048 		TEST_CASE_ST(ut_setup, ut_teardown,
19049 			test_kasumi_encryption_test_case_3),
19050 		TEST_CASE_ST(ut_setup, ut_teardown,
19051 			test_kasumi_encryption_test_case_4),
19052 		TEST_CASE_ST(ut_setup, ut_teardown,
19053 			test_kasumi_encryption_test_case_5),
19054 
19055 		/** KASUMI decrypt only (UEA1) */
19056 		TEST_CASE_ST(ut_setup, ut_teardown,
19057 			test_kasumi_decryption_test_case_1),
19058 		TEST_CASE_ST(ut_setup, ut_teardown,
19059 			test_kasumi_decryption_test_case_2),
19060 		TEST_CASE_ST(ut_setup, ut_teardown,
19061 			test_kasumi_decryption_test_case_3),
19062 		TEST_CASE_ST(ut_setup, ut_teardown,
19063 			test_kasumi_decryption_test_case_4),
19064 		TEST_CASE_ST(ut_setup, ut_teardown,
19065 			test_kasumi_decryption_test_case_5),
19066 		TEST_CASE_ST(ut_setup, ut_teardown,
19067 			test_kasumi_decryption_test_case_1_oop),
19068 		TEST_CASE_ST(ut_setup, ut_teardown,
19069 			test_kasumi_cipher_auth_test_case_1),
19070 
19071 		/** KASUMI generate auth, then encrypt (F8) */
19072 		TEST_CASE_ST(ut_setup, ut_teardown,
19073 			test_kasumi_auth_cipher_test_case_1),
19074 		TEST_CASE_ST(ut_setup, ut_teardown,
19075 			test_kasumi_auth_cipher_test_case_2),
19076 		TEST_CASE_ST(ut_setup, ut_teardown,
19077 			test_kasumi_auth_cipher_test_case_2_oop),
19078 		TEST_CASE_ST(ut_setup, ut_teardown,
19079 			test_kasumi_auth_cipher_test_case_2_sgl),
19080 		TEST_CASE_ST(ut_setup, ut_teardown,
19081 			test_kasumi_auth_cipher_test_case_2_oop_sgl),
19082 
19083 		/** KASUMI decrypt (F8), then verify auth */
19084 		TEST_CASE_ST(ut_setup, ut_teardown,
19085 			test_kasumi_auth_cipher_verify_test_case_1),
19086 		TEST_CASE_ST(ut_setup, ut_teardown,
19087 			test_kasumi_auth_cipher_verify_test_case_2),
19088 		TEST_CASE_ST(ut_setup, ut_teardown,
19089 			test_kasumi_auth_cipher_verify_test_case_2_oop),
19090 		TEST_CASE_ST(ut_setup, ut_teardown,
19091 			test_kasumi_auth_cipher_verify_test_case_2_sgl),
19092 		TEST_CASE_ST(ut_setup, ut_teardown,
19093 			test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
19094 
19095 		TEST_CASES_END()
19096 	}
19097 };
19098 
19099 static struct unit_test_suite cryptodev_esn_testsuite  = {
19100 	.suite_name = "ESN Test Suite",
19101 	.setup = esn_testsuite_setup,
19102 	.unit_test_cases = {
19103 		TEST_CASE_ST(ut_setup, ut_teardown,
19104 			auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
19105 		TEST_CASE_ST(ut_setup, ut_teardown,
19106 			auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
19107 		TEST_CASES_END()
19108 	}
19109 };
19110 
19111 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite  = {
19112 	.suite_name = "Negative AES GCM Test Suite",
19113 	.setup = negative_aes_gcm_testsuite_setup,
19114 	.unit_test_cases = {
19115 		TEST_CASE_ST(ut_setup, ut_teardown,
19116 			test_AES_GCM_auth_encryption_fail_iv_corrupt),
19117 		TEST_CASE_ST(ut_setup, ut_teardown,
19118 			test_AES_GCM_auth_encryption_fail_in_data_corrupt),
19119 		TEST_CASE_ST(ut_setup, ut_teardown,
19120 			test_AES_GCM_auth_encryption_fail_out_data_corrupt),
19121 		TEST_CASE_ST(ut_setup, ut_teardown,
19122 			test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
19123 		TEST_CASE_ST(ut_setup, ut_teardown,
19124 			test_AES_GCM_auth_encryption_fail_aad_corrupt),
19125 		TEST_CASE_ST(ut_setup, ut_teardown,
19126 			test_AES_GCM_auth_encryption_fail_tag_corrupt),
19127 		TEST_CASE_ST(ut_setup, ut_teardown,
19128 			test_AES_GCM_auth_decryption_fail_iv_corrupt),
19129 		TEST_CASE_ST(ut_setup, ut_teardown,
19130 			test_AES_GCM_auth_decryption_fail_in_data_corrupt),
19131 		TEST_CASE_ST(ut_setup, ut_teardown,
19132 			test_AES_GCM_auth_decryption_fail_out_data_corrupt),
19133 		TEST_CASE_ST(ut_setup, ut_teardown,
19134 			test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
19135 		TEST_CASE_ST(ut_setup, ut_teardown,
19136 			test_AES_GCM_auth_decryption_fail_aad_corrupt),
19137 		TEST_CASE_ST(ut_setup, ut_teardown,
19138 			test_AES_GCM_auth_decryption_fail_tag_corrupt),
19139 
19140 		TEST_CASES_END()
19141 	}
19142 };
19143 
19144 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite  = {
19145 	.suite_name = "Negative AES GMAC Test Suite",
19146 	.setup = negative_aes_gmac_testsuite_setup,
19147 	.unit_test_cases = {
19148 		TEST_CASE_ST(ut_setup, ut_teardown,
19149 			authentication_verify_AES128_GMAC_fail_data_corrupt),
19150 		TEST_CASE_ST(ut_setup, ut_teardown,
19151 			authentication_verify_AES128_GMAC_fail_tag_corrupt),
19152 
19153 		TEST_CASES_END()
19154 	}
19155 };
19156 
19157 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite  = {
19158 	.suite_name = "Mixed CIPHER + HASH algorithms Test Suite",
19159 	.setup = mixed_cipher_hash_testsuite_setup,
19160 	.unit_test_cases = {
19161 		/** AUTH AES CMAC + CIPHER AES CTR */
19162 		TEST_CASE_ST(ut_setup, ut_teardown,
19163 			test_aes_cmac_aes_ctr_digest_enc_test_case_1),
19164 		TEST_CASE_ST(ut_setup, ut_teardown,
19165 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
19166 		TEST_CASE_ST(ut_setup, ut_teardown,
19167 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
19168 		TEST_CASE_ST(ut_setup, ut_teardown,
19169 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
19170 		TEST_CASE_ST(ut_setup, ut_teardown,
19171 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
19172 		TEST_CASE_ST(ut_setup, ut_teardown,
19173 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
19174 		TEST_CASE_ST(ut_setup, ut_teardown,
19175 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
19176 		TEST_CASE_ST(ut_setup, ut_teardown,
19177 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
19178 		TEST_CASE_ST(ut_setup, ut_teardown,
19179 			test_aes_cmac_aes_ctr_digest_enc_test_case_2),
19180 		TEST_CASE_ST(ut_setup, ut_teardown,
19181 			test_aes_cmac_aes_ctr_digest_enc_test_case_2_oop),
19182 		TEST_CASE_ST(ut_setup, ut_teardown,
19183 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2),
19184 		TEST_CASE_ST(ut_setup, ut_teardown,
19185 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2_oop),
19186 
19187 		/** AUTH ZUC + CIPHER SNOW3G */
19188 		TEST_CASE_ST(ut_setup, ut_teardown,
19189 			test_auth_zuc_cipher_snow_test_case_1),
19190 		TEST_CASE_ST(ut_setup, ut_teardown,
19191 			test_verify_auth_zuc_cipher_snow_test_case_1),
19192 		TEST_CASE_ST(ut_setup, ut_teardown,
19193 			test_auth_zuc_cipher_snow_test_case_1_inplace),
19194 		TEST_CASE_ST(ut_setup, ut_teardown,
19195 			test_verify_auth_zuc_cipher_snow_test_case_1_inplace),
19196 		/** AUTH AES CMAC + CIPHER SNOW3G */
19197 		TEST_CASE_ST(ut_setup, ut_teardown,
19198 			test_auth_aes_cmac_cipher_snow_test_case_1),
19199 		TEST_CASE_ST(ut_setup, ut_teardown,
19200 			test_verify_auth_aes_cmac_cipher_snow_test_case_1),
19201 		TEST_CASE_ST(ut_setup, ut_teardown,
19202 			test_auth_aes_cmac_cipher_snow_test_case_1_inplace),
19203 		TEST_CASE_ST(ut_setup, ut_teardown,
19204 			test_verify_auth_aes_cmac_cipher_snow_test_case_1_inplace),
19205 		/** AUTH ZUC + CIPHER AES CTR */
19206 		TEST_CASE_ST(ut_setup, ut_teardown,
19207 			test_auth_zuc_cipher_aes_ctr_test_case_1),
19208 		TEST_CASE_ST(ut_setup, ut_teardown,
19209 			test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
19210 		TEST_CASE_ST(ut_setup, ut_teardown,
19211 			test_auth_zuc_cipher_aes_ctr_test_case_1_inplace),
19212 		TEST_CASE_ST(ut_setup, ut_teardown,
19213 			test_verify_auth_zuc_cipher_aes_ctr_test_case_1_inplace),
19214 		/** AUTH SNOW3G + CIPHER AES CTR */
19215 		TEST_CASE_ST(ut_setup, ut_teardown,
19216 			test_auth_snow_cipher_aes_ctr_test_case_1),
19217 		TEST_CASE_ST(ut_setup, ut_teardown,
19218 			test_verify_auth_snow_cipher_aes_ctr_test_case_1),
19219 		TEST_CASE_ST(ut_setup, ut_teardown,
19220 			test_auth_snow_cipher_aes_ctr_test_case_1_inplace),
19221 		TEST_CASE_ST(ut_setup, ut_teardown,
19222 			test_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl),
19223 		TEST_CASE_ST(ut_setup, ut_teardown,
19224 			test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace),
19225 		TEST_CASE_ST(ut_setup, ut_teardown,
19226 			test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl),
19227 		/** AUTH SNOW3G + CIPHER ZUC */
19228 		TEST_CASE_ST(ut_setup, ut_teardown,
19229 			test_auth_snow_cipher_zuc_test_case_1),
19230 		TEST_CASE_ST(ut_setup, ut_teardown,
19231 			test_verify_auth_snow_cipher_zuc_test_case_1),
19232 		TEST_CASE_ST(ut_setup, ut_teardown,
19233 			test_auth_snow_cipher_zuc_test_case_1_inplace),
19234 		TEST_CASE_ST(ut_setup, ut_teardown,
19235 			test_verify_auth_snow_cipher_zuc_test_case_1_inplace),
19236 		/** AUTH AES CMAC + CIPHER ZUC */
19237 		TEST_CASE_ST(ut_setup, ut_teardown,
19238 			test_auth_aes_cmac_cipher_zuc_test_case_1),
19239 		TEST_CASE_ST(ut_setup, ut_teardown,
19240 			test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
19241 		TEST_CASE_ST(ut_setup, ut_teardown,
19242 			test_auth_aes_cmac_cipher_zuc_test_case_1_inplace),
19243 		TEST_CASE_ST(ut_setup, ut_teardown,
19244 			test_verify_auth_aes_cmac_cipher_zuc_test_case_1_inplace),
19245 
19246 		/** AUTH NULL + CIPHER SNOW3G */
19247 		TEST_CASE_ST(ut_setup, ut_teardown,
19248 			test_auth_null_cipher_snow_test_case_1),
19249 		TEST_CASE_ST(ut_setup, ut_teardown,
19250 			test_verify_auth_null_cipher_snow_test_case_1),
19251 		/** AUTH NULL + CIPHER ZUC */
19252 		TEST_CASE_ST(ut_setup, ut_teardown,
19253 			test_auth_null_cipher_zuc_test_case_1),
19254 		TEST_CASE_ST(ut_setup, ut_teardown,
19255 			test_verify_auth_null_cipher_zuc_test_case_1),
19256 		/** AUTH SNOW3G + CIPHER NULL */
19257 		TEST_CASE_ST(ut_setup, ut_teardown,
19258 			test_auth_snow_cipher_null_test_case_1),
19259 		TEST_CASE_ST(ut_setup, ut_teardown,
19260 			test_verify_auth_snow_cipher_null_test_case_1),
19261 		/** AUTH ZUC + CIPHER NULL */
19262 		TEST_CASE_ST(ut_setup, ut_teardown,
19263 			test_auth_zuc_cipher_null_test_case_1),
19264 		TEST_CASE_ST(ut_setup, ut_teardown,
19265 			test_verify_auth_zuc_cipher_null_test_case_1),
19266 		/** AUTH NULL + CIPHER AES CTR */
19267 		TEST_CASE_ST(ut_setup, ut_teardown,
19268 			test_auth_null_cipher_aes_ctr_test_case_1),
19269 		TEST_CASE_ST(ut_setup, ut_teardown,
19270 			test_verify_auth_null_cipher_aes_ctr_test_case_1),
19271 		/** AUTH AES CMAC + CIPHER NULL */
19272 		TEST_CASE_ST(ut_setup, ut_teardown,
19273 			test_auth_aes_cmac_cipher_null_test_case_1),
19274 		TEST_CASE_ST(ut_setup, ut_teardown,
19275 			test_verify_auth_aes_cmac_cipher_null_test_case_1),
19276 		TEST_CASES_END()
19277 	}
19278 };
19279 
19280 static int
19281 run_cryptodev_testsuite(const char *pmd_name)
19282 {
19283 	uint8_t ret, j, i = 0, blk_start_idx = 0;
19284 	const enum blockcipher_test_type blk_suites[] = {
19285 		BLKCIPHER_AES_CHAIN_TYPE,
19286 		BLKCIPHER_AES_CIPHERONLY_TYPE,
19287 		BLKCIPHER_AES_DOCSIS_TYPE,
19288 		BLKCIPHER_3DES_CHAIN_TYPE,
19289 		BLKCIPHER_3DES_CIPHERONLY_TYPE,
19290 		BLKCIPHER_DES_CIPHERONLY_TYPE,
19291 		BLKCIPHER_DES_DOCSIS_TYPE,
19292 		BLKCIPHER_SM4_CHAIN_TYPE,
19293 		BLKCIPHER_SM4_CIPHERONLY_TYPE,
19294 		BLKCIPHER_AUTHONLY_TYPE};
19295 	struct unit_test_suite *static_suites[] = {
19296 		&cryptodev_multi_session_testsuite,
19297 		&cryptodev_null_testsuite,
19298 		&cryptodev_aes_ccm_auth_testsuite,
19299 		&cryptodev_aes_gcm_auth_testsuite,
19300 		&cryptodev_aes_gmac_auth_testsuite,
19301 		&cryptodev_snow3g_testsuite,
19302 		&cryptodev_chacha20_poly1305_testsuite,
19303 		&cryptodev_zuc_testsuite,
19304 		&cryptodev_hmac_md5_auth_testsuite,
19305 		&cryptodev_kasumi_testsuite,
19306 		&cryptodev_esn_testsuite,
19307 		&cryptodev_negative_aes_gcm_testsuite,
19308 		&cryptodev_negative_aes_gmac_testsuite,
19309 		&cryptodev_mixed_cipher_hash_testsuite,
19310 		&cryptodev_negative_hmac_sha1_testsuite,
19311 		&cryptodev_gen_testsuite,
19312 #ifdef RTE_LIB_SECURITY
19313 		&ipsec_proto_testsuite,
19314 		&pdcp_proto_testsuite,
19315 		&docsis_proto_testsuite,
19316 		&tls12_record_proto_testsuite,
19317 		&dtls12_record_proto_testsuite,
19318 		&tls13_record_proto_testsuite,
19319 #endif
19320 		&end_testsuite
19321 	};
19322 	static struct unit_test_suite ts = {
19323 		.suite_name = "Cryptodev Unit Test Suite",
19324 		.setup = testsuite_setup,
19325 		.teardown = testsuite_teardown,
19326 		.unit_test_cases = {TEST_CASES_END()}
19327 	};
19328 
19329 	gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name);
19330 
19331 	if (gbl_driver_id == -1) {
19332 		RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name);
19333 		return TEST_SKIPPED;
19334 	}
19335 
19336 	ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
19337 			(RTE_DIM(blk_suites) + RTE_DIM(static_suites)));
19338 
19339 	ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites));
19340 	ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
19341 	ret = unit_test_suite_runner(&ts);
19342 
19343 	FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites));
19344 	free(ts.unit_test_suites);
19345 	return ret;
19346 }
19347 
19348 static int
19349 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name)
19350 {
19351 	struct rte_cryptodev_info dev_info;
19352 	uint8_t i, nb_devs;
19353 	int driver_id;
19354 
19355 	driver_id = rte_cryptodev_driver_id_get(pmd_name);
19356 	if (driver_id == -1) {
19357 		RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name);
19358 		return TEST_SKIPPED;
19359 	}
19360 
19361 	nb_devs = rte_cryptodev_count();
19362 	if (nb_devs < 1) {
19363 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
19364 		return TEST_SKIPPED;
19365 	}
19366 
19367 	for (i = 0; i < nb_devs; i++) {
19368 		rte_cryptodev_info_get(i, &dev_info);
19369 		if (dev_info.driver_id == driver_id) {
19370 			if (!(dev_info.feature_flags & flag)) {
19371 				RTE_LOG(INFO, USER1, "%s not supported\n",
19372 						flag_name);
19373 				return TEST_SKIPPED;
19374 			}
19375 			return 0; /* found */
19376 		}
19377 	}
19378 
19379 	RTE_LOG(INFO, USER1, "%s not supported\n", flag_name);
19380 	return TEST_SKIPPED;
19381 }
19382 
19383 static int
19384 test_cryptodev_qat(void)
19385 {
19386 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
19387 }
19388 
19389 static int
19390 test_cryptodev_uadk(void)
19391 {
19392 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_UADK_PMD));
19393 }
19394 
19395 static int
19396 test_cryptodev_virtio(void)
19397 {
19398 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
19399 }
19400 
19401 static int
19402 test_cryptodev_aesni_mb(void)
19403 {
19404 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
19405 }
19406 
19407 static int
19408 test_cryptodev_cpu_aesni_mb(void)
19409 {
19410 	int32_t rc;
19411 	enum rte_security_session_action_type at = gbl_action_type;
19412 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
19413 	rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
19414 	gbl_action_type = at;
19415 	return rc;
19416 }
19417 
19418 static int
19419 test_cryptodev_chacha_poly_mb(void)
19420 {
19421 	int32_t rc;
19422 	enum rte_security_session_action_type at = gbl_action_type;
19423 	rc = run_cryptodev_testsuite(
19424 			RTE_STR(CRYPTODEV_NAME_CHACHA20_POLY1305_PMD));
19425 	gbl_action_type = at;
19426 	return rc;
19427 }
19428 
19429 static int
19430 test_cryptodev_openssl(void)
19431 {
19432 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
19433 }
19434 
19435 static int
19436 test_cryptodev_aesni_gcm(void)
19437 {
19438 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
19439 }
19440 
19441 static int
19442 test_cryptodev_cpu_aesni_gcm(void)
19443 {
19444 	int32_t rc;
19445 	enum rte_security_session_action_type at = gbl_action_type;
19446 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
19447 	rc  = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
19448 	gbl_action_type = at;
19449 	return rc;
19450 }
19451 
19452 static int
19453 test_cryptodev_mlx5(void)
19454 {
19455 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD));
19456 }
19457 
19458 static int
19459 test_cryptodev_null(void)
19460 {
19461 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD));
19462 }
19463 
19464 static int
19465 test_cryptodev_sw_snow3g(void)
19466 {
19467 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
19468 }
19469 
19470 static int
19471 test_cryptodev_sw_kasumi(void)
19472 {
19473 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
19474 }
19475 
19476 static int
19477 test_cryptodev_sw_zuc(void)
19478 {
19479 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
19480 }
19481 
19482 static int
19483 test_cryptodev_armv8(void)
19484 {
19485 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
19486 }
19487 
19488 static int
19489 test_cryptodev_mrvl(void)
19490 {
19491 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
19492 }
19493 
19494 #ifdef RTE_CRYPTO_SCHEDULER
19495 
19496 static int
19497 test_cryptodev_scheduler(void)
19498 {
19499 	uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0;
19500 	const enum blockcipher_test_type blk_suites[] = {
19501 		BLKCIPHER_AES_CHAIN_TYPE,
19502 		BLKCIPHER_AES_CIPHERONLY_TYPE,
19503 		BLKCIPHER_AUTHONLY_TYPE
19504 	};
19505 	static struct unit_test_suite scheduler_multicore = {
19506 		.suite_name = "Scheduler Multicore Unit Test Suite",
19507 		.setup = scheduler_multicore_testsuite_setup,
19508 		.teardown = scheduler_mode_testsuite_teardown,
19509 		.unit_test_cases = {TEST_CASES_END()}
19510 	};
19511 	static struct unit_test_suite scheduler_round_robin = {
19512 		.suite_name = "Scheduler Round Robin Unit Test Suite",
19513 		.setup = scheduler_roundrobin_testsuite_setup,
19514 		.teardown = scheduler_mode_testsuite_teardown,
19515 		.unit_test_cases = {TEST_CASES_END()}
19516 	};
19517 	static struct unit_test_suite scheduler_failover = {
19518 		.suite_name = "Scheduler Failover Unit Test Suite",
19519 		.setup = scheduler_failover_testsuite_setup,
19520 		.teardown = scheduler_mode_testsuite_teardown,
19521 		.unit_test_cases = {TEST_CASES_END()}
19522 	};
19523 	static struct unit_test_suite scheduler_pkt_size_distr = {
19524 		.suite_name = "Scheduler Pkt Size Distr Unit Test Suite",
19525 		.setup = scheduler_pkt_size_distr_testsuite_setup,
19526 		.teardown = scheduler_mode_testsuite_teardown,
19527 		.unit_test_cases = {TEST_CASES_END()}
19528 	};
19529 	struct unit_test_suite *sched_mode_suites[] = {
19530 		&scheduler_multicore,
19531 		&scheduler_round_robin,
19532 		&scheduler_failover,
19533 		&scheduler_pkt_size_distr
19534 	};
19535 	static struct unit_test_suite scheduler_config = {
19536 		.suite_name = "Crypto Device Scheduler Config Unit Test Suite",
19537 		.unit_test_cases = {
19538 			TEST_CASE(test_scheduler_attach_worker_op),
19539 			TEST_CASE(test_scheduler_mode_multicore_op),
19540 			TEST_CASE(test_scheduler_mode_roundrobin_op),
19541 			TEST_CASE(test_scheduler_mode_failover_op),
19542 			TEST_CASE(test_scheduler_mode_pkt_size_distr_op),
19543 			TEST_CASE(test_scheduler_detach_worker_op),
19544 
19545 			TEST_CASES_END() /**< NULL terminate array */
19546 		}
19547 	};
19548 	struct unit_test_suite *static_suites[] = {
19549 		&scheduler_config,
19550 		&end_testsuite
19551 	};
19552 	struct unit_test_suite *sched_mode_static_suites[] = {
19553 #ifdef RTE_LIB_SECURITY
19554 		&docsis_proto_testsuite,
19555 #endif
19556 		&end_testsuite
19557 	};
19558 	static struct unit_test_suite ts = {
19559 		.suite_name = "Scheduler Unit Test Suite",
19560 		.setup = scheduler_testsuite_setup,
19561 		.teardown = testsuite_teardown,
19562 		.unit_test_cases = {TEST_CASES_END()}
19563 	};
19564 
19565 	gbl_driver_id =	rte_cryptodev_driver_id_get(
19566 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
19567 
19568 	if (gbl_driver_id == -1) {
19569 		RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
19570 		return TEST_SKIPPED;
19571 	}
19572 
19573 	if (rte_cryptodev_driver_id_get(
19574 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
19575 		RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
19576 		return TEST_SKIPPED;
19577 	}
19578 
19579 	for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
19580 		uint8_t blk_i = 0;
19581 		sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof
19582 				(struct unit_test_suite *) *
19583 				(RTE_DIM(blk_suites) +
19584 				RTE_DIM(sched_mode_static_suites) + 1));
19585 		ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]),
19586 				blk_suites, RTE_DIM(blk_suites));
19587 		ADD_STATIC_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]),
19588 				sched_mode_static_suites,
19589 				RTE_DIM(sched_mode_static_suites));
19590 		sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite;
19591 	}
19592 
19593 	ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
19594 			(RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites)));
19595 	ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites,
19596 			RTE_DIM(sched_mode_suites));
19597 	ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
19598 	ret = unit_test_suite_runner(&ts);
19599 
19600 	for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
19601 		FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx,
19602 				(*sched_mode_suites[sched_i]),
19603 				RTE_DIM(blk_suites));
19604 		free(sched_mode_suites[sched_i]->unit_test_suites);
19605 	}
19606 	free(ts.unit_test_suites);
19607 	return ret;
19608 }
19609 
19610 REGISTER_DRIVER_TEST(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
19611 
19612 #endif
19613 
19614 static int
19615 test_cryptodev_dpaa2_sec(void)
19616 {
19617 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
19618 }
19619 
19620 static int
19621 test_cryptodev_dpaa_sec(void)
19622 {
19623 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
19624 }
19625 
19626 static int
19627 test_cryptodev_ccp(void)
19628 {
19629 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD));
19630 }
19631 
19632 static int
19633 test_cryptodev_octeontx(void)
19634 {
19635 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
19636 }
19637 
19638 static int
19639 test_cryptodev_caam_jr(void)
19640 {
19641 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
19642 }
19643 
19644 static int
19645 test_cryptodev_nitrox(void)
19646 {
19647 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
19648 }
19649 
19650 static int
19651 test_cryptodev_bcmfs(void)
19652 {
19653 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
19654 }
19655 
19656 static int
19657 run_cryptodev_raw_testsuite(const char *pmd_name)
19658 {
19659 	int ret;
19660 
19661 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP, "RAW API");
19662 	if (ret)
19663 		return ret;
19664 
19665 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
19666 	ret = run_cryptodev_testsuite(pmd_name);
19667 	global_api_test_type = CRYPTODEV_API_TEST;
19668 
19669 	return ret;
19670 }
19671 
19672 static int
19673 test_cryptodev_qat_raw_api(void)
19674 {
19675 	return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
19676 }
19677 
19678 static int
19679 test_cryptodev_cn9k(void)
19680 {
19681 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
19682 }
19683 
19684 static int
19685 test_cryptodev_cn10k(void)
19686 {
19687 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
19688 }
19689 
19690 static int
19691 test_cryptodev_cn10k_raw_api(void)
19692 {
19693 	return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
19694 }
19695 
19696 static int
19697 test_cryptodev_dpaa2_sec_raw_api(void)
19698 {
19699 	return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
19700 }
19701 
19702 static int
19703 test_cryptodev_dpaa_sec_raw_api(void)
19704 {
19705 	return run_cryptodev_raw_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
19706 }
19707 
19708 REGISTER_DRIVER_TEST(cryptodev_cn10k_raw_api_autotest,
19709 		test_cryptodev_cn10k_raw_api);
19710 REGISTER_DRIVER_TEST(cryptodev_dpaa2_sec_raw_api_autotest,
19711 		test_cryptodev_dpaa2_sec_raw_api);
19712 REGISTER_DRIVER_TEST(cryptodev_dpaa_sec_raw_api_autotest,
19713 		test_cryptodev_dpaa_sec_raw_api);
19714 REGISTER_DRIVER_TEST(cryptodev_qat_raw_api_autotest,
19715 		test_cryptodev_qat_raw_api);
19716 REGISTER_DRIVER_TEST(cryptodev_qat_autotest, test_cryptodev_qat);
19717 REGISTER_DRIVER_TEST(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
19718 REGISTER_DRIVER_TEST(cryptodev_cpu_aesni_mb_autotest,
19719 	test_cryptodev_cpu_aesni_mb);
19720 REGISTER_DRIVER_TEST(cryptodev_chacha_poly_mb_autotest,
19721 	test_cryptodev_chacha_poly_mb);
19722 REGISTER_DRIVER_TEST(cryptodev_openssl_autotest, test_cryptodev_openssl);
19723 REGISTER_DRIVER_TEST(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
19724 REGISTER_DRIVER_TEST(cryptodev_cpu_aesni_gcm_autotest,
19725 	test_cryptodev_cpu_aesni_gcm);
19726 REGISTER_DRIVER_TEST(cryptodev_mlx5_autotest, test_cryptodev_mlx5);
19727 REGISTER_DRIVER_TEST(cryptodev_null_autotest, test_cryptodev_null);
19728 REGISTER_DRIVER_TEST(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
19729 REGISTER_DRIVER_TEST(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
19730 REGISTER_DRIVER_TEST(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
19731 REGISTER_DRIVER_TEST(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
19732 REGISTER_DRIVER_TEST(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
19733 REGISTER_DRIVER_TEST(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
19734 REGISTER_DRIVER_TEST(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
19735 REGISTER_DRIVER_TEST(cryptodev_ccp_autotest, test_cryptodev_ccp);
19736 REGISTER_DRIVER_TEST(cryptodev_uadk_autotest, test_cryptodev_uadk);
19737 REGISTER_DRIVER_TEST(cryptodev_virtio_autotest, test_cryptodev_virtio);
19738 REGISTER_DRIVER_TEST(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
19739 REGISTER_DRIVER_TEST(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
19740 REGISTER_DRIVER_TEST(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
19741 REGISTER_DRIVER_TEST(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);
19742 REGISTER_DRIVER_TEST(cryptodev_cn9k_autotest, test_cryptodev_cn9k);
19743 REGISTER_DRIVER_TEST(cryptodev_cn10k_autotest, test_cryptodev_cn10k);
19744