xref: /dpdk/app/test/test_cryptodev.c (revision 49c19c94)
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 
17 #include <rte_crypto.h>
18 #include <rte_cryptodev.h>
19 #include <rte_ip.h>
20 #include <rte_string_fns.h>
21 #include <rte_tcp.h>
22 #include <rte_udp.h>
23 
24 #ifdef RTE_CRYPTO_SCHEDULER
25 #include <rte_cryptodev_scheduler.h>
26 #include <rte_cryptodev_scheduler_operations.h>
27 #endif
28 
29 #include <rte_lcore.h>
30 
31 #include "test.h"
32 #include "test_cryptodev.h"
33 
34 #include "test_cryptodev_blockcipher.h"
35 #include "test_cryptodev_aes_test_vectors.h"
36 #include "test_cryptodev_des_test_vectors.h"
37 #include "test_cryptodev_hash_test_vectors.h"
38 #include "test_cryptodev_kasumi_test_vectors.h"
39 #include "test_cryptodev_kasumi_hash_test_vectors.h"
40 #include "test_cryptodev_snow3g_test_vectors.h"
41 #include "test_cryptodev_snow3g_hash_test_vectors.h"
42 #include "test_cryptodev_zuc_test_vectors.h"
43 #include "test_cryptodev_aead_test_vectors.h"
44 #include "test_cryptodev_hmac_test_vectors.h"
45 #include "test_cryptodev_mixed_test_vectors.h"
46 #ifdef RTE_LIB_SECURITY
47 #include "test_cryptodev_security_ipsec.h"
48 #include "test_cryptodev_security_ipsec_test_vectors.h"
49 #include "test_cryptodev_security_pdcp_test_vectors.h"
50 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h"
51 #include "test_cryptodev_security_pdcp_test_func.h"
52 #include "test_cryptodev_security_docsis_test_vectors.h"
53 
54 #define SDAP_DISABLED	0
55 #define SDAP_ENABLED	1
56 #endif
57 
58 #define VDEV_ARGS_SIZE 100
59 #define MAX_NB_SESSIONS 4
60 
61 #define MAX_DRV_SERVICE_CTX_SIZE 256
62 
63 #define MAX_RAW_DEQUEUE_COUNT	65535
64 
65 #define IN_PLACE 0
66 #define OUT_OF_PLACE 1
67 
68 static int gbl_driver_id;
69 
70 static enum rte_security_session_action_type gbl_action_type =
71 	RTE_SECURITY_ACTION_TYPE_NONE;
72 
73 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST;
74 
75 struct crypto_unittest_params {
76 	struct rte_crypto_sym_xform cipher_xform;
77 	struct rte_crypto_sym_xform auth_xform;
78 	struct rte_crypto_sym_xform aead_xform;
79 #ifdef RTE_LIB_SECURITY
80 	struct rte_security_docsis_xform docsis_xform;
81 #endif
82 
83 	union {
84 		struct rte_cryptodev_sym_session *sess;
85 #ifdef RTE_LIB_SECURITY
86 		struct rte_security_session *sec_session;
87 #endif
88 	};
89 #ifdef RTE_LIB_SECURITY
90 	enum rte_security_session_action_type type;
91 #endif
92 	struct rte_crypto_op *op;
93 
94 	struct rte_mbuf *obuf, *ibuf;
95 
96 	uint8_t *digest;
97 };
98 
99 #define ALIGN_POW2_ROUNDUP(num, align) \
100 	(((num) + (align) - 1) & ~((align) - 1))
101 
102 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts)	\
103 	for (j = 0; j < num_child_ts; index++, j++)			\
104 		parent_ts.unit_test_suites[index] = child_ts[j]
105 
106 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types)	\
107 	for (j = 0; j < num_blk_types; index++, j++)				\
108 		parent_ts.unit_test_suites[index] =				\
109 				build_blockcipher_test_suite(blk_types[j])
110 
111 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types)		\
112 	for (j = index; j < index + num_blk_types; j++)				\
113 		free_blockcipher_test_suite(parent_ts.unit_test_suites[j])
114 
115 /*
116  * Forward declarations.
117  */
118 static int
119 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
120 		struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
121 		uint8_t *hmac_key);
122 
123 static int
124 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
125 		struct crypto_unittest_params *ut_params,
126 		struct crypto_testsuite_params *ts_param,
127 		const uint8_t *cipher,
128 		const uint8_t *digest,
129 		const uint8_t *iv);
130 
131 static int
132 security_proto_supported(enum rte_security_session_action_type action,
133 	enum rte_security_session_protocol proto);
134 
135 static int
136 dev_configure_and_start(uint64_t ff_disable);
137 
138 static struct rte_mbuf *
139 setup_test_string(struct rte_mempool *mpool,
140 		const char *string, size_t len, uint8_t blocksize)
141 {
142 	struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
143 	size_t t_len = len - (blocksize ? (len % blocksize) : 0);
144 
145 	if (m) {
146 		char *dst;
147 
148 		memset(m->buf_addr, 0, m->buf_len);
149 		dst = rte_pktmbuf_append(m, t_len);
150 		if (!dst) {
151 			rte_pktmbuf_free(m);
152 			return NULL;
153 		}
154 		if (string != NULL)
155 			rte_memcpy(dst, string, t_len);
156 		else
157 			memset(dst, 0, t_len);
158 	}
159 
160 	return m;
161 }
162 
163 /* Get number of bytes in X bits (rounding up) */
164 static uint32_t
165 ceil_byte_length(uint32_t num_bits)
166 {
167 	if (num_bits % 8)
168 		return ((num_bits >> 3) + 1);
169 	else
170 		return (num_bits >> 3);
171 }
172 
173 static void
174 post_process_raw_dp_op(void *user_data,	uint32_t index __rte_unused,
175 		uint8_t is_op_success)
176 {
177 	struct rte_crypto_op *op = user_data;
178 	op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS :
179 			RTE_CRYPTO_OP_STATUS_ERROR;
180 }
181 
182 void
183 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
184 		struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
185 		uint8_t len_in_bits, uint8_t cipher_iv_len)
186 {
187 	struct rte_crypto_sym_op *sop = op->sym;
188 	struct rte_crypto_op *ret_op = NULL;
189 	struct rte_crypto_vec data_vec[UINT8_MAX];
190 	struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv;
191 	union rte_crypto_sym_ofs ofs;
192 	struct rte_crypto_sym_vec vec;
193 	struct rte_crypto_sgl sgl;
194 	uint32_t max_len;
195 	union rte_cryptodev_session_ctx sess;
196 	uint32_t count = 0;
197 	struct rte_crypto_raw_dp_ctx *ctx;
198 	uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0,
199 			auth_len = 0;
200 	int32_t n;
201 	uint32_t n_success;
202 	int ctx_service_size;
203 	int32_t status = 0;
204 	int enqueue_status, dequeue_status;
205 
206 	ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
207 	if (ctx_service_size < 0) {
208 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
209 		return;
210 	}
211 
212 	ctx = malloc(ctx_service_size);
213 	if (!ctx) {
214 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
215 		return;
216 	}
217 
218 	/* Both are enums, setting crypto_sess will suit any session type */
219 	sess.crypto_sess = op->sym->session;
220 
221 	if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx,
222 			op->sess_type, sess, 0) < 0) {
223 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
224 		goto exit;
225 	}
226 
227 	cipher_iv.iova = 0;
228 	cipher_iv.va = NULL;
229 	aad_auth_iv.iova = 0;
230 	aad_auth_iv.va = NULL;
231 	digest.iova = 0;
232 	digest.va = NULL;
233 	sgl.vec = data_vec;
234 	vec.num = 1;
235 	vec.sgl = &sgl;
236 	vec.iv = &cipher_iv;
237 	vec.digest = &digest;
238 	vec.aad = &aad_auth_iv;
239 	vec.status = &status;
240 
241 	ofs.raw = 0;
242 
243 	if (is_cipher && is_auth) {
244 		cipher_offset = sop->cipher.data.offset;
245 		cipher_len = sop->cipher.data.length;
246 		auth_offset = sop->auth.data.offset;
247 		auth_len = sop->auth.data.length;
248 		max_len = RTE_MAX(cipher_offset + cipher_len,
249 				auth_offset + auth_len);
250 		if (len_in_bits) {
251 			max_len = max_len >> 3;
252 			cipher_offset = cipher_offset >> 3;
253 			auth_offset = auth_offset >> 3;
254 			cipher_len = cipher_len >> 3;
255 			auth_len = auth_len >> 3;
256 		}
257 		ofs.ofs.cipher.head = cipher_offset;
258 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
259 		ofs.ofs.auth.head = auth_offset;
260 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
261 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
262 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
263 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
264 				op, void *, IV_OFFSET + cipher_iv_len);
265 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
266 				cipher_iv_len);
267 		digest.va = (void *)sop->auth.digest.data;
268 		digest.iova = sop->auth.digest.phys_addr;
269 
270 	} else if (is_cipher) {
271 		cipher_offset = sop->cipher.data.offset;
272 		cipher_len = sop->cipher.data.length;
273 		max_len = cipher_len + cipher_offset;
274 		if (len_in_bits) {
275 			max_len = max_len >> 3;
276 			cipher_offset = cipher_offset >> 3;
277 			cipher_len = cipher_len >> 3;
278 		}
279 		ofs.ofs.cipher.head = cipher_offset;
280 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
281 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
282 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
283 
284 	} else if (is_auth) {
285 		auth_offset = sop->auth.data.offset;
286 		auth_len = sop->auth.data.length;
287 		max_len = auth_len + auth_offset;
288 		if (len_in_bits) {
289 			max_len = max_len >> 3;
290 			auth_offset = auth_offset >> 3;
291 			auth_len = auth_len >> 3;
292 		}
293 		ofs.ofs.auth.head = auth_offset;
294 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
295 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
296 				op, void *, IV_OFFSET + cipher_iv_len);
297 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
298 				cipher_iv_len);
299 		digest.va = (void *)sop->auth.digest.data;
300 		digest.iova = sop->auth.digest.phys_addr;
301 
302 	} else { /* aead */
303 		cipher_offset = sop->aead.data.offset;
304 		cipher_len = sop->aead.data.length;
305 		max_len = cipher_len + cipher_offset;
306 		if (len_in_bits) {
307 			max_len = max_len >> 3;
308 			cipher_offset = cipher_offset >> 3;
309 			cipher_len = cipher_len >> 3;
310 		}
311 		ofs.ofs.cipher.head = cipher_offset;
312 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
313 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
314 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
315 		aad_auth_iv.va = (void *)sop->aead.aad.data;
316 		aad_auth_iv.iova = sop->aead.aad.phys_addr;
317 		digest.va = (void *)sop->aead.digest.data;
318 		digest.iova = sop->aead.digest.phys_addr;
319 	}
320 
321 	n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
322 			data_vec, RTE_DIM(data_vec));
323 	if (n < 0 || n > sop->m_src->nb_segs) {
324 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
325 		goto exit;
326 	}
327 
328 	sgl.num = n;
329 
330 	if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op,
331 			&enqueue_status) < 1) {
332 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
333 		goto exit;
334 	}
335 
336 	if (enqueue_status == 0) {
337 		status = rte_cryptodev_raw_enqueue_done(ctx, 1);
338 		if (status < 0) {
339 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
340 			goto exit;
341 		}
342 	} else if (enqueue_status < 0) {
343 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
344 		goto exit;
345 	}
346 
347 	n = n_success = 0;
348 	while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) {
349 		n = rte_cryptodev_raw_dequeue_burst(ctx,
350 			NULL, 1, post_process_raw_dp_op,
351 				(void **)&ret_op, 0, &n_success,
352 				&dequeue_status);
353 		if (dequeue_status < 0) {
354 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
355 			goto exit;
356 		}
357 		if (n == 0)
358 			rte_pause();
359 	}
360 
361 	if (n == 1 && dequeue_status == 0) {
362 		if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) {
363 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
364 			goto exit;
365 		}
366 	}
367 
368 	op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op ||
369 			n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
370 					RTE_CRYPTO_OP_STATUS_SUCCESS;
371 
372 exit:
373 	free(ctx);
374 }
375 
376 static void
377 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
378 {
379 	int32_t n, st;
380 	struct rte_crypto_sym_op *sop;
381 	union rte_crypto_sym_ofs ofs;
382 	struct rte_crypto_sgl sgl;
383 	struct rte_crypto_sym_vec symvec;
384 	struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
385 	struct rte_crypto_vec vec[UINT8_MAX];
386 
387 	sop = op->sym;
388 
389 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
390 		sop->aead.data.length, vec, RTE_DIM(vec));
391 
392 	if (n < 0 || n != sop->m_src->nb_segs) {
393 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
394 		return;
395 	}
396 
397 	sgl.vec = vec;
398 	sgl.num = n;
399 	symvec.sgl = &sgl;
400 	symvec.iv = &iv_ptr;
401 	symvec.digest = &digest_ptr;
402 	symvec.aad = &aad_ptr;
403 	symvec.status = &st;
404 	symvec.num = 1;
405 
406 	/* for CPU crypto the IOVA address is not required */
407 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
408 	digest_ptr.va = (void *)sop->aead.digest.data;
409 	aad_ptr.va = (void *)sop->aead.aad.data;
410 
411 	ofs.raw = 0;
412 
413 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
414 		&symvec);
415 
416 	if (n != 1)
417 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
418 	else
419 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
420 }
421 
422 static void
423 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
424 {
425 	int32_t n, st;
426 	struct rte_crypto_sym_op *sop;
427 	union rte_crypto_sym_ofs ofs;
428 	struct rte_crypto_sgl sgl;
429 	struct rte_crypto_sym_vec symvec;
430 	struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
431 	struct rte_crypto_vec vec[UINT8_MAX];
432 
433 	sop = op->sym;
434 
435 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
436 		sop->auth.data.length, vec, RTE_DIM(vec));
437 
438 	if (n < 0 || n != sop->m_src->nb_segs) {
439 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
440 		return;
441 	}
442 
443 	sgl.vec = vec;
444 	sgl.num = n;
445 	symvec.sgl = &sgl;
446 	symvec.iv = &iv_ptr;
447 	symvec.digest = &digest_ptr;
448 	symvec.status = &st;
449 	symvec.num = 1;
450 
451 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
452 	digest_ptr.va = (void *)sop->auth.digest.data;
453 
454 	ofs.raw = 0;
455 	ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
456 	ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
457 		(sop->cipher.data.offset + sop->cipher.data.length);
458 
459 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
460 		&symvec);
461 
462 	if (n != 1)
463 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
464 	else
465 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
466 }
467 
468 static struct rte_crypto_op *
469 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
470 {
471 
472 	RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
473 
474 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
475 		RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
476 		return NULL;
477 	}
478 
479 	op = NULL;
480 
481 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
482 		rte_pause();
483 
484 	if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
485 		RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
486 		return NULL;
487 	}
488 
489 	return op;
490 }
491 
492 static struct crypto_testsuite_params testsuite_params = { NULL };
493 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params;
494 static struct crypto_unittest_params unittest_params;
495 
496 static int
497 testsuite_setup(void)
498 {
499 	struct crypto_testsuite_params *ts_params = &testsuite_params;
500 	struct rte_cryptodev_info info;
501 	uint32_t i = 0, nb_devs, dev_id;
502 	uint16_t qp_id;
503 
504 	memset(ts_params, 0, sizeof(*ts_params));
505 
506 	ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
507 	if (ts_params->mbuf_pool == NULL) {
508 		/* Not already created so create */
509 		ts_params->mbuf_pool = rte_pktmbuf_pool_create(
510 				"CRYPTO_MBUFPOOL",
511 				NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
512 				rte_socket_id());
513 		if (ts_params->mbuf_pool == NULL) {
514 			RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
515 			return TEST_FAILED;
516 		}
517 	}
518 
519 	ts_params->large_mbuf_pool = rte_mempool_lookup(
520 			"CRYPTO_LARGE_MBUFPOOL");
521 	if (ts_params->large_mbuf_pool == NULL) {
522 		/* Not already created so create */
523 		ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
524 				"CRYPTO_LARGE_MBUFPOOL",
525 				1, 0, 0, UINT16_MAX,
526 				rte_socket_id());
527 		if (ts_params->large_mbuf_pool == NULL) {
528 			RTE_LOG(ERR, USER1,
529 				"Can't create CRYPTO_LARGE_MBUFPOOL\n");
530 			return TEST_FAILED;
531 		}
532 	}
533 
534 	ts_params->op_mpool = rte_crypto_op_pool_create(
535 			"MBUF_CRYPTO_SYM_OP_POOL",
536 			RTE_CRYPTO_OP_TYPE_SYMMETRIC,
537 			NUM_MBUFS, MBUF_CACHE_SIZE,
538 			DEFAULT_NUM_XFORMS *
539 			sizeof(struct rte_crypto_sym_xform) +
540 			MAXIMUM_IV_LENGTH,
541 			rte_socket_id());
542 	if (ts_params->op_mpool == NULL) {
543 		RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
544 		return TEST_FAILED;
545 	}
546 
547 	nb_devs = rte_cryptodev_count();
548 	if (nb_devs < 1) {
549 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
550 		return TEST_SKIPPED;
551 	}
552 
553 	if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) {
554 		RTE_LOG(WARNING, USER1, "No %s devices found?\n",
555 				rte_cryptodev_driver_name_get(gbl_driver_id));
556 		return TEST_SKIPPED;
557 	}
558 
559 	/* Create list of valid crypto devs */
560 	for (i = 0; i < nb_devs; i++) {
561 		rte_cryptodev_info_get(i, &info);
562 		if (info.driver_id == gbl_driver_id)
563 			ts_params->valid_devs[ts_params->valid_dev_count++] = i;
564 	}
565 
566 	if (ts_params->valid_dev_count < 1)
567 		return TEST_FAILED;
568 
569 	/* Set up all the qps on the first of the valid devices found */
570 
571 	dev_id = ts_params->valid_devs[0];
572 
573 	rte_cryptodev_info_get(dev_id, &info);
574 
575 	ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
576 	ts_params->conf.socket_id = SOCKET_ID_ANY;
577 	ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
578 
579 	unsigned int session_size =
580 		rte_cryptodev_sym_get_private_session_size(dev_id);
581 
582 #ifdef RTE_LIB_SECURITY
583 	unsigned int security_session_size = rte_security_session_get_size(
584 			rte_cryptodev_get_sec_ctx(dev_id));
585 
586 	if (session_size < security_session_size)
587 		session_size = security_session_size;
588 #endif
589 	/*
590 	 * Create mempool with maximum number of sessions.
591 	 */
592 	if (info.sym.max_nb_sessions != 0 &&
593 			info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
594 		RTE_LOG(ERR, USER1, "Device does not support "
595 				"at least %u sessions\n",
596 				MAX_NB_SESSIONS);
597 		return TEST_FAILED;
598 	}
599 
600 	ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
601 			"test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
602 			SOCKET_ID_ANY);
603 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
604 			"session mempool allocation failed");
605 
606 	ts_params->session_priv_mpool = rte_mempool_create(
607 			"test_sess_mp_priv",
608 			MAX_NB_SESSIONS,
609 			session_size,
610 			0, 0, NULL, NULL, NULL,
611 			NULL, SOCKET_ID_ANY,
612 			0);
613 	TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
614 			"session mempool allocation failed");
615 
616 
617 
618 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
619 			&ts_params->conf),
620 			"Failed to configure cryptodev %u with %u qps",
621 			dev_id, ts_params->conf.nb_queue_pairs);
622 
623 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
624 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
625 	ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
626 
627 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
628 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
629 			dev_id, qp_id, &ts_params->qp_conf,
630 			rte_cryptodev_socket_id(dev_id)),
631 			"Failed to setup queue pair %u on cryptodev %u",
632 			qp_id, dev_id);
633 	}
634 
635 	return TEST_SUCCESS;
636 }
637 
638 static void
639 testsuite_teardown(void)
640 {
641 	struct crypto_testsuite_params *ts_params = &testsuite_params;
642 	int res;
643 
644 	if (ts_params->mbuf_pool != NULL) {
645 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
646 		rte_mempool_avail_count(ts_params->mbuf_pool));
647 	}
648 
649 	if (ts_params->op_mpool != NULL) {
650 		RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
651 		rte_mempool_avail_count(ts_params->op_mpool));
652 	}
653 
654 	/* Free session mempools */
655 	if (ts_params->session_priv_mpool != NULL) {
656 		rte_mempool_free(ts_params->session_priv_mpool);
657 		ts_params->session_priv_mpool = NULL;
658 	}
659 
660 	if (ts_params->session_mpool != NULL) {
661 		rte_mempool_free(ts_params->session_mpool);
662 		ts_params->session_mpool = NULL;
663 	}
664 
665 	res = rte_cryptodev_close(ts_params->valid_devs[0]);
666 	if (res)
667 		RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res);
668 }
669 
670 static int
671 check_capabilities_supported(enum rte_crypto_sym_xform_type type,
672 		const int *algs, uint16_t num_algs)
673 {
674 	uint8_t dev_id = testsuite_params.valid_devs[0];
675 	bool some_alg_supported = FALSE;
676 	uint16_t i;
677 
678 	for (i = 0; i < num_algs && !some_alg_supported; i++) {
679 		struct rte_cryptodev_sym_capability_idx alg = {
680 			type, {algs[i]}
681 		};
682 		if (rte_cryptodev_sym_capability_get(dev_id,
683 				&alg) != NULL)
684 			some_alg_supported = TRUE;
685 	}
686 	if (!some_alg_supported)
687 		return TEST_SKIPPED;
688 
689 	return 0;
690 }
691 
692 int
693 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
694 		uint16_t num_ciphers)
695 {
696 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER,
697 			(const int *) ciphers, num_ciphers);
698 }
699 
700 int
701 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
702 		uint16_t num_auths)
703 {
704 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH,
705 			(const int *) auths, num_auths);
706 }
707 
708 int
709 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
710 		uint16_t num_aeads)
711 {
712 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD,
713 			(const int *) aeads, num_aeads);
714 }
715 
716 static int
717 null_testsuite_setup(void)
718 {
719 	struct crypto_testsuite_params *ts_params = &testsuite_params;
720 	uint8_t dev_id = ts_params->valid_devs[0];
721 	struct rte_cryptodev_info dev_info;
722 	const enum rte_crypto_cipher_algorithm ciphers[] = {
723 		RTE_CRYPTO_CIPHER_NULL
724 	};
725 	const enum rte_crypto_auth_algorithm auths[] = {
726 		RTE_CRYPTO_AUTH_NULL
727 	};
728 
729 	rte_cryptodev_info_get(dev_id, &dev_info);
730 
731 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
732 		RTE_LOG(INFO, USER1, "Feature flag requirements for NULL "
733 				"testsuite not met\n");
734 		return TEST_SKIPPED;
735 	}
736 
737 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
738 			&& check_auth_capabilities_supported(auths,
739 			RTE_DIM(auths)) != 0) {
740 		RTE_LOG(INFO, USER1, "Capability requirements for NULL "
741 				"testsuite not met\n");
742 		return TEST_SKIPPED;
743 	}
744 
745 	return 0;
746 }
747 
748 static int
749 crypto_gen_testsuite_setup(void)
750 {
751 	struct crypto_testsuite_params *ts_params = &testsuite_params;
752 	uint8_t dev_id = ts_params->valid_devs[0];
753 	struct rte_cryptodev_info dev_info;
754 
755 	rte_cryptodev_info_get(dev_id, &dev_info);
756 
757 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
758 		RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen "
759 				"testsuite not met\n");
760 		return TEST_SKIPPED;
761 	}
762 
763 	return 0;
764 }
765 
766 #ifdef RTE_LIB_SECURITY
767 static int
768 ipsec_proto_testsuite_setup(void)
769 {
770 	struct crypto_testsuite_params *ts_params = &testsuite_params;
771 	struct crypto_unittest_params *ut_params = &unittest_params;
772 	struct rte_cryptodev_info dev_info;
773 	int ret = 0;
774 
775 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
776 
777 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) {
778 		RTE_LOG(INFO, USER1, "Feature flag requirements for IPsec Proto "
779 				"testsuite not met\n");
780 		return TEST_SKIPPED;
781 	}
782 
783 	/* Reconfigure to enable security */
784 	ret = dev_configure_and_start(0);
785 	if (ret != TEST_SUCCESS)
786 		return ret;
787 
788 	/* Set action type */
789 	ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
790 
791 	if (security_proto_supported(
792 			RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
793 			RTE_SECURITY_PROTOCOL_IPSEC) < 0) {
794 		RTE_LOG(INFO, USER1, "Capability requirements for IPsec Proto "
795 				"test not met\n");
796 		ret = TEST_SKIPPED;
797 	}
798 
799 	/*
800 	 * Stop the device. Device would be started again by individual test
801 	 * case setup routine.
802 	 */
803 	rte_cryptodev_stop(ts_params->valid_devs[0]);
804 
805 	return ret;
806 }
807 
808 static int
809 pdcp_proto_testsuite_setup(void)
810 {
811 	struct crypto_testsuite_params *ts_params = &testsuite_params;
812 	uint8_t dev_id = ts_params->valid_devs[0];
813 	struct rte_cryptodev_info dev_info;
814 	const enum rte_crypto_cipher_algorithm ciphers[] = {
815 		RTE_CRYPTO_CIPHER_NULL,
816 		RTE_CRYPTO_CIPHER_AES_CTR,
817 		RTE_CRYPTO_CIPHER_ZUC_EEA3,
818 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
819 	};
820 	const enum rte_crypto_auth_algorithm auths[] = {
821 		RTE_CRYPTO_AUTH_NULL,
822 		RTE_CRYPTO_AUTH_SNOW3G_UIA2,
823 		RTE_CRYPTO_AUTH_AES_CMAC,
824 		RTE_CRYPTO_AUTH_ZUC_EIA3
825 	};
826 
827 	rte_cryptodev_info_get(dev_id, &dev_info);
828 
829 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
830 			!(dev_info.feature_flags &
831 			RTE_CRYPTODEV_FF_SECURITY)) {
832 		RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto "
833 				"testsuite not met\n");
834 		return TEST_SKIPPED;
835 	}
836 
837 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
838 			&& check_auth_capabilities_supported(auths,
839 			RTE_DIM(auths)) != 0) {
840 		RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto "
841 				"testsuite not met\n");
842 		return TEST_SKIPPED;
843 	}
844 
845 	return 0;
846 }
847 
848 static int
849 docsis_proto_testsuite_setup(void)
850 {
851 	struct crypto_testsuite_params *ts_params = &testsuite_params;
852 	uint8_t dev_id = ts_params->valid_devs[0];
853 	struct rte_cryptodev_info dev_info;
854 	const enum rte_crypto_cipher_algorithm ciphers[] = {
855 		RTE_CRYPTO_CIPHER_AES_DOCSISBPI
856 	};
857 
858 	rte_cryptodev_info_get(dev_id, &dev_info);
859 
860 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
861 			!(dev_info.feature_flags &
862 			RTE_CRYPTODEV_FF_SECURITY)) {
863 		RTE_LOG(INFO, USER1, "Feature flag requirements for Docsis "
864 				"Proto testsuite not met\n");
865 		return TEST_SKIPPED;
866 	}
867 
868 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
869 		RTE_LOG(INFO, USER1, "Capability requirements for Docsis Proto "
870 				"testsuite not met\n");
871 		return TEST_SKIPPED;
872 	}
873 
874 	return 0;
875 }
876 #endif
877 
878 static int
879 aes_ccm_auth_testsuite_setup(void)
880 {
881 	struct crypto_testsuite_params *ts_params = &testsuite_params;
882 	uint8_t dev_id = ts_params->valid_devs[0];
883 	struct rte_cryptodev_info dev_info;
884 	const enum rte_crypto_aead_algorithm aeads[] = {
885 		RTE_CRYPTO_AEAD_AES_CCM
886 	};
887 
888 	rte_cryptodev_info_get(dev_id, &dev_info);
889 
890 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
891 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
892 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
893 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM "
894 				"testsuite not met\n");
895 		return TEST_SKIPPED;
896 	}
897 
898 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
899 		RTE_LOG(INFO, USER1, "Capability requirements for AES CCM "
900 				"testsuite not met\n");
901 		return TEST_SKIPPED;
902 	}
903 
904 	return 0;
905 }
906 
907 static int
908 aes_gcm_auth_testsuite_setup(void)
909 {
910 	struct crypto_testsuite_params *ts_params = &testsuite_params;
911 	uint8_t dev_id = ts_params->valid_devs[0];
912 	struct rte_cryptodev_info dev_info;
913 	const enum rte_crypto_aead_algorithm aeads[] = {
914 		RTE_CRYPTO_AEAD_AES_GCM
915 	};
916 
917 	rte_cryptodev_info_get(dev_id, &dev_info);
918 
919 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
920 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM "
921 				"testsuite not met\n");
922 		return TEST_SKIPPED;
923 	}
924 
925 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
926 		RTE_LOG(INFO, USER1, "Capability requirements for AES GCM "
927 				"testsuite not met\n");
928 		return TEST_SKIPPED;
929 	}
930 
931 	return 0;
932 }
933 
934 static int
935 aes_gmac_auth_testsuite_setup(void)
936 {
937 	struct crypto_testsuite_params *ts_params = &testsuite_params;
938 	uint8_t dev_id = ts_params->valid_devs[0];
939 	struct rte_cryptodev_info dev_info;
940 	const enum rte_crypto_auth_algorithm auths[] = {
941 		RTE_CRYPTO_AUTH_AES_GMAC
942 	};
943 
944 	rte_cryptodev_info_get(dev_id, &dev_info);
945 
946 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
947 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
948 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
949 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC "
950 				"testsuite not met\n");
951 		return TEST_SKIPPED;
952 	}
953 
954 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
955 		RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC "
956 				"testsuite not met\n");
957 		return TEST_SKIPPED;
958 	}
959 
960 	return 0;
961 }
962 
963 static int
964 chacha20_poly1305_testsuite_setup(void)
965 {
966 	struct crypto_testsuite_params *ts_params = &testsuite_params;
967 	uint8_t dev_id = ts_params->valid_devs[0];
968 	struct rte_cryptodev_info dev_info;
969 	const enum rte_crypto_aead_algorithm aeads[] = {
970 		RTE_CRYPTO_AEAD_CHACHA20_POLY1305
971 	};
972 
973 	rte_cryptodev_info_get(dev_id, &dev_info);
974 
975 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
976 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
977 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
978 		RTE_LOG(INFO, USER1, "Feature flag requirements for "
979 				"Chacha20-Poly1305 testsuite not met\n");
980 		return TEST_SKIPPED;
981 	}
982 
983 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
984 		RTE_LOG(INFO, USER1, "Capability requirements for "
985 				"Chacha20-Poly1305 testsuite not met\n");
986 		return TEST_SKIPPED;
987 	}
988 
989 	return 0;
990 }
991 
992 static int
993 snow3g_testsuite_setup(void)
994 {
995 	struct crypto_testsuite_params *ts_params = &testsuite_params;
996 	uint8_t dev_id = ts_params->valid_devs[0];
997 	struct rte_cryptodev_info dev_info;
998 	const enum rte_crypto_cipher_algorithm ciphers[] = {
999 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1000 
1001 	};
1002 	const enum rte_crypto_auth_algorithm auths[] = {
1003 		RTE_CRYPTO_AUTH_SNOW3G_UIA2
1004 	};
1005 
1006 	rte_cryptodev_info_get(dev_id, &dev_info);
1007 
1008 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1009 		RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G "
1010 				"testsuite not met\n");
1011 		return TEST_SKIPPED;
1012 	}
1013 
1014 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1015 			&& check_auth_capabilities_supported(auths,
1016 			RTE_DIM(auths)) != 0) {
1017 		RTE_LOG(INFO, USER1, "Capability requirements for Snow3G "
1018 				"testsuite not met\n");
1019 		return TEST_SKIPPED;
1020 	}
1021 
1022 	return 0;
1023 }
1024 
1025 static int
1026 zuc_testsuite_setup(void)
1027 {
1028 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1029 	uint8_t dev_id = ts_params->valid_devs[0];
1030 	struct rte_cryptodev_info dev_info;
1031 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1032 		RTE_CRYPTO_CIPHER_ZUC_EEA3
1033 	};
1034 	const enum rte_crypto_auth_algorithm auths[] = {
1035 		RTE_CRYPTO_AUTH_ZUC_EIA3
1036 	};
1037 
1038 	rte_cryptodev_info_get(dev_id, &dev_info);
1039 
1040 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1041 		RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC "
1042 				"testsuite not met\n");
1043 		return TEST_SKIPPED;
1044 	}
1045 
1046 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1047 			&& check_auth_capabilities_supported(auths,
1048 			RTE_DIM(auths)) != 0) {
1049 		RTE_LOG(INFO, USER1, "Capability requirements for ZUC "
1050 				"testsuite not met\n");
1051 		return TEST_SKIPPED;
1052 	}
1053 
1054 	return 0;
1055 }
1056 
1057 static int
1058 hmac_md5_auth_testsuite_setup(void)
1059 {
1060 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1061 	uint8_t dev_id = ts_params->valid_devs[0];
1062 	struct rte_cryptodev_info dev_info;
1063 	const enum rte_crypto_auth_algorithm auths[] = {
1064 		RTE_CRYPTO_AUTH_MD5_HMAC
1065 	};
1066 
1067 	rte_cryptodev_info_get(dev_id, &dev_info);
1068 
1069 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1070 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1071 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1072 		RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 "
1073 				"Auth testsuite not met\n");
1074 		return TEST_SKIPPED;
1075 	}
1076 
1077 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1078 		RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 "
1079 				"testsuite not met\n");
1080 		return TEST_SKIPPED;
1081 	}
1082 
1083 	return 0;
1084 }
1085 
1086 static int
1087 kasumi_testsuite_setup(void)
1088 {
1089 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1090 	uint8_t dev_id = ts_params->valid_devs[0];
1091 	struct rte_cryptodev_info dev_info;
1092 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1093 		RTE_CRYPTO_CIPHER_KASUMI_F8
1094 	};
1095 	const enum rte_crypto_auth_algorithm auths[] = {
1096 		RTE_CRYPTO_AUTH_KASUMI_F9
1097 	};
1098 
1099 	rte_cryptodev_info_get(dev_id, &dev_info);
1100 
1101 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1102 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1103 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1104 		RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi "
1105 				"testsuite not met\n");
1106 		return TEST_SKIPPED;
1107 	}
1108 
1109 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1110 			&& check_auth_capabilities_supported(auths,
1111 			RTE_DIM(auths)) != 0) {
1112 		RTE_LOG(INFO, USER1, "Capability requirements for Kasumi "
1113 				"testsuite not met\n");
1114 		return TEST_SKIPPED;
1115 	}
1116 
1117 	return 0;
1118 }
1119 
1120 static int
1121 negative_aes_gcm_testsuite_setup(void)
1122 {
1123 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1124 	uint8_t dev_id = ts_params->valid_devs[0];
1125 	struct rte_cryptodev_info dev_info;
1126 	const enum rte_crypto_aead_algorithm aeads[] = {
1127 		RTE_CRYPTO_AEAD_AES_GCM
1128 	};
1129 
1130 	rte_cryptodev_info_get(dev_id, &dev_info);
1131 
1132 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1133 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1134 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1135 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1136 				"AES GCM testsuite not met\n");
1137 		return TEST_SKIPPED;
1138 	}
1139 
1140 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1141 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1142 				"AES GCM testsuite not met\n");
1143 		return TEST_SKIPPED;
1144 	}
1145 
1146 	return 0;
1147 }
1148 
1149 static int
1150 negative_aes_gmac_testsuite_setup(void)
1151 {
1152 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1153 	uint8_t dev_id = ts_params->valid_devs[0];
1154 	struct rte_cryptodev_info dev_info;
1155 	const enum rte_crypto_auth_algorithm auths[] = {
1156 		RTE_CRYPTO_AUTH_AES_GMAC
1157 	};
1158 
1159 	rte_cryptodev_info_get(dev_id, &dev_info);
1160 
1161 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1162 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1163 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1164 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1165 				"AES GMAC testsuite not met\n");
1166 		return TEST_SKIPPED;
1167 	}
1168 
1169 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1170 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1171 				"AES GMAC testsuite not met\n");
1172 		return TEST_SKIPPED;
1173 	}
1174 
1175 	return 0;
1176 }
1177 
1178 static int
1179 mixed_cipher_hash_testsuite_setup(void)
1180 {
1181 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1182 	uint8_t dev_id = ts_params->valid_devs[0];
1183 	struct rte_cryptodev_info dev_info;
1184 	uint64_t feat_flags;
1185 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1186 		RTE_CRYPTO_CIPHER_NULL,
1187 		RTE_CRYPTO_CIPHER_AES_CTR,
1188 		RTE_CRYPTO_CIPHER_ZUC_EEA3,
1189 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1190 	};
1191 	const enum rte_crypto_auth_algorithm auths[] = {
1192 		RTE_CRYPTO_AUTH_NULL,
1193 		RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1194 		RTE_CRYPTO_AUTH_AES_CMAC,
1195 		RTE_CRYPTO_AUTH_ZUC_EIA3
1196 	};
1197 
1198 	rte_cryptodev_info_get(dev_id, &dev_info);
1199 	feat_flags = dev_info.feature_flags;
1200 
1201 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1202 			(global_api_test_type == CRYPTODEV_RAW_API_TEST)) {
1203 		RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed "
1204 				"Cipher Hash testsuite not met\n");
1205 		return TEST_SKIPPED;
1206 	}
1207 
1208 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1209 			&& check_auth_capabilities_supported(auths,
1210 			RTE_DIM(auths)) != 0) {
1211 		RTE_LOG(INFO, USER1, "Capability requirements for Mixed "
1212 				"Cipher Hash testsuite not met\n");
1213 		return TEST_SKIPPED;
1214 	}
1215 
1216 	return 0;
1217 }
1218 
1219 static int
1220 esn_testsuite_setup(void)
1221 {
1222 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1223 	uint8_t dev_id = ts_params->valid_devs[0];
1224 	struct rte_cryptodev_info dev_info;
1225 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1226 		RTE_CRYPTO_CIPHER_AES_CBC
1227 	};
1228 	const enum rte_crypto_auth_algorithm auths[] = {
1229 		RTE_CRYPTO_AUTH_SHA1_HMAC
1230 	};
1231 
1232 	rte_cryptodev_info_get(dev_id, &dev_info);
1233 
1234 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1235 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1236 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1237 		RTE_LOG(INFO, USER1, "Feature flag requirements for ESN "
1238 				"testsuite not met\n");
1239 		return TEST_SKIPPED;
1240 	}
1241 
1242 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1243 			&& check_auth_capabilities_supported(auths,
1244 			RTE_DIM(auths)) != 0) {
1245 		RTE_LOG(INFO, USER1, "Capability requirements for ESN "
1246 				"testsuite not met\n");
1247 		return TEST_SKIPPED;
1248 	}
1249 
1250 	return 0;
1251 }
1252 
1253 static int
1254 multi_session_testsuite_setup(void)
1255 {
1256 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1257 	uint8_t dev_id = ts_params->valid_devs[0];
1258 	struct rte_cryptodev_info dev_info;
1259 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1260 		RTE_CRYPTO_CIPHER_AES_CBC
1261 	};
1262 	const enum rte_crypto_auth_algorithm auths[] = {
1263 		RTE_CRYPTO_AUTH_SHA512_HMAC
1264 	};
1265 
1266 	rte_cryptodev_info_get(dev_id, &dev_info);
1267 
1268 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1269 		RTE_LOG(INFO, USER1, "Feature flag requirements for Multi "
1270 				"Session testsuite not met\n");
1271 		return TEST_SKIPPED;
1272 	}
1273 
1274 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1275 			&& check_auth_capabilities_supported(auths,
1276 			RTE_DIM(auths)) != 0) {
1277 		RTE_LOG(INFO, USER1, "Capability requirements for Multi "
1278 				"Session testsuite not met\n");
1279 		return TEST_SKIPPED;
1280 	}
1281 
1282 	return 0;
1283 }
1284 
1285 static int
1286 negative_hmac_sha1_testsuite_setup(void)
1287 {
1288 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1289 	uint8_t dev_id = ts_params->valid_devs[0];
1290 	struct rte_cryptodev_info dev_info;
1291 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1292 		RTE_CRYPTO_CIPHER_AES_CBC
1293 	};
1294 	const enum rte_crypto_auth_algorithm auths[] = {
1295 		RTE_CRYPTO_AUTH_SHA1_HMAC
1296 	};
1297 
1298 	rte_cryptodev_info_get(dev_id, &dev_info);
1299 
1300 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1301 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1302 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1303 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1304 				"HMAC SHA1 testsuite not met\n");
1305 		return TEST_SKIPPED;
1306 	}
1307 
1308 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1309 			&& check_auth_capabilities_supported(auths,
1310 			RTE_DIM(auths)) != 0) {
1311 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1312 				"HMAC SHA1 testsuite not met\n");
1313 		return TEST_SKIPPED;
1314 	}
1315 
1316 	return 0;
1317 }
1318 
1319 static int
1320 dev_configure_and_start(uint64_t ff_disable)
1321 {
1322 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1323 	struct crypto_unittest_params *ut_params = &unittest_params;
1324 
1325 	uint16_t qp_id;
1326 
1327 	/* Clear unit test parameters before running test */
1328 	memset(ut_params, 0, sizeof(*ut_params));
1329 
1330 	/* Reconfigure device to default parameters */
1331 	ts_params->conf.socket_id = SOCKET_ID_ANY;
1332 	ts_params->conf.ff_disable = ff_disable;
1333 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
1334 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
1335 	ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
1336 
1337 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1338 			&ts_params->conf),
1339 			"Failed to configure cryptodev %u",
1340 			ts_params->valid_devs[0]);
1341 
1342 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
1343 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1344 			ts_params->valid_devs[0], qp_id,
1345 			&ts_params->qp_conf,
1346 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1347 			"Failed to setup queue pair %u on cryptodev %u",
1348 			qp_id, ts_params->valid_devs[0]);
1349 	}
1350 
1351 
1352 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1353 
1354 	/* Start the device */
1355 	TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1356 			"Failed to start cryptodev %u",
1357 			ts_params->valid_devs[0]);
1358 
1359 	return TEST_SUCCESS;
1360 }
1361 
1362 int
1363 ut_setup(void)
1364 {
1365 	/* Configure and start the device with security feature disabled */
1366 	return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
1367 }
1368 
1369 static int
1370 ut_setup_security(void)
1371 {
1372 	/* Configure and start the device with no features disabled */
1373 	return dev_configure_and_start(0);
1374 }
1375 
1376 void
1377 ut_teardown(void)
1378 {
1379 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1380 	struct crypto_unittest_params *ut_params = &unittest_params;
1381 	struct rte_cryptodev_stats stats;
1382 
1383 	/* free crypto session structure */
1384 #ifdef RTE_LIB_SECURITY
1385 	if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
1386 		if (ut_params->sec_session) {
1387 			rte_security_session_destroy(rte_cryptodev_get_sec_ctx
1388 						(ts_params->valid_devs[0]),
1389 						ut_params->sec_session);
1390 			ut_params->sec_session = NULL;
1391 		}
1392 	} else
1393 #endif
1394 	{
1395 		if (ut_params->sess) {
1396 			rte_cryptodev_sym_session_clear(
1397 					ts_params->valid_devs[0],
1398 					ut_params->sess);
1399 			rte_cryptodev_sym_session_free(ut_params->sess);
1400 			ut_params->sess = NULL;
1401 		}
1402 	}
1403 
1404 	/* free crypto operation structure */
1405 	if (ut_params->op)
1406 		rte_crypto_op_free(ut_params->op);
1407 
1408 	/*
1409 	 * free mbuf - both obuf and ibuf are usually the same,
1410 	 * so check if they point at the same address is necessary,
1411 	 * to avoid freeing the mbuf twice.
1412 	 */
1413 	if (ut_params->obuf) {
1414 		rte_pktmbuf_free(ut_params->obuf);
1415 		if (ut_params->ibuf == ut_params->obuf)
1416 			ut_params->ibuf = 0;
1417 		ut_params->obuf = 0;
1418 	}
1419 	if (ut_params->ibuf) {
1420 		rte_pktmbuf_free(ut_params->ibuf);
1421 		ut_params->ibuf = 0;
1422 	}
1423 
1424 	if (ts_params->mbuf_pool != NULL)
1425 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
1426 			rte_mempool_avail_count(ts_params->mbuf_pool));
1427 
1428 	rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
1429 
1430 	/* Stop the device */
1431 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1432 }
1433 
1434 static int
1435 test_device_configure_invalid_dev_id(void)
1436 {
1437 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1438 	uint16_t dev_id, num_devs = 0;
1439 
1440 	TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
1441 			"Need at least %d devices for test", 1);
1442 
1443 	/* valid dev_id values */
1444 	dev_id = ts_params->valid_devs[0];
1445 
1446 	/* Stop the device in case it's started so it can be configured */
1447 	rte_cryptodev_stop(dev_id);
1448 
1449 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
1450 			"Failed test for rte_cryptodev_configure: "
1451 			"invalid dev_num %u", dev_id);
1452 
1453 	/* invalid dev_id values */
1454 	dev_id = num_devs;
1455 
1456 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1457 			"Failed test for rte_cryptodev_configure: "
1458 			"invalid dev_num %u", dev_id);
1459 
1460 	dev_id = 0xff;
1461 
1462 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1463 			"Failed test for rte_cryptodev_configure:"
1464 			"invalid dev_num %u", dev_id);
1465 
1466 	return TEST_SUCCESS;
1467 }
1468 
1469 static int
1470 test_device_configure_invalid_queue_pair_ids(void)
1471 {
1472 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1473 	uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1474 
1475 	/* Stop the device in case it's started so it can be configured */
1476 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1477 
1478 	/* valid - max value queue pairs */
1479 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1480 
1481 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1482 			&ts_params->conf),
1483 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1484 			ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1485 
1486 	/* valid - one queue pairs */
1487 	ts_params->conf.nb_queue_pairs = 1;
1488 
1489 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1490 			&ts_params->conf),
1491 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1492 			ts_params->valid_devs[0],
1493 			ts_params->conf.nb_queue_pairs);
1494 
1495 
1496 	/* invalid - zero queue pairs */
1497 	ts_params->conf.nb_queue_pairs = 0;
1498 
1499 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1500 			&ts_params->conf),
1501 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1502 			" invalid qps: %u",
1503 			ts_params->valid_devs[0],
1504 			ts_params->conf.nb_queue_pairs);
1505 
1506 
1507 	/* invalid - max value supported by field queue pairs */
1508 	ts_params->conf.nb_queue_pairs = UINT16_MAX;
1509 
1510 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1511 			&ts_params->conf),
1512 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1513 			" invalid qps: %u",
1514 			ts_params->valid_devs[0],
1515 			ts_params->conf.nb_queue_pairs);
1516 
1517 
1518 	/* invalid - max value + 1 queue pairs */
1519 	ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1520 
1521 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1522 			&ts_params->conf),
1523 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1524 			" invalid qps: %u",
1525 			ts_params->valid_devs[0],
1526 			ts_params->conf.nb_queue_pairs);
1527 
1528 	/* revert to original testsuite value */
1529 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1530 
1531 	return TEST_SUCCESS;
1532 }
1533 
1534 static int
1535 test_queue_pair_descriptor_setup(void)
1536 {
1537 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1538 	struct rte_cryptodev_qp_conf qp_conf = {
1539 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
1540 	};
1541 	uint16_t qp_id;
1542 
1543 	/* Stop the device in case it's started so it can be configured */
1544 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1545 
1546 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1547 			&ts_params->conf),
1548 			"Failed to configure cryptodev %u",
1549 			ts_params->valid_devs[0]);
1550 
1551 	/*
1552 	 * Test various ring sizes on this device. memzones can't be
1553 	 * freed so are re-used if ring is released and re-created.
1554 	 */
1555 	qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1556 	qp_conf.mp_session = ts_params->session_mpool;
1557 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
1558 
1559 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1560 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1561 				ts_params->valid_devs[0], qp_id, &qp_conf,
1562 				rte_cryptodev_socket_id(
1563 						ts_params->valid_devs[0])),
1564 				"Failed test for "
1565 				"rte_cryptodev_queue_pair_setup: num_inflights "
1566 				"%u on qp %u on cryptodev %u",
1567 				qp_conf.nb_descriptors, qp_id,
1568 				ts_params->valid_devs[0]);
1569 	}
1570 
1571 	qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1572 
1573 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1574 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1575 				ts_params->valid_devs[0], qp_id, &qp_conf,
1576 				rte_cryptodev_socket_id(
1577 						ts_params->valid_devs[0])),
1578 				"Failed test for"
1579 				" rte_cryptodev_queue_pair_setup: num_inflights"
1580 				" %u on qp %u on cryptodev %u",
1581 				qp_conf.nb_descriptors, qp_id,
1582 				ts_params->valid_devs[0]);
1583 	}
1584 
1585 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
1586 
1587 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1588 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1589 				ts_params->valid_devs[0], qp_id, &qp_conf,
1590 				rte_cryptodev_socket_id(
1591 						ts_params->valid_devs[0])),
1592 				"Failed test for "
1593 				"rte_cryptodev_queue_pair_setup: num_inflights"
1594 				" %u on qp %u on cryptodev %u",
1595 				qp_conf.nb_descriptors, qp_id,
1596 				ts_params->valid_devs[0]);
1597 	}
1598 
1599 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1600 
1601 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1602 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1603 				ts_params->valid_devs[0], qp_id, &qp_conf,
1604 				rte_cryptodev_socket_id(
1605 						ts_params->valid_devs[0])),
1606 				"Failed test for"
1607 				" rte_cryptodev_queue_pair_setup:"
1608 				"num_inflights %u on qp %u on cryptodev %u",
1609 				qp_conf.nb_descriptors, qp_id,
1610 				ts_params->valid_devs[0]);
1611 	}
1612 
1613 	/* test invalid queue pair id */
1614 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;	/*valid */
1615 
1616 	qp_id = ts_params->conf.nb_queue_pairs;		/*invalid */
1617 
1618 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1619 			ts_params->valid_devs[0],
1620 			qp_id, &qp_conf,
1621 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1622 			"Failed test for rte_cryptodev_queue_pair_setup:"
1623 			"invalid qp %u on cryptodev %u",
1624 			qp_id, ts_params->valid_devs[0]);
1625 
1626 	qp_id = 0xffff; /*invalid*/
1627 
1628 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1629 			ts_params->valid_devs[0],
1630 			qp_id, &qp_conf,
1631 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1632 			"Failed test for rte_cryptodev_queue_pair_setup:"
1633 			"invalid qp %u on cryptodev %u",
1634 			qp_id, ts_params->valid_devs[0]);
1635 
1636 	return TEST_SUCCESS;
1637 }
1638 
1639 /* ***** Plaintext data for tests ***** */
1640 
1641 const char catch_22_quote_1[] =
1642 		"There was only one catch and that was Catch-22, which "
1643 		"specified that a concern for one's safety in the face of "
1644 		"dangers that were real and immediate was the process of a "
1645 		"rational mind. Orr was crazy and could be grounded. All he "
1646 		"had to do was ask; and as soon as he did, he would no longer "
1647 		"be crazy and would have to fly more missions. Orr would be "
1648 		"crazy to fly more missions and sane if he didn't, but if he "
1649 		"was sane he had to fly them. If he flew them he was crazy "
1650 		"and didn't have to; but if he didn't want to he was sane and "
1651 		"had to. Yossarian was moved very deeply by the absolute "
1652 		"simplicity of this clause of Catch-22 and let out a "
1653 		"respectful whistle. \"That's some catch, that Catch-22\", he "
1654 		"observed. \"It's the best there is,\" Doc Daneeka agreed.";
1655 
1656 const char catch_22_quote[] =
1657 		"What a lousy earth! He wondered how many people were "
1658 		"destitute that same night even in his own prosperous country, "
1659 		"how many homes were shanties, how many husbands were drunk "
1660 		"and wives socked, and how many children were bullied, abused, "
1661 		"or abandoned. How many families hungered for food they could "
1662 		"not afford to buy? How many hearts were broken? How many "
1663 		"suicides would take place that same night, how many people "
1664 		"would go insane? How many cockroaches and landlords would "
1665 		"triumph? How many winners were losers, successes failures, "
1666 		"and rich men poor men? How many wise guys were stupid? How "
1667 		"many happy endings were unhappy endings? How many honest men "
1668 		"were liars, brave men cowards, loyal men traitors, how many "
1669 		"sainted men were corrupt, how many people in positions of "
1670 		"trust had sold their souls to bodyguards, how many had never "
1671 		"had souls? How many straight-and-narrow paths were crooked "
1672 		"paths? How many best families were worst families and how "
1673 		"many good people were bad people? When you added them all up "
1674 		"and then subtracted, you might be left with only the children, "
1675 		"and perhaps with Albert Einstein and an old violinist or "
1676 		"sculptor somewhere.";
1677 
1678 #define QUOTE_480_BYTES		(480)
1679 #define QUOTE_512_BYTES		(512)
1680 #define QUOTE_768_BYTES		(768)
1681 #define QUOTE_1024_BYTES	(1024)
1682 
1683 
1684 
1685 /* ***** SHA1 Hash Tests ***** */
1686 
1687 #define HMAC_KEY_LENGTH_SHA1	(DIGEST_BYTE_LENGTH_SHA1)
1688 
1689 static uint8_t hmac_sha1_key[] = {
1690 	0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1691 	0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1692 	0xDE, 0xF4, 0xDE, 0xAD };
1693 
1694 /* ***** SHA224 Hash Tests ***** */
1695 
1696 #define HMAC_KEY_LENGTH_SHA224	(DIGEST_BYTE_LENGTH_SHA224)
1697 
1698 
1699 /* ***** AES-CBC Cipher Tests ***** */
1700 
1701 #define CIPHER_KEY_LENGTH_AES_CBC	(16)
1702 #define CIPHER_IV_LENGTH_AES_CBC	(CIPHER_KEY_LENGTH_AES_CBC)
1703 
1704 static uint8_t aes_cbc_key[] = {
1705 	0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1706 	0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1707 
1708 static uint8_t aes_cbc_iv[] = {
1709 	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1710 	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1711 
1712 
1713 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1714 
1715 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1716 	0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1717 	0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1718 	0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1719 	0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1720 	0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1721 	0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1722 	0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1723 	0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1724 	0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1725 	0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1726 	0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1727 	0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1728 	0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1729 	0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1730 	0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1731 	0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1732 	0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1733 	0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1734 	0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1735 	0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1736 	0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1737 	0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1738 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1739 	0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1740 	0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1741 	0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1742 	0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1743 	0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1744 	0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1745 	0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1746 	0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1747 	0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1748 	0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1749 	0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1750 	0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1751 	0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1752 	0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1753 	0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1754 	0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1755 	0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1756 	0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1757 	0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1758 	0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1759 	0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1760 	0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1761 	0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1762 	0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1763 	0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1764 	0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1765 	0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1766 	0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1767 	0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1768 	0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1769 	0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1770 	0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1771 	0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1772 	0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1773 	0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1774 	0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1775 	0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1776 	0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1777 	0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1778 	0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1779 	0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1780 };
1781 
1782 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1783 	0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1784 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1785 	0x18, 0x8c, 0x1d, 0x32
1786 };
1787 
1788 
1789 /* Multisession Vector context Test */
1790 /*Begin Session 0 */
1791 static uint8_t ms_aes_cbc_key0[] = {
1792 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1793 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1794 };
1795 
1796 static uint8_t ms_aes_cbc_iv0[] = {
1797 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1798 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1799 };
1800 
1801 static const uint8_t ms_aes_cbc_cipher0[] = {
1802 		0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1803 		0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1804 		0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1805 		0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1806 		0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1807 		0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1808 		0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1809 		0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1810 		0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1811 		0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1812 		0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1813 		0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1814 		0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1815 		0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1816 		0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1817 		0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1818 		0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1819 		0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1820 		0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1821 		0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1822 		0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1823 		0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1824 		0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1825 		0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1826 		0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1827 		0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1828 		0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1829 		0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1830 		0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1831 		0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1832 		0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1833 		0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1834 		0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1835 		0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1836 		0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1837 		0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1838 		0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1839 		0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1840 		0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1841 		0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1842 		0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1843 		0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1844 		0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1845 		0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1846 		0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1847 		0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1848 		0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1849 		0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1850 		0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1851 		0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1852 		0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1853 		0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1854 		0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1855 		0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1856 		0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1857 		0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1858 		0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1859 		0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1860 		0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1861 		0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1862 		0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1863 		0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1864 		0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1865 		0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1866 };
1867 
1868 
1869 static  uint8_t ms_hmac_key0[] = {
1870 		0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1871 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1872 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1873 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1874 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1875 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1876 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1877 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1878 };
1879 
1880 static const uint8_t ms_hmac_digest0[] = {
1881 		0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1882 		0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1883 		0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1884 		0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1885 		0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1886 		0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1887 		0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1888 		0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1889 		};
1890 
1891 /* End Session 0 */
1892 /* Begin session 1 */
1893 
1894 static  uint8_t ms_aes_cbc_key1[] = {
1895 		0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1896 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1897 };
1898 
1899 static  uint8_t ms_aes_cbc_iv1[] = {
1900 	0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1901 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1902 };
1903 
1904 static const uint8_t ms_aes_cbc_cipher1[] = {
1905 		0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1906 		0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1907 		0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1908 		0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1909 		0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1910 		0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1911 		0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1912 		0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1913 		0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1914 		0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1915 		0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1916 		0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1917 		0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1918 		0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1919 		0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1920 		0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1921 		0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1922 		0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1923 		0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1924 		0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1925 		0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1926 		0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1927 		0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1928 		0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1929 		0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1930 		0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1931 		0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1932 		0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1933 		0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1934 		0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1935 		0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1936 		0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1937 		0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1938 		0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1939 		0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1940 		0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1941 		0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1942 		0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1943 		0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1944 		0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1945 		0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1946 		0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1947 		0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1948 		0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1949 		0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1950 		0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1951 		0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1952 		0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1953 		0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1954 		0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1955 		0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1956 		0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1957 		0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1958 		0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1959 		0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1960 		0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1961 		0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1962 		0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1963 		0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1964 		0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1965 		0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1966 		0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1967 		0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1968 		0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1969 
1970 };
1971 
1972 static uint8_t ms_hmac_key1[] = {
1973 		0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1974 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1975 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1976 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1977 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1978 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1979 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1980 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1981 };
1982 
1983 static const uint8_t ms_hmac_digest1[] = {
1984 		0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1985 		0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
1986 		0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
1987 		0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
1988 		0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
1989 		0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
1990 		0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
1991 		0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
1992 };
1993 /* End Session 1  */
1994 /* Begin Session 2 */
1995 static  uint8_t ms_aes_cbc_key2[] = {
1996 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1997 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1998 };
1999 
2000 static  uint8_t ms_aes_cbc_iv2[] = {
2001 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2002 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2003 };
2004 
2005 static const uint8_t ms_aes_cbc_cipher2[] = {
2006 		0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
2007 		0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
2008 		0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
2009 		0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
2010 		0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
2011 		0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
2012 		0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
2013 		0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
2014 		0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
2015 		0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
2016 		0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
2017 		0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
2018 		0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
2019 		0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
2020 		0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
2021 		0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
2022 		0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
2023 		0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
2024 		0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
2025 		0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
2026 		0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
2027 		0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
2028 		0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
2029 		0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
2030 		0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
2031 		0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
2032 		0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
2033 		0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
2034 		0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
2035 		0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
2036 		0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
2037 		0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
2038 		0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
2039 		0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
2040 		0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
2041 		0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
2042 		0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
2043 		0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
2044 		0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
2045 		0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
2046 		0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
2047 		0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
2048 		0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
2049 		0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
2050 		0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
2051 		0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
2052 		0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
2053 		0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
2054 		0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
2055 		0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
2056 		0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
2057 		0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
2058 		0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
2059 		0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
2060 		0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
2061 		0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
2062 		0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
2063 		0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
2064 		0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
2065 		0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
2066 		0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
2067 		0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
2068 		0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
2069 		0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
2070 };
2071 
2072 static  uint8_t ms_hmac_key2[] = {
2073 		0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2074 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2075 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2076 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2077 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2078 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2079 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2080 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2081 };
2082 
2083 static const uint8_t ms_hmac_digest2[] = {
2084 		0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
2085 		0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
2086 		0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
2087 		0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
2088 		0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
2089 		0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
2090 		0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
2091 		0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
2092 };
2093 
2094 /* End Session 2 */
2095 
2096 
2097 static int
2098 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
2099 {
2100 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2101 	struct crypto_unittest_params *ut_params = &unittest_params;
2102 
2103 	/* Verify the capabilities */
2104 	struct rte_cryptodev_sym_capability_idx cap_idx;
2105 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2106 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
2107 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2108 			&cap_idx) == NULL)
2109 		return TEST_SKIPPED;
2110 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2111 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
2112 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2113 			&cap_idx) == NULL)
2114 		return TEST_SKIPPED;
2115 
2116 	/* Generate test mbuf data and space for digest */
2117 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2118 			catch_22_quote,	QUOTE_512_BYTES, 0);
2119 
2120 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2121 			DIGEST_BYTE_LENGTH_SHA1);
2122 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2123 
2124 	/* Setup Cipher Parameters */
2125 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2126 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2127 
2128 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2129 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2130 	ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2131 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2132 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2133 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2134 
2135 	/* Setup HMAC Parameters */
2136 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2137 
2138 	ut_params->auth_xform.next = NULL;
2139 
2140 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2141 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
2142 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
2143 	ut_params->auth_xform.auth.key.data = hmac_sha1_key;
2144 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
2145 
2146 	ut_params->sess = rte_cryptodev_sym_session_create(
2147 			ts_params->session_mpool);
2148 
2149 	/* Create crypto session*/
2150 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
2151 			ut_params->sess, &ut_params->cipher_xform,
2152 			ts_params->session_priv_mpool);
2153 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2154 
2155 	/* Generate crypto op data structure */
2156 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2157 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2158 	TEST_ASSERT_NOT_NULL(ut_params->op,
2159 			"Failed to allocate symmetric crypto operation struct");
2160 
2161 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2162 
2163 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2164 
2165 	/* set crypto operation source mbuf */
2166 	sym_op->m_src = ut_params->ibuf;
2167 
2168 	/* Set crypto operation authentication parameters */
2169 	sym_op->auth.digest.data = ut_params->digest;
2170 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2171 			ut_params->ibuf, QUOTE_512_BYTES);
2172 
2173 	sym_op->auth.data.offset = 0;
2174 	sym_op->auth.data.length = QUOTE_512_BYTES;
2175 
2176 	/* Copy IV at the end of the crypto operation */
2177 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2178 			aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
2179 
2180 	/* Set crypto operation cipher parameters */
2181 	sym_op->cipher.data.offset = 0;
2182 	sym_op->cipher.data.length = QUOTE_512_BYTES;
2183 
2184 	/* Process crypto operation */
2185 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2186 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2187 			ut_params->op);
2188 	else
2189 		TEST_ASSERT_NOT_NULL(
2190 			process_crypto_request(ts_params->valid_devs[0],
2191 				ut_params->op),
2192 				"failed to process sym crypto op");
2193 
2194 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2195 			"crypto op processing failed");
2196 
2197 	/* Validate obuf */
2198 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
2199 			uint8_t *);
2200 
2201 	TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
2202 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2203 			QUOTE_512_BYTES,
2204 			"ciphertext data not as expected");
2205 
2206 	uint8_t *digest = ciphertext + QUOTE_512_BYTES;
2207 
2208 	TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
2209 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
2210 			gbl_driver_id == rte_cryptodev_driver_id_get(
2211 					RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
2212 					TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
2213 					DIGEST_BYTE_LENGTH_SHA1,
2214 			"Generated digest data not as expected");
2215 
2216 	return TEST_SUCCESS;
2217 }
2218 
2219 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
2220 
2221 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
2222 
2223 static uint8_t hmac_sha512_key[] = {
2224 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
2225 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2226 	0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2227 	0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
2228 	0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
2229 	0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2230 	0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
2231 	0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
2232 
2233 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
2234 	0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
2235 	0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
2236 	0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
2237 	0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
2238 	0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
2239 	0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
2240 	0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
2241 	0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
2242 
2243 
2244 
2245 static int
2246 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2247 		struct crypto_unittest_params *ut_params,
2248 		uint8_t *cipher_key,
2249 		uint8_t *hmac_key);
2250 
2251 static int
2252 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2253 		struct crypto_unittest_params *ut_params,
2254 		struct crypto_testsuite_params *ts_params,
2255 		const uint8_t *cipher,
2256 		const uint8_t *digest,
2257 		const uint8_t *iv);
2258 
2259 
2260 static int
2261 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2262 		struct crypto_unittest_params *ut_params,
2263 		uint8_t *cipher_key,
2264 		uint8_t *hmac_key)
2265 {
2266 
2267 	/* Setup Cipher Parameters */
2268 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2269 	ut_params->cipher_xform.next = NULL;
2270 
2271 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2272 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
2273 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2274 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2275 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2276 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2277 
2278 	/* Setup HMAC Parameters */
2279 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2280 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2281 
2282 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
2283 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
2284 	ut_params->auth_xform.auth.key.data = hmac_key;
2285 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
2286 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
2287 
2288 	return TEST_SUCCESS;
2289 }
2290 
2291 
2292 static int
2293 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2294 		struct crypto_unittest_params *ut_params,
2295 		struct crypto_testsuite_params *ts_params,
2296 		const uint8_t *cipher,
2297 		const uint8_t *digest,
2298 		const uint8_t *iv)
2299 {
2300 	/* Generate test mbuf data and digest */
2301 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2302 			(const char *)
2303 			cipher,
2304 			QUOTE_512_BYTES, 0);
2305 
2306 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2307 			DIGEST_BYTE_LENGTH_SHA512);
2308 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2309 
2310 	rte_memcpy(ut_params->digest,
2311 			digest,
2312 			DIGEST_BYTE_LENGTH_SHA512);
2313 
2314 	/* Generate Crypto op data structure */
2315 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2316 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2317 	TEST_ASSERT_NOT_NULL(ut_params->op,
2318 			"Failed to allocate symmetric crypto operation struct");
2319 
2320 	rte_crypto_op_attach_sym_session(ut_params->op, sess);
2321 
2322 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2323 
2324 	/* set crypto operation source mbuf */
2325 	sym_op->m_src = ut_params->ibuf;
2326 
2327 	sym_op->auth.digest.data = ut_params->digest;
2328 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2329 			ut_params->ibuf, QUOTE_512_BYTES);
2330 
2331 	sym_op->auth.data.offset = 0;
2332 	sym_op->auth.data.length = QUOTE_512_BYTES;
2333 
2334 	/* Copy IV at the end of the crypto operation */
2335 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2336 			iv, CIPHER_IV_LENGTH_AES_CBC);
2337 
2338 	sym_op->cipher.data.offset = 0;
2339 	sym_op->cipher.data.length = QUOTE_512_BYTES;
2340 
2341 	/* Process crypto operation */
2342 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2343 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2344 			ut_params->op);
2345 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2346 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2347 				ut_params->op, 1, 1, 0, 0);
2348 	else
2349 		TEST_ASSERT_NOT_NULL(
2350 				process_crypto_request(ts_params->valid_devs[0],
2351 					ut_params->op),
2352 					"failed to process sym crypto op");
2353 
2354 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2355 			"crypto op processing failed");
2356 
2357 	ut_params->obuf = ut_params->op->sym->m_src;
2358 
2359 	/* Validate obuf */
2360 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
2361 			rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
2362 			catch_22_quote,
2363 			QUOTE_512_BYTES,
2364 			"Plaintext data not as expected");
2365 
2366 	/* Validate obuf */
2367 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2368 			"Digest verification failed");
2369 
2370 	return TEST_SUCCESS;
2371 }
2372 
2373 /* ***** SNOW 3G Tests ***** */
2374 static int
2375 create_wireless_algo_hash_session(uint8_t dev_id,
2376 	const uint8_t *key, const uint8_t key_len,
2377 	const uint8_t iv_len, const uint8_t auth_len,
2378 	enum rte_crypto_auth_operation op,
2379 	enum rte_crypto_auth_algorithm algo)
2380 {
2381 	uint8_t hash_key[key_len];
2382 	int status;
2383 
2384 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2385 	struct crypto_unittest_params *ut_params = &unittest_params;
2386 
2387 	memcpy(hash_key, key, key_len);
2388 
2389 	debug_hexdump(stdout, "key:", key, key_len);
2390 
2391 	/* Setup Authentication Parameters */
2392 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2393 	ut_params->auth_xform.next = NULL;
2394 
2395 	ut_params->auth_xform.auth.op = op;
2396 	ut_params->auth_xform.auth.algo = algo;
2397 	ut_params->auth_xform.auth.key.length = key_len;
2398 	ut_params->auth_xform.auth.key.data = hash_key;
2399 	ut_params->auth_xform.auth.digest_length = auth_len;
2400 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2401 	ut_params->auth_xform.auth.iv.length = iv_len;
2402 	ut_params->sess = rte_cryptodev_sym_session_create(
2403 			ts_params->session_mpool);
2404 
2405 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2406 			&ut_params->auth_xform,
2407 			ts_params->session_priv_mpool);
2408 	if (status == -ENOTSUP)
2409 		return TEST_SKIPPED;
2410 
2411 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2412 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2413 	return 0;
2414 }
2415 
2416 static int
2417 create_wireless_algo_cipher_session(uint8_t dev_id,
2418 			enum rte_crypto_cipher_operation op,
2419 			enum rte_crypto_cipher_algorithm algo,
2420 			const uint8_t *key, const uint8_t key_len,
2421 			uint8_t iv_len)
2422 {
2423 	uint8_t cipher_key[key_len];
2424 	int status;
2425 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2426 	struct crypto_unittest_params *ut_params = &unittest_params;
2427 
2428 	memcpy(cipher_key, key, key_len);
2429 
2430 	/* Setup Cipher Parameters */
2431 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2432 	ut_params->cipher_xform.next = NULL;
2433 
2434 	ut_params->cipher_xform.cipher.algo = algo;
2435 	ut_params->cipher_xform.cipher.op = op;
2436 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2437 	ut_params->cipher_xform.cipher.key.length = key_len;
2438 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2439 	ut_params->cipher_xform.cipher.iv.length = iv_len;
2440 
2441 	debug_hexdump(stdout, "key:", key, key_len);
2442 
2443 	/* Create Crypto session */
2444 	ut_params->sess = rte_cryptodev_sym_session_create(
2445 			ts_params->session_mpool);
2446 
2447 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2448 			&ut_params->cipher_xform,
2449 			ts_params->session_priv_mpool);
2450 	if (status == -ENOTSUP)
2451 		return TEST_SKIPPED;
2452 
2453 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2454 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2455 	return 0;
2456 }
2457 
2458 static int
2459 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2460 			unsigned int cipher_len,
2461 			unsigned int cipher_offset)
2462 {
2463 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2464 	struct crypto_unittest_params *ut_params = &unittest_params;
2465 
2466 	/* Generate Crypto op data structure */
2467 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2468 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2469 	TEST_ASSERT_NOT_NULL(ut_params->op,
2470 				"Failed to allocate pktmbuf offload");
2471 
2472 	/* Set crypto operation data parameters */
2473 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2474 
2475 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2476 
2477 	/* set crypto operation source mbuf */
2478 	sym_op->m_src = ut_params->ibuf;
2479 
2480 	/* iv */
2481 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2482 			iv, iv_len);
2483 	sym_op->cipher.data.length = cipher_len;
2484 	sym_op->cipher.data.offset = cipher_offset;
2485 	return 0;
2486 }
2487 
2488 static int
2489 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2490 			unsigned int cipher_len,
2491 			unsigned int cipher_offset)
2492 {
2493 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2494 	struct crypto_unittest_params *ut_params = &unittest_params;
2495 
2496 	/* Generate Crypto op data structure */
2497 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2498 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2499 	TEST_ASSERT_NOT_NULL(ut_params->op,
2500 				"Failed to allocate pktmbuf offload");
2501 
2502 	/* Set crypto operation data parameters */
2503 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2504 
2505 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2506 
2507 	/* set crypto operation source mbuf */
2508 	sym_op->m_src = ut_params->ibuf;
2509 	sym_op->m_dst = ut_params->obuf;
2510 
2511 	/* iv */
2512 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2513 			iv, iv_len);
2514 	sym_op->cipher.data.length = cipher_len;
2515 	sym_op->cipher.data.offset = cipher_offset;
2516 	return 0;
2517 }
2518 
2519 static int
2520 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2521 		enum rte_crypto_cipher_operation cipher_op,
2522 		enum rte_crypto_auth_operation auth_op,
2523 		enum rte_crypto_auth_algorithm auth_algo,
2524 		enum rte_crypto_cipher_algorithm cipher_algo,
2525 		const uint8_t *key, uint8_t key_len,
2526 		uint8_t auth_iv_len, uint8_t auth_len,
2527 		uint8_t cipher_iv_len)
2528 
2529 {
2530 	uint8_t cipher_auth_key[key_len];
2531 	int status;
2532 
2533 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2534 	struct crypto_unittest_params *ut_params = &unittest_params;
2535 
2536 	memcpy(cipher_auth_key, key, key_len);
2537 
2538 	/* Setup Authentication Parameters */
2539 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2540 	ut_params->auth_xform.next = NULL;
2541 
2542 	ut_params->auth_xform.auth.op = auth_op;
2543 	ut_params->auth_xform.auth.algo = auth_algo;
2544 	ut_params->auth_xform.auth.key.length = key_len;
2545 	/* Hash key = cipher key */
2546 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2547 	ut_params->auth_xform.auth.digest_length = auth_len;
2548 	/* Auth IV will be after cipher IV */
2549 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2550 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2551 
2552 	/* Setup Cipher Parameters */
2553 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2554 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2555 
2556 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2557 	ut_params->cipher_xform.cipher.op = cipher_op;
2558 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2559 	ut_params->cipher_xform.cipher.key.length = key_len;
2560 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2561 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2562 
2563 	debug_hexdump(stdout, "key:", key, key_len);
2564 
2565 	/* Create Crypto session*/
2566 	ut_params->sess = rte_cryptodev_sym_session_create(
2567 			ts_params->session_mpool);
2568 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2569 
2570 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2571 			&ut_params->cipher_xform,
2572 			ts_params->session_priv_mpool);
2573 	if (status == -ENOTSUP)
2574 		return TEST_SKIPPED;
2575 
2576 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2577 	return 0;
2578 }
2579 
2580 static int
2581 create_wireless_cipher_auth_session(uint8_t dev_id,
2582 		enum rte_crypto_cipher_operation cipher_op,
2583 		enum rte_crypto_auth_operation auth_op,
2584 		enum rte_crypto_auth_algorithm auth_algo,
2585 		enum rte_crypto_cipher_algorithm cipher_algo,
2586 		const struct wireless_test_data *tdata)
2587 {
2588 	const uint8_t key_len = tdata->key.len;
2589 	uint8_t cipher_auth_key[key_len];
2590 	int status;
2591 
2592 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2593 	struct crypto_unittest_params *ut_params = &unittest_params;
2594 	const uint8_t *key = tdata->key.data;
2595 	const uint8_t auth_len = tdata->digest.len;
2596 	uint8_t cipher_iv_len = tdata->cipher_iv.len;
2597 	uint8_t auth_iv_len = tdata->auth_iv.len;
2598 
2599 	memcpy(cipher_auth_key, key, key_len);
2600 
2601 	/* Setup Authentication Parameters */
2602 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2603 	ut_params->auth_xform.next = NULL;
2604 
2605 	ut_params->auth_xform.auth.op = auth_op;
2606 	ut_params->auth_xform.auth.algo = auth_algo;
2607 	ut_params->auth_xform.auth.key.length = key_len;
2608 	/* Hash key = cipher key */
2609 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2610 	ut_params->auth_xform.auth.digest_length = auth_len;
2611 	/* Auth IV will be after cipher IV */
2612 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2613 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2614 
2615 	/* Setup Cipher Parameters */
2616 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2617 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2618 
2619 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2620 	ut_params->cipher_xform.cipher.op = cipher_op;
2621 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2622 	ut_params->cipher_xform.cipher.key.length = key_len;
2623 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2624 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2625 
2626 
2627 	debug_hexdump(stdout, "key:", key, key_len);
2628 
2629 	/* Create Crypto session*/
2630 	ut_params->sess = rte_cryptodev_sym_session_create(
2631 			ts_params->session_mpool);
2632 
2633 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2634 			&ut_params->cipher_xform,
2635 			ts_params->session_priv_mpool);
2636 	if (status == -ENOTSUP)
2637 		return TEST_SKIPPED;
2638 
2639 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2640 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2641 	return 0;
2642 }
2643 
2644 static int
2645 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2646 		const struct wireless_test_data *tdata)
2647 {
2648 	return create_wireless_cipher_auth_session(dev_id,
2649 		RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2650 		RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2651 		RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2652 }
2653 
2654 static int
2655 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2656 		enum rte_crypto_cipher_operation cipher_op,
2657 		enum rte_crypto_auth_operation auth_op,
2658 		enum rte_crypto_auth_algorithm auth_algo,
2659 		enum rte_crypto_cipher_algorithm cipher_algo,
2660 		const uint8_t *key, const uint8_t key_len,
2661 		uint8_t auth_iv_len, uint8_t auth_len,
2662 		uint8_t cipher_iv_len)
2663 {
2664 	uint8_t auth_cipher_key[key_len];
2665 	int status;
2666 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2667 	struct crypto_unittest_params *ut_params = &unittest_params;
2668 
2669 	memcpy(auth_cipher_key, key, key_len);
2670 
2671 	/* Setup Authentication Parameters */
2672 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2673 	ut_params->auth_xform.auth.op = auth_op;
2674 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2675 	ut_params->auth_xform.auth.algo = auth_algo;
2676 	ut_params->auth_xform.auth.key.length = key_len;
2677 	ut_params->auth_xform.auth.key.data = auth_cipher_key;
2678 	ut_params->auth_xform.auth.digest_length = auth_len;
2679 	/* Auth IV will be after cipher IV */
2680 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2681 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2682 
2683 	/* Setup Cipher Parameters */
2684 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2685 	ut_params->cipher_xform.next = NULL;
2686 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2687 	ut_params->cipher_xform.cipher.op = cipher_op;
2688 	ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2689 	ut_params->cipher_xform.cipher.key.length = key_len;
2690 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2691 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2692 
2693 	debug_hexdump(stdout, "key:", key, key_len);
2694 
2695 	/* Create Crypto session*/
2696 	ut_params->sess = rte_cryptodev_sym_session_create(
2697 			ts_params->session_mpool);
2698 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2699 
2700 	if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2701 		ut_params->auth_xform.next = NULL;
2702 		ut_params->cipher_xform.next = &ut_params->auth_xform;
2703 		status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2704 				&ut_params->cipher_xform,
2705 				ts_params->session_priv_mpool);
2706 
2707 	} else
2708 		status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2709 				&ut_params->auth_xform,
2710 				ts_params->session_priv_mpool);
2711 
2712 	if (status == -ENOTSUP)
2713 		return TEST_SKIPPED;
2714 
2715 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2716 
2717 	return 0;
2718 }
2719 
2720 static int
2721 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2722 		unsigned int auth_tag_len,
2723 		const uint8_t *iv, unsigned int iv_len,
2724 		unsigned int data_pad_len,
2725 		enum rte_crypto_auth_operation op,
2726 		unsigned int auth_len, unsigned int auth_offset)
2727 {
2728 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2729 
2730 	struct crypto_unittest_params *ut_params = &unittest_params;
2731 
2732 	/* Generate Crypto op data structure */
2733 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2734 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2735 	TEST_ASSERT_NOT_NULL(ut_params->op,
2736 		"Failed to allocate pktmbuf offload");
2737 
2738 	/* Set crypto operation data parameters */
2739 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2740 
2741 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2742 
2743 	/* set crypto operation source mbuf */
2744 	sym_op->m_src = ut_params->ibuf;
2745 
2746 	/* iv */
2747 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2748 			iv, iv_len);
2749 	/* digest */
2750 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2751 					ut_params->ibuf, auth_tag_len);
2752 
2753 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2754 				"no room to append auth tag");
2755 	ut_params->digest = sym_op->auth.digest.data;
2756 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2757 			ut_params->ibuf, data_pad_len);
2758 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2759 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2760 	else
2761 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2762 
2763 	debug_hexdump(stdout, "digest:",
2764 		sym_op->auth.digest.data,
2765 		auth_tag_len);
2766 
2767 	sym_op->auth.data.length = auth_len;
2768 	sym_op->auth.data.offset = auth_offset;
2769 
2770 	return 0;
2771 }
2772 
2773 static int
2774 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2775 	enum rte_crypto_auth_operation op)
2776 {
2777 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2778 	struct crypto_unittest_params *ut_params = &unittest_params;
2779 
2780 	const uint8_t *auth_tag = tdata->digest.data;
2781 	const unsigned int auth_tag_len = tdata->digest.len;
2782 	unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2783 	unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2784 
2785 	const uint8_t *cipher_iv = tdata->cipher_iv.data;
2786 	const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2787 	const uint8_t *auth_iv = tdata->auth_iv.data;
2788 	const uint8_t auth_iv_len = tdata->auth_iv.len;
2789 	const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2790 	const unsigned int auth_len = tdata->validAuthLenInBits.len;
2791 
2792 	/* Generate Crypto op data structure */
2793 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2794 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2795 	TEST_ASSERT_NOT_NULL(ut_params->op,
2796 			"Failed to allocate pktmbuf offload");
2797 	/* Set crypto operation data parameters */
2798 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2799 
2800 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2801 
2802 	/* set crypto operation source mbuf */
2803 	sym_op->m_src = ut_params->ibuf;
2804 
2805 	/* digest */
2806 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2807 			ut_params->ibuf, auth_tag_len);
2808 
2809 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2810 			"no room to append auth tag");
2811 	ut_params->digest = sym_op->auth.digest.data;
2812 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2813 			ut_params->ibuf, data_pad_len);
2814 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2815 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2816 	else
2817 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2818 
2819 	debug_hexdump(stdout, "digest:",
2820 		sym_op->auth.digest.data,
2821 		auth_tag_len);
2822 
2823 	/* Copy cipher and auth IVs at the end of the crypto operation */
2824 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2825 						IV_OFFSET);
2826 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2827 	iv_ptr += cipher_iv_len;
2828 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2829 
2830 	sym_op->cipher.data.length = cipher_len;
2831 	sym_op->cipher.data.offset = 0;
2832 	sym_op->auth.data.length = auth_len;
2833 	sym_op->auth.data.offset = 0;
2834 
2835 	return 0;
2836 }
2837 
2838 static int
2839 create_zuc_cipher_hash_generate_operation(
2840 		const struct wireless_test_data *tdata)
2841 {
2842 	return create_wireless_cipher_hash_operation(tdata,
2843 		RTE_CRYPTO_AUTH_OP_GENERATE);
2844 }
2845 
2846 static int
2847 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2848 		const unsigned auth_tag_len,
2849 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2850 		unsigned data_pad_len,
2851 		enum rte_crypto_auth_operation op,
2852 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2853 		const unsigned cipher_len, const unsigned cipher_offset,
2854 		const unsigned auth_len, const unsigned auth_offset)
2855 {
2856 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2857 	struct crypto_unittest_params *ut_params = &unittest_params;
2858 
2859 	enum rte_crypto_cipher_algorithm cipher_algo =
2860 			ut_params->cipher_xform.cipher.algo;
2861 	enum rte_crypto_auth_algorithm auth_algo =
2862 			ut_params->auth_xform.auth.algo;
2863 
2864 	/* Generate Crypto op data structure */
2865 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2866 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2867 	TEST_ASSERT_NOT_NULL(ut_params->op,
2868 			"Failed to allocate pktmbuf offload");
2869 	/* Set crypto operation data parameters */
2870 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2871 
2872 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2873 
2874 	/* set crypto operation source mbuf */
2875 	sym_op->m_src = ut_params->ibuf;
2876 
2877 	/* digest */
2878 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2879 			ut_params->ibuf, auth_tag_len);
2880 
2881 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2882 			"no room to append auth tag");
2883 	ut_params->digest = sym_op->auth.digest.data;
2884 
2885 	if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2886 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2887 				ut_params->ibuf, data_pad_len);
2888 	} else {
2889 		struct rte_mbuf *m = ut_params->ibuf;
2890 		unsigned int offset = data_pad_len;
2891 
2892 		while (offset > m->data_len && m->next != NULL) {
2893 			offset -= m->data_len;
2894 			m = m->next;
2895 		}
2896 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2897 			m, offset);
2898 	}
2899 
2900 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2901 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2902 	else
2903 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2904 
2905 	debug_hexdump(stdout, "digest:",
2906 		sym_op->auth.digest.data,
2907 		auth_tag_len);
2908 
2909 	/* Copy cipher and auth IVs at the end of the crypto operation */
2910 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2911 						IV_OFFSET);
2912 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2913 	iv_ptr += cipher_iv_len;
2914 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2915 
2916 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2917 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2918 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2919 		sym_op->cipher.data.length = cipher_len;
2920 		sym_op->cipher.data.offset = cipher_offset;
2921 	} else {
2922 		sym_op->cipher.data.length = cipher_len >> 3;
2923 		sym_op->cipher.data.offset = cipher_offset >> 3;
2924 	}
2925 
2926 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2927 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2928 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2929 		sym_op->auth.data.length = auth_len;
2930 		sym_op->auth.data.offset = auth_offset;
2931 	} else {
2932 		sym_op->auth.data.length = auth_len >> 3;
2933 		sym_op->auth.data.offset = auth_offset >> 3;
2934 	}
2935 
2936 	return 0;
2937 }
2938 
2939 static int
2940 create_wireless_algo_auth_cipher_operation(
2941 		const uint8_t *auth_tag, unsigned int auth_tag_len,
2942 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2943 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2944 		unsigned int data_pad_len,
2945 		unsigned int cipher_len, unsigned int cipher_offset,
2946 		unsigned int auth_len, unsigned int auth_offset,
2947 		uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2948 {
2949 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2950 	struct crypto_unittest_params *ut_params = &unittest_params;
2951 
2952 	enum rte_crypto_cipher_algorithm cipher_algo =
2953 			ut_params->cipher_xform.cipher.algo;
2954 	enum rte_crypto_auth_algorithm auth_algo =
2955 			ut_params->auth_xform.auth.algo;
2956 
2957 	/* Generate Crypto op data structure */
2958 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2959 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2960 	TEST_ASSERT_NOT_NULL(ut_params->op,
2961 			"Failed to allocate pktmbuf offload");
2962 
2963 	/* Set crypto operation data parameters */
2964 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2965 
2966 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2967 
2968 	/* set crypto operation mbufs */
2969 	sym_op->m_src = ut_params->ibuf;
2970 	if (op_mode == OUT_OF_PLACE)
2971 		sym_op->m_dst = ut_params->obuf;
2972 
2973 	/* digest */
2974 	if (!do_sgl) {
2975 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
2976 			(op_mode == IN_PLACE ?
2977 				ut_params->ibuf : ut_params->obuf),
2978 			uint8_t *, data_pad_len);
2979 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2980 			(op_mode == IN_PLACE ?
2981 				ut_params->ibuf : ut_params->obuf),
2982 			data_pad_len);
2983 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2984 	} else {
2985 		uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
2986 		struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
2987 				sym_op->m_src : sym_op->m_dst);
2988 		while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
2989 			remaining_off -= rte_pktmbuf_data_len(sgl_buf);
2990 			sgl_buf = sgl_buf->next;
2991 		}
2992 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
2993 				uint8_t *, remaining_off);
2994 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
2995 				remaining_off);
2996 		memset(sym_op->auth.digest.data, 0, remaining_off);
2997 		while (sgl_buf->next != NULL) {
2998 			memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
2999 				0, rte_pktmbuf_data_len(sgl_buf));
3000 			sgl_buf = sgl_buf->next;
3001 		}
3002 	}
3003 
3004 	/* Copy digest for the verification */
3005 	if (verify)
3006 		memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3007 
3008 	/* Copy cipher and auth IVs at the end of the crypto operation */
3009 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
3010 			ut_params->op, uint8_t *, IV_OFFSET);
3011 
3012 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
3013 	iv_ptr += cipher_iv_len;
3014 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
3015 
3016 	/* Only copy over the offset data needed from src to dst in OOP,
3017 	 * if the auth and cipher offsets are not aligned
3018 	 */
3019 	if (op_mode == OUT_OF_PLACE) {
3020 		if (cipher_offset > auth_offset)
3021 			rte_memcpy(
3022 				rte_pktmbuf_mtod_offset(
3023 					sym_op->m_dst,
3024 					uint8_t *, auth_offset >> 3),
3025 				rte_pktmbuf_mtod_offset(
3026 					sym_op->m_src,
3027 					uint8_t *, auth_offset >> 3),
3028 				((cipher_offset >> 3) - (auth_offset >> 3)));
3029 	}
3030 
3031 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
3032 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
3033 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
3034 		sym_op->cipher.data.length = cipher_len;
3035 		sym_op->cipher.data.offset = cipher_offset;
3036 	} else {
3037 		sym_op->cipher.data.length = cipher_len >> 3;
3038 		sym_op->cipher.data.offset = cipher_offset >> 3;
3039 	}
3040 
3041 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
3042 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
3043 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
3044 		sym_op->auth.data.length = auth_len;
3045 		sym_op->auth.data.offset = auth_offset;
3046 	} else {
3047 		sym_op->auth.data.length = auth_len >> 3;
3048 		sym_op->auth.data.offset = auth_offset >> 3;
3049 	}
3050 
3051 	return 0;
3052 }
3053 
3054 static int
3055 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
3056 {
3057 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3058 	struct crypto_unittest_params *ut_params = &unittest_params;
3059 
3060 	int retval;
3061 	unsigned plaintext_pad_len;
3062 	unsigned plaintext_len;
3063 	uint8_t *plaintext;
3064 	struct rte_cryptodev_info dev_info;
3065 
3066 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3067 	uint64_t feat_flags = dev_info.feature_flags;
3068 
3069 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3070 			((tdata->validAuthLenInBits.len % 8) != 0)) {
3071 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3072 		return TEST_SKIPPED;
3073 	}
3074 
3075 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3076 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3077 		printf("Device doesn't support RAW data-path APIs.\n");
3078 		return TEST_SKIPPED;
3079 	}
3080 
3081 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3082 		return TEST_SKIPPED;
3083 
3084 	/* Verify the capabilities */
3085 	struct rte_cryptodev_sym_capability_idx cap_idx;
3086 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3087 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3088 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3089 			&cap_idx) == NULL)
3090 		return TEST_SKIPPED;
3091 
3092 	/* Create SNOW 3G session */
3093 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3094 			tdata->key.data, tdata->key.len,
3095 			tdata->auth_iv.len, tdata->digest.len,
3096 			RTE_CRYPTO_AUTH_OP_GENERATE,
3097 			RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3098 	if (retval < 0)
3099 		return retval;
3100 
3101 	/* alloc mbuf and set payload */
3102 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3103 
3104 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3105 	rte_pktmbuf_tailroom(ut_params->ibuf));
3106 
3107 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3108 	/* Append data which is padded to a multiple of */
3109 	/* the algorithms block size */
3110 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3111 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3112 				plaintext_pad_len);
3113 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3114 
3115 	/* Create SNOW 3G operation */
3116 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3117 			tdata->auth_iv.data, tdata->auth_iv.len,
3118 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3119 			tdata->validAuthLenInBits.len,
3120 			0);
3121 	if (retval < 0)
3122 		return retval;
3123 
3124 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3125 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3126 				ut_params->op, 0, 1, 1, 0);
3127 	else
3128 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3129 				ut_params->op);
3130 	ut_params->obuf = ut_params->op->sym->m_src;
3131 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3132 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3133 			+ plaintext_pad_len;
3134 
3135 	/* Validate obuf */
3136 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3137 	ut_params->digest,
3138 	tdata->digest.data,
3139 	DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3140 	"SNOW 3G Generated auth tag not as expected");
3141 
3142 	return 0;
3143 }
3144 
3145 static int
3146 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
3147 {
3148 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3149 	struct crypto_unittest_params *ut_params = &unittest_params;
3150 
3151 	int retval;
3152 	unsigned plaintext_pad_len;
3153 	unsigned plaintext_len;
3154 	uint8_t *plaintext;
3155 	struct rte_cryptodev_info dev_info;
3156 
3157 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3158 	uint64_t feat_flags = dev_info.feature_flags;
3159 
3160 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3161 			((tdata->validAuthLenInBits.len % 8) != 0)) {
3162 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3163 		return TEST_SKIPPED;
3164 	}
3165 
3166 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3167 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3168 		printf("Device doesn't support RAW data-path APIs.\n");
3169 		return TEST_SKIPPED;
3170 	}
3171 
3172 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3173 		return TEST_SKIPPED;
3174 
3175 	/* Verify the capabilities */
3176 	struct rte_cryptodev_sym_capability_idx cap_idx;
3177 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3178 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3179 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3180 			&cap_idx) == NULL)
3181 		return TEST_SKIPPED;
3182 
3183 	/* Create SNOW 3G session */
3184 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3185 				tdata->key.data, tdata->key.len,
3186 				tdata->auth_iv.len, tdata->digest.len,
3187 				RTE_CRYPTO_AUTH_OP_VERIFY,
3188 				RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3189 	if (retval < 0)
3190 		return retval;
3191 	/* alloc mbuf and set payload */
3192 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3193 
3194 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3195 	rte_pktmbuf_tailroom(ut_params->ibuf));
3196 
3197 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3198 	/* Append data which is padded to a multiple of */
3199 	/* the algorithms block size */
3200 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3201 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3202 				plaintext_pad_len);
3203 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3204 
3205 	/* Create SNOW 3G operation */
3206 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
3207 			tdata->digest.len,
3208 			tdata->auth_iv.data, tdata->auth_iv.len,
3209 			plaintext_pad_len,
3210 			RTE_CRYPTO_AUTH_OP_VERIFY,
3211 			tdata->validAuthLenInBits.len,
3212 			0);
3213 	if (retval < 0)
3214 		return retval;
3215 
3216 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3217 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3218 				ut_params->op, 0, 1, 1, 0);
3219 	else
3220 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3221 				ut_params->op);
3222 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3223 	ut_params->obuf = ut_params->op->sym->m_src;
3224 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3225 				+ plaintext_pad_len;
3226 
3227 	/* Validate obuf */
3228 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3229 		return 0;
3230 	else
3231 		return -1;
3232 
3233 	return 0;
3234 }
3235 
3236 static int
3237 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
3238 {
3239 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3240 	struct crypto_unittest_params *ut_params = &unittest_params;
3241 
3242 	int retval;
3243 	unsigned plaintext_pad_len;
3244 	unsigned plaintext_len;
3245 	uint8_t *plaintext;
3246 	struct rte_cryptodev_info dev_info;
3247 
3248 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3249 	uint64_t feat_flags = dev_info.feature_flags;
3250 
3251 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3252 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3253 		printf("Device doesn't support RAW data-path APIs.\n");
3254 		return TEST_SKIPPED;
3255 	}
3256 
3257 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3258 		return TEST_SKIPPED;
3259 
3260 	/* Verify the capabilities */
3261 	struct rte_cryptodev_sym_capability_idx cap_idx;
3262 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3263 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3264 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3265 			&cap_idx) == NULL)
3266 		return TEST_SKIPPED;
3267 
3268 	/* Create KASUMI session */
3269 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3270 			tdata->key.data, tdata->key.len,
3271 			0, tdata->digest.len,
3272 			RTE_CRYPTO_AUTH_OP_GENERATE,
3273 			RTE_CRYPTO_AUTH_KASUMI_F9);
3274 	if (retval < 0)
3275 		return retval;
3276 
3277 	/* alloc mbuf and set payload */
3278 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3279 
3280 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3281 	rte_pktmbuf_tailroom(ut_params->ibuf));
3282 
3283 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3284 	/* Append data which is padded to a multiple of */
3285 	/* the algorithms block size */
3286 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3287 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3288 				plaintext_pad_len);
3289 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3290 
3291 	/* Create KASUMI operation */
3292 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3293 			NULL, 0,
3294 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3295 			tdata->plaintext.len,
3296 			0);
3297 	if (retval < 0)
3298 		return retval;
3299 
3300 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3301 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
3302 			ut_params->op);
3303 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3304 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3305 				ut_params->op, 0, 1, 1, 0);
3306 	else
3307 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3308 			ut_params->op);
3309 
3310 	ut_params->obuf = ut_params->op->sym->m_src;
3311 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3312 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3313 			+ plaintext_pad_len;
3314 
3315 	/* Validate obuf */
3316 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3317 	ut_params->digest,
3318 	tdata->digest.data,
3319 	DIGEST_BYTE_LENGTH_KASUMI_F9,
3320 	"KASUMI Generated auth tag not as expected");
3321 
3322 	return 0;
3323 }
3324 
3325 static int
3326 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
3327 {
3328 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3329 	struct crypto_unittest_params *ut_params = &unittest_params;
3330 
3331 	int retval;
3332 	unsigned plaintext_pad_len;
3333 	unsigned plaintext_len;
3334 	uint8_t *plaintext;
3335 	struct rte_cryptodev_info dev_info;
3336 
3337 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3338 	uint64_t feat_flags = dev_info.feature_flags;
3339 
3340 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3341 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3342 		printf("Device doesn't support RAW data-path APIs.\n");
3343 		return TEST_SKIPPED;
3344 	}
3345 
3346 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3347 		return TEST_SKIPPED;
3348 
3349 	/* Verify the capabilities */
3350 	struct rte_cryptodev_sym_capability_idx cap_idx;
3351 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3352 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3353 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3354 			&cap_idx) == NULL)
3355 		return TEST_SKIPPED;
3356 
3357 	/* Create KASUMI session */
3358 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3359 				tdata->key.data, tdata->key.len,
3360 				0, tdata->digest.len,
3361 				RTE_CRYPTO_AUTH_OP_VERIFY,
3362 				RTE_CRYPTO_AUTH_KASUMI_F9);
3363 	if (retval < 0)
3364 		return retval;
3365 	/* alloc mbuf and set payload */
3366 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3367 
3368 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3369 	rte_pktmbuf_tailroom(ut_params->ibuf));
3370 
3371 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3372 	/* Append data which is padded to a multiple */
3373 	/* of the algorithms block size */
3374 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3375 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3376 				plaintext_pad_len);
3377 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3378 
3379 	/* Create KASUMI operation */
3380 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
3381 			tdata->digest.len,
3382 			NULL, 0,
3383 			plaintext_pad_len,
3384 			RTE_CRYPTO_AUTH_OP_VERIFY,
3385 			tdata->plaintext.len,
3386 			0);
3387 	if (retval < 0)
3388 		return retval;
3389 
3390 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3391 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3392 				ut_params->op, 0, 1, 1, 0);
3393 	else
3394 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3395 				ut_params->op);
3396 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3397 	ut_params->obuf = ut_params->op->sym->m_src;
3398 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3399 				+ plaintext_pad_len;
3400 
3401 	/* Validate obuf */
3402 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3403 		return 0;
3404 	else
3405 		return -1;
3406 
3407 	return 0;
3408 }
3409 
3410 static int
3411 test_snow3g_hash_generate_test_case_1(void)
3412 {
3413 	return test_snow3g_authentication(&snow3g_hash_test_case_1);
3414 }
3415 
3416 static int
3417 test_snow3g_hash_generate_test_case_2(void)
3418 {
3419 	return test_snow3g_authentication(&snow3g_hash_test_case_2);
3420 }
3421 
3422 static int
3423 test_snow3g_hash_generate_test_case_3(void)
3424 {
3425 	return test_snow3g_authentication(&snow3g_hash_test_case_3);
3426 }
3427 
3428 static int
3429 test_snow3g_hash_generate_test_case_4(void)
3430 {
3431 	return test_snow3g_authentication(&snow3g_hash_test_case_4);
3432 }
3433 
3434 static int
3435 test_snow3g_hash_generate_test_case_5(void)
3436 {
3437 	return test_snow3g_authentication(&snow3g_hash_test_case_5);
3438 }
3439 
3440 static int
3441 test_snow3g_hash_generate_test_case_6(void)
3442 {
3443 	return test_snow3g_authentication(&snow3g_hash_test_case_6);
3444 }
3445 
3446 static int
3447 test_snow3g_hash_verify_test_case_1(void)
3448 {
3449 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3450 
3451 }
3452 
3453 static int
3454 test_snow3g_hash_verify_test_case_2(void)
3455 {
3456 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3457 }
3458 
3459 static int
3460 test_snow3g_hash_verify_test_case_3(void)
3461 {
3462 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3463 }
3464 
3465 static int
3466 test_snow3g_hash_verify_test_case_4(void)
3467 {
3468 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3469 }
3470 
3471 static int
3472 test_snow3g_hash_verify_test_case_5(void)
3473 {
3474 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3475 }
3476 
3477 static int
3478 test_snow3g_hash_verify_test_case_6(void)
3479 {
3480 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3481 }
3482 
3483 static int
3484 test_kasumi_hash_generate_test_case_1(void)
3485 {
3486 	return test_kasumi_authentication(&kasumi_hash_test_case_1);
3487 }
3488 
3489 static int
3490 test_kasumi_hash_generate_test_case_2(void)
3491 {
3492 	return test_kasumi_authentication(&kasumi_hash_test_case_2);
3493 }
3494 
3495 static int
3496 test_kasumi_hash_generate_test_case_3(void)
3497 {
3498 	return test_kasumi_authentication(&kasumi_hash_test_case_3);
3499 }
3500 
3501 static int
3502 test_kasumi_hash_generate_test_case_4(void)
3503 {
3504 	return test_kasumi_authentication(&kasumi_hash_test_case_4);
3505 }
3506 
3507 static int
3508 test_kasumi_hash_generate_test_case_5(void)
3509 {
3510 	return test_kasumi_authentication(&kasumi_hash_test_case_5);
3511 }
3512 
3513 static int
3514 test_kasumi_hash_generate_test_case_6(void)
3515 {
3516 	return test_kasumi_authentication(&kasumi_hash_test_case_6);
3517 }
3518 
3519 static int
3520 test_kasumi_hash_verify_test_case_1(void)
3521 {
3522 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3523 }
3524 
3525 static int
3526 test_kasumi_hash_verify_test_case_2(void)
3527 {
3528 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3529 }
3530 
3531 static int
3532 test_kasumi_hash_verify_test_case_3(void)
3533 {
3534 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3535 }
3536 
3537 static int
3538 test_kasumi_hash_verify_test_case_4(void)
3539 {
3540 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3541 }
3542 
3543 static int
3544 test_kasumi_hash_verify_test_case_5(void)
3545 {
3546 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3547 }
3548 
3549 static int
3550 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3551 {
3552 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3553 	struct crypto_unittest_params *ut_params = &unittest_params;
3554 
3555 	int retval;
3556 	uint8_t *plaintext, *ciphertext;
3557 	unsigned plaintext_pad_len;
3558 	unsigned plaintext_len;
3559 	struct rte_cryptodev_info dev_info;
3560 
3561 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3562 	uint64_t feat_flags = dev_info.feature_flags;
3563 
3564 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3565 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3566 		printf("Device doesn't support RAW data-path APIs.\n");
3567 		return TEST_SKIPPED;
3568 	}
3569 
3570 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3571 		return TEST_SKIPPED;
3572 
3573 	/* Verify the capabilities */
3574 	struct rte_cryptodev_sym_capability_idx cap_idx;
3575 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3576 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3577 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3578 			&cap_idx) == NULL)
3579 		return TEST_SKIPPED;
3580 
3581 	/* Create KASUMI session */
3582 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3583 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3584 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3585 					tdata->key.data, tdata->key.len,
3586 					tdata->cipher_iv.len);
3587 	if (retval < 0)
3588 		return retval;
3589 
3590 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3591 
3592 	/* Clear mbuf payload */
3593 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3594 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3595 
3596 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3597 	/* Append data which is padded to a multiple */
3598 	/* of the algorithms block size */
3599 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3600 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3601 				plaintext_pad_len);
3602 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3603 
3604 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3605 
3606 	/* Create KASUMI operation */
3607 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3608 				tdata->cipher_iv.len,
3609 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3610 				tdata->validCipherOffsetInBits.len);
3611 	if (retval < 0)
3612 		return retval;
3613 
3614 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3615 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3616 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3617 	else
3618 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3619 				ut_params->op);
3620 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3621 
3622 	ut_params->obuf = ut_params->op->sym->m_dst;
3623 	if (ut_params->obuf)
3624 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3625 	else
3626 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3627 
3628 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3629 
3630 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3631 				(tdata->validCipherOffsetInBits.len >> 3);
3632 	/* Validate obuf */
3633 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3634 		ciphertext,
3635 		reference_ciphertext,
3636 		tdata->validCipherLenInBits.len,
3637 		"KASUMI Ciphertext data not as expected");
3638 	return 0;
3639 }
3640 
3641 static int
3642 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3643 {
3644 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3645 	struct crypto_unittest_params *ut_params = &unittest_params;
3646 
3647 	int retval;
3648 
3649 	unsigned int plaintext_pad_len;
3650 	unsigned int plaintext_len;
3651 
3652 	uint8_t buffer[10000];
3653 	const uint8_t *ciphertext;
3654 
3655 	struct rte_cryptodev_info dev_info;
3656 
3657 	/* Verify the capabilities */
3658 	struct rte_cryptodev_sym_capability_idx cap_idx;
3659 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3660 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3661 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3662 			&cap_idx) == NULL)
3663 		return TEST_SKIPPED;
3664 
3665 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3666 
3667 	uint64_t feat_flags = dev_info.feature_flags;
3668 
3669 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3670 		printf("Device doesn't support in-place scatter-gather. "
3671 				"Test Skipped.\n");
3672 		return TEST_SKIPPED;
3673 	}
3674 
3675 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3676 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3677 		printf("Device doesn't support RAW data-path APIs.\n");
3678 		return TEST_SKIPPED;
3679 	}
3680 
3681 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3682 		return TEST_SKIPPED;
3683 
3684 	/* Create KASUMI session */
3685 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3686 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3687 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3688 					tdata->key.data, tdata->key.len,
3689 					tdata->cipher_iv.len);
3690 	if (retval < 0)
3691 		return retval;
3692 
3693 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3694 
3695 
3696 	/* Append data which is padded to a multiple */
3697 	/* of the algorithms block size */
3698 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3699 
3700 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3701 			plaintext_pad_len, 10, 0);
3702 
3703 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3704 
3705 	/* Create KASUMI operation */
3706 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3707 				tdata->cipher_iv.len,
3708 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3709 				tdata->validCipherOffsetInBits.len);
3710 	if (retval < 0)
3711 		return retval;
3712 
3713 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3714 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3715 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3716 	else
3717 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3718 						ut_params->op);
3719 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3720 
3721 	ut_params->obuf = ut_params->op->sym->m_dst;
3722 
3723 	if (ut_params->obuf)
3724 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3725 				plaintext_len, buffer);
3726 	else
3727 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3728 				tdata->validCipherOffsetInBits.len >> 3,
3729 				plaintext_len, buffer);
3730 
3731 	/* Validate obuf */
3732 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3733 
3734 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3735 				(tdata->validCipherOffsetInBits.len >> 3);
3736 	/* Validate obuf */
3737 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3738 		ciphertext,
3739 		reference_ciphertext,
3740 		tdata->validCipherLenInBits.len,
3741 		"KASUMI Ciphertext data not as expected");
3742 	return 0;
3743 }
3744 
3745 static int
3746 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3747 {
3748 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3749 	struct crypto_unittest_params *ut_params = &unittest_params;
3750 
3751 	int retval;
3752 	uint8_t *plaintext, *ciphertext;
3753 	unsigned plaintext_pad_len;
3754 	unsigned plaintext_len;
3755 
3756 	/* Verify the capabilities */
3757 	struct rte_cryptodev_sym_capability_idx cap_idx;
3758 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3759 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3760 	/* Data-path service does not support OOP */
3761 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3762 			&cap_idx) == NULL)
3763 		return TEST_SKIPPED;
3764 
3765 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3766 		return TEST_SKIPPED;
3767 
3768 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3769 		return TEST_SKIPPED;
3770 
3771 	/* Create KASUMI session */
3772 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3773 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3774 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3775 					tdata->key.data, tdata->key.len,
3776 					tdata->cipher_iv.len);
3777 	if (retval < 0)
3778 		return retval;
3779 
3780 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3781 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3782 
3783 	/* Clear mbuf payload */
3784 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3785 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3786 
3787 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3788 	/* Append data which is padded to a multiple */
3789 	/* of the algorithms block size */
3790 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3791 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3792 				plaintext_pad_len);
3793 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3794 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3795 
3796 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3797 
3798 	/* Create KASUMI operation */
3799 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3800 				tdata->cipher_iv.len,
3801 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3802 				tdata->validCipherOffsetInBits.len);
3803 	if (retval < 0)
3804 		return retval;
3805 
3806 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3807 						ut_params->op);
3808 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3809 
3810 	ut_params->obuf = ut_params->op->sym->m_dst;
3811 	if (ut_params->obuf)
3812 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3813 	else
3814 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3815 
3816 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3817 
3818 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3819 				(tdata->validCipherOffsetInBits.len >> 3);
3820 	/* Validate obuf */
3821 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3822 		ciphertext,
3823 		reference_ciphertext,
3824 		tdata->validCipherLenInBits.len,
3825 		"KASUMI Ciphertext data not as expected");
3826 	return 0;
3827 }
3828 
3829 static int
3830 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3831 {
3832 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3833 	struct crypto_unittest_params *ut_params = &unittest_params;
3834 
3835 	int retval;
3836 	unsigned int plaintext_pad_len;
3837 	unsigned int plaintext_len;
3838 
3839 	const uint8_t *ciphertext;
3840 	uint8_t buffer[2048];
3841 
3842 	struct rte_cryptodev_info dev_info;
3843 
3844 	/* Verify the capabilities */
3845 	struct rte_cryptodev_sym_capability_idx cap_idx;
3846 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3847 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3848 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3849 			&cap_idx) == NULL)
3850 		return TEST_SKIPPED;
3851 
3852 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3853 		return TEST_SKIPPED;
3854 
3855 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3856 		return TEST_SKIPPED;
3857 
3858 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3859 
3860 	uint64_t feat_flags = dev_info.feature_flags;
3861 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3862 		printf("Device doesn't support out-of-place scatter-gather "
3863 				"in both input and output mbufs. "
3864 				"Test Skipped.\n");
3865 		return TEST_SKIPPED;
3866 	}
3867 
3868 	/* Create KASUMI session */
3869 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3870 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3871 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3872 					tdata->key.data, tdata->key.len,
3873 					tdata->cipher_iv.len);
3874 	if (retval < 0)
3875 		return retval;
3876 
3877 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3878 	/* Append data which is padded to a multiple */
3879 	/* of the algorithms block size */
3880 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3881 
3882 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3883 			plaintext_pad_len, 10, 0);
3884 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3885 			plaintext_pad_len, 3, 0);
3886 
3887 	/* Append data which is padded to a multiple */
3888 	/* of the algorithms block size */
3889 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3890 
3891 	/* Create KASUMI operation */
3892 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3893 				tdata->cipher_iv.len,
3894 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3895 				tdata->validCipherOffsetInBits.len);
3896 	if (retval < 0)
3897 		return retval;
3898 
3899 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3900 						ut_params->op);
3901 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3902 
3903 	ut_params->obuf = ut_params->op->sym->m_dst;
3904 	if (ut_params->obuf)
3905 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3906 				plaintext_pad_len, buffer);
3907 	else
3908 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3909 				tdata->validCipherOffsetInBits.len >> 3,
3910 				plaintext_pad_len, buffer);
3911 
3912 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3913 				(tdata->validCipherOffsetInBits.len >> 3);
3914 	/* Validate obuf */
3915 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3916 		ciphertext,
3917 		reference_ciphertext,
3918 		tdata->validCipherLenInBits.len,
3919 		"KASUMI Ciphertext data not as expected");
3920 	return 0;
3921 }
3922 
3923 
3924 static int
3925 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3926 {
3927 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3928 	struct crypto_unittest_params *ut_params = &unittest_params;
3929 
3930 	int retval;
3931 	uint8_t *ciphertext, *plaintext;
3932 	unsigned ciphertext_pad_len;
3933 	unsigned ciphertext_len;
3934 
3935 	/* Verify the capabilities */
3936 	struct rte_cryptodev_sym_capability_idx cap_idx;
3937 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3938 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3939 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3940 			&cap_idx) == NULL)
3941 		return TEST_SKIPPED;
3942 
3943 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3944 		return TEST_SKIPPED;
3945 
3946 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3947 		return TEST_SKIPPED;
3948 
3949 	/* Create KASUMI session */
3950 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3951 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
3952 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3953 					tdata->key.data, tdata->key.len,
3954 					tdata->cipher_iv.len);
3955 	if (retval < 0)
3956 		return retval;
3957 
3958 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3959 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3960 
3961 	/* Clear mbuf payload */
3962 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3963 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3964 
3965 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3966 	/* Append data which is padded to a multiple */
3967 	/* of the algorithms block size */
3968 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3969 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3970 				ciphertext_pad_len);
3971 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3972 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3973 
3974 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3975 
3976 	/* Create KASUMI operation */
3977 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3978 				tdata->cipher_iv.len,
3979 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3980 				tdata->validCipherOffsetInBits.len);
3981 	if (retval < 0)
3982 		return retval;
3983 
3984 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3985 						ut_params->op);
3986 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3987 
3988 	ut_params->obuf = ut_params->op->sym->m_dst;
3989 	if (ut_params->obuf)
3990 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3991 	else
3992 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3993 
3994 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3995 
3996 	const uint8_t *reference_plaintext = tdata->plaintext.data +
3997 				(tdata->validCipherOffsetInBits.len >> 3);
3998 	/* Validate obuf */
3999 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4000 		plaintext,
4001 		reference_plaintext,
4002 		tdata->validCipherLenInBits.len,
4003 		"KASUMI Plaintext data not as expected");
4004 	return 0;
4005 }
4006 
4007 static int
4008 test_kasumi_decryption(const struct kasumi_test_data *tdata)
4009 {
4010 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4011 	struct crypto_unittest_params *ut_params = &unittest_params;
4012 
4013 	int retval;
4014 	uint8_t *ciphertext, *plaintext;
4015 	unsigned ciphertext_pad_len;
4016 	unsigned ciphertext_len;
4017 	struct rte_cryptodev_info dev_info;
4018 
4019 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4020 	uint64_t feat_flags = dev_info.feature_flags;
4021 
4022 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4023 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4024 		printf("Device doesn't support RAW data-path APIs.\n");
4025 		return TEST_SKIPPED;
4026 	}
4027 
4028 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4029 		return TEST_SKIPPED;
4030 
4031 	/* Verify the capabilities */
4032 	struct rte_cryptodev_sym_capability_idx cap_idx;
4033 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4034 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4035 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4036 			&cap_idx) == NULL)
4037 		return TEST_SKIPPED;
4038 
4039 	/* Create KASUMI session */
4040 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4041 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4042 					RTE_CRYPTO_CIPHER_KASUMI_F8,
4043 					tdata->key.data, tdata->key.len,
4044 					tdata->cipher_iv.len);
4045 	if (retval < 0)
4046 		return retval;
4047 
4048 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4049 
4050 	/* Clear mbuf payload */
4051 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4052 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4053 
4054 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4055 	/* Append data which is padded to a multiple */
4056 	/* of the algorithms block size */
4057 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4058 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4059 				ciphertext_pad_len);
4060 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4061 
4062 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4063 
4064 	/* Create KASUMI operation */
4065 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4066 					tdata->cipher_iv.len,
4067 					tdata->ciphertext.len,
4068 					tdata->validCipherOffsetInBits.len);
4069 	if (retval < 0)
4070 		return retval;
4071 
4072 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4073 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4074 				ut_params->op, 1, 0, 1, 0);
4075 	else
4076 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4077 						ut_params->op);
4078 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4079 
4080 	ut_params->obuf = ut_params->op->sym->m_dst;
4081 	if (ut_params->obuf)
4082 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4083 	else
4084 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4085 
4086 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4087 
4088 	const uint8_t *reference_plaintext = tdata->plaintext.data +
4089 				(tdata->validCipherOffsetInBits.len >> 3);
4090 	/* Validate obuf */
4091 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4092 		plaintext,
4093 		reference_plaintext,
4094 		tdata->validCipherLenInBits.len,
4095 		"KASUMI Plaintext data not as expected");
4096 	return 0;
4097 }
4098 
4099 static int
4100 test_snow3g_encryption(const struct snow3g_test_data *tdata)
4101 {
4102 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4103 	struct crypto_unittest_params *ut_params = &unittest_params;
4104 
4105 	int retval;
4106 	uint8_t *plaintext, *ciphertext;
4107 	unsigned plaintext_pad_len;
4108 	unsigned plaintext_len;
4109 	struct rte_cryptodev_info dev_info;
4110 
4111 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4112 	uint64_t feat_flags = dev_info.feature_flags;
4113 
4114 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4115 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4116 		printf("Device doesn't support RAW data-path APIs.\n");
4117 		return TEST_SKIPPED;
4118 	}
4119 
4120 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4121 		return TEST_SKIPPED;
4122 
4123 	/* Verify the capabilities */
4124 	struct rte_cryptodev_sym_capability_idx cap_idx;
4125 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4126 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4127 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4128 			&cap_idx) == NULL)
4129 		return TEST_SKIPPED;
4130 
4131 	/* Create SNOW 3G session */
4132 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4133 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4134 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4135 					tdata->key.data, tdata->key.len,
4136 					tdata->cipher_iv.len);
4137 	if (retval < 0)
4138 		return retval;
4139 
4140 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4141 
4142 	/* Clear mbuf payload */
4143 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4144 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4145 
4146 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4147 	/* Append data which is padded to a multiple of */
4148 	/* the algorithms block size */
4149 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4150 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4151 				plaintext_pad_len);
4152 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4153 
4154 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4155 
4156 	/* Create SNOW 3G operation */
4157 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4158 					tdata->cipher_iv.len,
4159 					tdata->validCipherLenInBits.len,
4160 					0);
4161 	if (retval < 0)
4162 		return retval;
4163 
4164 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4165 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4166 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4167 	else
4168 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4169 						ut_params->op);
4170 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4171 
4172 	ut_params->obuf = ut_params->op->sym->m_dst;
4173 	if (ut_params->obuf)
4174 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4175 	else
4176 		ciphertext = plaintext;
4177 
4178 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4179 
4180 	/* Validate obuf */
4181 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4182 		ciphertext,
4183 		tdata->ciphertext.data,
4184 		tdata->validDataLenInBits.len,
4185 		"SNOW 3G Ciphertext data not as expected");
4186 	return 0;
4187 }
4188 
4189 
4190 static int
4191 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
4192 {
4193 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4194 	struct crypto_unittest_params *ut_params = &unittest_params;
4195 	uint8_t *plaintext, *ciphertext;
4196 
4197 	int retval;
4198 	unsigned plaintext_pad_len;
4199 	unsigned plaintext_len;
4200 
4201 	/* Verify the capabilities */
4202 	struct rte_cryptodev_sym_capability_idx cap_idx;
4203 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4204 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4205 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4206 			&cap_idx) == NULL)
4207 		return TEST_SKIPPED;
4208 
4209 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4210 		return TEST_SKIPPED;
4211 
4212 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4213 		return TEST_SKIPPED;
4214 
4215 	/* Create SNOW 3G session */
4216 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4217 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4218 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4219 					tdata->key.data, tdata->key.len,
4220 					tdata->cipher_iv.len);
4221 	if (retval < 0)
4222 		return retval;
4223 
4224 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4225 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4226 
4227 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4228 			"Failed to allocate input buffer in mempool");
4229 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4230 			"Failed to allocate output buffer in mempool");
4231 
4232 	/* Clear mbuf payload */
4233 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4234 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4235 
4236 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4237 	/* Append data which is padded to a multiple of */
4238 	/* the algorithms block size */
4239 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4240 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4241 				plaintext_pad_len);
4242 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4243 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4244 
4245 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4246 
4247 	/* Create SNOW 3G operation */
4248 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4249 					tdata->cipher_iv.len,
4250 					tdata->validCipherLenInBits.len,
4251 					0);
4252 	if (retval < 0)
4253 		return retval;
4254 
4255 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4256 						ut_params->op);
4257 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4258 
4259 	ut_params->obuf = ut_params->op->sym->m_dst;
4260 	if (ut_params->obuf)
4261 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4262 	else
4263 		ciphertext = plaintext;
4264 
4265 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4266 
4267 	/* Validate obuf */
4268 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4269 		ciphertext,
4270 		tdata->ciphertext.data,
4271 		tdata->validDataLenInBits.len,
4272 		"SNOW 3G Ciphertext data not as expected");
4273 	return 0;
4274 }
4275 
4276 static int
4277 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
4278 {
4279 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4280 	struct crypto_unittest_params *ut_params = &unittest_params;
4281 
4282 	int retval;
4283 	unsigned int plaintext_pad_len;
4284 	unsigned int plaintext_len;
4285 	uint8_t buffer[10000];
4286 	const uint8_t *ciphertext;
4287 
4288 	struct rte_cryptodev_info dev_info;
4289 
4290 	/* Verify the capabilities */
4291 	struct rte_cryptodev_sym_capability_idx cap_idx;
4292 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4293 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4294 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4295 			&cap_idx) == NULL)
4296 		return TEST_SKIPPED;
4297 
4298 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4299 		return TEST_SKIPPED;
4300 
4301 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4302 		return TEST_SKIPPED;
4303 
4304 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4305 
4306 	uint64_t feat_flags = dev_info.feature_flags;
4307 
4308 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4309 		printf("Device doesn't support out-of-place scatter-gather "
4310 				"in both input and output mbufs. "
4311 				"Test Skipped.\n");
4312 		return TEST_SKIPPED;
4313 	}
4314 
4315 	/* Create SNOW 3G session */
4316 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4317 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4318 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4319 					tdata->key.data, tdata->key.len,
4320 					tdata->cipher_iv.len);
4321 	if (retval < 0)
4322 		return retval;
4323 
4324 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4325 	/* Append data which is padded to a multiple of */
4326 	/* the algorithms block size */
4327 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4328 
4329 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4330 			plaintext_pad_len, 10, 0);
4331 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4332 			plaintext_pad_len, 3, 0);
4333 
4334 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4335 			"Failed to allocate input buffer in mempool");
4336 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4337 			"Failed to allocate output buffer in mempool");
4338 
4339 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4340 
4341 	/* Create SNOW 3G operation */
4342 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4343 					tdata->cipher_iv.len,
4344 					tdata->validCipherLenInBits.len,
4345 					0);
4346 	if (retval < 0)
4347 		return retval;
4348 
4349 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4350 						ut_params->op);
4351 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4352 
4353 	ut_params->obuf = ut_params->op->sym->m_dst;
4354 	if (ut_params->obuf)
4355 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4356 				plaintext_len, buffer);
4357 	else
4358 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4359 				plaintext_len, buffer);
4360 
4361 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4362 
4363 	/* Validate obuf */
4364 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4365 		ciphertext,
4366 		tdata->ciphertext.data,
4367 		tdata->validDataLenInBits.len,
4368 		"SNOW 3G Ciphertext data not as expected");
4369 
4370 	return 0;
4371 }
4372 
4373 /* Shift right a buffer by "offset" bits, "offset" < 8 */
4374 static void
4375 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
4376 {
4377 	uint8_t curr_byte, prev_byte;
4378 	uint32_t length_in_bytes = ceil_byte_length(length + offset);
4379 	uint8_t lower_byte_mask = (1 << offset) - 1;
4380 	unsigned i;
4381 
4382 	prev_byte = buffer[0];
4383 	buffer[0] >>= offset;
4384 
4385 	for (i = 1; i < length_in_bytes; i++) {
4386 		curr_byte = buffer[i];
4387 		buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
4388 				(curr_byte >> offset);
4389 		prev_byte = curr_byte;
4390 	}
4391 }
4392 
4393 static int
4394 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
4395 {
4396 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4397 	struct crypto_unittest_params *ut_params = &unittest_params;
4398 	uint8_t *plaintext, *ciphertext;
4399 	int retval;
4400 	uint32_t plaintext_len;
4401 	uint32_t plaintext_pad_len;
4402 	uint8_t extra_offset = 4;
4403 	uint8_t *expected_ciphertext_shifted;
4404 	struct rte_cryptodev_info dev_info;
4405 
4406 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4407 	uint64_t feat_flags = dev_info.feature_flags;
4408 
4409 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4410 			((tdata->validDataLenInBits.len % 8) != 0)) {
4411 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4412 		return TEST_SKIPPED;
4413 	}
4414 
4415 	/* Verify the capabilities */
4416 	struct rte_cryptodev_sym_capability_idx cap_idx;
4417 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4418 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4419 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4420 			&cap_idx) == NULL)
4421 		return TEST_SKIPPED;
4422 
4423 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4424 		return TEST_SKIPPED;
4425 
4426 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4427 		return TEST_SKIPPED;
4428 
4429 	/* Create SNOW 3G session */
4430 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4431 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4432 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4433 					tdata->key.data, tdata->key.len,
4434 					tdata->cipher_iv.len);
4435 	if (retval < 0)
4436 		return retval;
4437 
4438 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4439 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4440 
4441 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4442 			"Failed to allocate input buffer in mempool");
4443 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4444 			"Failed to allocate output buffer in mempool");
4445 
4446 	/* Clear mbuf payload */
4447 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4448 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4449 
4450 	plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4451 	/*
4452 	 * Append data which is padded to a
4453 	 * multiple of the algorithms block size
4454 	 */
4455 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4456 
4457 	plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4458 						plaintext_pad_len);
4459 
4460 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4461 
4462 	memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4463 	buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4464 
4465 #ifdef RTE_APP_TEST_DEBUG
4466 	rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4467 #endif
4468 	/* Create SNOW 3G operation */
4469 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4470 					tdata->cipher_iv.len,
4471 					tdata->validCipherLenInBits.len,
4472 					extra_offset);
4473 	if (retval < 0)
4474 		return retval;
4475 
4476 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4477 						ut_params->op);
4478 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4479 
4480 	ut_params->obuf = ut_params->op->sym->m_dst;
4481 	if (ut_params->obuf)
4482 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4483 	else
4484 		ciphertext = plaintext;
4485 
4486 #ifdef RTE_APP_TEST_DEBUG
4487 	rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4488 #endif
4489 
4490 	expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4491 
4492 	TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4493 			"failed to reserve memory for ciphertext shifted\n");
4494 
4495 	memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4496 			ceil_byte_length(tdata->ciphertext.len));
4497 	buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4498 			extra_offset);
4499 	/* Validate obuf */
4500 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4501 		ciphertext,
4502 		expected_ciphertext_shifted,
4503 		tdata->validDataLenInBits.len,
4504 		extra_offset,
4505 		"SNOW 3G Ciphertext data not as expected");
4506 	return 0;
4507 }
4508 
4509 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4510 {
4511 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4512 	struct crypto_unittest_params *ut_params = &unittest_params;
4513 
4514 	int retval;
4515 
4516 	uint8_t *plaintext, *ciphertext;
4517 	unsigned ciphertext_pad_len;
4518 	unsigned ciphertext_len;
4519 	struct rte_cryptodev_info dev_info;
4520 
4521 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4522 	uint64_t feat_flags = dev_info.feature_flags;
4523 
4524 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4525 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4526 		printf("Device doesn't support RAW data-path APIs.\n");
4527 		return TEST_SKIPPED;
4528 	}
4529 
4530 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4531 		return TEST_SKIPPED;
4532 
4533 	/* Verify the capabilities */
4534 	struct rte_cryptodev_sym_capability_idx cap_idx;
4535 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4536 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4537 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4538 			&cap_idx) == NULL)
4539 		return TEST_SKIPPED;
4540 
4541 	/* Create SNOW 3G session */
4542 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4543 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4544 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4545 					tdata->key.data, tdata->key.len,
4546 					tdata->cipher_iv.len);
4547 	if (retval < 0)
4548 		return retval;
4549 
4550 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4551 
4552 	/* Clear mbuf payload */
4553 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4554 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4555 
4556 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4557 	/* Append data which is padded to a multiple of */
4558 	/* the algorithms block size */
4559 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4560 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4561 				ciphertext_pad_len);
4562 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4563 
4564 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4565 
4566 	/* Create SNOW 3G operation */
4567 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4568 					tdata->cipher_iv.len,
4569 					tdata->validCipherLenInBits.len,
4570 					tdata->cipher.offset_bits);
4571 	if (retval < 0)
4572 		return retval;
4573 
4574 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4575 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4576 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4577 	else
4578 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4579 						ut_params->op);
4580 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4581 	ut_params->obuf = ut_params->op->sym->m_dst;
4582 	if (ut_params->obuf)
4583 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4584 	else
4585 		plaintext = ciphertext;
4586 
4587 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4588 
4589 	/* Validate obuf */
4590 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4591 				tdata->plaintext.data,
4592 				tdata->validDataLenInBits.len,
4593 				"SNOW 3G Plaintext data not as expected");
4594 	return 0;
4595 }
4596 
4597 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4598 {
4599 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4600 	struct crypto_unittest_params *ut_params = &unittest_params;
4601 
4602 	int retval;
4603 
4604 	uint8_t *plaintext, *ciphertext;
4605 	unsigned ciphertext_pad_len;
4606 	unsigned ciphertext_len;
4607 
4608 	/* Verify the capabilities */
4609 	struct rte_cryptodev_sym_capability_idx cap_idx;
4610 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4611 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4612 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4613 			&cap_idx) == NULL)
4614 		return TEST_SKIPPED;
4615 
4616 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4617 		return TEST_SKIPPED;
4618 
4619 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4620 		return TEST_SKIPPED;
4621 
4622 	/* Create SNOW 3G session */
4623 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4624 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4625 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4626 					tdata->key.data, tdata->key.len,
4627 					tdata->cipher_iv.len);
4628 	if (retval < 0)
4629 		return retval;
4630 
4631 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4632 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4633 
4634 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4635 			"Failed to allocate input buffer");
4636 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4637 			"Failed to allocate output buffer");
4638 
4639 	/* Clear mbuf payload */
4640 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4641 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4642 
4643 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4644 		       rte_pktmbuf_tailroom(ut_params->obuf));
4645 
4646 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4647 	/* Append data which is padded to a multiple of */
4648 	/* the algorithms block size */
4649 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4650 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4651 				ciphertext_pad_len);
4652 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4653 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4654 
4655 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4656 
4657 	/* Create SNOW 3G operation */
4658 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4659 					tdata->cipher_iv.len,
4660 					tdata->validCipherLenInBits.len,
4661 					0);
4662 	if (retval < 0)
4663 		return retval;
4664 
4665 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4666 						ut_params->op);
4667 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4668 	ut_params->obuf = ut_params->op->sym->m_dst;
4669 	if (ut_params->obuf)
4670 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4671 	else
4672 		plaintext = ciphertext;
4673 
4674 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4675 
4676 	/* Validate obuf */
4677 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4678 				tdata->plaintext.data,
4679 				tdata->validDataLenInBits.len,
4680 				"SNOW 3G Plaintext data not as expected");
4681 	return 0;
4682 }
4683 
4684 static int
4685 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4686 {
4687 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4688 	struct crypto_unittest_params *ut_params = &unittest_params;
4689 
4690 	int retval;
4691 
4692 	uint8_t *plaintext, *ciphertext;
4693 	unsigned int plaintext_pad_len;
4694 	unsigned int plaintext_len;
4695 
4696 	struct rte_cryptodev_info dev_info;
4697 	struct rte_cryptodev_sym_capability_idx cap_idx;
4698 
4699 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4700 	uint64_t feat_flags = dev_info.feature_flags;
4701 
4702 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4703 			((tdata->validAuthLenInBits.len % 8 != 0) ||
4704 			(tdata->validDataLenInBits.len % 8 != 0))) {
4705 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4706 		return TEST_SKIPPED;
4707 	}
4708 
4709 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4710 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4711 		printf("Device doesn't support RAW data-path APIs.\n");
4712 		return TEST_SKIPPED;
4713 	}
4714 
4715 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4716 		return TEST_SKIPPED;
4717 
4718 	/* Check if device supports ZUC EEA3 */
4719 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4720 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4721 
4722 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4723 			&cap_idx) == NULL)
4724 		return TEST_SKIPPED;
4725 
4726 	/* Check if device supports ZUC EIA3 */
4727 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4728 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4729 
4730 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4731 			&cap_idx) == NULL)
4732 		return TEST_SKIPPED;
4733 
4734 	/* Create ZUC session */
4735 	retval = create_zuc_cipher_auth_encrypt_generate_session(
4736 			ts_params->valid_devs[0],
4737 			tdata);
4738 	if (retval != 0)
4739 		return retval;
4740 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4741 
4742 	/* clear mbuf payload */
4743 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4744 			rte_pktmbuf_tailroom(ut_params->ibuf));
4745 
4746 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4747 	/* Append data which is padded to a multiple of */
4748 	/* the algorithms block size */
4749 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4750 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4751 				plaintext_pad_len);
4752 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4753 
4754 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4755 
4756 	/* Create ZUC operation */
4757 	retval = create_zuc_cipher_hash_generate_operation(tdata);
4758 	if (retval < 0)
4759 		return retval;
4760 
4761 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4762 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4763 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4764 	else
4765 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4766 			ut_params->op);
4767 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4768 	ut_params->obuf = ut_params->op->sym->m_src;
4769 	if (ut_params->obuf)
4770 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4771 	else
4772 		ciphertext = plaintext;
4773 
4774 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4775 	/* Validate obuf */
4776 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4777 			ciphertext,
4778 			tdata->ciphertext.data,
4779 			tdata->validDataLenInBits.len,
4780 			"ZUC Ciphertext data not as expected");
4781 
4782 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4783 	    + plaintext_pad_len;
4784 
4785 	/* Validate obuf */
4786 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4787 			ut_params->digest,
4788 			tdata->digest.data,
4789 			4,
4790 			"ZUC Generated auth tag not as expected");
4791 	return 0;
4792 }
4793 
4794 static int
4795 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4796 {
4797 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4798 	struct crypto_unittest_params *ut_params = &unittest_params;
4799 
4800 	int retval;
4801 
4802 	uint8_t *plaintext, *ciphertext;
4803 	unsigned plaintext_pad_len;
4804 	unsigned plaintext_len;
4805 	struct rte_cryptodev_info dev_info;
4806 
4807 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4808 	uint64_t feat_flags = dev_info.feature_flags;
4809 
4810 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4811 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4812 		printf("Device doesn't support RAW data-path APIs.\n");
4813 		return TEST_SKIPPED;
4814 	}
4815 
4816 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4817 		return TEST_SKIPPED;
4818 
4819 	/* Verify the capabilities */
4820 	struct rte_cryptodev_sym_capability_idx cap_idx;
4821 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4822 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4823 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4824 			&cap_idx) == NULL)
4825 		return TEST_SKIPPED;
4826 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4827 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4828 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4829 			&cap_idx) == NULL)
4830 		return TEST_SKIPPED;
4831 
4832 	/* Create SNOW 3G session */
4833 	retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4834 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4835 			RTE_CRYPTO_AUTH_OP_GENERATE,
4836 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4837 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4838 			tdata->key.data, tdata->key.len,
4839 			tdata->auth_iv.len, tdata->digest.len,
4840 			tdata->cipher_iv.len);
4841 	if (retval != 0)
4842 		return retval;
4843 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4844 
4845 	/* clear mbuf payload */
4846 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4847 			rte_pktmbuf_tailroom(ut_params->ibuf));
4848 
4849 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4850 	/* Append data which is padded to a multiple of */
4851 	/* the algorithms block size */
4852 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4853 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4854 				plaintext_pad_len);
4855 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4856 
4857 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4858 
4859 	/* Create SNOW 3G operation */
4860 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4861 			tdata->digest.len, tdata->auth_iv.data,
4862 			tdata->auth_iv.len,
4863 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4864 			tdata->cipher_iv.data, tdata->cipher_iv.len,
4865 			tdata->validCipherLenInBits.len,
4866 			0,
4867 			tdata->validAuthLenInBits.len,
4868 			0
4869 			);
4870 	if (retval < 0)
4871 		return retval;
4872 
4873 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4874 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4875 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4876 	else
4877 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4878 			ut_params->op);
4879 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4880 	ut_params->obuf = ut_params->op->sym->m_src;
4881 	if (ut_params->obuf)
4882 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4883 	else
4884 		ciphertext = plaintext;
4885 
4886 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4887 	/* Validate obuf */
4888 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4889 			ciphertext,
4890 			tdata->ciphertext.data,
4891 			tdata->validDataLenInBits.len,
4892 			"SNOW 3G Ciphertext data not as expected");
4893 
4894 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4895 	    + plaintext_pad_len;
4896 
4897 	/* Validate obuf */
4898 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4899 			ut_params->digest,
4900 			tdata->digest.data,
4901 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4902 			"SNOW 3G Generated auth tag not as expected");
4903 	return 0;
4904 }
4905 
4906 static int
4907 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
4908 	uint8_t op_mode, uint8_t verify)
4909 {
4910 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4911 	struct crypto_unittest_params *ut_params = &unittest_params;
4912 
4913 	int retval;
4914 
4915 	uint8_t *plaintext = NULL, *ciphertext = NULL;
4916 	unsigned int plaintext_pad_len;
4917 	unsigned int plaintext_len;
4918 	unsigned int ciphertext_pad_len;
4919 	unsigned int ciphertext_len;
4920 
4921 	struct rte_cryptodev_info dev_info;
4922 
4923 	/* Verify the capabilities */
4924 	struct rte_cryptodev_sym_capability_idx cap_idx;
4925 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4926 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4927 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4928 			&cap_idx) == NULL)
4929 		return TEST_SKIPPED;
4930 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4931 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4932 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4933 			&cap_idx) == NULL)
4934 		return TEST_SKIPPED;
4935 
4936 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4937 		return TEST_SKIPPED;
4938 
4939 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4940 
4941 	uint64_t feat_flags = dev_info.feature_flags;
4942 
4943 	if (op_mode == OUT_OF_PLACE) {
4944 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4945 			printf("Device doesn't support digest encrypted.\n");
4946 			return TEST_SKIPPED;
4947 		}
4948 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4949 			return TEST_SKIPPED;
4950 	}
4951 
4952 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4953 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4954 		printf("Device doesn't support RAW data-path APIs.\n");
4955 		return TEST_SKIPPED;
4956 	}
4957 
4958 	/* Create SNOW 3G session */
4959 	retval = create_wireless_algo_auth_cipher_session(
4960 			ts_params->valid_devs[0],
4961 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4962 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4963 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4964 					: RTE_CRYPTO_AUTH_OP_GENERATE),
4965 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4966 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4967 			tdata->key.data, tdata->key.len,
4968 			tdata->auth_iv.len, tdata->digest.len,
4969 			tdata->cipher_iv.len);
4970 	if (retval != 0)
4971 		return retval;
4972 
4973 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4974 	if (op_mode == OUT_OF_PLACE)
4975 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4976 
4977 	/* clear mbuf payload */
4978 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4979 		rte_pktmbuf_tailroom(ut_params->ibuf));
4980 	if (op_mode == OUT_OF_PLACE)
4981 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4982 			rte_pktmbuf_tailroom(ut_params->obuf));
4983 
4984 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4985 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4986 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4987 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4988 
4989 	if (verify) {
4990 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4991 					ciphertext_pad_len);
4992 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4993 		if (op_mode == OUT_OF_PLACE)
4994 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4995 		debug_hexdump(stdout, "ciphertext:", ciphertext,
4996 			ciphertext_len);
4997 	} else {
4998 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4999 					plaintext_pad_len);
5000 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5001 		if (op_mode == OUT_OF_PLACE)
5002 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5003 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5004 	}
5005 
5006 	/* Create SNOW 3G operation */
5007 	retval = create_wireless_algo_auth_cipher_operation(
5008 		tdata->digest.data, tdata->digest.len,
5009 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5010 		tdata->auth_iv.data, tdata->auth_iv.len,
5011 		(tdata->digest.offset_bytes == 0 ?
5012 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5013 			: tdata->digest.offset_bytes),
5014 		tdata->validCipherLenInBits.len,
5015 		tdata->cipher.offset_bits,
5016 		tdata->validAuthLenInBits.len,
5017 		tdata->auth.offset_bits,
5018 		op_mode, 0, verify);
5019 
5020 	if (retval < 0)
5021 		return retval;
5022 
5023 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5024 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5025 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5026 	else
5027 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5028 			ut_params->op);
5029 
5030 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5031 
5032 	ut_params->obuf = (op_mode == IN_PLACE ?
5033 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5034 
5035 	if (verify) {
5036 		if (ut_params->obuf)
5037 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5038 							uint8_t *);
5039 		else
5040 			plaintext = ciphertext +
5041 				(tdata->cipher.offset_bits >> 3);
5042 
5043 		debug_hexdump(stdout, "plaintext:", plaintext,
5044 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5045 		debug_hexdump(stdout, "plaintext expected:",
5046 			tdata->plaintext.data,
5047 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5048 	} else {
5049 		if (ut_params->obuf)
5050 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5051 							uint8_t *);
5052 		else
5053 			ciphertext = plaintext;
5054 
5055 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5056 			ciphertext_len);
5057 		debug_hexdump(stdout, "ciphertext expected:",
5058 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5059 
5060 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5061 			+ (tdata->digest.offset_bytes == 0 ?
5062 		plaintext_pad_len : tdata->digest.offset_bytes);
5063 
5064 		debug_hexdump(stdout, "digest:", ut_params->digest,
5065 			tdata->digest.len);
5066 		debug_hexdump(stdout, "digest expected:", tdata->digest.data,
5067 				tdata->digest.len);
5068 	}
5069 
5070 	/* Validate obuf */
5071 	if (verify) {
5072 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5073 			plaintext,
5074 			tdata->plaintext.data,
5075 			(tdata->plaintext.len - tdata->cipher.offset_bits -
5076 			 (tdata->digest.len << 3)),
5077 			tdata->cipher.offset_bits,
5078 			"SNOW 3G Plaintext data not as expected");
5079 	} else {
5080 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5081 			ciphertext,
5082 			tdata->ciphertext.data,
5083 			(tdata->validDataLenInBits.len -
5084 			 tdata->cipher.offset_bits),
5085 			tdata->cipher.offset_bits,
5086 			"SNOW 3G Ciphertext data not as expected");
5087 
5088 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5089 			ut_params->digest,
5090 			tdata->digest.data,
5091 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5092 			"SNOW 3G Generated auth tag not as expected");
5093 	}
5094 	return 0;
5095 }
5096 
5097 static int
5098 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
5099 	uint8_t op_mode, uint8_t verify)
5100 {
5101 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5102 	struct crypto_unittest_params *ut_params = &unittest_params;
5103 
5104 	int retval;
5105 
5106 	const uint8_t *plaintext = NULL;
5107 	const uint8_t *ciphertext = NULL;
5108 	const uint8_t *digest = NULL;
5109 	unsigned int plaintext_pad_len;
5110 	unsigned int plaintext_len;
5111 	unsigned int ciphertext_pad_len;
5112 	unsigned int ciphertext_len;
5113 	uint8_t buffer[10000];
5114 	uint8_t digest_buffer[10000];
5115 
5116 	struct rte_cryptodev_info dev_info;
5117 
5118 	/* Verify the capabilities */
5119 	struct rte_cryptodev_sym_capability_idx cap_idx;
5120 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5121 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5122 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5123 			&cap_idx) == NULL)
5124 		return TEST_SKIPPED;
5125 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5126 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5127 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5128 			&cap_idx) == NULL)
5129 		return TEST_SKIPPED;
5130 
5131 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5132 		return TEST_SKIPPED;
5133 
5134 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5135 
5136 	uint64_t feat_flags = dev_info.feature_flags;
5137 
5138 	if (op_mode == IN_PLACE) {
5139 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5140 			printf("Device doesn't support in-place scatter-gather "
5141 					"in both input and output mbufs.\n");
5142 			return TEST_SKIPPED;
5143 		}
5144 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5145 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5146 			printf("Device doesn't support RAW data-path APIs.\n");
5147 			return TEST_SKIPPED;
5148 		}
5149 	} else {
5150 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5151 			return TEST_SKIPPED;
5152 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5153 			printf("Device doesn't support out-of-place scatter-gather "
5154 					"in both input and output mbufs.\n");
5155 			return TEST_SKIPPED;
5156 		}
5157 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5158 			printf("Device doesn't support digest encrypted.\n");
5159 			return TEST_SKIPPED;
5160 		}
5161 	}
5162 
5163 	/* Create SNOW 3G session */
5164 	retval = create_wireless_algo_auth_cipher_session(
5165 			ts_params->valid_devs[0],
5166 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5167 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5168 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5169 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5170 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5171 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5172 			tdata->key.data, tdata->key.len,
5173 			tdata->auth_iv.len, tdata->digest.len,
5174 			tdata->cipher_iv.len);
5175 
5176 	if (retval != 0)
5177 		return retval;
5178 
5179 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5180 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5181 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5182 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5183 
5184 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5185 			plaintext_pad_len, 15, 0);
5186 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5187 			"Failed to allocate input buffer in mempool");
5188 
5189 	if (op_mode == OUT_OF_PLACE) {
5190 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5191 				plaintext_pad_len, 15, 0);
5192 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5193 				"Failed to allocate output buffer in mempool");
5194 	}
5195 
5196 	if (verify) {
5197 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5198 			tdata->ciphertext.data);
5199 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5200 					ciphertext_len, buffer);
5201 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5202 			ciphertext_len);
5203 	} else {
5204 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5205 			tdata->plaintext.data);
5206 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5207 					plaintext_len, buffer);
5208 		debug_hexdump(stdout, "plaintext:", plaintext,
5209 			plaintext_len);
5210 	}
5211 	memset(buffer, 0, sizeof(buffer));
5212 
5213 	/* Create SNOW 3G operation */
5214 	retval = create_wireless_algo_auth_cipher_operation(
5215 		tdata->digest.data, tdata->digest.len,
5216 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5217 		tdata->auth_iv.data, tdata->auth_iv.len,
5218 		(tdata->digest.offset_bytes == 0 ?
5219 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5220 			: tdata->digest.offset_bytes),
5221 		tdata->validCipherLenInBits.len,
5222 		tdata->cipher.offset_bits,
5223 		tdata->validAuthLenInBits.len,
5224 		tdata->auth.offset_bits,
5225 		op_mode, 1, verify);
5226 
5227 	if (retval < 0)
5228 		return retval;
5229 
5230 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5231 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5232 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5233 	else
5234 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5235 			ut_params->op);
5236 
5237 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5238 
5239 	ut_params->obuf = (op_mode == IN_PLACE ?
5240 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5241 
5242 	if (verify) {
5243 		if (ut_params->obuf)
5244 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5245 					plaintext_len, buffer);
5246 		else
5247 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5248 					plaintext_len, buffer);
5249 
5250 		debug_hexdump(stdout, "plaintext:", plaintext,
5251 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5252 		debug_hexdump(stdout, "plaintext expected:",
5253 			tdata->plaintext.data,
5254 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5255 	} else {
5256 		if (ut_params->obuf)
5257 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5258 					ciphertext_len, buffer);
5259 		else
5260 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5261 					ciphertext_len, buffer);
5262 
5263 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5264 			ciphertext_len);
5265 		debug_hexdump(stdout, "ciphertext expected:",
5266 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5267 
5268 		if (ut_params->obuf)
5269 			digest = rte_pktmbuf_read(ut_params->obuf,
5270 				(tdata->digest.offset_bytes == 0 ?
5271 				plaintext_pad_len : tdata->digest.offset_bytes),
5272 				tdata->digest.len, digest_buffer);
5273 		else
5274 			digest = rte_pktmbuf_read(ut_params->ibuf,
5275 				(tdata->digest.offset_bytes == 0 ?
5276 				plaintext_pad_len : tdata->digest.offset_bytes),
5277 				tdata->digest.len, digest_buffer);
5278 
5279 		debug_hexdump(stdout, "digest:", digest,
5280 			tdata->digest.len);
5281 		debug_hexdump(stdout, "digest expected:",
5282 			tdata->digest.data, tdata->digest.len);
5283 	}
5284 
5285 	/* Validate obuf */
5286 	if (verify) {
5287 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5288 			plaintext,
5289 			tdata->plaintext.data,
5290 			(tdata->plaintext.len - tdata->cipher.offset_bits -
5291 			 (tdata->digest.len << 3)),
5292 			tdata->cipher.offset_bits,
5293 			"SNOW 3G Plaintext data not as expected");
5294 	} else {
5295 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5296 			ciphertext,
5297 			tdata->ciphertext.data,
5298 			(tdata->validDataLenInBits.len -
5299 			 tdata->cipher.offset_bits),
5300 			tdata->cipher.offset_bits,
5301 			"SNOW 3G Ciphertext data not as expected");
5302 
5303 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5304 			digest,
5305 			tdata->digest.data,
5306 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5307 			"SNOW 3G Generated auth tag not as expected");
5308 	}
5309 	return 0;
5310 }
5311 
5312 static int
5313 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
5314 	uint8_t op_mode, uint8_t verify)
5315 {
5316 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5317 	struct crypto_unittest_params *ut_params = &unittest_params;
5318 
5319 	int retval;
5320 
5321 	uint8_t *plaintext = NULL, *ciphertext = NULL;
5322 	unsigned int plaintext_pad_len;
5323 	unsigned int plaintext_len;
5324 	unsigned int ciphertext_pad_len;
5325 	unsigned int ciphertext_len;
5326 
5327 	struct rte_cryptodev_info dev_info;
5328 
5329 	/* Verify the capabilities */
5330 	struct rte_cryptodev_sym_capability_idx cap_idx;
5331 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5332 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5333 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5334 			&cap_idx) == NULL)
5335 		return TEST_SKIPPED;
5336 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5337 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5338 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5339 			&cap_idx) == NULL)
5340 		return TEST_SKIPPED;
5341 
5342 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5343 
5344 	uint64_t feat_flags = dev_info.feature_flags;
5345 
5346 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5347 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5348 		printf("Device doesn't support RAW data-path APIs.\n");
5349 		return TEST_SKIPPED;
5350 	}
5351 
5352 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5353 		return TEST_SKIPPED;
5354 
5355 	if (op_mode == OUT_OF_PLACE) {
5356 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5357 			return TEST_SKIPPED;
5358 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5359 			printf("Device doesn't support digest encrypted.\n");
5360 			return TEST_SKIPPED;
5361 		}
5362 	}
5363 
5364 	/* Create KASUMI session */
5365 	retval = create_wireless_algo_auth_cipher_session(
5366 			ts_params->valid_devs[0],
5367 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5368 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5369 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5370 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5371 			RTE_CRYPTO_AUTH_KASUMI_F9,
5372 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5373 			tdata->key.data, tdata->key.len,
5374 			0, tdata->digest.len,
5375 			tdata->cipher_iv.len);
5376 
5377 	if (retval != 0)
5378 		return retval;
5379 
5380 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5381 	if (op_mode == OUT_OF_PLACE)
5382 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5383 
5384 	/* clear mbuf payload */
5385 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5386 		rte_pktmbuf_tailroom(ut_params->ibuf));
5387 	if (op_mode == OUT_OF_PLACE)
5388 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5389 			rte_pktmbuf_tailroom(ut_params->obuf));
5390 
5391 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5392 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5393 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5394 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5395 
5396 	if (verify) {
5397 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5398 					ciphertext_pad_len);
5399 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5400 		if (op_mode == OUT_OF_PLACE)
5401 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5402 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5403 			ciphertext_len);
5404 	} else {
5405 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5406 					plaintext_pad_len);
5407 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5408 		if (op_mode == OUT_OF_PLACE)
5409 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5410 		debug_hexdump(stdout, "plaintext:", plaintext,
5411 			plaintext_len);
5412 	}
5413 
5414 	/* Create KASUMI operation */
5415 	retval = create_wireless_algo_auth_cipher_operation(
5416 		tdata->digest.data, tdata->digest.len,
5417 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5418 		NULL, 0,
5419 		(tdata->digest.offset_bytes == 0 ?
5420 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5421 			: tdata->digest.offset_bytes),
5422 		tdata->validCipherLenInBits.len,
5423 		tdata->validCipherOffsetInBits.len,
5424 		tdata->validAuthLenInBits.len,
5425 		0,
5426 		op_mode, 0, verify);
5427 
5428 	if (retval < 0)
5429 		return retval;
5430 
5431 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5432 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5433 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5434 	else
5435 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5436 			ut_params->op);
5437 
5438 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5439 
5440 	ut_params->obuf = (op_mode == IN_PLACE ?
5441 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5442 
5443 
5444 	if (verify) {
5445 		if (ut_params->obuf)
5446 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5447 							uint8_t *);
5448 		else
5449 			plaintext = ciphertext;
5450 
5451 		debug_hexdump(stdout, "plaintext:", plaintext,
5452 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5453 		debug_hexdump(stdout, "plaintext expected:",
5454 			tdata->plaintext.data,
5455 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5456 	} else {
5457 		if (ut_params->obuf)
5458 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5459 							uint8_t *);
5460 		else
5461 			ciphertext = plaintext;
5462 
5463 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5464 			ciphertext_len);
5465 		debug_hexdump(stdout, "ciphertext expected:",
5466 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5467 
5468 		ut_params->digest = rte_pktmbuf_mtod(
5469 			ut_params->obuf, uint8_t *) +
5470 			(tdata->digest.offset_bytes == 0 ?
5471 			plaintext_pad_len : tdata->digest.offset_bytes);
5472 
5473 		debug_hexdump(stdout, "digest:", ut_params->digest,
5474 			tdata->digest.len);
5475 		debug_hexdump(stdout, "digest expected:",
5476 			tdata->digest.data, tdata->digest.len);
5477 	}
5478 
5479 	/* Validate obuf */
5480 	if (verify) {
5481 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5482 			plaintext,
5483 			tdata->plaintext.data,
5484 			tdata->plaintext.len >> 3,
5485 			"KASUMI Plaintext data not as expected");
5486 	} else {
5487 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5488 			ciphertext,
5489 			tdata->ciphertext.data,
5490 			tdata->ciphertext.len >> 3,
5491 			"KASUMI Ciphertext data not as expected");
5492 
5493 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5494 			ut_params->digest,
5495 			tdata->digest.data,
5496 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5497 			"KASUMI Generated auth tag not as expected");
5498 	}
5499 	return 0;
5500 }
5501 
5502 static int
5503 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5504 	uint8_t op_mode, uint8_t verify)
5505 {
5506 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5507 	struct crypto_unittest_params *ut_params = &unittest_params;
5508 
5509 	int retval;
5510 
5511 	const uint8_t *plaintext = NULL;
5512 	const uint8_t *ciphertext = NULL;
5513 	const uint8_t *digest = NULL;
5514 	unsigned int plaintext_pad_len;
5515 	unsigned int plaintext_len;
5516 	unsigned int ciphertext_pad_len;
5517 	unsigned int ciphertext_len;
5518 	uint8_t buffer[10000];
5519 	uint8_t digest_buffer[10000];
5520 
5521 	struct rte_cryptodev_info dev_info;
5522 
5523 	/* Verify the capabilities */
5524 	struct rte_cryptodev_sym_capability_idx cap_idx;
5525 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5526 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5527 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5528 			&cap_idx) == NULL)
5529 		return TEST_SKIPPED;
5530 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5531 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5532 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5533 			&cap_idx) == NULL)
5534 		return TEST_SKIPPED;
5535 
5536 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5537 		return TEST_SKIPPED;
5538 
5539 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5540 
5541 	uint64_t feat_flags = dev_info.feature_flags;
5542 
5543 	if (op_mode == IN_PLACE) {
5544 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5545 			printf("Device doesn't support in-place scatter-gather "
5546 					"in both input and output mbufs.\n");
5547 			return TEST_SKIPPED;
5548 		}
5549 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5550 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5551 			printf("Device doesn't support RAW data-path APIs.\n");
5552 			return TEST_SKIPPED;
5553 		}
5554 	} else {
5555 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5556 			return TEST_SKIPPED;
5557 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5558 			printf("Device doesn't support out-of-place scatter-gather "
5559 					"in both input and output mbufs.\n");
5560 			return TEST_SKIPPED;
5561 		}
5562 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5563 			printf("Device doesn't support digest encrypted.\n");
5564 			return TEST_SKIPPED;
5565 		}
5566 	}
5567 
5568 	/* Create KASUMI session */
5569 	retval = create_wireless_algo_auth_cipher_session(
5570 			ts_params->valid_devs[0],
5571 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5572 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5573 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5574 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5575 			RTE_CRYPTO_AUTH_KASUMI_F9,
5576 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5577 			tdata->key.data, tdata->key.len,
5578 			0, tdata->digest.len,
5579 			tdata->cipher_iv.len);
5580 
5581 	if (retval != 0)
5582 		return retval;
5583 
5584 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5585 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5586 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5587 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5588 
5589 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5590 			plaintext_pad_len, 15, 0);
5591 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5592 			"Failed to allocate input buffer in mempool");
5593 
5594 	if (op_mode == OUT_OF_PLACE) {
5595 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5596 				plaintext_pad_len, 15, 0);
5597 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5598 				"Failed to allocate output buffer in mempool");
5599 	}
5600 
5601 	if (verify) {
5602 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5603 			tdata->ciphertext.data);
5604 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5605 					ciphertext_len, buffer);
5606 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5607 			ciphertext_len);
5608 	} else {
5609 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5610 			tdata->plaintext.data);
5611 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5612 					plaintext_len, buffer);
5613 		debug_hexdump(stdout, "plaintext:", plaintext,
5614 			plaintext_len);
5615 	}
5616 	memset(buffer, 0, sizeof(buffer));
5617 
5618 	/* Create KASUMI operation */
5619 	retval = create_wireless_algo_auth_cipher_operation(
5620 		tdata->digest.data, tdata->digest.len,
5621 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5622 		NULL, 0,
5623 		(tdata->digest.offset_bytes == 0 ?
5624 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5625 			: tdata->digest.offset_bytes),
5626 		tdata->validCipherLenInBits.len,
5627 		tdata->validCipherOffsetInBits.len,
5628 		tdata->validAuthLenInBits.len,
5629 		0,
5630 		op_mode, 1, verify);
5631 
5632 	if (retval < 0)
5633 		return retval;
5634 
5635 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5636 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5637 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5638 	else
5639 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5640 			ut_params->op);
5641 
5642 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5643 
5644 	ut_params->obuf = (op_mode == IN_PLACE ?
5645 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5646 
5647 	if (verify) {
5648 		if (ut_params->obuf)
5649 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5650 					plaintext_len, buffer);
5651 		else
5652 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5653 					plaintext_len, buffer);
5654 
5655 		debug_hexdump(stdout, "plaintext:", plaintext,
5656 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5657 		debug_hexdump(stdout, "plaintext expected:",
5658 			tdata->plaintext.data,
5659 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5660 	} else {
5661 		if (ut_params->obuf)
5662 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5663 					ciphertext_len, buffer);
5664 		else
5665 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5666 					ciphertext_len, buffer);
5667 
5668 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5669 			ciphertext_len);
5670 		debug_hexdump(stdout, "ciphertext expected:",
5671 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5672 
5673 		if (ut_params->obuf)
5674 			digest = rte_pktmbuf_read(ut_params->obuf,
5675 				(tdata->digest.offset_bytes == 0 ?
5676 				plaintext_pad_len : tdata->digest.offset_bytes),
5677 				tdata->digest.len, digest_buffer);
5678 		else
5679 			digest = rte_pktmbuf_read(ut_params->ibuf,
5680 				(tdata->digest.offset_bytes == 0 ?
5681 				plaintext_pad_len : tdata->digest.offset_bytes),
5682 				tdata->digest.len, digest_buffer);
5683 
5684 		debug_hexdump(stdout, "digest:", digest,
5685 			tdata->digest.len);
5686 		debug_hexdump(stdout, "digest expected:",
5687 			tdata->digest.data, tdata->digest.len);
5688 	}
5689 
5690 	/* Validate obuf */
5691 	if (verify) {
5692 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5693 			plaintext,
5694 			tdata->plaintext.data,
5695 			tdata->plaintext.len >> 3,
5696 			"KASUMI Plaintext data not as expected");
5697 	} else {
5698 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5699 			ciphertext,
5700 			tdata->ciphertext.data,
5701 			tdata->validDataLenInBits.len,
5702 			"KASUMI Ciphertext data not as expected");
5703 
5704 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5705 			digest,
5706 			tdata->digest.data,
5707 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5708 			"KASUMI Generated auth tag not as expected");
5709 	}
5710 	return 0;
5711 }
5712 
5713 static int
5714 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5715 {
5716 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5717 	struct crypto_unittest_params *ut_params = &unittest_params;
5718 
5719 	int retval;
5720 
5721 	uint8_t *plaintext, *ciphertext;
5722 	unsigned plaintext_pad_len;
5723 	unsigned plaintext_len;
5724 	struct rte_cryptodev_info dev_info;
5725 
5726 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5727 	uint64_t feat_flags = dev_info.feature_flags;
5728 
5729 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5730 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5731 		printf("Device doesn't support RAW data-path APIs.\n");
5732 		return TEST_SKIPPED;
5733 	}
5734 
5735 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5736 		return TEST_SKIPPED;
5737 
5738 	/* Verify the capabilities */
5739 	struct rte_cryptodev_sym_capability_idx cap_idx;
5740 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5741 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5742 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5743 			&cap_idx) == NULL)
5744 		return TEST_SKIPPED;
5745 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5746 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5747 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5748 			&cap_idx) == NULL)
5749 		return TEST_SKIPPED;
5750 
5751 	/* Create KASUMI session */
5752 	retval = create_wireless_algo_cipher_auth_session(
5753 			ts_params->valid_devs[0],
5754 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5755 			RTE_CRYPTO_AUTH_OP_GENERATE,
5756 			RTE_CRYPTO_AUTH_KASUMI_F9,
5757 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5758 			tdata->key.data, tdata->key.len,
5759 			0, tdata->digest.len,
5760 			tdata->cipher_iv.len);
5761 	if (retval != 0)
5762 		return retval;
5763 
5764 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5765 
5766 	/* clear mbuf payload */
5767 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5768 			rte_pktmbuf_tailroom(ut_params->ibuf));
5769 
5770 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5771 	/* Append data which is padded to a multiple of */
5772 	/* the algorithms block size */
5773 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5774 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5775 				plaintext_pad_len);
5776 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5777 
5778 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5779 
5780 	/* Create KASUMI operation */
5781 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5782 				tdata->digest.len, NULL, 0,
5783 				plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5784 				tdata->cipher_iv.data, tdata->cipher_iv.len,
5785 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5786 				tdata->validCipherOffsetInBits.len,
5787 				tdata->validAuthLenInBits.len,
5788 				0
5789 				);
5790 	if (retval < 0)
5791 		return retval;
5792 
5793 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5794 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5795 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5796 	else
5797 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5798 			ut_params->op);
5799 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5800 
5801 	if (ut_params->op->sym->m_dst)
5802 		ut_params->obuf = ut_params->op->sym->m_dst;
5803 	else
5804 		ut_params->obuf = ut_params->op->sym->m_src;
5805 
5806 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5807 				tdata->validCipherOffsetInBits.len >> 3);
5808 
5809 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5810 			+ plaintext_pad_len;
5811 
5812 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5813 				(tdata->validCipherOffsetInBits.len >> 3);
5814 	/* Validate obuf */
5815 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5816 		ciphertext,
5817 		reference_ciphertext,
5818 		tdata->validCipherLenInBits.len,
5819 		"KASUMI Ciphertext data not as expected");
5820 
5821 	/* Validate obuf */
5822 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
5823 		ut_params->digest,
5824 		tdata->digest.data,
5825 		DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5826 		"KASUMI Generated auth tag not as expected");
5827 	return 0;
5828 }
5829 
5830 static int
5831 test_zuc_encryption(const struct wireless_test_data *tdata)
5832 {
5833 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5834 	struct crypto_unittest_params *ut_params = &unittest_params;
5835 
5836 	int retval;
5837 	uint8_t *plaintext, *ciphertext;
5838 	unsigned plaintext_pad_len;
5839 	unsigned plaintext_len;
5840 	struct rte_cryptodev_info dev_info;
5841 
5842 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5843 	uint64_t feat_flags = dev_info.feature_flags;
5844 
5845 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5846 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5847 		printf("Device doesn't support RAW data-path APIs.\n");
5848 		return TEST_SKIPPED;
5849 	}
5850 
5851 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5852 		return TEST_SKIPPED;
5853 
5854 	struct rte_cryptodev_sym_capability_idx cap_idx;
5855 
5856 	/* Check if device supports ZUC EEA3 */
5857 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5858 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5859 
5860 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5861 			&cap_idx) == NULL)
5862 		return TEST_SKIPPED;
5863 
5864 	/* Create ZUC session */
5865 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5866 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5867 					RTE_CRYPTO_CIPHER_ZUC_EEA3,
5868 					tdata->key.data, tdata->key.len,
5869 					tdata->cipher_iv.len);
5870 	if (retval != 0)
5871 		return retval;
5872 
5873 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5874 
5875 	/* Clear mbuf payload */
5876 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5877 	       rte_pktmbuf_tailroom(ut_params->ibuf));
5878 
5879 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5880 	/* Append data which is padded to a multiple */
5881 	/* of the algorithms block size */
5882 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5883 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5884 				plaintext_pad_len);
5885 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5886 
5887 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5888 
5889 	/* Create ZUC operation */
5890 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5891 					tdata->cipher_iv.len,
5892 					tdata->plaintext.len,
5893 					0);
5894 	if (retval < 0)
5895 		return retval;
5896 
5897 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5898 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5899 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5900 	else
5901 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5902 						ut_params->op);
5903 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5904 
5905 	ut_params->obuf = ut_params->op->sym->m_dst;
5906 	if (ut_params->obuf)
5907 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5908 	else
5909 		ciphertext = plaintext;
5910 
5911 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5912 
5913 	/* Validate obuf */
5914 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5915 		ciphertext,
5916 		tdata->ciphertext.data,
5917 		tdata->validCipherLenInBits.len,
5918 		"ZUC Ciphertext data not as expected");
5919 	return 0;
5920 }
5921 
5922 static int
5923 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
5924 {
5925 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5926 	struct crypto_unittest_params *ut_params = &unittest_params;
5927 
5928 	int retval;
5929 
5930 	unsigned int plaintext_pad_len;
5931 	unsigned int plaintext_len;
5932 	const uint8_t *ciphertext;
5933 	uint8_t ciphertext_buffer[2048];
5934 	struct rte_cryptodev_info dev_info;
5935 
5936 	struct rte_cryptodev_sym_capability_idx cap_idx;
5937 
5938 	/* Check if device supports ZUC EEA3 */
5939 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5940 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5941 
5942 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5943 			&cap_idx) == NULL)
5944 		return TEST_SKIPPED;
5945 
5946 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5947 		return TEST_SKIPPED;
5948 
5949 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5950 
5951 	uint64_t feat_flags = dev_info.feature_flags;
5952 
5953 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5954 		printf("Device doesn't support in-place scatter-gather. "
5955 				"Test Skipped.\n");
5956 		return TEST_SKIPPED;
5957 	}
5958 
5959 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5960 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5961 		printf("Device doesn't support RAW data-path APIs.\n");
5962 		return TEST_SKIPPED;
5963 	}
5964 
5965 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5966 
5967 	/* Append data which is padded to a multiple */
5968 	/* of the algorithms block size */
5969 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5970 
5971 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5972 			plaintext_pad_len, 10, 0);
5973 
5974 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5975 			tdata->plaintext.data);
5976 
5977 	/* Create ZUC session */
5978 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5979 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5980 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
5981 			tdata->key.data, tdata->key.len,
5982 			tdata->cipher_iv.len);
5983 	if (retval < 0)
5984 		return retval;
5985 
5986 	/* Clear mbuf payload */
5987 
5988 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
5989 
5990 	/* Create ZUC operation */
5991 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5992 			tdata->cipher_iv.len, tdata->plaintext.len,
5993 			0);
5994 	if (retval < 0)
5995 		return retval;
5996 
5997 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5998 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5999 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
6000 	else
6001 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6002 						ut_params->op);
6003 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6004 
6005 	ut_params->obuf = ut_params->op->sym->m_dst;
6006 	if (ut_params->obuf)
6007 		ciphertext = rte_pktmbuf_read(ut_params->obuf,
6008 			0, plaintext_len, ciphertext_buffer);
6009 	else
6010 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
6011 			0, plaintext_len, ciphertext_buffer);
6012 
6013 	/* Validate obuf */
6014 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6015 
6016 	/* Validate obuf */
6017 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6018 		ciphertext,
6019 		tdata->ciphertext.data,
6020 		tdata->validCipherLenInBits.len,
6021 		"ZUC Ciphertext data not as expected");
6022 
6023 	return 0;
6024 }
6025 
6026 static int
6027 test_zuc_authentication(const struct wireless_test_data *tdata)
6028 {
6029 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6030 	struct crypto_unittest_params *ut_params = &unittest_params;
6031 
6032 	int retval;
6033 	unsigned plaintext_pad_len;
6034 	unsigned plaintext_len;
6035 	uint8_t *plaintext;
6036 
6037 	struct rte_cryptodev_sym_capability_idx cap_idx;
6038 	struct rte_cryptodev_info dev_info;
6039 
6040 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6041 	uint64_t feat_flags = dev_info.feature_flags;
6042 
6043 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
6044 			(tdata->validAuthLenInBits.len % 8 != 0)) {
6045 		printf("Device doesn't support NON-Byte Aligned Data.\n");
6046 		return TEST_SKIPPED;
6047 	}
6048 
6049 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6050 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6051 		printf("Device doesn't support RAW data-path APIs.\n");
6052 		return TEST_SKIPPED;
6053 	}
6054 
6055 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6056 		return TEST_SKIPPED;
6057 
6058 	/* Check if device supports ZUC EIA3 */
6059 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6060 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6061 
6062 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6063 			&cap_idx) == NULL)
6064 		return TEST_SKIPPED;
6065 
6066 	/* Create ZUC session */
6067 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
6068 			tdata->key.data, tdata->key.len,
6069 			tdata->auth_iv.len, tdata->digest.len,
6070 			RTE_CRYPTO_AUTH_OP_GENERATE,
6071 			RTE_CRYPTO_AUTH_ZUC_EIA3);
6072 	if (retval != 0)
6073 		return retval;
6074 
6075 	/* alloc mbuf and set payload */
6076 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6077 
6078 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6079 	rte_pktmbuf_tailroom(ut_params->ibuf));
6080 
6081 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6082 	/* Append data which is padded to a multiple of */
6083 	/* the algorithms block size */
6084 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6085 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6086 				plaintext_pad_len);
6087 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6088 
6089 	/* Create ZUC operation */
6090 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
6091 			tdata->auth_iv.data, tdata->auth_iv.len,
6092 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
6093 			tdata->validAuthLenInBits.len,
6094 			0);
6095 	if (retval < 0)
6096 		return retval;
6097 
6098 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6099 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6100 				ut_params->op, 0, 1, 1, 0);
6101 	else
6102 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6103 				ut_params->op);
6104 	ut_params->obuf = ut_params->op->sym->m_src;
6105 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6106 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6107 			+ plaintext_pad_len;
6108 
6109 	/* Validate obuf */
6110 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
6111 	ut_params->digest,
6112 	tdata->digest.data,
6113 	tdata->digest.len,
6114 	"ZUC Generated auth tag not as expected");
6115 
6116 	return 0;
6117 }
6118 
6119 static int
6120 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
6121 	uint8_t op_mode, uint8_t verify)
6122 {
6123 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6124 	struct crypto_unittest_params *ut_params = &unittest_params;
6125 
6126 	int retval;
6127 
6128 	uint8_t *plaintext = NULL, *ciphertext = NULL;
6129 	unsigned int plaintext_pad_len;
6130 	unsigned int plaintext_len;
6131 	unsigned int ciphertext_pad_len;
6132 	unsigned int ciphertext_len;
6133 
6134 	struct rte_cryptodev_info dev_info;
6135 	struct rte_cryptodev_sym_capability_idx cap_idx;
6136 
6137 	/* Check if device supports ZUC EIA3 */
6138 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6139 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6140 
6141 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6142 			&cap_idx) == NULL)
6143 		return TEST_SKIPPED;
6144 
6145 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6146 
6147 	uint64_t feat_flags = dev_info.feature_flags;
6148 
6149 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6150 		printf("Device doesn't support digest encrypted.\n");
6151 		return TEST_SKIPPED;
6152 	}
6153 	if (op_mode == IN_PLACE) {
6154 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6155 			printf("Device doesn't support in-place scatter-gather "
6156 					"in both input and output mbufs.\n");
6157 			return TEST_SKIPPED;
6158 		}
6159 
6160 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6161 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6162 			printf("Device doesn't support RAW data-path APIs.\n");
6163 			return TEST_SKIPPED;
6164 		}
6165 	} else {
6166 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6167 			return TEST_SKIPPED;
6168 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6169 			printf("Device doesn't support out-of-place scatter-gather "
6170 					"in both input and output mbufs.\n");
6171 			return TEST_SKIPPED;
6172 		}
6173 	}
6174 
6175 	/* Create ZUC session */
6176 	retval = create_wireless_algo_auth_cipher_session(
6177 			ts_params->valid_devs[0],
6178 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6179 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6180 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6181 					: RTE_CRYPTO_AUTH_OP_GENERATE),
6182 			RTE_CRYPTO_AUTH_ZUC_EIA3,
6183 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6184 			tdata->key.data, tdata->key.len,
6185 			tdata->auth_iv.len, tdata->digest.len,
6186 			tdata->cipher_iv.len);
6187 
6188 	if (retval != 0)
6189 		return retval;
6190 
6191 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6192 	if (op_mode == OUT_OF_PLACE)
6193 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6194 
6195 	/* clear mbuf payload */
6196 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6197 		rte_pktmbuf_tailroom(ut_params->ibuf));
6198 	if (op_mode == OUT_OF_PLACE)
6199 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6200 			rte_pktmbuf_tailroom(ut_params->obuf));
6201 
6202 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6203 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6204 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6205 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6206 
6207 	if (verify) {
6208 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6209 					ciphertext_pad_len);
6210 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6211 		if (op_mode == OUT_OF_PLACE)
6212 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6213 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6214 			ciphertext_len);
6215 	} else {
6216 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6217 					plaintext_pad_len);
6218 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6219 		if (op_mode == OUT_OF_PLACE)
6220 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
6221 		debug_hexdump(stdout, "plaintext:", plaintext,
6222 			plaintext_len);
6223 	}
6224 
6225 	/* Create ZUC operation */
6226 	retval = create_wireless_algo_auth_cipher_operation(
6227 		tdata->digest.data, tdata->digest.len,
6228 		tdata->cipher_iv.data, tdata->cipher_iv.len,
6229 		tdata->auth_iv.data, tdata->auth_iv.len,
6230 		(tdata->digest.offset_bytes == 0 ?
6231 		(verify ? ciphertext_pad_len : plaintext_pad_len)
6232 			: tdata->digest.offset_bytes),
6233 		tdata->validCipherLenInBits.len,
6234 		tdata->validCipherOffsetInBits.len,
6235 		tdata->validAuthLenInBits.len,
6236 		0,
6237 		op_mode, 0, verify);
6238 
6239 	if (retval < 0)
6240 		return retval;
6241 
6242 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6243 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6244 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6245 	else
6246 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6247 			ut_params->op);
6248 
6249 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6250 
6251 	ut_params->obuf = (op_mode == IN_PLACE ?
6252 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6253 
6254 
6255 	if (verify) {
6256 		if (ut_params->obuf)
6257 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6258 							uint8_t *);
6259 		else
6260 			plaintext = ciphertext;
6261 
6262 		debug_hexdump(stdout, "plaintext:", plaintext,
6263 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6264 		debug_hexdump(stdout, "plaintext expected:",
6265 			tdata->plaintext.data,
6266 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6267 	} else {
6268 		if (ut_params->obuf)
6269 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6270 							uint8_t *);
6271 		else
6272 			ciphertext = plaintext;
6273 
6274 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6275 			ciphertext_len);
6276 		debug_hexdump(stdout, "ciphertext expected:",
6277 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6278 
6279 		ut_params->digest = rte_pktmbuf_mtod(
6280 			ut_params->obuf, uint8_t *) +
6281 			(tdata->digest.offset_bytes == 0 ?
6282 			plaintext_pad_len : tdata->digest.offset_bytes);
6283 
6284 		debug_hexdump(stdout, "digest:", ut_params->digest,
6285 			tdata->digest.len);
6286 		debug_hexdump(stdout, "digest expected:",
6287 			tdata->digest.data, tdata->digest.len);
6288 	}
6289 
6290 	/* Validate obuf */
6291 	if (verify) {
6292 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6293 			plaintext,
6294 			tdata->plaintext.data,
6295 			tdata->plaintext.len >> 3,
6296 			"ZUC Plaintext data not as expected");
6297 	} else {
6298 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6299 			ciphertext,
6300 			tdata->ciphertext.data,
6301 			tdata->ciphertext.len >> 3,
6302 			"ZUC Ciphertext data not as expected");
6303 
6304 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6305 			ut_params->digest,
6306 			tdata->digest.data,
6307 			DIGEST_BYTE_LENGTH_KASUMI_F9,
6308 			"ZUC Generated auth tag not as expected");
6309 	}
6310 	return 0;
6311 }
6312 
6313 static int
6314 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
6315 	uint8_t op_mode, uint8_t verify)
6316 {
6317 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6318 	struct crypto_unittest_params *ut_params = &unittest_params;
6319 
6320 	int retval;
6321 
6322 	const uint8_t *plaintext = NULL;
6323 	const uint8_t *ciphertext = NULL;
6324 	const uint8_t *digest = NULL;
6325 	unsigned int plaintext_pad_len;
6326 	unsigned int plaintext_len;
6327 	unsigned int ciphertext_pad_len;
6328 	unsigned int ciphertext_len;
6329 	uint8_t buffer[10000];
6330 	uint8_t digest_buffer[10000];
6331 
6332 	struct rte_cryptodev_info dev_info;
6333 	struct rte_cryptodev_sym_capability_idx cap_idx;
6334 
6335 	/* Check if device supports ZUC EIA3 */
6336 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6337 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6338 
6339 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6340 			&cap_idx) == NULL)
6341 		return TEST_SKIPPED;
6342 
6343 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6344 
6345 	uint64_t feat_flags = dev_info.feature_flags;
6346 
6347 	if (op_mode == IN_PLACE) {
6348 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6349 			printf("Device doesn't support in-place scatter-gather "
6350 					"in both input and output mbufs.\n");
6351 			return TEST_SKIPPED;
6352 		}
6353 
6354 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6355 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6356 			printf("Device doesn't support RAW data-path APIs.\n");
6357 			return TEST_SKIPPED;
6358 		}
6359 	} else {
6360 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6361 			return TEST_SKIPPED;
6362 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6363 			printf("Device doesn't support out-of-place scatter-gather "
6364 					"in both input and output mbufs.\n");
6365 			return TEST_SKIPPED;
6366 		}
6367 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6368 			printf("Device doesn't support digest encrypted.\n");
6369 			return TEST_SKIPPED;
6370 		}
6371 	}
6372 
6373 	/* Create ZUC session */
6374 	retval = create_wireless_algo_auth_cipher_session(
6375 			ts_params->valid_devs[0],
6376 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6377 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6378 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6379 					: RTE_CRYPTO_AUTH_OP_GENERATE),
6380 			RTE_CRYPTO_AUTH_ZUC_EIA3,
6381 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6382 			tdata->key.data, tdata->key.len,
6383 			tdata->auth_iv.len, tdata->digest.len,
6384 			tdata->cipher_iv.len);
6385 
6386 	if (retval != 0)
6387 		return retval;
6388 
6389 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6390 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6391 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6392 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6393 
6394 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6395 			plaintext_pad_len, 15, 0);
6396 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6397 			"Failed to allocate input buffer in mempool");
6398 
6399 	if (op_mode == OUT_OF_PLACE) {
6400 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6401 				plaintext_pad_len, 15, 0);
6402 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
6403 				"Failed to allocate output buffer in mempool");
6404 	}
6405 
6406 	if (verify) {
6407 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6408 			tdata->ciphertext.data);
6409 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6410 					ciphertext_len, buffer);
6411 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6412 			ciphertext_len);
6413 	} else {
6414 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6415 			tdata->plaintext.data);
6416 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6417 					plaintext_len, buffer);
6418 		debug_hexdump(stdout, "plaintext:", plaintext,
6419 			plaintext_len);
6420 	}
6421 	memset(buffer, 0, sizeof(buffer));
6422 
6423 	/* Create ZUC operation */
6424 	retval = create_wireless_algo_auth_cipher_operation(
6425 		tdata->digest.data, tdata->digest.len,
6426 		tdata->cipher_iv.data, tdata->cipher_iv.len,
6427 		NULL, 0,
6428 		(tdata->digest.offset_bytes == 0 ?
6429 		(verify ? ciphertext_pad_len : plaintext_pad_len)
6430 			: tdata->digest.offset_bytes),
6431 		tdata->validCipherLenInBits.len,
6432 		tdata->validCipherOffsetInBits.len,
6433 		tdata->validAuthLenInBits.len,
6434 		0,
6435 		op_mode, 1, verify);
6436 
6437 	if (retval < 0)
6438 		return retval;
6439 
6440 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6441 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6442 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6443 	else
6444 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6445 			ut_params->op);
6446 
6447 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6448 
6449 	ut_params->obuf = (op_mode == IN_PLACE ?
6450 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6451 
6452 	if (verify) {
6453 		if (ut_params->obuf)
6454 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6455 					plaintext_len, buffer);
6456 		else
6457 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6458 					plaintext_len, buffer);
6459 
6460 		debug_hexdump(stdout, "plaintext:", plaintext,
6461 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6462 		debug_hexdump(stdout, "plaintext expected:",
6463 			tdata->plaintext.data,
6464 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6465 	} else {
6466 		if (ut_params->obuf)
6467 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6468 					ciphertext_len, buffer);
6469 		else
6470 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6471 					ciphertext_len, buffer);
6472 
6473 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6474 			ciphertext_len);
6475 		debug_hexdump(stdout, "ciphertext expected:",
6476 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6477 
6478 		if (ut_params->obuf)
6479 			digest = rte_pktmbuf_read(ut_params->obuf,
6480 				(tdata->digest.offset_bytes == 0 ?
6481 				plaintext_pad_len : tdata->digest.offset_bytes),
6482 				tdata->digest.len, digest_buffer);
6483 		else
6484 			digest = rte_pktmbuf_read(ut_params->ibuf,
6485 				(tdata->digest.offset_bytes == 0 ?
6486 				plaintext_pad_len : tdata->digest.offset_bytes),
6487 				tdata->digest.len, digest_buffer);
6488 
6489 		debug_hexdump(stdout, "digest:", digest,
6490 			tdata->digest.len);
6491 		debug_hexdump(stdout, "digest expected:",
6492 			tdata->digest.data, tdata->digest.len);
6493 	}
6494 
6495 	/* Validate obuf */
6496 	if (verify) {
6497 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6498 			plaintext,
6499 			tdata->plaintext.data,
6500 			tdata->plaintext.len >> 3,
6501 			"ZUC Plaintext data not as expected");
6502 	} else {
6503 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6504 			ciphertext,
6505 			tdata->ciphertext.data,
6506 			tdata->validDataLenInBits.len,
6507 			"ZUC Ciphertext data not as expected");
6508 
6509 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6510 			digest,
6511 			tdata->digest.data,
6512 			DIGEST_BYTE_LENGTH_KASUMI_F9,
6513 			"ZUC Generated auth tag not as expected");
6514 	}
6515 	return 0;
6516 }
6517 
6518 static int
6519 test_kasumi_encryption_test_case_1(void)
6520 {
6521 	return test_kasumi_encryption(&kasumi_test_case_1);
6522 }
6523 
6524 static int
6525 test_kasumi_encryption_test_case_1_sgl(void)
6526 {
6527 	return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6528 }
6529 
6530 static int
6531 test_kasumi_encryption_test_case_1_oop(void)
6532 {
6533 	return test_kasumi_encryption_oop(&kasumi_test_case_1);
6534 }
6535 
6536 static int
6537 test_kasumi_encryption_test_case_1_oop_sgl(void)
6538 {
6539 	return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6540 }
6541 
6542 static int
6543 test_kasumi_encryption_test_case_2(void)
6544 {
6545 	return test_kasumi_encryption(&kasumi_test_case_2);
6546 }
6547 
6548 static int
6549 test_kasumi_encryption_test_case_3(void)
6550 {
6551 	return test_kasumi_encryption(&kasumi_test_case_3);
6552 }
6553 
6554 static int
6555 test_kasumi_encryption_test_case_4(void)
6556 {
6557 	return test_kasumi_encryption(&kasumi_test_case_4);
6558 }
6559 
6560 static int
6561 test_kasumi_encryption_test_case_5(void)
6562 {
6563 	return test_kasumi_encryption(&kasumi_test_case_5);
6564 }
6565 
6566 static int
6567 test_kasumi_decryption_test_case_1(void)
6568 {
6569 	return test_kasumi_decryption(&kasumi_test_case_1);
6570 }
6571 
6572 static int
6573 test_kasumi_decryption_test_case_1_oop(void)
6574 {
6575 	return test_kasumi_decryption_oop(&kasumi_test_case_1);
6576 }
6577 
6578 static int
6579 test_kasumi_decryption_test_case_2(void)
6580 {
6581 	return test_kasumi_decryption(&kasumi_test_case_2);
6582 }
6583 
6584 static int
6585 test_kasumi_decryption_test_case_3(void)
6586 {
6587 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6588 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6589 		return TEST_SKIPPED;
6590 	return test_kasumi_decryption(&kasumi_test_case_3);
6591 }
6592 
6593 static int
6594 test_kasumi_decryption_test_case_4(void)
6595 {
6596 	return test_kasumi_decryption(&kasumi_test_case_4);
6597 }
6598 
6599 static int
6600 test_kasumi_decryption_test_case_5(void)
6601 {
6602 	return test_kasumi_decryption(&kasumi_test_case_5);
6603 }
6604 static int
6605 test_snow3g_encryption_test_case_1(void)
6606 {
6607 	return test_snow3g_encryption(&snow3g_test_case_1);
6608 }
6609 
6610 static int
6611 test_snow3g_encryption_test_case_1_oop(void)
6612 {
6613 	return test_snow3g_encryption_oop(&snow3g_test_case_1);
6614 }
6615 
6616 static int
6617 test_snow3g_encryption_test_case_1_oop_sgl(void)
6618 {
6619 	return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6620 }
6621 
6622 
6623 static int
6624 test_snow3g_encryption_test_case_1_offset_oop(void)
6625 {
6626 	return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6627 }
6628 
6629 static int
6630 test_snow3g_encryption_test_case_2(void)
6631 {
6632 	return test_snow3g_encryption(&snow3g_test_case_2);
6633 }
6634 
6635 static int
6636 test_snow3g_encryption_test_case_3(void)
6637 {
6638 	return test_snow3g_encryption(&snow3g_test_case_3);
6639 }
6640 
6641 static int
6642 test_snow3g_encryption_test_case_4(void)
6643 {
6644 	return test_snow3g_encryption(&snow3g_test_case_4);
6645 }
6646 
6647 static int
6648 test_snow3g_encryption_test_case_5(void)
6649 {
6650 	return test_snow3g_encryption(&snow3g_test_case_5);
6651 }
6652 
6653 static int
6654 test_snow3g_decryption_test_case_1(void)
6655 {
6656 	return test_snow3g_decryption(&snow3g_test_case_1);
6657 }
6658 
6659 static int
6660 test_snow3g_decryption_test_case_1_oop(void)
6661 {
6662 	return test_snow3g_decryption_oop(&snow3g_test_case_1);
6663 }
6664 
6665 static int
6666 test_snow3g_decryption_test_case_2(void)
6667 {
6668 	return test_snow3g_decryption(&snow3g_test_case_2);
6669 }
6670 
6671 static int
6672 test_snow3g_decryption_test_case_3(void)
6673 {
6674 	return test_snow3g_decryption(&snow3g_test_case_3);
6675 }
6676 
6677 static int
6678 test_snow3g_decryption_test_case_4(void)
6679 {
6680 	return test_snow3g_decryption(&snow3g_test_case_4);
6681 }
6682 
6683 static int
6684 test_snow3g_decryption_test_case_5(void)
6685 {
6686 	return test_snow3g_decryption(&snow3g_test_case_5);
6687 }
6688 
6689 /*
6690  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6691  * Pattern digest from snow3g_test_data must be allocated as
6692  * 4 last bytes in plaintext.
6693  */
6694 static void
6695 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6696 		struct snow3g_hash_test_data *output)
6697 {
6698 	if ((pattern != NULL) && (output != NULL)) {
6699 		output->key.len = pattern->key.len;
6700 
6701 		memcpy(output->key.data,
6702 		pattern->key.data, pattern->key.len);
6703 
6704 		output->auth_iv.len = pattern->auth_iv.len;
6705 
6706 		memcpy(output->auth_iv.data,
6707 		pattern->auth_iv.data, pattern->auth_iv.len);
6708 
6709 		output->plaintext.len = pattern->plaintext.len;
6710 
6711 		memcpy(output->plaintext.data,
6712 		pattern->plaintext.data, pattern->plaintext.len >> 3);
6713 
6714 		output->digest.len = pattern->digest.len;
6715 
6716 		memcpy(output->digest.data,
6717 		&pattern->plaintext.data[pattern->digest.offset_bytes],
6718 		pattern->digest.len);
6719 
6720 		output->validAuthLenInBits.len =
6721 		pattern->validAuthLenInBits.len;
6722 	}
6723 }
6724 
6725 /*
6726  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6727  */
6728 static int
6729 test_snow3g_decryption_with_digest_test_case_1(void)
6730 {
6731 	struct snow3g_hash_test_data snow3g_hash_data;
6732 	struct rte_cryptodev_info dev_info;
6733 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6734 
6735 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6736 	uint64_t feat_flags = dev_info.feature_flags;
6737 
6738 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6739 		printf("Device doesn't support encrypted digest operations.\n");
6740 		return TEST_SKIPPED;
6741 	}
6742 
6743 	/*
6744 	 * Function prepare data for hash veryfication test case.
6745 	 * Digest is allocated in 4 last bytes in plaintext, pattern.
6746 	 */
6747 	snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6748 
6749 	return test_snow3g_decryption(&snow3g_test_case_7) &
6750 			test_snow3g_authentication_verify(&snow3g_hash_data);
6751 }
6752 
6753 static int
6754 test_snow3g_cipher_auth_test_case_1(void)
6755 {
6756 	return test_snow3g_cipher_auth(&snow3g_test_case_3);
6757 }
6758 
6759 static int
6760 test_snow3g_auth_cipher_test_case_1(void)
6761 {
6762 	return test_snow3g_auth_cipher(
6763 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6764 }
6765 
6766 static int
6767 test_snow3g_auth_cipher_test_case_2(void)
6768 {
6769 	return test_snow3g_auth_cipher(
6770 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6771 }
6772 
6773 static int
6774 test_snow3g_auth_cipher_test_case_2_oop(void)
6775 {
6776 	return test_snow3g_auth_cipher(
6777 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6778 }
6779 
6780 static int
6781 test_snow3g_auth_cipher_part_digest_enc(void)
6782 {
6783 	return test_snow3g_auth_cipher(
6784 		&snow3g_auth_cipher_partial_digest_encryption,
6785 			IN_PLACE, 0);
6786 }
6787 
6788 static int
6789 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6790 {
6791 	return test_snow3g_auth_cipher(
6792 		&snow3g_auth_cipher_partial_digest_encryption,
6793 			OUT_OF_PLACE, 0);
6794 }
6795 
6796 static int
6797 test_snow3g_auth_cipher_test_case_3_sgl(void)
6798 {
6799 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6800 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6801 		return TEST_SKIPPED;
6802 	return test_snow3g_auth_cipher_sgl(
6803 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6804 }
6805 
6806 static int
6807 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6808 {
6809 	return test_snow3g_auth_cipher_sgl(
6810 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6811 }
6812 
6813 static int
6814 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6815 {
6816 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6817 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6818 		return TEST_SKIPPED;
6819 	return test_snow3g_auth_cipher_sgl(
6820 		&snow3g_auth_cipher_partial_digest_encryption,
6821 			IN_PLACE, 0);
6822 }
6823 
6824 static int
6825 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6826 {
6827 	return test_snow3g_auth_cipher_sgl(
6828 		&snow3g_auth_cipher_partial_digest_encryption,
6829 			OUT_OF_PLACE, 0);
6830 }
6831 
6832 static int
6833 test_snow3g_auth_cipher_verify_test_case_1(void)
6834 {
6835 	return test_snow3g_auth_cipher(
6836 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6837 }
6838 
6839 static int
6840 test_snow3g_auth_cipher_verify_test_case_2(void)
6841 {
6842 	return test_snow3g_auth_cipher(
6843 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6844 }
6845 
6846 static int
6847 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6848 {
6849 	return test_snow3g_auth_cipher(
6850 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6851 }
6852 
6853 static int
6854 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6855 {
6856 	return test_snow3g_auth_cipher(
6857 		&snow3g_auth_cipher_partial_digest_encryption,
6858 			IN_PLACE, 1);
6859 }
6860 
6861 static int
6862 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
6863 {
6864 	return test_snow3g_auth_cipher(
6865 		&snow3g_auth_cipher_partial_digest_encryption,
6866 			OUT_OF_PLACE, 1);
6867 }
6868 
6869 static int
6870 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
6871 {
6872 	return test_snow3g_auth_cipher_sgl(
6873 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
6874 }
6875 
6876 static int
6877 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
6878 {
6879 	return test_snow3g_auth_cipher_sgl(
6880 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
6881 }
6882 
6883 static int
6884 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
6885 {
6886 	return test_snow3g_auth_cipher_sgl(
6887 		&snow3g_auth_cipher_partial_digest_encryption,
6888 			IN_PLACE, 1);
6889 }
6890 
6891 static int
6892 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
6893 {
6894 	return test_snow3g_auth_cipher_sgl(
6895 		&snow3g_auth_cipher_partial_digest_encryption,
6896 			OUT_OF_PLACE, 1);
6897 }
6898 
6899 static int
6900 test_snow3g_auth_cipher_with_digest_test_case_1(void)
6901 {
6902 	return test_snow3g_auth_cipher(
6903 		&snow3g_test_case_7, IN_PLACE, 0);
6904 }
6905 
6906 static int
6907 test_kasumi_auth_cipher_test_case_1(void)
6908 {
6909 	return test_kasumi_auth_cipher(
6910 		&kasumi_test_case_3, IN_PLACE, 0);
6911 }
6912 
6913 static int
6914 test_kasumi_auth_cipher_test_case_2(void)
6915 {
6916 	return test_kasumi_auth_cipher(
6917 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6918 }
6919 
6920 static int
6921 test_kasumi_auth_cipher_test_case_2_oop(void)
6922 {
6923 	return test_kasumi_auth_cipher(
6924 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6925 }
6926 
6927 static int
6928 test_kasumi_auth_cipher_test_case_2_sgl(void)
6929 {
6930 	return test_kasumi_auth_cipher_sgl(
6931 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6932 }
6933 
6934 static int
6935 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
6936 {
6937 	return test_kasumi_auth_cipher_sgl(
6938 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6939 }
6940 
6941 static int
6942 test_kasumi_auth_cipher_verify_test_case_1(void)
6943 {
6944 	return test_kasumi_auth_cipher(
6945 		&kasumi_test_case_3, IN_PLACE, 1);
6946 }
6947 
6948 static int
6949 test_kasumi_auth_cipher_verify_test_case_2(void)
6950 {
6951 	return test_kasumi_auth_cipher(
6952 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6953 }
6954 
6955 static int
6956 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
6957 {
6958 	return test_kasumi_auth_cipher(
6959 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6960 }
6961 
6962 static int
6963 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
6964 {
6965 	return test_kasumi_auth_cipher_sgl(
6966 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6967 }
6968 
6969 static int
6970 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
6971 {
6972 	return test_kasumi_auth_cipher_sgl(
6973 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6974 }
6975 
6976 static int
6977 test_kasumi_cipher_auth_test_case_1(void)
6978 {
6979 	return test_kasumi_cipher_auth(&kasumi_test_case_6);
6980 }
6981 
6982 static int
6983 test_zuc_encryption_test_case_1(void)
6984 {
6985 	return test_zuc_encryption(&zuc_test_case_cipher_193b);
6986 }
6987 
6988 static int
6989 test_zuc_encryption_test_case_2(void)
6990 {
6991 	return test_zuc_encryption(&zuc_test_case_cipher_800b);
6992 }
6993 
6994 static int
6995 test_zuc_encryption_test_case_3(void)
6996 {
6997 	return test_zuc_encryption(&zuc_test_case_cipher_1570b);
6998 }
6999 
7000 static int
7001 test_zuc_encryption_test_case_4(void)
7002 {
7003 	return test_zuc_encryption(&zuc_test_case_cipher_2798b);
7004 }
7005 
7006 static int
7007 test_zuc_encryption_test_case_5(void)
7008 {
7009 	return test_zuc_encryption(&zuc_test_case_cipher_4019b);
7010 }
7011 
7012 static int
7013 test_zuc_encryption_test_case_6_sgl(void)
7014 {
7015 	return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
7016 }
7017 
7018 static int
7019 test_zuc_encryption_test_case_7(void)
7020 {
7021 	return test_zuc_encryption(&zuc_test_case_cipher_800b_key_256b);
7022 }
7023 
7024 static int
7025 test_zuc_hash_generate_test_case_1(void)
7026 {
7027 	return test_zuc_authentication(&zuc_test_case_auth_1b);
7028 }
7029 
7030 static int
7031 test_zuc_hash_generate_test_case_2(void)
7032 {
7033 	return test_zuc_authentication(&zuc_test_case_auth_90b);
7034 }
7035 
7036 static int
7037 test_zuc_hash_generate_test_case_3(void)
7038 {
7039 	return test_zuc_authentication(&zuc_test_case_auth_577b);
7040 }
7041 
7042 static int
7043 test_zuc_hash_generate_test_case_4(void)
7044 {
7045 	return test_zuc_authentication(&zuc_test_case_auth_2079b);
7046 }
7047 
7048 static int
7049 test_zuc_hash_generate_test_case_5(void)
7050 {
7051 	return test_zuc_authentication(&zuc_test_auth_5670b);
7052 }
7053 
7054 static int
7055 test_zuc_hash_generate_test_case_6(void)
7056 {
7057 	return test_zuc_authentication(&zuc_test_case_auth_128b);
7058 }
7059 
7060 static int
7061 test_zuc_hash_generate_test_case_7(void)
7062 {
7063 	return test_zuc_authentication(&zuc_test_case_auth_2080b);
7064 }
7065 
7066 static int
7067 test_zuc_hash_generate_test_case_8(void)
7068 {
7069 	return test_zuc_authentication(&zuc_test_case_auth_584b);
7070 }
7071 
7072 static int
7073 test_zuc_hash_generate_test_case_9(void)
7074 {
7075 	return test_zuc_authentication(&zuc_test_case_auth_584b_mac_64b);
7076 }
7077 
7078 static int
7079 test_zuc_hash_generate_test_case_10(void)
7080 {
7081 	return test_zuc_authentication(&zuc_test_case_auth_2080b_mac_128b);
7082 }
7083 
7084 static int
7085 test_zuc_cipher_auth_test_case_1(void)
7086 {
7087 	return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
7088 }
7089 
7090 static int
7091 test_zuc_cipher_auth_test_case_2(void)
7092 {
7093 	return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
7094 }
7095 
7096 static int
7097 test_zuc_auth_cipher_test_case_1(void)
7098 {
7099 	return test_zuc_auth_cipher(
7100 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7101 }
7102 
7103 static int
7104 test_zuc_auth_cipher_test_case_1_oop(void)
7105 {
7106 	return test_zuc_auth_cipher(
7107 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7108 }
7109 
7110 static int
7111 test_zuc_auth_cipher_test_case_1_sgl(void)
7112 {
7113 	return test_zuc_auth_cipher_sgl(
7114 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7115 }
7116 
7117 static int
7118 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
7119 {
7120 	return test_zuc_auth_cipher_sgl(
7121 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7122 }
7123 
7124 static int
7125 test_zuc_auth_cipher_verify_test_case_1(void)
7126 {
7127 	return test_zuc_auth_cipher(
7128 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7129 }
7130 
7131 static int
7132 test_zuc_auth_cipher_verify_test_case_1_oop(void)
7133 {
7134 	return test_zuc_auth_cipher(
7135 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7136 }
7137 
7138 static int
7139 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
7140 {
7141 	return test_zuc_auth_cipher_sgl(
7142 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7143 }
7144 
7145 static int
7146 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
7147 {
7148 	return test_zuc_auth_cipher_sgl(
7149 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7150 }
7151 
7152 static int
7153 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
7154 {
7155 	uint8_t dev_id = testsuite_params.valid_devs[0];
7156 
7157 	struct rte_cryptodev_sym_capability_idx cap_idx;
7158 
7159 	/* Check if device supports particular cipher algorithm */
7160 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7161 	cap_idx.algo.cipher = tdata->cipher_algo;
7162 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7163 		return TEST_SKIPPED;
7164 
7165 	/* Check if device supports particular hash algorithm */
7166 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7167 	cap_idx.algo.auth = tdata->auth_algo;
7168 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7169 		return TEST_SKIPPED;
7170 
7171 	return 0;
7172 }
7173 
7174 static int
7175 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
7176 	uint8_t op_mode, uint8_t verify)
7177 {
7178 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7179 	struct crypto_unittest_params *ut_params = &unittest_params;
7180 
7181 	int retval;
7182 
7183 	uint8_t *plaintext = NULL, *ciphertext = NULL;
7184 	unsigned int plaintext_pad_len;
7185 	unsigned int plaintext_len;
7186 	unsigned int ciphertext_pad_len;
7187 	unsigned int ciphertext_len;
7188 
7189 	struct rte_cryptodev_info dev_info;
7190 	struct rte_crypto_op *op;
7191 
7192 	/* Check if device supports particular algorithms separately */
7193 	if (test_mixed_check_if_unsupported(tdata))
7194 		return TEST_SKIPPED;
7195 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7196 		return TEST_SKIPPED;
7197 
7198 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7199 
7200 	uint64_t feat_flags = dev_info.feature_flags;
7201 
7202 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7203 		printf("Device doesn't support digest encrypted.\n");
7204 		return TEST_SKIPPED;
7205 	}
7206 
7207 	/* Create the session */
7208 	if (verify)
7209 		retval = create_wireless_algo_cipher_auth_session(
7210 				ts_params->valid_devs[0],
7211 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
7212 				RTE_CRYPTO_AUTH_OP_VERIFY,
7213 				tdata->auth_algo,
7214 				tdata->cipher_algo,
7215 				tdata->auth_key.data, tdata->auth_key.len,
7216 				tdata->auth_iv.len, tdata->digest_enc.len,
7217 				tdata->cipher_iv.len);
7218 	else
7219 		retval = create_wireless_algo_auth_cipher_session(
7220 				ts_params->valid_devs[0],
7221 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7222 				RTE_CRYPTO_AUTH_OP_GENERATE,
7223 				tdata->auth_algo,
7224 				tdata->cipher_algo,
7225 				tdata->auth_key.data, tdata->auth_key.len,
7226 				tdata->auth_iv.len, tdata->digest_enc.len,
7227 				tdata->cipher_iv.len);
7228 	if (retval != 0)
7229 		return retval;
7230 
7231 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7232 	if (op_mode == OUT_OF_PLACE)
7233 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7234 
7235 	/* clear mbuf payload */
7236 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7237 		rte_pktmbuf_tailroom(ut_params->ibuf));
7238 	if (op_mode == OUT_OF_PLACE) {
7239 
7240 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
7241 				rte_pktmbuf_tailroom(ut_params->obuf));
7242 	}
7243 
7244 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7245 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7246 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7247 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7248 
7249 	if (verify) {
7250 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7251 				ciphertext_pad_len);
7252 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
7253 		if (op_mode == OUT_OF_PLACE)
7254 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
7255 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7256 				ciphertext_len);
7257 	} else {
7258 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7259 				plaintext_pad_len);
7260 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7261 		if (op_mode == OUT_OF_PLACE)
7262 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
7263 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
7264 	}
7265 
7266 	/* Create the operation */
7267 	retval = create_wireless_algo_auth_cipher_operation(
7268 			tdata->digest_enc.data, tdata->digest_enc.len,
7269 			tdata->cipher_iv.data, tdata->cipher_iv.len,
7270 			tdata->auth_iv.data, tdata->auth_iv.len,
7271 			(tdata->digest_enc.offset == 0 ?
7272 				plaintext_pad_len
7273 				: tdata->digest_enc.offset),
7274 			tdata->validCipherLen.len_bits,
7275 			tdata->cipher.offset_bits,
7276 			tdata->validAuthLen.len_bits,
7277 			tdata->auth.offset_bits,
7278 			op_mode, 0, verify);
7279 
7280 	if (retval < 0)
7281 		return retval;
7282 
7283 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7284 
7285 	/* Check if the op failed because the device doesn't */
7286 	/* support this particular combination of algorithms */
7287 	if (op == NULL && ut_params->op->status ==
7288 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7289 		printf("Device doesn't support this mixed combination. "
7290 				"Test Skipped.\n");
7291 		return TEST_SKIPPED;
7292 	}
7293 	ut_params->op = op;
7294 
7295 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7296 
7297 	ut_params->obuf = (op_mode == IN_PLACE ?
7298 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7299 
7300 	if (verify) {
7301 		if (ut_params->obuf)
7302 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
7303 							uint8_t *);
7304 		else
7305 			plaintext = ciphertext +
7306 					(tdata->cipher.offset_bits >> 3);
7307 
7308 		debug_hexdump(stdout, "plaintext:", plaintext,
7309 				tdata->plaintext.len_bits >> 3);
7310 		debug_hexdump(stdout, "plaintext expected:",
7311 				tdata->plaintext.data,
7312 				tdata->plaintext.len_bits >> 3);
7313 	} else {
7314 		if (ut_params->obuf)
7315 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
7316 					uint8_t *);
7317 		else
7318 			ciphertext = plaintext;
7319 
7320 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7321 				ciphertext_len);
7322 		debug_hexdump(stdout, "ciphertext expected:",
7323 				tdata->ciphertext.data,
7324 				tdata->ciphertext.len_bits >> 3);
7325 
7326 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
7327 				+ (tdata->digest_enc.offset == 0 ?
7328 		plaintext_pad_len : tdata->digest_enc.offset);
7329 
7330 		debug_hexdump(stdout, "digest:", ut_params->digest,
7331 				tdata->digest_enc.len);
7332 		debug_hexdump(stdout, "digest expected:",
7333 				tdata->digest_enc.data,
7334 				tdata->digest_enc.len);
7335 	}
7336 
7337 	/* Validate obuf */
7338 	if (verify) {
7339 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7340 				plaintext,
7341 				tdata->plaintext.data,
7342 				tdata->plaintext.len_bits >> 3,
7343 				"Plaintext data not as expected");
7344 	} else {
7345 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7346 				ciphertext,
7347 				tdata->ciphertext.data,
7348 				tdata->validDataLen.len_bits,
7349 				"Ciphertext data not as expected");
7350 
7351 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
7352 				ut_params->digest,
7353 				tdata->digest_enc.data,
7354 				DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
7355 				"Generated auth tag not as expected");
7356 	}
7357 
7358 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7359 			"crypto op processing failed");
7360 
7361 	return 0;
7362 }
7363 
7364 static int
7365 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
7366 	uint8_t op_mode, uint8_t verify)
7367 {
7368 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7369 	struct crypto_unittest_params *ut_params = &unittest_params;
7370 
7371 	int retval;
7372 
7373 	const uint8_t *plaintext = NULL;
7374 	const uint8_t *ciphertext = NULL;
7375 	const uint8_t *digest = NULL;
7376 	unsigned int plaintext_pad_len;
7377 	unsigned int plaintext_len;
7378 	unsigned int ciphertext_pad_len;
7379 	unsigned int ciphertext_len;
7380 	uint8_t buffer[10000];
7381 	uint8_t digest_buffer[10000];
7382 
7383 	struct rte_cryptodev_info dev_info;
7384 	struct rte_crypto_op *op;
7385 
7386 	/* Check if device supports particular algorithms */
7387 	if (test_mixed_check_if_unsupported(tdata))
7388 		return TEST_SKIPPED;
7389 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7390 		return TEST_SKIPPED;
7391 
7392 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7393 
7394 	uint64_t feat_flags = dev_info.feature_flags;
7395 
7396 	if (op_mode == IN_PLACE) {
7397 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
7398 			printf("Device doesn't support in-place scatter-gather "
7399 					"in both input and output mbufs.\n");
7400 			return TEST_SKIPPED;
7401 		}
7402 	} else {
7403 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
7404 			printf("Device doesn't support out-of-place scatter-gather "
7405 					"in both input and output mbufs.\n");
7406 			return TEST_SKIPPED;
7407 		}
7408 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7409 			printf("Device doesn't support digest encrypted.\n");
7410 			return TEST_SKIPPED;
7411 		}
7412 	}
7413 
7414 	/* Create the session */
7415 	if (verify)
7416 		retval = create_wireless_algo_cipher_auth_session(
7417 				ts_params->valid_devs[0],
7418 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
7419 				RTE_CRYPTO_AUTH_OP_VERIFY,
7420 				tdata->auth_algo,
7421 				tdata->cipher_algo,
7422 				tdata->auth_key.data, tdata->auth_key.len,
7423 				tdata->auth_iv.len, tdata->digest_enc.len,
7424 				tdata->cipher_iv.len);
7425 	else
7426 		retval = create_wireless_algo_auth_cipher_session(
7427 				ts_params->valid_devs[0],
7428 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7429 				RTE_CRYPTO_AUTH_OP_GENERATE,
7430 				tdata->auth_algo,
7431 				tdata->cipher_algo,
7432 				tdata->auth_key.data, tdata->auth_key.len,
7433 				tdata->auth_iv.len, tdata->digest_enc.len,
7434 				tdata->cipher_iv.len);
7435 	if (retval != 0)
7436 		return retval;
7437 
7438 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7439 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7440 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7441 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7442 
7443 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
7444 			ciphertext_pad_len, 15, 0);
7445 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7446 			"Failed to allocate input buffer in mempool");
7447 
7448 	if (op_mode == OUT_OF_PLACE) {
7449 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
7450 				plaintext_pad_len, 15, 0);
7451 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
7452 				"Failed to allocate output buffer in mempool");
7453 	}
7454 
7455 	if (verify) {
7456 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
7457 			tdata->ciphertext.data);
7458 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7459 					ciphertext_len, buffer);
7460 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7461 			ciphertext_len);
7462 	} else {
7463 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
7464 			tdata->plaintext.data);
7465 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7466 					plaintext_len, buffer);
7467 		debug_hexdump(stdout, "plaintext:", plaintext,
7468 			plaintext_len);
7469 	}
7470 	memset(buffer, 0, sizeof(buffer));
7471 
7472 	/* Create the operation */
7473 	retval = create_wireless_algo_auth_cipher_operation(
7474 			tdata->digest_enc.data, tdata->digest_enc.len,
7475 			tdata->cipher_iv.data, tdata->cipher_iv.len,
7476 			tdata->auth_iv.data, tdata->auth_iv.len,
7477 			(tdata->digest_enc.offset == 0 ?
7478 				plaintext_pad_len
7479 				: tdata->digest_enc.offset),
7480 			tdata->validCipherLen.len_bits,
7481 			tdata->cipher.offset_bits,
7482 			tdata->validAuthLen.len_bits,
7483 			tdata->auth.offset_bits,
7484 			op_mode, 1, verify);
7485 
7486 	if (retval < 0)
7487 		return retval;
7488 
7489 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7490 
7491 	/* Check if the op failed because the device doesn't */
7492 	/* support this particular combination of algorithms */
7493 	if (op == NULL && ut_params->op->status ==
7494 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7495 		printf("Device doesn't support this mixed combination. "
7496 				"Test Skipped.\n");
7497 		return TEST_SKIPPED;
7498 	}
7499 	ut_params->op = op;
7500 
7501 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7502 
7503 	ut_params->obuf = (op_mode == IN_PLACE ?
7504 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7505 
7506 	if (verify) {
7507 		if (ut_params->obuf)
7508 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
7509 					plaintext_len, buffer);
7510 		else
7511 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7512 					plaintext_len, buffer);
7513 
7514 		debug_hexdump(stdout, "plaintext:", plaintext,
7515 				(tdata->plaintext.len_bits >> 3) -
7516 				tdata->digest_enc.len);
7517 		debug_hexdump(stdout, "plaintext expected:",
7518 				tdata->plaintext.data,
7519 				(tdata->plaintext.len_bits >> 3) -
7520 				tdata->digest_enc.len);
7521 	} else {
7522 		if (ut_params->obuf)
7523 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7524 					ciphertext_len, buffer);
7525 		else
7526 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7527 					ciphertext_len, buffer);
7528 
7529 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7530 			ciphertext_len);
7531 		debug_hexdump(stdout, "ciphertext expected:",
7532 			tdata->ciphertext.data,
7533 			tdata->ciphertext.len_bits >> 3);
7534 
7535 		if (ut_params->obuf)
7536 			digest = rte_pktmbuf_read(ut_params->obuf,
7537 					(tdata->digest_enc.offset == 0 ?
7538 						plaintext_pad_len :
7539 						tdata->digest_enc.offset),
7540 					tdata->digest_enc.len, digest_buffer);
7541 		else
7542 			digest = rte_pktmbuf_read(ut_params->ibuf,
7543 					(tdata->digest_enc.offset == 0 ?
7544 						plaintext_pad_len :
7545 						tdata->digest_enc.offset),
7546 					tdata->digest_enc.len, digest_buffer);
7547 
7548 		debug_hexdump(stdout, "digest:", digest,
7549 				tdata->digest_enc.len);
7550 		debug_hexdump(stdout, "digest expected:",
7551 				tdata->digest_enc.data, tdata->digest_enc.len);
7552 	}
7553 
7554 	/* Validate obuf */
7555 	if (verify) {
7556 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7557 				plaintext,
7558 				tdata->plaintext.data,
7559 				tdata->plaintext.len_bits >> 3,
7560 				"Plaintext data not as expected");
7561 	} else {
7562 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7563 				ciphertext,
7564 				tdata->ciphertext.data,
7565 				tdata->validDataLen.len_bits,
7566 				"Ciphertext data not as expected");
7567 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
7568 				digest,
7569 				tdata->digest_enc.data,
7570 				tdata->digest_enc.len,
7571 				"Generated auth tag not as expected");
7572 	}
7573 
7574 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7575 			"crypto op processing failed");
7576 
7577 	return 0;
7578 }
7579 
7580 /** AUTH AES CMAC + CIPHER AES CTR */
7581 
7582 static int
7583 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7584 {
7585 	return test_mixed_auth_cipher(
7586 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7587 }
7588 
7589 static int
7590 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7591 {
7592 	return test_mixed_auth_cipher(
7593 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7594 }
7595 
7596 static int
7597 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7598 {
7599 	return test_mixed_auth_cipher_sgl(
7600 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7601 }
7602 
7603 static int
7604 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7605 {
7606 	return test_mixed_auth_cipher_sgl(
7607 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7608 }
7609 
7610 static int
7611 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7612 {
7613 	return test_mixed_auth_cipher(
7614 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7615 }
7616 
7617 static int
7618 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7619 {
7620 	return test_mixed_auth_cipher(
7621 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7622 }
7623 
7624 static int
7625 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7626 {
7627 	return test_mixed_auth_cipher_sgl(
7628 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7629 }
7630 
7631 static int
7632 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7633 {
7634 	return test_mixed_auth_cipher_sgl(
7635 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7636 }
7637 
7638 /** MIXED AUTH + CIPHER */
7639 
7640 static int
7641 test_auth_zuc_cipher_snow_test_case_1(void)
7642 {
7643 	return test_mixed_auth_cipher(
7644 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7645 }
7646 
7647 static int
7648 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7649 {
7650 	return test_mixed_auth_cipher(
7651 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7652 }
7653 
7654 static int
7655 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7656 {
7657 	return test_mixed_auth_cipher(
7658 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7659 }
7660 
7661 static int
7662 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7663 {
7664 	return test_mixed_auth_cipher(
7665 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7666 }
7667 
7668 static int
7669 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7670 {
7671 	return test_mixed_auth_cipher(
7672 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7673 }
7674 
7675 static int
7676 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7677 {
7678 	return test_mixed_auth_cipher(
7679 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7680 }
7681 
7682 static int
7683 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7684 {
7685 	return test_mixed_auth_cipher(
7686 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7687 }
7688 
7689 static int
7690 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7691 {
7692 	return test_mixed_auth_cipher(
7693 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7694 }
7695 
7696 static int
7697 test_auth_snow_cipher_zuc_test_case_1(void)
7698 {
7699 	return test_mixed_auth_cipher(
7700 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7701 }
7702 
7703 static int
7704 test_verify_auth_snow_cipher_zuc_test_case_1(void)
7705 {
7706 	return test_mixed_auth_cipher(
7707 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7708 }
7709 
7710 static int
7711 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
7712 {
7713 	return test_mixed_auth_cipher(
7714 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7715 }
7716 
7717 static int
7718 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
7719 {
7720 	return test_mixed_auth_cipher(
7721 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7722 }
7723 
7724 static int
7725 test_auth_null_cipher_snow_test_case_1(void)
7726 {
7727 	return test_mixed_auth_cipher(
7728 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7729 }
7730 
7731 static int
7732 test_verify_auth_null_cipher_snow_test_case_1(void)
7733 {
7734 	return test_mixed_auth_cipher(
7735 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7736 }
7737 
7738 static int
7739 test_auth_null_cipher_zuc_test_case_1(void)
7740 {
7741 	return test_mixed_auth_cipher(
7742 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7743 }
7744 
7745 static int
7746 test_verify_auth_null_cipher_zuc_test_case_1(void)
7747 {
7748 	return test_mixed_auth_cipher(
7749 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7750 }
7751 
7752 static int
7753 test_auth_snow_cipher_null_test_case_1(void)
7754 {
7755 	return test_mixed_auth_cipher(
7756 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7757 }
7758 
7759 static int
7760 test_verify_auth_snow_cipher_null_test_case_1(void)
7761 {
7762 	return test_mixed_auth_cipher(
7763 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7764 }
7765 
7766 static int
7767 test_auth_zuc_cipher_null_test_case_1(void)
7768 {
7769 	return test_mixed_auth_cipher(
7770 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7771 }
7772 
7773 static int
7774 test_verify_auth_zuc_cipher_null_test_case_1(void)
7775 {
7776 	return test_mixed_auth_cipher(
7777 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7778 }
7779 
7780 static int
7781 test_auth_null_cipher_aes_ctr_test_case_1(void)
7782 {
7783 	return test_mixed_auth_cipher(
7784 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7785 }
7786 
7787 static int
7788 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
7789 {
7790 	return test_mixed_auth_cipher(
7791 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7792 }
7793 
7794 static int
7795 test_auth_aes_cmac_cipher_null_test_case_1(void)
7796 {
7797 	return test_mixed_auth_cipher(
7798 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7799 }
7800 
7801 static int
7802 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
7803 {
7804 	return test_mixed_auth_cipher(
7805 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7806 }
7807 
7808 /* ***** AEAD algorithm Tests ***** */
7809 
7810 static int
7811 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
7812 		enum rte_crypto_aead_operation op,
7813 		const uint8_t *key, const uint8_t key_len,
7814 		const uint16_t aad_len, const uint8_t auth_len,
7815 		uint8_t iv_len)
7816 {
7817 	uint8_t aead_key[key_len];
7818 
7819 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7820 	struct crypto_unittest_params *ut_params = &unittest_params;
7821 
7822 	memcpy(aead_key, key, key_len);
7823 
7824 	/* Setup AEAD Parameters */
7825 	ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7826 	ut_params->aead_xform.next = NULL;
7827 	ut_params->aead_xform.aead.algo = algo;
7828 	ut_params->aead_xform.aead.op = op;
7829 	ut_params->aead_xform.aead.key.data = aead_key;
7830 	ut_params->aead_xform.aead.key.length = key_len;
7831 	ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
7832 	ut_params->aead_xform.aead.iv.length = iv_len;
7833 	ut_params->aead_xform.aead.digest_length = auth_len;
7834 	ut_params->aead_xform.aead.aad_length = aad_len;
7835 
7836 	debug_hexdump(stdout, "key:", key, key_len);
7837 
7838 	/* Create Crypto session*/
7839 	ut_params->sess = rte_cryptodev_sym_session_create(
7840 			ts_params->session_mpool);
7841 
7842 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7843 			&ut_params->aead_xform,
7844 			ts_params->session_priv_mpool);
7845 
7846 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7847 
7848 	return 0;
7849 }
7850 
7851 static int
7852 create_aead_xform(struct rte_crypto_op *op,
7853 		enum rte_crypto_aead_algorithm algo,
7854 		enum rte_crypto_aead_operation aead_op,
7855 		uint8_t *key, const uint8_t key_len,
7856 		const uint8_t aad_len, const uint8_t auth_len,
7857 		uint8_t iv_len)
7858 {
7859 	TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
7860 			"failed to allocate space for crypto transform");
7861 
7862 	struct rte_crypto_sym_op *sym_op = op->sym;
7863 
7864 	/* Setup AEAD Parameters */
7865 	sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
7866 	sym_op->xform->next = NULL;
7867 	sym_op->xform->aead.algo = algo;
7868 	sym_op->xform->aead.op = aead_op;
7869 	sym_op->xform->aead.key.data = key;
7870 	sym_op->xform->aead.key.length = key_len;
7871 	sym_op->xform->aead.iv.offset = IV_OFFSET;
7872 	sym_op->xform->aead.iv.length = iv_len;
7873 	sym_op->xform->aead.digest_length = auth_len;
7874 	sym_op->xform->aead.aad_length = aad_len;
7875 
7876 	debug_hexdump(stdout, "key:", key, key_len);
7877 
7878 	return 0;
7879 }
7880 
7881 static int
7882 create_aead_operation(enum rte_crypto_aead_operation op,
7883 		const struct aead_test_data *tdata)
7884 {
7885 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7886 	struct crypto_unittest_params *ut_params = &unittest_params;
7887 
7888 	uint8_t *plaintext, *ciphertext;
7889 	unsigned int aad_pad_len, plaintext_pad_len;
7890 
7891 	/* Generate Crypto op data structure */
7892 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7893 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7894 	TEST_ASSERT_NOT_NULL(ut_params->op,
7895 			"Failed to allocate symmetric crypto operation struct");
7896 
7897 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7898 
7899 	/* Append aad data */
7900 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
7901 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
7902 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7903 				aad_pad_len);
7904 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7905 				"no room to append aad");
7906 
7907 		sym_op->aead.aad.phys_addr =
7908 				rte_pktmbuf_iova(ut_params->ibuf);
7909 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
7910 		memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
7911 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7912 			tdata->aad.len);
7913 
7914 		/* Append IV at the end of the crypto operation*/
7915 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7916 				uint8_t *, IV_OFFSET);
7917 
7918 		/* Copy IV 1 byte after the IV pointer, according to the API */
7919 		rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
7920 		debug_hexdump(stdout, "iv:", iv_ptr,
7921 			tdata->iv.len);
7922 	} else {
7923 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
7924 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7925 				aad_pad_len);
7926 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7927 				"no room to append aad");
7928 
7929 		sym_op->aead.aad.phys_addr =
7930 				rte_pktmbuf_iova(ut_params->ibuf);
7931 		memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
7932 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7933 			tdata->aad.len);
7934 
7935 		/* Append IV at the end of the crypto operation*/
7936 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7937 				uint8_t *, IV_OFFSET);
7938 
7939 		if (tdata->iv.len == 0) {
7940 			rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
7941 			debug_hexdump(stdout, "iv:", iv_ptr,
7942 				AES_GCM_J0_LENGTH);
7943 		} else {
7944 			rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
7945 			debug_hexdump(stdout, "iv:", iv_ptr,
7946 				tdata->iv.len);
7947 		}
7948 	}
7949 
7950 	/* Append plaintext/ciphertext */
7951 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7952 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7953 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7954 				plaintext_pad_len);
7955 		TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7956 
7957 		memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
7958 		debug_hexdump(stdout, "plaintext:", plaintext,
7959 				tdata->plaintext.len);
7960 
7961 		if (ut_params->obuf) {
7962 			ciphertext = (uint8_t *)rte_pktmbuf_append(
7963 					ut_params->obuf,
7964 					plaintext_pad_len + aad_pad_len);
7965 			TEST_ASSERT_NOT_NULL(ciphertext,
7966 					"no room to append ciphertext");
7967 
7968 			memset(ciphertext + aad_pad_len, 0,
7969 					tdata->ciphertext.len);
7970 		}
7971 	} else {
7972 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
7973 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7974 				plaintext_pad_len);
7975 		TEST_ASSERT_NOT_NULL(ciphertext,
7976 				"no room to append ciphertext");
7977 
7978 		memcpy(ciphertext, tdata->ciphertext.data,
7979 				tdata->ciphertext.len);
7980 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7981 				tdata->ciphertext.len);
7982 
7983 		if (ut_params->obuf) {
7984 			plaintext = (uint8_t *)rte_pktmbuf_append(
7985 					ut_params->obuf,
7986 					plaintext_pad_len + aad_pad_len);
7987 			TEST_ASSERT_NOT_NULL(plaintext,
7988 					"no room to append plaintext");
7989 
7990 			memset(plaintext + aad_pad_len, 0,
7991 					tdata->plaintext.len);
7992 		}
7993 	}
7994 
7995 	/* Append digest data */
7996 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7997 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7998 				ut_params->obuf ? ut_params->obuf :
7999 						ut_params->ibuf,
8000 						tdata->auth_tag.len);
8001 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8002 				"no room to append digest");
8003 		memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
8004 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8005 				ut_params->obuf ? ut_params->obuf :
8006 						ut_params->ibuf,
8007 						plaintext_pad_len +
8008 						aad_pad_len);
8009 	} else {
8010 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8011 				ut_params->ibuf, tdata->auth_tag.len);
8012 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8013 				"no room to append digest");
8014 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8015 				ut_params->ibuf,
8016 				plaintext_pad_len + aad_pad_len);
8017 
8018 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
8019 			tdata->auth_tag.len);
8020 		debug_hexdump(stdout, "digest:",
8021 			sym_op->aead.digest.data,
8022 			tdata->auth_tag.len);
8023 	}
8024 
8025 	sym_op->aead.data.length = tdata->plaintext.len;
8026 	sym_op->aead.data.offset = aad_pad_len;
8027 
8028 	return 0;
8029 }
8030 
8031 static int
8032 test_authenticated_encryption(const struct aead_test_data *tdata)
8033 {
8034 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8035 	struct crypto_unittest_params *ut_params = &unittest_params;
8036 
8037 	int retval;
8038 	uint8_t *ciphertext, *auth_tag;
8039 	uint16_t plaintext_pad_len;
8040 	uint32_t i;
8041 	struct rte_cryptodev_info dev_info;
8042 
8043 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8044 	uint64_t feat_flags = dev_info.feature_flags;
8045 
8046 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8047 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8048 		printf("Device doesn't support RAW data-path APIs.\n");
8049 		return TEST_SKIPPED;
8050 	}
8051 
8052 	/* Verify the capabilities */
8053 	struct rte_cryptodev_sym_capability_idx cap_idx;
8054 	const struct rte_cryptodev_symmetric_capability *capability;
8055 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8056 	cap_idx.algo.aead = tdata->algo;
8057 	capability = rte_cryptodev_sym_capability_get(
8058 			ts_params->valid_devs[0], &cap_idx);
8059 	if (capability == NULL)
8060 		return TEST_SKIPPED;
8061 	if (rte_cryptodev_sym_capability_check_aead(
8062 			capability, tdata->key.len, tdata->auth_tag.len,
8063 			tdata->aad.len, tdata->iv.len))
8064 		return TEST_SKIPPED;
8065 
8066 	/* Create AEAD session */
8067 	retval = create_aead_session(ts_params->valid_devs[0],
8068 			tdata->algo,
8069 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
8070 			tdata->key.data, tdata->key.len,
8071 			tdata->aad.len, tdata->auth_tag.len,
8072 			tdata->iv.len);
8073 	if (retval < 0)
8074 		return retval;
8075 
8076 	if (tdata->aad.len > MBUF_SIZE) {
8077 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8078 		/* Populate full size of add data */
8079 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
8080 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
8081 	} else
8082 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8083 
8084 	/* clear mbuf payload */
8085 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8086 			rte_pktmbuf_tailroom(ut_params->ibuf));
8087 
8088 	/* Create AEAD operation */
8089 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8090 	if (retval < 0)
8091 		return retval;
8092 
8093 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8094 
8095 	ut_params->op->sym->m_src = ut_params->ibuf;
8096 
8097 	/* Process crypto operation */
8098 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8099 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
8100 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
8101 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8102 				ut_params->op, 0, 0, 0, 0);
8103 	else
8104 		TEST_ASSERT_NOT_NULL(
8105 			process_crypto_request(ts_params->valid_devs[0],
8106 			ut_params->op), "failed to process sym crypto op");
8107 
8108 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8109 			"crypto op processing failed");
8110 
8111 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8112 
8113 	if (ut_params->op->sym->m_dst) {
8114 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8115 				uint8_t *);
8116 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8117 				uint8_t *, plaintext_pad_len);
8118 	} else {
8119 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8120 				uint8_t *,
8121 				ut_params->op->sym->cipher.data.offset);
8122 		auth_tag = ciphertext + plaintext_pad_len;
8123 	}
8124 
8125 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8126 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8127 
8128 	/* Validate obuf */
8129 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
8130 			ciphertext,
8131 			tdata->ciphertext.data,
8132 			tdata->ciphertext.len,
8133 			"Ciphertext data not as expected");
8134 
8135 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
8136 			auth_tag,
8137 			tdata->auth_tag.data,
8138 			tdata->auth_tag.len,
8139 			"Generated auth tag not as expected");
8140 
8141 	return 0;
8142 
8143 }
8144 
8145 #ifdef RTE_LIB_SECURITY
8146 static int
8147 security_proto_supported(enum rte_security_session_action_type action,
8148 	enum rte_security_session_protocol proto)
8149 {
8150 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8151 
8152 	const struct rte_security_capability *capabilities;
8153 	const struct rte_security_capability *capability;
8154 	uint16_t i = 0;
8155 
8156 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8157 				rte_cryptodev_get_sec_ctx(
8158 				ts_params->valid_devs[0]);
8159 
8160 
8161 	capabilities = rte_security_capabilities_get(ctx);
8162 
8163 	if (capabilities == NULL)
8164 		return -ENOTSUP;
8165 
8166 	while ((capability = &capabilities[i++])->action !=
8167 			RTE_SECURITY_ACTION_TYPE_NONE) {
8168 		if (capability->action == action &&
8169 				capability->protocol == proto)
8170 			return 0;
8171 	}
8172 
8173 	return -ENOTSUP;
8174 }
8175 
8176 /* Basic algorithm run function for async inplace mode.
8177  * Creates a session from input parameters and runs one operation
8178  * on input_vec. Checks the output of the crypto operation against
8179  * output_vec.
8180  */
8181 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
8182 			   enum rte_crypto_auth_operation opa,
8183 			   const uint8_t *input_vec, unsigned int input_vec_len,
8184 			   const uint8_t *output_vec,
8185 			   unsigned int output_vec_len,
8186 			   enum rte_crypto_cipher_algorithm cipher_alg,
8187 			   const uint8_t *cipher_key, uint32_t cipher_key_len,
8188 			   enum rte_crypto_auth_algorithm auth_alg,
8189 			   const uint8_t *auth_key, uint32_t auth_key_len,
8190 			   uint8_t bearer, enum rte_security_pdcp_domain domain,
8191 			   uint8_t packet_direction, uint8_t sn_size,
8192 			   uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
8193 {
8194 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8195 	struct crypto_unittest_params *ut_params = &unittest_params;
8196 	uint8_t *plaintext;
8197 	int ret = TEST_SUCCESS;
8198 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8199 				rte_cryptodev_get_sec_ctx(
8200 				ts_params->valid_devs[0]);
8201 
8202 	/* Verify the capabilities */
8203 	struct rte_security_capability_idx sec_cap_idx;
8204 
8205 	sec_cap_idx.action = ut_params->type;
8206 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8207 	sec_cap_idx.pdcp.domain = domain;
8208 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8209 		return TEST_SKIPPED;
8210 
8211 	/* Generate test mbuf data */
8212 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8213 
8214 	/* clear mbuf payload */
8215 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8216 			rte_pktmbuf_tailroom(ut_params->ibuf));
8217 
8218 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8219 						  input_vec_len);
8220 	memcpy(plaintext, input_vec, input_vec_len);
8221 
8222 	/* Out of place support */
8223 	if (oop) {
8224 		/*
8225 		 * For out-op-place we need to alloc another mbuf
8226 		 */
8227 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8228 		rte_pktmbuf_append(ut_params->obuf, output_vec_len);
8229 	}
8230 
8231 	/* Setup Cipher Parameters */
8232 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8233 	ut_params->cipher_xform.cipher.algo = cipher_alg;
8234 	ut_params->cipher_xform.cipher.op = opc;
8235 	ut_params->cipher_xform.cipher.key.data = cipher_key;
8236 	ut_params->cipher_xform.cipher.key.length = cipher_key_len;
8237 	ut_params->cipher_xform.cipher.iv.length =
8238 				packet_direction ? 4 : 0;
8239 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8240 
8241 	/* Setup HMAC Parameters if ICV header is required */
8242 	if (auth_alg != 0) {
8243 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8244 		ut_params->auth_xform.next = NULL;
8245 		ut_params->auth_xform.auth.algo = auth_alg;
8246 		ut_params->auth_xform.auth.op = opa;
8247 		ut_params->auth_xform.auth.key.data = auth_key;
8248 		ut_params->auth_xform.auth.key.length = auth_key_len;
8249 
8250 		ut_params->cipher_xform.next = &ut_params->auth_xform;
8251 	} else {
8252 		ut_params->cipher_xform.next = NULL;
8253 	}
8254 
8255 	struct rte_security_session_conf sess_conf = {
8256 		.action_type = ut_params->type,
8257 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
8258 		{.pdcp = {
8259 			.bearer = bearer,
8260 			.domain = domain,
8261 			.pkt_dir = packet_direction,
8262 			.sn_size = sn_size,
8263 			.hfn = packet_direction ? 0 : hfn,
8264 			/**
8265 			 * hfn can be set as pdcp_test_hfn[i]
8266 			 * if hfn_ovrd is not set. Here, PDCP
8267 			 * packet direction is just used to
8268 			 * run half of the cases with session
8269 			 * HFN and other half with per packet
8270 			 * HFN.
8271 			 */
8272 			.hfn_threshold = hfn_threshold,
8273 			.hfn_ovrd = packet_direction ? 1 : 0,
8274 			.sdap_enabled = sdap,
8275 		} },
8276 		.crypto_xform = &ut_params->cipher_xform
8277 	};
8278 
8279 	/* Create security session */
8280 	ut_params->sec_session = rte_security_session_create(ctx,
8281 				&sess_conf, ts_params->session_mpool,
8282 				ts_params->session_priv_mpool);
8283 
8284 	if (!ut_params->sec_session) {
8285 		printf("TestCase %s()-%d line %d failed %s: ",
8286 			__func__, i, __LINE__, "Failed to allocate session");
8287 		ret = TEST_FAILED;
8288 		goto on_err;
8289 	}
8290 
8291 	/* Generate crypto op data structure */
8292 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8293 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8294 	if (!ut_params->op) {
8295 		printf("TestCase %s()-%d line %d failed %s: ",
8296 			__func__, i, __LINE__,
8297 			"Failed to allocate symmetric crypto operation struct");
8298 		ret = TEST_FAILED;
8299 		goto on_err;
8300 	}
8301 
8302 	uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
8303 					uint32_t *, IV_OFFSET);
8304 	*per_pkt_hfn = packet_direction ? hfn : 0;
8305 
8306 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8307 
8308 	/* set crypto operation source mbuf */
8309 	ut_params->op->sym->m_src = ut_params->ibuf;
8310 	if (oop)
8311 		ut_params->op->sym->m_dst = ut_params->obuf;
8312 
8313 	/* Process crypto operation */
8314 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8315 		== NULL) {
8316 		printf("TestCase %s()-%d line %d failed %s: ",
8317 			__func__, i, __LINE__,
8318 			"failed to process sym crypto op");
8319 		ret = TEST_FAILED;
8320 		goto on_err;
8321 	}
8322 
8323 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8324 		printf("TestCase %s()-%d line %d failed %s: ",
8325 			__func__, i, __LINE__, "crypto op processing failed");
8326 		ret = TEST_FAILED;
8327 		goto on_err;
8328 	}
8329 
8330 	/* Validate obuf */
8331 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8332 			uint8_t *);
8333 	if (oop) {
8334 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8335 				uint8_t *);
8336 	}
8337 
8338 	if (memcmp(ciphertext, output_vec, output_vec_len)) {
8339 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8340 		rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
8341 		rte_hexdump(stdout, "reference", output_vec, output_vec_len);
8342 		ret = TEST_FAILED;
8343 		goto on_err;
8344 	}
8345 
8346 on_err:
8347 	rte_crypto_op_free(ut_params->op);
8348 	ut_params->op = NULL;
8349 
8350 	if (ut_params->sec_session)
8351 		rte_security_session_destroy(ctx, ut_params->sec_session);
8352 	ut_params->sec_session = NULL;
8353 
8354 	rte_pktmbuf_free(ut_params->ibuf);
8355 	ut_params->ibuf = NULL;
8356 	if (oop) {
8357 		rte_pktmbuf_free(ut_params->obuf);
8358 		ut_params->obuf = NULL;
8359 	}
8360 
8361 	return ret;
8362 }
8363 
8364 static int
8365 test_pdcp_proto_SGL(int i, int oop,
8366 	enum rte_crypto_cipher_operation opc,
8367 	enum rte_crypto_auth_operation opa,
8368 	uint8_t *input_vec,
8369 	unsigned int input_vec_len,
8370 	uint8_t *output_vec,
8371 	unsigned int output_vec_len,
8372 	uint32_t fragsz,
8373 	uint32_t fragsz_oop)
8374 {
8375 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8376 	struct crypto_unittest_params *ut_params = &unittest_params;
8377 	uint8_t *plaintext;
8378 	struct rte_mbuf *buf, *buf_oop = NULL;
8379 	int ret = TEST_SUCCESS;
8380 	int to_trn = 0;
8381 	int to_trn_tbl[16];
8382 	int segs = 1;
8383 	unsigned int trn_data = 0;
8384 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8385 				rte_cryptodev_get_sec_ctx(
8386 				ts_params->valid_devs[0]);
8387 
8388 	/* Verify the capabilities */
8389 	struct rte_security_capability_idx sec_cap_idx;
8390 
8391 	sec_cap_idx.action = ut_params->type;
8392 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8393 	sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
8394 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8395 		return TEST_SKIPPED;
8396 
8397 	if (fragsz > input_vec_len)
8398 		fragsz = input_vec_len;
8399 
8400 	uint16_t plaintext_len = fragsz;
8401 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
8402 
8403 	if (fragsz_oop > output_vec_len)
8404 		frag_size_oop = output_vec_len;
8405 
8406 	int ecx = 0;
8407 	if (input_vec_len % fragsz != 0) {
8408 		if (input_vec_len / fragsz + 1 > 16)
8409 			return 1;
8410 	} else if (input_vec_len / fragsz > 16)
8411 		return 1;
8412 
8413 	/* Out of place support */
8414 	if (oop) {
8415 		/*
8416 		 * For out-op-place we need to alloc another mbuf
8417 		 */
8418 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8419 		rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
8420 		buf_oop = ut_params->obuf;
8421 	}
8422 
8423 	/* Generate test mbuf data */
8424 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8425 
8426 	/* clear mbuf payload */
8427 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8428 			rte_pktmbuf_tailroom(ut_params->ibuf));
8429 
8430 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8431 						  plaintext_len);
8432 	memcpy(plaintext, input_vec, plaintext_len);
8433 	trn_data += plaintext_len;
8434 
8435 	buf = ut_params->ibuf;
8436 
8437 	/*
8438 	 * Loop until no more fragments
8439 	 */
8440 
8441 	while (trn_data < input_vec_len) {
8442 		++segs;
8443 		to_trn = (input_vec_len - trn_data < fragsz) ?
8444 				(input_vec_len - trn_data) : fragsz;
8445 
8446 		to_trn_tbl[ecx++] = to_trn;
8447 
8448 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8449 		buf = buf->next;
8450 
8451 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8452 				rte_pktmbuf_tailroom(buf));
8453 
8454 		/* OOP */
8455 		if (oop && !fragsz_oop) {
8456 			buf_oop->next =
8457 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
8458 			buf_oop = buf_oop->next;
8459 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8460 					0, rte_pktmbuf_tailroom(buf_oop));
8461 			rte_pktmbuf_append(buf_oop, to_trn);
8462 		}
8463 
8464 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8465 				to_trn);
8466 
8467 		memcpy(plaintext, input_vec + trn_data, to_trn);
8468 		trn_data += to_trn;
8469 	}
8470 
8471 	ut_params->ibuf->nb_segs = segs;
8472 
8473 	segs = 1;
8474 	if (fragsz_oop && oop) {
8475 		to_trn = 0;
8476 		ecx = 0;
8477 
8478 		trn_data = frag_size_oop;
8479 		while (trn_data < output_vec_len) {
8480 			++segs;
8481 			to_trn =
8482 				(output_vec_len - trn_data <
8483 						frag_size_oop) ?
8484 				(output_vec_len - trn_data) :
8485 						frag_size_oop;
8486 
8487 			to_trn_tbl[ecx++] = to_trn;
8488 
8489 			buf_oop->next =
8490 				rte_pktmbuf_alloc(ts_params->mbuf_pool);
8491 			buf_oop = buf_oop->next;
8492 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8493 					0, rte_pktmbuf_tailroom(buf_oop));
8494 			rte_pktmbuf_append(buf_oop, to_trn);
8495 
8496 			trn_data += to_trn;
8497 		}
8498 		ut_params->obuf->nb_segs = segs;
8499 	}
8500 
8501 	/* Setup Cipher Parameters */
8502 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8503 	ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
8504 	ut_params->cipher_xform.cipher.op = opc;
8505 	ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
8506 	ut_params->cipher_xform.cipher.key.length =
8507 					pdcp_test_params[i].cipher_key_len;
8508 	ut_params->cipher_xform.cipher.iv.length = 0;
8509 
8510 	/* Setup HMAC Parameters if ICV header is required */
8511 	if (pdcp_test_params[i].auth_alg != 0) {
8512 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8513 		ut_params->auth_xform.next = NULL;
8514 		ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
8515 		ut_params->auth_xform.auth.op = opa;
8516 		ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
8517 		ut_params->auth_xform.auth.key.length =
8518 					pdcp_test_params[i].auth_key_len;
8519 
8520 		ut_params->cipher_xform.next = &ut_params->auth_xform;
8521 	} else {
8522 		ut_params->cipher_xform.next = NULL;
8523 	}
8524 
8525 	struct rte_security_session_conf sess_conf = {
8526 		.action_type = ut_params->type,
8527 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
8528 		{.pdcp = {
8529 			.bearer = pdcp_test_bearer[i],
8530 			.domain = pdcp_test_params[i].domain,
8531 			.pkt_dir = pdcp_test_packet_direction[i],
8532 			.sn_size = pdcp_test_data_sn_size[i],
8533 			.hfn = pdcp_test_hfn[i],
8534 			.hfn_threshold = pdcp_test_hfn_threshold[i],
8535 			.hfn_ovrd = 0,
8536 		} },
8537 		.crypto_xform = &ut_params->cipher_xform
8538 	};
8539 
8540 	/* Create security session */
8541 	ut_params->sec_session = rte_security_session_create(ctx,
8542 				&sess_conf, ts_params->session_mpool,
8543 				ts_params->session_priv_mpool);
8544 
8545 	if (!ut_params->sec_session) {
8546 		printf("TestCase %s()-%d line %d failed %s: ",
8547 			__func__, i, __LINE__, "Failed to allocate session");
8548 		ret = TEST_FAILED;
8549 		goto on_err;
8550 	}
8551 
8552 	/* Generate crypto op data structure */
8553 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8554 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8555 	if (!ut_params->op) {
8556 		printf("TestCase %s()-%d line %d failed %s: ",
8557 			__func__, i, __LINE__,
8558 			"Failed to allocate symmetric crypto operation struct");
8559 		ret = TEST_FAILED;
8560 		goto on_err;
8561 	}
8562 
8563 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8564 
8565 	/* set crypto operation source mbuf */
8566 	ut_params->op->sym->m_src = ut_params->ibuf;
8567 	if (oop)
8568 		ut_params->op->sym->m_dst = ut_params->obuf;
8569 
8570 	/* Process crypto operation */
8571 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8572 		== NULL) {
8573 		printf("TestCase %s()-%d line %d failed %s: ",
8574 			__func__, i, __LINE__,
8575 			"failed to process sym crypto op");
8576 		ret = TEST_FAILED;
8577 		goto on_err;
8578 	}
8579 
8580 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8581 		printf("TestCase %s()-%d line %d failed %s: ",
8582 			__func__, i, __LINE__, "crypto op processing failed");
8583 		ret = TEST_FAILED;
8584 		goto on_err;
8585 	}
8586 
8587 	/* Validate obuf */
8588 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8589 			uint8_t *);
8590 	if (oop) {
8591 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8592 				uint8_t *);
8593 	}
8594 	if (fragsz_oop)
8595 		fragsz = frag_size_oop;
8596 	if (memcmp(ciphertext, output_vec, fragsz)) {
8597 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8598 		rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8599 		rte_hexdump(stdout, "reference", output_vec, fragsz);
8600 		ret = TEST_FAILED;
8601 		goto on_err;
8602 	}
8603 
8604 	buf = ut_params->op->sym->m_src->next;
8605 	if (oop)
8606 		buf = ut_params->op->sym->m_dst->next;
8607 
8608 	unsigned int off = fragsz;
8609 
8610 	ecx = 0;
8611 	while (buf) {
8612 		ciphertext = rte_pktmbuf_mtod(buf,
8613 				uint8_t *);
8614 		if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8615 			printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8616 			rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8617 			rte_hexdump(stdout, "reference", output_vec + off,
8618 					to_trn_tbl[ecx]);
8619 			ret = TEST_FAILED;
8620 			goto on_err;
8621 		}
8622 		off += to_trn_tbl[ecx++];
8623 		buf = buf->next;
8624 	}
8625 on_err:
8626 	rte_crypto_op_free(ut_params->op);
8627 	ut_params->op = NULL;
8628 
8629 	if (ut_params->sec_session)
8630 		rte_security_session_destroy(ctx, ut_params->sec_session);
8631 	ut_params->sec_session = NULL;
8632 
8633 	rte_pktmbuf_free(ut_params->ibuf);
8634 	ut_params->ibuf = NULL;
8635 	if (oop) {
8636 		rte_pktmbuf_free(ut_params->obuf);
8637 		ut_params->obuf = NULL;
8638 	}
8639 
8640 	return ret;
8641 }
8642 
8643 int
8644 test_pdcp_proto_cplane_encap(int i)
8645 {
8646 	return test_pdcp_proto(
8647 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8648 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8649 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8650 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8651 		pdcp_test_params[i].cipher_key_len,
8652 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8653 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8654 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8655 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8656 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8657 }
8658 
8659 int
8660 test_pdcp_proto_uplane_encap(int i)
8661 {
8662 	return test_pdcp_proto(
8663 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8664 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8665 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8666 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8667 		pdcp_test_params[i].cipher_key_len,
8668 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8669 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8670 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8671 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8672 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8673 }
8674 
8675 int
8676 test_pdcp_proto_uplane_encap_with_int(int i)
8677 {
8678 	return test_pdcp_proto(
8679 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8680 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8681 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8682 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8683 		pdcp_test_params[i].cipher_key_len,
8684 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8685 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8686 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8687 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8688 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8689 }
8690 
8691 int
8692 test_pdcp_proto_cplane_decap(int i)
8693 {
8694 	return test_pdcp_proto(
8695 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8696 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8697 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8698 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8699 		pdcp_test_params[i].cipher_key_len,
8700 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8701 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8702 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8703 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8704 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8705 }
8706 
8707 int
8708 test_pdcp_proto_uplane_decap(int i)
8709 {
8710 	return test_pdcp_proto(
8711 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8712 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8713 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8714 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8715 		pdcp_test_params[i].cipher_key_len,
8716 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8717 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8718 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8719 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8720 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8721 }
8722 
8723 int
8724 test_pdcp_proto_uplane_decap_with_int(int i)
8725 {
8726 	return test_pdcp_proto(
8727 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8728 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8729 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8730 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8731 		pdcp_test_params[i].cipher_key_len,
8732 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8733 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8734 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8735 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8736 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8737 }
8738 
8739 static int
8740 test_PDCP_PROTO_SGL_in_place_32B(void)
8741 {
8742 	/* i can be used for running any PDCP case
8743 	 * In this case it is uplane 12-bit AES-SNOW DL encap
8744 	 */
8745 	int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
8746 	return test_pdcp_proto_SGL(i, IN_PLACE,
8747 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8748 			RTE_CRYPTO_AUTH_OP_GENERATE,
8749 			pdcp_test_data_in[i],
8750 			pdcp_test_data_in_len[i],
8751 			pdcp_test_data_out[i],
8752 			pdcp_test_data_in_len[i]+4,
8753 			32, 0);
8754 }
8755 static int
8756 test_PDCP_PROTO_SGL_oop_32B_128B(void)
8757 {
8758 	/* i can be used for running any PDCP case
8759 	 * In this case it is uplane 18-bit NULL-NULL DL encap
8760 	 */
8761 	int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
8762 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8763 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8764 			RTE_CRYPTO_AUTH_OP_GENERATE,
8765 			pdcp_test_data_in[i],
8766 			pdcp_test_data_in_len[i],
8767 			pdcp_test_data_out[i],
8768 			pdcp_test_data_in_len[i]+4,
8769 			32, 128);
8770 }
8771 static int
8772 test_PDCP_PROTO_SGL_oop_32B_40B(void)
8773 {
8774 	/* i can be used for running any PDCP case
8775 	 * In this case it is uplane 18-bit AES DL encap
8776 	 */
8777 	int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
8778 			+ DOWNLINK;
8779 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8780 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8781 			RTE_CRYPTO_AUTH_OP_GENERATE,
8782 			pdcp_test_data_in[i],
8783 			pdcp_test_data_in_len[i],
8784 			pdcp_test_data_out[i],
8785 			pdcp_test_data_in_len[i],
8786 			32, 40);
8787 }
8788 static int
8789 test_PDCP_PROTO_SGL_oop_128B_32B(void)
8790 {
8791 	/* i can be used for running any PDCP case
8792 	 * In this case it is cplane 12-bit AES-ZUC DL encap
8793 	 */
8794 	int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
8795 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8796 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8797 			RTE_CRYPTO_AUTH_OP_GENERATE,
8798 			pdcp_test_data_in[i],
8799 			pdcp_test_data_in_len[i],
8800 			pdcp_test_data_out[i],
8801 			pdcp_test_data_in_len[i]+4,
8802 			128, 32);
8803 }
8804 
8805 static int
8806 test_PDCP_SDAP_PROTO_encap_all(void)
8807 {
8808 	int i = 0, size = 0;
8809 	int err, all_err = TEST_SUCCESS;
8810 	const struct pdcp_sdap_test *cur_test;
8811 
8812 	size = RTE_DIM(list_pdcp_sdap_tests);
8813 
8814 	for (i = 0; i < size; i++) {
8815 		cur_test = &list_pdcp_sdap_tests[i];
8816 		err = test_pdcp_proto(
8817 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8818 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8819 			cur_test->in_len, cur_test->data_out,
8820 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8821 			cur_test->param.cipher_alg, cur_test->cipher_key,
8822 			cur_test->param.cipher_key_len,
8823 			cur_test->param.auth_alg,
8824 			cur_test->auth_key, cur_test->param.auth_key_len,
8825 			cur_test->bearer, cur_test->param.domain,
8826 			cur_test->packet_direction, cur_test->sn_size,
8827 			cur_test->hfn,
8828 			cur_test->hfn_threshold, SDAP_ENABLED);
8829 		if (err) {
8830 			printf("\t%d) %s: Encapsulation failed\n",
8831 					cur_test->test_idx,
8832 					cur_test->param.name);
8833 			err = TEST_FAILED;
8834 		} else {
8835 			printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
8836 					cur_test->param.name);
8837 			err = TEST_SUCCESS;
8838 		}
8839 		all_err += err;
8840 	}
8841 
8842 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8843 
8844 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8845 }
8846 
8847 static int
8848 test_PDCP_PROTO_short_mac(void)
8849 {
8850 	int i = 0, size = 0;
8851 	int err, all_err = TEST_SUCCESS;
8852 	const struct pdcp_short_mac_test *cur_test;
8853 
8854 	size = RTE_DIM(list_pdcp_smac_tests);
8855 
8856 	for (i = 0; i < size; i++) {
8857 		cur_test = &list_pdcp_smac_tests[i];
8858 		err = test_pdcp_proto(
8859 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8860 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8861 			cur_test->in_len, cur_test->data_out,
8862 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8863 			RTE_CRYPTO_CIPHER_NULL, NULL,
8864 			0, cur_test->param.auth_alg,
8865 			cur_test->auth_key, cur_test->param.auth_key_len,
8866 			0, cur_test->param.domain, 0, 0,
8867 			0, 0, 0);
8868 		if (err) {
8869 			printf("\t%d) %s: Short MAC test failed\n",
8870 					cur_test->test_idx,
8871 					cur_test->param.name);
8872 			err = TEST_FAILED;
8873 		} else {
8874 			printf("\t%d) %s: Short MAC test PASS\n",
8875 					cur_test->test_idx,
8876 					cur_test->param.name);
8877 			rte_hexdump(stdout, "MAC I",
8878 				    cur_test->data_out + cur_test->in_len + 2,
8879 				    2);
8880 			err = TEST_SUCCESS;
8881 		}
8882 		all_err += err;
8883 	}
8884 
8885 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8886 
8887 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8888 
8889 }
8890 
8891 static int
8892 test_PDCP_SDAP_PROTO_decap_all(void)
8893 {
8894 	int i = 0, size = 0;
8895 	int err, all_err = TEST_SUCCESS;
8896 	const struct pdcp_sdap_test *cur_test;
8897 
8898 	size = RTE_DIM(list_pdcp_sdap_tests);
8899 
8900 	for (i = 0; i < size; i++) {
8901 		cur_test = &list_pdcp_sdap_tests[i];
8902 		err = test_pdcp_proto(
8903 			i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
8904 			RTE_CRYPTO_AUTH_OP_VERIFY,
8905 			cur_test->data_out,
8906 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8907 			cur_test->data_in, cur_test->in_len,
8908 			cur_test->param.cipher_alg,
8909 			cur_test->cipher_key, cur_test->param.cipher_key_len,
8910 			cur_test->param.auth_alg, cur_test->auth_key,
8911 			cur_test->param.auth_key_len, cur_test->bearer,
8912 			cur_test->param.domain, cur_test->packet_direction,
8913 			cur_test->sn_size, cur_test->hfn,
8914 			cur_test->hfn_threshold, SDAP_ENABLED);
8915 		if (err) {
8916 			printf("\t%d) %s: Decapsulation failed\n",
8917 					cur_test->test_idx,
8918 					cur_test->param.name);
8919 			err = TEST_FAILED;
8920 		} else {
8921 			printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
8922 					cur_test->param.name);
8923 			err = TEST_SUCCESS;
8924 		}
8925 		all_err += err;
8926 	}
8927 
8928 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8929 
8930 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8931 }
8932 
8933 static int
8934 test_ipsec_proto_process(const struct ipsec_test_data td[],
8935 			 struct ipsec_test_data res_d[],
8936 			 int nb_td,
8937 			 bool silent,
8938 			 const struct ipsec_test_flags *flags)
8939 {
8940 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8941 	struct crypto_unittest_params *ut_params = &unittest_params;
8942 	struct rte_security_capability_idx sec_cap_idx;
8943 	const struct rte_security_capability *sec_cap;
8944 	struct rte_security_ipsec_xform ipsec_xform;
8945 	uint8_t dev_id = ts_params->valid_devs[0];
8946 	enum rte_security_ipsec_sa_direction dir;
8947 	struct ipsec_test_data *res_d_tmp = NULL;
8948 	uint32_t src = RTE_IPV4(192, 168, 1, 0);
8949 	uint32_t dst = RTE_IPV4(192, 168, 1, 1);
8950 	int salt_len, i, ret = TEST_SUCCESS;
8951 	struct rte_security_ctx *ctx;
8952 	uint8_t *input_text;
8953 	uint32_t verify;
8954 
8955 	ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
8956 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
8957 
8958 	/* Use first test data to create session */
8959 
8960 	/* Copy IPsec xform */
8961 	memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform));
8962 
8963 	dir = ipsec_xform.direction;
8964 	verify = flags->tunnel_hdr_verify;
8965 
8966 	if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) {
8967 		if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR)
8968 			src += 1;
8969 		else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR)
8970 			dst += 1;
8971 	}
8972 
8973 	memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src, sizeof(src));
8974 	memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst, sizeof(dst));
8975 
8976 	ctx = rte_cryptodev_get_sec_ctx(dev_id);
8977 
8978 	sec_cap_idx.action = ut_params->type;
8979 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC;
8980 	sec_cap_idx.ipsec.proto = ipsec_xform.proto;
8981 	sec_cap_idx.ipsec.mode = ipsec_xform.mode;
8982 	sec_cap_idx.ipsec.direction = ipsec_xform.direction;
8983 
8984 	if (flags->udp_encap)
8985 		ipsec_xform.options.udp_encap = 1;
8986 
8987 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
8988 	if (sec_cap == NULL)
8989 		return TEST_SKIPPED;
8990 
8991 	/* Copy cipher session parameters */
8992 	if (td[0].aead) {
8993 		memcpy(&ut_params->aead_xform, &td[0].xform.aead,
8994 		       sizeof(ut_params->aead_xform));
8995 		ut_params->aead_xform.aead.key.data = td[0].key.data;
8996 		ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
8997 
8998 		/* Verify crypto capabilities */
8999 		if (test_ipsec_crypto_caps_aead_verify(
9000 				sec_cap,
9001 				&ut_params->aead_xform) != 0) {
9002 			if (!silent)
9003 				RTE_LOG(INFO, USER1,
9004 					"Crypto capabilities not supported\n");
9005 			return TEST_SKIPPED;
9006 		}
9007 	} else {
9008 		/* Only AEAD supported now */
9009 		return TEST_SKIPPED;
9010 	}
9011 
9012 	if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0)
9013 		return TEST_SKIPPED;
9014 
9015 	salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len);
9016 	memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len);
9017 
9018 	struct rte_security_session_conf sess_conf = {
9019 		.action_type = ut_params->type,
9020 		.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
9021 		.ipsec = ipsec_xform,
9022 		.crypto_xform = &ut_params->aead_xform,
9023 	};
9024 
9025 	/* Create security session */
9026 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9027 					ts_params->session_mpool,
9028 					ts_params->session_priv_mpool);
9029 
9030 	if (ut_params->sec_session == NULL)
9031 		return TEST_SKIPPED;
9032 
9033 	for (i = 0; i < nb_td; i++) {
9034 		/* Setup source mbuf payload */
9035 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9036 		memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9037 				rte_pktmbuf_tailroom(ut_params->ibuf));
9038 
9039 		input_text = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9040 				td[i].input_text.len);
9041 
9042 		memcpy(input_text, td[i].input_text.data,
9043 		       td[i].input_text.len);
9044 
9045 		/* Generate crypto op data structure */
9046 		ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9047 					RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9048 		if (!ut_params->op) {
9049 			printf("TestCase %s line %d: %s\n",
9050 				__func__, __LINE__,
9051 				"failed to allocate crypto op");
9052 			ret = TEST_FAILED;
9053 			goto crypto_op_free;
9054 		}
9055 
9056 		/* Attach session to operation */
9057 		rte_security_attach_session(ut_params->op,
9058 					    ut_params->sec_session);
9059 
9060 		/* Set crypto operation mbufs */
9061 		ut_params->op->sym->m_src = ut_params->ibuf;
9062 		ut_params->op->sym->m_dst = NULL;
9063 
9064 		/* Copy IV in crypto operation when IV generation is disabled */
9065 		if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS &&
9066 		    ipsec_xform.options.iv_gen_disable == 1) {
9067 			uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op,
9068 								uint8_t *,
9069 								IV_OFFSET);
9070 			int len;
9071 
9072 			if (td[i].aead)
9073 				len = td[i].xform.aead.aead.iv.length;
9074 			else
9075 				len = td[i].xform.chain.cipher.cipher.iv.length;
9076 
9077 			memcpy(iv, td[i].iv.data, len);
9078 		}
9079 
9080 		/* Process crypto operation */
9081 		process_crypto_request(dev_id, ut_params->op);
9082 
9083 		ret = test_ipsec_status_check(ut_params->op, flags, dir, i + 1);
9084 		if (ret != TEST_SUCCESS)
9085 			goto crypto_op_free;
9086 
9087 		if (res_d != NULL)
9088 			res_d_tmp = &res_d[i];
9089 
9090 		ret = test_ipsec_post_process(ut_params->ibuf, &td[i],
9091 					      res_d_tmp, silent, flags);
9092 		if (ret != TEST_SUCCESS)
9093 			goto crypto_op_free;
9094 
9095 		rte_crypto_op_free(ut_params->op);
9096 		ut_params->op = NULL;
9097 
9098 		rte_pktmbuf_free(ut_params->ibuf);
9099 		ut_params->ibuf = NULL;
9100 	}
9101 
9102 crypto_op_free:
9103 	rte_crypto_op_free(ut_params->op);
9104 	ut_params->op = NULL;
9105 
9106 	rte_pktmbuf_free(ut_params->ibuf);
9107 	ut_params->ibuf = NULL;
9108 
9109 	if (ut_params->sec_session)
9110 		rte_security_session_destroy(ctx, ut_params->sec_session);
9111 	ut_params->sec_session = NULL;
9112 
9113 	return ret;
9114 }
9115 
9116 static int
9117 test_ipsec_proto_known_vec(const void *test_data)
9118 {
9119 	struct ipsec_test_data td_outb;
9120 	struct ipsec_test_flags flags;
9121 
9122 	memset(&flags, 0, sizeof(flags));
9123 
9124 	memcpy(&td_outb, test_data, sizeof(td_outb));
9125 
9126 	/* Disable IV gen to be able to test with known vectors */
9127 	td_outb.ipsec_xform.options.iv_gen_disable = 1;
9128 
9129 	return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
9130 }
9131 
9132 static int
9133 test_ipsec_proto_known_vec_inb(const void *td_outb)
9134 {
9135 	struct ipsec_test_flags flags;
9136 	struct ipsec_test_data td_inb;
9137 
9138 	memset(&flags, 0, sizeof(flags));
9139 
9140 	test_ipsec_td_in_from_out(td_outb, &td_inb);
9141 
9142 	return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags);
9143 }
9144 
9145 static int
9146 test_ipsec_proto_all(const struct ipsec_test_flags *flags)
9147 {
9148 	struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
9149 	struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
9150 	unsigned int i, nb_pkts = 1, pass_cnt = 0;
9151 	int ret;
9152 
9153 	if (flags->iv_gen ||
9154 	    flags->sa_expiry_pkts_soft ||
9155 	    flags->sa_expiry_pkts_hard)
9156 		nb_pkts = IPSEC_TEST_PACKETS_MAX;
9157 
9158 	for (i = 0; i < RTE_DIM(aead_list); i++) {
9159 		test_ipsec_td_prepare(&aead_list[i],
9160 				      NULL,
9161 				      flags,
9162 				      td_outb,
9163 				      nb_pkts);
9164 
9165 		ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
9166 					       flags);
9167 		if (ret == TEST_SKIPPED)
9168 			continue;
9169 
9170 		if (ret == TEST_FAILED)
9171 			return TEST_FAILED;
9172 
9173 		test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags);
9174 
9175 		ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
9176 					       flags);
9177 		if (ret == TEST_SKIPPED)
9178 			continue;
9179 
9180 		if (ret == TEST_FAILED)
9181 			return TEST_FAILED;
9182 
9183 		if (flags->display_alg)
9184 			test_ipsec_display_alg(&aead_list[i], NULL);
9185 
9186 		pass_cnt++;
9187 	}
9188 
9189 	if (pass_cnt > 0)
9190 		return TEST_SUCCESS;
9191 	else
9192 		return TEST_SKIPPED;
9193 }
9194 
9195 static int
9196 test_ipsec_proto_display_list(const void *data __rte_unused)
9197 {
9198 	struct ipsec_test_flags flags;
9199 
9200 	memset(&flags, 0, sizeof(flags));
9201 
9202 	flags.display_alg = true;
9203 
9204 	return test_ipsec_proto_all(&flags);
9205 }
9206 
9207 static int
9208 test_ipsec_proto_iv_gen(const void *data __rte_unused)
9209 {
9210 	struct ipsec_test_flags flags;
9211 
9212 	memset(&flags, 0, sizeof(flags));
9213 
9214 	flags.iv_gen = true;
9215 
9216 	return test_ipsec_proto_all(&flags);
9217 }
9218 
9219 static int
9220 test_ipsec_proto_sa_exp_pkts_soft(const void *data __rte_unused)
9221 {
9222 	struct ipsec_test_flags flags;
9223 
9224 	memset(&flags, 0, sizeof(flags));
9225 
9226 	flags.sa_expiry_pkts_soft = true;
9227 
9228 	return test_ipsec_proto_all(&flags);
9229 }
9230 
9231 static int
9232 test_ipsec_proto_sa_exp_pkts_hard(const void *data __rte_unused)
9233 {
9234 	struct ipsec_test_flags flags;
9235 
9236 	memset(&flags, 0, sizeof(flags));
9237 
9238 	flags.sa_expiry_pkts_hard = true;
9239 
9240 	return test_ipsec_proto_all(&flags);
9241 }
9242 
9243 static int
9244 test_ipsec_proto_err_icv_corrupt(const void *data __rte_unused)
9245 {
9246 	struct ipsec_test_flags flags;
9247 
9248 	memset(&flags, 0, sizeof(flags));
9249 
9250 	flags.icv_corrupt = true;
9251 
9252 	return test_ipsec_proto_all(&flags);
9253 }
9254 
9255 static int
9256 test_ipsec_proto_udp_encap(const void *data __rte_unused)
9257 {
9258 	struct ipsec_test_flags flags;
9259 
9260 	memset(&flags, 0, sizeof(flags));
9261 
9262 	flags.udp_encap = true;
9263 
9264 	return test_ipsec_proto_all(&flags);
9265 }
9266 
9267 static int
9268 test_ipsec_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused)
9269 {
9270 	struct ipsec_test_flags flags;
9271 
9272 	memset(&flags, 0, sizeof(flags));
9273 
9274 	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
9275 
9276 	return test_ipsec_proto_all(&flags);
9277 }
9278 
9279 static int
9280 test_ipsec_proto_tunnel_dst_addr_verify(const void *data __rte_unused)
9281 {
9282 	struct ipsec_test_flags flags;
9283 
9284 	memset(&flags, 0, sizeof(flags));
9285 
9286 	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR;
9287 
9288 	return test_ipsec_proto_all(&flags);
9289 }
9290 
9291 static int
9292 test_ipsec_proto_udp_ports_verify(const void *data __rte_unused)
9293 {
9294 	struct ipsec_test_flags flags;
9295 
9296 	memset(&flags, 0, sizeof(flags));
9297 
9298 	flags.udp_encap = true;
9299 	flags.udp_ports_verify = true;
9300 
9301 	return test_ipsec_proto_all(&flags);
9302 }
9303 
9304 static int
9305 test_ipsec_proto_inner_ip_csum(const void *data __rte_unused)
9306 {
9307 	struct ipsec_test_flags flags;
9308 
9309 	memset(&flags, 0, sizeof(flags));
9310 
9311 	flags.ip_csum = true;
9312 
9313 	return test_ipsec_proto_all(&flags);
9314 }
9315 
9316 static int
9317 test_ipsec_proto_inner_l4_csum(const void *data __rte_unused)
9318 {
9319 	struct ipsec_test_flags flags;
9320 
9321 	memset(&flags, 0, sizeof(flags));
9322 
9323 	flags.l4_csum = true;
9324 
9325 	return test_ipsec_proto_all(&flags);
9326 }
9327 
9328 static int
9329 test_PDCP_PROTO_all(void)
9330 {
9331 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9332 	struct crypto_unittest_params *ut_params = &unittest_params;
9333 	struct rte_cryptodev_info dev_info;
9334 	int status;
9335 
9336 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9337 	uint64_t feat_flags = dev_info.feature_flags;
9338 
9339 	if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
9340 		return TEST_SKIPPED;
9341 
9342 	/* Set action type */
9343 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9344 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9345 		gbl_action_type;
9346 
9347 	if (security_proto_supported(ut_params->type,
9348 			RTE_SECURITY_PROTOCOL_PDCP) < 0)
9349 		return TEST_SKIPPED;
9350 
9351 	status = test_PDCP_PROTO_cplane_encap_all();
9352 	status += test_PDCP_PROTO_cplane_decap_all();
9353 	status += test_PDCP_PROTO_uplane_encap_all();
9354 	status += test_PDCP_PROTO_uplane_decap_all();
9355 	status += test_PDCP_PROTO_SGL_in_place_32B();
9356 	status += test_PDCP_PROTO_SGL_oop_32B_128B();
9357 	status += test_PDCP_PROTO_SGL_oop_32B_40B();
9358 	status += test_PDCP_PROTO_SGL_oop_128B_32B();
9359 	status += test_PDCP_SDAP_PROTO_encap_all();
9360 	status += test_PDCP_SDAP_PROTO_decap_all();
9361 	status += test_PDCP_PROTO_short_mac();
9362 
9363 	if (status)
9364 		return TEST_FAILED;
9365 	else
9366 		return TEST_SUCCESS;
9367 }
9368 
9369 static int
9370 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td)
9371 {
9372 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9373 	struct crypto_unittest_params *ut_params = &unittest_params;
9374 	uint8_t *plaintext, *ciphertext;
9375 	uint8_t *iv_ptr;
9376 	int32_t cipher_len, crc_len;
9377 	uint32_t crc_data_len;
9378 	int ret = TEST_SUCCESS;
9379 
9380 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9381 					rte_cryptodev_get_sec_ctx(
9382 						ts_params->valid_devs[0]);
9383 
9384 	/* Verify the capabilities */
9385 	struct rte_security_capability_idx sec_cap_idx;
9386 	const struct rte_security_capability *sec_cap;
9387 	const struct rte_cryptodev_capabilities *crypto_cap;
9388 	const struct rte_cryptodev_symmetric_capability *sym_cap;
9389 	int j = 0;
9390 
9391 	sec_cap_idx.action = ut_params->type;
9392 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9393 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
9394 
9395 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9396 	if (sec_cap == NULL)
9397 		return TEST_SKIPPED;
9398 
9399 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9400 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9401 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9402 				crypto_cap->sym.xform_type ==
9403 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
9404 				crypto_cap->sym.cipher.algo ==
9405 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9406 			sym_cap = &crypto_cap->sym;
9407 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9408 						d_td->key.len,
9409 						d_td->iv.len) == 0)
9410 				break;
9411 		}
9412 	}
9413 
9414 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9415 		return TEST_SKIPPED;
9416 
9417 	/* Setup source mbuf payload */
9418 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9419 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9420 			rte_pktmbuf_tailroom(ut_params->ibuf));
9421 
9422 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9423 			d_td->ciphertext.len);
9424 
9425 	memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
9426 
9427 	/* Setup cipher session parameters */
9428 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9429 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9430 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
9431 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9432 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9433 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9434 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9435 	ut_params->cipher_xform.next = NULL;
9436 
9437 	/* Setup DOCSIS session parameters */
9438 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
9439 
9440 	struct rte_security_session_conf sess_conf = {
9441 		.action_type = ut_params->type,
9442 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9443 		.docsis = ut_params->docsis_xform,
9444 		.crypto_xform = &ut_params->cipher_xform,
9445 	};
9446 
9447 	/* Create security session */
9448 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9449 					ts_params->session_mpool,
9450 					ts_params->session_priv_mpool);
9451 
9452 	if (!ut_params->sec_session) {
9453 		printf("TestCase %s(%d) line %d: %s\n",
9454 			__func__, i, __LINE__, "failed to allocate session");
9455 		ret = TEST_FAILED;
9456 		goto on_err;
9457 	}
9458 
9459 	/* Generate crypto op data structure */
9460 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9461 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9462 	if (!ut_params->op) {
9463 		printf("TestCase %s(%d) line %d: %s\n",
9464 			__func__, i, __LINE__,
9465 			"failed to allocate symmetric crypto operation");
9466 		ret = TEST_FAILED;
9467 		goto on_err;
9468 	}
9469 
9470 	/* Setup CRC operation parameters */
9471 	crc_len = d_td->ciphertext.no_crc == false ?
9472 			(d_td->ciphertext.len -
9473 				d_td->ciphertext.crc_offset -
9474 				RTE_ETHER_CRC_LEN) :
9475 			0;
9476 	crc_len = crc_len > 0 ? crc_len : 0;
9477 	crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
9478 	ut_params->op->sym->auth.data.length = crc_len;
9479 	ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
9480 
9481 	/* Setup cipher operation parameters */
9482 	cipher_len = d_td->ciphertext.no_cipher == false ?
9483 			(d_td->ciphertext.len -
9484 				d_td->ciphertext.cipher_offset) :
9485 			0;
9486 	cipher_len = cipher_len > 0 ? cipher_len : 0;
9487 	ut_params->op->sym->cipher.data.length = cipher_len;
9488 	ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
9489 
9490 	/* Setup cipher IV */
9491 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9492 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9493 
9494 	/* Attach session to operation */
9495 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
9496 
9497 	/* Set crypto operation mbufs */
9498 	ut_params->op->sym->m_src = ut_params->ibuf;
9499 	ut_params->op->sym->m_dst = NULL;
9500 
9501 	/* Process crypto operation */
9502 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9503 			NULL) {
9504 		printf("TestCase %s(%d) line %d: %s\n",
9505 			__func__, i, __LINE__,
9506 			"failed to process security crypto op");
9507 		ret = TEST_FAILED;
9508 		goto on_err;
9509 	}
9510 
9511 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9512 		printf("TestCase %s(%d) line %d: %s\n",
9513 			__func__, i, __LINE__, "crypto op processing failed");
9514 		ret = TEST_FAILED;
9515 		goto on_err;
9516 	}
9517 
9518 	/* Validate plaintext */
9519 	plaintext = ciphertext;
9520 
9521 	if (memcmp(plaintext, d_td->plaintext.data,
9522 			d_td->plaintext.len - crc_data_len)) {
9523 		printf("TestCase %s(%d) line %d: %s\n",
9524 			__func__, i, __LINE__, "plaintext not as expected\n");
9525 		rte_hexdump(stdout, "expected", d_td->plaintext.data,
9526 				d_td->plaintext.len);
9527 		rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
9528 		ret = TEST_FAILED;
9529 		goto on_err;
9530 	}
9531 
9532 on_err:
9533 	rte_crypto_op_free(ut_params->op);
9534 	ut_params->op = NULL;
9535 
9536 	if (ut_params->sec_session)
9537 		rte_security_session_destroy(ctx, ut_params->sec_session);
9538 	ut_params->sec_session = NULL;
9539 
9540 	rte_pktmbuf_free(ut_params->ibuf);
9541 	ut_params->ibuf = NULL;
9542 
9543 	return ret;
9544 }
9545 
9546 static int
9547 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td)
9548 {
9549 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9550 	struct crypto_unittest_params *ut_params = &unittest_params;
9551 	uint8_t *plaintext, *ciphertext;
9552 	uint8_t *iv_ptr;
9553 	int32_t cipher_len, crc_len;
9554 	int ret = TEST_SUCCESS;
9555 
9556 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9557 					rte_cryptodev_get_sec_ctx(
9558 						ts_params->valid_devs[0]);
9559 
9560 	/* Verify the capabilities */
9561 	struct rte_security_capability_idx sec_cap_idx;
9562 	const struct rte_security_capability *sec_cap;
9563 	const struct rte_cryptodev_capabilities *crypto_cap;
9564 	const struct rte_cryptodev_symmetric_capability *sym_cap;
9565 	int j = 0;
9566 
9567 	sec_cap_idx.action = ut_params->type;
9568 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9569 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9570 
9571 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9572 	if (sec_cap == NULL)
9573 		return TEST_SKIPPED;
9574 
9575 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9576 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9577 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9578 				crypto_cap->sym.xform_type ==
9579 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
9580 				crypto_cap->sym.cipher.algo ==
9581 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9582 			sym_cap = &crypto_cap->sym;
9583 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9584 						d_td->key.len,
9585 						d_td->iv.len) == 0)
9586 				break;
9587 		}
9588 	}
9589 
9590 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9591 		return TEST_SKIPPED;
9592 
9593 	/* Setup source mbuf payload */
9594 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9595 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9596 			rte_pktmbuf_tailroom(ut_params->ibuf));
9597 
9598 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9599 			d_td->plaintext.len);
9600 
9601 	memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
9602 
9603 	/* Setup cipher session parameters */
9604 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9605 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9606 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9607 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9608 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9609 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9610 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9611 	ut_params->cipher_xform.next = NULL;
9612 
9613 	/* Setup DOCSIS session parameters */
9614 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9615 
9616 	struct rte_security_session_conf sess_conf = {
9617 		.action_type = ut_params->type,
9618 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9619 		.docsis = ut_params->docsis_xform,
9620 		.crypto_xform = &ut_params->cipher_xform,
9621 	};
9622 
9623 	/* Create security session */
9624 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9625 					ts_params->session_mpool,
9626 					ts_params->session_priv_mpool);
9627 
9628 	if (!ut_params->sec_session) {
9629 		printf("TestCase %s(%d) line %d: %s\n",
9630 			__func__, i, __LINE__, "failed to allocate session");
9631 		ret = TEST_FAILED;
9632 		goto on_err;
9633 	}
9634 
9635 	/* Generate crypto op data structure */
9636 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9637 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9638 	if (!ut_params->op) {
9639 		printf("TestCase %s(%d) line %d: %s\n",
9640 			__func__, i, __LINE__,
9641 			"failed to allocate security crypto operation");
9642 		ret = TEST_FAILED;
9643 		goto on_err;
9644 	}
9645 
9646 	/* Setup CRC operation parameters */
9647 	crc_len = d_td->plaintext.no_crc == false ?
9648 			(d_td->plaintext.len -
9649 				d_td->plaintext.crc_offset -
9650 				RTE_ETHER_CRC_LEN) :
9651 			0;
9652 	crc_len = crc_len > 0 ? crc_len : 0;
9653 	ut_params->op->sym->auth.data.length = crc_len;
9654 	ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
9655 
9656 	/* Setup cipher operation parameters */
9657 	cipher_len = d_td->plaintext.no_cipher == false ?
9658 			(d_td->plaintext.len -
9659 				d_td->plaintext.cipher_offset) :
9660 			0;
9661 	cipher_len = cipher_len > 0 ? cipher_len : 0;
9662 	ut_params->op->sym->cipher.data.length = cipher_len;
9663 	ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
9664 
9665 	/* Setup cipher IV */
9666 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9667 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9668 
9669 	/* Attach session to operation */
9670 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
9671 
9672 	/* Set crypto operation mbufs */
9673 	ut_params->op->sym->m_src = ut_params->ibuf;
9674 	ut_params->op->sym->m_dst = NULL;
9675 
9676 	/* Process crypto operation */
9677 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9678 			NULL) {
9679 		printf("TestCase %s(%d) line %d: %s\n",
9680 			__func__, i, __LINE__,
9681 			"failed to process security crypto op");
9682 		ret = TEST_FAILED;
9683 		goto on_err;
9684 	}
9685 
9686 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9687 		printf("TestCase %s(%d) line %d: %s\n",
9688 			__func__, i, __LINE__, "crypto op processing failed");
9689 		ret = TEST_FAILED;
9690 		goto on_err;
9691 	}
9692 
9693 	/* Validate ciphertext */
9694 	ciphertext = plaintext;
9695 
9696 	if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
9697 		printf("TestCase %s(%d) line %d: %s\n",
9698 			__func__, i, __LINE__, "ciphertext not as expected\n");
9699 		rte_hexdump(stdout, "expected", d_td->ciphertext.data,
9700 				d_td->ciphertext.len);
9701 		rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
9702 		ret = TEST_FAILED;
9703 		goto on_err;
9704 	}
9705 
9706 on_err:
9707 	rte_crypto_op_free(ut_params->op);
9708 	ut_params->op = NULL;
9709 
9710 	if (ut_params->sec_session)
9711 		rte_security_session_destroy(ctx, ut_params->sec_session);
9712 	ut_params->sec_session = NULL;
9713 
9714 	rte_pktmbuf_free(ut_params->ibuf);
9715 	ut_params->ibuf = NULL;
9716 
9717 	return ret;
9718 }
9719 
9720 #define TEST_DOCSIS_COUNT(func) do {			\
9721 	int ret = func;					\
9722 	if (ret == TEST_SUCCESS)  {			\
9723 		printf("\t%2d)", n++);			\
9724 		printf("+++++ PASSED:" #func"\n");	\
9725 		p++;					\
9726 	} else if (ret == TEST_SKIPPED) {		\
9727 		printf("\t%2d)", n++);			\
9728 		printf("~~~~~ SKIPPED:" #func"\n");	\
9729 		s++;					\
9730 	} else {					\
9731 		printf("\t%2d)", n++);			\
9732 		printf("----- FAILED:" #func"\n");	\
9733 		f++;					\
9734 	}						\
9735 } while (0)
9736 
9737 static int
9738 test_DOCSIS_PROTO_uplink_all(void)
9739 {
9740 	int p = 0, s = 0, f = 0, n = 0;
9741 
9742 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1));
9743 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2));
9744 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3));
9745 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4));
9746 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5));
9747 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6));
9748 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7));
9749 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8));
9750 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9));
9751 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10));
9752 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11));
9753 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12));
9754 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13));
9755 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14));
9756 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15));
9757 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16));
9758 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17));
9759 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18));
9760 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19));
9761 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20));
9762 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21));
9763 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22));
9764 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23));
9765 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24));
9766 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25));
9767 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26));
9768 
9769 	if (f)
9770 		printf("## %s: %d passed out of %d (%d skipped)\n",
9771 			__func__, p, n, s);
9772 
9773 	return f;
9774 };
9775 
9776 static int
9777 test_DOCSIS_PROTO_downlink_all(void)
9778 {
9779 	int p = 0, s = 0, f = 0, n = 0;
9780 
9781 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1));
9782 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2));
9783 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3));
9784 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4));
9785 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5));
9786 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6));
9787 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7));
9788 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8));
9789 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9));
9790 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10));
9791 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11));
9792 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12));
9793 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13));
9794 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14));
9795 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15));
9796 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16));
9797 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17));
9798 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18));
9799 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19));
9800 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20));
9801 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21));
9802 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22));
9803 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23));
9804 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24));
9805 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25));
9806 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26));
9807 
9808 	if (f)
9809 		printf("## %s: %d passed out of %d (%d skipped)\n",
9810 			__func__, p, n, s);
9811 
9812 	return f;
9813 };
9814 
9815 static int
9816 test_DOCSIS_PROTO_all(void)
9817 {
9818 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9819 	struct crypto_unittest_params *ut_params = &unittest_params;
9820 	struct rte_cryptodev_info dev_info;
9821 	int status;
9822 
9823 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9824 	uint64_t feat_flags = dev_info.feature_flags;
9825 
9826 	if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
9827 		return TEST_SKIPPED;
9828 
9829 	/* Set action type */
9830 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9831 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9832 		gbl_action_type;
9833 
9834 	if (security_proto_supported(ut_params->type,
9835 			RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
9836 		return TEST_SKIPPED;
9837 
9838 	status = test_DOCSIS_PROTO_uplink_all();
9839 	status += test_DOCSIS_PROTO_downlink_all();
9840 
9841 	if (status)
9842 		return TEST_FAILED;
9843 	else
9844 		return TEST_SUCCESS;
9845 }
9846 #endif
9847 
9848 static int
9849 test_AES_GCM_authenticated_encryption_test_case_1(void)
9850 {
9851 	return test_authenticated_encryption(&gcm_test_case_1);
9852 }
9853 
9854 static int
9855 test_AES_GCM_authenticated_encryption_test_case_2(void)
9856 {
9857 	return test_authenticated_encryption(&gcm_test_case_2);
9858 }
9859 
9860 static int
9861 test_AES_GCM_authenticated_encryption_test_case_3(void)
9862 {
9863 	return test_authenticated_encryption(&gcm_test_case_3);
9864 }
9865 
9866 static int
9867 test_AES_GCM_authenticated_encryption_test_case_4(void)
9868 {
9869 	return test_authenticated_encryption(&gcm_test_case_4);
9870 }
9871 
9872 static int
9873 test_AES_GCM_authenticated_encryption_test_case_5(void)
9874 {
9875 	return test_authenticated_encryption(&gcm_test_case_5);
9876 }
9877 
9878 static int
9879 test_AES_GCM_authenticated_encryption_test_case_6(void)
9880 {
9881 	return test_authenticated_encryption(&gcm_test_case_6);
9882 }
9883 
9884 static int
9885 test_AES_GCM_authenticated_encryption_test_case_7(void)
9886 {
9887 	return test_authenticated_encryption(&gcm_test_case_7);
9888 }
9889 
9890 static int
9891 test_AES_GCM_authenticated_encryption_test_case_8(void)
9892 {
9893 	return test_authenticated_encryption(&gcm_test_case_8);
9894 }
9895 
9896 static int
9897 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
9898 {
9899 	return test_authenticated_encryption(&gcm_J0_test_case_1);
9900 }
9901 
9902 static int
9903 test_AES_GCM_auth_encryption_test_case_192_1(void)
9904 {
9905 	return test_authenticated_encryption(&gcm_test_case_192_1);
9906 }
9907 
9908 static int
9909 test_AES_GCM_auth_encryption_test_case_192_2(void)
9910 {
9911 	return test_authenticated_encryption(&gcm_test_case_192_2);
9912 }
9913 
9914 static int
9915 test_AES_GCM_auth_encryption_test_case_192_3(void)
9916 {
9917 	return test_authenticated_encryption(&gcm_test_case_192_3);
9918 }
9919 
9920 static int
9921 test_AES_GCM_auth_encryption_test_case_192_4(void)
9922 {
9923 	return test_authenticated_encryption(&gcm_test_case_192_4);
9924 }
9925 
9926 static int
9927 test_AES_GCM_auth_encryption_test_case_192_5(void)
9928 {
9929 	return test_authenticated_encryption(&gcm_test_case_192_5);
9930 }
9931 
9932 static int
9933 test_AES_GCM_auth_encryption_test_case_192_6(void)
9934 {
9935 	return test_authenticated_encryption(&gcm_test_case_192_6);
9936 }
9937 
9938 static int
9939 test_AES_GCM_auth_encryption_test_case_192_7(void)
9940 {
9941 	return test_authenticated_encryption(&gcm_test_case_192_7);
9942 }
9943 
9944 static int
9945 test_AES_GCM_auth_encryption_test_case_256_1(void)
9946 {
9947 	return test_authenticated_encryption(&gcm_test_case_256_1);
9948 }
9949 
9950 static int
9951 test_AES_GCM_auth_encryption_test_case_256_2(void)
9952 {
9953 	return test_authenticated_encryption(&gcm_test_case_256_2);
9954 }
9955 
9956 static int
9957 test_AES_GCM_auth_encryption_test_case_256_3(void)
9958 {
9959 	return test_authenticated_encryption(&gcm_test_case_256_3);
9960 }
9961 
9962 static int
9963 test_AES_GCM_auth_encryption_test_case_256_4(void)
9964 {
9965 	return test_authenticated_encryption(&gcm_test_case_256_4);
9966 }
9967 
9968 static int
9969 test_AES_GCM_auth_encryption_test_case_256_5(void)
9970 {
9971 	return test_authenticated_encryption(&gcm_test_case_256_5);
9972 }
9973 
9974 static int
9975 test_AES_GCM_auth_encryption_test_case_256_6(void)
9976 {
9977 	return test_authenticated_encryption(&gcm_test_case_256_6);
9978 }
9979 
9980 static int
9981 test_AES_GCM_auth_encryption_test_case_256_7(void)
9982 {
9983 	return test_authenticated_encryption(&gcm_test_case_256_7);
9984 }
9985 
9986 static int
9987 test_AES_GCM_auth_encryption_test_case_aad_1(void)
9988 {
9989 	return test_authenticated_encryption(&gcm_test_case_aad_1);
9990 }
9991 
9992 static int
9993 test_AES_GCM_auth_encryption_test_case_aad_2(void)
9994 {
9995 	return test_authenticated_encryption(&gcm_test_case_aad_2);
9996 }
9997 
9998 static int
9999 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
10000 {
10001 	struct aead_test_data tdata;
10002 	int res;
10003 
10004 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10005 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10006 	tdata.iv.data[0] += 1;
10007 	res = test_authenticated_encryption(&tdata);
10008 	if (res == TEST_SKIPPED)
10009 		return res;
10010 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10011 	return TEST_SUCCESS;
10012 }
10013 
10014 static int
10015 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
10016 {
10017 	struct aead_test_data tdata;
10018 	int res;
10019 
10020 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10021 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10022 	tdata.plaintext.data[0] += 1;
10023 	res = test_authenticated_encryption(&tdata);
10024 	if (res == TEST_SKIPPED)
10025 		return res;
10026 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10027 	return TEST_SUCCESS;
10028 }
10029 
10030 static int
10031 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
10032 {
10033 	struct aead_test_data tdata;
10034 	int res;
10035 
10036 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10037 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10038 	tdata.ciphertext.data[0] += 1;
10039 	res = test_authenticated_encryption(&tdata);
10040 	if (res == TEST_SKIPPED)
10041 		return res;
10042 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10043 	return TEST_SUCCESS;
10044 }
10045 
10046 static int
10047 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
10048 {
10049 	struct aead_test_data tdata;
10050 	int res;
10051 
10052 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10053 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10054 	tdata.aad.len += 1;
10055 	res = test_authenticated_encryption(&tdata);
10056 	if (res == TEST_SKIPPED)
10057 		return res;
10058 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10059 	return TEST_SUCCESS;
10060 }
10061 
10062 static int
10063 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
10064 {
10065 	struct aead_test_data tdata;
10066 	uint8_t aad[gcm_test_case_7.aad.len];
10067 	int res;
10068 
10069 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10070 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10071 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
10072 	aad[0] += 1;
10073 	tdata.aad.data = aad;
10074 	res = test_authenticated_encryption(&tdata);
10075 	if (res == TEST_SKIPPED)
10076 		return res;
10077 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10078 	return TEST_SUCCESS;
10079 }
10080 
10081 static int
10082 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
10083 {
10084 	struct aead_test_data tdata;
10085 	int res;
10086 
10087 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10088 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10089 	tdata.auth_tag.data[0] += 1;
10090 	res = test_authenticated_encryption(&tdata);
10091 	if (res == TEST_SKIPPED)
10092 		return res;
10093 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10094 	return TEST_SUCCESS;
10095 }
10096 
10097 static int
10098 test_authenticated_decryption(const struct aead_test_data *tdata)
10099 {
10100 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10101 	struct crypto_unittest_params *ut_params = &unittest_params;
10102 
10103 	int retval;
10104 	uint8_t *plaintext;
10105 	uint32_t i;
10106 	struct rte_cryptodev_info dev_info;
10107 
10108 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10109 	uint64_t feat_flags = dev_info.feature_flags;
10110 
10111 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10112 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10113 		printf("Device doesn't support RAW data-path APIs.\n");
10114 		return TEST_SKIPPED;
10115 	}
10116 
10117 	/* Verify the capabilities */
10118 	struct rte_cryptodev_sym_capability_idx cap_idx;
10119 	const struct rte_cryptodev_symmetric_capability *capability;
10120 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10121 	cap_idx.algo.aead = tdata->algo;
10122 	capability = rte_cryptodev_sym_capability_get(
10123 			ts_params->valid_devs[0], &cap_idx);
10124 	if (capability == NULL)
10125 		return TEST_SKIPPED;
10126 	if (rte_cryptodev_sym_capability_check_aead(
10127 			capability, tdata->key.len, tdata->auth_tag.len,
10128 			tdata->aad.len, tdata->iv.len))
10129 		return TEST_SKIPPED;
10130 
10131 	/* Create AEAD session */
10132 	retval = create_aead_session(ts_params->valid_devs[0],
10133 			tdata->algo,
10134 			RTE_CRYPTO_AEAD_OP_DECRYPT,
10135 			tdata->key.data, tdata->key.len,
10136 			tdata->aad.len, tdata->auth_tag.len,
10137 			tdata->iv.len);
10138 	if (retval < 0)
10139 		return retval;
10140 
10141 	/* alloc mbuf and set payload */
10142 	if (tdata->aad.len > MBUF_SIZE) {
10143 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
10144 		/* Populate full size of add data */
10145 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
10146 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
10147 	} else
10148 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10149 
10150 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10151 			rte_pktmbuf_tailroom(ut_params->ibuf));
10152 
10153 	/* Create AEAD operation */
10154 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10155 	if (retval < 0)
10156 		return retval;
10157 
10158 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10159 
10160 	ut_params->op->sym->m_src = ut_params->ibuf;
10161 
10162 	/* Process crypto operation */
10163 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10164 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
10165 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10166 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10167 				ut_params->op, 0, 0, 0, 0);
10168 	else
10169 		TEST_ASSERT_NOT_NULL(
10170 			process_crypto_request(ts_params->valid_devs[0],
10171 			ut_params->op), "failed to process sym crypto op");
10172 
10173 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10174 			"crypto op processing failed");
10175 
10176 	if (ut_params->op->sym->m_dst)
10177 		plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
10178 				uint8_t *);
10179 	else
10180 		plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
10181 				uint8_t *,
10182 				ut_params->op->sym->cipher.data.offset);
10183 
10184 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10185 
10186 	/* Validate obuf */
10187 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10188 			plaintext,
10189 			tdata->plaintext.data,
10190 			tdata->plaintext.len,
10191 			"Plaintext data not as expected");
10192 
10193 	TEST_ASSERT_EQUAL(ut_params->op->status,
10194 			RTE_CRYPTO_OP_STATUS_SUCCESS,
10195 			"Authentication failed");
10196 
10197 	return 0;
10198 }
10199 
10200 static int
10201 test_AES_GCM_authenticated_decryption_test_case_1(void)
10202 {
10203 	return test_authenticated_decryption(&gcm_test_case_1);
10204 }
10205 
10206 static int
10207 test_AES_GCM_authenticated_decryption_test_case_2(void)
10208 {
10209 	return test_authenticated_decryption(&gcm_test_case_2);
10210 }
10211 
10212 static int
10213 test_AES_GCM_authenticated_decryption_test_case_3(void)
10214 {
10215 	return test_authenticated_decryption(&gcm_test_case_3);
10216 }
10217 
10218 static int
10219 test_AES_GCM_authenticated_decryption_test_case_4(void)
10220 {
10221 	return test_authenticated_decryption(&gcm_test_case_4);
10222 }
10223 
10224 static int
10225 test_AES_GCM_authenticated_decryption_test_case_5(void)
10226 {
10227 	return test_authenticated_decryption(&gcm_test_case_5);
10228 }
10229 
10230 static int
10231 test_AES_GCM_authenticated_decryption_test_case_6(void)
10232 {
10233 	return test_authenticated_decryption(&gcm_test_case_6);
10234 }
10235 
10236 static int
10237 test_AES_GCM_authenticated_decryption_test_case_7(void)
10238 {
10239 	return test_authenticated_decryption(&gcm_test_case_7);
10240 }
10241 
10242 static int
10243 test_AES_GCM_authenticated_decryption_test_case_8(void)
10244 {
10245 	return test_authenticated_decryption(&gcm_test_case_8);
10246 }
10247 
10248 static int
10249 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
10250 {
10251 	return test_authenticated_decryption(&gcm_J0_test_case_1);
10252 }
10253 
10254 static int
10255 test_AES_GCM_auth_decryption_test_case_192_1(void)
10256 {
10257 	return test_authenticated_decryption(&gcm_test_case_192_1);
10258 }
10259 
10260 static int
10261 test_AES_GCM_auth_decryption_test_case_192_2(void)
10262 {
10263 	return test_authenticated_decryption(&gcm_test_case_192_2);
10264 }
10265 
10266 static int
10267 test_AES_GCM_auth_decryption_test_case_192_3(void)
10268 {
10269 	return test_authenticated_decryption(&gcm_test_case_192_3);
10270 }
10271 
10272 static int
10273 test_AES_GCM_auth_decryption_test_case_192_4(void)
10274 {
10275 	return test_authenticated_decryption(&gcm_test_case_192_4);
10276 }
10277 
10278 static int
10279 test_AES_GCM_auth_decryption_test_case_192_5(void)
10280 {
10281 	return test_authenticated_decryption(&gcm_test_case_192_5);
10282 }
10283 
10284 static int
10285 test_AES_GCM_auth_decryption_test_case_192_6(void)
10286 {
10287 	return test_authenticated_decryption(&gcm_test_case_192_6);
10288 }
10289 
10290 static int
10291 test_AES_GCM_auth_decryption_test_case_192_7(void)
10292 {
10293 	return test_authenticated_decryption(&gcm_test_case_192_7);
10294 }
10295 
10296 static int
10297 test_AES_GCM_auth_decryption_test_case_256_1(void)
10298 {
10299 	return test_authenticated_decryption(&gcm_test_case_256_1);
10300 }
10301 
10302 static int
10303 test_AES_GCM_auth_decryption_test_case_256_2(void)
10304 {
10305 	return test_authenticated_decryption(&gcm_test_case_256_2);
10306 }
10307 
10308 static int
10309 test_AES_GCM_auth_decryption_test_case_256_3(void)
10310 {
10311 	return test_authenticated_decryption(&gcm_test_case_256_3);
10312 }
10313 
10314 static int
10315 test_AES_GCM_auth_decryption_test_case_256_4(void)
10316 {
10317 	return test_authenticated_decryption(&gcm_test_case_256_4);
10318 }
10319 
10320 static int
10321 test_AES_GCM_auth_decryption_test_case_256_5(void)
10322 {
10323 	return test_authenticated_decryption(&gcm_test_case_256_5);
10324 }
10325 
10326 static int
10327 test_AES_GCM_auth_decryption_test_case_256_6(void)
10328 {
10329 	return test_authenticated_decryption(&gcm_test_case_256_6);
10330 }
10331 
10332 static int
10333 test_AES_GCM_auth_decryption_test_case_256_7(void)
10334 {
10335 	return test_authenticated_decryption(&gcm_test_case_256_7);
10336 }
10337 
10338 static int
10339 test_AES_GCM_auth_decryption_test_case_aad_1(void)
10340 {
10341 	return test_authenticated_decryption(&gcm_test_case_aad_1);
10342 }
10343 
10344 static int
10345 test_AES_GCM_auth_decryption_test_case_aad_2(void)
10346 {
10347 	return test_authenticated_decryption(&gcm_test_case_aad_2);
10348 }
10349 
10350 static int
10351 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
10352 {
10353 	struct aead_test_data tdata;
10354 	int res;
10355 
10356 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10357 	tdata.iv.data[0] += 1;
10358 	res = test_authenticated_decryption(&tdata);
10359 	if (res == TEST_SKIPPED)
10360 		return res;
10361 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10362 	return TEST_SUCCESS;
10363 }
10364 
10365 static int
10366 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
10367 {
10368 	struct aead_test_data tdata;
10369 	int res;
10370 
10371 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10372 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10373 	tdata.plaintext.data[0] += 1;
10374 	res = test_authenticated_decryption(&tdata);
10375 	if (res == TEST_SKIPPED)
10376 		return res;
10377 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10378 	return TEST_SUCCESS;
10379 }
10380 
10381 static int
10382 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
10383 {
10384 	struct aead_test_data tdata;
10385 	int res;
10386 
10387 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10388 	tdata.ciphertext.data[0] += 1;
10389 	res = test_authenticated_decryption(&tdata);
10390 	if (res == TEST_SKIPPED)
10391 		return res;
10392 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10393 	return TEST_SUCCESS;
10394 }
10395 
10396 static int
10397 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
10398 {
10399 	struct aead_test_data tdata;
10400 	int res;
10401 
10402 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10403 	tdata.aad.len += 1;
10404 	res = test_authenticated_decryption(&tdata);
10405 	if (res == TEST_SKIPPED)
10406 		return res;
10407 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10408 	return TEST_SUCCESS;
10409 }
10410 
10411 static int
10412 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
10413 {
10414 	struct aead_test_data tdata;
10415 	uint8_t aad[gcm_test_case_7.aad.len];
10416 	int res;
10417 
10418 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10419 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
10420 	aad[0] += 1;
10421 	tdata.aad.data = aad;
10422 	res = test_authenticated_decryption(&tdata);
10423 	if (res == TEST_SKIPPED)
10424 		return res;
10425 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10426 	return TEST_SUCCESS;
10427 }
10428 
10429 static int
10430 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
10431 {
10432 	struct aead_test_data tdata;
10433 	int res;
10434 
10435 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10436 	tdata.auth_tag.data[0] += 1;
10437 	res = test_authenticated_decryption(&tdata);
10438 	if (res == TEST_SKIPPED)
10439 		return res;
10440 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
10441 	return TEST_SUCCESS;
10442 }
10443 
10444 static int
10445 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
10446 {
10447 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10448 	struct crypto_unittest_params *ut_params = &unittest_params;
10449 
10450 	int retval;
10451 	uint8_t *ciphertext, *auth_tag;
10452 	uint16_t plaintext_pad_len;
10453 
10454 	/* Verify the capabilities */
10455 	struct rte_cryptodev_sym_capability_idx cap_idx;
10456 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10457 	cap_idx.algo.aead = tdata->algo;
10458 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10459 			&cap_idx) == NULL)
10460 		return TEST_SKIPPED;
10461 
10462 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10463 		return TEST_SKIPPED;
10464 
10465 	/* not supported with CPU crypto */
10466 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10467 		return TEST_SKIPPED;
10468 
10469 	/* Create AEAD session */
10470 	retval = create_aead_session(ts_params->valid_devs[0],
10471 			tdata->algo,
10472 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
10473 			tdata->key.data, tdata->key.len,
10474 			tdata->aad.len, tdata->auth_tag.len,
10475 			tdata->iv.len);
10476 	if (retval < 0)
10477 		return retval;
10478 
10479 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10480 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10481 
10482 	/* clear mbuf payload */
10483 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10484 			rte_pktmbuf_tailroom(ut_params->ibuf));
10485 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10486 			rte_pktmbuf_tailroom(ut_params->obuf));
10487 
10488 	/* Create AEAD operation */
10489 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10490 	if (retval < 0)
10491 		return retval;
10492 
10493 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10494 
10495 	ut_params->op->sym->m_src = ut_params->ibuf;
10496 	ut_params->op->sym->m_dst = ut_params->obuf;
10497 
10498 	/* Process crypto operation */
10499 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10500 			ut_params->op), "failed to process sym crypto op");
10501 
10502 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10503 			"crypto op processing failed");
10504 
10505 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10506 
10507 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10508 			ut_params->op->sym->cipher.data.offset);
10509 	auth_tag = ciphertext + plaintext_pad_len;
10510 
10511 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10512 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10513 
10514 	/* Validate obuf */
10515 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10516 			ciphertext,
10517 			tdata->ciphertext.data,
10518 			tdata->ciphertext.len,
10519 			"Ciphertext data not as expected");
10520 
10521 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10522 			auth_tag,
10523 			tdata->auth_tag.data,
10524 			tdata->auth_tag.len,
10525 			"Generated auth tag not as expected");
10526 
10527 	return 0;
10528 
10529 }
10530 
10531 static int
10532 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
10533 {
10534 	return test_authenticated_encryption_oop(&gcm_test_case_5);
10535 }
10536 
10537 static int
10538 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
10539 {
10540 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10541 	struct crypto_unittest_params *ut_params = &unittest_params;
10542 
10543 	int retval;
10544 	uint8_t *plaintext;
10545 
10546 	/* Verify the capabilities */
10547 	struct rte_cryptodev_sym_capability_idx cap_idx;
10548 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10549 	cap_idx.algo.aead = tdata->algo;
10550 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10551 			&cap_idx) == NULL)
10552 		return TEST_SKIPPED;
10553 
10554 	/* not supported with CPU crypto and raw data-path APIs*/
10555 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
10556 			global_api_test_type == CRYPTODEV_RAW_API_TEST)
10557 		return TEST_SKIPPED;
10558 
10559 	/* Create AEAD session */
10560 	retval = create_aead_session(ts_params->valid_devs[0],
10561 			tdata->algo,
10562 			RTE_CRYPTO_AEAD_OP_DECRYPT,
10563 			tdata->key.data, tdata->key.len,
10564 			tdata->aad.len, tdata->auth_tag.len,
10565 			tdata->iv.len);
10566 	if (retval < 0)
10567 		return retval;
10568 
10569 	/* alloc mbuf and set payload */
10570 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10571 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10572 
10573 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10574 			rte_pktmbuf_tailroom(ut_params->ibuf));
10575 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10576 			rte_pktmbuf_tailroom(ut_params->obuf));
10577 
10578 	/* Create AEAD operation */
10579 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10580 	if (retval < 0)
10581 		return retval;
10582 
10583 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10584 
10585 	ut_params->op->sym->m_src = ut_params->ibuf;
10586 	ut_params->op->sym->m_dst = ut_params->obuf;
10587 
10588 	/* Process crypto operation */
10589 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10590 			ut_params->op), "failed to process sym crypto op");
10591 
10592 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10593 			"crypto op processing failed");
10594 
10595 	plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10596 			ut_params->op->sym->cipher.data.offset);
10597 
10598 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10599 
10600 	/* Validate obuf */
10601 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10602 			plaintext,
10603 			tdata->plaintext.data,
10604 			tdata->plaintext.len,
10605 			"Plaintext data not as expected");
10606 
10607 	TEST_ASSERT_EQUAL(ut_params->op->status,
10608 			RTE_CRYPTO_OP_STATUS_SUCCESS,
10609 			"Authentication failed");
10610 	return 0;
10611 }
10612 
10613 static int
10614 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
10615 {
10616 	return test_authenticated_decryption_oop(&gcm_test_case_5);
10617 }
10618 
10619 static int
10620 test_authenticated_encryption_sessionless(
10621 		const struct aead_test_data *tdata)
10622 {
10623 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10624 	struct crypto_unittest_params *ut_params = &unittest_params;
10625 
10626 	int retval;
10627 	uint8_t *ciphertext, *auth_tag;
10628 	uint16_t plaintext_pad_len;
10629 	uint8_t key[tdata->key.len + 1];
10630 	struct rte_cryptodev_info dev_info;
10631 
10632 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10633 	uint64_t feat_flags = dev_info.feature_flags;
10634 
10635 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10636 		printf("Device doesn't support Sessionless ops.\n");
10637 		return TEST_SKIPPED;
10638 	}
10639 
10640 	/* not supported with CPU crypto */
10641 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10642 		return TEST_SKIPPED;
10643 
10644 	/* Verify the capabilities */
10645 	struct rte_cryptodev_sym_capability_idx cap_idx;
10646 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10647 	cap_idx.algo.aead = tdata->algo;
10648 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10649 			&cap_idx) == NULL)
10650 		return TEST_SKIPPED;
10651 
10652 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10653 
10654 	/* clear mbuf payload */
10655 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10656 			rte_pktmbuf_tailroom(ut_params->ibuf));
10657 
10658 	/* Create AEAD operation */
10659 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10660 	if (retval < 0)
10661 		return retval;
10662 
10663 	/* Create GCM xform */
10664 	memcpy(key, tdata->key.data, tdata->key.len);
10665 	retval = create_aead_xform(ut_params->op,
10666 			tdata->algo,
10667 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
10668 			key, tdata->key.len,
10669 			tdata->aad.len, tdata->auth_tag.len,
10670 			tdata->iv.len);
10671 	if (retval < 0)
10672 		return retval;
10673 
10674 	ut_params->op->sym->m_src = ut_params->ibuf;
10675 
10676 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10677 			RTE_CRYPTO_OP_SESSIONLESS,
10678 			"crypto op session type not sessionless");
10679 
10680 	/* Process crypto operation */
10681 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10682 			ut_params->op), "failed to process sym crypto op");
10683 
10684 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10685 
10686 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10687 			"crypto op status not success");
10688 
10689 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10690 
10691 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10692 			ut_params->op->sym->cipher.data.offset);
10693 	auth_tag = ciphertext + plaintext_pad_len;
10694 
10695 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10696 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10697 
10698 	/* Validate obuf */
10699 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10700 			ciphertext,
10701 			tdata->ciphertext.data,
10702 			tdata->ciphertext.len,
10703 			"Ciphertext data not as expected");
10704 
10705 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10706 			auth_tag,
10707 			tdata->auth_tag.data,
10708 			tdata->auth_tag.len,
10709 			"Generated auth tag not as expected");
10710 
10711 	return 0;
10712 
10713 }
10714 
10715 static int
10716 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
10717 {
10718 	return test_authenticated_encryption_sessionless(
10719 			&gcm_test_case_5);
10720 }
10721 
10722 static int
10723 test_authenticated_decryption_sessionless(
10724 		const struct aead_test_data *tdata)
10725 {
10726 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10727 	struct crypto_unittest_params *ut_params = &unittest_params;
10728 
10729 	int retval;
10730 	uint8_t *plaintext;
10731 	uint8_t key[tdata->key.len + 1];
10732 	struct rte_cryptodev_info dev_info;
10733 
10734 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10735 	uint64_t feat_flags = dev_info.feature_flags;
10736 
10737 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10738 		printf("Device doesn't support Sessionless ops.\n");
10739 		return TEST_SKIPPED;
10740 	}
10741 
10742 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10743 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10744 		printf("Device doesn't support RAW data-path APIs.\n");
10745 		return TEST_SKIPPED;
10746 	}
10747 
10748 	/* not supported with CPU crypto */
10749 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10750 		return TEST_SKIPPED;
10751 
10752 	/* Verify the capabilities */
10753 	struct rte_cryptodev_sym_capability_idx cap_idx;
10754 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10755 	cap_idx.algo.aead = tdata->algo;
10756 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10757 			&cap_idx) == NULL)
10758 		return TEST_SKIPPED;
10759 
10760 	/* alloc mbuf and set payload */
10761 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10762 
10763 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10764 			rte_pktmbuf_tailroom(ut_params->ibuf));
10765 
10766 	/* Create AEAD operation */
10767 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10768 	if (retval < 0)
10769 		return retval;
10770 
10771 	/* Create AEAD xform */
10772 	memcpy(key, tdata->key.data, tdata->key.len);
10773 	retval = create_aead_xform(ut_params->op,
10774 			tdata->algo,
10775 			RTE_CRYPTO_AEAD_OP_DECRYPT,
10776 			key, tdata->key.len,
10777 			tdata->aad.len, tdata->auth_tag.len,
10778 			tdata->iv.len);
10779 	if (retval < 0)
10780 		return retval;
10781 
10782 	ut_params->op->sym->m_src = ut_params->ibuf;
10783 
10784 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10785 			RTE_CRYPTO_OP_SESSIONLESS,
10786 			"crypto op session type not sessionless");
10787 
10788 	/* Process crypto operation */
10789 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10790 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10791 				ut_params->op, 0, 0, 0, 0);
10792 	else
10793 		TEST_ASSERT_NOT_NULL(process_crypto_request(
10794 			ts_params->valid_devs[0], ut_params->op),
10795 				"failed to process sym crypto op");
10796 
10797 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10798 
10799 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10800 			"crypto op status not success");
10801 
10802 	plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10803 			ut_params->op->sym->cipher.data.offset);
10804 
10805 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10806 
10807 	/* Validate obuf */
10808 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10809 			plaintext,
10810 			tdata->plaintext.data,
10811 			tdata->plaintext.len,
10812 			"Plaintext data not as expected");
10813 
10814 	TEST_ASSERT_EQUAL(ut_params->op->status,
10815 			RTE_CRYPTO_OP_STATUS_SUCCESS,
10816 			"Authentication failed");
10817 	return 0;
10818 }
10819 
10820 static int
10821 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
10822 {
10823 	return test_authenticated_decryption_sessionless(
10824 			&gcm_test_case_5);
10825 }
10826 
10827 static int
10828 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
10829 {
10830 	return test_authenticated_encryption(&ccm_test_case_128_1);
10831 }
10832 
10833 static int
10834 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
10835 {
10836 	return test_authenticated_encryption(&ccm_test_case_128_2);
10837 }
10838 
10839 static int
10840 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
10841 {
10842 	return test_authenticated_encryption(&ccm_test_case_128_3);
10843 }
10844 
10845 static int
10846 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
10847 {
10848 	return test_authenticated_decryption(&ccm_test_case_128_1);
10849 }
10850 
10851 static int
10852 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
10853 {
10854 	return test_authenticated_decryption(&ccm_test_case_128_2);
10855 }
10856 
10857 static int
10858 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
10859 {
10860 	return test_authenticated_decryption(&ccm_test_case_128_3);
10861 }
10862 
10863 static int
10864 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
10865 {
10866 	return test_authenticated_encryption(&ccm_test_case_192_1);
10867 }
10868 
10869 static int
10870 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
10871 {
10872 	return test_authenticated_encryption(&ccm_test_case_192_2);
10873 }
10874 
10875 static int
10876 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
10877 {
10878 	return test_authenticated_encryption(&ccm_test_case_192_3);
10879 }
10880 
10881 static int
10882 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
10883 {
10884 	return test_authenticated_decryption(&ccm_test_case_192_1);
10885 }
10886 
10887 static int
10888 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
10889 {
10890 	return test_authenticated_decryption(&ccm_test_case_192_2);
10891 }
10892 
10893 static int
10894 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
10895 {
10896 	return test_authenticated_decryption(&ccm_test_case_192_3);
10897 }
10898 
10899 static int
10900 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
10901 {
10902 	return test_authenticated_encryption(&ccm_test_case_256_1);
10903 }
10904 
10905 static int
10906 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
10907 {
10908 	return test_authenticated_encryption(&ccm_test_case_256_2);
10909 }
10910 
10911 static int
10912 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
10913 {
10914 	return test_authenticated_encryption(&ccm_test_case_256_3);
10915 }
10916 
10917 static int
10918 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
10919 {
10920 	return test_authenticated_decryption(&ccm_test_case_256_1);
10921 }
10922 
10923 static int
10924 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
10925 {
10926 	return test_authenticated_decryption(&ccm_test_case_256_2);
10927 }
10928 
10929 static int
10930 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
10931 {
10932 	return test_authenticated_decryption(&ccm_test_case_256_3);
10933 }
10934 
10935 static int
10936 test_stats(void)
10937 {
10938 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10939 	struct rte_cryptodev_stats stats;
10940 
10941 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10942 		return TEST_SKIPPED;
10943 
10944 	/* Verify the capabilities */
10945 	struct rte_cryptodev_sym_capability_idx cap_idx;
10946 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10947 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
10948 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10949 			&cap_idx) == NULL)
10950 		return TEST_SKIPPED;
10951 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10952 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10953 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10954 			&cap_idx) == NULL)
10955 		return TEST_SKIPPED;
10956 
10957 	if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
10958 			== -ENOTSUP)
10959 		return TEST_SKIPPED;
10960 
10961 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10962 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
10963 			&stats) == -ENODEV),
10964 		"rte_cryptodev_stats_get invalid dev failed");
10965 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
10966 		"rte_cryptodev_stats_get invalid Param failed");
10967 
10968 	/* Test expected values */
10969 	test_AES_CBC_HMAC_SHA1_encrypt_digest();
10970 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10971 			&stats),
10972 		"rte_cryptodev_stats_get failed");
10973 	TEST_ASSERT((stats.enqueued_count == 1),
10974 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10975 	TEST_ASSERT((stats.dequeued_count == 1),
10976 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10977 	TEST_ASSERT((stats.enqueue_err_count == 0),
10978 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10979 	TEST_ASSERT((stats.dequeue_err_count == 0),
10980 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10981 
10982 	/* invalid device but should ignore and not reset device stats*/
10983 	rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
10984 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10985 			&stats),
10986 		"rte_cryptodev_stats_get failed");
10987 	TEST_ASSERT((stats.enqueued_count == 1),
10988 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10989 
10990 	/* check that a valid reset clears stats */
10991 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10992 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10993 			&stats),
10994 					  "rte_cryptodev_stats_get failed");
10995 	TEST_ASSERT((stats.enqueued_count == 0),
10996 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10997 	TEST_ASSERT((stats.dequeued_count == 0),
10998 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10999 
11000 	return TEST_SUCCESS;
11001 }
11002 
11003 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
11004 				   struct crypto_unittest_params *ut_params,
11005 				   enum rte_crypto_auth_operation op,
11006 				   const struct HMAC_MD5_vector *test_case)
11007 {
11008 	uint8_t key[64];
11009 
11010 	memcpy(key, test_case->key.data, test_case->key.len);
11011 
11012 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11013 	ut_params->auth_xform.next = NULL;
11014 	ut_params->auth_xform.auth.op = op;
11015 
11016 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
11017 
11018 	ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
11019 	ut_params->auth_xform.auth.key.length = test_case->key.len;
11020 	ut_params->auth_xform.auth.key.data = key;
11021 
11022 	ut_params->sess = rte_cryptodev_sym_session_create(
11023 			ts_params->session_mpool);
11024 
11025 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11026 			ut_params->sess, &ut_params->auth_xform,
11027 			ts_params->session_priv_mpool);
11028 
11029 	if (ut_params->sess == NULL)
11030 		return TEST_FAILED;
11031 
11032 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11033 
11034 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11035 			rte_pktmbuf_tailroom(ut_params->ibuf));
11036 
11037 	return 0;
11038 }
11039 
11040 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
11041 			      const struct HMAC_MD5_vector *test_case,
11042 			      uint8_t **plaintext)
11043 {
11044 	uint16_t plaintext_pad_len;
11045 
11046 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11047 
11048 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
11049 				16);
11050 
11051 	*plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11052 			plaintext_pad_len);
11053 	memcpy(*plaintext, test_case->plaintext.data,
11054 			test_case->plaintext.len);
11055 
11056 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11057 			ut_params->ibuf, MD5_DIGEST_LEN);
11058 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11059 			"no room to append digest");
11060 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11061 			ut_params->ibuf, plaintext_pad_len);
11062 
11063 	if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11064 		rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
11065 			   test_case->auth_tag.len);
11066 	}
11067 
11068 	sym_op->auth.data.offset = 0;
11069 	sym_op->auth.data.length = test_case->plaintext.len;
11070 
11071 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11072 	ut_params->op->sym->m_src = ut_params->ibuf;
11073 
11074 	return 0;
11075 }
11076 
11077 static int
11078 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
11079 {
11080 	uint16_t plaintext_pad_len;
11081 	uint8_t *plaintext, *auth_tag;
11082 
11083 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11084 	struct crypto_unittest_params *ut_params = &unittest_params;
11085 	struct rte_cryptodev_info dev_info;
11086 
11087 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11088 	uint64_t feat_flags = dev_info.feature_flags;
11089 
11090 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11091 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11092 		printf("Device doesn't support RAW data-path APIs.\n");
11093 		return TEST_SKIPPED;
11094 	}
11095 
11096 	/* Verify the capabilities */
11097 	struct rte_cryptodev_sym_capability_idx cap_idx;
11098 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11099 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
11100 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11101 			&cap_idx) == NULL)
11102 		return TEST_SKIPPED;
11103 
11104 	if (MD5_HMAC_create_session(ts_params, ut_params,
11105 			RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
11106 		return TEST_FAILED;
11107 
11108 	/* Generate Crypto op data structure */
11109 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11110 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11111 	TEST_ASSERT_NOT_NULL(ut_params->op,
11112 			"Failed to allocate symmetric crypto operation struct");
11113 
11114 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
11115 				16);
11116 
11117 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
11118 		return TEST_FAILED;
11119 
11120 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11121 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11122 			ut_params->op);
11123 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11124 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11125 				ut_params->op, 0, 1, 0, 0);
11126 	else
11127 		TEST_ASSERT_NOT_NULL(
11128 			process_crypto_request(ts_params->valid_devs[0],
11129 				ut_params->op),
11130 				"failed to process sym crypto op");
11131 
11132 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11133 			"crypto op processing failed");
11134 
11135 	if (ut_params->op->sym->m_dst) {
11136 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11137 				uint8_t *, plaintext_pad_len);
11138 	} else {
11139 		auth_tag = plaintext + plaintext_pad_len;
11140 	}
11141 
11142 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11143 			auth_tag,
11144 			test_case->auth_tag.data,
11145 			test_case->auth_tag.len,
11146 			"HMAC_MD5 generated tag not as expected");
11147 
11148 	return TEST_SUCCESS;
11149 }
11150 
11151 static int
11152 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
11153 {
11154 	uint8_t *plaintext;
11155 
11156 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11157 	struct crypto_unittest_params *ut_params = &unittest_params;
11158 	struct rte_cryptodev_info dev_info;
11159 
11160 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11161 	uint64_t feat_flags = dev_info.feature_flags;
11162 
11163 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11164 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11165 		printf("Device doesn't support RAW data-path APIs.\n");
11166 		return TEST_SKIPPED;
11167 	}
11168 
11169 	/* Verify the capabilities */
11170 	struct rte_cryptodev_sym_capability_idx cap_idx;
11171 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11172 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
11173 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11174 			&cap_idx) == NULL)
11175 		return TEST_SKIPPED;
11176 
11177 	if (MD5_HMAC_create_session(ts_params, ut_params,
11178 			RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
11179 		return TEST_FAILED;
11180 	}
11181 
11182 	/* Generate Crypto op data structure */
11183 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11184 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11185 	TEST_ASSERT_NOT_NULL(ut_params->op,
11186 			"Failed to allocate symmetric crypto operation struct");
11187 
11188 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
11189 		return TEST_FAILED;
11190 
11191 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11192 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11193 			ut_params->op);
11194 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11195 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11196 				ut_params->op, 0, 1, 0, 0);
11197 	else
11198 		TEST_ASSERT_NOT_NULL(
11199 			process_crypto_request(ts_params->valid_devs[0],
11200 				ut_params->op),
11201 				"failed to process sym crypto op");
11202 
11203 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11204 			"HMAC_MD5 crypto op processing failed");
11205 
11206 	return TEST_SUCCESS;
11207 }
11208 
11209 static int
11210 test_MD5_HMAC_generate_case_1(void)
11211 {
11212 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
11213 }
11214 
11215 static int
11216 test_MD5_HMAC_verify_case_1(void)
11217 {
11218 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
11219 }
11220 
11221 static int
11222 test_MD5_HMAC_generate_case_2(void)
11223 {
11224 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
11225 }
11226 
11227 static int
11228 test_MD5_HMAC_verify_case_2(void)
11229 {
11230 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
11231 }
11232 
11233 static int
11234 test_multi_session(void)
11235 {
11236 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11237 	struct crypto_unittest_params *ut_params = &unittest_params;
11238 
11239 	struct rte_cryptodev_info dev_info;
11240 	struct rte_cryptodev_sym_session **sessions;
11241 
11242 	uint16_t i;
11243 
11244 	/* Verify the capabilities */
11245 	struct rte_cryptodev_sym_capability_idx cap_idx;
11246 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11247 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
11248 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11249 			&cap_idx) == NULL)
11250 		return TEST_SKIPPED;
11251 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11252 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11253 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11254 			&cap_idx) == NULL)
11255 		return TEST_SKIPPED;
11256 
11257 	test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
11258 			aes_cbc_key, hmac_sha512_key);
11259 
11260 
11261 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11262 
11263 	sessions = rte_malloc(NULL,
11264 			sizeof(struct rte_cryptodev_sym_session *) *
11265 			(MAX_NB_SESSIONS + 1), 0);
11266 
11267 	/* Create multiple crypto sessions*/
11268 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
11269 
11270 		sessions[i] = rte_cryptodev_sym_session_create(
11271 				ts_params->session_mpool);
11272 
11273 		rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11274 				sessions[i], &ut_params->auth_xform,
11275 				ts_params->session_priv_mpool);
11276 		TEST_ASSERT_NOT_NULL(sessions[i],
11277 				"Session creation failed at session number %u",
11278 				i);
11279 
11280 		/* Attempt to send a request on each session */
11281 		TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
11282 			sessions[i],
11283 			ut_params,
11284 			ts_params,
11285 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
11286 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
11287 			aes_cbc_iv),
11288 			"Failed to perform decrypt on request number %u.", i);
11289 		/* free crypto operation structure */
11290 		if (ut_params->op)
11291 			rte_crypto_op_free(ut_params->op);
11292 
11293 		/*
11294 		 * free mbuf - both obuf and ibuf are usually the same,
11295 		 * so check if they point at the same address is necessary,
11296 		 * to avoid freeing the mbuf twice.
11297 		 */
11298 		if (ut_params->obuf) {
11299 			rte_pktmbuf_free(ut_params->obuf);
11300 			if (ut_params->ibuf == ut_params->obuf)
11301 				ut_params->ibuf = 0;
11302 			ut_params->obuf = 0;
11303 		}
11304 		if (ut_params->ibuf) {
11305 			rte_pktmbuf_free(ut_params->ibuf);
11306 			ut_params->ibuf = 0;
11307 		}
11308 	}
11309 
11310 	sessions[i] = NULL;
11311 	/* Next session create should fail */
11312 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11313 			sessions[i], &ut_params->auth_xform,
11314 			ts_params->session_priv_mpool);
11315 	TEST_ASSERT_NULL(sessions[i],
11316 			"Session creation succeeded unexpectedly!");
11317 
11318 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
11319 		rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
11320 				sessions[i]);
11321 		rte_cryptodev_sym_session_free(sessions[i]);
11322 	}
11323 
11324 	rte_free(sessions);
11325 
11326 	return TEST_SUCCESS;
11327 }
11328 
11329 struct multi_session_params {
11330 	struct crypto_unittest_params ut_params;
11331 	uint8_t *cipher_key;
11332 	uint8_t *hmac_key;
11333 	const uint8_t *cipher;
11334 	const uint8_t *digest;
11335 	uint8_t *iv;
11336 };
11337 
11338 #define MB_SESSION_NUMBER 3
11339 
11340 static int
11341 test_multi_session_random_usage(void)
11342 {
11343 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11344 	struct rte_cryptodev_info dev_info;
11345 	struct rte_cryptodev_sym_session **sessions;
11346 	uint32_t i, j;
11347 	struct multi_session_params ut_paramz[] = {
11348 
11349 		{
11350 			.cipher_key = ms_aes_cbc_key0,
11351 			.hmac_key = ms_hmac_key0,
11352 			.cipher = ms_aes_cbc_cipher0,
11353 			.digest = ms_hmac_digest0,
11354 			.iv = ms_aes_cbc_iv0
11355 		},
11356 		{
11357 			.cipher_key = ms_aes_cbc_key1,
11358 			.hmac_key = ms_hmac_key1,
11359 			.cipher = ms_aes_cbc_cipher1,
11360 			.digest = ms_hmac_digest1,
11361 			.iv = ms_aes_cbc_iv1
11362 		},
11363 		{
11364 			.cipher_key = ms_aes_cbc_key2,
11365 			.hmac_key = ms_hmac_key2,
11366 			.cipher = ms_aes_cbc_cipher2,
11367 			.digest = ms_hmac_digest2,
11368 			.iv = ms_aes_cbc_iv2
11369 		},
11370 
11371 	};
11372 
11373 	/* Verify the capabilities */
11374 	struct rte_cryptodev_sym_capability_idx cap_idx;
11375 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11376 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
11377 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11378 			&cap_idx) == NULL)
11379 		return TEST_SKIPPED;
11380 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11381 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11382 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11383 			&cap_idx) == NULL)
11384 		return TEST_SKIPPED;
11385 
11386 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11387 
11388 	sessions = rte_malloc(NULL,
11389 			(sizeof(struct rte_cryptodev_sym_session *)
11390 					* MAX_NB_SESSIONS) + 1, 0);
11391 
11392 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
11393 		sessions[i] = rte_cryptodev_sym_session_create(
11394 				ts_params->session_mpool);
11395 
11396 		rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
11397 				sizeof(struct crypto_unittest_params));
11398 
11399 		test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
11400 				&ut_paramz[i].ut_params,
11401 				ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
11402 
11403 		/* Create multiple crypto sessions*/
11404 		rte_cryptodev_sym_session_init(
11405 				ts_params->valid_devs[0],
11406 				sessions[i],
11407 				&ut_paramz[i].ut_params.auth_xform,
11408 				ts_params->session_priv_mpool);
11409 
11410 		TEST_ASSERT_NOT_NULL(sessions[i],
11411 				"Session creation failed at session number %u",
11412 				i);
11413 
11414 	}
11415 
11416 	srand(time(NULL));
11417 	for (i = 0; i < 40000; i++) {
11418 
11419 		j = rand() % MB_SESSION_NUMBER;
11420 
11421 		TEST_ASSERT_SUCCESS(
11422 			test_AES_CBC_HMAC_SHA512_decrypt_perform(
11423 					sessions[j],
11424 					&ut_paramz[j].ut_params,
11425 					ts_params, ut_paramz[j].cipher,
11426 					ut_paramz[j].digest,
11427 					ut_paramz[j].iv),
11428 			"Failed to perform decrypt on request number %u.", i);
11429 
11430 		if (ut_paramz[j].ut_params.op)
11431 			rte_crypto_op_free(ut_paramz[j].ut_params.op);
11432 
11433 		/*
11434 		 * free mbuf - both obuf and ibuf are usually the same,
11435 		 * so check if they point at the same address is necessary,
11436 		 * to avoid freeing the mbuf twice.
11437 		 */
11438 		if (ut_paramz[j].ut_params.obuf) {
11439 			rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
11440 			if (ut_paramz[j].ut_params.ibuf
11441 					== ut_paramz[j].ut_params.obuf)
11442 				ut_paramz[j].ut_params.ibuf = 0;
11443 			ut_paramz[j].ut_params.obuf = 0;
11444 		}
11445 		if (ut_paramz[j].ut_params.ibuf) {
11446 			rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
11447 			ut_paramz[j].ut_params.ibuf = 0;
11448 		}
11449 	}
11450 
11451 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
11452 		rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
11453 				sessions[i]);
11454 		rte_cryptodev_sym_session_free(sessions[i]);
11455 	}
11456 
11457 	rte_free(sessions);
11458 
11459 	return TEST_SUCCESS;
11460 }
11461 
11462 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
11463 			0xab, 0xab, 0xab, 0xab,
11464 			0xab, 0xab, 0xab, 0xab,
11465 			0xab, 0xab, 0xab, 0xab};
11466 
11467 static int
11468 test_null_invalid_operation(void)
11469 {
11470 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11471 	struct crypto_unittest_params *ut_params = &unittest_params;
11472 	int ret;
11473 
11474 	/* This test is for NULL PMD only */
11475 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
11476 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11477 		return TEST_SKIPPED;
11478 
11479 	/* Setup Cipher Parameters */
11480 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11481 	ut_params->cipher_xform.next = NULL;
11482 
11483 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
11484 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11485 
11486 	ut_params->sess = rte_cryptodev_sym_session_create(
11487 			ts_params->session_mpool);
11488 
11489 	/* Create Crypto session*/
11490 	ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11491 			ut_params->sess, &ut_params->cipher_xform,
11492 			ts_params->session_priv_mpool);
11493 	TEST_ASSERT(ret < 0,
11494 			"Session creation succeeded unexpectedly");
11495 
11496 
11497 	/* Setup HMAC Parameters */
11498 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11499 	ut_params->auth_xform.next = NULL;
11500 
11501 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
11502 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11503 
11504 	ut_params->sess = rte_cryptodev_sym_session_create(
11505 			ts_params->session_mpool);
11506 
11507 	/* Create Crypto session*/
11508 	ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11509 			ut_params->sess, &ut_params->auth_xform,
11510 			ts_params->session_priv_mpool);
11511 	TEST_ASSERT(ret < 0,
11512 			"Session creation succeeded unexpectedly");
11513 
11514 	return TEST_SUCCESS;
11515 }
11516 
11517 
11518 #define NULL_BURST_LENGTH (32)
11519 
11520 static int
11521 test_null_burst_operation(void)
11522 {
11523 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11524 	struct crypto_unittest_params *ut_params = &unittest_params;
11525 
11526 	unsigned i, burst_len = NULL_BURST_LENGTH;
11527 
11528 	struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
11529 	struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
11530 
11531 	/* This test is for NULL PMD only */
11532 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
11533 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11534 		return TEST_SKIPPED;
11535 
11536 	/* Setup Cipher Parameters */
11537 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11538 	ut_params->cipher_xform.next = &ut_params->auth_xform;
11539 
11540 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
11541 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11542 
11543 	/* Setup HMAC Parameters */
11544 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11545 	ut_params->auth_xform.next = NULL;
11546 
11547 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
11548 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11549 
11550 	ut_params->sess = rte_cryptodev_sym_session_create(
11551 			ts_params->session_mpool);
11552 
11553 	/* Create Crypto session*/
11554 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11555 			ut_params->sess, &ut_params->cipher_xform,
11556 			ts_params->session_priv_mpool);
11557 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11558 
11559 	TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
11560 			RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
11561 			burst_len, "failed to generate burst of crypto ops");
11562 
11563 	/* Generate an operation for each mbuf in burst */
11564 	for (i = 0; i < burst_len; i++) {
11565 		struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11566 
11567 		TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
11568 
11569 		unsigned *data = (unsigned *)rte_pktmbuf_append(m,
11570 				sizeof(unsigned));
11571 		*data = i;
11572 
11573 		rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
11574 
11575 		burst[i]->sym->m_src = m;
11576 	}
11577 
11578 	/* Process crypto operation */
11579 	TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
11580 			0, burst, burst_len),
11581 			burst_len,
11582 			"Error enqueuing burst");
11583 
11584 	TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
11585 			0, burst_dequeued, burst_len),
11586 			burst_len,
11587 			"Error dequeuing burst");
11588 
11589 
11590 	for (i = 0; i < burst_len; i++) {
11591 		TEST_ASSERT_EQUAL(
11592 			*rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
11593 			*rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
11594 					uint32_t *),
11595 			"data not as expected");
11596 
11597 		rte_pktmbuf_free(burst[i]->sym->m_src);
11598 		rte_crypto_op_free(burst[i]);
11599 	}
11600 
11601 	return TEST_SUCCESS;
11602 }
11603 
11604 static uint16_t
11605 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11606 		  uint16_t nb_ops, void *user_param)
11607 {
11608 	RTE_SET_USED(dev_id);
11609 	RTE_SET_USED(qp_id);
11610 	RTE_SET_USED(ops);
11611 	RTE_SET_USED(user_param);
11612 
11613 	printf("crypto enqueue callback called\n");
11614 	return nb_ops;
11615 }
11616 
11617 static uint16_t
11618 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11619 		  uint16_t nb_ops, void *user_param)
11620 {
11621 	RTE_SET_USED(dev_id);
11622 	RTE_SET_USED(qp_id);
11623 	RTE_SET_USED(ops);
11624 	RTE_SET_USED(user_param);
11625 
11626 	printf("crypto dequeue callback called\n");
11627 	return nb_ops;
11628 }
11629 
11630 /*
11631  * Thread using enqueue/dequeue callback with RCU.
11632  */
11633 static int
11634 test_enqdeq_callback_thread(void *arg)
11635 {
11636 	RTE_SET_USED(arg);
11637 	/* DP thread calls rte_cryptodev_enqueue_burst()/
11638 	 * rte_cryptodev_dequeue_burst() and invokes callback.
11639 	 */
11640 	test_null_burst_operation();
11641 	return 0;
11642 }
11643 
11644 static int
11645 test_enq_callback_setup(void)
11646 {
11647 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11648 	struct rte_cryptodev_info dev_info;
11649 	struct rte_cryptodev_qp_conf qp_conf = {
11650 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
11651 	};
11652 
11653 	struct rte_cryptodev_cb *cb;
11654 	uint16_t qp_id = 0;
11655 
11656 	/* Stop the device in case it's started so it can be configured */
11657 	rte_cryptodev_stop(ts_params->valid_devs[0]);
11658 
11659 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11660 
11661 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11662 			&ts_params->conf),
11663 			"Failed to configure cryptodev %u",
11664 			ts_params->valid_devs[0]);
11665 
11666 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11667 	qp_conf.mp_session = ts_params->session_mpool;
11668 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
11669 
11670 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11671 			ts_params->valid_devs[0], qp_id, &qp_conf,
11672 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11673 			"Failed test for "
11674 			"rte_cryptodev_queue_pair_setup: num_inflights "
11675 			"%u on qp %u on cryptodev %u",
11676 			qp_conf.nb_descriptors, qp_id,
11677 			ts_params->valid_devs[0]);
11678 
11679 	/* Test with invalid crypto device */
11680 	cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
11681 			qp_id, test_enq_callback, NULL);
11682 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11683 			"cryptodev %u did not fail",
11684 			qp_id, RTE_CRYPTO_MAX_DEVS);
11685 
11686 	/* Test with invalid queue pair */
11687 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11688 			dev_info.max_nb_queue_pairs + 1,
11689 			test_enq_callback, NULL);
11690 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11691 			"cryptodev %u did not fail",
11692 			dev_info.max_nb_queue_pairs + 1,
11693 			ts_params->valid_devs[0]);
11694 
11695 	/* Test with NULL callback */
11696 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11697 			qp_id, NULL, NULL);
11698 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11699 			"cryptodev %u did not fail",
11700 			qp_id, ts_params->valid_devs[0]);
11701 
11702 	/* Test with valid configuration */
11703 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11704 			qp_id, test_enq_callback, NULL);
11705 	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11706 			"qp %u on cryptodev %u",
11707 			qp_id, ts_params->valid_devs[0]);
11708 
11709 	rte_cryptodev_start(ts_params->valid_devs[0]);
11710 
11711 	/* Launch a thread */
11712 	rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11713 				rte_get_next_lcore(-1, 1, 0));
11714 
11715 	/* Wait until reader exited. */
11716 	rte_eal_mp_wait_lcore();
11717 
11718 	/* Test with invalid crypto device */
11719 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11720 			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11721 			"Expected call to fail as crypto device is invalid");
11722 
11723 	/* Test with invalid queue pair */
11724 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11725 			ts_params->valid_devs[0],
11726 			dev_info.max_nb_queue_pairs + 1, cb),
11727 			"Expected call to fail as queue pair is invalid");
11728 
11729 	/* Test with NULL callback */
11730 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11731 			ts_params->valid_devs[0], qp_id, NULL),
11732 			"Expected call to fail as callback is NULL");
11733 
11734 	/* Test with valid configuration */
11735 	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
11736 			ts_params->valid_devs[0], qp_id, cb),
11737 			"Failed test to remove callback on "
11738 			"qp %u on cryptodev %u",
11739 			qp_id, ts_params->valid_devs[0]);
11740 
11741 	return TEST_SUCCESS;
11742 }
11743 
11744 static int
11745 test_deq_callback_setup(void)
11746 {
11747 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11748 	struct rte_cryptodev_info dev_info;
11749 	struct rte_cryptodev_qp_conf qp_conf = {
11750 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
11751 	};
11752 
11753 	struct rte_cryptodev_cb *cb;
11754 	uint16_t qp_id = 0;
11755 
11756 	/* Stop the device in case it's started so it can be configured */
11757 	rte_cryptodev_stop(ts_params->valid_devs[0]);
11758 
11759 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11760 
11761 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11762 			&ts_params->conf),
11763 			"Failed to configure cryptodev %u",
11764 			ts_params->valid_devs[0]);
11765 
11766 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11767 	qp_conf.mp_session = ts_params->session_mpool;
11768 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
11769 
11770 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11771 			ts_params->valid_devs[0], qp_id, &qp_conf,
11772 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11773 			"Failed test for "
11774 			"rte_cryptodev_queue_pair_setup: num_inflights "
11775 			"%u on qp %u on cryptodev %u",
11776 			qp_conf.nb_descriptors, qp_id,
11777 			ts_params->valid_devs[0]);
11778 
11779 	/* Test with invalid crypto device */
11780 	cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
11781 			qp_id, test_deq_callback, NULL);
11782 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11783 			"cryptodev %u did not fail",
11784 			qp_id, RTE_CRYPTO_MAX_DEVS);
11785 
11786 	/* Test with invalid queue pair */
11787 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11788 			dev_info.max_nb_queue_pairs + 1,
11789 			test_deq_callback, NULL);
11790 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11791 			"cryptodev %u did not fail",
11792 			dev_info.max_nb_queue_pairs + 1,
11793 			ts_params->valid_devs[0]);
11794 
11795 	/* Test with NULL callback */
11796 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11797 			qp_id, NULL, NULL);
11798 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11799 			"cryptodev %u did not fail",
11800 			qp_id, ts_params->valid_devs[0]);
11801 
11802 	/* Test with valid configuration */
11803 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11804 			qp_id, test_deq_callback, NULL);
11805 	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11806 			"qp %u on cryptodev %u",
11807 			qp_id, ts_params->valid_devs[0]);
11808 
11809 	rte_cryptodev_start(ts_params->valid_devs[0]);
11810 
11811 	/* Launch a thread */
11812 	rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11813 				rte_get_next_lcore(-1, 1, 0));
11814 
11815 	/* Wait until reader exited. */
11816 	rte_eal_mp_wait_lcore();
11817 
11818 	/* Test with invalid crypto device */
11819 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11820 			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11821 			"Expected call to fail as crypto device is invalid");
11822 
11823 	/* Test with invalid queue pair */
11824 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11825 			ts_params->valid_devs[0],
11826 			dev_info.max_nb_queue_pairs + 1, cb),
11827 			"Expected call to fail as queue pair is invalid");
11828 
11829 	/* Test with NULL callback */
11830 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11831 			ts_params->valid_devs[0], qp_id, NULL),
11832 			"Expected call to fail as callback is NULL");
11833 
11834 	/* Test with valid configuration */
11835 	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
11836 			ts_params->valid_devs[0], qp_id, cb),
11837 			"Failed test to remove callback on "
11838 			"qp %u on cryptodev %u",
11839 			qp_id, ts_params->valid_devs[0]);
11840 
11841 	return TEST_SUCCESS;
11842 }
11843 
11844 static void
11845 generate_gmac_large_plaintext(uint8_t *data)
11846 {
11847 	uint16_t i;
11848 
11849 	for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
11850 		memcpy(&data[i], &data[0], 32);
11851 }
11852 
11853 static int
11854 create_gmac_operation(enum rte_crypto_auth_operation op,
11855 		const struct gmac_test_data *tdata)
11856 {
11857 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11858 	struct crypto_unittest_params *ut_params = &unittest_params;
11859 	struct rte_crypto_sym_op *sym_op;
11860 
11861 	uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11862 
11863 	/* Generate Crypto op data structure */
11864 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11865 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11866 	TEST_ASSERT_NOT_NULL(ut_params->op,
11867 			"Failed to allocate symmetric crypto operation struct");
11868 
11869 	sym_op = ut_params->op->sym;
11870 
11871 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11872 			ut_params->ibuf, tdata->gmac_tag.len);
11873 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11874 			"no room to append digest");
11875 
11876 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11877 			ut_params->ibuf, plaintext_pad_len);
11878 
11879 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11880 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11881 				tdata->gmac_tag.len);
11882 		debug_hexdump(stdout, "digest:",
11883 				sym_op->auth.digest.data,
11884 				tdata->gmac_tag.len);
11885 	}
11886 
11887 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11888 			uint8_t *, IV_OFFSET);
11889 
11890 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11891 
11892 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11893 
11894 	sym_op->cipher.data.length = 0;
11895 	sym_op->cipher.data.offset = 0;
11896 
11897 	sym_op->auth.data.offset = 0;
11898 	sym_op->auth.data.length = tdata->plaintext.len;
11899 
11900 	return 0;
11901 }
11902 
11903 static int
11904 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
11905 		const struct gmac_test_data *tdata,
11906 		void *digest_mem, uint64_t digest_phys)
11907 {
11908 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11909 	struct crypto_unittest_params *ut_params = &unittest_params;
11910 	struct rte_crypto_sym_op *sym_op;
11911 
11912 	/* Generate Crypto op data structure */
11913 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11914 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11915 	TEST_ASSERT_NOT_NULL(ut_params->op,
11916 			"Failed to allocate symmetric crypto operation struct");
11917 
11918 	sym_op = ut_params->op->sym;
11919 
11920 	sym_op->auth.digest.data = digest_mem;
11921 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11922 			"no room to append digest");
11923 
11924 	sym_op->auth.digest.phys_addr = digest_phys;
11925 
11926 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11927 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11928 				tdata->gmac_tag.len);
11929 		debug_hexdump(stdout, "digest:",
11930 				sym_op->auth.digest.data,
11931 				tdata->gmac_tag.len);
11932 	}
11933 
11934 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11935 			uint8_t *, IV_OFFSET);
11936 
11937 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11938 
11939 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11940 
11941 	sym_op->cipher.data.length = 0;
11942 	sym_op->cipher.data.offset = 0;
11943 
11944 	sym_op->auth.data.offset = 0;
11945 	sym_op->auth.data.length = tdata->plaintext.len;
11946 
11947 	return 0;
11948 }
11949 
11950 static int create_gmac_session(uint8_t dev_id,
11951 		const struct gmac_test_data *tdata,
11952 		enum rte_crypto_auth_operation auth_op)
11953 {
11954 	uint8_t auth_key[tdata->key.len];
11955 
11956 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11957 	struct crypto_unittest_params *ut_params = &unittest_params;
11958 
11959 	memcpy(auth_key, tdata->key.data, tdata->key.len);
11960 
11961 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11962 	ut_params->auth_xform.next = NULL;
11963 
11964 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
11965 	ut_params->auth_xform.auth.op = auth_op;
11966 	ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
11967 	ut_params->auth_xform.auth.key.length = tdata->key.len;
11968 	ut_params->auth_xform.auth.key.data = auth_key;
11969 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
11970 	ut_params->auth_xform.auth.iv.length = tdata->iv.len;
11971 
11972 
11973 	ut_params->sess = rte_cryptodev_sym_session_create(
11974 			ts_params->session_mpool);
11975 
11976 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
11977 			&ut_params->auth_xform,
11978 			ts_params->session_priv_mpool);
11979 
11980 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11981 
11982 	return 0;
11983 }
11984 
11985 static int
11986 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
11987 {
11988 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11989 	struct crypto_unittest_params *ut_params = &unittest_params;
11990 	struct rte_cryptodev_info dev_info;
11991 
11992 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11993 	uint64_t feat_flags = dev_info.feature_flags;
11994 
11995 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11996 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11997 		printf("Device doesn't support RAW data-path APIs.\n");
11998 		return TEST_SKIPPED;
11999 	}
12000 
12001 	int retval;
12002 
12003 	uint8_t *auth_tag, *plaintext;
12004 	uint16_t plaintext_pad_len;
12005 
12006 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12007 			      "No GMAC length in the source data");
12008 
12009 	/* Verify the capabilities */
12010 	struct rte_cryptodev_sym_capability_idx cap_idx;
12011 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12012 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12013 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12014 			&cap_idx) == NULL)
12015 		return TEST_SKIPPED;
12016 
12017 	retval = create_gmac_session(ts_params->valid_devs[0],
12018 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
12019 
12020 	if (retval < 0)
12021 		return retval;
12022 
12023 	if (tdata->plaintext.len > MBUF_SIZE)
12024 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
12025 	else
12026 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12027 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12028 			"Failed to allocate input buffer in mempool");
12029 
12030 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12031 			rte_pktmbuf_tailroom(ut_params->ibuf));
12032 
12033 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12034 	/*
12035 	 * Runtime generate the large plain text instead of use hard code
12036 	 * plain text vector. It is done to avoid create huge source file
12037 	 * with the test vector.
12038 	 */
12039 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
12040 		generate_gmac_large_plaintext(tdata->plaintext.data);
12041 
12042 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12043 				plaintext_pad_len);
12044 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12045 
12046 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
12047 	debug_hexdump(stdout, "plaintext:", plaintext,
12048 			tdata->plaintext.len);
12049 
12050 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
12051 			tdata);
12052 
12053 	if (retval < 0)
12054 		return retval;
12055 
12056 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12057 
12058 	ut_params->op->sym->m_src = ut_params->ibuf;
12059 
12060 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12061 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12062 			ut_params->op);
12063 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12064 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12065 				ut_params->op, 0, 1, 0, 0);
12066 	else
12067 		TEST_ASSERT_NOT_NULL(
12068 			process_crypto_request(ts_params->valid_devs[0],
12069 			ut_params->op), "failed to process sym crypto op");
12070 
12071 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12072 			"crypto op processing failed");
12073 
12074 	if (ut_params->op->sym->m_dst) {
12075 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
12076 				uint8_t *, plaintext_pad_len);
12077 	} else {
12078 		auth_tag = plaintext + plaintext_pad_len;
12079 	}
12080 
12081 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
12082 
12083 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12084 			auth_tag,
12085 			tdata->gmac_tag.data,
12086 			tdata->gmac_tag.len,
12087 			"GMAC Generated auth tag not as expected");
12088 
12089 	return 0;
12090 }
12091 
12092 static int
12093 test_AES_GMAC_authentication_test_case_1(void)
12094 {
12095 	return test_AES_GMAC_authentication(&gmac_test_case_1);
12096 }
12097 
12098 static int
12099 test_AES_GMAC_authentication_test_case_2(void)
12100 {
12101 	return test_AES_GMAC_authentication(&gmac_test_case_2);
12102 }
12103 
12104 static int
12105 test_AES_GMAC_authentication_test_case_3(void)
12106 {
12107 	return test_AES_GMAC_authentication(&gmac_test_case_3);
12108 }
12109 
12110 static int
12111 test_AES_GMAC_authentication_test_case_4(void)
12112 {
12113 	return test_AES_GMAC_authentication(&gmac_test_case_4);
12114 }
12115 
12116 static int
12117 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
12118 {
12119 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12120 	struct crypto_unittest_params *ut_params = &unittest_params;
12121 	int retval;
12122 	uint32_t plaintext_pad_len;
12123 	uint8_t *plaintext;
12124 	struct rte_cryptodev_info dev_info;
12125 
12126 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12127 	uint64_t feat_flags = dev_info.feature_flags;
12128 
12129 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12130 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12131 		printf("Device doesn't support RAW data-path APIs.\n");
12132 		return TEST_SKIPPED;
12133 	}
12134 
12135 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12136 			      "No GMAC length in the source data");
12137 
12138 	/* Verify the capabilities */
12139 	struct rte_cryptodev_sym_capability_idx cap_idx;
12140 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12141 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12142 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12143 			&cap_idx) == NULL)
12144 		return TEST_SKIPPED;
12145 
12146 	retval = create_gmac_session(ts_params->valid_devs[0],
12147 			tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
12148 
12149 	if (retval < 0)
12150 		return retval;
12151 
12152 	if (tdata->plaintext.len > MBUF_SIZE)
12153 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
12154 	else
12155 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12156 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12157 			"Failed to allocate input buffer in mempool");
12158 
12159 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12160 			rte_pktmbuf_tailroom(ut_params->ibuf));
12161 
12162 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12163 
12164 	/*
12165 	 * Runtime generate the large plain text instead of use hard code
12166 	 * plain text vector. It is done to avoid create huge source file
12167 	 * with the test vector.
12168 	 */
12169 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
12170 		generate_gmac_large_plaintext(tdata->plaintext.data);
12171 
12172 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12173 				plaintext_pad_len);
12174 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12175 
12176 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
12177 	debug_hexdump(stdout, "plaintext:", plaintext,
12178 			tdata->plaintext.len);
12179 
12180 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
12181 			tdata);
12182 
12183 	if (retval < 0)
12184 		return retval;
12185 
12186 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12187 
12188 	ut_params->op->sym->m_src = ut_params->ibuf;
12189 
12190 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12191 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12192 			ut_params->op);
12193 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12194 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12195 				ut_params->op, 0, 1, 0, 0);
12196 	else
12197 		TEST_ASSERT_NOT_NULL(
12198 			process_crypto_request(ts_params->valid_devs[0],
12199 			ut_params->op), "failed to process sym crypto op");
12200 
12201 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12202 			"crypto op processing failed");
12203 
12204 	return 0;
12205 
12206 }
12207 
12208 static int
12209 test_AES_GMAC_authentication_verify_test_case_1(void)
12210 {
12211 	return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
12212 }
12213 
12214 static int
12215 test_AES_GMAC_authentication_verify_test_case_2(void)
12216 {
12217 	return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
12218 }
12219 
12220 static int
12221 test_AES_GMAC_authentication_verify_test_case_3(void)
12222 {
12223 	return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
12224 }
12225 
12226 static int
12227 test_AES_GMAC_authentication_verify_test_case_4(void)
12228 {
12229 	return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
12230 }
12231 
12232 static int
12233 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
12234 				uint32_t fragsz)
12235 {
12236 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12237 	struct crypto_unittest_params *ut_params = &unittest_params;
12238 	struct rte_cryptodev_info dev_info;
12239 	uint64_t feature_flags;
12240 	unsigned int trn_data = 0;
12241 	void *digest_mem = NULL;
12242 	uint32_t segs = 1;
12243 	unsigned int to_trn = 0;
12244 	struct rte_mbuf *buf = NULL;
12245 	uint8_t *auth_tag, *plaintext;
12246 	int retval;
12247 
12248 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12249 			      "No GMAC length in the source data");
12250 
12251 	/* Verify the capabilities */
12252 	struct rte_cryptodev_sym_capability_idx cap_idx;
12253 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12254 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12255 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12256 			&cap_idx) == NULL)
12257 		return TEST_SKIPPED;
12258 
12259 	/* Check for any input SGL support */
12260 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12261 	feature_flags = dev_info.feature_flags;
12262 
12263 	if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
12264 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
12265 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
12266 		return TEST_SKIPPED;
12267 
12268 	if (fragsz > tdata->plaintext.len)
12269 		fragsz = tdata->plaintext.len;
12270 
12271 	uint16_t plaintext_len = fragsz;
12272 
12273 	retval = create_gmac_session(ts_params->valid_devs[0],
12274 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
12275 
12276 	if (retval < 0)
12277 		return retval;
12278 
12279 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12280 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12281 			"Failed to allocate input buffer in mempool");
12282 
12283 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12284 			rte_pktmbuf_tailroom(ut_params->ibuf));
12285 
12286 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12287 				plaintext_len);
12288 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12289 
12290 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
12291 
12292 	trn_data += plaintext_len;
12293 
12294 	buf = ut_params->ibuf;
12295 
12296 	/*
12297 	 * Loop until no more fragments
12298 	 */
12299 
12300 	while (trn_data < tdata->plaintext.len) {
12301 		++segs;
12302 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
12303 				(tdata->plaintext.len - trn_data) : fragsz;
12304 
12305 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12306 		buf = buf->next;
12307 
12308 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
12309 				rte_pktmbuf_tailroom(buf));
12310 
12311 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
12312 				to_trn);
12313 
12314 		memcpy(plaintext, tdata->plaintext.data + trn_data,
12315 				to_trn);
12316 		trn_data += to_trn;
12317 		if (trn_data  == tdata->plaintext.len)
12318 			digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
12319 					tdata->gmac_tag.len);
12320 	}
12321 	ut_params->ibuf->nb_segs = segs;
12322 
12323 	/*
12324 	 * Place digest at the end of the last buffer
12325 	 */
12326 	uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
12327 
12328 	if (!digest_mem) {
12329 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12330 				+ tdata->gmac_tag.len);
12331 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
12332 				tdata->plaintext.len);
12333 	}
12334 
12335 	retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
12336 			tdata, digest_mem, digest_phys);
12337 
12338 	if (retval < 0)
12339 		return retval;
12340 
12341 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12342 
12343 	ut_params->op->sym->m_src = ut_params->ibuf;
12344 
12345 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12346 		return TEST_SKIPPED;
12347 
12348 	TEST_ASSERT_NOT_NULL(
12349 		process_crypto_request(ts_params->valid_devs[0],
12350 		ut_params->op), "failed to process sym crypto op");
12351 
12352 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12353 			"crypto op processing failed");
12354 
12355 	auth_tag = digest_mem;
12356 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
12357 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12358 			auth_tag,
12359 			tdata->gmac_tag.data,
12360 			tdata->gmac_tag.len,
12361 			"GMAC Generated auth tag not as expected");
12362 
12363 	return 0;
12364 }
12365 
12366 /* Segment size not multiple of block size (16B) */
12367 static int
12368 test_AES_GMAC_authentication_SGL_40B(void)
12369 {
12370 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
12371 }
12372 
12373 static int
12374 test_AES_GMAC_authentication_SGL_80B(void)
12375 {
12376 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
12377 }
12378 
12379 static int
12380 test_AES_GMAC_authentication_SGL_2048B(void)
12381 {
12382 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
12383 }
12384 
12385 /* Segment size not multiple of block size (16B) */
12386 static int
12387 test_AES_GMAC_authentication_SGL_2047B(void)
12388 {
12389 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
12390 }
12391 
12392 struct test_crypto_vector {
12393 	enum rte_crypto_cipher_algorithm crypto_algo;
12394 	unsigned int cipher_offset;
12395 	unsigned int cipher_len;
12396 
12397 	struct {
12398 		uint8_t data[64];
12399 		unsigned int len;
12400 	} cipher_key;
12401 
12402 	struct {
12403 		uint8_t data[64];
12404 		unsigned int len;
12405 	} iv;
12406 
12407 	struct {
12408 		const uint8_t *data;
12409 		unsigned int len;
12410 	} plaintext;
12411 
12412 	struct {
12413 		const uint8_t *data;
12414 		unsigned int len;
12415 	} ciphertext;
12416 
12417 	enum rte_crypto_auth_algorithm auth_algo;
12418 	unsigned int auth_offset;
12419 
12420 	struct {
12421 		uint8_t data[128];
12422 		unsigned int len;
12423 	} auth_key;
12424 
12425 	struct {
12426 		const uint8_t *data;
12427 		unsigned int len;
12428 	} aad;
12429 
12430 	struct {
12431 		uint8_t data[128];
12432 		unsigned int len;
12433 	} digest;
12434 };
12435 
12436 static const struct test_crypto_vector
12437 hmac_sha1_test_crypto_vector = {
12438 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12439 	.plaintext = {
12440 		.data = plaintext_hash,
12441 		.len = 512
12442 	},
12443 	.auth_key = {
12444 		.data = {
12445 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12446 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12447 			0xDE, 0xF4, 0xDE, 0xAD
12448 		},
12449 		.len = 20
12450 	},
12451 	.digest = {
12452 		.data = {
12453 			0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
12454 			0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
12455 			0x3F, 0x91, 0x64, 0x59
12456 		},
12457 		.len = 20
12458 	}
12459 };
12460 
12461 static const struct test_crypto_vector
12462 aes128_gmac_test_vector = {
12463 	.auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
12464 	.plaintext = {
12465 		.data = plaintext_hash,
12466 		.len = 512
12467 	},
12468 	.iv = {
12469 		.data = {
12470 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12471 			0x08, 0x09, 0x0A, 0x0B
12472 		},
12473 		.len = 12
12474 	},
12475 	.auth_key = {
12476 		.data = {
12477 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12478 			0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
12479 		},
12480 		.len = 16
12481 	},
12482 	.digest = {
12483 		.data = {
12484 			0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
12485 			0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
12486 		},
12487 		.len = 16
12488 	}
12489 };
12490 
12491 static const struct test_crypto_vector
12492 aes128cbc_hmac_sha1_test_vector = {
12493 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12494 	.cipher_offset = 0,
12495 	.cipher_len = 512,
12496 	.cipher_key = {
12497 		.data = {
12498 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12499 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12500 		},
12501 		.len = 16
12502 	},
12503 	.iv = {
12504 		.data = {
12505 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12506 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12507 		},
12508 		.len = 16
12509 	},
12510 	.plaintext = {
12511 		.data = plaintext_hash,
12512 		.len = 512
12513 	},
12514 	.ciphertext = {
12515 		.data = ciphertext512_aes128cbc,
12516 		.len = 512
12517 	},
12518 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12519 	.auth_offset = 0,
12520 	.auth_key = {
12521 		.data = {
12522 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12523 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12524 			0xDE, 0xF4, 0xDE, 0xAD
12525 		},
12526 		.len = 20
12527 	},
12528 	.digest = {
12529 		.data = {
12530 			0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
12531 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12532 			0x18, 0x8C, 0x1D, 0x32
12533 		},
12534 		.len = 20
12535 	}
12536 };
12537 
12538 static const struct test_crypto_vector
12539 aes128cbc_hmac_sha1_aad_test_vector = {
12540 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12541 	.cipher_offset = 8,
12542 	.cipher_len = 496,
12543 	.cipher_key = {
12544 		.data = {
12545 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12546 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12547 		},
12548 		.len = 16
12549 	},
12550 	.iv = {
12551 		.data = {
12552 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12553 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12554 		},
12555 		.len = 16
12556 	},
12557 	.plaintext = {
12558 		.data = plaintext_hash,
12559 		.len = 512
12560 	},
12561 	.ciphertext = {
12562 		.data = ciphertext512_aes128cbc_aad,
12563 		.len = 512
12564 	},
12565 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12566 	.auth_offset = 0,
12567 	.auth_key = {
12568 		.data = {
12569 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12570 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12571 			0xDE, 0xF4, 0xDE, 0xAD
12572 		},
12573 		.len = 20
12574 	},
12575 	.digest = {
12576 		.data = {
12577 			0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
12578 			0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
12579 			0x62, 0x0F, 0xFB, 0x10
12580 		},
12581 		.len = 20
12582 	}
12583 };
12584 
12585 static void
12586 data_corruption(uint8_t *data)
12587 {
12588 	data[0] += 1;
12589 }
12590 
12591 static void
12592 tag_corruption(uint8_t *data, unsigned int tag_offset)
12593 {
12594 	data[tag_offset] += 1;
12595 }
12596 
12597 static int
12598 create_auth_session(struct crypto_unittest_params *ut_params,
12599 		uint8_t dev_id,
12600 		const struct test_crypto_vector *reference,
12601 		enum rte_crypto_auth_operation auth_op)
12602 {
12603 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12604 	uint8_t auth_key[reference->auth_key.len + 1];
12605 
12606 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12607 
12608 	/* Setup Authentication Parameters */
12609 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12610 	ut_params->auth_xform.auth.op = auth_op;
12611 	ut_params->auth_xform.next = NULL;
12612 	ut_params->auth_xform.auth.algo = reference->auth_algo;
12613 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12614 	ut_params->auth_xform.auth.key.data = auth_key;
12615 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
12616 
12617 	/* Create Crypto session*/
12618 	ut_params->sess = rte_cryptodev_sym_session_create(
12619 			ts_params->session_mpool);
12620 
12621 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12622 				&ut_params->auth_xform,
12623 				ts_params->session_priv_mpool);
12624 
12625 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12626 
12627 	return 0;
12628 }
12629 
12630 static int
12631 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
12632 		uint8_t dev_id,
12633 		const struct test_crypto_vector *reference,
12634 		enum rte_crypto_auth_operation auth_op,
12635 		enum rte_crypto_cipher_operation cipher_op)
12636 {
12637 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12638 	uint8_t cipher_key[reference->cipher_key.len + 1];
12639 	uint8_t auth_key[reference->auth_key.len + 1];
12640 
12641 	memcpy(cipher_key, reference->cipher_key.data,
12642 			reference->cipher_key.len);
12643 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12644 
12645 	/* Setup Authentication Parameters */
12646 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12647 	ut_params->auth_xform.auth.op = auth_op;
12648 	ut_params->auth_xform.auth.algo = reference->auth_algo;
12649 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12650 	ut_params->auth_xform.auth.key.data = auth_key;
12651 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
12652 
12653 	if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
12654 		ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12655 		ut_params->auth_xform.auth.iv.length = reference->iv.len;
12656 	} else {
12657 		ut_params->auth_xform.next = &ut_params->cipher_xform;
12658 
12659 		/* Setup Cipher Parameters */
12660 		ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12661 		ut_params->cipher_xform.next = NULL;
12662 		ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12663 		ut_params->cipher_xform.cipher.op = cipher_op;
12664 		ut_params->cipher_xform.cipher.key.data = cipher_key;
12665 		ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12666 		ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12667 		ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12668 	}
12669 
12670 	/* Create Crypto session*/
12671 	ut_params->sess = rte_cryptodev_sym_session_create(
12672 			ts_params->session_mpool);
12673 
12674 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12675 				&ut_params->auth_xform,
12676 				ts_params->session_priv_mpool);
12677 
12678 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12679 
12680 	return 0;
12681 }
12682 
12683 static int
12684 create_auth_operation(struct crypto_testsuite_params *ts_params,
12685 		struct crypto_unittest_params *ut_params,
12686 		const struct test_crypto_vector *reference,
12687 		unsigned int auth_generate)
12688 {
12689 	/* Generate Crypto op data structure */
12690 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12691 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12692 	TEST_ASSERT_NOT_NULL(ut_params->op,
12693 			"Failed to allocate pktmbuf offload");
12694 
12695 	/* Set crypto operation data parameters */
12696 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12697 
12698 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12699 
12700 	/* set crypto operation source mbuf */
12701 	sym_op->m_src = ut_params->ibuf;
12702 
12703 	/* digest */
12704 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12705 			ut_params->ibuf, reference->digest.len);
12706 
12707 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12708 			"no room to append auth tag");
12709 
12710 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12711 			ut_params->ibuf, reference->plaintext.len);
12712 
12713 	if (auth_generate)
12714 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
12715 	else
12716 		memcpy(sym_op->auth.digest.data,
12717 				reference->digest.data,
12718 				reference->digest.len);
12719 
12720 	debug_hexdump(stdout, "digest:",
12721 			sym_op->auth.digest.data,
12722 			reference->digest.len);
12723 
12724 	sym_op->auth.data.length = reference->plaintext.len;
12725 	sym_op->auth.data.offset = 0;
12726 
12727 	return 0;
12728 }
12729 
12730 static int
12731 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
12732 		struct crypto_unittest_params *ut_params,
12733 		const struct test_crypto_vector *reference,
12734 		unsigned int auth_generate)
12735 {
12736 	/* Generate Crypto op data structure */
12737 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12738 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12739 	TEST_ASSERT_NOT_NULL(ut_params->op,
12740 			"Failed to allocate pktmbuf offload");
12741 
12742 	/* Set crypto operation data parameters */
12743 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12744 
12745 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12746 
12747 	/* set crypto operation source mbuf */
12748 	sym_op->m_src = ut_params->ibuf;
12749 
12750 	/* digest */
12751 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12752 			ut_params->ibuf, reference->digest.len);
12753 
12754 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12755 			"no room to append auth tag");
12756 
12757 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12758 			ut_params->ibuf, reference->ciphertext.len);
12759 
12760 	if (auth_generate)
12761 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
12762 	else
12763 		memcpy(sym_op->auth.digest.data,
12764 				reference->digest.data,
12765 				reference->digest.len);
12766 
12767 	debug_hexdump(stdout, "digest:",
12768 			sym_op->auth.digest.data,
12769 			reference->digest.len);
12770 
12771 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12772 			reference->iv.data, reference->iv.len);
12773 
12774 	sym_op->cipher.data.length = 0;
12775 	sym_op->cipher.data.offset = 0;
12776 
12777 	sym_op->auth.data.length = reference->plaintext.len;
12778 	sym_op->auth.data.offset = 0;
12779 
12780 	return 0;
12781 }
12782 
12783 static int
12784 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
12785 		struct crypto_unittest_params *ut_params,
12786 		const struct test_crypto_vector *reference,
12787 		unsigned int auth_generate)
12788 {
12789 	/* Generate Crypto op data structure */
12790 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12791 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12792 	TEST_ASSERT_NOT_NULL(ut_params->op,
12793 			"Failed to allocate pktmbuf offload");
12794 
12795 	/* Set crypto operation data parameters */
12796 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12797 
12798 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12799 
12800 	/* set crypto operation source mbuf */
12801 	sym_op->m_src = ut_params->ibuf;
12802 
12803 	/* digest */
12804 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12805 			ut_params->ibuf, reference->digest.len);
12806 
12807 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12808 			"no room to append auth tag");
12809 
12810 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12811 			ut_params->ibuf, reference->ciphertext.len);
12812 
12813 	if (auth_generate)
12814 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
12815 	else
12816 		memcpy(sym_op->auth.digest.data,
12817 				reference->digest.data,
12818 				reference->digest.len);
12819 
12820 	debug_hexdump(stdout, "digest:",
12821 			sym_op->auth.digest.data,
12822 			reference->digest.len);
12823 
12824 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12825 			reference->iv.data, reference->iv.len);
12826 
12827 	sym_op->cipher.data.length = reference->cipher_len;
12828 	sym_op->cipher.data.offset = reference->cipher_offset;
12829 
12830 	sym_op->auth.data.length = reference->plaintext.len;
12831 	sym_op->auth.data.offset = reference->auth_offset;
12832 
12833 	return 0;
12834 }
12835 
12836 static int
12837 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12838 		struct crypto_unittest_params *ut_params,
12839 		const struct test_crypto_vector *reference)
12840 {
12841 	return create_auth_operation(ts_params, ut_params, reference, 0);
12842 }
12843 
12844 static int
12845 create_auth_verify_GMAC_operation(
12846 		struct crypto_testsuite_params *ts_params,
12847 		struct crypto_unittest_params *ut_params,
12848 		const struct test_crypto_vector *reference)
12849 {
12850 	return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
12851 }
12852 
12853 static int
12854 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12855 		struct crypto_unittest_params *ut_params,
12856 		const struct test_crypto_vector *reference)
12857 {
12858 	return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
12859 }
12860 
12861 static int
12862 test_authentication_verify_fail_when_data_corruption(
12863 		struct crypto_testsuite_params *ts_params,
12864 		struct crypto_unittest_params *ut_params,
12865 		const struct test_crypto_vector *reference,
12866 		unsigned int data_corrupted)
12867 {
12868 	int retval;
12869 
12870 	uint8_t *plaintext;
12871 	struct rte_cryptodev_info dev_info;
12872 
12873 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12874 	uint64_t feat_flags = dev_info.feature_flags;
12875 
12876 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12877 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12878 		printf("Device doesn't support RAW data-path APIs.\n");
12879 		return TEST_SKIPPED;
12880 	}
12881 
12882 	/* Verify the capabilities */
12883 	struct rte_cryptodev_sym_capability_idx cap_idx;
12884 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12885 	cap_idx.algo.auth = reference->auth_algo;
12886 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12887 			&cap_idx) == NULL)
12888 		return TEST_SKIPPED;
12889 
12890 
12891 	/* Create session */
12892 	retval = create_auth_session(ut_params,
12893 			ts_params->valid_devs[0],
12894 			reference,
12895 			RTE_CRYPTO_AUTH_OP_VERIFY);
12896 	if (retval < 0)
12897 		return retval;
12898 
12899 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12900 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12901 			"Failed to allocate input buffer in mempool");
12902 
12903 	/* clear mbuf payload */
12904 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12905 			rte_pktmbuf_tailroom(ut_params->ibuf));
12906 
12907 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12908 			reference->plaintext.len);
12909 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12910 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12911 
12912 	debug_hexdump(stdout, "plaintext:", plaintext,
12913 		reference->plaintext.len);
12914 
12915 	/* Create operation */
12916 	retval = create_auth_verify_operation(ts_params, ut_params, reference);
12917 
12918 	if (retval < 0)
12919 		return retval;
12920 
12921 	if (data_corrupted)
12922 		data_corruption(plaintext);
12923 	else
12924 		tag_corruption(plaintext, reference->plaintext.len);
12925 
12926 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12927 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12928 			ut_params->op);
12929 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12930 			RTE_CRYPTO_OP_STATUS_SUCCESS,
12931 			"authentication not failed");
12932 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12933 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12934 				ut_params->op, 0, 1, 0, 0);
12935 	else {
12936 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12937 			ut_params->op);
12938 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12939 	}
12940 
12941 	return 0;
12942 }
12943 
12944 static int
12945 test_authentication_verify_GMAC_fail_when_corruption(
12946 		struct crypto_testsuite_params *ts_params,
12947 		struct crypto_unittest_params *ut_params,
12948 		const struct test_crypto_vector *reference,
12949 		unsigned int data_corrupted)
12950 {
12951 	int retval;
12952 	uint8_t *plaintext;
12953 	struct rte_cryptodev_info dev_info;
12954 
12955 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12956 	uint64_t feat_flags = dev_info.feature_flags;
12957 
12958 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12959 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12960 		printf("Device doesn't support RAW data-path APIs.\n");
12961 		return TEST_SKIPPED;
12962 	}
12963 
12964 	/* Verify the capabilities */
12965 	struct rte_cryptodev_sym_capability_idx cap_idx;
12966 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12967 	cap_idx.algo.auth = reference->auth_algo;
12968 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12969 			&cap_idx) == NULL)
12970 		return TEST_SKIPPED;
12971 
12972 	/* Create session */
12973 	retval = create_auth_cipher_session(ut_params,
12974 			ts_params->valid_devs[0],
12975 			reference,
12976 			RTE_CRYPTO_AUTH_OP_VERIFY,
12977 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
12978 	if (retval < 0)
12979 		return retval;
12980 
12981 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12982 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12983 			"Failed to allocate input buffer in mempool");
12984 
12985 	/* clear mbuf payload */
12986 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12987 			rte_pktmbuf_tailroom(ut_params->ibuf));
12988 
12989 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12990 			reference->plaintext.len);
12991 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12992 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12993 
12994 	debug_hexdump(stdout, "plaintext:", plaintext,
12995 		reference->plaintext.len);
12996 
12997 	/* Create operation */
12998 	retval = create_auth_verify_GMAC_operation(ts_params,
12999 			ut_params,
13000 			reference);
13001 
13002 	if (retval < 0)
13003 		return retval;
13004 
13005 	if (data_corrupted)
13006 		data_corruption(plaintext);
13007 	else
13008 		tag_corruption(plaintext, reference->aad.len);
13009 
13010 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13011 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13012 			ut_params->op);
13013 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13014 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13015 			"authentication not failed");
13016 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13017 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13018 				ut_params->op, 0, 1, 0, 0);
13019 	else {
13020 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13021 			ut_params->op);
13022 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
13023 	}
13024 
13025 	return 0;
13026 }
13027 
13028 static int
13029 test_authenticated_decryption_fail_when_corruption(
13030 		struct crypto_testsuite_params *ts_params,
13031 		struct crypto_unittest_params *ut_params,
13032 		const struct test_crypto_vector *reference,
13033 		unsigned int data_corrupted)
13034 {
13035 	int retval;
13036 
13037 	uint8_t *ciphertext;
13038 	struct rte_cryptodev_info dev_info;
13039 
13040 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13041 	uint64_t feat_flags = dev_info.feature_flags;
13042 
13043 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13044 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13045 		printf("Device doesn't support RAW data-path APIs.\n");
13046 		return TEST_SKIPPED;
13047 	}
13048 
13049 	/* Verify the capabilities */
13050 	struct rte_cryptodev_sym_capability_idx cap_idx;
13051 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13052 	cap_idx.algo.auth = reference->auth_algo;
13053 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13054 			&cap_idx) == NULL)
13055 		return TEST_SKIPPED;
13056 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13057 	cap_idx.algo.cipher = reference->crypto_algo;
13058 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13059 			&cap_idx) == NULL)
13060 		return TEST_SKIPPED;
13061 
13062 	/* Create session */
13063 	retval = create_auth_cipher_session(ut_params,
13064 			ts_params->valid_devs[0],
13065 			reference,
13066 			RTE_CRYPTO_AUTH_OP_VERIFY,
13067 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
13068 	if (retval < 0)
13069 		return retval;
13070 
13071 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13072 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13073 			"Failed to allocate input buffer in mempool");
13074 
13075 	/* clear mbuf payload */
13076 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13077 			rte_pktmbuf_tailroom(ut_params->ibuf));
13078 
13079 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13080 			reference->ciphertext.len);
13081 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
13082 	memcpy(ciphertext, reference->ciphertext.data,
13083 			reference->ciphertext.len);
13084 
13085 	/* Create operation */
13086 	retval = create_cipher_auth_verify_operation(ts_params,
13087 			ut_params,
13088 			reference);
13089 
13090 	if (retval < 0)
13091 		return retval;
13092 
13093 	if (data_corrupted)
13094 		data_corruption(ciphertext);
13095 	else
13096 		tag_corruption(ciphertext, reference->ciphertext.len);
13097 
13098 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13099 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13100 			ut_params->op);
13101 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13102 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13103 			"authentication not failed");
13104 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13105 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13106 				ut_params->op, 1, 1, 0, 0);
13107 	else {
13108 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13109 			ut_params->op);
13110 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
13111 	}
13112 
13113 	return 0;
13114 }
13115 
13116 static int
13117 test_authenticated_encrypt_with_esn(
13118 		struct crypto_testsuite_params *ts_params,
13119 		struct crypto_unittest_params *ut_params,
13120 		const struct test_crypto_vector *reference)
13121 {
13122 	int retval;
13123 
13124 	uint8_t *authciphertext, *plaintext, *auth_tag;
13125 	uint16_t plaintext_pad_len;
13126 	uint8_t cipher_key[reference->cipher_key.len + 1];
13127 	uint8_t auth_key[reference->auth_key.len + 1];
13128 	struct rte_cryptodev_info dev_info;
13129 
13130 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13131 	uint64_t feat_flags = dev_info.feature_flags;
13132 
13133 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13134 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13135 		printf("Device doesn't support RAW data-path APIs.\n");
13136 		return TEST_SKIPPED;
13137 	}
13138 
13139 	/* Verify the capabilities */
13140 	struct rte_cryptodev_sym_capability_idx cap_idx;
13141 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13142 	cap_idx.algo.auth = reference->auth_algo;
13143 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13144 			&cap_idx) == NULL)
13145 		return TEST_SKIPPED;
13146 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13147 	cap_idx.algo.cipher = reference->crypto_algo;
13148 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13149 			&cap_idx) == NULL)
13150 		return TEST_SKIPPED;
13151 
13152 	/* Create session */
13153 	memcpy(cipher_key, reference->cipher_key.data,
13154 			reference->cipher_key.len);
13155 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13156 
13157 	/* Setup Cipher Parameters */
13158 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13159 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13160 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
13161 	ut_params->cipher_xform.cipher.key.data = cipher_key;
13162 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13163 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13164 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13165 
13166 	ut_params->cipher_xform.next = &ut_params->auth_xform;
13167 
13168 	/* Setup Authentication Parameters */
13169 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13170 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
13171 	ut_params->auth_xform.auth.algo = reference->auth_algo;
13172 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13173 	ut_params->auth_xform.auth.key.data = auth_key;
13174 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
13175 	ut_params->auth_xform.next = NULL;
13176 
13177 	/* Create Crypto session*/
13178 	ut_params->sess = rte_cryptodev_sym_session_create(
13179 			ts_params->session_mpool);
13180 
13181 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
13182 				ut_params->sess,
13183 				&ut_params->cipher_xform,
13184 				ts_params->session_priv_mpool);
13185 
13186 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13187 
13188 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13189 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13190 			"Failed to allocate input buffer in mempool");
13191 
13192 	/* clear mbuf payload */
13193 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13194 			rte_pktmbuf_tailroom(ut_params->ibuf));
13195 
13196 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13197 			reference->plaintext.len);
13198 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13199 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13200 
13201 	/* Create operation */
13202 	retval = create_cipher_auth_operation(ts_params,
13203 			ut_params,
13204 			reference, 0);
13205 
13206 	if (retval < 0)
13207 		return retval;
13208 
13209 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13210 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13211 			ut_params->op);
13212 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13213 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13214 				ut_params->op, 1, 1, 0, 0);
13215 	else
13216 		ut_params->op = process_crypto_request(
13217 			ts_params->valid_devs[0], ut_params->op);
13218 
13219 	TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
13220 
13221 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13222 			"crypto op processing failed");
13223 
13224 	plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
13225 
13226 	authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
13227 			ut_params->op->sym->auth.data.offset);
13228 	auth_tag = authciphertext + plaintext_pad_len;
13229 	debug_hexdump(stdout, "ciphertext:", authciphertext,
13230 			reference->ciphertext.len);
13231 	debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
13232 
13233 	/* Validate obuf */
13234 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13235 			authciphertext,
13236 			reference->ciphertext.data,
13237 			reference->ciphertext.len,
13238 			"Ciphertext data not as expected");
13239 
13240 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13241 			auth_tag,
13242 			reference->digest.data,
13243 			reference->digest.len,
13244 			"Generated digest not as expected");
13245 
13246 	return TEST_SUCCESS;
13247 
13248 }
13249 
13250 static int
13251 test_authenticated_decrypt_with_esn(
13252 		struct crypto_testsuite_params *ts_params,
13253 		struct crypto_unittest_params *ut_params,
13254 		const struct test_crypto_vector *reference)
13255 {
13256 	int retval;
13257 
13258 	uint8_t *ciphertext;
13259 	uint8_t cipher_key[reference->cipher_key.len + 1];
13260 	uint8_t auth_key[reference->auth_key.len + 1];
13261 	struct rte_cryptodev_info dev_info;
13262 
13263 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13264 	uint64_t feat_flags = dev_info.feature_flags;
13265 
13266 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13267 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13268 		printf("Device doesn't support RAW data-path APIs.\n");
13269 		return TEST_SKIPPED;
13270 	}
13271 
13272 	/* Verify the capabilities */
13273 	struct rte_cryptodev_sym_capability_idx cap_idx;
13274 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13275 	cap_idx.algo.auth = reference->auth_algo;
13276 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13277 			&cap_idx) == NULL)
13278 		return TEST_SKIPPED;
13279 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13280 	cap_idx.algo.cipher = reference->crypto_algo;
13281 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13282 			&cap_idx) == NULL)
13283 		return TEST_SKIPPED;
13284 
13285 	/* Create session */
13286 	memcpy(cipher_key, reference->cipher_key.data,
13287 			reference->cipher_key.len);
13288 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13289 
13290 	/* Setup Authentication Parameters */
13291 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13292 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
13293 	ut_params->auth_xform.auth.algo = reference->auth_algo;
13294 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13295 	ut_params->auth_xform.auth.key.data = auth_key;
13296 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
13297 	ut_params->auth_xform.next = &ut_params->cipher_xform;
13298 
13299 	/* Setup Cipher Parameters */
13300 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13301 	ut_params->cipher_xform.next = NULL;
13302 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13303 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
13304 	ut_params->cipher_xform.cipher.key.data = cipher_key;
13305 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13306 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13307 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13308 
13309 	/* Create Crypto session*/
13310 	ut_params->sess = rte_cryptodev_sym_session_create(
13311 			ts_params->session_mpool);
13312 
13313 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
13314 				ut_params->sess,
13315 				&ut_params->auth_xform,
13316 				ts_params->session_priv_mpool);
13317 
13318 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13319 
13320 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13321 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13322 			"Failed to allocate input buffer in mempool");
13323 
13324 	/* clear mbuf payload */
13325 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13326 			rte_pktmbuf_tailroom(ut_params->ibuf));
13327 
13328 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13329 			reference->ciphertext.len);
13330 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
13331 	memcpy(ciphertext, reference->ciphertext.data,
13332 			reference->ciphertext.len);
13333 
13334 	/* Create operation */
13335 	retval = create_cipher_auth_verify_operation(ts_params,
13336 			ut_params,
13337 			reference);
13338 
13339 	if (retval < 0)
13340 		return retval;
13341 
13342 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13343 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13344 			ut_params->op);
13345 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13346 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13347 				ut_params->op, 1, 1, 0, 0);
13348 	else
13349 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13350 			ut_params->op);
13351 
13352 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
13353 	TEST_ASSERT_EQUAL(ut_params->op->status,
13354 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13355 			"crypto op processing passed");
13356 
13357 	ut_params->obuf = ut_params->op->sym->m_src;
13358 	TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
13359 
13360 	return 0;
13361 }
13362 
13363 static int
13364 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
13365 		const struct aead_test_data *tdata,
13366 		void *digest_mem, uint64_t digest_phys)
13367 {
13368 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13369 	struct crypto_unittest_params *ut_params = &unittest_params;
13370 
13371 	const unsigned int auth_tag_len = tdata->auth_tag.len;
13372 	const unsigned int iv_len = tdata->iv.len;
13373 	unsigned int aad_len = tdata->aad.len;
13374 	unsigned int aad_len_pad = 0;
13375 
13376 	/* Generate Crypto op data structure */
13377 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
13378 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
13379 	TEST_ASSERT_NOT_NULL(ut_params->op,
13380 		"Failed to allocate symmetric crypto operation struct");
13381 
13382 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
13383 
13384 	sym_op->aead.digest.data = digest_mem;
13385 
13386 	TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
13387 			"no room to append digest");
13388 
13389 	sym_op->aead.digest.phys_addr = digest_phys;
13390 
13391 	if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
13392 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
13393 				auth_tag_len);
13394 		debug_hexdump(stdout, "digest:",
13395 				sym_op->aead.digest.data,
13396 				auth_tag_len);
13397 	}
13398 
13399 	/* Append aad data */
13400 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
13401 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
13402 				uint8_t *, IV_OFFSET);
13403 
13404 		/* Copy IV 1 byte after the IV pointer, according to the API */
13405 		rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
13406 
13407 		aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
13408 
13409 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
13410 				ut_params->ibuf, aad_len);
13411 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
13412 				"no room to prepend aad");
13413 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
13414 				ut_params->ibuf);
13415 
13416 		memset(sym_op->aead.aad.data, 0, aad_len);
13417 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
13418 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
13419 
13420 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
13421 		debug_hexdump(stdout, "aad:",
13422 				sym_op->aead.aad.data, aad_len);
13423 	} else {
13424 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
13425 				uint8_t *, IV_OFFSET);
13426 
13427 		rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
13428 
13429 		aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
13430 
13431 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
13432 				ut_params->ibuf, aad_len_pad);
13433 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
13434 				"no room to prepend aad");
13435 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
13436 				ut_params->ibuf);
13437 
13438 		memset(sym_op->aead.aad.data, 0, aad_len);
13439 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
13440 
13441 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
13442 		debug_hexdump(stdout, "aad:",
13443 				sym_op->aead.aad.data, aad_len);
13444 	}
13445 
13446 	sym_op->aead.data.length = tdata->plaintext.len;
13447 	sym_op->aead.data.offset = aad_len_pad;
13448 
13449 	return 0;
13450 }
13451 
13452 #define SGL_MAX_NO	16
13453 
13454 static int
13455 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
13456 		const int oop, uint32_t fragsz, uint32_t fragsz_oop)
13457 {
13458 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13459 	struct crypto_unittest_params *ut_params = &unittest_params;
13460 	struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
13461 	int retval;
13462 	int to_trn = 0;
13463 	int to_trn_tbl[SGL_MAX_NO];
13464 	int segs = 1;
13465 	unsigned int trn_data = 0;
13466 	uint8_t *plaintext, *ciphertext, *auth_tag;
13467 	struct rte_cryptodev_info dev_info;
13468 
13469 	/* Verify the capabilities */
13470 	struct rte_cryptodev_sym_capability_idx cap_idx;
13471 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
13472 	cap_idx.algo.aead = tdata->algo;
13473 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13474 			&cap_idx) == NULL)
13475 		return TEST_SKIPPED;
13476 
13477 	/* OOP not supported with CPU crypto */
13478 	if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13479 		return TEST_SKIPPED;
13480 
13481 	/* Detailed check for the particular SGL support flag */
13482 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13483 	if (!oop) {
13484 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
13485 		if (sgl_in && (!(dev_info.feature_flags &
13486 				RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
13487 			return TEST_SKIPPED;
13488 
13489 		uint64_t feat_flags = dev_info.feature_flags;
13490 
13491 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13492 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13493 			printf("Device doesn't support RAW data-path APIs.\n");
13494 			return TEST_SKIPPED;
13495 		}
13496 	} else {
13497 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
13498 		unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
13499 				tdata->plaintext.len;
13500 		/* Raw data path API does not support OOP */
13501 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13502 			return TEST_SKIPPED;
13503 		if (sgl_in && !sgl_out) {
13504 			if (!(dev_info.feature_flags &
13505 					RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
13506 				return TEST_SKIPPED;
13507 		} else if (!sgl_in && sgl_out) {
13508 			if (!(dev_info.feature_flags &
13509 					RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
13510 				return TEST_SKIPPED;
13511 		} else if (sgl_in && sgl_out) {
13512 			if (!(dev_info.feature_flags &
13513 					RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
13514 				return TEST_SKIPPED;
13515 		}
13516 	}
13517 
13518 	if (fragsz > tdata->plaintext.len)
13519 		fragsz = tdata->plaintext.len;
13520 
13521 	uint16_t plaintext_len = fragsz;
13522 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
13523 
13524 	if (fragsz_oop > tdata->plaintext.len)
13525 		frag_size_oop = tdata->plaintext.len;
13526 
13527 	int ecx = 0;
13528 	void *digest_mem = NULL;
13529 
13530 	uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
13531 
13532 	if (tdata->plaintext.len % fragsz != 0) {
13533 		if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
13534 			return 1;
13535 	}	else {
13536 		if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
13537 			return 1;
13538 	}
13539 
13540 	/*
13541 	 * For out-op-place we need to alloc another mbuf
13542 	 */
13543 	if (oop) {
13544 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13545 		rte_pktmbuf_append(ut_params->obuf,
13546 				frag_size_oop + prepend_len);
13547 		buf_oop = ut_params->obuf;
13548 	}
13549 
13550 	/* Create AEAD session */
13551 	retval = create_aead_session(ts_params->valid_devs[0],
13552 			tdata->algo,
13553 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
13554 			tdata->key.data, tdata->key.len,
13555 			tdata->aad.len, tdata->auth_tag.len,
13556 			tdata->iv.len);
13557 	if (retval < 0)
13558 		return retval;
13559 
13560 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13561 
13562 	/* clear mbuf payload */
13563 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13564 			rte_pktmbuf_tailroom(ut_params->ibuf));
13565 
13566 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13567 			plaintext_len);
13568 
13569 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
13570 
13571 	trn_data += plaintext_len;
13572 
13573 	buf = ut_params->ibuf;
13574 
13575 	/*
13576 	 * Loop until no more fragments
13577 	 */
13578 
13579 	while (trn_data < tdata->plaintext.len) {
13580 		++segs;
13581 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
13582 				(tdata->plaintext.len - trn_data) : fragsz;
13583 
13584 		to_trn_tbl[ecx++] = to_trn;
13585 
13586 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13587 		buf = buf->next;
13588 
13589 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
13590 				rte_pktmbuf_tailroom(buf));
13591 
13592 		/* OOP */
13593 		if (oop && !fragsz_oop) {
13594 			buf_last_oop = buf_oop->next =
13595 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
13596 			buf_oop = buf_oop->next;
13597 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13598 					0, rte_pktmbuf_tailroom(buf_oop));
13599 			rte_pktmbuf_append(buf_oop, to_trn);
13600 		}
13601 
13602 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
13603 				to_trn);
13604 
13605 		memcpy(plaintext, tdata->plaintext.data + trn_data,
13606 				to_trn);
13607 		trn_data += to_trn;
13608 		if (trn_data  == tdata->plaintext.len) {
13609 			if (oop) {
13610 				if (!fragsz_oop)
13611 					digest_mem = rte_pktmbuf_append(buf_oop,
13612 						tdata->auth_tag.len);
13613 			} else
13614 				digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
13615 					tdata->auth_tag.len);
13616 		}
13617 	}
13618 
13619 	uint64_t digest_phys = 0;
13620 
13621 	ut_params->ibuf->nb_segs = segs;
13622 
13623 	segs = 1;
13624 	if (fragsz_oop && oop) {
13625 		to_trn = 0;
13626 		ecx = 0;
13627 
13628 		if (frag_size_oop == tdata->plaintext.len) {
13629 			digest_mem = rte_pktmbuf_append(ut_params->obuf,
13630 				tdata->auth_tag.len);
13631 
13632 			digest_phys = rte_pktmbuf_iova_offset(
13633 					ut_params->obuf,
13634 					tdata->plaintext.len + prepend_len);
13635 		}
13636 
13637 		trn_data = frag_size_oop;
13638 		while (trn_data < tdata->plaintext.len) {
13639 			++segs;
13640 			to_trn =
13641 				(tdata->plaintext.len - trn_data <
13642 						frag_size_oop) ?
13643 				(tdata->plaintext.len - trn_data) :
13644 						frag_size_oop;
13645 
13646 			to_trn_tbl[ecx++] = to_trn;
13647 
13648 			buf_last_oop = buf_oop->next =
13649 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
13650 			buf_oop = buf_oop->next;
13651 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13652 					0, rte_pktmbuf_tailroom(buf_oop));
13653 			rte_pktmbuf_append(buf_oop, to_trn);
13654 
13655 			trn_data += to_trn;
13656 
13657 			if (trn_data  == tdata->plaintext.len) {
13658 				digest_mem = rte_pktmbuf_append(buf_oop,
13659 					tdata->auth_tag.len);
13660 			}
13661 		}
13662 
13663 		ut_params->obuf->nb_segs = segs;
13664 	}
13665 
13666 	/*
13667 	 * Place digest at the end of the last buffer
13668 	 */
13669 	if (!digest_phys)
13670 		digest_phys = rte_pktmbuf_iova(buf) + to_trn;
13671 	if (oop && buf_last_oop)
13672 		digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
13673 
13674 	if (!digest_mem && !oop) {
13675 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13676 				+ tdata->auth_tag.len);
13677 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
13678 				tdata->plaintext.len);
13679 	}
13680 
13681 	/* Create AEAD operation */
13682 	retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
13683 			tdata, digest_mem, digest_phys);
13684 
13685 	if (retval < 0)
13686 		return retval;
13687 
13688 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13689 
13690 	ut_params->op->sym->m_src = ut_params->ibuf;
13691 	if (oop)
13692 		ut_params->op->sym->m_dst = ut_params->obuf;
13693 
13694 	/* Process crypto operation */
13695 	if (oop == IN_PLACE &&
13696 			gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13697 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
13698 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13699 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13700 				ut_params->op, 0, 0, 0, 0);
13701 	else
13702 		TEST_ASSERT_NOT_NULL(
13703 			process_crypto_request(ts_params->valid_devs[0],
13704 			ut_params->op), "failed to process sym crypto op");
13705 
13706 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13707 			"crypto op processing failed");
13708 
13709 
13710 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
13711 			uint8_t *, prepend_len);
13712 	if (oop) {
13713 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
13714 				uint8_t *, prepend_len);
13715 	}
13716 
13717 	if (fragsz_oop)
13718 		fragsz = fragsz_oop;
13719 
13720 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13721 			ciphertext,
13722 			tdata->ciphertext.data,
13723 			fragsz,
13724 			"Ciphertext data not as expected");
13725 
13726 	buf = ut_params->op->sym->m_src->next;
13727 	if (oop)
13728 		buf = ut_params->op->sym->m_dst->next;
13729 
13730 	unsigned int off = fragsz;
13731 
13732 	ecx = 0;
13733 	while (buf) {
13734 		ciphertext = rte_pktmbuf_mtod(buf,
13735 				uint8_t *);
13736 
13737 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
13738 				ciphertext,
13739 				tdata->ciphertext.data + off,
13740 				to_trn_tbl[ecx],
13741 				"Ciphertext data not as expected");
13742 
13743 		off += to_trn_tbl[ecx++];
13744 		buf = buf->next;
13745 	}
13746 
13747 	auth_tag = digest_mem;
13748 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13749 			auth_tag,
13750 			tdata->auth_tag.data,
13751 			tdata->auth_tag.len,
13752 			"Generated auth tag not as expected");
13753 
13754 	return 0;
13755 }
13756 
13757 static int
13758 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
13759 {
13760 	return test_authenticated_encryption_SGL(
13761 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
13762 }
13763 
13764 static int
13765 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
13766 {
13767 	return test_authenticated_encryption_SGL(
13768 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
13769 }
13770 
13771 static int
13772 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
13773 {
13774 	return test_authenticated_encryption_SGL(
13775 			&gcm_test_case_8, OUT_OF_PLACE, 400,
13776 			gcm_test_case_8.plaintext.len);
13777 }
13778 
13779 static int
13780 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
13781 {
13782 	/* This test is not for OPENSSL PMD */
13783 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
13784 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
13785 		return TEST_SKIPPED;
13786 
13787 	return test_authenticated_encryption_SGL(
13788 			&gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
13789 }
13790 
13791 static int
13792 test_authentication_verify_fail_when_data_corrupted(
13793 		struct crypto_testsuite_params *ts_params,
13794 		struct crypto_unittest_params *ut_params,
13795 		const struct test_crypto_vector *reference)
13796 {
13797 	return test_authentication_verify_fail_when_data_corruption(
13798 			ts_params, ut_params, reference, 1);
13799 }
13800 
13801 static int
13802 test_authentication_verify_fail_when_tag_corrupted(
13803 		struct crypto_testsuite_params *ts_params,
13804 		struct crypto_unittest_params *ut_params,
13805 		const struct test_crypto_vector *reference)
13806 {
13807 	return test_authentication_verify_fail_when_data_corruption(
13808 			ts_params, ut_params, reference, 0);
13809 }
13810 
13811 static int
13812 test_authentication_verify_GMAC_fail_when_data_corrupted(
13813 		struct crypto_testsuite_params *ts_params,
13814 		struct crypto_unittest_params *ut_params,
13815 		const struct test_crypto_vector *reference)
13816 {
13817 	return test_authentication_verify_GMAC_fail_when_corruption(
13818 			ts_params, ut_params, reference, 1);
13819 }
13820 
13821 static int
13822 test_authentication_verify_GMAC_fail_when_tag_corrupted(
13823 		struct crypto_testsuite_params *ts_params,
13824 		struct crypto_unittest_params *ut_params,
13825 		const struct test_crypto_vector *reference)
13826 {
13827 	return test_authentication_verify_GMAC_fail_when_corruption(
13828 			ts_params, ut_params, reference, 0);
13829 }
13830 
13831 static int
13832 test_authenticated_decryption_fail_when_data_corrupted(
13833 		struct crypto_testsuite_params *ts_params,
13834 		struct crypto_unittest_params *ut_params,
13835 		const struct test_crypto_vector *reference)
13836 {
13837 	return test_authenticated_decryption_fail_when_corruption(
13838 			ts_params, ut_params, reference, 1);
13839 }
13840 
13841 static int
13842 test_authenticated_decryption_fail_when_tag_corrupted(
13843 		struct crypto_testsuite_params *ts_params,
13844 		struct crypto_unittest_params *ut_params,
13845 		const struct test_crypto_vector *reference)
13846 {
13847 	return test_authenticated_decryption_fail_when_corruption(
13848 			ts_params, ut_params, reference, 0);
13849 }
13850 
13851 static int
13852 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
13853 {
13854 	return test_authentication_verify_fail_when_data_corrupted(
13855 			&testsuite_params, &unittest_params,
13856 			&hmac_sha1_test_crypto_vector);
13857 }
13858 
13859 static int
13860 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
13861 {
13862 	return test_authentication_verify_fail_when_tag_corrupted(
13863 			&testsuite_params, &unittest_params,
13864 			&hmac_sha1_test_crypto_vector);
13865 }
13866 
13867 static int
13868 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
13869 {
13870 	return test_authentication_verify_GMAC_fail_when_data_corrupted(
13871 			&testsuite_params, &unittest_params,
13872 			&aes128_gmac_test_vector);
13873 }
13874 
13875 static int
13876 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
13877 {
13878 	return test_authentication_verify_GMAC_fail_when_tag_corrupted(
13879 			&testsuite_params, &unittest_params,
13880 			&aes128_gmac_test_vector);
13881 }
13882 
13883 static int
13884 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
13885 {
13886 	return test_authenticated_decryption_fail_when_data_corrupted(
13887 			&testsuite_params,
13888 			&unittest_params,
13889 			&aes128cbc_hmac_sha1_test_vector);
13890 }
13891 
13892 static int
13893 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
13894 {
13895 	return test_authenticated_decryption_fail_when_tag_corrupted(
13896 			&testsuite_params,
13897 			&unittest_params,
13898 			&aes128cbc_hmac_sha1_test_vector);
13899 }
13900 
13901 static int
13902 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13903 {
13904 	return test_authenticated_encrypt_with_esn(
13905 			&testsuite_params,
13906 			&unittest_params,
13907 			&aes128cbc_hmac_sha1_aad_test_vector);
13908 }
13909 
13910 static int
13911 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13912 {
13913 	return test_authenticated_decrypt_with_esn(
13914 			&testsuite_params,
13915 			&unittest_params,
13916 			&aes128cbc_hmac_sha1_aad_test_vector);
13917 }
13918 
13919 static int
13920 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
13921 {
13922 	return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
13923 }
13924 
13925 static int
13926 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
13927 {
13928 	return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
13929 }
13930 
13931 #ifdef RTE_CRYPTO_SCHEDULER
13932 
13933 /* global AESNI worker IDs for the scheduler test */
13934 uint8_t aesni_ids[2];
13935 
13936 static int
13937 scheduler_testsuite_setup(void)
13938 {
13939 	uint32_t i = 0;
13940 	int32_t nb_devs, ret;
13941 	char vdev_args[VDEV_ARGS_SIZE] = {""};
13942 	char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
13943 		"ordering=enable,name=cryptodev_test_scheduler,corelist="};
13944 	uint16_t worker_core_count = 0;
13945 	uint16_t socket_id = 0;
13946 
13947 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
13948 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
13949 
13950 		/* Identify the Worker Cores
13951 		 * Use 2 worker cores for the device args
13952 		 */
13953 		RTE_LCORE_FOREACH_WORKER(i) {
13954 			if (worker_core_count > 1)
13955 				break;
13956 			snprintf(vdev_args, sizeof(vdev_args),
13957 					"%s%d", temp_str, i);
13958 			strcpy(temp_str, vdev_args);
13959 			strlcat(temp_str, ";", sizeof(temp_str));
13960 			worker_core_count++;
13961 			socket_id = rte_lcore_to_socket_id(i);
13962 		}
13963 		if (worker_core_count != 2) {
13964 			RTE_LOG(ERR, USER1,
13965 				"Cryptodev scheduler test require at least "
13966 				"two worker cores to run. "
13967 				"Please use the correct coremask.\n");
13968 			return TEST_FAILED;
13969 		}
13970 		strcpy(temp_str, vdev_args);
13971 		snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
13972 				temp_str, socket_id);
13973 		RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
13974 		nb_devs = rte_cryptodev_device_count_by_driver(
13975 				rte_cryptodev_driver_id_get(
13976 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
13977 		if (nb_devs < 1) {
13978 			ret = rte_vdev_init(
13979 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
13980 					vdev_args);
13981 			TEST_ASSERT(ret == 0,
13982 				"Failed to create instance %u of pmd : %s",
13983 				i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
13984 		}
13985 	}
13986 	return testsuite_setup();
13987 }
13988 
13989 static int
13990 test_scheduler_attach_worker_op(void)
13991 {
13992 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13993 	uint8_t sched_id = ts_params->valid_devs[0];
13994 	uint32_t i, nb_devs_attached = 0;
13995 	int ret;
13996 	char vdev_name[32];
13997 	unsigned int count = rte_cryptodev_count();
13998 
13999 	/* create 2 AESNI_MB vdevs on top of existing devices */
14000 	for (i = count; i < count + 2; i++) {
14001 		snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
14002 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
14003 				i);
14004 		ret = rte_vdev_init(vdev_name, NULL);
14005 
14006 		TEST_ASSERT(ret == 0,
14007 			"Failed to create instance %u of"
14008 			" pmd : %s",
14009 			i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14010 
14011 		if (ret < 0) {
14012 			RTE_LOG(ERR, USER1,
14013 				"Failed to create 2 AESNI MB PMDs.\n");
14014 			return TEST_SKIPPED;
14015 		}
14016 	}
14017 
14018 	/* attach 2 AESNI_MB cdevs */
14019 	for (i = count; i < count + 2; i++) {
14020 		struct rte_cryptodev_info info;
14021 		unsigned int session_size;
14022 
14023 		rte_cryptodev_info_get(i, &info);
14024 		if (info.driver_id != rte_cryptodev_driver_id_get(
14025 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
14026 			continue;
14027 
14028 		session_size = rte_cryptodev_sym_get_private_session_size(i);
14029 		/*
14030 		 * Create the session mempool again, since now there are new devices
14031 		 * to use the mempool.
14032 		 */
14033 		if (ts_params->session_mpool) {
14034 			rte_mempool_free(ts_params->session_mpool);
14035 			ts_params->session_mpool = NULL;
14036 		}
14037 		if (ts_params->session_priv_mpool) {
14038 			rte_mempool_free(ts_params->session_priv_mpool);
14039 			ts_params->session_priv_mpool = NULL;
14040 		}
14041 
14042 		if (info.sym.max_nb_sessions != 0 &&
14043 				info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
14044 			RTE_LOG(ERR, USER1,
14045 					"Device does not support "
14046 					"at least %u sessions\n",
14047 					MAX_NB_SESSIONS);
14048 			return TEST_FAILED;
14049 		}
14050 		/*
14051 		 * Create mempool with maximum number of sessions,
14052 		 * to include the session headers
14053 		 */
14054 		if (ts_params->session_mpool == NULL) {
14055 			ts_params->session_mpool =
14056 				rte_cryptodev_sym_session_pool_create(
14057 						"test_sess_mp",
14058 						MAX_NB_SESSIONS, 0, 0, 0,
14059 						SOCKET_ID_ANY);
14060 			TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
14061 					"session mempool allocation failed");
14062 		}
14063 
14064 		/*
14065 		 * Create mempool with maximum number of sessions,
14066 		 * to include device specific session private data
14067 		 */
14068 		if (ts_params->session_priv_mpool == NULL) {
14069 			ts_params->session_priv_mpool = rte_mempool_create(
14070 					"test_sess_mp_priv",
14071 					MAX_NB_SESSIONS,
14072 					session_size,
14073 					0, 0, NULL, NULL, NULL,
14074 					NULL, SOCKET_ID_ANY,
14075 					0);
14076 
14077 			TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
14078 					"session mempool allocation failed");
14079 		}
14080 
14081 		ts_params->qp_conf.mp_session = ts_params->session_mpool;
14082 		ts_params->qp_conf.mp_session_private =
14083 				ts_params->session_priv_mpool;
14084 
14085 		ret = rte_cryptodev_scheduler_worker_attach(sched_id,
14086 				(uint8_t)i);
14087 
14088 		TEST_ASSERT(ret == 0,
14089 			"Failed to attach device %u of pmd : %s", i,
14090 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14091 
14092 		aesni_ids[nb_devs_attached] = (uint8_t)i;
14093 
14094 		nb_devs_attached++;
14095 	}
14096 
14097 	return 0;
14098 }
14099 
14100 static int
14101 test_scheduler_detach_worker_op(void)
14102 {
14103 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14104 	uint8_t sched_id = ts_params->valid_devs[0];
14105 	uint32_t i;
14106 	int ret;
14107 
14108 	for (i = 0; i < 2; i++) {
14109 		ret = rte_cryptodev_scheduler_worker_detach(sched_id,
14110 				aesni_ids[i]);
14111 		TEST_ASSERT(ret == 0,
14112 			"Failed to detach device %u", aesni_ids[i]);
14113 	}
14114 
14115 	return 0;
14116 }
14117 
14118 static int
14119 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
14120 {
14121 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14122 	uint8_t sched_id = ts_params->valid_devs[0];
14123 	/* set mode */
14124 	return rte_cryptodev_scheduler_mode_set(sched_id,
14125 		scheduler_mode);
14126 }
14127 
14128 static int
14129 test_scheduler_mode_roundrobin_op(void)
14130 {
14131 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
14132 			0, "Failed to set roundrobin mode");
14133 	return 0;
14134 
14135 }
14136 
14137 static int
14138 test_scheduler_mode_multicore_op(void)
14139 {
14140 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
14141 			0, "Failed to set multicore mode");
14142 
14143 	return 0;
14144 }
14145 
14146 static int
14147 test_scheduler_mode_failover_op(void)
14148 {
14149 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
14150 			0, "Failed to set failover mode");
14151 
14152 	return 0;
14153 }
14154 
14155 static int
14156 test_scheduler_mode_pkt_size_distr_op(void)
14157 {
14158 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
14159 			0, "Failed to set pktsize mode");
14160 
14161 	return 0;
14162 }
14163 
14164 static int
14165 scheduler_multicore_testsuite_setup(void)
14166 {
14167 	if (test_scheduler_attach_worker_op() < 0)
14168 		return TEST_SKIPPED;
14169 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0)
14170 		return TEST_SKIPPED;
14171 	return 0;
14172 }
14173 
14174 static int
14175 scheduler_roundrobin_testsuite_setup(void)
14176 {
14177 	if (test_scheduler_attach_worker_op() < 0)
14178 		return TEST_SKIPPED;
14179 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0)
14180 		return TEST_SKIPPED;
14181 	return 0;
14182 }
14183 
14184 static int
14185 scheduler_failover_testsuite_setup(void)
14186 {
14187 	if (test_scheduler_attach_worker_op() < 0)
14188 		return TEST_SKIPPED;
14189 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0)
14190 		return TEST_SKIPPED;
14191 	return 0;
14192 }
14193 
14194 static int
14195 scheduler_pkt_size_distr_testsuite_setup(void)
14196 {
14197 	if (test_scheduler_attach_worker_op() < 0)
14198 		return TEST_SKIPPED;
14199 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0)
14200 		return TEST_SKIPPED;
14201 	return 0;
14202 }
14203 
14204 static void
14205 scheduler_mode_testsuite_teardown(void)
14206 {
14207 	test_scheduler_detach_worker_op();
14208 }
14209 
14210 #endif /* RTE_CRYPTO_SCHEDULER */
14211 
14212 static struct unit_test_suite end_testsuite = {
14213 	.suite_name = NULL,
14214 	.setup = NULL,
14215 	.teardown = NULL,
14216 	.unit_test_suites = NULL
14217 };
14218 
14219 #ifdef RTE_LIB_SECURITY
14220 static struct unit_test_suite ipsec_proto_testsuite  = {
14221 	.suite_name = "IPsec Proto Unit Test Suite",
14222 	.setup = ipsec_proto_testsuite_setup,
14223 	.unit_test_cases = {
14224 		TEST_CASE_NAMED_WITH_DATA(
14225 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
14226 			ut_setup_security, ut_teardown,
14227 			test_ipsec_proto_known_vec, &pkt_aes_128_gcm),
14228 		TEST_CASE_NAMED_WITH_DATA(
14229 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
14230 			ut_setup_security, ut_teardown,
14231 			test_ipsec_proto_known_vec, &pkt_aes_192_gcm),
14232 		TEST_CASE_NAMED_WITH_DATA(
14233 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
14234 			ut_setup_security, ut_teardown,
14235 			test_ipsec_proto_known_vec, &pkt_aes_256_gcm),
14236 		TEST_CASE_NAMED_WITH_DATA(
14237 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
14238 			ut_setup_security, ut_teardown,
14239 			test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm),
14240 		TEST_CASE_NAMED_WITH_DATA(
14241 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
14242 			ut_setup_security, ut_teardown,
14243 			test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm),
14244 		TEST_CASE_NAMED_WITH_DATA(
14245 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
14246 			ut_setup_security, ut_teardown,
14247 			test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm),
14248 		TEST_CASE_NAMED_ST(
14249 			"Combined test alg list",
14250 			ut_setup_security, ut_teardown,
14251 			test_ipsec_proto_display_list),
14252 		TEST_CASE_NAMED_ST(
14253 			"IV generation",
14254 			ut_setup_security, ut_teardown,
14255 			test_ipsec_proto_iv_gen),
14256 		TEST_CASE_NAMED_ST(
14257 			"UDP encapsulation",
14258 			ut_setup_security, ut_teardown,
14259 			test_ipsec_proto_udp_encap),
14260 		TEST_CASE_NAMED_ST(
14261 			"UDP encapsulation ports verification test",
14262 			ut_setup_security, ut_teardown,
14263 			test_ipsec_proto_udp_ports_verify),
14264 		TEST_CASE_NAMED_ST(
14265 			"SA expiry packets soft",
14266 			ut_setup_security, ut_teardown,
14267 			test_ipsec_proto_sa_exp_pkts_soft),
14268 		TEST_CASE_NAMED_ST(
14269 			"SA expiry packets hard",
14270 			ut_setup_security, ut_teardown,
14271 			test_ipsec_proto_sa_exp_pkts_hard),
14272 		TEST_CASE_NAMED_ST(
14273 			"Negative test: ICV corruption",
14274 			ut_setup_security, ut_teardown,
14275 			test_ipsec_proto_err_icv_corrupt),
14276 		TEST_CASE_NAMED_ST(
14277 			"Tunnel dst addr verification",
14278 			ut_setup_security, ut_teardown,
14279 			test_ipsec_proto_tunnel_dst_addr_verify),
14280 		TEST_CASE_NAMED_ST(
14281 			"Tunnel src and dst addr verification",
14282 			ut_setup_security, ut_teardown,
14283 			test_ipsec_proto_tunnel_src_dst_addr_verify),
14284 		TEST_CASE_NAMED_ST(
14285 			"Inner IP checksum",
14286 			ut_setup_security, ut_teardown,
14287 			test_ipsec_proto_inner_ip_csum),
14288 		TEST_CASE_NAMED_ST(
14289 			"Inner L4 checksum",
14290 			ut_setup_security, ut_teardown,
14291 			test_ipsec_proto_inner_l4_csum),
14292 		TEST_CASES_END() /**< NULL terminate unit test array */
14293 	}
14294 };
14295 
14296 static struct unit_test_suite pdcp_proto_testsuite  = {
14297 	.suite_name = "PDCP Proto Unit Test Suite",
14298 	.setup = pdcp_proto_testsuite_setup,
14299 	.unit_test_cases = {
14300 		TEST_CASE_ST(ut_setup_security, ut_teardown,
14301 			test_PDCP_PROTO_all),
14302 		TEST_CASES_END() /**< NULL terminate unit test array */
14303 	}
14304 };
14305 
14306 static struct unit_test_suite docsis_proto_testsuite  = {
14307 	.suite_name = "Docsis Proto Unit Test Suite",
14308 	.setup = docsis_proto_testsuite_setup,
14309 	.unit_test_cases = {
14310 		TEST_CASE_ST(ut_setup_security, ut_teardown,
14311 			test_DOCSIS_PROTO_all),
14312 		TEST_CASES_END() /**< NULL terminate unit test array */
14313 	}
14314 };
14315 #endif
14316 
14317 static struct unit_test_suite cryptodev_gen_testsuite  = {
14318 	.suite_name = "Crypto General Unit Test Suite",
14319 	.setup = crypto_gen_testsuite_setup,
14320 	.unit_test_cases = {
14321 		TEST_CASE_ST(ut_setup, ut_teardown,
14322 				test_device_configure_invalid_dev_id),
14323 		TEST_CASE_ST(ut_setup, ut_teardown,
14324 				test_queue_pair_descriptor_setup),
14325 		TEST_CASE_ST(ut_setup, ut_teardown,
14326 				test_device_configure_invalid_queue_pair_ids),
14327 		TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
14328 		TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup),
14329 		TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup),
14330 		TEST_CASES_END() /**< NULL terminate unit test array */
14331 	}
14332 };
14333 
14334 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = {
14335 	.suite_name = "Negative HMAC SHA1 Unit Test Suite",
14336 	.setup = negative_hmac_sha1_testsuite_setup,
14337 	.unit_test_cases = {
14338 		/** Negative tests */
14339 		TEST_CASE_ST(ut_setup, ut_teardown,
14340 			authentication_verify_HMAC_SHA1_fail_data_corrupt),
14341 		TEST_CASE_ST(ut_setup, ut_teardown,
14342 			authentication_verify_HMAC_SHA1_fail_tag_corrupt),
14343 		TEST_CASE_ST(ut_setup, ut_teardown,
14344 			auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
14345 		TEST_CASE_ST(ut_setup, ut_teardown,
14346 			auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
14347 
14348 		TEST_CASES_END() /**< NULL terminate unit test array */
14349 	}
14350 };
14351 
14352 static struct unit_test_suite cryptodev_multi_session_testsuite = {
14353 	.suite_name = "Multi Session Unit Test Suite",
14354 	.setup = multi_session_testsuite_setup,
14355 	.unit_test_cases = {
14356 		TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
14357 		TEST_CASE_ST(ut_setup, ut_teardown,
14358 				test_multi_session_random_usage),
14359 
14360 		TEST_CASES_END() /**< NULL terminate unit test array */
14361 	}
14362 };
14363 
14364 static struct unit_test_suite cryptodev_null_testsuite  = {
14365 	.suite_name = "NULL Test Suite",
14366 	.setup = null_testsuite_setup,
14367 	.unit_test_cases = {
14368 		TEST_CASE_ST(ut_setup, ut_teardown,
14369 			test_null_invalid_operation),
14370 		TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
14371 		TEST_CASES_END()
14372 	}
14373 };
14374 
14375 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite  = {
14376 	.suite_name = "AES CCM Authenticated Test Suite",
14377 	.setup = aes_ccm_auth_testsuite_setup,
14378 	.unit_test_cases = {
14379 		/** AES CCM Authenticated Encryption 128 bits key*/
14380 		TEST_CASE_ST(ut_setup, ut_teardown,
14381 			test_AES_CCM_authenticated_encryption_test_case_128_1),
14382 		TEST_CASE_ST(ut_setup, ut_teardown,
14383 			test_AES_CCM_authenticated_encryption_test_case_128_2),
14384 		TEST_CASE_ST(ut_setup, ut_teardown,
14385 			test_AES_CCM_authenticated_encryption_test_case_128_3),
14386 
14387 		/** AES CCM Authenticated Decryption 128 bits key*/
14388 		TEST_CASE_ST(ut_setup, ut_teardown,
14389 			test_AES_CCM_authenticated_decryption_test_case_128_1),
14390 		TEST_CASE_ST(ut_setup, ut_teardown,
14391 			test_AES_CCM_authenticated_decryption_test_case_128_2),
14392 		TEST_CASE_ST(ut_setup, ut_teardown,
14393 			test_AES_CCM_authenticated_decryption_test_case_128_3),
14394 
14395 		/** AES CCM Authenticated Encryption 192 bits key */
14396 		TEST_CASE_ST(ut_setup, ut_teardown,
14397 			test_AES_CCM_authenticated_encryption_test_case_192_1),
14398 		TEST_CASE_ST(ut_setup, ut_teardown,
14399 			test_AES_CCM_authenticated_encryption_test_case_192_2),
14400 		TEST_CASE_ST(ut_setup, ut_teardown,
14401 			test_AES_CCM_authenticated_encryption_test_case_192_3),
14402 
14403 		/** AES CCM Authenticated Decryption 192 bits key*/
14404 		TEST_CASE_ST(ut_setup, ut_teardown,
14405 			test_AES_CCM_authenticated_decryption_test_case_192_1),
14406 		TEST_CASE_ST(ut_setup, ut_teardown,
14407 			test_AES_CCM_authenticated_decryption_test_case_192_2),
14408 		TEST_CASE_ST(ut_setup, ut_teardown,
14409 			test_AES_CCM_authenticated_decryption_test_case_192_3),
14410 
14411 		/** AES CCM Authenticated Encryption 256 bits key */
14412 		TEST_CASE_ST(ut_setup, ut_teardown,
14413 			test_AES_CCM_authenticated_encryption_test_case_256_1),
14414 		TEST_CASE_ST(ut_setup, ut_teardown,
14415 			test_AES_CCM_authenticated_encryption_test_case_256_2),
14416 		TEST_CASE_ST(ut_setup, ut_teardown,
14417 			test_AES_CCM_authenticated_encryption_test_case_256_3),
14418 
14419 		/** AES CCM Authenticated Decryption 256 bits key*/
14420 		TEST_CASE_ST(ut_setup, ut_teardown,
14421 			test_AES_CCM_authenticated_decryption_test_case_256_1),
14422 		TEST_CASE_ST(ut_setup, ut_teardown,
14423 			test_AES_CCM_authenticated_decryption_test_case_256_2),
14424 		TEST_CASE_ST(ut_setup, ut_teardown,
14425 			test_AES_CCM_authenticated_decryption_test_case_256_3),
14426 		TEST_CASES_END()
14427 	}
14428 };
14429 
14430 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite  = {
14431 	.suite_name = "AES GCM Authenticated Test Suite",
14432 	.setup = aes_gcm_auth_testsuite_setup,
14433 	.unit_test_cases = {
14434 		/** AES GCM Authenticated Encryption */
14435 		TEST_CASE_ST(ut_setup, ut_teardown,
14436 			test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
14437 		TEST_CASE_ST(ut_setup, ut_teardown,
14438 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
14439 		TEST_CASE_ST(ut_setup, ut_teardown,
14440 			test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
14441 		TEST_CASE_ST(ut_setup, ut_teardown,
14442 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
14443 		TEST_CASE_ST(ut_setup, ut_teardown,
14444 			test_AES_GCM_authenticated_encryption_test_case_1),
14445 		TEST_CASE_ST(ut_setup, ut_teardown,
14446 			test_AES_GCM_authenticated_encryption_test_case_2),
14447 		TEST_CASE_ST(ut_setup, ut_teardown,
14448 			test_AES_GCM_authenticated_encryption_test_case_3),
14449 		TEST_CASE_ST(ut_setup, ut_teardown,
14450 			test_AES_GCM_authenticated_encryption_test_case_4),
14451 		TEST_CASE_ST(ut_setup, ut_teardown,
14452 			test_AES_GCM_authenticated_encryption_test_case_5),
14453 		TEST_CASE_ST(ut_setup, ut_teardown,
14454 			test_AES_GCM_authenticated_encryption_test_case_6),
14455 		TEST_CASE_ST(ut_setup, ut_teardown,
14456 			test_AES_GCM_authenticated_encryption_test_case_7),
14457 		TEST_CASE_ST(ut_setup, ut_teardown,
14458 			test_AES_GCM_authenticated_encryption_test_case_8),
14459 		TEST_CASE_ST(ut_setup, ut_teardown,
14460 			test_AES_GCM_J0_authenticated_encryption_test_case_1),
14461 
14462 		/** AES GCM Authenticated Decryption */
14463 		TEST_CASE_ST(ut_setup, ut_teardown,
14464 			test_AES_GCM_authenticated_decryption_test_case_1),
14465 		TEST_CASE_ST(ut_setup, ut_teardown,
14466 			test_AES_GCM_authenticated_decryption_test_case_2),
14467 		TEST_CASE_ST(ut_setup, ut_teardown,
14468 			test_AES_GCM_authenticated_decryption_test_case_3),
14469 		TEST_CASE_ST(ut_setup, ut_teardown,
14470 			test_AES_GCM_authenticated_decryption_test_case_4),
14471 		TEST_CASE_ST(ut_setup, ut_teardown,
14472 			test_AES_GCM_authenticated_decryption_test_case_5),
14473 		TEST_CASE_ST(ut_setup, ut_teardown,
14474 			test_AES_GCM_authenticated_decryption_test_case_6),
14475 		TEST_CASE_ST(ut_setup, ut_teardown,
14476 			test_AES_GCM_authenticated_decryption_test_case_7),
14477 		TEST_CASE_ST(ut_setup, ut_teardown,
14478 			test_AES_GCM_authenticated_decryption_test_case_8),
14479 		TEST_CASE_ST(ut_setup, ut_teardown,
14480 			test_AES_GCM_J0_authenticated_decryption_test_case_1),
14481 
14482 		/** AES GCM Authenticated Encryption 192 bits key */
14483 		TEST_CASE_ST(ut_setup, ut_teardown,
14484 			test_AES_GCM_auth_encryption_test_case_192_1),
14485 		TEST_CASE_ST(ut_setup, ut_teardown,
14486 			test_AES_GCM_auth_encryption_test_case_192_2),
14487 		TEST_CASE_ST(ut_setup, ut_teardown,
14488 			test_AES_GCM_auth_encryption_test_case_192_3),
14489 		TEST_CASE_ST(ut_setup, ut_teardown,
14490 			test_AES_GCM_auth_encryption_test_case_192_4),
14491 		TEST_CASE_ST(ut_setup, ut_teardown,
14492 			test_AES_GCM_auth_encryption_test_case_192_5),
14493 		TEST_CASE_ST(ut_setup, ut_teardown,
14494 			test_AES_GCM_auth_encryption_test_case_192_6),
14495 		TEST_CASE_ST(ut_setup, ut_teardown,
14496 			test_AES_GCM_auth_encryption_test_case_192_7),
14497 
14498 		/** AES GCM Authenticated Decryption 192 bits key */
14499 		TEST_CASE_ST(ut_setup, ut_teardown,
14500 			test_AES_GCM_auth_decryption_test_case_192_1),
14501 		TEST_CASE_ST(ut_setup, ut_teardown,
14502 			test_AES_GCM_auth_decryption_test_case_192_2),
14503 		TEST_CASE_ST(ut_setup, ut_teardown,
14504 			test_AES_GCM_auth_decryption_test_case_192_3),
14505 		TEST_CASE_ST(ut_setup, ut_teardown,
14506 			test_AES_GCM_auth_decryption_test_case_192_4),
14507 		TEST_CASE_ST(ut_setup, ut_teardown,
14508 			test_AES_GCM_auth_decryption_test_case_192_5),
14509 		TEST_CASE_ST(ut_setup, ut_teardown,
14510 			test_AES_GCM_auth_decryption_test_case_192_6),
14511 		TEST_CASE_ST(ut_setup, ut_teardown,
14512 			test_AES_GCM_auth_decryption_test_case_192_7),
14513 
14514 		/** AES GCM Authenticated Encryption 256 bits key */
14515 		TEST_CASE_ST(ut_setup, ut_teardown,
14516 			test_AES_GCM_auth_encryption_test_case_256_1),
14517 		TEST_CASE_ST(ut_setup, ut_teardown,
14518 			test_AES_GCM_auth_encryption_test_case_256_2),
14519 		TEST_CASE_ST(ut_setup, ut_teardown,
14520 			test_AES_GCM_auth_encryption_test_case_256_3),
14521 		TEST_CASE_ST(ut_setup, ut_teardown,
14522 			test_AES_GCM_auth_encryption_test_case_256_4),
14523 		TEST_CASE_ST(ut_setup, ut_teardown,
14524 			test_AES_GCM_auth_encryption_test_case_256_5),
14525 		TEST_CASE_ST(ut_setup, ut_teardown,
14526 			test_AES_GCM_auth_encryption_test_case_256_6),
14527 		TEST_CASE_ST(ut_setup, ut_teardown,
14528 			test_AES_GCM_auth_encryption_test_case_256_7),
14529 
14530 		/** AES GCM Authenticated Decryption 256 bits key */
14531 		TEST_CASE_ST(ut_setup, ut_teardown,
14532 			test_AES_GCM_auth_decryption_test_case_256_1),
14533 		TEST_CASE_ST(ut_setup, ut_teardown,
14534 			test_AES_GCM_auth_decryption_test_case_256_2),
14535 		TEST_CASE_ST(ut_setup, ut_teardown,
14536 			test_AES_GCM_auth_decryption_test_case_256_3),
14537 		TEST_CASE_ST(ut_setup, ut_teardown,
14538 			test_AES_GCM_auth_decryption_test_case_256_4),
14539 		TEST_CASE_ST(ut_setup, ut_teardown,
14540 			test_AES_GCM_auth_decryption_test_case_256_5),
14541 		TEST_CASE_ST(ut_setup, ut_teardown,
14542 			test_AES_GCM_auth_decryption_test_case_256_6),
14543 		TEST_CASE_ST(ut_setup, ut_teardown,
14544 			test_AES_GCM_auth_decryption_test_case_256_7),
14545 
14546 		/** AES GCM Authenticated Encryption big aad size */
14547 		TEST_CASE_ST(ut_setup, ut_teardown,
14548 			test_AES_GCM_auth_encryption_test_case_aad_1),
14549 		TEST_CASE_ST(ut_setup, ut_teardown,
14550 			test_AES_GCM_auth_encryption_test_case_aad_2),
14551 
14552 		/** AES GCM Authenticated Decryption big aad size */
14553 		TEST_CASE_ST(ut_setup, ut_teardown,
14554 			test_AES_GCM_auth_decryption_test_case_aad_1),
14555 		TEST_CASE_ST(ut_setup, ut_teardown,
14556 			test_AES_GCM_auth_decryption_test_case_aad_2),
14557 
14558 		/** Out of place tests */
14559 		TEST_CASE_ST(ut_setup, ut_teardown,
14560 			test_AES_GCM_authenticated_encryption_oop_test_case_1),
14561 		TEST_CASE_ST(ut_setup, ut_teardown,
14562 			test_AES_GCM_authenticated_decryption_oop_test_case_1),
14563 
14564 		/** Session-less tests */
14565 		TEST_CASE_ST(ut_setup, ut_teardown,
14566 			test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
14567 		TEST_CASE_ST(ut_setup, ut_teardown,
14568 			test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
14569 
14570 		TEST_CASES_END()
14571 	}
14572 };
14573 
14574 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite  = {
14575 	.suite_name = "AES GMAC Authentication Test Suite",
14576 	.setup = aes_gmac_auth_testsuite_setup,
14577 	.unit_test_cases = {
14578 		TEST_CASE_ST(ut_setup, ut_teardown,
14579 			test_AES_GMAC_authentication_test_case_1),
14580 		TEST_CASE_ST(ut_setup, ut_teardown,
14581 			test_AES_GMAC_authentication_verify_test_case_1),
14582 		TEST_CASE_ST(ut_setup, ut_teardown,
14583 			test_AES_GMAC_authentication_test_case_2),
14584 		TEST_CASE_ST(ut_setup, ut_teardown,
14585 			test_AES_GMAC_authentication_verify_test_case_2),
14586 		TEST_CASE_ST(ut_setup, ut_teardown,
14587 			test_AES_GMAC_authentication_test_case_3),
14588 		TEST_CASE_ST(ut_setup, ut_teardown,
14589 			test_AES_GMAC_authentication_verify_test_case_3),
14590 		TEST_CASE_ST(ut_setup, ut_teardown,
14591 			test_AES_GMAC_authentication_test_case_4),
14592 		TEST_CASE_ST(ut_setup, ut_teardown,
14593 			test_AES_GMAC_authentication_verify_test_case_4),
14594 		TEST_CASE_ST(ut_setup, ut_teardown,
14595 			test_AES_GMAC_authentication_SGL_40B),
14596 		TEST_CASE_ST(ut_setup, ut_teardown,
14597 			test_AES_GMAC_authentication_SGL_80B),
14598 		TEST_CASE_ST(ut_setup, ut_teardown,
14599 			test_AES_GMAC_authentication_SGL_2048B),
14600 		TEST_CASE_ST(ut_setup, ut_teardown,
14601 			test_AES_GMAC_authentication_SGL_2047B),
14602 
14603 		TEST_CASES_END()
14604 	}
14605 };
14606 
14607 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite  = {
14608 	.suite_name = "Chacha20-Poly1305 Test Suite",
14609 	.setup = chacha20_poly1305_testsuite_setup,
14610 	.unit_test_cases = {
14611 		TEST_CASE_ST(ut_setup, ut_teardown,
14612 			test_chacha20_poly1305_encrypt_test_case_rfc8439),
14613 		TEST_CASE_ST(ut_setup, ut_teardown,
14614 			test_chacha20_poly1305_decrypt_test_case_rfc8439),
14615 		TEST_CASES_END()
14616 	}
14617 };
14618 
14619 static struct unit_test_suite cryptodev_snow3g_testsuite  = {
14620 	.suite_name = "SNOW 3G Test Suite",
14621 	.setup = snow3g_testsuite_setup,
14622 	.unit_test_cases = {
14623 		/** SNOW 3G encrypt only (UEA2) */
14624 		TEST_CASE_ST(ut_setup, ut_teardown,
14625 			test_snow3g_encryption_test_case_1),
14626 		TEST_CASE_ST(ut_setup, ut_teardown,
14627 			test_snow3g_encryption_test_case_2),
14628 		TEST_CASE_ST(ut_setup, ut_teardown,
14629 			test_snow3g_encryption_test_case_3),
14630 		TEST_CASE_ST(ut_setup, ut_teardown,
14631 			test_snow3g_encryption_test_case_4),
14632 		TEST_CASE_ST(ut_setup, ut_teardown,
14633 			test_snow3g_encryption_test_case_5),
14634 
14635 		TEST_CASE_ST(ut_setup, ut_teardown,
14636 			test_snow3g_encryption_test_case_1_oop),
14637 		TEST_CASE_ST(ut_setup, ut_teardown,
14638 			test_snow3g_encryption_test_case_1_oop_sgl),
14639 		TEST_CASE_ST(ut_setup, ut_teardown,
14640 			test_snow3g_encryption_test_case_1_offset_oop),
14641 		TEST_CASE_ST(ut_setup, ut_teardown,
14642 			test_snow3g_decryption_test_case_1_oop),
14643 
14644 		/** SNOW 3G generate auth, then encrypt (UEA2) */
14645 		TEST_CASE_ST(ut_setup, ut_teardown,
14646 			test_snow3g_auth_cipher_test_case_1),
14647 		TEST_CASE_ST(ut_setup, ut_teardown,
14648 			test_snow3g_auth_cipher_test_case_2),
14649 		TEST_CASE_ST(ut_setup, ut_teardown,
14650 			test_snow3g_auth_cipher_test_case_2_oop),
14651 		TEST_CASE_ST(ut_setup, ut_teardown,
14652 			test_snow3g_auth_cipher_part_digest_enc),
14653 		TEST_CASE_ST(ut_setup, ut_teardown,
14654 			test_snow3g_auth_cipher_part_digest_enc_oop),
14655 		TEST_CASE_ST(ut_setup, ut_teardown,
14656 			test_snow3g_auth_cipher_test_case_3_sgl),
14657 		TEST_CASE_ST(ut_setup, ut_teardown,
14658 			test_snow3g_auth_cipher_test_case_3_oop_sgl),
14659 		TEST_CASE_ST(ut_setup, ut_teardown,
14660 			test_snow3g_auth_cipher_part_digest_enc_sgl),
14661 		TEST_CASE_ST(ut_setup, ut_teardown,
14662 			test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
14663 
14664 		/** SNOW 3G decrypt (UEA2), then verify auth */
14665 		TEST_CASE_ST(ut_setup, ut_teardown,
14666 			test_snow3g_auth_cipher_verify_test_case_1),
14667 		TEST_CASE_ST(ut_setup, ut_teardown,
14668 			test_snow3g_auth_cipher_verify_test_case_2),
14669 		TEST_CASE_ST(ut_setup, ut_teardown,
14670 			test_snow3g_auth_cipher_verify_test_case_2_oop),
14671 		TEST_CASE_ST(ut_setup, ut_teardown,
14672 			test_snow3g_auth_cipher_verify_part_digest_enc),
14673 		TEST_CASE_ST(ut_setup, ut_teardown,
14674 			test_snow3g_auth_cipher_verify_part_digest_enc_oop),
14675 		TEST_CASE_ST(ut_setup, ut_teardown,
14676 			test_snow3g_auth_cipher_verify_test_case_3_sgl),
14677 		TEST_CASE_ST(ut_setup, ut_teardown,
14678 			test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
14679 		TEST_CASE_ST(ut_setup, ut_teardown,
14680 			test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
14681 		TEST_CASE_ST(ut_setup, ut_teardown,
14682 			test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
14683 
14684 		/** SNOW 3G decrypt only (UEA2) */
14685 		TEST_CASE_ST(ut_setup, ut_teardown,
14686 			test_snow3g_decryption_test_case_1),
14687 		TEST_CASE_ST(ut_setup, ut_teardown,
14688 			test_snow3g_decryption_test_case_2),
14689 		TEST_CASE_ST(ut_setup, ut_teardown,
14690 			test_snow3g_decryption_test_case_3),
14691 		TEST_CASE_ST(ut_setup, ut_teardown,
14692 			test_snow3g_decryption_test_case_4),
14693 		TEST_CASE_ST(ut_setup, ut_teardown,
14694 			test_snow3g_decryption_test_case_5),
14695 		TEST_CASE_ST(ut_setup, ut_teardown,
14696 			test_snow3g_decryption_with_digest_test_case_1),
14697 		TEST_CASE_ST(ut_setup, ut_teardown,
14698 			test_snow3g_hash_generate_test_case_1),
14699 		TEST_CASE_ST(ut_setup, ut_teardown,
14700 			test_snow3g_hash_generate_test_case_2),
14701 		TEST_CASE_ST(ut_setup, ut_teardown,
14702 			test_snow3g_hash_generate_test_case_3),
14703 
14704 		/* Tests with buffers which length is not byte-aligned */
14705 		TEST_CASE_ST(ut_setup, ut_teardown,
14706 			test_snow3g_hash_generate_test_case_4),
14707 		TEST_CASE_ST(ut_setup, ut_teardown,
14708 			test_snow3g_hash_generate_test_case_5),
14709 		TEST_CASE_ST(ut_setup, ut_teardown,
14710 			test_snow3g_hash_generate_test_case_6),
14711 		TEST_CASE_ST(ut_setup, ut_teardown,
14712 			test_snow3g_hash_verify_test_case_1),
14713 		TEST_CASE_ST(ut_setup, ut_teardown,
14714 			test_snow3g_hash_verify_test_case_2),
14715 		TEST_CASE_ST(ut_setup, ut_teardown,
14716 			test_snow3g_hash_verify_test_case_3),
14717 
14718 		/* Tests with buffers which length is not byte-aligned */
14719 		TEST_CASE_ST(ut_setup, ut_teardown,
14720 			test_snow3g_hash_verify_test_case_4),
14721 		TEST_CASE_ST(ut_setup, ut_teardown,
14722 			test_snow3g_hash_verify_test_case_5),
14723 		TEST_CASE_ST(ut_setup, ut_teardown,
14724 			test_snow3g_hash_verify_test_case_6),
14725 		TEST_CASE_ST(ut_setup, ut_teardown,
14726 			test_snow3g_cipher_auth_test_case_1),
14727 		TEST_CASE_ST(ut_setup, ut_teardown,
14728 			test_snow3g_auth_cipher_with_digest_test_case_1),
14729 		TEST_CASES_END()
14730 	}
14731 };
14732 
14733 static struct unit_test_suite cryptodev_zuc_testsuite  = {
14734 	.suite_name = "ZUC Test Suite",
14735 	.setup = zuc_testsuite_setup,
14736 	.unit_test_cases = {
14737 		/** ZUC encrypt only (EEA3) */
14738 		TEST_CASE_ST(ut_setup, ut_teardown,
14739 			test_zuc_encryption_test_case_1),
14740 		TEST_CASE_ST(ut_setup, ut_teardown,
14741 			test_zuc_encryption_test_case_2),
14742 		TEST_CASE_ST(ut_setup, ut_teardown,
14743 			test_zuc_encryption_test_case_3),
14744 		TEST_CASE_ST(ut_setup, ut_teardown,
14745 			test_zuc_encryption_test_case_4),
14746 		TEST_CASE_ST(ut_setup, ut_teardown,
14747 			test_zuc_encryption_test_case_5),
14748 		TEST_CASE_ST(ut_setup, ut_teardown,
14749 			test_zuc_encryption_test_case_6_sgl),
14750 		TEST_CASE_ST(ut_setup, ut_teardown,
14751 			test_zuc_encryption_test_case_7),
14752 
14753 		/** ZUC authenticate (EIA3) */
14754 		TEST_CASE_ST(ut_setup, ut_teardown,
14755 			test_zuc_hash_generate_test_case_1),
14756 		TEST_CASE_ST(ut_setup, ut_teardown,
14757 			test_zuc_hash_generate_test_case_2),
14758 		TEST_CASE_ST(ut_setup, ut_teardown,
14759 			test_zuc_hash_generate_test_case_3),
14760 		TEST_CASE_ST(ut_setup, ut_teardown,
14761 			test_zuc_hash_generate_test_case_4),
14762 		TEST_CASE_ST(ut_setup, ut_teardown,
14763 			test_zuc_hash_generate_test_case_5),
14764 		TEST_CASE_ST(ut_setup, ut_teardown,
14765 			test_zuc_hash_generate_test_case_6),
14766 		TEST_CASE_ST(ut_setup, ut_teardown,
14767 			test_zuc_hash_generate_test_case_7),
14768 		TEST_CASE_ST(ut_setup, ut_teardown,
14769 			test_zuc_hash_generate_test_case_8),
14770 		TEST_CASE_ST(ut_setup, ut_teardown,
14771 			test_zuc_hash_generate_test_case_9),
14772 		TEST_CASE_ST(ut_setup, ut_teardown,
14773 			test_zuc_hash_generate_test_case_10),
14774 
14775 
14776 		/** ZUC alg-chain (EEA3/EIA3) */
14777 		TEST_CASE_ST(ut_setup, ut_teardown,
14778 			test_zuc_cipher_auth_test_case_1),
14779 		TEST_CASE_ST(ut_setup, ut_teardown,
14780 			test_zuc_cipher_auth_test_case_2),
14781 
14782 		/** ZUC generate auth, then encrypt (EEA3) */
14783 		TEST_CASE_ST(ut_setup, ut_teardown,
14784 			test_zuc_auth_cipher_test_case_1),
14785 		TEST_CASE_ST(ut_setup, ut_teardown,
14786 			test_zuc_auth_cipher_test_case_1_oop),
14787 		TEST_CASE_ST(ut_setup, ut_teardown,
14788 			test_zuc_auth_cipher_test_case_1_sgl),
14789 		TEST_CASE_ST(ut_setup, ut_teardown,
14790 			test_zuc_auth_cipher_test_case_1_oop_sgl),
14791 
14792 		/** ZUC decrypt (EEA3), then verify auth */
14793 		TEST_CASE_ST(ut_setup, ut_teardown,
14794 			test_zuc_auth_cipher_verify_test_case_1),
14795 		TEST_CASE_ST(ut_setup, ut_teardown,
14796 			test_zuc_auth_cipher_verify_test_case_1_oop),
14797 		TEST_CASE_ST(ut_setup, ut_teardown,
14798 			test_zuc_auth_cipher_verify_test_case_1_sgl),
14799 		TEST_CASE_ST(ut_setup, ut_teardown,
14800 			test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
14801 		TEST_CASES_END()
14802 	}
14803 };
14804 
14805 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite  = {
14806 	.suite_name = "HMAC_MD5 Authentication Test Suite",
14807 	.setup = hmac_md5_auth_testsuite_setup,
14808 	.unit_test_cases = {
14809 		TEST_CASE_ST(ut_setup, ut_teardown,
14810 			test_MD5_HMAC_generate_case_1),
14811 		TEST_CASE_ST(ut_setup, ut_teardown,
14812 			test_MD5_HMAC_verify_case_1),
14813 		TEST_CASE_ST(ut_setup, ut_teardown,
14814 			test_MD5_HMAC_generate_case_2),
14815 		TEST_CASE_ST(ut_setup, ut_teardown,
14816 			test_MD5_HMAC_verify_case_2),
14817 		TEST_CASES_END()
14818 	}
14819 };
14820 
14821 static struct unit_test_suite cryptodev_kasumi_testsuite  = {
14822 	.suite_name = "Kasumi Test Suite",
14823 	.setup = kasumi_testsuite_setup,
14824 	.unit_test_cases = {
14825 		/** KASUMI hash only (UIA1) */
14826 		TEST_CASE_ST(ut_setup, ut_teardown,
14827 			test_kasumi_hash_generate_test_case_1),
14828 		TEST_CASE_ST(ut_setup, ut_teardown,
14829 			test_kasumi_hash_generate_test_case_2),
14830 		TEST_CASE_ST(ut_setup, ut_teardown,
14831 			test_kasumi_hash_generate_test_case_3),
14832 		TEST_CASE_ST(ut_setup, ut_teardown,
14833 			test_kasumi_hash_generate_test_case_4),
14834 		TEST_CASE_ST(ut_setup, ut_teardown,
14835 			test_kasumi_hash_generate_test_case_5),
14836 		TEST_CASE_ST(ut_setup, ut_teardown,
14837 			test_kasumi_hash_generate_test_case_6),
14838 
14839 		TEST_CASE_ST(ut_setup, ut_teardown,
14840 			test_kasumi_hash_verify_test_case_1),
14841 		TEST_CASE_ST(ut_setup, ut_teardown,
14842 			test_kasumi_hash_verify_test_case_2),
14843 		TEST_CASE_ST(ut_setup, ut_teardown,
14844 			test_kasumi_hash_verify_test_case_3),
14845 		TEST_CASE_ST(ut_setup, ut_teardown,
14846 			test_kasumi_hash_verify_test_case_4),
14847 		TEST_CASE_ST(ut_setup, ut_teardown,
14848 			test_kasumi_hash_verify_test_case_5),
14849 
14850 		/** KASUMI encrypt only (UEA1) */
14851 		TEST_CASE_ST(ut_setup, ut_teardown,
14852 			test_kasumi_encryption_test_case_1),
14853 		TEST_CASE_ST(ut_setup, ut_teardown,
14854 			test_kasumi_encryption_test_case_1_sgl),
14855 		TEST_CASE_ST(ut_setup, ut_teardown,
14856 			test_kasumi_encryption_test_case_1_oop),
14857 		TEST_CASE_ST(ut_setup, ut_teardown,
14858 			test_kasumi_encryption_test_case_1_oop_sgl),
14859 		TEST_CASE_ST(ut_setup, ut_teardown,
14860 			test_kasumi_encryption_test_case_2),
14861 		TEST_CASE_ST(ut_setup, ut_teardown,
14862 			test_kasumi_encryption_test_case_3),
14863 		TEST_CASE_ST(ut_setup, ut_teardown,
14864 			test_kasumi_encryption_test_case_4),
14865 		TEST_CASE_ST(ut_setup, ut_teardown,
14866 			test_kasumi_encryption_test_case_5),
14867 
14868 		/** KASUMI decrypt only (UEA1) */
14869 		TEST_CASE_ST(ut_setup, ut_teardown,
14870 			test_kasumi_decryption_test_case_1),
14871 		TEST_CASE_ST(ut_setup, ut_teardown,
14872 			test_kasumi_decryption_test_case_2),
14873 		TEST_CASE_ST(ut_setup, ut_teardown,
14874 			test_kasumi_decryption_test_case_3),
14875 		TEST_CASE_ST(ut_setup, ut_teardown,
14876 			test_kasumi_decryption_test_case_4),
14877 		TEST_CASE_ST(ut_setup, ut_teardown,
14878 			test_kasumi_decryption_test_case_5),
14879 		TEST_CASE_ST(ut_setup, ut_teardown,
14880 			test_kasumi_decryption_test_case_1_oop),
14881 		TEST_CASE_ST(ut_setup, ut_teardown,
14882 			test_kasumi_cipher_auth_test_case_1),
14883 
14884 		/** KASUMI generate auth, then encrypt (F8) */
14885 		TEST_CASE_ST(ut_setup, ut_teardown,
14886 			test_kasumi_auth_cipher_test_case_1),
14887 		TEST_CASE_ST(ut_setup, ut_teardown,
14888 			test_kasumi_auth_cipher_test_case_2),
14889 		TEST_CASE_ST(ut_setup, ut_teardown,
14890 			test_kasumi_auth_cipher_test_case_2_oop),
14891 		TEST_CASE_ST(ut_setup, ut_teardown,
14892 			test_kasumi_auth_cipher_test_case_2_sgl),
14893 		TEST_CASE_ST(ut_setup, ut_teardown,
14894 			test_kasumi_auth_cipher_test_case_2_oop_sgl),
14895 
14896 		/** KASUMI decrypt (F8), then verify auth */
14897 		TEST_CASE_ST(ut_setup, ut_teardown,
14898 			test_kasumi_auth_cipher_verify_test_case_1),
14899 		TEST_CASE_ST(ut_setup, ut_teardown,
14900 			test_kasumi_auth_cipher_verify_test_case_2),
14901 		TEST_CASE_ST(ut_setup, ut_teardown,
14902 			test_kasumi_auth_cipher_verify_test_case_2_oop),
14903 		TEST_CASE_ST(ut_setup, ut_teardown,
14904 			test_kasumi_auth_cipher_verify_test_case_2_sgl),
14905 		TEST_CASE_ST(ut_setup, ut_teardown,
14906 			test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
14907 
14908 		TEST_CASES_END()
14909 	}
14910 };
14911 
14912 static struct unit_test_suite cryptodev_esn_testsuite  = {
14913 	.suite_name = "ESN Test Suite",
14914 	.setup = esn_testsuite_setup,
14915 	.unit_test_cases = {
14916 		TEST_CASE_ST(ut_setup, ut_teardown,
14917 			auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
14918 		TEST_CASE_ST(ut_setup, ut_teardown,
14919 			auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
14920 		TEST_CASES_END()
14921 	}
14922 };
14923 
14924 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite  = {
14925 	.suite_name = "Negative AES GCM Test Suite",
14926 	.setup = negative_aes_gcm_testsuite_setup,
14927 	.unit_test_cases = {
14928 		TEST_CASE_ST(ut_setup, ut_teardown,
14929 			test_AES_GCM_auth_encryption_fail_iv_corrupt),
14930 		TEST_CASE_ST(ut_setup, ut_teardown,
14931 			test_AES_GCM_auth_encryption_fail_in_data_corrupt),
14932 		TEST_CASE_ST(ut_setup, ut_teardown,
14933 			test_AES_GCM_auth_encryption_fail_out_data_corrupt),
14934 		TEST_CASE_ST(ut_setup, ut_teardown,
14935 			test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
14936 		TEST_CASE_ST(ut_setup, ut_teardown,
14937 			test_AES_GCM_auth_encryption_fail_aad_corrupt),
14938 		TEST_CASE_ST(ut_setup, ut_teardown,
14939 			test_AES_GCM_auth_encryption_fail_tag_corrupt),
14940 		TEST_CASE_ST(ut_setup, ut_teardown,
14941 			test_AES_GCM_auth_decryption_fail_iv_corrupt),
14942 		TEST_CASE_ST(ut_setup, ut_teardown,
14943 			test_AES_GCM_auth_decryption_fail_in_data_corrupt),
14944 		TEST_CASE_ST(ut_setup, ut_teardown,
14945 			test_AES_GCM_auth_decryption_fail_out_data_corrupt),
14946 		TEST_CASE_ST(ut_setup, ut_teardown,
14947 			test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
14948 		TEST_CASE_ST(ut_setup, ut_teardown,
14949 			test_AES_GCM_auth_decryption_fail_aad_corrupt),
14950 		TEST_CASE_ST(ut_setup, ut_teardown,
14951 			test_AES_GCM_auth_decryption_fail_tag_corrupt),
14952 
14953 		TEST_CASES_END()
14954 	}
14955 };
14956 
14957 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite  = {
14958 	.suite_name = "Negative AES GMAC Test Suite",
14959 	.setup = negative_aes_gmac_testsuite_setup,
14960 	.unit_test_cases = {
14961 		TEST_CASE_ST(ut_setup, ut_teardown,
14962 			authentication_verify_AES128_GMAC_fail_data_corrupt),
14963 		TEST_CASE_ST(ut_setup, ut_teardown,
14964 			authentication_verify_AES128_GMAC_fail_tag_corrupt),
14965 
14966 		TEST_CASES_END()
14967 	}
14968 };
14969 
14970 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite  = {
14971 	.suite_name = "Mixed CIPHER + HASH algorithms Test Suite",
14972 	.setup = mixed_cipher_hash_testsuite_setup,
14973 	.unit_test_cases = {
14974 		/** AUTH AES CMAC + CIPHER AES CTR */
14975 		TEST_CASE_ST(ut_setup, ut_teardown,
14976 			test_aes_cmac_aes_ctr_digest_enc_test_case_1),
14977 		TEST_CASE_ST(ut_setup, ut_teardown,
14978 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
14979 		TEST_CASE_ST(ut_setup, ut_teardown,
14980 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
14981 		TEST_CASE_ST(ut_setup, ut_teardown,
14982 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
14983 		TEST_CASE_ST(ut_setup, ut_teardown,
14984 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
14985 		TEST_CASE_ST(ut_setup, ut_teardown,
14986 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
14987 		TEST_CASE_ST(ut_setup, ut_teardown,
14988 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
14989 		TEST_CASE_ST(ut_setup, ut_teardown,
14990 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
14991 
14992 		/** AUTH ZUC + CIPHER SNOW3G */
14993 		TEST_CASE_ST(ut_setup, ut_teardown,
14994 			test_auth_zuc_cipher_snow_test_case_1),
14995 		TEST_CASE_ST(ut_setup, ut_teardown,
14996 			test_verify_auth_zuc_cipher_snow_test_case_1),
14997 		/** AUTH AES CMAC + CIPHER SNOW3G */
14998 		TEST_CASE_ST(ut_setup, ut_teardown,
14999 			test_auth_aes_cmac_cipher_snow_test_case_1),
15000 		TEST_CASE_ST(ut_setup, ut_teardown,
15001 			test_verify_auth_aes_cmac_cipher_snow_test_case_1),
15002 		/** AUTH ZUC + CIPHER AES CTR */
15003 		TEST_CASE_ST(ut_setup, ut_teardown,
15004 			test_auth_zuc_cipher_aes_ctr_test_case_1),
15005 		TEST_CASE_ST(ut_setup, ut_teardown,
15006 			test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
15007 		/** AUTH SNOW3G + CIPHER AES CTR */
15008 		TEST_CASE_ST(ut_setup, ut_teardown,
15009 			test_auth_snow_cipher_aes_ctr_test_case_1),
15010 		TEST_CASE_ST(ut_setup, ut_teardown,
15011 			test_verify_auth_snow_cipher_aes_ctr_test_case_1),
15012 		/** AUTH SNOW3G + CIPHER ZUC */
15013 		TEST_CASE_ST(ut_setup, ut_teardown,
15014 			test_auth_snow_cipher_zuc_test_case_1),
15015 		TEST_CASE_ST(ut_setup, ut_teardown,
15016 			test_verify_auth_snow_cipher_zuc_test_case_1),
15017 		/** AUTH AES CMAC + CIPHER ZUC */
15018 		TEST_CASE_ST(ut_setup, ut_teardown,
15019 			test_auth_aes_cmac_cipher_zuc_test_case_1),
15020 		TEST_CASE_ST(ut_setup, ut_teardown,
15021 			test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
15022 
15023 		/** AUTH NULL + CIPHER SNOW3G */
15024 		TEST_CASE_ST(ut_setup, ut_teardown,
15025 			test_auth_null_cipher_snow_test_case_1),
15026 		TEST_CASE_ST(ut_setup, ut_teardown,
15027 			test_verify_auth_null_cipher_snow_test_case_1),
15028 		/** AUTH NULL + CIPHER ZUC */
15029 		TEST_CASE_ST(ut_setup, ut_teardown,
15030 			test_auth_null_cipher_zuc_test_case_1),
15031 		TEST_CASE_ST(ut_setup, ut_teardown,
15032 			test_verify_auth_null_cipher_zuc_test_case_1),
15033 		/** AUTH SNOW3G + CIPHER NULL */
15034 		TEST_CASE_ST(ut_setup, ut_teardown,
15035 			test_auth_snow_cipher_null_test_case_1),
15036 		TEST_CASE_ST(ut_setup, ut_teardown,
15037 			test_verify_auth_snow_cipher_null_test_case_1),
15038 		/** AUTH ZUC + CIPHER NULL */
15039 		TEST_CASE_ST(ut_setup, ut_teardown,
15040 			test_auth_zuc_cipher_null_test_case_1),
15041 		TEST_CASE_ST(ut_setup, ut_teardown,
15042 			test_verify_auth_zuc_cipher_null_test_case_1),
15043 		/** AUTH NULL + CIPHER AES CTR */
15044 		TEST_CASE_ST(ut_setup, ut_teardown,
15045 			test_auth_null_cipher_aes_ctr_test_case_1),
15046 		TEST_CASE_ST(ut_setup, ut_teardown,
15047 			test_verify_auth_null_cipher_aes_ctr_test_case_1),
15048 		/** AUTH AES CMAC + CIPHER NULL */
15049 		TEST_CASE_ST(ut_setup, ut_teardown,
15050 			test_auth_aes_cmac_cipher_null_test_case_1),
15051 		TEST_CASE_ST(ut_setup, ut_teardown,
15052 			test_verify_auth_aes_cmac_cipher_null_test_case_1),
15053 		TEST_CASES_END()
15054 	}
15055 };
15056 
15057 static int
15058 run_cryptodev_testsuite(const char *pmd_name)
15059 {
15060 	uint8_t ret, j, i = 0, blk_start_idx = 0;
15061 	const enum blockcipher_test_type blk_suites[] = {
15062 		BLKCIPHER_AES_CHAIN_TYPE,
15063 		BLKCIPHER_AES_CIPHERONLY_TYPE,
15064 		BLKCIPHER_AES_DOCSIS_TYPE,
15065 		BLKCIPHER_3DES_CHAIN_TYPE,
15066 		BLKCIPHER_3DES_CIPHERONLY_TYPE,
15067 		BLKCIPHER_DES_CIPHERONLY_TYPE,
15068 		BLKCIPHER_DES_DOCSIS_TYPE,
15069 		BLKCIPHER_AUTHONLY_TYPE};
15070 	struct unit_test_suite *static_suites[] = {
15071 		&cryptodev_multi_session_testsuite,
15072 		&cryptodev_null_testsuite,
15073 		&cryptodev_aes_ccm_auth_testsuite,
15074 		&cryptodev_aes_gcm_auth_testsuite,
15075 		&cryptodev_aes_gmac_auth_testsuite,
15076 		&cryptodev_snow3g_testsuite,
15077 		&cryptodev_chacha20_poly1305_testsuite,
15078 		&cryptodev_zuc_testsuite,
15079 		&cryptodev_hmac_md5_auth_testsuite,
15080 		&cryptodev_kasumi_testsuite,
15081 		&cryptodev_esn_testsuite,
15082 		&cryptodev_negative_aes_gcm_testsuite,
15083 		&cryptodev_negative_aes_gmac_testsuite,
15084 		&cryptodev_mixed_cipher_hash_testsuite,
15085 		&cryptodev_negative_hmac_sha1_testsuite,
15086 		&cryptodev_gen_testsuite,
15087 #ifdef RTE_LIB_SECURITY
15088 		&ipsec_proto_testsuite,
15089 		&pdcp_proto_testsuite,
15090 		&docsis_proto_testsuite,
15091 #endif
15092 		&end_testsuite
15093 	};
15094 	static struct unit_test_suite ts = {
15095 		.suite_name = "Cryptodev Unit Test Suite",
15096 		.setup = testsuite_setup,
15097 		.teardown = testsuite_teardown,
15098 		.unit_test_cases = {TEST_CASES_END()}
15099 	};
15100 
15101 	gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name);
15102 
15103 	if (gbl_driver_id == -1) {
15104 		RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name);
15105 		return TEST_SKIPPED;
15106 	}
15107 
15108 	ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
15109 			(RTE_DIM(blk_suites) + RTE_DIM(static_suites)));
15110 
15111 	ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites));
15112 	ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
15113 	ret = unit_test_suite_runner(&ts);
15114 
15115 	FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites));
15116 	free(ts.unit_test_suites);
15117 	return ret;
15118 }
15119 
15120 static int
15121 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name)
15122 {
15123 	struct rte_cryptodev_info dev_info;
15124 	uint8_t i, nb_devs;
15125 	int driver_id;
15126 
15127 	driver_id = rte_cryptodev_driver_id_get(pmd_name);
15128 	if (driver_id == -1) {
15129 		RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name);
15130 		return TEST_SKIPPED;
15131 	}
15132 
15133 	nb_devs = rte_cryptodev_count();
15134 	if (nb_devs < 1) {
15135 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
15136 		return TEST_SKIPPED;
15137 	}
15138 
15139 	for (i = 0; i < nb_devs; i++) {
15140 		rte_cryptodev_info_get(i, &dev_info);
15141 		if (dev_info.driver_id == driver_id) {
15142 			if (!(dev_info.feature_flags & flag)) {
15143 				RTE_LOG(INFO, USER1, "%s not supported\n",
15144 						flag_name);
15145 				return TEST_SKIPPED;
15146 			}
15147 			return 0; /* found */
15148 		}
15149 	}
15150 
15151 	RTE_LOG(INFO, USER1, "%s not supported\n", flag_name);
15152 	return TEST_SKIPPED;
15153 }
15154 
15155 static int
15156 test_cryptodev_qat(void)
15157 {
15158 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
15159 }
15160 
15161 static int
15162 test_cryptodev_virtio(void)
15163 {
15164 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
15165 }
15166 
15167 static int
15168 test_cryptodev_aesni_mb(void)
15169 {
15170 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
15171 }
15172 
15173 static int
15174 test_cryptodev_cpu_aesni_mb(void)
15175 {
15176 	int32_t rc;
15177 	enum rte_security_session_action_type at = gbl_action_type;
15178 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
15179 	rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
15180 	gbl_action_type = at;
15181 	return rc;
15182 }
15183 
15184 static int
15185 test_cryptodev_openssl(void)
15186 {
15187 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
15188 }
15189 
15190 static int
15191 test_cryptodev_aesni_gcm(void)
15192 {
15193 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
15194 }
15195 
15196 static int
15197 test_cryptodev_cpu_aesni_gcm(void)
15198 {
15199 	int32_t rc;
15200 	enum rte_security_session_action_type at = gbl_action_type;
15201 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
15202 	rc  = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
15203 	gbl_action_type = at;
15204 	return rc;
15205 }
15206 
15207 static int
15208 test_cryptodev_mlx5(void)
15209 {
15210 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD));
15211 }
15212 
15213 static int
15214 test_cryptodev_null(void)
15215 {
15216 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD));
15217 }
15218 
15219 static int
15220 test_cryptodev_sw_snow3g(void)
15221 {
15222 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
15223 }
15224 
15225 static int
15226 test_cryptodev_sw_kasumi(void)
15227 {
15228 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
15229 }
15230 
15231 static int
15232 test_cryptodev_sw_zuc(void)
15233 {
15234 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
15235 }
15236 
15237 static int
15238 test_cryptodev_armv8(void)
15239 {
15240 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
15241 }
15242 
15243 static int
15244 test_cryptodev_mrvl(void)
15245 {
15246 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
15247 }
15248 
15249 #ifdef RTE_CRYPTO_SCHEDULER
15250 
15251 static int
15252 test_cryptodev_scheduler(void)
15253 {
15254 	uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0;
15255 	const enum blockcipher_test_type blk_suites[] = {
15256 		BLKCIPHER_AES_CHAIN_TYPE,
15257 		BLKCIPHER_AES_CIPHERONLY_TYPE,
15258 		BLKCIPHER_AUTHONLY_TYPE
15259 	};
15260 	static struct unit_test_suite scheduler_multicore = {
15261 		.suite_name = "Scheduler Multicore Unit Test Suite",
15262 		.setup = scheduler_multicore_testsuite_setup,
15263 		.teardown = scheduler_mode_testsuite_teardown,
15264 		.unit_test_cases = {TEST_CASES_END()}
15265 	};
15266 	static struct unit_test_suite scheduler_round_robin = {
15267 		.suite_name = "Scheduler Round Robin Unit Test Suite",
15268 		.setup = scheduler_roundrobin_testsuite_setup,
15269 		.teardown = scheduler_mode_testsuite_teardown,
15270 		.unit_test_cases = {TEST_CASES_END()}
15271 	};
15272 	static struct unit_test_suite scheduler_failover = {
15273 		.suite_name = "Scheduler Failover Unit Test Suite",
15274 		.setup = scheduler_failover_testsuite_setup,
15275 		.teardown = scheduler_mode_testsuite_teardown,
15276 		.unit_test_cases = {TEST_CASES_END()}
15277 	};
15278 	static struct unit_test_suite scheduler_pkt_size_distr = {
15279 		.suite_name = "Scheduler Pkt Size Distr Unit Test Suite",
15280 		.setup = scheduler_pkt_size_distr_testsuite_setup,
15281 		.teardown = scheduler_mode_testsuite_teardown,
15282 		.unit_test_cases = {TEST_CASES_END()}
15283 	};
15284 	struct unit_test_suite *sched_mode_suites[] = {
15285 		&scheduler_multicore,
15286 		&scheduler_round_robin,
15287 		&scheduler_failover,
15288 		&scheduler_pkt_size_distr
15289 	};
15290 	static struct unit_test_suite scheduler_config = {
15291 		.suite_name = "Crypto Device Scheduler Config Unit Test Suite",
15292 		.unit_test_cases = {
15293 			TEST_CASE(test_scheduler_attach_worker_op),
15294 			TEST_CASE(test_scheduler_mode_multicore_op),
15295 			TEST_CASE(test_scheduler_mode_roundrobin_op),
15296 			TEST_CASE(test_scheduler_mode_failover_op),
15297 			TEST_CASE(test_scheduler_mode_pkt_size_distr_op),
15298 			TEST_CASE(test_scheduler_detach_worker_op),
15299 
15300 			TEST_CASES_END() /**< NULL terminate array */
15301 		}
15302 	};
15303 	struct unit_test_suite *static_suites[] = {
15304 		&scheduler_config,
15305 		&end_testsuite
15306 	};
15307 	static struct unit_test_suite ts = {
15308 		.suite_name = "Scheduler Unit Test Suite",
15309 		.setup = scheduler_testsuite_setup,
15310 		.teardown = testsuite_teardown,
15311 		.unit_test_cases = {TEST_CASES_END()}
15312 	};
15313 
15314 	gbl_driver_id =	rte_cryptodev_driver_id_get(
15315 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
15316 
15317 	if (gbl_driver_id == -1) {
15318 		RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
15319 		return TEST_SKIPPED;
15320 	}
15321 
15322 	if (rte_cryptodev_driver_id_get(
15323 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
15324 		RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
15325 		return TEST_SKIPPED;
15326 	}
15327 
15328 	for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
15329 		uint8_t blk_i = 0;
15330 		sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof
15331 				(struct unit_test_suite *) *
15332 				(RTE_DIM(blk_suites) + 1));
15333 		ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]),
15334 				blk_suites, RTE_DIM(blk_suites));
15335 		sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite;
15336 	}
15337 
15338 	ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
15339 			(RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites)));
15340 	ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites,
15341 			RTE_DIM(sched_mode_suites));
15342 	ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
15343 	ret = unit_test_suite_runner(&ts);
15344 
15345 	for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
15346 		FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx,
15347 				(*sched_mode_suites[sched_i]),
15348 				RTE_DIM(blk_suites));
15349 		free(sched_mode_suites[sched_i]->unit_test_suites);
15350 	}
15351 	free(ts.unit_test_suites);
15352 	return ret;
15353 }
15354 
15355 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
15356 
15357 #endif
15358 
15359 static int
15360 test_cryptodev_dpaa2_sec(void)
15361 {
15362 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
15363 }
15364 
15365 static int
15366 test_cryptodev_dpaa_sec(void)
15367 {
15368 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
15369 }
15370 
15371 static int
15372 test_cryptodev_ccp(void)
15373 {
15374 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD));
15375 }
15376 
15377 static int
15378 test_cryptodev_octeontx(void)
15379 {
15380 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
15381 }
15382 
15383 static int
15384 test_cryptodev_octeontx2(void)
15385 {
15386 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
15387 }
15388 
15389 static int
15390 test_cryptodev_caam_jr(void)
15391 {
15392 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
15393 }
15394 
15395 static int
15396 test_cryptodev_nitrox(void)
15397 {
15398 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
15399 }
15400 
15401 static int
15402 test_cryptodev_bcmfs(void)
15403 {
15404 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
15405 }
15406 
15407 static int
15408 test_cryptodev_qat_raw_api(void)
15409 {
15410 	static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD);
15411 	int ret;
15412 
15413 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
15414 			"RAW API");
15415 	if (ret)
15416 		return ret;
15417 
15418 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
15419 	ret = run_cryptodev_testsuite(pmd_name);
15420 	global_api_test_type = CRYPTODEV_API_TEST;
15421 
15422 	return ret;
15423 }
15424 
15425 static int
15426 test_cryptodev_cn9k(void)
15427 {
15428 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
15429 }
15430 
15431 static int
15432 test_cryptodev_cn10k(void)
15433 {
15434 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
15435 }
15436 
15437 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
15438 		test_cryptodev_qat_raw_api);
15439 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
15440 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
15441 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
15442 	test_cryptodev_cpu_aesni_mb);
15443 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
15444 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
15445 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
15446 	test_cryptodev_cpu_aesni_gcm);
15447 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5);
15448 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
15449 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
15450 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
15451 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
15452 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
15453 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
15454 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
15455 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
15456 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
15457 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
15458 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
15459 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
15460 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
15461 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
15462 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);
15463 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k);
15464 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k);
15465