xref: /dpdk/app/test/test_cryptodev.c (revision fbef5a42)
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_cryptodev_pmd.h>
20 #include <rte_string_fns.h>
21 
22 #ifdef RTE_CRYPTO_SCHEDULER
23 #include <rte_cryptodev_scheduler.h>
24 #include <rte_cryptodev_scheduler_operations.h>
25 #endif
26 
27 #include <rte_lcore.h>
28 
29 #include "test.h"
30 #include "test_cryptodev.h"
31 
32 #include "test_cryptodev_blockcipher.h"
33 #include "test_cryptodev_aes_test_vectors.h"
34 #include "test_cryptodev_des_test_vectors.h"
35 #include "test_cryptodev_hash_test_vectors.h"
36 #include "test_cryptodev_kasumi_test_vectors.h"
37 #include "test_cryptodev_kasumi_hash_test_vectors.h"
38 #include "test_cryptodev_snow3g_test_vectors.h"
39 #include "test_cryptodev_snow3g_hash_test_vectors.h"
40 #include "test_cryptodev_zuc_test_vectors.h"
41 #include "test_cryptodev_aead_test_vectors.h"
42 #include "test_cryptodev_hmac_test_vectors.h"
43 #include "test_cryptodev_mixed_test_vectors.h"
44 #ifdef RTE_LIB_SECURITY
45 #include "test_cryptodev_security_pdcp_test_vectors.h"
46 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h"
47 #include "test_cryptodev_security_pdcp_test_func.h"
48 #include "test_cryptodev_security_docsis_test_vectors.h"
49 
50 #define SDAP_DISABLED	0
51 #define SDAP_ENABLED	1
52 #endif
53 
54 #define VDEV_ARGS_SIZE 100
55 #define MAX_NB_SESSIONS 4
56 
57 #define MAX_DRV_SERVICE_CTX_SIZE 256
58 
59 #define MAX_RAW_DEQUEUE_COUNT	65535
60 
61 #define IN_PLACE 0
62 #define OUT_OF_PLACE 1
63 
64 #ifndef ARRAY_SIZE
65 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
66 #endif
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_testsuite_params {
76 	struct rte_mempool *mbuf_pool;
77 	struct rte_mempool *large_mbuf_pool;
78 	struct rte_mempool *op_mpool;
79 	struct rte_mempool *session_mpool;
80 	struct rte_mempool *session_priv_mpool;
81 	struct rte_cryptodev_config conf;
82 	struct rte_cryptodev_qp_conf qp_conf;
83 
84 	uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
85 	uint8_t valid_dev_count;
86 };
87 
88 struct crypto_unittest_params {
89 	struct rte_crypto_sym_xform cipher_xform;
90 	struct rte_crypto_sym_xform auth_xform;
91 	struct rte_crypto_sym_xform aead_xform;
92 #ifdef RTE_LIB_SECURITY
93 	struct rte_security_docsis_xform docsis_xform;
94 #endif
95 
96 	union {
97 		struct rte_cryptodev_sym_session *sess;
98 #ifdef RTE_LIB_SECURITY
99 		struct rte_security_session *sec_session;
100 #endif
101 	};
102 #ifdef RTE_LIB_SECURITY
103 	enum rte_security_session_action_type type;
104 #endif
105 	struct rte_crypto_op *op;
106 
107 	struct rte_mbuf *obuf, *ibuf;
108 
109 	uint8_t *digest;
110 };
111 
112 #define ALIGN_POW2_ROUNDUP(num, align) \
113 	(((num) + (align) - 1) & ~((align) - 1))
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 struct rte_mbuf *
132 setup_test_string(struct rte_mempool *mpool,
133 		const char *string, size_t len, uint8_t blocksize)
134 {
135 	struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
136 	size_t t_len = len - (blocksize ? (len % blocksize) : 0);
137 
138 	memset(m->buf_addr, 0, m->buf_len);
139 	if (m) {
140 		char *dst = rte_pktmbuf_append(m, t_len);
141 
142 		if (!dst) {
143 			rte_pktmbuf_free(m);
144 			return NULL;
145 		}
146 		if (string != NULL)
147 			rte_memcpy(dst, string, t_len);
148 		else
149 			memset(dst, 0, t_len);
150 	}
151 
152 	return m;
153 }
154 
155 /* Get number of bytes in X bits (rounding up) */
156 static uint32_t
157 ceil_byte_length(uint32_t num_bits)
158 {
159 	if (num_bits % 8)
160 		return ((num_bits >> 3) + 1);
161 	else
162 		return (num_bits >> 3);
163 }
164 
165 static uint32_t
166 get_raw_dp_dequeue_count(void *user_data __rte_unused)
167 {
168 	return 1;
169 }
170 
171 static void
172 post_process_raw_dp_op(void *user_data,	uint32_t index __rte_unused,
173 		uint8_t is_op_success)
174 {
175 	struct rte_crypto_op *op = user_data;
176 	op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS :
177 			RTE_CRYPTO_OP_STATUS_ERROR;
178 }
179 
180 void
181 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
182 		struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
183 		uint8_t len_in_bits, uint8_t cipher_iv_len)
184 {
185 	struct rte_crypto_sym_op *sop = op->sym;
186 	struct rte_crypto_op *ret_op = NULL;
187 	struct rte_crypto_vec data_vec[UINT8_MAX];
188 	struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv;
189 	union rte_crypto_sym_ofs ofs;
190 	struct rte_crypto_sym_vec vec;
191 	struct rte_crypto_sgl sgl;
192 	uint32_t max_len;
193 	union rte_cryptodev_session_ctx sess;
194 	uint32_t count = 0;
195 	struct rte_crypto_raw_dp_ctx *ctx;
196 	uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0,
197 			auth_len = 0;
198 	int32_t n;
199 	uint32_t n_success;
200 	int ctx_service_size;
201 	int32_t status = 0;
202 	int enqueue_status, dequeue_status;
203 
204 	ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
205 	if (ctx_service_size < 0) {
206 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
207 		return;
208 	}
209 
210 	ctx = malloc(ctx_service_size);
211 	if (!ctx) {
212 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
213 		return;
214 	}
215 
216 	/* Both are enums, setting crypto_sess will suit any session type */
217 	sess.crypto_sess = op->sym->session;
218 
219 	if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx,
220 			op->sess_type, sess, 0) < 0) {
221 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
222 		goto exit;
223 	}
224 
225 	cipher_iv.iova = 0;
226 	cipher_iv.va = NULL;
227 	aad_auth_iv.iova = 0;
228 	aad_auth_iv.va = NULL;
229 	digest.iova = 0;
230 	digest.va = NULL;
231 	sgl.vec = data_vec;
232 	vec.num = 1;
233 	vec.sgl = &sgl;
234 	vec.iv = &cipher_iv;
235 	vec.digest = &digest;
236 	vec.aad = &aad_auth_iv;
237 	vec.status = &status;
238 
239 	ofs.raw = 0;
240 
241 	if (is_cipher && is_auth) {
242 		cipher_offset = sop->cipher.data.offset;
243 		cipher_len = sop->cipher.data.length;
244 		auth_offset = sop->auth.data.offset;
245 		auth_len = sop->auth.data.length;
246 		max_len = RTE_MAX(cipher_offset + cipher_len,
247 				auth_offset + auth_len);
248 		if (len_in_bits) {
249 			max_len = max_len >> 3;
250 			cipher_offset = cipher_offset >> 3;
251 			auth_offset = auth_offset >> 3;
252 			cipher_len = cipher_len >> 3;
253 			auth_len = auth_len >> 3;
254 		}
255 		ofs.ofs.cipher.head = cipher_offset;
256 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
257 		ofs.ofs.auth.head = auth_offset;
258 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
259 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
260 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
261 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
262 				op, void *, IV_OFFSET + cipher_iv_len);
263 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
264 				cipher_iv_len);
265 		digest.va = (void *)sop->auth.digest.data;
266 		digest.iova = sop->auth.digest.phys_addr;
267 
268 	} else if (is_cipher) {
269 		cipher_offset = sop->cipher.data.offset;
270 		cipher_len = sop->cipher.data.length;
271 		max_len = cipher_len + cipher_offset;
272 		if (len_in_bits) {
273 			max_len = max_len >> 3;
274 			cipher_offset = cipher_offset >> 3;
275 			cipher_len = cipher_len >> 3;
276 		}
277 		ofs.ofs.cipher.head = cipher_offset;
278 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
279 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
280 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
281 
282 	} else if (is_auth) {
283 		auth_offset = sop->auth.data.offset;
284 		auth_len = sop->auth.data.length;
285 		max_len = auth_len + auth_offset;
286 		if (len_in_bits) {
287 			max_len = max_len >> 3;
288 			auth_offset = auth_offset >> 3;
289 			auth_len = auth_len >> 3;
290 		}
291 		ofs.ofs.auth.head = auth_offset;
292 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
293 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
294 				op, void *, IV_OFFSET + cipher_iv_len);
295 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
296 				cipher_iv_len);
297 		digest.va = (void *)sop->auth.digest.data;
298 		digest.iova = sop->auth.digest.phys_addr;
299 
300 	} else { /* aead */
301 		cipher_offset = sop->aead.data.offset;
302 		cipher_len = sop->aead.data.length;
303 		max_len = cipher_len + cipher_offset;
304 		if (len_in_bits) {
305 			max_len = max_len >> 3;
306 			cipher_offset = cipher_offset >> 3;
307 			cipher_len = cipher_len >> 3;
308 		}
309 		ofs.ofs.cipher.head = cipher_offset;
310 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
311 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
312 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
313 		aad_auth_iv.va = (void *)sop->aead.aad.data;
314 		aad_auth_iv.iova = sop->aead.aad.phys_addr;
315 		digest.va = (void *)sop->aead.digest.data;
316 		digest.iova = sop->aead.digest.phys_addr;
317 	}
318 
319 	n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
320 			data_vec, RTE_DIM(data_vec));
321 	if (n < 0 || n > sop->m_src->nb_segs) {
322 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
323 		goto exit;
324 	}
325 
326 	sgl.num = n;
327 
328 	if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op,
329 			&enqueue_status) < 1) {
330 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
331 		goto exit;
332 	}
333 
334 	if (enqueue_status == 0) {
335 		status = rte_cryptodev_raw_enqueue_done(ctx, 1);
336 		if (status < 0) {
337 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
338 			goto exit;
339 		}
340 	} else if (enqueue_status < 0) {
341 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
342 		goto exit;
343 	}
344 
345 	n = n_success = 0;
346 	while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) {
347 		n = rte_cryptodev_raw_dequeue_burst(ctx,
348 			get_raw_dp_dequeue_count, post_process_raw_dp_op,
349 				(void **)&ret_op, 0, &n_success,
350 				&dequeue_status);
351 		if (dequeue_status < 0) {
352 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
353 			goto exit;
354 		}
355 		if (n == 0)
356 			rte_pause();
357 	}
358 
359 	if (n == 1 && dequeue_status == 0) {
360 		if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) {
361 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
362 			goto exit;
363 		}
364 	}
365 
366 	op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op ||
367 			n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
368 					RTE_CRYPTO_OP_STATUS_SUCCESS;
369 
370 exit:
371 	free(ctx);
372 }
373 
374 static void
375 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
376 {
377 	int32_t n, st;
378 	struct rte_crypto_sym_op *sop;
379 	union rte_crypto_sym_ofs ofs;
380 	struct rte_crypto_sgl sgl;
381 	struct rte_crypto_sym_vec symvec;
382 	struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
383 	struct rte_crypto_vec vec[UINT8_MAX];
384 
385 	sop = op->sym;
386 
387 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
388 		sop->aead.data.length, vec, RTE_DIM(vec));
389 
390 	if (n < 0 || n != sop->m_src->nb_segs) {
391 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
392 		return;
393 	}
394 
395 	sgl.vec = vec;
396 	sgl.num = n;
397 	symvec.sgl = &sgl;
398 	symvec.iv = &iv_ptr;
399 	symvec.digest = &digest_ptr;
400 	symvec.aad = &aad_ptr;
401 	symvec.status = &st;
402 	symvec.num = 1;
403 
404 	/* for CPU crypto the IOVA address is not required */
405 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
406 	digest_ptr.va = (void *)sop->aead.digest.data;
407 	aad_ptr.va = (void *)sop->aead.aad.data;
408 
409 	ofs.raw = 0;
410 
411 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
412 		&symvec);
413 
414 	if (n != 1)
415 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
416 	else
417 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
418 }
419 
420 static void
421 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
422 {
423 	int32_t n, st;
424 	struct rte_crypto_sym_op *sop;
425 	union rte_crypto_sym_ofs ofs;
426 	struct rte_crypto_sgl sgl;
427 	struct rte_crypto_sym_vec symvec;
428 	struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
429 	struct rte_crypto_vec vec[UINT8_MAX];
430 
431 	sop = op->sym;
432 
433 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
434 		sop->auth.data.length, vec, RTE_DIM(vec));
435 
436 	if (n < 0 || n != sop->m_src->nb_segs) {
437 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
438 		return;
439 	}
440 
441 	sgl.vec = vec;
442 	sgl.num = n;
443 	symvec.sgl = &sgl;
444 	symvec.iv = &iv_ptr;
445 	symvec.digest = &digest_ptr;
446 	symvec.status = &st;
447 	symvec.num = 1;
448 
449 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
450 	digest_ptr.va = (void *)sop->auth.digest.data;
451 
452 	ofs.raw = 0;
453 	ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
454 	ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
455 		(sop->cipher.data.offset + sop->cipher.data.length);
456 
457 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
458 		&symvec);
459 
460 	if (n != 1)
461 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
462 	else
463 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
464 }
465 
466 static struct rte_crypto_op *
467 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
468 {
469 
470 	RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
471 
472 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
473 		RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
474 		return NULL;
475 	}
476 
477 	op = NULL;
478 
479 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
480 		rte_pause();
481 
482 	if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
483 		RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
484 		return NULL;
485 	}
486 
487 	return op;
488 }
489 
490 static struct crypto_testsuite_params testsuite_params = { NULL };
491 static struct crypto_unittest_params unittest_params;
492 
493 static int
494 testsuite_setup(void)
495 {
496 	struct crypto_testsuite_params *ts_params = &testsuite_params;
497 	struct rte_cryptodev_info info;
498 	uint32_t i = 0, nb_devs, dev_id;
499 	int ret;
500 	uint16_t qp_id;
501 
502 	memset(ts_params, 0, sizeof(*ts_params));
503 
504 	ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
505 	if (ts_params->mbuf_pool == NULL) {
506 		/* Not already created so create */
507 		ts_params->mbuf_pool = rte_pktmbuf_pool_create(
508 				"CRYPTO_MBUFPOOL",
509 				NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
510 				rte_socket_id());
511 		if (ts_params->mbuf_pool == NULL) {
512 			RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
513 			return TEST_FAILED;
514 		}
515 	}
516 
517 	ts_params->large_mbuf_pool = rte_mempool_lookup(
518 			"CRYPTO_LARGE_MBUFPOOL");
519 	if (ts_params->large_mbuf_pool == NULL) {
520 		/* Not already created so create */
521 		ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
522 				"CRYPTO_LARGE_MBUFPOOL",
523 				1, 0, 0, UINT16_MAX,
524 				rte_socket_id());
525 		if (ts_params->large_mbuf_pool == NULL) {
526 			RTE_LOG(ERR, USER1,
527 				"Can't create CRYPTO_LARGE_MBUFPOOL\n");
528 			return TEST_FAILED;
529 		}
530 	}
531 
532 	ts_params->op_mpool = rte_crypto_op_pool_create(
533 			"MBUF_CRYPTO_SYM_OP_POOL",
534 			RTE_CRYPTO_OP_TYPE_SYMMETRIC,
535 			NUM_MBUFS, MBUF_CACHE_SIZE,
536 			DEFAULT_NUM_XFORMS *
537 			sizeof(struct rte_crypto_sym_xform) +
538 			MAXIMUM_IV_LENGTH,
539 			rte_socket_id());
540 	if (ts_params->op_mpool == NULL) {
541 		RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
542 		return TEST_FAILED;
543 	}
544 
545 	/* Create an AESNI MB device if required */
546 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
547 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD))) {
548 		nb_devs = rte_cryptodev_device_count_by_driver(
549 				rte_cryptodev_driver_id_get(
550 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
551 		if (nb_devs < 1) {
552 			ret = rte_vdev_init(
553 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL);
554 
555 			TEST_ASSERT(ret == 0,
556 				"Failed to create instance of"
557 				" pmd : %s",
558 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
559 		}
560 	}
561 
562 	/* Create an AESNI GCM device if required */
563 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
564 			RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD))) {
565 		nb_devs = rte_cryptodev_device_count_by_driver(
566 				rte_cryptodev_driver_id_get(
567 				RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD)));
568 		if (nb_devs < 1) {
569 			TEST_ASSERT_SUCCESS(rte_vdev_init(
570 				RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), NULL),
571 				"Failed to create instance of"
572 				" pmd : %s",
573 				RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
574 		}
575 	}
576 
577 	/* Create a SNOW 3G device if required */
578 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
579 			RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD))) {
580 		nb_devs = rte_cryptodev_device_count_by_driver(
581 				rte_cryptodev_driver_id_get(
582 				RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD)));
583 		if (nb_devs < 1) {
584 			TEST_ASSERT_SUCCESS(rte_vdev_init(
585 				RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), NULL),
586 				"Failed to create instance of"
587 				" pmd : %s",
588 				RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
589 		}
590 	}
591 
592 	/* Create a KASUMI device if required */
593 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
594 			RTE_STR(CRYPTODEV_NAME_KASUMI_PMD))) {
595 		nb_devs = rte_cryptodev_device_count_by_driver(
596 				rte_cryptodev_driver_id_get(
597 				RTE_STR(CRYPTODEV_NAME_KASUMI_PMD)));
598 		if (nb_devs < 1) {
599 			TEST_ASSERT_SUCCESS(rte_vdev_init(
600 				RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), NULL),
601 				"Failed to create instance of"
602 				" pmd : %s",
603 				RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
604 		}
605 	}
606 
607 	/* Create a ZUC device if required */
608 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
609 			RTE_STR(CRYPTODEV_NAME_ZUC_PMD))) {
610 		nb_devs = rte_cryptodev_device_count_by_driver(
611 				rte_cryptodev_driver_id_get(
612 				RTE_STR(CRYPTODEV_NAME_ZUC_PMD)));
613 		if (nb_devs < 1) {
614 			TEST_ASSERT_SUCCESS(rte_vdev_init(
615 				RTE_STR(CRYPTODEV_NAME_ZUC_PMD), NULL),
616 				"Failed to create instance of"
617 				" pmd : %s",
618 				RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
619 		}
620 	}
621 
622 	/* Create a NULL device if required */
623 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
624 			RTE_STR(CRYPTODEV_NAME_NULL_PMD))) {
625 		nb_devs = rte_cryptodev_device_count_by_driver(
626 				rte_cryptodev_driver_id_get(
627 				RTE_STR(CRYPTODEV_NAME_NULL_PMD)));
628 		if (nb_devs < 1) {
629 			ret = rte_vdev_init(
630 				RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL);
631 
632 			TEST_ASSERT(ret == 0,
633 				"Failed to create instance of"
634 				" pmd : %s",
635 				RTE_STR(CRYPTODEV_NAME_NULL_PMD));
636 		}
637 	}
638 
639 	/* Create an OPENSSL device if required */
640 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
641 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
642 		nb_devs = rte_cryptodev_device_count_by_driver(
643 				rte_cryptodev_driver_id_get(
644 				RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
645 		if (nb_devs < 1) {
646 			ret = rte_vdev_init(
647 				RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
648 				NULL);
649 
650 			TEST_ASSERT(ret == 0, "Failed to create "
651 				"instance of pmd : %s",
652 				RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
653 		}
654 	}
655 
656 	/* Create a ARMv8 device if required */
657 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
658 			RTE_STR(CRYPTODEV_NAME_ARMV8_PMD))) {
659 		nb_devs = rte_cryptodev_device_count_by_driver(
660 				rte_cryptodev_driver_id_get(
661 				RTE_STR(CRYPTODEV_NAME_ARMV8_PMD)));
662 		if (nb_devs < 1) {
663 			ret = rte_vdev_init(
664 				RTE_STR(CRYPTODEV_NAME_ARMV8_PMD),
665 				NULL);
666 
667 			TEST_ASSERT(ret == 0, "Failed to create "
668 				"instance of pmd : %s",
669 				RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
670 		}
671 	}
672 
673 	/* Create a MVSAM device if required */
674 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
675 			RTE_STR(CRYPTODEV_NAME_MVSAM_PMD))) {
676 		nb_devs = rte_cryptodev_device_count_by_driver(
677 				rte_cryptodev_driver_id_get(
678 				RTE_STR(CRYPTODEV_NAME_MVSAM_PMD)));
679 		if (nb_devs < 1) {
680 			ret = rte_vdev_init(
681 				RTE_STR(CRYPTODEV_NAME_MVSAM_PMD),
682 				NULL);
683 
684 			TEST_ASSERT(ret == 0, "Failed to create "
685 				"instance of pmd : %s",
686 				RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
687 		}
688 	}
689 
690 	/* Create an CCP device if required */
691 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
692 			RTE_STR(CRYPTODEV_NAME_CCP_PMD))) {
693 		nb_devs = rte_cryptodev_device_count_by_driver(
694 				rte_cryptodev_driver_id_get(
695 				RTE_STR(CRYPTODEV_NAME_CCP_PMD)));
696 		if (nb_devs < 1) {
697 			ret = rte_vdev_init(
698 				RTE_STR(CRYPTODEV_NAME_CCP_PMD),
699 				NULL);
700 
701 			TEST_ASSERT(ret == 0, "Failed to create "
702 				"instance of pmd : %s",
703 				RTE_STR(CRYPTODEV_NAME_CCP_PMD));
704 		}
705 	}
706 
707 #ifdef RTE_CRYPTO_SCHEDULER
708 	char vdev_args[VDEV_ARGS_SIZE] = {""};
709 	char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
710 		"ordering=enable,name=cryptodev_test_scheduler,corelist="};
711 	uint16_t worker_core_count = 0;
712 	uint16_t socket_id = 0;
713 
714 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
715 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
716 
717 		/* Identify the Worker Cores
718 		 * Use 2 worker cores for the device args
719 		 */
720 		RTE_LCORE_FOREACH_WORKER(i) {
721 			if (worker_core_count > 1)
722 				break;
723 			snprintf(vdev_args, sizeof(vdev_args),
724 					"%s%d", temp_str, i);
725 			strcpy(temp_str, vdev_args);
726 			strlcat(temp_str, ";", sizeof(temp_str));
727 			worker_core_count++;
728 			socket_id = rte_lcore_to_socket_id(i);
729 		}
730 		if (worker_core_count != 2) {
731 			RTE_LOG(ERR, USER1,
732 				"Cryptodev scheduler test require at least "
733 				"two worker cores to run. "
734 				"Please use the correct coremask.\n");
735 			return TEST_FAILED;
736 		}
737 		strcpy(temp_str, vdev_args);
738 		snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
739 				temp_str, socket_id);
740 		RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
741 		nb_devs = rte_cryptodev_device_count_by_driver(
742 				rte_cryptodev_driver_id_get(
743 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
744 		if (nb_devs < 1) {
745 			ret = rte_vdev_init(
746 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
747 					vdev_args);
748 			TEST_ASSERT(ret == 0,
749 				"Failed to create instance %u of"
750 				" pmd : %s",
751 				i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
752 		}
753 	}
754 #endif /* RTE_CRYPTO_SCHEDULER */
755 
756 	nb_devs = rte_cryptodev_count();
757 	if (nb_devs < 1) {
758 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
759 		return TEST_SKIPPED;
760 	}
761 
762 	/* Create list of valid crypto devs */
763 	for (i = 0; i < nb_devs; i++) {
764 		rte_cryptodev_info_get(i, &info);
765 		if (info.driver_id == gbl_driver_id)
766 			ts_params->valid_devs[ts_params->valid_dev_count++] = i;
767 	}
768 
769 	if (ts_params->valid_dev_count < 1)
770 		return TEST_FAILED;
771 
772 	/* Set up all the qps on the first of the valid devices found */
773 
774 	dev_id = ts_params->valid_devs[0];
775 
776 	rte_cryptodev_info_get(dev_id, &info);
777 
778 	ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
779 	ts_params->conf.socket_id = SOCKET_ID_ANY;
780 	ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
781 
782 	unsigned int session_size =
783 		rte_cryptodev_sym_get_private_session_size(dev_id);
784 
785 #ifdef RTE_LIB_SECURITY
786 	unsigned int security_session_size = rte_security_session_get_size(
787 			rte_cryptodev_get_sec_ctx(dev_id));
788 
789 	if (session_size < security_session_size)
790 		session_size = security_session_size;
791 #endif
792 	/*
793 	 * Create mempool with maximum number of sessions.
794 	 */
795 	if (info.sym.max_nb_sessions != 0 &&
796 			info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
797 		RTE_LOG(ERR, USER1, "Device does not support "
798 				"at least %u sessions\n",
799 				MAX_NB_SESSIONS);
800 		return TEST_FAILED;
801 	}
802 
803 	ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
804 			"test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
805 			SOCKET_ID_ANY);
806 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
807 			"session mempool allocation failed");
808 
809 	ts_params->session_priv_mpool = rte_mempool_create(
810 			"test_sess_mp_priv",
811 			MAX_NB_SESSIONS,
812 			session_size,
813 			0, 0, NULL, NULL, NULL,
814 			NULL, SOCKET_ID_ANY,
815 			0);
816 	TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
817 			"session mempool allocation failed");
818 
819 
820 
821 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
822 			&ts_params->conf),
823 			"Failed to configure cryptodev %u with %u qps",
824 			dev_id, ts_params->conf.nb_queue_pairs);
825 
826 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
827 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
828 	ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
829 
830 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
831 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
832 			dev_id, qp_id, &ts_params->qp_conf,
833 			rte_cryptodev_socket_id(dev_id)),
834 			"Failed to setup queue pair %u on cryptodev %u",
835 			qp_id, dev_id);
836 	}
837 
838 	return TEST_SUCCESS;
839 }
840 
841 static void
842 testsuite_teardown(void)
843 {
844 	struct crypto_testsuite_params *ts_params = &testsuite_params;
845 
846 	if (ts_params->mbuf_pool != NULL) {
847 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
848 		rte_mempool_avail_count(ts_params->mbuf_pool));
849 	}
850 
851 	if (ts_params->op_mpool != NULL) {
852 		RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
853 		rte_mempool_avail_count(ts_params->op_mpool));
854 	}
855 
856 	/* Free session mempools */
857 	if (ts_params->session_priv_mpool != NULL) {
858 		rte_mempool_free(ts_params->session_priv_mpool);
859 		ts_params->session_priv_mpool = NULL;
860 	}
861 
862 	if (ts_params->session_mpool != NULL) {
863 		rte_mempool_free(ts_params->session_mpool);
864 		ts_params->session_mpool = NULL;
865 	}
866 }
867 
868 static int
869 dev_configure_and_start(uint64_t ff_disable)
870 {
871 	struct crypto_testsuite_params *ts_params = &testsuite_params;
872 	struct crypto_unittest_params *ut_params = &unittest_params;
873 
874 	uint16_t qp_id;
875 
876 	/* Clear unit test parameters before running test */
877 	memset(ut_params, 0, sizeof(*ut_params));
878 
879 	/* Reconfigure device to default parameters */
880 	ts_params->conf.socket_id = SOCKET_ID_ANY;
881 	ts_params->conf.ff_disable = ff_disable;
882 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
883 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
884 	ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
885 
886 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
887 			&ts_params->conf),
888 			"Failed to configure cryptodev %u",
889 			ts_params->valid_devs[0]);
890 
891 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
892 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
893 			ts_params->valid_devs[0], qp_id,
894 			&ts_params->qp_conf,
895 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
896 			"Failed to setup queue pair %u on cryptodev %u",
897 			qp_id, ts_params->valid_devs[0]);
898 	}
899 
900 
901 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
902 
903 	/* Start the device */
904 	TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
905 			"Failed to start cryptodev %u",
906 			ts_params->valid_devs[0]);
907 
908 	return TEST_SUCCESS;
909 }
910 
911 static int
912 ut_setup(void)
913 {
914 	/* Configure and start the device with security feature disabled */
915 	return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
916 }
917 
918 static int
919 ut_setup_security(void)
920 {
921 	/* Configure and start the device with no features disabled */
922 	return dev_configure_and_start(0);
923 }
924 
925 static void
926 ut_teardown(void)
927 {
928 	struct crypto_testsuite_params *ts_params = &testsuite_params;
929 	struct crypto_unittest_params *ut_params = &unittest_params;
930 	struct rte_cryptodev_stats stats;
931 
932 	/* free crypto session structure */
933 #ifdef RTE_LIB_SECURITY
934 	if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
935 		if (ut_params->sec_session) {
936 			rte_security_session_destroy(rte_cryptodev_get_sec_ctx
937 						(ts_params->valid_devs[0]),
938 						ut_params->sec_session);
939 			ut_params->sec_session = NULL;
940 		}
941 	} else
942 #endif
943 	{
944 		if (ut_params->sess) {
945 			rte_cryptodev_sym_session_clear(
946 					ts_params->valid_devs[0],
947 					ut_params->sess);
948 			rte_cryptodev_sym_session_free(ut_params->sess);
949 			ut_params->sess = NULL;
950 		}
951 	}
952 
953 	/* free crypto operation structure */
954 	if (ut_params->op)
955 		rte_crypto_op_free(ut_params->op);
956 
957 	/*
958 	 * free mbuf - both obuf and ibuf are usually the same,
959 	 * so check if they point at the same address is necessary,
960 	 * to avoid freeing the mbuf twice.
961 	 */
962 	if (ut_params->obuf) {
963 		rte_pktmbuf_free(ut_params->obuf);
964 		if (ut_params->ibuf == ut_params->obuf)
965 			ut_params->ibuf = 0;
966 		ut_params->obuf = 0;
967 	}
968 	if (ut_params->ibuf) {
969 		rte_pktmbuf_free(ut_params->ibuf);
970 		ut_params->ibuf = 0;
971 	}
972 
973 	if (ts_params->mbuf_pool != NULL)
974 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
975 			rte_mempool_avail_count(ts_params->mbuf_pool));
976 
977 	rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
978 
979 	/* Stop the device */
980 	rte_cryptodev_stop(ts_params->valid_devs[0]);
981 }
982 
983 static int
984 test_device_configure_invalid_dev_id(void)
985 {
986 	struct crypto_testsuite_params *ts_params = &testsuite_params;
987 	uint16_t dev_id, num_devs = 0;
988 
989 	TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
990 			"Need at least %d devices for test", 1);
991 
992 	/* valid dev_id values */
993 	dev_id = ts_params->valid_devs[0];
994 
995 	/* Stop the device in case it's started so it can be configured */
996 	rte_cryptodev_stop(dev_id);
997 
998 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
999 			"Failed test for rte_cryptodev_configure: "
1000 			"invalid dev_num %u", dev_id);
1001 
1002 	/* invalid dev_id values */
1003 	dev_id = num_devs;
1004 
1005 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1006 			"Failed test for rte_cryptodev_configure: "
1007 			"invalid dev_num %u", dev_id);
1008 
1009 	dev_id = 0xff;
1010 
1011 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1012 			"Failed test for rte_cryptodev_configure:"
1013 			"invalid dev_num %u", dev_id);
1014 
1015 	return TEST_SUCCESS;
1016 }
1017 
1018 static int
1019 test_device_configure_invalid_queue_pair_ids(void)
1020 {
1021 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1022 	uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1023 
1024 	/* Stop the device in case it's started so it can be configured */
1025 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1026 
1027 	/* valid - max value queue pairs */
1028 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1029 
1030 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1031 			&ts_params->conf),
1032 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1033 			ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1034 
1035 	/* valid - one queue pairs */
1036 	ts_params->conf.nb_queue_pairs = 1;
1037 
1038 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1039 			&ts_params->conf),
1040 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1041 			ts_params->valid_devs[0],
1042 			ts_params->conf.nb_queue_pairs);
1043 
1044 
1045 	/* invalid - zero queue pairs */
1046 	ts_params->conf.nb_queue_pairs = 0;
1047 
1048 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1049 			&ts_params->conf),
1050 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1051 			" invalid qps: %u",
1052 			ts_params->valid_devs[0],
1053 			ts_params->conf.nb_queue_pairs);
1054 
1055 
1056 	/* invalid - max value supported by field queue pairs */
1057 	ts_params->conf.nb_queue_pairs = UINT16_MAX;
1058 
1059 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1060 			&ts_params->conf),
1061 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1062 			" invalid qps: %u",
1063 			ts_params->valid_devs[0],
1064 			ts_params->conf.nb_queue_pairs);
1065 
1066 
1067 	/* invalid - max value + 1 queue pairs */
1068 	ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1069 
1070 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1071 			&ts_params->conf),
1072 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1073 			" invalid qps: %u",
1074 			ts_params->valid_devs[0],
1075 			ts_params->conf.nb_queue_pairs);
1076 
1077 	/* revert to original testsuite value */
1078 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1079 
1080 	return TEST_SUCCESS;
1081 }
1082 
1083 static int
1084 test_queue_pair_descriptor_setup(void)
1085 {
1086 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1087 	struct rte_cryptodev_qp_conf qp_conf = {
1088 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
1089 	};
1090 	uint16_t qp_id;
1091 
1092 	/* Stop the device in case it's started so it can be configured */
1093 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1094 
1095 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1096 			&ts_params->conf),
1097 			"Failed to configure cryptodev %u",
1098 			ts_params->valid_devs[0]);
1099 
1100 	/*
1101 	 * Test various ring sizes on this device. memzones can't be
1102 	 * freed so are re-used if ring is released and re-created.
1103 	 */
1104 	qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1105 	qp_conf.mp_session = ts_params->session_mpool;
1106 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
1107 
1108 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1109 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1110 				ts_params->valid_devs[0], qp_id, &qp_conf,
1111 				rte_cryptodev_socket_id(
1112 						ts_params->valid_devs[0])),
1113 				"Failed test for "
1114 				"rte_cryptodev_queue_pair_setup: num_inflights "
1115 				"%u on qp %u on cryptodev %u",
1116 				qp_conf.nb_descriptors, qp_id,
1117 				ts_params->valid_devs[0]);
1118 	}
1119 
1120 	qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1121 
1122 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1123 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1124 				ts_params->valid_devs[0], qp_id, &qp_conf,
1125 				rte_cryptodev_socket_id(
1126 						ts_params->valid_devs[0])),
1127 				"Failed test for"
1128 				" rte_cryptodev_queue_pair_setup: num_inflights"
1129 				" %u on qp %u on cryptodev %u",
1130 				qp_conf.nb_descriptors, qp_id,
1131 				ts_params->valid_devs[0]);
1132 	}
1133 
1134 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
1135 
1136 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1137 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1138 				ts_params->valid_devs[0], qp_id, &qp_conf,
1139 				rte_cryptodev_socket_id(
1140 						ts_params->valid_devs[0])),
1141 				"Failed test for "
1142 				"rte_cryptodev_queue_pair_setup: num_inflights"
1143 				" %u on qp %u on cryptodev %u",
1144 				qp_conf.nb_descriptors, qp_id,
1145 				ts_params->valid_devs[0]);
1146 	}
1147 
1148 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1149 
1150 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1151 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1152 				ts_params->valid_devs[0], qp_id, &qp_conf,
1153 				rte_cryptodev_socket_id(
1154 						ts_params->valid_devs[0])),
1155 				"Failed test for"
1156 				" rte_cryptodev_queue_pair_setup:"
1157 				"num_inflights %u on qp %u on cryptodev %u",
1158 				qp_conf.nb_descriptors, qp_id,
1159 				ts_params->valid_devs[0]);
1160 	}
1161 
1162 	/* test invalid queue pair id */
1163 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;	/*valid */
1164 
1165 	qp_id = ts_params->conf.nb_queue_pairs;		/*invalid */
1166 
1167 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1168 			ts_params->valid_devs[0],
1169 			qp_id, &qp_conf,
1170 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1171 			"Failed test for rte_cryptodev_queue_pair_setup:"
1172 			"invalid qp %u on cryptodev %u",
1173 			qp_id, ts_params->valid_devs[0]);
1174 
1175 	qp_id = 0xffff; /*invalid*/
1176 
1177 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1178 			ts_params->valid_devs[0],
1179 			qp_id, &qp_conf,
1180 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1181 			"Failed test for rte_cryptodev_queue_pair_setup:"
1182 			"invalid qp %u on cryptodev %u",
1183 			qp_id, ts_params->valid_devs[0]);
1184 
1185 	return TEST_SUCCESS;
1186 }
1187 
1188 /* ***** Plaintext data for tests ***** */
1189 
1190 const char catch_22_quote_1[] =
1191 		"There was only one catch and that was Catch-22, which "
1192 		"specified that a concern for one's safety in the face of "
1193 		"dangers that were real and immediate was the process of a "
1194 		"rational mind. Orr was crazy and could be grounded. All he "
1195 		"had to do was ask; and as soon as he did, he would no longer "
1196 		"be crazy and would have to fly more missions. Orr would be "
1197 		"crazy to fly more missions and sane if he didn't, but if he "
1198 		"was sane he had to fly them. If he flew them he was crazy "
1199 		"and didn't have to; but if he didn't want to he was sane and "
1200 		"had to. Yossarian was moved very deeply by the absolute "
1201 		"simplicity of this clause of Catch-22 and let out a "
1202 		"respectful whistle. \"That's some catch, that Catch-22\", he "
1203 		"observed. \"It's the best there is,\" Doc Daneeka agreed.";
1204 
1205 const char catch_22_quote[] =
1206 		"What a lousy earth! He wondered how many people were "
1207 		"destitute that same night even in his own prosperous country, "
1208 		"how many homes were shanties, how many husbands were drunk "
1209 		"and wives socked, and how many children were bullied, abused, "
1210 		"or abandoned. How many families hungered for food they could "
1211 		"not afford to buy? How many hearts were broken? How many "
1212 		"suicides would take place that same night, how many people "
1213 		"would go insane? How many cockroaches and landlords would "
1214 		"triumph? How many winners were losers, successes failures, "
1215 		"and rich men poor men? How many wise guys were stupid? How "
1216 		"many happy endings were unhappy endings? How many honest men "
1217 		"were liars, brave men cowards, loyal men traitors, how many "
1218 		"sainted men were corrupt, how many people in positions of "
1219 		"trust had sold their souls to bodyguards, how many had never "
1220 		"had souls? How many straight-and-narrow paths were crooked "
1221 		"paths? How many best families were worst families and how "
1222 		"many good people were bad people? When you added them all up "
1223 		"and then subtracted, you might be left with only the children, "
1224 		"and perhaps with Albert Einstein and an old violinist or "
1225 		"sculptor somewhere.";
1226 
1227 #define QUOTE_480_BYTES		(480)
1228 #define QUOTE_512_BYTES		(512)
1229 #define QUOTE_768_BYTES		(768)
1230 #define QUOTE_1024_BYTES	(1024)
1231 
1232 
1233 
1234 /* ***** SHA1 Hash Tests ***** */
1235 
1236 #define HMAC_KEY_LENGTH_SHA1	(DIGEST_BYTE_LENGTH_SHA1)
1237 
1238 static uint8_t hmac_sha1_key[] = {
1239 	0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1240 	0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1241 	0xDE, 0xF4, 0xDE, 0xAD };
1242 
1243 /* ***** SHA224 Hash Tests ***** */
1244 
1245 #define HMAC_KEY_LENGTH_SHA224	(DIGEST_BYTE_LENGTH_SHA224)
1246 
1247 
1248 /* ***** AES-CBC Cipher Tests ***** */
1249 
1250 #define CIPHER_KEY_LENGTH_AES_CBC	(16)
1251 #define CIPHER_IV_LENGTH_AES_CBC	(CIPHER_KEY_LENGTH_AES_CBC)
1252 
1253 static uint8_t aes_cbc_key[] = {
1254 	0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1255 	0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1256 
1257 static uint8_t aes_cbc_iv[] = {
1258 	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1259 	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1260 
1261 
1262 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1263 
1264 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1265 	0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1266 	0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1267 	0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1268 	0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1269 	0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1270 	0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1271 	0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1272 	0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1273 	0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1274 	0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1275 	0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1276 	0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1277 	0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1278 	0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1279 	0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1280 	0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1281 	0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1282 	0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1283 	0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1284 	0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1285 	0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1286 	0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1287 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1288 	0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1289 	0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1290 	0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1291 	0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1292 	0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1293 	0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1294 	0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1295 	0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1296 	0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1297 	0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1298 	0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1299 	0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1300 	0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1301 	0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1302 	0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1303 	0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1304 	0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1305 	0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1306 	0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1307 	0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1308 	0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1309 	0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1310 	0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1311 	0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1312 	0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1313 	0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1314 	0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1315 	0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1316 	0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1317 	0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1318 	0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1319 	0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1320 	0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1321 	0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1322 	0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1323 	0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1324 	0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1325 	0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1326 	0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1327 	0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1328 	0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1329 };
1330 
1331 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1332 	0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1333 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1334 	0x18, 0x8c, 0x1d, 0x32
1335 };
1336 
1337 
1338 /* Multisession Vector context Test */
1339 /*Begin Session 0 */
1340 static uint8_t ms_aes_cbc_key0[] = {
1341 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1342 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1343 };
1344 
1345 static uint8_t ms_aes_cbc_iv0[] = {
1346 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1347 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1348 };
1349 
1350 static const uint8_t ms_aes_cbc_cipher0[] = {
1351 		0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1352 		0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1353 		0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1354 		0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1355 		0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1356 		0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1357 		0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1358 		0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1359 		0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1360 		0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1361 		0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1362 		0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1363 		0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1364 		0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1365 		0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1366 		0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1367 		0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1368 		0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1369 		0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1370 		0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1371 		0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1372 		0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1373 		0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1374 		0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1375 		0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1376 		0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1377 		0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1378 		0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1379 		0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1380 		0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1381 		0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1382 		0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1383 		0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1384 		0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1385 		0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1386 		0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1387 		0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1388 		0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1389 		0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1390 		0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1391 		0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1392 		0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1393 		0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1394 		0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1395 		0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1396 		0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1397 		0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1398 		0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1399 		0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1400 		0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1401 		0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1402 		0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1403 		0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1404 		0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1405 		0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1406 		0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1407 		0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1408 		0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1409 		0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1410 		0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1411 		0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1412 		0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1413 		0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1414 		0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1415 };
1416 
1417 
1418 static  uint8_t ms_hmac_key0[] = {
1419 		0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1420 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1421 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1422 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1423 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1424 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1425 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1426 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1427 };
1428 
1429 static const uint8_t ms_hmac_digest0[] = {
1430 		0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1431 		0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1432 		0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1433 		0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1434 		0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1435 		0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1436 		0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1437 		0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1438 		};
1439 
1440 /* End Session 0 */
1441 /* Begin session 1 */
1442 
1443 static  uint8_t ms_aes_cbc_key1[] = {
1444 		0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1445 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1446 };
1447 
1448 static  uint8_t ms_aes_cbc_iv1[] = {
1449 	0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1450 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1451 };
1452 
1453 static const uint8_t ms_aes_cbc_cipher1[] = {
1454 		0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1455 		0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1456 		0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1457 		0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1458 		0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1459 		0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1460 		0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1461 		0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1462 		0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1463 		0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1464 		0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1465 		0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1466 		0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1467 		0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1468 		0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1469 		0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1470 		0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1471 		0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1472 		0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1473 		0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1474 		0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1475 		0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1476 		0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1477 		0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1478 		0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1479 		0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1480 		0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1481 		0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1482 		0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1483 		0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1484 		0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1485 		0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1486 		0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1487 		0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1488 		0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1489 		0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1490 		0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1491 		0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1492 		0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1493 		0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1494 		0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1495 		0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1496 		0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1497 		0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1498 		0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1499 		0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1500 		0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1501 		0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1502 		0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1503 		0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1504 		0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1505 		0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1506 		0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1507 		0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1508 		0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1509 		0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1510 		0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1511 		0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1512 		0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1513 		0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1514 		0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1515 		0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1516 		0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1517 		0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1518 
1519 };
1520 
1521 static uint8_t ms_hmac_key1[] = {
1522 		0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1523 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1524 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1525 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1526 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1527 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1528 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1529 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1530 };
1531 
1532 static const uint8_t ms_hmac_digest1[] = {
1533 		0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1534 		0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
1535 		0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
1536 		0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
1537 		0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
1538 		0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
1539 		0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
1540 		0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
1541 };
1542 /* End Session 1  */
1543 /* Begin Session 2 */
1544 static  uint8_t ms_aes_cbc_key2[] = {
1545 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1546 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1547 };
1548 
1549 static  uint8_t ms_aes_cbc_iv2[] = {
1550 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1551 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1552 };
1553 
1554 static const uint8_t ms_aes_cbc_cipher2[] = {
1555 		0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
1556 		0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
1557 		0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
1558 		0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
1559 		0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
1560 		0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
1561 		0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
1562 		0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
1563 		0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
1564 		0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
1565 		0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
1566 		0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
1567 		0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
1568 		0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
1569 		0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
1570 		0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
1571 		0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
1572 		0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
1573 		0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
1574 		0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
1575 		0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
1576 		0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
1577 		0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
1578 		0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
1579 		0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
1580 		0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
1581 		0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
1582 		0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
1583 		0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
1584 		0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
1585 		0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
1586 		0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
1587 		0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
1588 		0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
1589 		0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
1590 		0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
1591 		0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
1592 		0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
1593 		0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
1594 		0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
1595 		0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
1596 		0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
1597 		0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
1598 		0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
1599 		0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
1600 		0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
1601 		0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
1602 		0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
1603 		0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
1604 		0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
1605 		0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
1606 		0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
1607 		0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
1608 		0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
1609 		0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
1610 		0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
1611 		0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
1612 		0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
1613 		0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
1614 		0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
1615 		0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
1616 		0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
1617 		0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
1618 		0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
1619 };
1620 
1621 static  uint8_t ms_hmac_key2[] = {
1622 		0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1623 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1624 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1625 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1626 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1627 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1628 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1629 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1630 };
1631 
1632 static const uint8_t ms_hmac_digest2[] = {
1633 		0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
1634 		0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
1635 		0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
1636 		0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
1637 		0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
1638 		0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
1639 		0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
1640 		0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
1641 };
1642 
1643 /* End Session 2 */
1644 
1645 
1646 static int
1647 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
1648 {
1649 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1650 	struct crypto_unittest_params *ut_params = &unittest_params;
1651 
1652 	/* Verify the capabilities */
1653 	struct rte_cryptodev_sym_capability_idx cap_idx;
1654 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1655 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
1656 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
1657 			&cap_idx) == NULL)
1658 		return -ENOTSUP;
1659 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1660 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
1661 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
1662 			&cap_idx) == NULL)
1663 		return -ENOTSUP;
1664 
1665 	/* Generate test mbuf data and space for digest */
1666 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1667 			catch_22_quote,	QUOTE_512_BYTES, 0);
1668 
1669 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1670 			DIGEST_BYTE_LENGTH_SHA1);
1671 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1672 
1673 	/* Setup Cipher Parameters */
1674 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1675 	ut_params->cipher_xform.next = &ut_params->auth_xform;
1676 
1677 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1678 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1679 	ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1680 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1681 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
1682 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1683 
1684 	/* Setup HMAC Parameters */
1685 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1686 
1687 	ut_params->auth_xform.next = NULL;
1688 
1689 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1690 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1691 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
1692 	ut_params->auth_xform.auth.key.data = hmac_sha1_key;
1693 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
1694 
1695 	ut_params->sess = rte_cryptodev_sym_session_create(
1696 			ts_params->session_mpool);
1697 
1698 	/* Create crypto session*/
1699 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
1700 			ut_params->sess, &ut_params->cipher_xform,
1701 			ts_params->session_priv_mpool);
1702 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1703 
1704 	/* Generate crypto op data structure */
1705 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1706 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1707 	TEST_ASSERT_NOT_NULL(ut_params->op,
1708 			"Failed to allocate symmetric crypto operation struct");
1709 
1710 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1711 
1712 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1713 
1714 	/* set crypto operation source mbuf */
1715 	sym_op->m_src = ut_params->ibuf;
1716 
1717 	/* Set crypto operation authentication parameters */
1718 	sym_op->auth.digest.data = ut_params->digest;
1719 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
1720 			ut_params->ibuf, QUOTE_512_BYTES);
1721 
1722 	sym_op->auth.data.offset = 0;
1723 	sym_op->auth.data.length = QUOTE_512_BYTES;
1724 
1725 	/* Copy IV at the end of the crypto operation */
1726 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
1727 			aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
1728 
1729 	/* Set crypto operation cipher parameters */
1730 	sym_op->cipher.data.offset = 0;
1731 	sym_op->cipher.data.length = QUOTE_512_BYTES;
1732 
1733 	/* Process crypto operation */
1734 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
1735 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
1736 			ut_params->op);
1737 	else
1738 		TEST_ASSERT_NOT_NULL(
1739 			process_crypto_request(ts_params->valid_devs[0],
1740 				ut_params->op),
1741 				"failed to process sym crypto op");
1742 
1743 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1744 			"crypto op processing failed");
1745 
1746 	/* Validate obuf */
1747 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
1748 			uint8_t *);
1749 
1750 	TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
1751 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1752 			QUOTE_512_BYTES,
1753 			"ciphertext data not as expected");
1754 
1755 	uint8_t *digest = ciphertext + QUOTE_512_BYTES;
1756 
1757 	TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
1758 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1759 			gbl_driver_id == rte_cryptodev_driver_id_get(
1760 					RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
1761 					TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
1762 					DIGEST_BYTE_LENGTH_SHA1,
1763 			"Generated digest data not as expected");
1764 
1765 	return TEST_SUCCESS;
1766 }
1767 
1768 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1769 
1770 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
1771 
1772 static uint8_t hmac_sha512_key[] = {
1773 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1774 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1775 	0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1776 	0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1777 	0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1778 	0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1779 	0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1780 	0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1781 
1782 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1783 	0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1784 	0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1785 	0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1786 	0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1787 	0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1788 	0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1789 	0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1790 	0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1791 
1792 
1793 
1794 static int
1795 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1796 		struct crypto_unittest_params *ut_params,
1797 		uint8_t *cipher_key,
1798 		uint8_t *hmac_key);
1799 
1800 static int
1801 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1802 		struct crypto_unittest_params *ut_params,
1803 		struct crypto_testsuite_params *ts_params,
1804 		const uint8_t *cipher,
1805 		const uint8_t *digest,
1806 		const uint8_t *iv);
1807 
1808 
1809 static int
1810 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1811 		struct crypto_unittest_params *ut_params,
1812 		uint8_t *cipher_key,
1813 		uint8_t *hmac_key)
1814 {
1815 
1816 	/* Setup Cipher Parameters */
1817 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1818 	ut_params->cipher_xform.next = NULL;
1819 
1820 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1821 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1822 	ut_params->cipher_xform.cipher.key.data = cipher_key;
1823 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1824 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
1825 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1826 
1827 	/* Setup HMAC Parameters */
1828 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1829 	ut_params->auth_xform.next = &ut_params->cipher_xform;
1830 
1831 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1832 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1833 	ut_params->auth_xform.auth.key.data = hmac_key;
1834 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1835 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1836 
1837 	return TEST_SUCCESS;
1838 }
1839 
1840 
1841 static int
1842 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1843 		struct crypto_unittest_params *ut_params,
1844 		struct crypto_testsuite_params *ts_params,
1845 		const uint8_t *cipher,
1846 		const uint8_t *digest,
1847 		const uint8_t *iv)
1848 {
1849 	/* Generate test mbuf data and digest */
1850 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1851 			(const char *)
1852 			cipher,
1853 			QUOTE_512_BYTES, 0);
1854 
1855 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1856 			DIGEST_BYTE_LENGTH_SHA512);
1857 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1858 
1859 	rte_memcpy(ut_params->digest,
1860 			digest,
1861 			DIGEST_BYTE_LENGTH_SHA512);
1862 
1863 	/* Generate Crypto op data structure */
1864 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1865 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1866 	TEST_ASSERT_NOT_NULL(ut_params->op,
1867 			"Failed to allocate symmetric crypto operation struct");
1868 
1869 	rte_crypto_op_attach_sym_session(ut_params->op, sess);
1870 
1871 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1872 
1873 	/* set crypto operation source mbuf */
1874 	sym_op->m_src = ut_params->ibuf;
1875 
1876 	sym_op->auth.digest.data = ut_params->digest;
1877 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
1878 			ut_params->ibuf, QUOTE_512_BYTES);
1879 
1880 	sym_op->auth.data.offset = 0;
1881 	sym_op->auth.data.length = QUOTE_512_BYTES;
1882 
1883 	/* Copy IV at the end of the crypto operation */
1884 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
1885 			iv, CIPHER_IV_LENGTH_AES_CBC);
1886 
1887 	sym_op->cipher.data.offset = 0;
1888 	sym_op->cipher.data.length = QUOTE_512_BYTES;
1889 
1890 	/* Process crypto operation */
1891 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
1892 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
1893 			ut_params->op);
1894 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
1895 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
1896 				ut_params->op, 1, 1, 0, 0);
1897 	else
1898 		TEST_ASSERT_NOT_NULL(
1899 				process_crypto_request(ts_params->valid_devs[0],
1900 					ut_params->op),
1901 					"failed to process sym crypto op");
1902 
1903 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1904 			"crypto op processing failed");
1905 
1906 	ut_params->obuf = ut_params->op->sym->m_src;
1907 
1908 	/* Validate obuf */
1909 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
1910 			rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
1911 			catch_22_quote,
1912 			QUOTE_512_BYTES,
1913 			"Plaintext data not as expected");
1914 
1915 	/* Validate obuf */
1916 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1917 			"Digest verification failed");
1918 
1919 	return TEST_SUCCESS;
1920 }
1921 
1922 static int
1923 test_blockcipher(enum blockcipher_test_type test_type)
1924 {
1925 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1926 	int status;
1927 
1928 	status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1929 		ts_params->op_mpool,
1930 		ts_params->session_mpool, ts_params->session_priv_mpool,
1931 		ts_params->valid_devs[0],
1932 		test_type);
1933 
1934 	if (status == -ENOTSUP)
1935 		return status;
1936 
1937 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1938 
1939 	return TEST_SUCCESS;
1940 }
1941 
1942 static int
1943 test_AES_cipheronly_all(void)
1944 {
1945 	return test_blockcipher(BLKCIPHER_AES_CIPHERONLY_TYPE);
1946 }
1947 
1948 static int
1949 test_AES_docsis_all(void)
1950 {
1951 	/* Data-path service does not support DOCSIS yet */
1952 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
1953 		return -ENOTSUP;
1954 	return test_blockcipher(BLKCIPHER_AES_DOCSIS_TYPE);
1955 }
1956 
1957 static int
1958 test_DES_docsis_all(void)
1959 {
1960 	/* Data-path service does not support DOCSIS yet */
1961 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
1962 		return -ENOTSUP;
1963 	return test_blockcipher(BLKCIPHER_DES_DOCSIS_TYPE);
1964 }
1965 
1966 static int
1967 test_DES_cipheronly_all(void)
1968 {
1969 	return test_blockcipher(BLKCIPHER_DES_CIPHERONLY_TYPE);
1970 }
1971 
1972 static int
1973 test_authonly_all(void)
1974 {
1975 	return test_blockcipher(BLKCIPHER_AUTHONLY_TYPE);
1976 }
1977 
1978 static int
1979 test_AES_chain_all(void)
1980 {
1981 	return test_blockcipher(BLKCIPHER_AES_CHAIN_TYPE);
1982 }
1983 
1984 static int
1985 test_3DES_chain_all(void)
1986 {
1987 	return test_blockcipher(BLKCIPHER_3DES_CHAIN_TYPE);
1988 }
1989 
1990 static int
1991 test_3DES_cipheronly_all(void)
1992 {
1993 	return test_blockcipher(BLKCIPHER_3DES_CIPHERONLY_TYPE);
1994 }
1995 
1996 /* ***** SNOW 3G Tests ***** */
1997 static int
1998 create_wireless_algo_hash_session(uint8_t dev_id,
1999 	const uint8_t *key, const uint8_t key_len,
2000 	const uint8_t iv_len, const uint8_t auth_len,
2001 	enum rte_crypto_auth_operation op,
2002 	enum rte_crypto_auth_algorithm algo)
2003 {
2004 	uint8_t hash_key[key_len];
2005 	int status;
2006 
2007 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2008 	struct crypto_unittest_params *ut_params = &unittest_params;
2009 
2010 	memcpy(hash_key, key, key_len);
2011 
2012 	debug_hexdump(stdout, "key:", key, key_len);
2013 
2014 	/* Setup Authentication Parameters */
2015 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2016 	ut_params->auth_xform.next = NULL;
2017 
2018 	ut_params->auth_xform.auth.op = op;
2019 	ut_params->auth_xform.auth.algo = algo;
2020 	ut_params->auth_xform.auth.key.length = key_len;
2021 	ut_params->auth_xform.auth.key.data = hash_key;
2022 	ut_params->auth_xform.auth.digest_length = auth_len;
2023 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2024 	ut_params->auth_xform.auth.iv.length = iv_len;
2025 	ut_params->sess = rte_cryptodev_sym_session_create(
2026 			ts_params->session_mpool);
2027 
2028 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2029 			&ut_params->auth_xform,
2030 			ts_params->session_priv_mpool);
2031 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2032 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2033 	return 0;
2034 }
2035 
2036 static int
2037 create_wireless_algo_cipher_session(uint8_t dev_id,
2038 			enum rte_crypto_cipher_operation op,
2039 			enum rte_crypto_cipher_algorithm algo,
2040 			const uint8_t *key, const uint8_t key_len,
2041 			uint8_t iv_len)
2042 {
2043 	uint8_t cipher_key[key_len];
2044 	int status;
2045 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2046 	struct crypto_unittest_params *ut_params = &unittest_params;
2047 
2048 	memcpy(cipher_key, key, key_len);
2049 
2050 	/* Setup Cipher Parameters */
2051 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2052 	ut_params->cipher_xform.next = NULL;
2053 
2054 	ut_params->cipher_xform.cipher.algo = algo;
2055 	ut_params->cipher_xform.cipher.op = op;
2056 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2057 	ut_params->cipher_xform.cipher.key.length = key_len;
2058 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2059 	ut_params->cipher_xform.cipher.iv.length = iv_len;
2060 
2061 	debug_hexdump(stdout, "key:", key, key_len);
2062 
2063 	/* Create Crypto session */
2064 	ut_params->sess = rte_cryptodev_sym_session_create(
2065 			ts_params->session_mpool);
2066 
2067 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2068 			&ut_params->cipher_xform,
2069 			ts_params->session_priv_mpool);
2070 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2071 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2072 	return 0;
2073 }
2074 
2075 static int
2076 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2077 			unsigned int cipher_len,
2078 			unsigned int cipher_offset)
2079 {
2080 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2081 	struct crypto_unittest_params *ut_params = &unittest_params;
2082 
2083 	/* Generate Crypto op data structure */
2084 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2085 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2086 	TEST_ASSERT_NOT_NULL(ut_params->op,
2087 				"Failed to allocate pktmbuf offload");
2088 
2089 	/* Set crypto operation data parameters */
2090 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2091 
2092 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2093 
2094 	/* set crypto operation source mbuf */
2095 	sym_op->m_src = ut_params->ibuf;
2096 
2097 	/* iv */
2098 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2099 			iv, iv_len);
2100 	sym_op->cipher.data.length = cipher_len;
2101 	sym_op->cipher.data.offset = cipher_offset;
2102 	return 0;
2103 }
2104 
2105 static int
2106 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2107 			unsigned int cipher_len,
2108 			unsigned int cipher_offset)
2109 {
2110 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2111 	struct crypto_unittest_params *ut_params = &unittest_params;
2112 
2113 	/* Generate Crypto op data structure */
2114 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2115 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2116 	TEST_ASSERT_NOT_NULL(ut_params->op,
2117 				"Failed to allocate pktmbuf offload");
2118 
2119 	/* Set crypto operation data parameters */
2120 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2121 
2122 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2123 
2124 	/* set crypto operation source mbuf */
2125 	sym_op->m_src = ut_params->ibuf;
2126 	sym_op->m_dst = ut_params->obuf;
2127 
2128 	/* iv */
2129 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2130 			iv, iv_len);
2131 	sym_op->cipher.data.length = cipher_len;
2132 	sym_op->cipher.data.offset = cipher_offset;
2133 	return 0;
2134 }
2135 
2136 static int
2137 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2138 		enum rte_crypto_cipher_operation cipher_op,
2139 		enum rte_crypto_auth_operation auth_op,
2140 		enum rte_crypto_auth_algorithm auth_algo,
2141 		enum rte_crypto_cipher_algorithm cipher_algo,
2142 		const uint8_t *key, uint8_t key_len,
2143 		uint8_t auth_iv_len, uint8_t auth_len,
2144 		uint8_t cipher_iv_len)
2145 
2146 {
2147 	uint8_t cipher_auth_key[key_len];
2148 	int status;
2149 
2150 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2151 	struct crypto_unittest_params *ut_params = &unittest_params;
2152 
2153 	memcpy(cipher_auth_key, key, key_len);
2154 
2155 	/* Setup Authentication Parameters */
2156 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2157 	ut_params->auth_xform.next = NULL;
2158 
2159 	ut_params->auth_xform.auth.op = auth_op;
2160 	ut_params->auth_xform.auth.algo = auth_algo;
2161 	ut_params->auth_xform.auth.key.length = key_len;
2162 	/* Hash key = cipher key */
2163 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2164 	ut_params->auth_xform.auth.digest_length = auth_len;
2165 	/* Auth IV will be after cipher IV */
2166 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2167 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2168 
2169 	/* Setup Cipher Parameters */
2170 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2171 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2172 
2173 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2174 	ut_params->cipher_xform.cipher.op = cipher_op;
2175 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2176 	ut_params->cipher_xform.cipher.key.length = key_len;
2177 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2178 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2179 
2180 	debug_hexdump(stdout, "key:", key, key_len);
2181 
2182 	/* Create Crypto session*/
2183 	ut_params->sess = rte_cryptodev_sym_session_create(
2184 			ts_params->session_mpool);
2185 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2186 
2187 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2188 			&ut_params->cipher_xform,
2189 			ts_params->session_priv_mpool);
2190 	if (status == -ENOTSUP)
2191 		return status;
2192 
2193 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2194 	return 0;
2195 }
2196 
2197 static int
2198 create_wireless_cipher_auth_session(uint8_t dev_id,
2199 		enum rte_crypto_cipher_operation cipher_op,
2200 		enum rte_crypto_auth_operation auth_op,
2201 		enum rte_crypto_auth_algorithm auth_algo,
2202 		enum rte_crypto_cipher_algorithm cipher_algo,
2203 		const struct wireless_test_data *tdata)
2204 {
2205 	const uint8_t key_len = tdata->key.len;
2206 	uint8_t cipher_auth_key[key_len];
2207 	int status;
2208 
2209 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2210 	struct crypto_unittest_params *ut_params = &unittest_params;
2211 	const uint8_t *key = tdata->key.data;
2212 	const uint8_t auth_len = tdata->digest.len;
2213 	uint8_t cipher_iv_len = tdata->cipher_iv.len;
2214 	uint8_t auth_iv_len = tdata->auth_iv.len;
2215 
2216 	memcpy(cipher_auth_key, key, key_len);
2217 
2218 	/* Setup Authentication Parameters */
2219 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2220 	ut_params->auth_xform.next = NULL;
2221 
2222 	ut_params->auth_xform.auth.op = auth_op;
2223 	ut_params->auth_xform.auth.algo = auth_algo;
2224 	ut_params->auth_xform.auth.key.length = key_len;
2225 	/* Hash key = cipher key */
2226 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2227 	ut_params->auth_xform.auth.digest_length = auth_len;
2228 	/* Auth IV will be after cipher IV */
2229 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2230 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2231 
2232 	/* Setup Cipher Parameters */
2233 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2234 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2235 
2236 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2237 	ut_params->cipher_xform.cipher.op = cipher_op;
2238 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2239 	ut_params->cipher_xform.cipher.key.length = key_len;
2240 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2241 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2242 
2243 
2244 	debug_hexdump(stdout, "key:", key, key_len);
2245 
2246 	/* Create Crypto session*/
2247 	ut_params->sess = rte_cryptodev_sym_session_create(
2248 			ts_params->session_mpool);
2249 
2250 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2251 			&ut_params->cipher_xform,
2252 			ts_params->session_priv_mpool);
2253 	if (status == -ENOTSUP)
2254 		return status;
2255 
2256 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2257 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2258 	return 0;
2259 }
2260 
2261 static int
2262 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2263 		const struct wireless_test_data *tdata)
2264 {
2265 	return create_wireless_cipher_auth_session(dev_id,
2266 		RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2267 		RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2268 		RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2269 }
2270 
2271 static int
2272 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2273 		enum rte_crypto_cipher_operation cipher_op,
2274 		enum rte_crypto_auth_operation auth_op,
2275 		enum rte_crypto_auth_algorithm auth_algo,
2276 		enum rte_crypto_cipher_algorithm cipher_algo,
2277 		const uint8_t *key, const uint8_t key_len,
2278 		uint8_t auth_iv_len, uint8_t auth_len,
2279 		uint8_t cipher_iv_len)
2280 {
2281 	uint8_t auth_cipher_key[key_len];
2282 	int status;
2283 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2284 	struct crypto_unittest_params *ut_params = &unittest_params;
2285 
2286 	memcpy(auth_cipher_key, key, key_len);
2287 
2288 	/* Setup Authentication Parameters */
2289 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2290 	ut_params->auth_xform.auth.op = auth_op;
2291 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2292 	ut_params->auth_xform.auth.algo = auth_algo;
2293 	ut_params->auth_xform.auth.key.length = key_len;
2294 	ut_params->auth_xform.auth.key.data = auth_cipher_key;
2295 	ut_params->auth_xform.auth.digest_length = auth_len;
2296 	/* Auth IV will be after cipher IV */
2297 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2298 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2299 
2300 	/* Setup Cipher Parameters */
2301 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2302 	ut_params->cipher_xform.next = NULL;
2303 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2304 	ut_params->cipher_xform.cipher.op = cipher_op;
2305 	ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2306 	ut_params->cipher_xform.cipher.key.length = key_len;
2307 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2308 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2309 
2310 	debug_hexdump(stdout, "key:", key, key_len);
2311 
2312 	/* Create Crypto session*/
2313 	ut_params->sess = rte_cryptodev_sym_session_create(
2314 			ts_params->session_mpool);
2315 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2316 
2317 	if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2318 		ut_params->auth_xform.next = NULL;
2319 		ut_params->cipher_xform.next = &ut_params->auth_xform;
2320 		status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2321 				&ut_params->cipher_xform,
2322 				ts_params->session_priv_mpool);
2323 
2324 	} else
2325 		status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2326 				&ut_params->auth_xform,
2327 				ts_params->session_priv_mpool);
2328 
2329 	if (status == -ENOTSUP)
2330 		return status;
2331 
2332 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2333 
2334 	return 0;
2335 }
2336 
2337 static int
2338 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2339 		unsigned int auth_tag_len,
2340 		const uint8_t *iv, unsigned int iv_len,
2341 		unsigned int data_pad_len,
2342 		enum rte_crypto_auth_operation op,
2343 		unsigned int auth_len, unsigned int auth_offset)
2344 {
2345 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2346 
2347 	struct crypto_unittest_params *ut_params = &unittest_params;
2348 
2349 	/* Generate Crypto op data structure */
2350 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2351 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2352 	TEST_ASSERT_NOT_NULL(ut_params->op,
2353 		"Failed to allocate pktmbuf offload");
2354 
2355 	/* Set crypto operation data parameters */
2356 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2357 
2358 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2359 
2360 	/* set crypto operation source mbuf */
2361 	sym_op->m_src = ut_params->ibuf;
2362 
2363 	/* iv */
2364 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2365 			iv, iv_len);
2366 	/* digest */
2367 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2368 					ut_params->ibuf, auth_tag_len);
2369 
2370 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2371 				"no room to append auth tag");
2372 	ut_params->digest = sym_op->auth.digest.data;
2373 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2374 			ut_params->ibuf, data_pad_len);
2375 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2376 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2377 	else
2378 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2379 
2380 	debug_hexdump(stdout, "digest:",
2381 		sym_op->auth.digest.data,
2382 		auth_tag_len);
2383 
2384 	sym_op->auth.data.length = auth_len;
2385 	sym_op->auth.data.offset = auth_offset;
2386 
2387 	return 0;
2388 }
2389 
2390 static int
2391 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2392 	enum rte_crypto_auth_operation op)
2393 {
2394 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2395 	struct crypto_unittest_params *ut_params = &unittest_params;
2396 
2397 	const uint8_t *auth_tag = tdata->digest.data;
2398 	const unsigned int auth_tag_len = tdata->digest.len;
2399 	unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2400 	unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2401 
2402 	const uint8_t *cipher_iv = tdata->cipher_iv.data;
2403 	const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2404 	const uint8_t *auth_iv = tdata->auth_iv.data;
2405 	const uint8_t auth_iv_len = tdata->auth_iv.len;
2406 	const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2407 	const unsigned int auth_len = tdata->validAuthLenInBits.len;
2408 
2409 	/* Generate Crypto op data structure */
2410 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2411 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2412 	TEST_ASSERT_NOT_NULL(ut_params->op,
2413 			"Failed to allocate pktmbuf offload");
2414 	/* Set crypto operation data parameters */
2415 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2416 
2417 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2418 
2419 	/* set crypto operation source mbuf */
2420 	sym_op->m_src = ut_params->ibuf;
2421 
2422 	/* digest */
2423 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2424 			ut_params->ibuf, auth_tag_len);
2425 
2426 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2427 			"no room to append auth tag");
2428 	ut_params->digest = sym_op->auth.digest.data;
2429 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2430 			ut_params->ibuf, data_pad_len);
2431 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2432 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2433 	else
2434 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2435 
2436 	debug_hexdump(stdout, "digest:",
2437 		sym_op->auth.digest.data,
2438 		auth_tag_len);
2439 
2440 	/* Copy cipher and auth IVs at the end of the crypto operation */
2441 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2442 						IV_OFFSET);
2443 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2444 	iv_ptr += cipher_iv_len;
2445 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2446 
2447 	sym_op->cipher.data.length = cipher_len;
2448 	sym_op->cipher.data.offset = 0;
2449 	sym_op->auth.data.length = auth_len;
2450 	sym_op->auth.data.offset = 0;
2451 
2452 	return 0;
2453 }
2454 
2455 static int
2456 create_zuc_cipher_hash_generate_operation(
2457 		const struct wireless_test_data *tdata)
2458 {
2459 	return create_wireless_cipher_hash_operation(tdata,
2460 		RTE_CRYPTO_AUTH_OP_GENERATE);
2461 }
2462 
2463 static int
2464 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2465 		const unsigned auth_tag_len,
2466 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2467 		unsigned data_pad_len,
2468 		enum rte_crypto_auth_operation op,
2469 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2470 		const unsigned cipher_len, const unsigned cipher_offset,
2471 		const unsigned auth_len, const unsigned auth_offset)
2472 {
2473 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2474 	struct crypto_unittest_params *ut_params = &unittest_params;
2475 
2476 	enum rte_crypto_cipher_algorithm cipher_algo =
2477 			ut_params->cipher_xform.cipher.algo;
2478 	enum rte_crypto_auth_algorithm auth_algo =
2479 			ut_params->auth_xform.auth.algo;
2480 
2481 	/* Generate Crypto op data structure */
2482 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2483 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2484 	TEST_ASSERT_NOT_NULL(ut_params->op,
2485 			"Failed to allocate pktmbuf offload");
2486 	/* Set crypto operation data parameters */
2487 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2488 
2489 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2490 
2491 	/* set crypto operation source mbuf */
2492 	sym_op->m_src = ut_params->ibuf;
2493 
2494 	/* digest */
2495 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2496 			ut_params->ibuf, auth_tag_len);
2497 
2498 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2499 			"no room to append auth tag");
2500 	ut_params->digest = sym_op->auth.digest.data;
2501 
2502 	if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2503 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2504 				ut_params->ibuf, data_pad_len);
2505 	} else {
2506 		struct rte_mbuf *m = ut_params->ibuf;
2507 		unsigned int offset = data_pad_len;
2508 
2509 		while (offset > m->data_len && m->next != NULL) {
2510 			offset -= m->data_len;
2511 			m = m->next;
2512 		}
2513 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2514 			m, offset);
2515 	}
2516 
2517 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2518 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2519 	else
2520 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2521 
2522 	debug_hexdump(stdout, "digest:",
2523 		sym_op->auth.digest.data,
2524 		auth_tag_len);
2525 
2526 	/* Copy cipher and auth IVs at the end of the crypto operation */
2527 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2528 						IV_OFFSET);
2529 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2530 	iv_ptr += cipher_iv_len;
2531 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2532 
2533 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2534 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2535 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2536 		sym_op->cipher.data.length = cipher_len;
2537 		sym_op->cipher.data.offset = cipher_offset;
2538 	} else {
2539 		sym_op->cipher.data.length = cipher_len >> 3;
2540 		sym_op->cipher.data.offset = cipher_offset >> 3;
2541 	}
2542 
2543 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2544 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2545 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2546 		sym_op->auth.data.length = auth_len;
2547 		sym_op->auth.data.offset = auth_offset;
2548 	} else {
2549 		sym_op->auth.data.length = auth_len >> 3;
2550 		sym_op->auth.data.offset = auth_offset >> 3;
2551 	}
2552 
2553 	return 0;
2554 }
2555 
2556 static int
2557 create_wireless_algo_auth_cipher_operation(
2558 		const uint8_t *auth_tag, unsigned int auth_tag_len,
2559 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2560 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2561 		unsigned int data_pad_len,
2562 		unsigned int cipher_len, unsigned int cipher_offset,
2563 		unsigned int auth_len, unsigned int auth_offset,
2564 		uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2565 {
2566 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2567 	struct crypto_unittest_params *ut_params = &unittest_params;
2568 
2569 	enum rte_crypto_cipher_algorithm cipher_algo =
2570 			ut_params->cipher_xform.cipher.algo;
2571 	enum rte_crypto_auth_algorithm auth_algo =
2572 			ut_params->auth_xform.auth.algo;
2573 
2574 	/* Generate Crypto op data structure */
2575 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2576 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2577 	TEST_ASSERT_NOT_NULL(ut_params->op,
2578 			"Failed to allocate pktmbuf offload");
2579 
2580 	/* Set crypto operation data parameters */
2581 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2582 
2583 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2584 
2585 	/* set crypto operation mbufs */
2586 	sym_op->m_src = ut_params->ibuf;
2587 	if (op_mode == OUT_OF_PLACE)
2588 		sym_op->m_dst = ut_params->obuf;
2589 
2590 	/* digest */
2591 	if (!do_sgl) {
2592 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
2593 			(op_mode == IN_PLACE ?
2594 				ut_params->ibuf : ut_params->obuf),
2595 			uint8_t *, data_pad_len);
2596 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2597 			(op_mode == IN_PLACE ?
2598 				ut_params->ibuf : ut_params->obuf),
2599 			data_pad_len);
2600 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2601 	} else {
2602 		uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
2603 		struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
2604 				sym_op->m_src : sym_op->m_dst);
2605 		while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
2606 			remaining_off -= rte_pktmbuf_data_len(sgl_buf);
2607 			sgl_buf = sgl_buf->next;
2608 		}
2609 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
2610 				uint8_t *, remaining_off);
2611 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
2612 				remaining_off);
2613 		memset(sym_op->auth.digest.data, 0, remaining_off);
2614 		while (sgl_buf->next != NULL) {
2615 			memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
2616 				0, rte_pktmbuf_data_len(sgl_buf));
2617 			sgl_buf = sgl_buf->next;
2618 		}
2619 	}
2620 
2621 	/* Copy digest for the verification */
2622 	if (verify)
2623 		memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2624 
2625 	/* Copy cipher and auth IVs at the end of the crypto operation */
2626 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
2627 			ut_params->op, uint8_t *, IV_OFFSET);
2628 
2629 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2630 	iv_ptr += cipher_iv_len;
2631 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2632 
2633 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2634 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2635 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2636 		sym_op->cipher.data.length = cipher_len;
2637 		sym_op->cipher.data.offset = cipher_offset;
2638 	} else {
2639 		sym_op->cipher.data.length = cipher_len >> 3;
2640 		sym_op->cipher.data.offset = cipher_offset >> 3;
2641 	}
2642 
2643 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2644 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2645 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2646 		sym_op->auth.data.length = auth_len;
2647 		sym_op->auth.data.offset = auth_offset;
2648 	} else {
2649 		sym_op->auth.data.length = auth_len >> 3;
2650 		sym_op->auth.data.offset = auth_offset >> 3;
2651 	}
2652 
2653 	return 0;
2654 }
2655 
2656 static int
2657 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2658 {
2659 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2660 	struct crypto_unittest_params *ut_params = &unittest_params;
2661 
2662 	int retval;
2663 	unsigned plaintext_pad_len;
2664 	unsigned plaintext_len;
2665 	uint8_t *plaintext;
2666 	struct rte_cryptodev_info dev_info;
2667 
2668 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2669 	uint64_t feat_flags = dev_info.feature_flags;
2670 
2671 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
2672 			((tdata->validAuthLenInBits.len % 8) != 0)) {
2673 		printf("Device doesn't support NON-Byte Aligned Data.\n");
2674 		return -ENOTSUP;
2675 	}
2676 
2677 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
2678 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
2679 		printf("Device doesn't support RAW data-path APIs.\n");
2680 		return -ENOTSUP;
2681 	}
2682 
2683 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2684 		return -ENOTSUP;
2685 
2686 	/* Verify the capabilities */
2687 	struct rte_cryptodev_sym_capability_idx cap_idx;
2688 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2689 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2690 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2691 			&cap_idx) == NULL)
2692 		return -ENOTSUP;
2693 
2694 	/* Create SNOW 3G session */
2695 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2696 			tdata->key.data, tdata->key.len,
2697 			tdata->auth_iv.len, tdata->digest.len,
2698 			RTE_CRYPTO_AUTH_OP_GENERATE,
2699 			RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2700 	if (retval < 0)
2701 		return retval;
2702 
2703 	/* alloc mbuf and set payload */
2704 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2705 
2706 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2707 	rte_pktmbuf_tailroom(ut_params->ibuf));
2708 
2709 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
2710 	/* Append data which is padded to a multiple of */
2711 	/* the algorithms block size */
2712 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2713 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2714 				plaintext_pad_len);
2715 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2716 
2717 	/* Create SNOW 3G operation */
2718 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2719 			tdata->auth_iv.data, tdata->auth_iv.len,
2720 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2721 			tdata->validAuthLenInBits.len,
2722 			0);
2723 	if (retval < 0)
2724 		return retval;
2725 
2726 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2727 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2728 				ut_params->op, 0, 1, 1, 0);
2729 	else
2730 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2731 				ut_params->op);
2732 	ut_params->obuf = ut_params->op->sym->m_src;
2733 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2734 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2735 			+ plaintext_pad_len;
2736 
2737 	/* Validate obuf */
2738 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
2739 	ut_params->digest,
2740 	tdata->digest.data,
2741 	DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2742 	"SNOW 3G Generated auth tag not as expected");
2743 
2744 	return 0;
2745 }
2746 
2747 static int
2748 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
2749 {
2750 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2751 	struct crypto_unittest_params *ut_params = &unittest_params;
2752 
2753 	int retval;
2754 	unsigned plaintext_pad_len;
2755 	unsigned plaintext_len;
2756 	uint8_t *plaintext;
2757 	struct rte_cryptodev_info dev_info;
2758 
2759 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2760 	uint64_t feat_flags = dev_info.feature_flags;
2761 
2762 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
2763 			((tdata->validAuthLenInBits.len % 8) != 0)) {
2764 		printf("Device doesn't support NON-Byte Aligned Data.\n");
2765 		return -ENOTSUP;
2766 	}
2767 
2768 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
2769 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
2770 		printf("Device doesn't support RAW data-path APIs.\n");
2771 		return -ENOTSUP;
2772 	}
2773 
2774 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2775 		return -ENOTSUP;
2776 
2777 	/* Verify the capabilities */
2778 	struct rte_cryptodev_sym_capability_idx cap_idx;
2779 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2780 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2781 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2782 			&cap_idx) == NULL)
2783 		return -ENOTSUP;
2784 
2785 	/* Create SNOW 3G session */
2786 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2787 				tdata->key.data, tdata->key.len,
2788 				tdata->auth_iv.len, tdata->digest.len,
2789 				RTE_CRYPTO_AUTH_OP_VERIFY,
2790 				RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2791 	if (retval < 0)
2792 		return retval;
2793 	/* alloc mbuf and set payload */
2794 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2795 
2796 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2797 	rte_pktmbuf_tailroom(ut_params->ibuf));
2798 
2799 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
2800 	/* Append data which is padded to a multiple of */
2801 	/* the algorithms block size */
2802 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2803 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2804 				plaintext_pad_len);
2805 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2806 
2807 	/* Create SNOW 3G operation */
2808 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
2809 			tdata->digest.len,
2810 			tdata->auth_iv.data, tdata->auth_iv.len,
2811 			plaintext_pad_len,
2812 			RTE_CRYPTO_AUTH_OP_VERIFY,
2813 			tdata->validAuthLenInBits.len,
2814 			0);
2815 	if (retval < 0)
2816 		return retval;
2817 
2818 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2819 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2820 				ut_params->op, 0, 1, 1, 0);
2821 	else
2822 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2823 				ut_params->op);
2824 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2825 	ut_params->obuf = ut_params->op->sym->m_src;
2826 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2827 				+ plaintext_pad_len;
2828 
2829 	/* Validate obuf */
2830 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2831 		return 0;
2832 	else
2833 		return -1;
2834 
2835 	return 0;
2836 }
2837 
2838 static int
2839 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
2840 {
2841 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2842 	struct crypto_unittest_params *ut_params = &unittest_params;
2843 
2844 	int retval;
2845 	unsigned plaintext_pad_len;
2846 	unsigned plaintext_len;
2847 	uint8_t *plaintext;
2848 	struct rte_cryptodev_info dev_info;
2849 
2850 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2851 	uint64_t feat_flags = dev_info.feature_flags;
2852 
2853 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
2854 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
2855 		printf("Device doesn't support RAW data-path APIs.\n");
2856 		return -ENOTSUP;
2857 	}
2858 
2859 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2860 		return -ENOTSUP;
2861 
2862 	/* Verify the capabilities */
2863 	struct rte_cryptodev_sym_capability_idx cap_idx;
2864 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2865 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
2866 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2867 			&cap_idx) == NULL)
2868 		return -ENOTSUP;
2869 
2870 	/* Create KASUMI session */
2871 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2872 			tdata->key.data, tdata->key.len,
2873 			0, tdata->digest.len,
2874 			RTE_CRYPTO_AUTH_OP_GENERATE,
2875 			RTE_CRYPTO_AUTH_KASUMI_F9);
2876 	if (retval < 0)
2877 		return retval;
2878 
2879 	/* alloc mbuf and set payload */
2880 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2881 
2882 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2883 	rte_pktmbuf_tailroom(ut_params->ibuf));
2884 
2885 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
2886 	/* Append data which is padded to a multiple of */
2887 	/* the algorithms block size */
2888 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2889 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2890 				plaintext_pad_len);
2891 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2892 
2893 	/* Create KASUMI operation */
2894 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2895 			NULL, 0,
2896 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2897 			tdata->plaintext.len,
2898 			0);
2899 	if (retval < 0)
2900 		return retval;
2901 
2902 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2903 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2904 			ut_params->op);
2905 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2906 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2907 				ut_params->op, 0, 1, 1, 0);
2908 	else
2909 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2910 			ut_params->op);
2911 
2912 	ut_params->obuf = ut_params->op->sym->m_src;
2913 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2914 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2915 			+ plaintext_pad_len;
2916 
2917 	/* Validate obuf */
2918 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
2919 	ut_params->digest,
2920 	tdata->digest.data,
2921 	DIGEST_BYTE_LENGTH_KASUMI_F9,
2922 	"KASUMI Generated auth tag not as expected");
2923 
2924 	return 0;
2925 }
2926 
2927 static int
2928 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
2929 {
2930 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2931 	struct crypto_unittest_params *ut_params = &unittest_params;
2932 
2933 	int retval;
2934 	unsigned plaintext_pad_len;
2935 	unsigned plaintext_len;
2936 	uint8_t *plaintext;
2937 	struct rte_cryptodev_info dev_info;
2938 
2939 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2940 	uint64_t feat_flags = dev_info.feature_flags;
2941 
2942 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
2943 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
2944 		printf("Device doesn't support RAW data-path APIs.\n");
2945 		return -ENOTSUP;
2946 	}
2947 
2948 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2949 		return -ENOTSUP;
2950 
2951 	/* Verify the capabilities */
2952 	struct rte_cryptodev_sym_capability_idx cap_idx;
2953 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2954 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
2955 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2956 			&cap_idx) == NULL)
2957 		return -ENOTSUP;
2958 
2959 	/* Create KASUMI session */
2960 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2961 				tdata->key.data, tdata->key.len,
2962 				0, tdata->digest.len,
2963 				RTE_CRYPTO_AUTH_OP_VERIFY,
2964 				RTE_CRYPTO_AUTH_KASUMI_F9);
2965 	if (retval < 0)
2966 		return retval;
2967 	/* alloc mbuf and set payload */
2968 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2969 
2970 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2971 	rte_pktmbuf_tailroom(ut_params->ibuf));
2972 
2973 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
2974 	/* Append data which is padded to a multiple */
2975 	/* of the algorithms block size */
2976 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2977 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2978 				plaintext_pad_len);
2979 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2980 
2981 	/* Create KASUMI operation */
2982 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
2983 			tdata->digest.len,
2984 			NULL, 0,
2985 			plaintext_pad_len,
2986 			RTE_CRYPTO_AUTH_OP_VERIFY,
2987 			tdata->plaintext.len,
2988 			0);
2989 	if (retval < 0)
2990 		return retval;
2991 
2992 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2993 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2994 				ut_params->op, 0, 1, 1, 0);
2995 	else
2996 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2997 				ut_params->op);
2998 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2999 	ut_params->obuf = ut_params->op->sym->m_src;
3000 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3001 				+ plaintext_pad_len;
3002 
3003 	/* Validate obuf */
3004 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3005 		return 0;
3006 	else
3007 		return -1;
3008 
3009 	return 0;
3010 }
3011 
3012 static int
3013 test_snow3g_hash_generate_test_case_1(void)
3014 {
3015 	return test_snow3g_authentication(&snow3g_hash_test_case_1);
3016 }
3017 
3018 static int
3019 test_snow3g_hash_generate_test_case_2(void)
3020 {
3021 	return test_snow3g_authentication(&snow3g_hash_test_case_2);
3022 }
3023 
3024 static int
3025 test_snow3g_hash_generate_test_case_3(void)
3026 {
3027 	return test_snow3g_authentication(&snow3g_hash_test_case_3);
3028 }
3029 
3030 static int
3031 test_snow3g_hash_generate_test_case_4(void)
3032 {
3033 	return test_snow3g_authentication(&snow3g_hash_test_case_4);
3034 }
3035 
3036 static int
3037 test_snow3g_hash_generate_test_case_5(void)
3038 {
3039 	return test_snow3g_authentication(&snow3g_hash_test_case_5);
3040 }
3041 
3042 static int
3043 test_snow3g_hash_generate_test_case_6(void)
3044 {
3045 	return test_snow3g_authentication(&snow3g_hash_test_case_6);
3046 }
3047 
3048 static int
3049 test_snow3g_hash_verify_test_case_1(void)
3050 {
3051 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3052 
3053 }
3054 
3055 static int
3056 test_snow3g_hash_verify_test_case_2(void)
3057 {
3058 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3059 }
3060 
3061 static int
3062 test_snow3g_hash_verify_test_case_3(void)
3063 {
3064 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3065 }
3066 
3067 static int
3068 test_snow3g_hash_verify_test_case_4(void)
3069 {
3070 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3071 }
3072 
3073 static int
3074 test_snow3g_hash_verify_test_case_5(void)
3075 {
3076 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3077 }
3078 
3079 static int
3080 test_snow3g_hash_verify_test_case_6(void)
3081 {
3082 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3083 }
3084 
3085 static int
3086 test_kasumi_hash_generate_test_case_1(void)
3087 {
3088 	return test_kasumi_authentication(&kasumi_hash_test_case_1);
3089 }
3090 
3091 static int
3092 test_kasumi_hash_generate_test_case_2(void)
3093 {
3094 	return test_kasumi_authentication(&kasumi_hash_test_case_2);
3095 }
3096 
3097 static int
3098 test_kasumi_hash_generate_test_case_3(void)
3099 {
3100 	return test_kasumi_authentication(&kasumi_hash_test_case_3);
3101 }
3102 
3103 static int
3104 test_kasumi_hash_generate_test_case_4(void)
3105 {
3106 	return test_kasumi_authentication(&kasumi_hash_test_case_4);
3107 }
3108 
3109 static int
3110 test_kasumi_hash_generate_test_case_5(void)
3111 {
3112 	return test_kasumi_authentication(&kasumi_hash_test_case_5);
3113 }
3114 
3115 static int
3116 test_kasumi_hash_generate_test_case_6(void)
3117 {
3118 	return test_kasumi_authentication(&kasumi_hash_test_case_6);
3119 }
3120 
3121 static int
3122 test_kasumi_hash_verify_test_case_1(void)
3123 {
3124 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3125 }
3126 
3127 static int
3128 test_kasumi_hash_verify_test_case_2(void)
3129 {
3130 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3131 }
3132 
3133 static int
3134 test_kasumi_hash_verify_test_case_3(void)
3135 {
3136 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3137 }
3138 
3139 static int
3140 test_kasumi_hash_verify_test_case_4(void)
3141 {
3142 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3143 }
3144 
3145 static int
3146 test_kasumi_hash_verify_test_case_5(void)
3147 {
3148 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3149 }
3150 
3151 static int
3152 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3153 {
3154 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3155 	struct crypto_unittest_params *ut_params = &unittest_params;
3156 
3157 	int retval;
3158 	uint8_t *plaintext, *ciphertext;
3159 	unsigned plaintext_pad_len;
3160 	unsigned plaintext_len;
3161 	struct rte_cryptodev_info dev_info;
3162 
3163 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3164 	uint64_t feat_flags = dev_info.feature_flags;
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 -ENOTSUP;
3170 	}
3171 
3172 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3173 		return -ENOTSUP;
3174 
3175 	/* Verify the capabilities */
3176 	struct rte_cryptodev_sym_capability_idx cap_idx;
3177 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3178 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3179 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3180 			&cap_idx) == NULL)
3181 		return -ENOTSUP;
3182 
3183 	/* Create KASUMI session */
3184 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3185 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3186 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3187 					tdata->key.data, tdata->key.len,
3188 					tdata->cipher_iv.len);
3189 	if (retval < 0)
3190 		return retval;
3191 
3192 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3193 
3194 	/* Clear mbuf payload */
3195 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3196 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3197 
3198 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3199 	/* Append data which is padded to a multiple */
3200 	/* of the algorithms block size */
3201 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3202 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3203 				plaintext_pad_len);
3204 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3205 
3206 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3207 
3208 	/* Create KASUMI operation */
3209 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3210 				tdata->cipher_iv.len,
3211 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3212 				tdata->validCipherOffsetInBits.len);
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, 1, 0, 1, tdata->cipher_iv.len);
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 
3224 	ut_params->obuf = ut_params->op->sym->m_dst;
3225 	if (ut_params->obuf)
3226 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3227 	else
3228 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3229 
3230 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3231 
3232 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3233 				(tdata->validCipherOffsetInBits.len >> 3);
3234 	/* Validate obuf */
3235 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3236 		ciphertext,
3237 		reference_ciphertext,
3238 		tdata->validCipherLenInBits.len,
3239 		"KASUMI Ciphertext data not as expected");
3240 	return 0;
3241 }
3242 
3243 static int
3244 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3245 {
3246 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3247 	struct crypto_unittest_params *ut_params = &unittest_params;
3248 
3249 	int retval;
3250 
3251 	unsigned int plaintext_pad_len;
3252 	unsigned int plaintext_len;
3253 
3254 	uint8_t buffer[10000];
3255 	const uint8_t *ciphertext;
3256 
3257 	struct rte_cryptodev_info dev_info;
3258 
3259 	/* Verify the capabilities */
3260 	struct rte_cryptodev_sym_capability_idx cap_idx;
3261 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3262 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3263 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3264 			&cap_idx) == NULL)
3265 		return -ENOTSUP;
3266 
3267 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3268 
3269 	uint64_t feat_flags = dev_info.feature_flags;
3270 
3271 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3272 		printf("Device doesn't support in-place scatter-gather. "
3273 				"Test Skipped.\n");
3274 		return -ENOTSUP;
3275 	}
3276 
3277 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3278 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3279 		printf("Device doesn't support RAW data-path APIs.\n");
3280 		return -ENOTSUP;
3281 	}
3282 
3283 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3284 		return -ENOTSUP;
3285 
3286 	/* Create KASUMI session */
3287 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3288 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3289 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3290 					tdata->key.data, tdata->key.len,
3291 					tdata->cipher_iv.len);
3292 	if (retval < 0)
3293 		return retval;
3294 
3295 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3296 
3297 
3298 	/* Append data which is padded to a multiple */
3299 	/* of the algorithms block size */
3300 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3301 
3302 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3303 			plaintext_pad_len, 10, 0);
3304 
3305 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3306 
3307 	/* Create KASUMI operation */
3308 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3309 				tdata->cipher_iv.len,
3310 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3311 				tdata->validCipherOffsetInBits.len);
3312 	if (retval < 0)
3313 		return retval;
3314 
3315 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3316 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3317 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3318 	else
3319 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3320 						ut_params->op);
3321 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3322 
3323 	ut_params->obuf = ut_params->op->sym->m_dst;
3324 
3325 	if (ut_params->obuf)
3326 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3327 				plaintext_len, buffer);
3328 	else
3329 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3330 				tdata->validCipherOffsetInBits.len >> 3,
3331 				plaintext_len, buffer);
3332 
3333 	/* Validate obuf */
3334 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3335 
3336 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3337 				(tdata->validCipherOffsetInBits.len >> 3);
3338 	/* Validate obuf */
3339 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3340 		ciphertext,
3341 		reference_ciphertext,
3342 		tdata->validCipherLenInBits.len,
3343 		"KASUMI Ciphertext data not as expected");
3344 	return 0;
3345 }
3346 
3347 static int
3348 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3349 {
3350 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3351 	struct crypto_unittest_params *ut_params = &unittest_params;
3352 
3353 	int retval;
3354 	uint8_t *plaintext, *ciphertext;
3355 	unsigned plaintext_pad_len;
3356 	unsigned plaintext_len;
3357 
3358 	/* Verify the capabilities */
3359 	struct rte_cryptodev_sym_capability_idx cap_idx;
3360 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3361 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3362 	/* Data-path service does not support OOP */
3363 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3364 			&cap_idx) == NULL)
3365 		return -ENOTSUP;
3366 
3367 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3368 		return -ENOTSUP;
3369 
3370 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3371 		return -ENOTSUP;
3372 
3373 	/* Create KASUMI session */
3374 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3375 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3376 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3377 					tdata->key.data, tdata->key.len,
3378 					tdata->cipher_iv.len);
3379 	if (retval < 0)
3380 		return retval;
3381 
3382 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3383 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3384 
3385 	/* Clear mbuf payload */
3386 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3387 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3388 
3389 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3390 	/* Append data which is padded to a multiple */
3391 	/* of the algorithms block size */
3392 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3393 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3394 				plaintext_pad_len);
3395 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3396 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3397 
3398 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3399 
3400 	/* Create KASUMI operation */
3401 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3402 				tdata->cipher_iv.len,
3403 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3404 				tdata->validCipherOffsetInBits.len);
3405 	if (retval < 0)
3406 		return retval;
3407 
3408 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3409 						ut_params->op);
3410 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3411 
3412 	ut_params->obuf = ut_params->op->sym->m_dst;
3413 	if (ut_params->obuf)
3414 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3415 	else
3416 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3417 
3418 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3419 
3420 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3421 				(tdata->validCipherOffsetInBits.len >> 3);
3422 	/* Validate obuf */
3423 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3424 		ciphertext,
3425 		reference_ciphertext,
3426 		tdata->validCipherLenInBits.len,
3427 		"KASUMI Ciphertext data not as expected");
3428 	return 0;
3429 }
3430 
3431 static int
3432 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3433 {
3434 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3435 	struct crypto_unittest_params *ut_params = &unittest_params;
3436 
3437 	int retval;
3438 	unsigned int plaintext_pad_len;
3439 	unsigned int plaintext_len;
3440 
3441 	const uint8_t *ciphertext;
3442 	uint8_t buffer[2048];
3443 
3444 	struct rte_cryptodev_info dev_info;
3445 
3446 	/* Verify the capabilities */
3447 	struct rte_cryptodev_sym_capability_idx cap_idx;
3448 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3449 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3450 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3451 			&cap_idx) == NULL)
3452 		return -ENOTSUP;
3453 
3454 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3455 		return -ENOTSUP;
3456 
3457 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3458 		return -ENOTSUP;
3459 
3460 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3461 
3462 	uint64_t feat_flags = dev_info.feature_flags;
3463 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3464 		printf("Device doesn't support out-of-place scatter-gather "
3465 				"in both input and output mbufs. "
3466 				"Test Skipped.\n");
3467 		return -ENOTSUP;
3468 	}
3469 
3470 	/* Create KASUMI session */
3471 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3472 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3473 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3474 					tdata->key.data, tdata->key.len,
3475 					tdata->cipher_iv.len);
3476 	if (retval < 0)
3477 		return retval;
3478 
3479 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3480 	/* Append data which is padded to a multiple */
3481 	/* of the algorithms block size */
3482 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3483 
3484 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3485 			plaintext_pad_len, 10, 0);
3486 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3487 			plaintext_pad_len, 3, 0);
3488 
3489 	/* Append data which is padded to a multiple */
3490 	/* of the algorithms block size */
3491 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3492 
3493 	/* Create KASUMI operation */
3494 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3495 				tdata->cipher_iv.len,
3496 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3497 				tdata->validCipherOffsetInBits.len);
3498 	if (retval < 0)
3499 		return retval;
3500 
3501 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3502 						ut_params->op);
3503 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3504 
3505 	ut_params->obuf = ut_params->op->sym->m_dst;
3506 	if (ut_params->obuf)
3507 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3508 				plaintext_pad_len, buffer);
3509 	else
3510 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3511 				tdata->validCipherOffsetInBits.len >> 3,
3512 				plaintext_pad_len, buffer);
3513 
3514 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3515 				(tdata->validCipherOffsetInBits.len >> 3);
3516 	/* Validate obuf */
3517 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3518 		ciphertext,
3519 		reference_ciphertext,
3520 		tdata->validCipherLenInBits.len,
3521 		"KASUMI Ciphertext data not as expected");
3522 	return 0;
3523 }
3524 
3525 
3526 static int
3527 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3528 {
3529 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3530 	struct crypto_unittest_params *ut_params = &unittest_params;
3531 
3532 	int retval;
3533 	uint8_t *ciphertext, *plaintext;
3534 	unsigned ciphertext_pad_len;
3535 	unsigned ciphertext_len;
3536 
3537 	/* Verify the capabilities */
3538 	struct rte_cryptodev_sym_capability_idx cap_idx;
3539 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3540 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3541 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3542 			&cap_idx) == NULL)
3543 		return -ENOTSUP;
3544 
3545 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3546 		return -ENOTSUP;
3547 
3548 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3549 		return -ENOTSUP;
3550 
3551 	/* Create KASUMI session */
3552 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3553 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
3554 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3555 					tdata->key.data, tdata->key.len,
3556 					tdata->cipher_iv.len);
3557 	if (retval < 0)
3558 		return retval;
3559 
3560 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3561 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3562 
3563 	/* Clear mbuf payload */
3564 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3565 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3566 
3567 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3568 	/* Append data which is padded to a multiple */
3569 	/* of the algorithms block size */
3570 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3571 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3572 				ciphertext_pad_len);
3573 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3574 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3575 
3576 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3577 
3578 	/* Create KASUMI operation */
3579 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3580 				tdata->cipher_iv.len,
3581 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3582 				tdata->validCipherOffsetInBits.len);
3583 	if (retval < 0)
3584 		return retval;
3585 
3586 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3587 						ut_params->op);
3588 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3589 
3590 	ut_params->obuf = ut_params->op->sym->m_dst;
3591 	if (ut_params->obuf)
3592 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3593 	else
3594 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3595 
3596 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3597 
3598 	const uint8_t *reference_plaintext = tdata->plaintext.data +
3599 				(tdata->validCipherOffsetInBits.len >> 3);
3600 	/* Validate obuf */
3601 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3602 		plaintext,
3603 		reference_plaintext,
3604 		tdata->validCipherLenInBits.len,
3605 		"KASUMI Plaintext data not as expected");
3606 	return 0;
3607 }
3608 
3609 static int
3610 test_kasumi_decryption(const struct kasumi_test_data *tdata)
3611 {
3612 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3613 	struct crypto_unittest_params *ut_params = &unittest_params;
3614 
3615 	int retval;
3616 	uint8_t *ciphertext, *plaintext;
3617 	unsigned ciphertext_pad_len;
3618 	unsigned ciphertext_len;
3619 	struct rte_cryptodev_info dev_info;
3620 
3621 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3622 	uint64_t feat_flags = dev_info.feature_flags;
3623 
3624 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3625 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3626 		printf("Device doesn't support RAW data-path APIs.\n");
3627 		return -ENOTSUP;
3628 	}
3629 
3630 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3631 		return -ENOTSUP;
3632 
3633 	/* Verify the capabilities */
3634 	struct rte_cryptodev_sym_capability_idx cap_idx;
3635 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3636 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3637 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3638 			&cap_idx) == NULL)
3639 		return -ENOTSUP;
3640 
3641 	/* Create KASUMI session */
3642 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3643 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
3644 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3645 					tdata->key.data, tdata->key.len,
3646 					tdata->cipher_iv.len);
3647 	if (retval < 0)
3648 		return retval;
3649 
3650 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3651 
3652 	/* Clear mbuf payload */
3653 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3654 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3655 
3656 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3657 	/* Append data which is padded to a multiple */
3658 	/* of the algorithms block size */
3659 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3660 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3661 				ciphertext_pad_len);
3662 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3663 
3664 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3665 
3666 	/* Create KASUMI operation */
3667 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3668 					tdata->cipher_iv.len,
3669 					tdata->ciphertext.len,
3670 					tdata->validCipherOffsetInBits.len);
3671 	if (retval < 0)
3672 		return retval;
3673 
3674 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3675 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3676 				ut_params->op, 1, 0, 1, 0);
3677 	else
3678 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3679 						ut_params->op);
3680 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3681 
3682 	ut_params->obuf = ut_params->op->sym->m_dst;
3683 	if (ut_params->obuf)
3684 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3685 	else
3686 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3687 
3688 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3689 
3690 	const uint8_t *reference_plaintext = tdata->plaintext.data +
3691 				(tdata->validCipherOffsetInBits.len >> 3);
3692 	/* Validate obuf */
3693 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3694 		plaintext,
3695 		reference_plaintext,
3696 		tdata->validCipherLenInBits.len,
3697 		"KASUMI Plaintext data not as expected");
3698 	return 0;
3699 }
3700 
3701 static int
3702 test_snow3g_encryption(const struct snow3g_test_data *tdata)
3703 {
3704 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3705 	struct crypto_unittest_params *ut_params = &unittest_params;
3706 
3707 	int retval;
3708 	uint8_t *plaintext, *ciphertext;
3709 	unsigned plaintext_pad_len;
3710 	unsigned plaintext_len;
3711 	struct rte_cryptodev_info dev_info;
3712 
3713 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3714 	uint64_t feat_flags = dev_info.feature_flags;
3715 
3716 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3717 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3718 		printf("Device doesn't support RAW data-path APIs.\n");
3719 		return -ENOTSUP;
3720 	}
3721 
3722 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3723 		return -ENOTSUP;
3724 
3725 	/* Verify the capabilities */
3726 	struct rte_cryptodev_sym_capability_idx cap_idx;
3727 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3728 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3729 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3730 			&cap_idx) == NULL)
3731 		return -ENOTSUP;
3732 
3733 	/* Create SNOW 3G session */
3734 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3735 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3736 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3737 					tdata->key.data, tdata->key.len,
3738 					tdata->cipher_iv.len);
3739 	if (retval < 0)
3740 		return retval;
3741 
3742 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3743 
3744 	/* Clear mbuf payload */
3745 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3746 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3747 
3748 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3749 	/* Append data which is padded to a multiple of */
3750 	/* the algorithms block size */
3751 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3752 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3753 				plaintext_pad_len);
3754 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3755 
3756 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3757 
3758 	/* Create SNOW 3G operation */
3759 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3760 					tdata->cipher_iv.len,
3761 					tdata->validCipherLenInBits.len,
3762 					0);
3763 	if (retval < 0)
3764 		return retval;
3765 
3766 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3767 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3768 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3769 	else
3770 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3771 						ut_params->op);
3772 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3773 
3774 	ut_params->obuf = ut_params->op->sym->m_dst;
3775 	if (ut_params->obuf)
3776 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3777 	else
3778 		ciphertext = plaintext;
3779 
3780 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3781 
3782 	/* Validate obuf */
3783 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3784 		ciphertext,
3785 		tdata->ciphertext.data,
3786 		tdata->validDataLenInBits.len,
3787 		"SNOW 3G Ciphertext data not as expected");
3788 	return 0;
3789 }
3790 
3791 
3792 static int
3793 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
3794 {
3795 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3796 	struct crypto_unittest_params *ut_params = &unittest_params;
3797 	uint8_t *plaintext, *ciphertext;
3798 
3799 	int retval;
3800 	unsigned plaintext_pad_len;
3801 	unsigned plaintext_len;
3802 
3803 	/* Verify the capabilities */
3804 	struct rte_cryptodev_sym_capability_idx cap_idx;
3805 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3806 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3807 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3808 			&cap_idx) == NULL)
3809 		return -ENOTSUP;
3810 
3811 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3812 		return -ENOTSUP;
3813 
3814 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3815 		return -ENOTSUP;
3816 
3817 	/* Create SNOW 3G session */
3818 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3819 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3820 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3821 					tdata->key.data, tdata->key.len,
3822 					tdata->cipher_iv.len);
3823 	if (retval < 0)
3824 		return retval;
3825 
3826 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3827 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3828 
3829 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3830 			"Failed to allocate input buffer in mempool");
3831 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
3832 			"Failed to allocate output buffer in mempool");
3833 
3834 	/* Clear mbuf payload */
3835 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3836 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3837 
3838 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3839 	/* Append data which is padded to a multiple of */
3840 	/* the algorithms block size */
3841 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3842 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3843 				plaintext_pad_len);
3844 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3845 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3846 
3847 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3848 
3849 	/* Create SNOW 3G operation */
3850 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3851 					tdata->cipher_iv.len,
3852 					tdata->validCipherLenInBits.len,
3853 					0);
3854 	if (retval < 0)
3855 		return retval;
3856 
3857 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3858 						ut_params->op);
3859 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3860 
3861 	ut_params->obuf = ut_params->op->sym->m_dst;
3862 	if (ut_params->obuf)
3863 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3864 	else
3865 		ciphertext = plaintext;
3866 
3867 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3868 
3869 	/* Validate obuf */
3870 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3871 		ciphertext,
3872 		tdata->ciphertext.data,
3873 		tdata->validDataLenInBits.len,
3874 		"SNOW 3G Ciphertext data not as expected");
3875 	return 0;
3876 }
3877 
3878 static int
3879 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
3880 {
3881 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3882 	struct crypto_unittest_params *ut_params = &unittest_params;
3883 
3884 	int retval;
3885 	unsigned int plaintext_pad_len;
3886 	unsigned int plaintext_len;
3887 	uint8_t buffer[10000];
3888 	const uint8_t *ciphertext;
3889 
3890 	struct rte_cryptodev_info dev_info;
3891 
3892 	/* Verify the capabilities */
3893 	struct rte_cryptodev_sym_capability_idx cap_idx;
3894 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3895 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3896 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3897 			&cap_idx) == NULL)
3898 		return -ENOTSUP;
3899 
3900 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3901 		return -ENOTSUP;
3902 
3903 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3904 		return -ENOTSUP;
3905 
3906 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3907 
3908 	uint64_t feat_flags = dev_info.feature_flags;
3909 
3910 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3911 		printf("Device doesn't support out-of-place scatter-gather "
3912 				"in both input and output mbufs. "
3913 				"Test Skipped.\n");
3914 		return -ENOTSUP;
3915 	}
3916 
3917 	/* Create SNOW 3G session */
3918 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3919 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3920 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3921 					tdata->key.data, tdata->key.len,
3922 					tdata->cipher_iv.len);
3923 	if (retval < 0)
3924 		return retval;
3925 
3926 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3927 	/* Append data which is padded to a multiple of */
3928 	/* the algorithms block size */
3929 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3930 
3931 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3932 			plaintext_pad_len, 10, 0);
3933 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3934 			plaintext_pad_len, 3, 0);
3935 
3936 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3937 			"Failed to allocate input buffer in mempool");
3938 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
3939 			"Failed to allocate output buffer in mempool");
3940 
3941 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3942 
3943 	/* Create SNOW 3G operation */
3944 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3945 					tdata->cipher_iv.len,
3946 					tdata->validCipherLenInBits.len,
3947 					0);
3948 	if (retval < 0)
3949 		return retval;
3950 
3951 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3952 						ut_params->op);
3953 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3954 
3955 	ut_params->obuf = ut_params->op->sym->m_dst;
3956 	if (ut_params->obuf)
3957 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3958 				plaintext_len, buffer);
3959 	else
3960 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
3961 				plaintext_len, buffer);
3962 
3963 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3964 
3965 	/* Validate obuf */
3966 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3967 		ciphertext,
3968 		tdata->ciphertext.data,
3969 		tdata->validDataLenInBits.len,
3970 		"SNOW 3G Ciphertext data not as expected");
3971 
3972 	return 0;
3973 }
3974 
3975 /* Shift right a buffer by "offset" bits, "offset" < 8 */
3976 static void
3977 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
3978 {
3979 	uint8_t curr_byte, prev_byte;
3980 	uint32_t length_in_bytes = ceil_byte_length(length + offset);
3981 	uint8_t lower_byte_mask = (1 << offset) - 1;
3982 	unsigned i;
3983 
3984 	prev_byte = buffer[0];
3985 	buffer[0] >>= offset;
3986 
3987 	for (i = 1; i < length_in_bytes; i++) {
3988 		curr_byte = buffer[i];
3989 		buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
3990 				(curr_byte >> offset);
3991 		prev_byte = curr_byte;
3992 	}
3993 }
3994 
3995 static int
3996 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
3997 {
3998 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3999 	struct crypto_unittest_params *ut_params = &unittest_params;
4000 	uint8_t *plaintext, *ciphertext;
4001 	int retval;
4002 	uint32_t plaintext_len;
4003 	uint32_t plaintext_pad_len;
4004 	uint8_t extra_offset = 4;
4005 	uint8_t *expected_ciphertext_shifted;
4006 	struct rte_cryptodev_info dev_info;
4007 
4008 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4009 	uint64_t feat_flags = dev_info.feature_flags;
4010 
4011 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4012 			((tdata->validDataLenInBits.len % 8) != 0)) {
4013 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4014 		return -ENOTSUP;
4015 	}
4016 
4017 	/* Verify the capabilities */
4018 	struct rte_cryptodev_sym_capability_idx cap_idx;
4019 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4020 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4021 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4022 			&cap_idx) == NULL)
4023 		return -ENOTSUP;
4024 
4025 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4026 		return -ENOTSUP;
4027 
4028 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4029 		return -ENOTSUP;
4030 
4031 	/* Create SNOW 3G session */
4032 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4033 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4034 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4035 					tdata->key.data, tdata->key.len,
4036 					tdata->cipher_iv.len);
4037 	if (retval < 0)
4038 		return retval;
4039 
4040 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4041 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4042 
4043 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4044 			"Failed to allocate input buffer in mempool");
4045 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4046 			"Failed to allocate output buffer in mempool");
4047 
4048 	/* Clear mbuf payload */
4049 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4050 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4051 
4052 	plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4053 	/*
4054 	 * Append data which is padded to a
4055 	 * multiple of the algorithms block size
4056 	 */
4057 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4058 
4059 	plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4060 						plaintext_pad_len);
4061 
4062 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4063 
4064 	memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4065 	buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4066 
4067 #ifdef RTE_APP_TEST_DEBUG
4068 	rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4069 #endif
4070 	/* Create SNOW 3G operation */
4071 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4072 					tdata->cipher_iv.len,
4073 					tdata->validCipherLenInBits.len,
4074 					extra_offset);
4075 	if (retval < 0)
4076 		return retval;
4077 
4078 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4079 						ut_params->op);
4080 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4081 
4082 	ut_params->obuf = ut_params->op->sym->m_dst;
4083 	if (ut_params->obuf)
4084 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4085 	else
4086 		ciphertext = plaintext;
4087 
4088 #ifdef RTE_APP_TEST_DEBUG
4089 	rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4090 #endif
4091 
4092 	expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4093 
4094 	TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4095 			"failed to reserve memory for ciphertext shifted\n");
4096 
4097 	memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4098 			ceil_byte_length(tdata->ciphertext.len));
4099 	buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4100 			extra_offset);
4101 	/* Validate obuf */
4102 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4103 		ciphertext,
4104 		expected_ciphertext_shifted,
4105 		tdata->validDataLenInBits.len,
4106 		extra_offset,
4107 		"SNOW 3G Ciphertext data not as expected");
4108 	return 0;
4109 }
4110 
4111 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4112 {
4113 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4114 	struct crypto_unittest_params *ut_params = &unittest_params;
4115 
4116 	int retval;
4117 
4118 	uint8_t *plaintext, *ciphertext;
4119 	unsigned ciphertext_pad_len;
4120 	unsigned ciphertext_len;
4121 	struct rte_cryptodev_info dev_info;
4122 
4123 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4124 	uint64_t feat_flags = dev_info.feature_flags;
4125 
4126 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4127 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4128 		printf("Device doesn't support RAW data-path APIs.\n");
4129 		return -ENOTSUP;
4130 	}
4131 
4132 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4133 		return -ENOTSUP;
4134 
4135 	/* Verify the capabilities */
4136 	struct rte_cryptodev_sym_capability_idx cap_idx;
4137 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4138 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4139 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4140 			&cap_idx) == NULL)
4141 		return -ENOTSUP;
4142 
4143 	/* Create SNOW 3G session */
4144 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4145 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4146 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4147 					tdata->key.data, tdata->key.len,
4148 					tdata->cipher_iv.len);
4149 	if (retval < 0)
4150 		return retval;
4151 
4152 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4153 
4154 	/* Clear mbuf payload */
4155 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4156 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4157 
4158 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4159 	/* Append data which is padded to a multiple of */
4160 	/* the algorithms block size */
4161 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4162 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4163 				ciphertext_pad_len);
4164 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4165 
4166 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4167 
4168 	/* Create SNOW 3G operation */
4169 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4170 					tdata->cipher_iv.len,
4171 					tdata->validCipherLenInBits.len,
4172 					tdata->cipher.offset_bits);
4173 	if (retval < 0)
4174 		return retval;
4175 
4176 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4177 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4178 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4179 	else
4180 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4181 						ut_params->op);
4182 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4183 	ut_params->obuf = ut_params->op->sym->m_dst;
4184 	if (ut_params->obuf)
4185 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4186 	else
4187 		plaintext = ciphertext;
4188 
4189 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4190 
4191 	/* Validate obuf */
4192 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4193 				tdata->plaintext.data,
4194 				tdata->validDataLenInBits.len,
4195 				"SNOW 3G Plaintext data not as expected");
4196 	return 0;
4197 }
4198 
4199 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4200 {
4201 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4202 	struct crypto_unittest_params *ut_params = &unittest_params;
4203 
4204 	int retval;
4205 
4206 	uint8_t *plaintext, *ciphertext;
4207 	unsigned ciphertext_pad_len;
4208 	unsigned ciphertext_len;
4209 
4210 	/* Verify the capabilities */
4211 	struct rte_cryptodev_sym_capability_idx cap_idx;
4212 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4213 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4214 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4215 			&cap_idx) == NULL)
4216 		return -ENOTSUP;
4217 
4218 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4219 		return -ENOTSUP;
4220 
4221 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4222 		return -ENOTSUP;
4223 
4224 	/* Create SNOW 3G session */
4225 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4226 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4227 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4228 					tdata->key.data, tdata->key.len,
4229 					tdata->cipher_iv.len);
4230 	if (retval < 0)
4231 		return retval;
4232 
4233 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4234 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4235 
4236 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4237 			"Failed to allocate input buffer");
4238 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4239 			"Failed to allocate output buffer");
4240 
4241 	/* Clear mbuf payload */
4242 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4243 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4244 
4245 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4246 		       rte_pktmbuf_tailroom(ut_params->obuf));
4247 
4248 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4249 	/* Append data which is padded to a multiple of */
4250 	/* the algorithms block size */
4251 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4252 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4253 				ciphertext_pad_len);
4254 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4255 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4256 
4257 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4258 
4259 	/* Create SNOW 3G operation */
4260 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4261 					tdata->cipher_iv.len,
4262 					tdata->validCipherLenInBits.len,
4263 					0);
4264 	if (retval < 0)
4265 		return retval;
4266 
4267 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4268 						ut_params->op);
4269 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4270 	ut_params->obuf = ut_params->op->sym->m_dst;
4271 	if (ut_params->obuf)
4272 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4273 	else
4274 		plaintext = ciphertext;
4275 
4276 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4277 
4278 	/* Validate obuf */
4279 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4280 				tdata->plaintext.data,
4281 				tdata->validDataLenInBits.len,
4282 				"SNOW 3G Plaintext data not as expected");
4283 	return 0;
4284 }
4285 
4286 static int
4287 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4288 {
4289 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4290 	struct crypto_unittest_params *ut_params = &unittest_params;
4291 
4292 	int retval;
4293 
4294 	uint8_t *plaintext, *ciphertext;
4295 	unsigned int plaintext_pad_len;
4296 	unsigned int plaintext_len;
4297 
4298 	struct rte_cryptodev_info dev_info;
4299 	struct rte_cryptodev_sym_capability_idx cap_idx;
4300 
4301 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4302 	uint64_t feat_flags = dev_info.feature_flags;
4303 
4304 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4305 			((tdata->validAuthLenInBits.len % 8 != 0) ||
4306 			(tdata->validDataLenInBits.len % 8 != 0))) {
4307 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4308 		return -ENOTSUP;
4309 	}
4310 
4311 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4312 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4313 		printf("Device doesn't support RAW data-path APIs.\n");
4314 		return -ENOTSUP;
4315 	}
4316 
4317 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4318 		return -ENOTSUP;
4319 
4320 	/* Check if device supports ZUC EEA3 */
4321 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4322 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4323 
4324 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4325 			&cap_idx) == NULL)
4326 		return -ENOTSUP;
4327 
4328 	/* Check if device supports ZUC EIA3 */
4329 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4330 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4331 
4332 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4333 			&cap_idx) == NULL)
4334 		return -ENOTSUP;
4335 
4336 	/* Create ZUC session */
4337 	retval = create_zuc_cipher_auth_encrypt_generate_session(
4338 			ts_params->valid_devs[0],
4339 			tdata);
4340 	if (retval < 0)
4341 		return retval;
4342 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4343 
4344 	/* clear mbuf payload */
4345 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4346 			rte_pktmbuf_tailroom(ut_params->ibuf));
4347 
4348 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4349 	/* Append data which is padded to a multiple of */
4350 	/* the algorithms block size */
4351 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4352 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4353 				plaintext_pad_len);
4354 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4355 
4356 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4357 
4358 	/* Create ZUC operation */
4359 	retval = create_zuc_cipher_hash_generate_operation(tdata);
4360 	if (retval < 0)
4361 		return retval;
4362 
4363 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4364 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4365 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4366 	else
4367 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4368 			ut_params->op);
4369 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4370 	ut_params->obuf = ut_params->op->sym->m_src;
4371 	if (ut_params->obuf)
4372 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4373 	else
4374 		ciphertext = plaintext;
4375 
4376 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4377 	/* Validate obuf */
4378 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4379 			ciphertext,
4380 			tdata->ciphertext.data,
4381 			tdata->validDataLenInBits.len,
4382 			"ZUC Ciphertext data not as expected");
4383 
4384 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4385 	    + plaintext_pad_len;
4386 
4387 	/* Validate obuf */
4388 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4389 			ut_params->digest,
4390 			tdata->digest.data,
4391 			4,
4392 			"ZUC Generated auth tag not as expected");
4393 	return 0;
4394 }
4395 
4396 static int
4397 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4398 {
4399 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4400 	struct crypto_unittest_params *ut_params = &unittest_params;
4401 
4402 	int retval;
4403 
4404 	uint8_t *plaintext, *ciphertext;
4405 	unsigned plaintext_pad_len;
4406 	unsigned plaintext_len;
4407 	struct rte_cryptodev_info dev_info;
4408 
4409 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4410 	uint64_t feat_flags = dev_info.feature_flags;
4411 
4412 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4413 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4414 		printf("Device doesn't support RAW data-path APIs.\n");
4415 		return -ENOTSUP;
4416 	}
4417 
4418 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4419 		return -ENOTSUP;
4420 
4421 	/* Verify the capabilities */
4422 	struct rte_cryptodev_sym_capability_idx cap_idx;
4423 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4424 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4425 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4426 			&cap_idx) == NULL)
4427 		return -ENOTSUP;
4428 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4429 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4430 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4431 			&cap_idx) == NULL)
4432 		return -ENOTSUP;
4433 
4434 	/* Create SNOW 3G session */
4435 	retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4436 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4437 			RTE_CRYPTO_AUTH_OP_GENERATE,
4438 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4439 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4440 			tdata->key.data, tdata->key.len,
4441 			tdata->auth_iv.len, tdata->digest.len,
4442 			tdata->cipher_iv.len);
4443 	if (retval < 0)
4444 		return retval;
4445 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4446 
4447 	/* clear mbuf payload */
4448 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4449 			rte_pktmbuf_tailroom(ut_params->ibuf));
4450 
4451 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4452 	/* Append data which is padded to a multiple of */
4453 	/* the algorithms block size */
4454 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4455 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4456 				plaintext_pad_len);
4457 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4458 
4459 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4460 
4461 	/* Create SNOW 3G operation */
4462 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4463 			tdata->digest.len, tdata->auth_iv.data,
4464 			tdata->auth_iv.len,
4465 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4466 			tdata->cipher_iv.data, tdata->cipher_iv.len,
4467 			tdata->validCipherLenInBits.len,
4468 			0,
4469 			tdata->validAuthLenInBits.len,
4470 			0
4471 			);
4472 	if (retval < 0)
4473 		return retval;
4474 
4475 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4476 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4477 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4478 	else
4479 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4480 			ut_params->op);
4481 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4482 	ut_params->obuf = ut_params->op->sym->m_src;
4483 	if (ut_params->obuf)
4484 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4485 	else
4486 		ciphertext = plaintext;
4487 
4488 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4489 	/* Validate obuf */
4490 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4491 			ciphertext,
4492 			tdata->ciphertext.data,
4493 			tdata->validDataLenInBits.len,
4494 			"SNOW 3G Ciphertext data not as expected");
4495 
4496 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4497 	    + plaintext_pad_len;
4498 
4499 	/* Validate obuf */
4500 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4501 			ut_params->digest,
4502 			tdata->digest.data,
4503 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4504 			"SNOW 3G Generated auth tag not as expected");
4505 	return 0;
4506 }
4507 
4508 static int
4509 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
4510 	uint8_t op_mode, uint8_t verify)
4511 {
4512 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4513 	struct crypto_unittest_params *ut_params = &unittest_params;
4514 
4515 	int retval;
4516 
4517 	uint8_t *plaintext = NULL, *ciphertext = NULL;
4518 	unsigned int plaintext_pad_len;
4519 	unsigned int plaintext_len;
4520 	unsigned int ciphertext_pad_len;
4521 	unsigned int ciphertext_len;
4522 
4523 	struct rte_cryptodev_info dev_info;
4524 
4525 	/* Verify the capabilities */
4526 	struct rte_cryptodev_sym_capability_idx cap_idx;
4527 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4528 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4529 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4530 			&cap_idx) == NULL)
4531 		return -ENOTSUP;
4532 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4533 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4534 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4535 			&cap_idx) == NULL)
4536 		return -ENOTSUP;
4537 
4538 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4539 		return -ENOTSUP;
4540 
4541 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4542 
4543 	uint64_t feat_flags = dev_info.feature_flags;
4544 
4545 	if (op_mode == OUT_OF_PLACE) {
4546 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4547 			printf("Device doesn't support digest encrypted.\n");
4548 			return -ENOTSUP;
4549 		}
4550 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4551 			return -ENOTSUP;
4552 	}
4553 
4554 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4555 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4556 		printf("Device doesn't support RAW data-path APIs.\n");
4557 		return -ENOTSUP;
4558 	}
4559 
4560 	/* Create SNOW 3G session */
4561 	retval = create_wireless_algo_auth_cipher_session(
4562 			ts_params->valid_devs[0],
4563 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4564 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4565 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4566 					: RTE_CRYPTO_AUTH_OP_GENERATE),
4567 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4568 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4569 			tdata->key.data, tdata->key.len,
4570 			tdata->auth_iv.len, tdata->digest.len,
4571 			tdata->cipher_iv.len);
4572 
4573 	if (retval < 0)
4574 		return retval;
4575 
4576 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4577 	if (op_mode == OUT_OF_PLACE)
4578 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4579 
4580 	/* clear mbuf payload */
4581 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4582 		rte_pktmbuf_tailroom(ut_params->ibuf));
4583 	if (op_mode == OUT_OF_PLACE)
4584 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4585 			rte_pktmbuf_tailroom(ut_params->obuf));
4586 
4587 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4588 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4589 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4590 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4591 
4592 	if (verify) {
4593 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4594 					ciphertext_pad_len);
4595 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4596 		if (op_mode == OUT_OF_PLACE)
4597 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4598 		debug_hexdump(stdout, "ciphertext:", ciphertext,
4599 			ciphertext_len);
4600 	} else {
4601 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4602 					plaintext_pad_len);
4603 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4604 		if (op_mode == OUT_OF_PLACE)
4605 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4606 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4607 	}
4608 
4609 	/* Create SNOW 3G operation */
4610 	retval = create_wireless_algo_auth_cipher_operation(
4611 		tdata->digest.data, tdata->digest.len,
4612 		tdata->cipher_iv.data, tdata->cipher_iv.len,
4613 		tdata->auth_iv.data, tdata->auth_iv.len,
4614 		(tdata->digest.offset_bytes == 0 ?
4615 		(verify ? ciphertext_pad_len : plaintext_pad_len)
4616 			: tdata->digest.offset_bytes),
4617 		tdata->validCipherLenInBits.len,
4618 		tdata->cipher.offset_bits,
4619 		tdata->validAuthLenInBits.len,
4620 		tdata->auth.offset_bits,
4621 		op_mode, 0, verify);
4622 
4623 	if (retval < 0)
4624 		return retval;
4625 
4626 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4627 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4628 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4629 	else
4630 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4631 			ut_params->op);
4632 
4633 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4634 
4635 	ut_params->obuf = (op_mode == IN_PLACE ?
4636 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4637 
4638 	if (verify) {
4639 		if (ut_params->obuf)
4640 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
4641 							uint8_t *);
4642 		else
4643 			plaintext = ciphertext +
4644 				(tdata->cipher.offset_bits >> 3);
4645 
4646 		debug_hexdump(stdout, "plaintext:", plaintext,
4647 			(tdata->plaintext.len >> 3) - tdata->digest.len);
4648 		debug_hexdump(stdout, "plaintext expected:",
4649 			tdata->plaintext.data,
4650 			(tdata->plaintext.len >> 3) - tdata->digest.len);
4651 	} else {
4652 		if (ut_params->obuf)
4653 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
4654 							uint8_t *);
4655 		else
4656 			ciphertext = plaintext;
4657 
4658 		debug_hexdump(stdout, "ciphertext:", ciphertext,
4659 			ciphertext_len);
4660 		debug_hexdump(stdout, "ciphertext expected:",
4661 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
4662 
4663 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4664 			+ (tdata->digest.offset_bytes == 0 ?
4665 		plaintext_pad_len : tdata->digest.offset_bytes);
4666 
4667 		debug_hexdump(stdout, "digest:", ut_params->digest,
4668 			tdata->digest.len);
4669 		debug_hexdump(stdout, "digest expected:", tdata->digest.data,
4670 				tdata->digest.len);
4671 	}
4672 
4673 	/* Validate obuf */
4674 	if (verify) {
4675 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4676 			plaintext,
4677 			tdata->plaintext.data,
4678 			tdata->plaintext.len >> 3,
4679 			"SNOW 3G Plaintext data not as expected");
4680 	} else {
4681 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4682 			ciphertext,
4683 			tdata->ciphertext.data,
4684 			tdata->validDataLenInBits.len,
4685 			"SNOW 3G Ciphertext data not as expected");
4686 
4687 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
4688 			ut_params->digest,
4689 			tdata->digest.data,
4690 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4691 			"SNOW 3G Generated auth tag not as expected");
4692 	}
4693 	return 0;
4694 }
4695 
4696 static int
4697 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
4698 	uint8_t op_mode, uint8_t verify)
4699 {
4700 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4701 	struct crypto_unittest_params *ut_params = &unittest_params;
4702 
4703 	int retval;
4704 
4705 	const uint8_t *plaintext = NULL;
4706 	const uint8_t *ciphertext = NULL;
4707 	const uint8_t *digest = NULL;
4708 	unsigned int plaintext_pad_len;
4709 	unsigned int plaintext_len;
4710 	unsigned int ciphertext_pad_len;
4711 	unsigned int ciphertext_len;
4712 	uint8_t buffer[10000];
4713 	uint8_t digest_buffer[10000];
4714 
4715 	struct rte_cryptodev_info dev_info;
4716 
4717 	/* Verify the capabilities */
4718 	struct rte_cryptodev_sym_capability_idx cap_idx;
4719 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4720 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4721 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4722 			&cap_idx) == NULL)
4723 		return -ENOTSUP;
4724 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4725 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4726 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4727 			&cap_idx) == NULL)
4728 		return -ENOTSUP;
4729 
4730 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4731 		return -ENOTSUP;
4732 
4733 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4734 
4735 	uint64_t feat_flags = dev_info.feature_flags;
4736 
4737 	if (op_mode == IN_PLACE) {
4738 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
4739 			printf("Device doesn't support in-place scatter-gather "
4740 					"in both input and output mbufs.\n");
4741 			return -ENOTSUP;
4742 		}
4743 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4744 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4745 			printf("Device doesn't support RAW data-path APIs.\n");
4746 			return -ENOTSUP;
4747 		}
4748 	} else {
4749 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4750 			return -ENOTSUP;
4751 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4752 			printf("Device doesn't support out-of-place scatter-gather "
4753 					"in both input and output mbufs.\n");
4754 			return -ENOTSUP;
4755 		}
4756 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4757 			printf("Device doesn't support digest encrypted.\n");
4758 			return -ENOTSUP;
4759 		}
4760 	}
4761 
4762 	/* Create SNOW 3G session */
4763 	retval = create_wireless_algo_auth_cipher_session(
4764 			ts_params->valid_devs[0],
4765 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4766 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4767 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4768 					: RTE_CRYPTO_AUTH_OP_GENERATE),
4769 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4770 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4771 			tdata->key.data, tdata->key.len,
4772 			tdata->auth_iv.len, tdata->digest.len,
4773 			tdata->cipher_iv.len);
4774 
4775 	if (retval < 0)
4776 		return retval;
4777 
4778 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4779 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4780 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4781 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4782 
4783 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4784 			plaintext_pad_len, 15, 0);
4785 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4786 			"Failed to allocate input buffer in mempool");
4787 
4788 	if (op_mode == OUT_OF_PLACE) {
4789 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4790 				plaintext_pad_len, 15, 0);
4791 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
4792 				"Failed to allocate output buffer in mempool");
4793 	}
4794 
4795 	if (verify) {
4796 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
4797 			tdata->ciphertext.data);
4798 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4799 					ciphertext_len, buffer);
4800 		debug_hexdump(stdout, "ciphertext:", ciphertext,
4801 			ciphertext_len);
4802 	} else {
4803 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
4804 			tdata->plaintext.data);
4805 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
4806 					plaintext_len, buffer);
4807 		debug_hexdump(stdout, "plaintext:", plaintext,
4808 			plaintext_len);
4809 	}
4810 	memset(buffer, 0, sizeof(buffer));
4811 
4812 	/* Create SNOW 3G operation */
4813 	retval = create_wireless_algo_auth_cipher_operation(
4814 		tdata->digest.data, tdata->digest.len,
4815 		tdata->cipher_iv.data, tdata->cipher_iv.len,
4816 		tdata->auth_iv.data, tdata->auth_iv.len,
4817 		(tdata->digest.offset_bytes == 0 ?
4818 		(verify ? ciphertext_pad_len : plaintext_pad_len)
4819 			: tdata->digest.offset_bytes),
4820 		tdata->validCipherLenInBits.len,
4821 		tdata->cipher.offset_bits,
4822 		tdata->validAuthLenInBits.len,
4823 		tdata->auth.offset_bits,
4824 		op_mode, 1, verify);
4825 
4826 	if (retval < 0)
4827 		return retval;
4828 
4829 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4830 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4831 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4832 	else
4833 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4834 			ut_params->op);
4835 
4836 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4837 
4838 	ut_params->obuf = (op_mode == IN_PLACE ?
4839 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4840 
4841 	if (verify) {
4842 		if (ut_params->obuf)
4843 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
4844 					plaintext_len, buffer);
4845 		else
4846 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
4847 					plaintext_len, buffer);
4848 
4849 		debug_hexdump(stdout, "plaintext:", plaintext,
4850 			(tdata->plaintext.len >> 3) - tdata->digest.len);
4851 		debug_hexdump(stdout, "plaintext expected:",
4852 			tdata->plaintext.data,
4853 			(tdata->plaintext.len >> 3) - tdata->digest.len);
4854 	} else {
4855 		if (ut_params->obuf)
4856 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4857 					ciphertext_len, buffer);
4858 		else
4859 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4860 					ciphertext_len, buffer);
4861 
4862 		debug_hexdump(stdout, "ciphertext:", ciphertext,
4863 			ciphertext_len);
4864 		debug_hexdump(stdout, "ciphertext expected:",
4865 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
4866 
4867 		if (ut_params->obuf)
4868 			digest = rte_pktmbuf_read(ut_params->obuf,
4869 				(tdata->digest.offset_bytes == 0 ?
4870 				plaintext_pad_len : tdata->digest.offset_bytes),
4871 				tdata->digest.len, digest_buffer);
4872 		else
4873 			digest = rte_pktmbuf_read(ut_params->ibuf,
4874 				(tdata->digest.offset_bytes == 0 ?
4875 				plaintext_pad_len : tdata->digest.offset_bytes),
4876 				tdata->digest.len, digest_buffer);
4877 
4878 		debug_hexdump(stdout, "digest:", digest,
4879 			tdata->digest.len);
4880 		debug_hexdump(stdout, "digest expected:",
4881 			tdata->digest.data, tdata->digest.len);
4882 	}
4883 
4884 	/* Validate obuf */
4885 	if (verify) {
4886 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4887 			plaintext,
4888 			tdata->plaintext.data,
4889 			tdata->plaintext.len >> 3,
4890 			"SNOW 3G Plaintext data not as expected");
4891 	} else {
4892 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4893 			ciphertext,
4894 			tdata->ciphertext.data,
4895 			tdata->validDataLenInBits.len,
4896 			"SNOW 3G Ciphertext data not as expected");
4897 
4898 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
4899 			digest,
4900 			tdata->digest.data,
4901 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4902 			"SNOW 3G Generated auth tag not as expected");
4903 	}
4904 	return 0;
4905 }
4906 
4907 static int
4908 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
4909 	uint8_t op_mode, uint8_t verify)
4910 {
4911 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4912 	struct crypto_unittest_params *ut_params = &unittest_params;
4913 
4914 	int retval;
4915 
4916 	uint8_t *plaintext = NULL, *ciphertext = NULL;
4917 	unsigned int plaintext_pad_len;
4918 	unsigned int plaintext_len;
4919 	unsigned int ciphertext_pad_len;
4920 	unsigned int ciphertext_len;
4921 
4922 	struct rte_cryptodev_info dev_info;
4923 
4924 	/* Verify the capabilities */
4925 	struct rte_cryptodev_sym_capability_idx cap_idx;
4926 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4927 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
4928 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4929 			&cap_idx) == NULL)
4930 		return -ENOTSUP;
4931 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4932 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4933 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4934 			&cap_idx) == NULL)
4935 		return -ENOTSUP;
4936 
4937 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4938 
4939 	uint64_t feat_flags = dev_info.feature_flags;
4940 
4941 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4942 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4943 		printf("Device doesn't support RAW data-path APIs.\n");
4944 		return -ENOTSUP;
4945 	}
4946 
4947 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4948 		return -ENOTSUP;
4949 
4950 	if (op_mode == OUT_OF_PLACE) {
4951 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4952 			return -ENOTSUP;
4953 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4954 			printf("Device doesn't support digest encrypted.\n");
4955 			return -ENOTSUP;
4956 		}
4957 	}
4958 
4959 	/* Create KASUMI session */
4960 	retval = create_wireless_algo_auth_cipher_session(
4961 			ts_params->valid_devs[0],
4962 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4963 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4964 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4965 					: RTE_CRYPTO_AUTH_OP_GENERATE),
4966 			RTE_CRYPTO_AUTH_KASUMI_F9,
4967 			RTE_CRYPTO_CIPHER_KASUMI_F8,
4968 			tdata->key.data, tdata->key.len,
4969 			0, tdata->digest.len,
4970 			tdata->cipher_iv.len);
4971 
4972 	if (retval < 0)
4973 		return retval;
4974 
4975 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4976 	if (op_mode == OUT_OF_PLACE)
4977 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4978 
4979 	/* clear mbuf payload */
4980 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4981 		rte_pktmbuf_tailroom(ut_params->ibuf));
4982 	if (op_mode == OUT_OF_PLACE)
4983 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4984 			rte_pktmbuf_tailroom(ut_params->obuf));
4985 
4986 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4987 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4988 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4989 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4990 
4991 	if (verify) {
4992 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4993 					ciphertext_pad_len);
4994 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4995 		if (op_mode == OUT_OF_PLACE)
4996 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4997 		debug_hexdump(stdout, "ciphertext:", ciphertext,
4998 			ciphertext_len);
4999 	} else {
5000 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5001 					plaintext_pad_len);
5002 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5003 		if (op_mode == OUT_OF_PLACE)
5004 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5005 		debug_hexdump(stdout, "plaintext:", plaintext,
5006 			plaintext_len);
5007 	}
5008 
5009 	/* Create KASUMI operation */
5010 	retval = create_wireless_algo_auth_cipher_operation(
5011 		tdata->digest.data, tdata->digest.len,
5012 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5013 		NULL, 0,
5014 		(tdata->digest.offset_bytes == 0 ?
5015 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5016 			: tdata->digest.offset_bytes),
5017 		tdata->validCipherLenInBits.len,
5018 		tdata->validCipherOffsetInBits.len,
5019 		tdata->validAuthLenInBits.len,
5020 		0,
5021 		op_mode, 0, verify);
5022 
5023 	if (retval < 0)
5024 		return retval;
5025 
5026 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5027 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5028 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5029 	else
5030 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5031 			ut_params->op);
5032 
5033 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5034 
5035 	ut_params->obuf = (op_mode == IN_PLACE ?
5036 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5037 
5038 
5039 	if (verify) {
5040 		if (ut_params->obuf)
5041 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5042 							uint8_t *);
5043 		else
5044 			plaintext = ciphertext;
5045 
5046 		debug_hexdump(stdout, "plaintext:", plaintext,
5047 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5048 		debug_hexdump(stdout, "plaintext expected:",
5049 			tdata->plaintext.data,
5050 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5051 	} else {
5052 		if (ut_params->obuf)
5053 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5054 							uint8_t *);
5055 		else
5056 			ciphertext = plaintext;
5057 
5058 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5059 			ciphertext_len);
5060 		debug_hexdump(stdout, "ciphertext expected:",
5061 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5062 
5063 		ut_params->digest = rte_pktmbuf_mtod(
5064 			ut_params->obuf, uint8_t *) +
5065 			(tdata->digest.offset_bytes == 0 ?
5066 			plaintext_pad_len : tdata->digest.offset_bytes);
5067 
5068 		debug_hexdump(stdout, "digest:", ut_params->digest,
5069 			tdata->digest.len);
5070 		debug_hexdump(stdout, "digest expected:",
5071 			tdata->digest.data, tdata->digest.len);
5072 	}
5073 
5074 	/* Validate obuf */
5075 	if (verify) {
5076 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5077 			plaintext,
5078 			tdata->plaintext.data,
5079 			tdata->plaintext.len >> 3,
5080 			"KASUMI Plaintext data not as expected");
5081 	} else {
5082 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5083 			ciphertext,
5084 			tdata->ciphertext.data,
5085 			tdata->ciphertext.len >> 3,
5086 			"KASUMI Ciphertext data not as expected");
5087 
5088 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5089 			ut_params->digest,
5090 			tdata->digest.data,
5091 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5092 			"KASUMI Generated auth tag not as expected");
5093 	}
5094 	return 0;
5095 }
5096 
5097 static int
5098 test_kasumi_auth_cipher_sgl(const struct kasumi_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_KASUMI_F9;
5122 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5123 			&cap_idx) == NULL)
5124 		return -ENOTSUP;
5125 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5126 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5127 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5128 			&cap_idx) == NULL)
5129 		return -ENOTSUP;
5130 
5131 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5132 		return -ENOTSUP;
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 -ENOTSUP;
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 -ENOTSUP;
5148 		}
5149 	} else {
5150 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5151 			return -ENOTSUP;
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 -ENOTSUP;
5156 		}
5157 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5158 			printf("Device doesn't support digest encrypted.\n");
5159 			return -ENOTSUP;
5160 		}
5161 	}
5162 
5163 	/* Create KASUMI 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_KASUMI_F9,
5171 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5172 			tdata->key.data, tdata->key.len,
5173 			0, 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 KASUMI 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 		NULL, 0,
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->validCipherOffsetInBits.len,
5223 		tdata->validAuthLenInBits.len,
5224 		0,
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(
5288 			plaintext,
5289 			tdata->plaintext.data,
5290 			tdata->plaintext.len >> 3,
5291 			"KASUMI Plaintext data not as expected");
5292 	} else {
5293 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5294 			ciphertext,
5295 			tdata->ciphertext.data,
5296 			tdata->validDataLenInBits.len,
5297 			"KASUMI Ciphertext data not as expected");
5298 
5299 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5300 			digest,
5301 			tdata->digest.data,
5302 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5303 			"KASUMI Generated auth tag not as expected");
5304 	}
5305 	return 0;
5306 }
5307 
5308 static int
5309 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5310 {
5311 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5312 	struct crypto_unittest_params *ut_params = &unittest_params;
5313 
5314 	int retval;
5315 
5316 	uint8_t *plaintext, *ciphertext;
5317 	unsigned plaintext_pad_len;
5318 	unsigned plaintext_len;
5319 	struct rte_cryptodev_info dev_info;
5320 
5321 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5322 	uint64_t feat_flags = dev_info.feature_flags;
5323 
5324 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5325 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5326 		printf("Device doesn't support RAW data-path APIs.\n");
5327 		return -ENOTSUP;
5328 	}
5329 
5330 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5331 		return -ENOTSUP;
5332 
5333 	/* Verify the capabilities */
5334 	struct rte_cryptodev_sym_capability_idx cap_idx;
5335 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5336 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5337 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5338 			&cap_idx) == NULL)
5339 		return -ENOTSUP;
5340 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5341 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5342 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5343 			&cap_idx) == NULL)
5344 		return -ENOTSUP;
5345 
5346 	/* Create KASUMI session */
5347 	retval = create_wireless_algo_cipher_auth_session(
5348 			ts_params->valid_devs[0],
5349 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5350 			RTE_CRYPTO_AUTH_OP_GENERATE,
5351 			RTE_CRYPTO_AUTH_KASUMI_F9,
5352 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5353 			tdata->key.data, tdata->key.len,
5354 			0, tdata->digest.len,
5355 			tdata->cipher_iv.len);
5356 	if (retval < 0)
5357 		return retval;
5358 
5359 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5360 
5361 	/* clear mbuf payload */
5362 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5363 			rte_pktmbuf_tailroom(ut_params->ibuf));
5364 
5365 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5366 	/* Append data which is padded to a multiple of */
5367 	/* the algorithms block size */
5368 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5369 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5370 				plaintext_pad_len);
5371 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5372 
5373 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5374 
5375 	/* Create KASUMI operation */
5376 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5377 				tdata->digest.len, NULL, 0,
5378 				plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5379 				tdata->cipher_iv.data, tdata->cipher_iv.len,
5380 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5381 				tdata->validCipherOffsetInBits.len,
5382 				tdata->validAuthLenInBits.len,
5383 				0
5384 				);
5385 	if (retval < 0)
5386 		return retval;
5387 
5388 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5389 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5390 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5391 	else
5392 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5393 			ut_params->op);
5394 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5395 
5396 	if (ut_params->op->sym->m_dst)
5397 		ut_params->obuf = ut_params->op->sym->m_dst;
5398 	else
5399 		ut_params->obuf = ut_params->op->sym->m_src;
5400 
5401 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5402 				tdata->validCipherOffsetInBits.len >> 3);
5403 
5404 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5405 			+ plaintext_pad_len;
5406 
5407 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5408 				(tdata->validCipherOffsetInBits.len >> 3);
5409 	/* Validate obuf */
5410 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5411 		ciphertext,
5412 		reference_ciphertext,
5413 		tdata->validCipherLenInBits.len,
5414 		"KASUMI Ciphertext data not as expected");
5415 
5416 	/* Validate obuf */
5417 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
5418 		ut_params->digest,
5419 		tdata->digest.data,
5420 		DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5421 		"KASUMI Generated auth tag not as expected");
5422 	return 0;
5423 }
5424 
5425 static int
5426 test_zuc_encryption(const struct wireless_test_data *tdata)
5427 {
5428 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5429 	struct crypto_unittest_params *ut_params = &unittest_params;
5430 
5431 	int retval;
5432 	uint8_t *plaintext, *ciphertext;
5433 	unsigned plaintext_pad_len;
5434 	unsigned plaintext_len;
5435 	struct rte_cryptodev_info dev_info;
5436 
5437 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5438 	uint64_t feat_flags = dev_info.feature_flags;
5439 
5440 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5441 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5442 		printf("Device doesn't support RAW data-path APIs.\n");
5443 		return -ENOTSUP;
5444 	}
5445 
5446 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5447 		return -ENOTSUP;
5448 
5449 	struct rte_cryptodev_sym_capability_idx cap_idx;
5450 
5451 	/* Check if device supports ZUC EEA3 */
5452 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5453 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5454 
5455 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5456 			&cap_idx) == NULL)
5457 		return -ENOTSUP;
5458 
5459 	/* Create ZUC session */
5460 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5461 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5462 					RTE_CRYPTO_CIPHER_ZUC_EEA3,
5463 					tdata->key.data, tdata->key.len,
5464 					tdata->cipher_iv.len);
5465 	if (retval < 0)
5466 		return retval;
5467 
5468 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5469 
5470 	/* Clear mbuf payload */
5471 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5472 	       rte_pktmbuf_tailroom(ut_params->ibuf));
5473 
5474 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5475 	/* Append data which is padded to a multiple */
5476 	/* of the algorithms block size */
5477 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5478 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5479 				plaintext_pad_len);
5480 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5481 
5482 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5483 
5484 	/* Create ZUC operation */
5485 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5486 					tdata->cipher_iv.len,
5487 					tdata->plaintext.len,
5488 					0);
5489 	if (retval < 0)
5490 		return retval;
5491 
5492 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5493 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5494 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5495 	else
5496 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5497 						ut_params->op);
5498 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5499 
5500 	ut_params->obuf = ut_params->op->sym->m_dst;
5501 	if (ut_params->obuf)
5502 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5503 	else
5504 		ciphertext = plaintext;
5505 
5506 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5507 
5508 	/* Validate obuf */
5509 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5510 		ciphertext,
5511 		tdata->ciphertext.data,
5512 		tdata->validCipherLenInBits.len,
5513 		"ZUC Ciphertext data not as expected");
5514 	return 0;
5515 }
5516 
5517 static int
5518 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
5519 {
5520 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5521 	struct crypto_unittest_params *ut_params = &unittest_params;
5522 
5523 	int retval;
5524 
5525 	unsigned int plaintext_pad_len;
5526 	unsigned int plaintext_len;
5527 	const uint8_t *ciphertext;
5528 	uint8_t ciphertext_buffer[2048];
5529 	struct rte_cryptodev_info dev_info;
5530 
5531 	struct rte_cryptodev_sym_capability_idx cap_idx;
5532 
5533 	/* Check if device supports ZUC EEA3 */
5534 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5535 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5536 
5537 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5538 			&cap_idx) == NULL)
5539 		return -ENOTSUP;
5540 
5541 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5542 		return -ENOTSUP;
5543 
5544 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5545 
5546 	uint64_t feat_flags = dev_info.feature_flags;
5547 
5548 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5549 		printf("Device doesn't support in-place scatter-gather. "
5550 				"Test Skipped.\n");
5551 		return -ENOTSUP;
5552 	}
5553 
5554 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5555 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5556 		printf("Device doesn't support RAW data-path APIs.\n");
5557 		return -ENOTSUP;
5558 	}
5559 
5560 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5561 
5562 	/* Append data which is padded to a multiple */
5563 	/* of the algorithms block size */
5564 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5565 
5566 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5567 			plaintext_pad_len, 10, 0);
5568 
5569 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5570 			tdata->plaintext.data);
5571 
5572 	/* Create ZUC session */
5573 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5574 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5575 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
5576 			tdata->key.data, tdata->key.len,
5577 			tdata->cipher_iv.len);
5578 	if (retval < 0)
5579 		return retval;
5580 
5581 	/* Clear mbuf payload */
5582 
5583 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
5584 
5585 	/* Create ZUC operation */
5586 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5587 			tdata->cipher_iv.len, tdata->plaintext.len,
5588 			0);
5589 	if (retval < 0)
5590 		return retval;
5591 
5592 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5593 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5594 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5595 	else
5596 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5597 						ut_params->op);
5598 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5599 
5600 	ut_params->obuf = ut_params->op->sym->m_dst;
5601 	if (ut_params->obuf)
5602 		ciphertext = rte_pktmbuf_read(ut_params->obuf,
5603 			0, plaintext_len, ciphertext_buffer);
5604 	else
5605 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
5606 			0, plaintext_len, ciphertext_buffer);
5607 
5608 	/* Validate obuf */
5609 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5610 
5611 	/* Validate obuf */
5612 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5613 		ciphertext,
5614 		tdata->ciphertext.data,
5615 		tdata->validCipherLenInBits.len,
5616 		"ZUC Ciphertext data not as expected");
5617 
5618 	return 0;
5619 }
5620 
5621 static int
5622 test_zuc_authentication(const struct wireless_test_data *tdata)
5623 {
5624 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5625 	struct crypto_unittest_params *ut_params = &unittest_params;
5626 
5627 	int retval;
5628 	unsigned plaintext_pad_len;
5629 	unsigned plaintext_len;
5630 	uint8_t *plaintext;
5631 
5632 	struct rte_cryptodev_sym_capability_idx cap_idx;
5633 	struct rte_cryptodev_info dev_info;
5634 
5635 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5636 	uint64_t feat_flags = dev_info.feature_flags;
5637 
5638 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
5639 			(tdata->validAuthLenInBits.len % 8 != 0)) {
5640 		printf("Device doesn't support NON-Byte Aligned Data.\n");
5641 		return -ENOTSUP;
5642 	}
5643 
5644 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5645 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5646 		printf("Device doesn't support RAW data-path APIs.\n");
5647 		return -ENOTSUP;
5648 	}
5649 
5650 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5651 		return -ENOTSUP;
5652 
5653 	/* Check if device supports ZUC EIA3 */
5654 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5655 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
5656 
5657 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5658 			&cap_idx) == NULL)
5659 		return -ENOTSUP;
5660 
5661 	/* Create ZUC session */
5662 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
5663 			tdata->key.data, tdata->key.len,
5664 			tdata->auth_iv.len, tdata->digest.len,
5665 			RTE_CRYPTO_AUTH_OP_GENERATE,
5666 			RTE_CRYPTO_AUTH_ZUC_EIA3);
5667 	if (retval < 0)
5668 		return retval;
5669 
5670 	/* alloc mbuf and set payload */
5671 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5672 
5673 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5674 	rte_pktmbuf_tailroom(ut_params->ibuf));
5675 
5676 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5677 	/* Append data which is padded to a multiple of */
5678 	/* the algorithms block size */
5679 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5680 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5681 				plaintext_pad_len);
5682 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5683 
5684 	/* Create ZUC operation */
5685 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
5686 			tdata->auth_iv.data, tdata->auth_iv.len,
5687 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5688 			tdata->validAuthLenInBits.len,
5689 			0);
5690 	if (retval < 0)
5691 		return retval;
5692 
5693 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5694 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5695 				ut_params->op, 0, 1, 1, 0);
5696 	else
5697 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5698 				ut_params->op);
5699 	ut_params->obuf = ut_params->op->sym->m_src;
5700 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5701 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5702 			+ plaintext_pad_len;
5703 
5704 	/* Validate obuf */
5705 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
5706 	ut_params->digest,
5707 	tdata->digest.data,
5708 	tdata->digest.len,
5709 	"ZUC Generated auth tag not as expected");
5710 
5711 	return 0;
5712 }
5713 
5714 static int
5715 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
5716 	uint8_t op_mode, uint8_t verify)
5717 {
5718 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5719 	struct crypto_unittest_params *ut_params = &unittest_params;
5720 
5721 	int retval;
5722 
5723 	uint8_t *plaintext = NULL, *ciphertext = NULL;
5724 	unsigned int plaintext_pad_len;
5725 	unsigned int plaintext_len;
5726 	unsigned int ciphertext_pad_len;
5727 	unsigned int ciphertext_len;
5728 
5729 	struct rte_cryptodev_info dev_info;
5730 	struct rte_cryptodev_sym_capability_idx cap_idx;
5731 
5732 	/* Check if device supports ZUC EIA3 */
5733 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5734 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
5735 
5736 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5737 			&cap_idx) == NULL)
5738 		return -ENOTSUP;
5739 
5740 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5741 
5742 	uint64_t feat_flags = dev_info.feature_flags;
5743 
5744 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5745 		printf("Device doesn't support digest encrypted.\n");
5746 		return -ENOTSUP;
5747 	}
5748 	if (op_mode == IN_PLACE) {
5749 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5750 			printf("Device doesn't support in-place scatter-gather "
5751 					"in both input and output mbufs.\n");
5752 			return -ENOTSUP;
5753 		}
5754 
5755 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5756 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5757 			printf("Device doesn't support RAW data-path APIs.\n");
5758 			return -ENOTSUP;
5759 		}
5760 	} else {
5761 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5762 			return -ENOTSUP;
5763 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5764 			printf("Device doesn't support out-of-place scatter-gather "
5765 					"in both input and output mbufs.\n");
5766 			return -ENOTSUP;
5767 		}
5768 	}
5769 
5770 	/* Create ZUC session */
5771 	retval = create_wireless_algo_auth_cipher_session(
5772 			ts_params->valid_devs[0],
5773 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5774 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5775 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5776 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5777 			RTE_CRYPTO_AUTH_ZUC_EIA3,
5778 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
5779 			tdata->key.data, tdata->key.len,
5780 			tdata->auth_iv.len, tdata->digest.len,
5781 			tdata->cipher_iv.len);
5782 
5783 	if (retval < 0)
5784 		return retval;
5785 
5786 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5787 	if (op_mode == OUT_OF_PLACE)
5788 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5789 
5790 	/* clear mbuf payload */
5791 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5792 		rte_pktmbuf_tailroom(ut_params->ibuf));
5793 	if (op_mode == OUT_OF_PLACE)
5794 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5795 			rte_pktmbuf_tailroom(ut_params->obuf));
5796 
5797 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5798 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5799 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5800 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5801 
5802 	if (verify) {
5803 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5804 					ciphertext_pad_len);
5805 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5806 		if (op_mode == OUT_OF_PLACE)
5807 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5808 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5809 			ciphertext_len);
5810 	} else {
5811 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5812 					plaintext_pad_len);
5813 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5814 		if (op_mode == OUT_OF_PLACE)
5815 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5816 		debug_hexdump(stdout, "plaintext:", plaintext,
5817 			plaintext_len);
5818 	}
5819 
5820 	/* Create ZUC operation */
5821 	retval = create_wireless_algo_auth_cipher_operation(
5822 		tdata->digest.data, tdata->digest.len,
5823 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5824 		tdata->auth_iv.data, tdata->auth_iv.len,
5825 		(tdata->digest.offset_bytes == 0 ?
5826 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5827 			: tdata->digest.offset_bytes),
5828 		tdata->validCipherLenInBits.len,
5829 		tdata->validCipherOffsetInBits.len,
5830 		tdata->validAuthLenInBits.len,
5831 		0,
5832 		op_mode, 0, verify);
5833 
5834 	if (retval < 0)
5835 		return retval;
5836 
5837 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5838 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5839 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5840 	else
5841 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5842 			ut_params->op);
5843 
5844 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5845 
5846 	ut_params->obuf = (op_mode == IN_PLACE ?
5847 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5848 
5849 
5850 	if (verify) {
5851 		if (ut_params->obuf)
5852 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5853 							uint8_t *);
5854 		else
5855 			plaintext = ciphertext;
5856 
5857 		debug_hexdump(stdout, "plaintext:", plaintext,
5858 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5859 		debug_hexdump(stdout, "plaintext expected:",
5860 			tdata->plaintext.data,
5861 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5862 	} else {
5863 		if (ut_params->obuf)
5864 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5865 							uint8_t *);
5866 		else
5867 			ciphertext = plaintext;
5868 
5869 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5870 			ciphertext_len);
5871 		debug_hexdump(stdout, "ciphertext expected:",
5872 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5873 
5874 		ut_params->digest = rte_pktmbuf_mtod(
5875 			ut_params->obuf, uint8_t *) +
5876 			(tdata->digest.offset_bytes == 0 ?
5877 			plaintext_pad_len : tdata->digest.offset_bytes);
5878 
5879 		debug_hexdump(stdout, "digest:", ut_params->digest,
5880 			tdata->digest.len);
5881 		debug_hexdump(stdout, "digest expected:",
5882 			tdata->digest.data, tdata->digest.len);
5883 	}
5884 
5885 	/* Validate obuf */
5886 	if (verify) {
5887 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5888 			plaintext,
5889 			tdata->plaintext.data,
5890 			tdata->plaintext.len >> 3,
5891 			"ZUC Plaintext data not as expected");
5892 	} else {
5893 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5894 			ciphertext,
5895 			tdata->ciphertext.data,
5896 			tdata->ciphertext.len >> 3,
5897 			"ZUC Ciphertext data not as expected");
5898 
5899 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5900 			ut_params->digest,
5901 			tdata->digest.data,
5902 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5903 			"ZUC Generated auth tag not as expected");
5904 	}
5905 	return 0;
5906 }
5907 
5908 static int
5909 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
5910 	uint8_t op_mode, uint8_t verify)
5911 {
5912 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5913 	struct crypto_unittest_params *ut_params = &unittest_params;
5914 
5915 	int retval;
5916 
5917 	const uint8_t *plaintext = NULL;
5918 	const uint8_t *ciphertext = NULL;
5919 	const uint8_t *digest = NULL;
5920 	unsigned int plaintext_pad_len;
5921 	unsigned int plaintext_len;
5922 	unsigned int ciphertext_pad_len;
5923 	unsigned int ciphertext_len;
5924 	uint8_t buffer[10000];
5925 	uint8_t digest_buffer[10000];
5926 
5927 	struct rte_cryptodev_info dev_info;
5928 	struct rte_cryptodev_sym_capability_idx cap_idx;
5929 
5930 	/* Check if device supports ZUC EIA3 */
5931 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5932 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
5933 
5934 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5935 			&cap_idx) == NULL)
5936 		return -ENOTSUP;
5937 
5938 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5939 
5940 	uint64_t feat_flags = dev_info.feature_flags;
5941 
5942 	if (op_mode == IN_PLACE) {
5943 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5944 			printf("Device doesn't support in-place scatter-gather "
5945 					"in both input and output mbufs.\n");
5946 			return -ENOTSUP;
5947 		}
5948 
5949 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5950 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5951 			printf("Device doesn't support RAW data-path APIs.\n");
5952 			return -ENOTSUP;
5953 		}
5954 	} else {
5955 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5956 			return -ENOTSUP;
5957 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5958 			printf("Device doesn't support out-of-place scatter-gather "
5959 					"in both input and output mbufs.\n");
5960 			return -ENOTSUP;
5961 		}
5962 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5963 			printf("Device doesn't support digest encrypted.\n");
5964 			return -ENOTSUP;
5965 		}
5966 	}
5967 
5968 	/* Create ZUC session */
5969 	retval = create_wireless_algo_auth_cipher_session(
5970 			ts_params->valid_devs[0],
5971 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5972 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5973 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5974 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5975 			RTE_CRYPTO_AUTH_ZUC_EIA3,
5976 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
5977 			tdata->key.data, tdata->key.len,
5978 			tdata->auth_iv.len, tdata->digest.len,
5979 			tdata->cipher_iv.len);
5980 
5981 	if (retval < 0)
5982 		return retval;
5983 
5984 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5985 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5986 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5987 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5988 
5989 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5990 			plaintext_pad_len, 15, 0);
5991 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5992 			"Failed to allocate input buffer in mempool");
5993 
5994 	if (op_mode == OUT_OF_PLACE) {
5995 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5996 				plaintext_pad_len, 15, 0);
5997 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5998 				"Failed to allocate output buffer in mempool");
5999 	}
6000 
6001 	if (verify) {
6002 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6003 			tdata->ciphertext.data);
6004 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6005 					ciphertext_len, buffer);
6006 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6007 			ciphertext_len);
6008 	} else {
6009 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6010 			tdata->plaintext.data);
6011 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6012 					plaintext_len, buffer);
6013 		debug_hexdump(stdout, "plaintext:", plaintext,
6014 			plaintext_len);
6015 	}
6016 	memset(buffer, 0, sizeof(buffer));
6017 
6018 	/* Create ZUC operation */
6019 	retval = create_wireless_algo_auth_cipher_operation(
6020 		tdata->digest.data, tdata->digest.len,
6021 		tdata->cipher_iv.data, tdata->cipher_iv.len,
6022 		NULL, 0,
6023 		(tdata->digest.offset_bytes == 0 ?
6024 		(verify ? ciphertext_pad_len : plaintext_pad_len)
6025 			: tdata->digest.offset_bytes),
6026 		tdata->validCipherLenInBits.len,
6027 		tdata->validCipherOffsetInBits.len,
6028 		tdata->validAuthLenInBits.len,
6029 		0,
6030 		op_mode, 1, verify);
6031 
6032 	if (retval < 0)
6033 		return retval;
6034 
6035 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6036 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6037 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6038 	else
6039 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6040 			ut_params->op);
6041 
6042 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6043 
6044 	ut_params->obuf = (op_mode == IN_PLACE ?
6045 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6046 
6047 	if (verify) {
6048 		if (ut_params->obuf)
6049 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6050 					plaintext_len, buffer);
6051 		else
6052 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6053 					plaintext_len, buffer);
6054 
6055 		debug_hexdump(stdout, "plaintext:", plaintext,
6056 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6057 		debug_hexdump(stdout, "plaintext expected:",
6058 			tdata->plaintext.data,
6059 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6060 	} else {
6061 		if (ut_params->obuf)
6062 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6063 					ciphertext_len, buffer);
6064 		else
6065 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6066 					ciphertext_len, buffer);
6067 
6068 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6069 			ciphertext_len);
6070 		debug_hexdump(stdout, "ciphertext expected:",
6071 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6072 
6073 		if (ut_params->obuf)
6074 			digest = rte_pktmbuf_read(ut_params->obuf,
6075 				(tdata->digest.offset_bytes == 0 ?
6076 				plaintext_pad_len : tdata->digest.offset_bytes),
6077 				tdata->digest.len, digest_buffer);
6078 		else
6079 			digest = rte_pktmbuf_read(ut_params->ibuf,
6080 				(tdata->digest.offset_bytes == 0 ?
6081 				plaintext_pad_len : tdata->digest.offset_bytes),
6082 				tdata->digest.len, digest_buffer);
6083 
6084 		debug_hexdump(stdout, "digest:", digest,
6085 			tdata->digest.len);
6086 		debug_hexdump(stdout, "digest expected:",
6087 			tdata->digest.data, tdata->digest.len);
6088 	}
6089 
6090 	/* Validate obuf */
6091 	if (verify) {
6092 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6093 			plaintext,
6094 			tdata->plaintext.data,
6095 			tdata->plaintext.len >> 3,
6096 			"ZUC Plaintext data not as expected");
6097 	} else {
6098 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6099 			ciphertext,
6100 			tdata->ciphertext.data,
6101 			tdata->validDataLenInBits.len,
6102 			"ZUC Ciphertext data not as expected");
6103 
6104 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6105 			digest,
6106 			tdata->digest.data,
6107 			DIGEST_BYTE_LENGTH_KASUMI_F9,
6108 			"ZUC Generated auth tag not as expected");
6109 	}
6110 	return 0;
6111 }
6112 
6113 static int
6114 test_kasumi_encryption_test_case_1(void)
6115 {
6116 	return test_kasumi_encryption(&kasumi_test_case_1);
6117 }
6118 
6119 static int
6120 test_kasumi_encryption_test_case_1_sgl(void)
6121 {
6122 	return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6123 }
6124 
6125 static int
6126 test_kasumi_encryption_test_case_1_oop(void)
6127 {
6128 	return test_kasumi_encryption_oop(&kasumi_test_case_1);
6129 }
6130 
6131 static int
6132 test_kasumi_encryption_test_case_1_oop_sgl(void)
6133 {
6134 	return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6135 }
6136 
6137 static int
6138 test_kasumi_encryption_test_case_2(void)
6139 {
6140 	return test_kasumi_encryption(&kasumi_test_case_2);
6141 }
6142 
6143 static int
6144 test_kasumi_encryption_test_case_3(void)
6145 {
6146 	return test_kasumi_encryption(&kasumi_test_case_3);
6147 }
6148 
6149 static int
6150 test_kasumi_encryption_test_case_4(void)
6151 {
6152 	return test_kasumi_encryption(&kasumi_test_case_4);
6153 }
6154 
6155 static int
6156 test_kasumi_encryption_test_case_5(void)
6157 {
6158 	return test_kasumi_encryption(&kasumi_test_case_5);
6159 }
6160 
6161 static int
6162 test_kasumi_decryption_test_case_1(void)
6163 {
6164 	return test_kasumi_decryption(&kasumi_test_case_1);
6165 }
6166 
6167 static int
6168 test_kasumi_decryption_test_case_1_oop(void)
6169 {
6170 	return test_kasumi_decryption_oop(&kasumi_test_case_1);
6171 }
6172 
6173 static int
6174 test_kasumi_decryption_test_case_2(void)
6175 {
6176 	return test_kasumi_decryption(&kasumi_test_case_2);
6177 }
6178 
6179 static int
6180 test_kasumi_decryption_test_case_3(void)
6181 {
6182 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6183 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6184 		return -ENOTSUP;
6185 	return test_kasumi_decryption(&kasumi_test_case_3);
6186 }
6187 
6188 static int
6189 test_kasumi_decryption_test_case_4(void)
6190 {
6191 	return test_kasumi_decryption(&kasumi_test_case_4);
6192 }
6193 
6194 static int
6195 test_kasumi_decryption_test_case_5(void)
6196 {
6197 	return test_kasumi_decryption(&kasumi_test_case_5);
6198 }
6199 static int
6200 test_snow3g_encryption_test_case_1(void)
6201 {
6202 	return test_snow3g_encryption(&snow3g_test_case_1);
6203 }
6204 
6205 static int
6206 test_snow3g_encryption_test_case_1_oop(void)
6207 {
6208 	return test_snow3g_encryption_oop(&snow3g_test_case_1);
6209 }
6210 
6211 static int
6212 test_snow3g_encryption_test_case_1_oop_sgl(void)
6213 {
6214 	return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6215 }
6216 
6217 
6218 static int
6219 test_snow3g_encryption_test_case_1_offset_oop(void)
6220 {
6221 	return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6222 }
6223 
6224 static int
6225 test_snow3g_encryption_test_case_2(void)
6226 {
6227 	return test_snow3g_encryption(&snow3g_test_case_2);
6228 }
6229 
6230 static int
6231 test_snow3g_encryption_test_case_3(void)
6232 {
6233 	return test_snow3g_encryption(&snow3g_test_case_3);
6234 }
6235 
6236 static int
6237 test_snow3g_encryption_test_case_4(void)
6238 {
6239 	return test_snow3g_encryption(&snow3g_test_case_4);
6240 }
6241 
6242 static int
6243 test_snow3g_encryption_test_case_5(void)
6244 {
6245 	return test_snow3g_encryption(&snow3g_test_case_5);
6246 }
6247 
6248 static int
6249 test_snow3g_decryption_test_case_1(void)
6250 {
6251 	return test_snow3g_decryption(&snow3g_test_case_1);
6252 }
6253 
6254 static int
6255 test_snow3g_decryption_test_case_1_oop(void)
6256 {
6257 	return test_snow3g_decryption_oop(&snow3g_test_case_1);
6258 }
6259 
6260 static int
6261 test_snow3g_decryption_test_case_2(void)
6262 {
6263 	return test_snow3g_decryption(&snow3g_test_case_2);
6264 }
6265 
6266 static int
6267 test_snow3g_decryption_test_case_3(void)
6268 {
6269 	return test_snow3g_decryption(&snow3g_test_case_3);
6270 }
6271 
6272 static int
6273 test_snow3g_decryption_test_case_4(void)
6274 {
6275 	return test_snow3g_decryption(&snow3g_test_case_4);
6276 }
6277 
6278 static int
6279 test_snow3g_decryption_test_case_5(void)
6280 {
6281 	return test_snow3g_decryption(&snow3g_test_case_5);
6282 }
6283 
6284 /*
6285  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6286  * Pattern digest from snow3g_test_data must be allocated as
6287  * 4 last bytes in plaintext.
6288  */
6289 static void
6290 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6291 		struct snow3g_hash_test_data *output)
6292 {
6293 	if ((pattern != NULL) && (output != NULL)) {
6294 		output->key.len = pattern->key.len;
6295 
6296 		memcpy(output->key.data,
6297 		pattern->key.data, pattern->key.len);
6298 
6299 		output->auth_iv.len = pattern->auth_iv.len;
6300 
6301 		memcpy(output->auth_iv.data,
6302 		pattern->auth_iv.data, pattern->auth_iv.len);
6303 
6304 		output->plaintext.len = pattern->plaintext.len;
6305 
6306 		memcpy(output->plaintext.data,
6307 		pattern->plaintext.data, pattern->plaintext.len >> 3);
6308 
6309 		output->digest.len = pattern->digest.len;
6310 
6311 		memcpy(output->digest.data,
6312 		&pattern->plaintext.data[pattern->digest.offset_bytes],
6313 		pattern->digest.len);
6314 
6315 		output->validAuthLenInBits.len =
6316 		pattern->validAuthLenInBits.len;
6317 	}
6318 }
6319 
6320 /*
6321  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6322  */
6323 static int
6324 test_snow3g_decryption_with_digest_test_case_1(void)
6325 {
6326 	struct snow3g_hash_test_data snow3g_hash_data;
6327 
6328 	/*
6329 	 * Function prepare data for hash veryfication test case.
6330 	 * Digest is allocated in 4 last bytes in plaintext, pattern.
6331 	 */
6332 	snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6333 
6334 	return test_snow3g_decryption(&snow3g_test_case_7) &
6335 			test_snow3g_authentication_verify(&snow3g_hash_data);
6336 }
6337 
6338 static int
6339 test_snow3g_cipher_auth_test_case_1(void)
6340 {
6341 	return test_snow3g_cipher_auth(&snow3g_test_case_3);
6342 }
6343 
6344 static int
6345 test_snow3g_auth_cipher_test_case_1(void)
6346 {
6347 	return test_snow3g_auth_cipher(
6348 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6349 }
6350 
6351 static int
6352 test_snow3g_auth_cipher_test_case_2(void)
6353 {
6354 	return test_snow3g_auth_cipher(
6355 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6356 }
6357 
6358 static int
6359 test_snow3g_auth_cipher_test_case_2_oop(void)
6360 {
6361 	return test_snow3g_auth_cipher(
6362 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6363 }
6364 
6365 static int
6366 test_snow3g_auth_cipher_part_digest_enc(void)
6367 {
6368 	return test_snow3g_auth_cipher(
6369 		&snow3g_auth_cipher_partial_digest_encryption,
6370 			IN_PLACE, 0);
6371 }
6372 
6373 static int
6374 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6375 {
6376 	return test_snow3g_auth_cipher(
6377 		&snow3g_auth_cipher_partial_digest_encryption,
6378 			OUT_OF_PLACE, 0);
6379 }
6380 
6381 static int
6382 test_snow3g_auth_cipher_test_case_3_sgl(void)
6383 {
6384 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6385 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6386 		return -ENOTSUP;
6387 	return test_snow3g_auth_cipher_sgl(
6388 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6389 }
6390 
6391 static int
6392 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6393 {
6394 	return test_snow3g_auth_cipher_sgl(
6395 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6396 }
6397 
6398 static int
6399 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6400 {
6401 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6402 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6403 		return -ENOTSUP;
6404 	return test_snow3g_auth_cipher_sgl(
6405 		&snow3g_auth_cipher_partial_digest_encryption,
6406 			IN_PLACE, 0);
6407 }
6408 
6409 static int
6410 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6411 {
6412 	return test_snow3g_auth_cipher_sgl(
6413 		&snow3g_auth_cipher_partial_digest_encryption,
6414 			OUT_OF_PLACE, 0);
6415 }
6416 
6417 static int
6418 test_snow3g_auth_cipher_verify_test_case_1(void)
6419 {
6420 	return test_snow3g_auth_cipher(
6421 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6422 }
6423 
6424 static int
6425 test_snow3g_auth_cipher_verify_test_case_2(void)
6426 {
6427 	return test_snow3g_auth_cipher(
6428 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6429 }
6430 
6431 static int
6432 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6433 {
6434 	return test_snow3g_auth_cipher(
6435 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6436 }
6437 
6438 static int
6439 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6440 {
6441 	return test_snow3g_auth_cipher(
6442 		&snow3g_auth_cipher_partial_digest_encryption,
6443 			IN_PLACE, 1);
6444 }
6445 
6446 static int
6447 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
6448 {
6449 	return test_snow3g_auth_cipher(
6450 		&snow3g_auth_cipher_partial_digest_encryption,
6451 			OUT_OF_PLACE, 1);
6452 }
6453 
6454 static int
6455 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
6456 {
6457 	return test_snow3g_auth_cipher_sgl(
6458 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
6459 }
6460 
6461 static int
6462 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
6463 {
6464 	return test_snow3g_auth_cipher_sgl(
6465 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
6466 }
6467 
6468 static int
6469 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
6470 {
6471 	return test_snow3g_auth_cipher_sgl(
6472 		&snow3g_auth_cipher_partial_digest_encryption,
6473 			IN_PLACE, 1);
6474 }
6475 
6476 static int
6477 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
6478 {
6479 	return test_snow3g_auth_cipher_sgl(
6480 		&snow3g_auth_cipher_partial_digest_encryption,
6481 			OUT_OF_PLACE, 1);
6482 }
6483 
6484 static int
6485 test_snow3g_auth_cipher_with_digest_test_case_1(void)
6486 {
6487 	return test_snow3g_auth_cipher(
6488 		&snow3g_test_case_7, IN_PLACE, 0);
6489 }
6490 
6491 static int
6492 test_kasumi_auth_cipher_test_case_1(void)
6493 {
6494 	return test_kasumi_auth_cipher(
6495 		&kasumi_test_case_3, IN_PLACE, 0);
6496 }
6497 
6498 static int
6499 test_kasumi_auth_cipher_test_case_2(void)
6500 {
6501 	return test_kasumi_auth_cipher(
6502 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6503 }
6504 
6505 static int
6506 test_kasumi_auth_cipher_test_case_2_oop(void)
6507 {
6508 	return test_kasumi_auth_cipher(
6509 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6510 }
6511 
6512 static int
6513 test_kasumi_auth_cipher_test_case_2_sgl(void)
6514 {
6515 	return test_kasumi_auth_cipher_sgl(
6516 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6517 }
6518 
6519 static int
6520 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
6521 {
6522 	return test_kasumi_auth_cipher_sgl(
6523 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6524 }
6525 
6526 static int
6527 test_kasumi_auth_cipher_verify_test_case_1(void)
6528 {
6529 	return test_kasumi_auth_cipher(
6530 		&kasumi_test_case_3, IN_PLACE, 1);
6531 }
6532 
6533 static int
6534 test_kasumi_auth_cipher_verify_test_case_2(void)
6535 {
6536 	return test_kasumi_auth_cipher(
6537 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6538 }
6539 
6540 static int
6541 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
6542 {
6543 	return test_kasumi_auth_cipher(
6544 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6545 }
6546 
6547 static int
6548 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
6549 {
6550 	return test_kasumi_auth_cipher_sgl(
6551 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6552 }
6553 
6554 static int
6555 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
6556 {
6557 	return test_kasumi_auth_cipher_sgl(
6558 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6559 }
6560 
6561 static int
6562 test_kasumi_cipher_auth_test_case_1(void)
6563 {
6564 	return test_kasumi_cipher_auth(&kasumi_test_case_6);
6565 }
6566 
6567 static int
6568 test_zuc_encryption_test_case_1(void)
6569 {
6570 	return test_zuc_encryption(&zuc_test_case_cipher_193b);
6571 }
6572 
6573 static int
6574 test_zuc_encryption_test_case_2(void)
6575 {
6576 	return test_zuc_encryption(&zuc_test_case_cipher_800b);
6577 }
6578 
6579 static int
6580 test_zuc_encryption_test_case_3(void)
6581 {
6582 	return test_zuc_encryption(&zuc_test_case_cipher_1570b);
6583 }
6584 
6585 static int
6586 test_zuc_encryption_test_case_4(void)
6587 {
6588 	return test_zuc_encryption(&zuc_test_case_cipher_2798b);
6589 }
6590 
6591 static int
6592 test_zuc_encryption_test_case_5(void)
6593 {
6594 	return test_zuc_encryption(&zuc_test_case_cipher_4019b);
6595 }
6596 
6597 static int
6598 test_zuc_encryption_test_case_6_sgl(void)
6599 {
6600 	return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
6601 }
6602 
6603 static int
6604 test_zuc_hash_generate_test_case_1(void)
6605 {
6606 	return test_zuc_authentication(&zuc_test_case_auth_1b);
6607 }
6608 
6609 static int
6610 test_zuc_hash_generate_test_case_2(void)
6611 {
6612 	return test_zuc_authentication(&zuc_test_case_auth_90b);
6613 }
6614 
6615 static int
6616 test_zuc_hash_generate_test_case_3(void)
6617 {
6618 	return test_zuc_authentication(&zuc_test_case_auth_577b);
6619 }
6620 
6621 static int
6622 test_zuc_hash_generate_test_case_4(void)
6623 {
6624 	return test_zuc_authentication(&zuc_test_case_auth_2079b);
6625 }
6626 
6627 static int
6628 test_zuc_hash_generate_test_case_5(void)
6629 {
6630 	return test_zuc_authentication(&zuc_test_auth_5670b);
6631 }
6632 
6633 static int
6634 test_zuc_hash_generate_test_case_6(void)
6635 {
6636 	return test_zuc_authentication(&zuc_test_case_auth_128b);
6637 }
6638 
6639 static int
6640 test_zuc_hash_generate_test_case_7(void)
6641 {
6642 	return test_zuc_authentication(&zuc_test_case_auth_2080b);
6643 }
6644 
6645 static int
6646 test_zuc_hash_generate_test_case_8(void)
6647 {
6648 	return test_zuc_authentication(&zuc_test_case_auth_584b);
6649 }
6650 
6651 static int
6652 test_zuc_cipher_auth_test_case_1(void)
6653 {
6654 	return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
6655 }
6656 
6657 static int
6658 test_zuc_cipher_auth_test_case_2(void)
6659 {
6660 	return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
6661 }
6662 
6663 static int
6664 test_zuc_auth_cipher_test_case_1(void)
6665 {
6666 	return test_zuc_auth_cipher(
6667 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
6668 }
6669 
6670 static int
6671 test_zuc_auth_cipher_test_case_1_oop(void)
6672 {
6673 	return test_zuc_auth_cipher(
6674 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
6675 }
6676 
6677 static int
6678 test_zuc_auth_cipher_test_case_1_sgl(void)
6679 {
6680 	return test_zuc_auth_cipher_sgl(
6681 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
6682 }
6683 
6684 static int
6685 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
6686 {
6687 	return test_zuc_auth_cipher_sgl(
6688 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
6689 }
6690 
6691 static int
6692 test_zuc_auth_cipher_verify_test_case_1(void)
6693 {
6694 	return test_zuc_auth_cipher(
6695 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
6696 }
6697 
6698 static int
6699 test_zuc_auth_cipher_verify_test_case_1_oop(void)
6700 {
6701 	return test_zuc_auth_cipher(
6702 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
6703 }
6704 
6705 static int
6706 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
6707 {
6708 	return test_zuc_auth_cipher_sgl(
6709 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
6710 }
6711 
6712 static int
6713 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
6714 {
6715 	return test_zuc_auth_cipher_sgl(
6716 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
6717 }
6718 
6719 static int
6720 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
6721 {
6722 	uint8_t dev_id = testsuite_params.valid_devs[0];
6723 
6724 	struct rte_cryptodev_sym_capability_idx cap_idx;
6725 
6726 	/* Check if device supports particular cipher algorithm */
6727 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6728 	cap_idx.algo.cipher = tdata->cipher_algo;
6729 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
6730 		return -ENOTSUP;
6731 
6732 	/* Check if device supports particular hash algorithm */
6733 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6734 	cap_idx.algo.auth = tdata->auth_algo;
6735 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
6736 		return -ENOTSUP;
6737 
6738 	return 0;
6739 }
6740 
6741 static int
6742 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
6743 	uint8_t op_mode, uint8_t verify)
6744 {
6745 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6746 	struct crypto_unittest_params *ut_params = &unittest_params;
6747 
6748 	int retval;
6749 
6750 	uint8_t *plaintext = NULL, *ciphertext = NULL;
6751 	unsigned int plaintext_pad_len;
6752 	unsigned int plaintext_len;
6753 	unsigned int ciphertext_pad_len;
6754 	unsigned int ciphertext_len;
6755 
6756 	struct rte_cryptodev_info dev_info;
6757 	struct rte_crypto_op *op;
6758 
6759 	/* Check if device supports particular algorithms separately */
6760 	if (test_mixed_check_if_unsupported(tdata))
6761 		return -ENOTSUP;
6762 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6763 		return -ENOTSUP;
6764 
6765 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6766 
6767 	uint64_t feat_flags = dev_info.feature_flags;
6768 
6769 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6770 		printf("Device doesn't support digest encrypted.\n");
6771 		return -ENOTSUP;
6772 	}
6773 
6774 	if (op_mode == OUT_OF_PLACE)
6775 		return -ENOTSUP;
6776 
6777 	/* Create the session */
6778 	if (verify)
6779 		retval = create_wireless_algo_cipher_auth_session(
6780 				ts_params->valid_devs[0],
6781 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
6782 				RTE_CRYPTO_AUTH_OP_VERIFY,
6783 				tdata->auth_algo,
6784 				tdata->cipher_algo,
6785 				tdata->auth_key.data, tdata->auth_key.len,
6786 				tdata->auth_iv.len, tdata->digest_enc.len,
6787 				tdata->cipher_iv.len);
6788 	else
6789 		retval = create_wireless_algo_auth_cipher_session(
6790 				ts_params->valid_devs[0],
6791 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6792 				RTE_CRYPTO_AUTH_OP_GENERATE,
6793 				tdata->auth_algo,
6794 				tdata->cipher_algo,
6795 				tdata->auth_key.data, tdata->auth_key.len,
6796 				tdata->auth_iv.len, tdata->digest_enc.len,
6797 				tdata->cipher_iv.len);
6798 	if (retval < 0)
6799 		return retval;
6800 
6801 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6802 	if (op_mode == OUT_OF_PLACE)
6803 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6804 
6805 	/* clear mbuf payload */
6806 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6807 		rte_pktmbuf_tailroom(ut_params->ibuf));
6808 	if (op_mode == OUT_OF_PLACE) {
6809 
6810 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6811 				rte_pktmbuf_tailroom(ut_params->obuf));
6812 	}
6813 
6814 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
6815 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
6816 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6817 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6818 
6819 	if (verify) {
6820 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6821 				ciphertext_pad_len);
6822 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6823 		if (op_mode == OUT_OF_PLACE)
6824 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6825 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6826 				ciphertext_len);
6827 	} else {
6828 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6829 				plaintext_pad_len);
6830 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6831 		if (op_mode == OUT_OF_PLACE)
6832 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
6833 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
6834 	}
6835 
6836 	/* Create the operation */
6837 	retval = create_wireless_algo_auth_cipher_operation(
6838 			tdata->digest_enc.data, tdata->digest_enc.len,
6839 			tdata->cipher_iv.data, tdata->cipher_iv.len,
6840 			tdata->auth_iv.data, tdata->auth_iv.len,
6841 			(tdata->digest_enc.offset == 0 ?
6842 				plaintext_pad_len
6843 				: tdata->digest_enc.offset),
6844 			tdata->validCipherLen.len_bits,
6845 			tdata->cipher.offset_bits,
6846 			tdata->validAuthLen.len_bits,
6847 			tdata->auth.offset_bits,
6848 			op_mode, 0, verify);
6849 
6850 	if (retval < 0)
6851 		return retval;
6852 
6853 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
6854 
6855 	/* Check if the op failed because the device doesn't */
6856 	/* support this particular combination of algorithms */
6857 	if (op == NULL && ut_params->op->status ==
6858 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
6859 		printf("Device doesn't support this mixed combination. "
6860 				"Test Skipped.\n");
6861 		return -ENOTSUP;
6862 	}
6863 	ut_params->op = op;
6864 
6865 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6866 
6867 	ut_params->obuf = (op_mode == IN_PLACE ?
6868 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6869 
6870 	if (verify) {
6871 		if (ut_params->obuf)
6872 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6873 							uint8_t *);
6874 		else
6875 			plaintext = ciphertext +
6876 					(tdata->cipher.offset_bits >> 3);
6877 
6878 		debug_hexdump(stdout, "plaintext:", plaintext,
6879 				tdata->plaintext.len_bits >> 3);
6880 		debug_hexdump(stdout, "plaintext expected:",
6881 				tdata->plaintext.data,
6882 				tdata->plaintext.len_bits >> 3);
6883 	} else {
6884 		if (ut_params->obuf)
6885 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6886 					uint8_t *);
6887 		else
6888 			ciphertext = plaintext;
6889 
6890 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6891 				ciphertext_len);
6892 		debug_hexdump(stdout, "ciphertext expected:",
6893 				tdata->ciphertext.data,
6894 				tdata->ciphertext.len_bits >> 3);
6895 
6896 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6897 				+ (tdata->digest_enc.offset == 0 ?
6898 		plaintext_pad_len : tdata->digest_enc.offset);
6899 
6900 		debug_hexdump(stdout, "digest:", ut_params->digest,
6901 				tdata->digest_enc.len);
6902 		debug_hexdump(stdout, "digest expected:",
6903 				tdata->digest_enc.data,
6904 				tdata->digest_enc.len);
6905 	}
6906 
6907 	/* Validate obuf */
6908 	if (verify) {
6909 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6910 				plaintext,
6911 				tdata->plaintext.data,
6912 				tdata->plaintext.len_bits >> 3,
6913 				"Plaintext data not as expected");
6914 	} else {
6915 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6916 				ciphertext,
6917 				tdata->ciphertext.data,
6918 				tdata->validDataLen.len_bits,
6919 				"Ciphertext data not as expected");
6920 
6921 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6922 				ut_params->digest,
6923 				tdata->digest_enc.data,
6924 				DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
6925 				"Generated auth tag not as expected");
6926 	}
6927 
6928 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6929 			"crypto op processing failed");
6930 
6931 	return 0;
6932 }
6933 
6934 static int
6935 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
6936 	uint8_t op_mode, uint8_t verify)
6937 {
6938 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6939 	struct crypto_unittest_params *ut_params = &unittest_params;
6940 
6941 	int retval;
6942 
6943 	const uint8_t *plaintext = NULL;
6944 	const uint8_t *ciphertext = NULL;
6945 	const uint8_t *digest = NULL;
6946 	unsigned int plaintext_pad_len;
6947 	unsigned int plaintext_len;
6948 	unsigned int ciphertext_pad_len;
6949 	unsigned int ciphertext_len;
6950 	uint8_t buffer[10000];
6951 	uint8_t digest_buffer[10000];
6952 
6953 	struct rte_cryptodev_info dev_info;
6954 	struct rte_crypto_op *op;
6955 
6956 	/* Check if device supports particular algorithms */
6957 	if (test_mixed_check_if_unsupported(tdata))
6958 		return -ENOTSUP;
6959 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6960 		return -ENOTSUP;
6961 
6962 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6963 
6964 	uint64_t feat_flags = dev_info.feature_flags;
6965 
6966 	if (op_mode == IN_PLACE) {
6967 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6968 			printf("Device doesn't support in-place scatter-gather "
6969 					"in both input and output mbufs.\n");
6970 			return -ENOTSUP;
6971 		}
6972 	} else {
6973 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6974 			printf("Device doesn't support out-of-place scatter-gather "
6975 					"in both input and output mbufs.\n");
6976 			return -ENOTSUP;
6977 		}
6978 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6979 			printf("Device doesn't support digest encrypted.\n");
6980 			return -ENOTSUP;
6981 		}
6982 	}
6983 
6984 	/* Create the session */
6985 	if (verify)
6986 		retval = create_wireless_algo_cipher_auth_session(
6987 				ts_params->valid_devs[0],
6988 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
6989 				RTE_CRYPTO_AUTH_OP_VERIFY,
6990 				tdata->auth_algo,
6991 				tdata->cipher_algo,
6992 				tdata->auth_key.data, tdata->auth_key.len,
6993 				tdata->auth_iv.len, tdata->digest_enc.len,
6994 				tdata->cipher_iv.len);
6995 	else
6996 		retval = create_wireless_algo_auth_cipher_session(
6997 				ts_params->valid_devs[0],
6998 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6999 				RTE_CRYPTO_AUTH_OP_GENERATE,
7000 				tdata->auth_algo,
7001 				tdata->cipher_algo,
7002 				tdata->auth_key.data, tdata->auth_key.len,
7003 				tdata->auth_iv.len, tdata->digest_enc.len,
7004 				tdata->cipher_iv.len);
7005 	if (retval < 0)
7006 		return retval;
7007 
7008 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7009 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7010 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7011 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7012 
7013 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
7014 			ciphertext_pad_len, 15, 0);
7015 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7016 			"Failed to allocate input buffer in mempool");
7017 
7018 	if (op_mode == OUT_OF_PLACE) {
7019 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
7020 				plaintext_pad_len, 15, 0);
7021 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
7022 				"Failed to allocate output buffer in mempool");
7023 	}
7024 
7025 	if (verify) {
7026 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
7027 			tdata->ciphertext.data);
7028 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7029 					ciphertext_len, buffer);
7030 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7031 			ciphertext_len);
7032 	} else {
7033 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
7034 			tdata->plaintext.data);
7035 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7036 					plaintext_len, buffer);
7037 		debug_hexdump(stdout, "plaintext:", plaintext,
7038 			plaintext_len);
7039 	}
7040 	memset(buffer, 0, sizeof(buffer));
7041 
7042 	/* Create the operation */
7043 	retval = create_wireless_algo_auth_cipher_operation(
7044 			tdata->digest_enc.data, tdata->digest_enc.len,
7045 			tdata->cipher_iv.data, tdata->cipher_iv.len,
7046 			tdata->auth_iv.data, tdata->auth_iv.len,
7047 			(tdata->digest_enc.offset == 0 ?
7048 				plaintext_pad_len
7049 				: tdata->digest_enc.offset),
7050 			tdata->validCipherLen.len_bits,
7051 			tdata->cipher.offset_bits,
7052 			tdata->validAuthLen.len_bits,
7053 			tdata->auth.offset_bits,
7054 			op_mode, 1, verify);
7055 
7056 	if (retval < 0)
7057 		return retval;
7058 
7059 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7060 
7061 	/* Check if the op failed because the device doesn't */
7062 	/* support this particular combination of algorithms */
7063 	if (op == NULL && ut_params->op->status ==
7064 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7065 		printf("Device doesn't support this mixed combination. "
7066 				"Test Skipped.\n");
7067 		return -ENOTSUP;
7068 	}
7069 	ut_params->op = op;
7070 
7071 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7072 
7073 	ut_params->obuf = (op_mode == IN_PLACE ?
7074 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7075 
7076 	if (verify) {
7077 		if (ut_params->obuf)
7078 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
7079 					plaintext_len, buffer);
7080 		else
7081 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7082 					plaintext_len, buffer);
7083 
7084 		debug_hexdump(stdout, "plaintext:", plaintext,
7085 				(tdata->plaintext.len_bits >> 3) -
7086 				tdata->digest_enc.len);
7087 		debug_hexdump(stdout, "plaintext expected:",
7088 				tdata->plaintext.data,
7089 				(tdata->plaintext.len_bits >> 3) -
7090 				tdata->digest_enc.len);
7091 	} else {
7092 		if (ut_params->obuf)
7093 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7094 					ciphertext_len, buffer);
7095 		else
7096 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7097 					ciphertext_len, buffer);
7098 
7099 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7100 			ciphertext_len);
7101 		debug_hexdump(stdout, "ciphertext expected:",
7102 			tdata->ciphertext.data,
7103 			tdata->ciphertext.len_bits >> 3);
7104 
7105 		if (ut_params->obuf)
7106 			digest = rte_pktmbuf_read(ut_params->obuf,
7107 					(tdata->digest_enc.offset == 0 ?
7108 						plaintext_pad_len :
7109 						tdata->digest_enc.offset),
7110 					tdata->digest_enc.len, digest_buffer);
7111 		else
7112 			digest = rte_pktmbuf_read(ut_params->ibuf,
7113 					(tdata->digest_enc.offset == 0 ?
7114 						plaintext_pad_len :
7115 						tdata->digest_enc.offset),
7116 					tdata->digest_enc.len, digest_buffer);
7117 
7118 		debug_hexdump(stdout, "digest:", digest,
7119 				tdata->digest_enc.len);
7120 		debug_hexdump(stdout, "digest expected:",
7121 				tdata->digest_enc.data, tdata->digest_enc.len);
7122 	}
7123 
7124 	/* Validate obuf */
7125 	if (verify) {
7126 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7127 				plaintext,
7128 				tdata->plaintext.data,
7129 				tdata->plaintext.len_bits >> 3,
7130 				"Plaintext data not as expected");
7131 	} else {
7132 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7133 				ciphertext,
7134 				tdata->ciphertext.data,
7135 				tdata->validDataLen.len_bits,
7136 				"Ciphertext data not as expected");
7137 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
7138 				digest,
7139 				tdata->digest_enc.data,
7140 				tdata->digest_enc.len,
7141 				"Generated auth tag not as expected");
7142 	}
7143 
7144 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7145 			"crypto op processing failed");
7146 
7147 	return 0;
7148 }
7149 
7150 /** AUTH AES CMAC + CIPHER AES CTR */
7151 
7152 static int
7153 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7154 {
7155 	return test_mixed_auth_cipher(
7156 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7157 }
7158 
7159 static int
7160 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7161 {
7162 	return test_mixed_auth_cipher(
7163 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7164 }
7165 
7166 static int
7167 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7168 {
7169 	return test_mixed_auth_cipher_sgl(
7170 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7171 }
7172 
7173 static int
7174 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7175 {
7176 	return test_mixed_auth_cipher_sgl(
7177 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7178 }
7179 
7180 static int
7181 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7182 {
7183 	return test_mixed_auth_cipher(
7184 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7185 }
7186 
7187 static int
7188 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7189 {
7190 	return test_mixed_auth_cipher(
7191 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7192 }
7193 
7194 static int
7195 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7196 {
7197 	return test_mixed_auth_cipher_sgl(
7198 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7199 }
7200 
7201 static int
7202 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7203 {
7204 	return test_mixed_auth_cipher_sgl(
7205 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7206 }
7207 
7208 /** MIXED AUTH + CIPHER */
7209 
7210 static int
7211 test_auth_zuc_cipher_snow_test_case_1(void)
7212 {
7213 	return test_mixed_auth_cipher(
7214 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7215 }
7216 
7217 static int
7218 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7219 {
7220 	return test_mixed_auth_cipher(
7221 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7222 }
7223 
7224 static int
7225 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7226 {
7227 	return test_mixed_auth_cipher(
7228 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7229 }
7230 
7231 static int
7232 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7233 {
7234 	return test_mixed_auth_cipher(
7235 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7236 }
7237 
7238 static int
7239 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7240 {
7241 	return test_mixed_auth_cipher(
7242 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7243 }
7244 
7245 static int
7246 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7247 {
7248 	return test_mixed_auth_cipher(
7249 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7250 }
7251 
7252 static int
7253 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7254 {
7255 	return test_mixed_auth_cipher(
7256 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7257 }
7258 
7259 static int
7260 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7261 {
7262 	return test_mixed_auth_cipher(
7263 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7264 }
7265 
7266 static int
7267 test_auth_snow_cipher_zuc_test_case_1(void)
7268 {
7269 	return test_mixed_auth_cipher(
7270 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7271 }
7272 
7273 static int
7274 test_verify_auth_snow_cipher_zuc_test_case_1(void)
7275 {
7276 	return test_mixed_auth_cipher(
7277 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7278 }
7279 
7280 static int
7281 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
7282 {
7283 	return test_mixed_auth_cipher(
7284 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7285 }
7286 
7287 static int
7288 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
7289 {
7290 	return test_mixed_auth_cipher(
7291 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7292 }
7293 
7294 static int
7295 test_auth_null_cipher_snow_test_case_1(void)
7296 {
7297 	return test_mixed_auth_cipher(
7298 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7299 }
7300 
7301 static int
7302 test_verify_auth_null_cipher_snow_test_case_1(void)
7303 {
7304 	return test_mixed_auth_cipher(
7305 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7306 }
7307 
7308 static int
7309 test_auth_null_cipher_zuc_test_case_1(void)
7310 {
7311 	return test_mixed_auth_cipher(
7312 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7313 }
7314 
7315 static int
7316 test_verify_auth_null_cipher_zuc_test_case_1(void)
7317 {
7318 	return test_mixed_auth_cipher(
7319 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7320 }
7321 
7322 static int
7323 test_auth_snow_cipher_null_test_case_1(void)
7324 {
7325 	return test_mixed_auth_cipher(
7326 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7327 }
7328 
7329 static int
7330 test_verify_auth_snow_cipher_null_test_case_1(void)
7331 {
7332 	return test_mixed_auth_cipher(
7333 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7334 }
7335 
7336 static int
7337 test_auth_zuc_cipher_null_test_case_1(void)
7338 {
7339 	return test_mixed_auth_cipher(
7340 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7341 }
7342 
7343 static int
7344 test_verify_auth_zuc_cipher_null_test_case_1(void)
7345 {
7346 	return test_mixed_auth_cipher(
7347 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7348 }
7349 
7350 static int
7351 test_auth_null_cipher_aes_ctr_test_case_1(void)
7352 {
7353 	return test_mixed_auth_cipher(
7354 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7355 }
7356 
7357 static int
7358 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
7359 {
7360 	return test_mixed_auth_cipher(
7361 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7362 }
7363 
7364 static int
7365 test_auth_aes_cmac_cipher_null_test_case_1(void)
7366 {
7367 	return test_mixed_auth_cipher(
7368 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7369 }
7370 
7371 static int
7372 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
7373 {
7374 	return test_mixed_auth_cipher(
7375 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7376 }
7377 
7378 /* ***** AEAD algorithm Tests ***** */
7379 
7380 static int
7381 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
7382 		enum rte_crypto_aead_operation op,
7383 		const uint8_t *key, const uint8_t key_len,
7384 		const uint16_t aad_len, const uint8_t auth_len,
7385 		uint8_t iv_len)
7386 {
7387 	uint8_t aead_key[key_len];
7388 
7389 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7390 	struct crypto_unittest_params *ut_params = &unittest_params;
7391 
7392 	memcpy(aead_key, key, key_len);
7393 
7394 	/* Setup AEAD Parameters */
7395 	ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7396 	ut_params->aead_xform.next = NULL;
7397 	ut_params->aead_xform.aead.algo = algo;
7398 	ut_params->aead_xform.aead.op = op;
7399 	ut_params->aead_xform.aead.key.data = aead_key;
7400 	ut_params->aead_xform.aead.key.length = key_len;
7401 	ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
7402 	ut_params->aead_xform.aead.iv.length = iv_len;
7403 	ut_params->aead_xform.aead.digest_length = auth_len;
7404 	ut_params->aead_xform.aead.aad_length = aad_len;
7405 
7406 	debug_hexdump(stdout, "key:", key, key_len);
7407 
7408 	/* Create Crypto session*/
7409 	ut_params->sess = rte_cryptodev_sym_session_create(
7410 			ts_params->session_mpool);
7411 
7412 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7413 			&ut_params->aead_xform,
7414 			ts_params->session_priv_mpool);
7415 
7416 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7417 
7418 	return 0;
7419 }
7420 
7421 static int
7422 create_aead_xform(struct rte_crypto_op *op,
7423 		enum rte_crypto_aead_algorithm algo,
7424 		enum rte_crypto_aead_operation aead_op,
7425 		uint8_t *key, const uint8_t key_len,
7426 		const uint8_t aad_len, const uint8_t auth_len,
7427 		uint8_t iv_len)
7428 {
7429 	TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
7430 			"failed to allocate space for crypto transform");
7431 
7432 	struct rte_crypto_sym_op *sym_op = op->sym;
7433 
7434 	/* Setup AEAD Parameters */
7435 	sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
7436 	sym_op->xform->next = NULL;
7437 	sym_op->xform->aead.algo = algo;
7438 	sym_op->xform->aead.op = aead_op;
7439 	sym_op->xform->aead.key.data = key;
7440 	sym_op->xform->aead.key.length = key_len;
7441 	sym_op->xform->aead.iv.offset = IV_OFFSET;
7442 	sym_op->xform->aead.iv.length = iv_len;
7443 	sym_op->xform->aead.digest_length = auth_len;
7444 	sym_op->xform->aead.aad_length = aad_len;
7445 
7446 	debug_hexdump(stdout, "key:", key, key_len);
7447 
7448 	return 0;
7449 }
7450 
7451 static int
7452 create_aead_operation(enum rte_crypto_aead_operation op,
7453 		const struct aead_test_data *tdata)
7454 {
7455 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7456 	struct crypto_unittest_params *ut_params = &unittest_params;
7457 
7458 	uint8_t *plaintext, *ciphertext;
7459 	unsigned int aad_pad_len, plaintext_pad_len;
7460 
7461 	/* Generate Crypto op data structure */
7462 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7463 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7464 	TEST_ASSERT_NOT_NULL(ut_params->op,
7465 			"Failed to allocate symmetric crypto operation struct");
7466 
7467 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7468 
7469 	/* Append aad data */
7470 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
7471 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
7472 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7473 				aad_pad_len);
7474 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7475 				"no room to append aad");
7476 
7477 		sym_op->aead.aad.phys_addr =
7478 				rte_pktmbuf_iova(ut_params->ibuf);
7479 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
7480 		memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
7481 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7482 			tdata->aad.len);
7483 
7484 		/* Append IV at the end of the crypto operation*/
7485 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7486 				uint8_t *, IV_OFFSET);
7487 
7488 		/* Copy IV 1 byte after the IV pointer, according to the API */
7489 		rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
7490 		debug_hexdump(stdout, "iv:", iv_ptr,
7491 			tdata->iv.len);
7492 	} else {
7493 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
7494 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7495 				aad_pad_len);
7496 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7497 				"no room to append aad");
7498 
7499 		sym_op->aead.aad.phys_addr =
7500 				rte_pktmbuf_iova(ut_params->ibuf);
7501 		memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
7502 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7503 			tdata->aad.len);
7504 
7505 		/* Append IV at the end of the crypto operation*/
7506 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7507 				uint8_t *, IV_OFFSET);
7508 
7509 		if (tdata->iv.len == 0) {
7510 			rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
7511 			debug_hexdump(stdout, "iv:", iv_ptr,
7512 				AES_GCM_J0_LENGTH);
7513 		} else {
7514 			rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
7515 			debug_hexdump(stdout, "iv:", iv_ptr,
7516 				tdata->iv.len);
7517 		}
7518 	}
7519 
7520 	/* Append plaintext/ciphertext */
7521 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7522 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7523 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7524 				plaintext_pad_len);
7525 		TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7526 
7527 		memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
7528 		debug_hexdump(stdout, "plaintext:", plaintext,
7529 				tdata->plaintext.len);
7530 
7531 		if (ut_params->obuf) {
7532 			ciphertext = (uint8_t *)rte_pktmbuf_append(
7533 					ut_params->obuf,
7534 					plaintext_pad_len + aad_pad_len);
7535 			TEST_ASSERT_NOT_NULL(ciphertext,
7536 					"no room to append ciphertext");
7537 
7538 			memset(ciphertext + aad_pad_len, 0,
7539 					tdata->ciphertext.len);
7540 		}
7541 	} else {
7542 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
7543 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7544 				plaintext_pad_len);
7545 		TEST_ASSERT_NOT_NULL(ciphertext,
7546 				"no room to append ciphertext");
7547 
7548 		memcpy(ciphertext, tdata->ciphertext.data,
7549 				tdata->ciphertext.len);
7550 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7551 				tdata->ciphertext.len);
7552 
7553 		if (ut_params->obuf) {
7554 			plaintext = (uint8_t *)rte_pktmbuf_append(
7555 					ut_params->obuf,
7556 					plaintext_pad_len + aad_pad_len);
7557 			TEST_ASSERT_NOT_NULL(plaintext,
7558 					"no room to append plaintext");
7559 
7560 			memset(plaintext + aad_pad_len, 0,
7561 					tdata->plaintext.len);
7562 		}
7563 	}
7564 
7565 	/* Append digest data */
7566 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7567 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7568 				ut_params->obuf ? ut_params->obuf :
7569 						ut_params->ibuf,
7570 						tdata->auth_tag.len);
7571 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7572 				"no room to append digest");
7573 		memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
7574 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
7575 				ut_params->obuf ? ut_params->obuf :
7576 						ut_params->ibuf,
7577 						plaintext_pad_len +
7578 						aad_pad_len);
7579 	} else {
7580 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7581 				ut_params->ibuf, tdata->auth_tag.len);
7582 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7583 				"no room to append digest");
7584 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
7585 				ut_params->ibuf,
7586 				plaintext_pad_len + aad_pad_len);
7587 
7588 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
7589 			tdata->auth_tag.len);
7590 		debug_hexdump(stdout, "digest:",
7591 			sym_op->aead.digest.data,
7592 			tdata->auth_tag.len);
7593 	}
7594 
7595 	sym_op->aead.data.length = tdata->plaintext.len;
7596 	sym_op->aead.data.offset = aad_pad_len;
7597 
7598 	return 0;
7599 }
7600 
7601 static int
7602 test_authenticated_encryption(const struct aead_test_data *tdata)
7603 {
7604 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7605 	struct crypto_unittest_params *ut_params = &unittest_params;
7606 
7607 	int retval;
7608 	uint8_t *ciphertext, *auth_tag;
7609 	uint16_t plaintext_pad_len;
7610 	uint32_t i;
7611 	struct rte_cryptodev_info dev_info;
7612 
7613 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7614 	uint64_t feat_flags = dev_info.feature_flags;
7615 
7616 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
7617 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
7618 		printf("Device doesn't support RAW data-path APIs.\n");
7619 		return -ENOTSUP;
7620 	}
7621 
7622 	/* Verify the capabilities */
7623 	struct rte_cryptodev_sym_capability_idx cap_idx;
7624 	const struct rte_cryptodev_symmetric_capability *capability;
7625 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7626 	cap_idx.algo.aead = tdata->algo;
7627 	capability = rte_cryptodev_sym_capability_get(
7628 			ts_params->valid_devs[0], &cap_idx);
7629 	if (capability == NULL)
7630 		return -ENOTSUP;
7631 	if (rte_cryptodev_sym_capability_check_aead(
7632 			capability, tdata->key.len, tdata->auth_tag.len,
7633 			tdata->aad.len, tdata->iv.len))
7634 		return -ENOTSUP;
7635 
7636 	/* Create AEAD session */
7637 	retval = create_aead_session(ts_params->valid_devs[0],
7638 			tdata->algo,
7639 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
7640 			tdata->key.data, tdata->key.len,
7641 			tdata->aad.len, tdata->auth_tag.len,
7642 			tdata->iv.len);
7643 	if (retval < 0)
7644 		return retval;
7645 
7646 	if (tdata->aad.len > MBUF_SIZE) {
7647 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
7648 		/* Populate full size of add data */
7649 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
7650 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
7651 	} else
7652 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7653 
7654 	/* clear mbuf payload */
7655 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7656 			rte_pktmbuf_tailroom(ut_params->ibuf));
7657 
7658 	/* Create AEAD operation */
7659 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
7660 	if (retval < 0)
7661 		return retval;
7662 
7663 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7664 
7665 	ut_params->op->sym->m_src = ut_params->ibuf;
7666 
7667 	/* Process crypto operation */
7668 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
7669 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
7670 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7671 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
7672 				ut_params->op, 0, 0, 0, 0);
7673 	else
7674 		TEST_ASSERT_NOT_NULL(
7675 			process_crypto_request(ts_params->valid_devs[0],
7676 			ut_params->op), "failed to process sym crypto op");
7677 
7678 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7679 			"crypto op processing failed");
7680 
7681 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7682 
7683 	if (ut_params->op->sym->m_dst) {
7684 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
7685 				uint8_t *);
7686 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
7687 				uint8_t *, plaintext_pad_len);
7688 	} else {
7689 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
7690 				uint8_t *,
7691 				ut_params->op->sym->cipher.data.offset);
7692 		auth_tag = ciphertext + plaintext_pad_len;
7693 	}
7694 
7695 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
7696 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
7697 
7698 	/* Validate obuf */
7699 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
7700 			ciphertext,
7701 			tdata->ciphertext.data,
7702 			tdata->ciphertext.len,
7703 			"Ciphertext data not as expected");
7704 
7705 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
7706 			auth_tag,
7707 			tdata->auth_tag.data,
7708 			tdata->auth_tag.len,
7709 			"Generated auth tag not as expected");
7710 
7711 	return 0;
7712 
7713 }
7714 
7715 #ifdef RTE_LIB_SECURITY
7716 static int
7717 security_proto_supported(enum rte_security_session_action_type action,
7718 	enum rte_security_session_protocol proto)
7719 {
7720 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7721 
7722 	const struct rte_security_capability *capabilities;
7723 	const struct rte_security_capability *capability;
7724 	uint16_t i = 0;
7725 
7726 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
7727 				rte_cryptodev_get_sec_ctx(
7728 				ts_params->valid_devs[0]);
7729 
7730 
7731 	capabilities = rte_security_capabilities_get(ctx);
7732 
7733 	if (capabilities == NULL)
7734 		return -ENOTSUP;
7735 
7736 	while ((capability = &capabilities[i++])->action !=
7737 			RTE_SECURITY_ACTION_TYPE_NONE) {
7738 		if (capability->action == action &&
7739 				capability->protocol == proto)
7740 			return 0;
7741 	}
7742 
7743 	return -ENOTSUP;
7744 }
7745 
7746 /* Basic algorithm run function for async inplace mode.
7747  * Creates a session from input parameters and runs one operation
7748  * on input_vec. Checks the output of the crypto operation against
7749  * output_vec.
7750  */
7751 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
7752 			   enum rte_crypto_auth_operation opa,
7753 			   const uint8_t *input_vec, unsigned int input_vec_len,
7754 			   const uint8_t *output_vec,
7755 			   unsigned int output_vec_len,
7756 			   enum rte_crypto_cipher_algorithm cipher_alg,
7757 			   const uint8_t *cipher_key, uint32_t cipher_key_len,
7758 			   enum rte_crypto_auth_algorithm auth_alg,
7759 			   const uint8_t *auth_key, uint32_t auth_key_len,
7760 			   uint8_t bearer, enum rte_security_pdcp_domain domain,
7761 			   uint8_t packet_direction, uint8_t sn_size,
7762 			   uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
7763 {
7764 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7765 	struct crypto_unittest_params *ut_params = &unittest_params;
7766 	uint8_t *plaintext;
7767 	int ret = TEST_SUCCESS;
7768 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
7769 				rte_cryptodev_get_sec_ctx(
7770 				ts_params->valid_devs[0]);
7771 
7772 	/* Verify the capabilities */
7773 	struct rte_security_capability_idx sec_cap_idx;
7774 
7775 	sec_cap_idx.action = ut_params->type;
7776 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
7777 	sec_cap_idx.pdcp.domain = domain;
7778 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
7779 		return -ENOTSUP;
7780 
7781 	/* Generate test mbuf data */
7782 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7783 
7784 	/* clear mbuf payload */
7785 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7786 			rte_pktmbuf_tailroom(ut_params->ibuf));
7787 
7788 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7789 						  input_vec_len);
7790 	memcpy(plaintext, input_vec, input_vec_len);
7791 
7792 	/* Out of place support */
7793 	if (oop) {
7794 		/*
7795 		 * For out-op-place we need to alloc another mbuf
7796 		 */
7797 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7798 		rte_pktmbuf_append(ut_params->obuf, output_vec_len);
7799 	}
7800 
7801 	/* Setup Cipher Parameters */
7802 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7803 	ut_params->cipher_xform.cipher.algo = cipher_alg;
7804 	ut_params->cipher_xform.cipher.op = opc;
7805 	ut_params->cipher_xform.cipher.key.data = cipher_key;
7806 	ut_params->cipher_xform.cipher.key.length = cipher_key_len;
7807 	ut_params->cipher_xform.cipher.iv.length =
7808 				packet_direction ? 4 : 0;
7809 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
7810 
7811 	/* Setup HMAC Parameters if ICV header is required */
7812 	if (auth_alg != 0) {
7813 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7814 		ut_params->auth_xform.next = NULL;
7815 		ut_params->auth_xform.auth.algo = auth_alg;
7816 		ut_params->auth_xform.auth.op = opa;
7817 		ut_params->auth_xform.auth.key.data = auth_key;
7818 		ut_params->auth_xform.auth.key.length = auth_key_len;
7819 
7820 		ut_params->cipher_xform.next = &ut_params->auth_xform;
7821 	} else {
7822 		ut_params->cipher_xform.next = NULL;
7823 	}
7824 
7825 	struct rte_security_session_conf sess_conf = {
7826 		.action_type = ut_params->type,
7827 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
7828 		{.pdcp = {
7829 			.bearer = bearer,
7830 			.domain = domain,
7831 			.pkt_dir = packet_direction,
7832 			.sn_size = sn_size,
7833 			.hfn = packet_direction ? 0 : hfn,
7834 			/**
7835 			 * hfn can be set as pdcp_test_hfn[i]
7836 			 * if hfn_ovrd is not set. Here, PDCP
7837 			 * packet direction is just used to
7838 			 * run half of the cases with session
7839 			 * HFN and other half with per packet
7840 			 * HFN.
7841 			 */
7842 			.hfn_threshold = hfn_threshold,
7843 			.hfn_ovrd = packet_direction ? 1 : 0,
7844 			.sdap_enabled = sdap,
7845 		} },
7846 		.crypto_xform = &ut_params->cipher_xform
7847 	};
7848 
7849 	/* Create security session */
7850 	ut_params->sec_session = rte_security_session_create(ctx,
7851 				&sess_conf, ts_params->session_mpool,
7852 				ts_params->session_priv_mpool);
7853 
7854 	if (!ut_params->sec_session) {
7855 		printf("TestCase %s()-%d line %d failed %s: ",
7856 			__func__, i, __LINE__, "Failed to allocate session");
7857 		ret = TEST_FAILED;
7858 		goto on_err;
7859 	}
7860 
7861 	/* Generate crypto op data structure */
7862 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7863 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7864 	if (!ut_params->op) {
7865 		printf("TestCase %s()-%d line %d failed %s: ",
7866 			__func__, i, __LINE__,
7867 			"Failed to allocate symmetric crypto operation struct");
7868 		ret = TEST_FAILED;
7869 		goto on_err;
7870 	}
7871 
7872 	uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
7873 					uint32_t *, IV_OFFSET);
7874 	*per_pkt_hfn = packet_direction ? hfn : 0;
7875 
7876 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
7877 
7878 	/* set crypto operation source mbuf */
7879 	ut_params->op->sym->m_src = ut_params->ibuf;
7880 	if (oop)
7881 		ut_params->op->sym->m_dst = ut_params->obuf;
7882 
7883 	/* Process crypto operation */
7884 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
7885 		== NULL) {
7886 		printf("TestCase %s()-%d line %d failed %s: ",
7887 			__func__, i, __LINE__,
7888 			"failed to process sym crypto op");
7889 		ret = TEST_FAILED;
7890 		goto on_err;
7891 	}
7892 
7893 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
7894 		printf("TestCase %s()-%d line %d failed %s: ",
7895 			__func__, i, __LINE__, "crypto op processing failed");
7896 		ret = TEST_FAILED;
7897 		goto on_err;
7898 	}
7899 
7900 	/* Validate obuf */
7901 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
7902 			uint8_t *);
7903 	if (oop) {
7904 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
7905 				uint8_t *);
7906 	}
7907 
7908 	if (memcmp(ciphertext, output_vec, output_vec_len)) {
7909 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
7910 		rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
7911 		rte_hexdump(stdout, "reference", output_vec, output_vec_len);
7912 		ret = TEST_FAILED;
7913 		goto on_err;
7914 	}
7915 
7916 on_err:
7917 	rte_crypto_op_free(ut_params->op);
7918 	ut_params->op = NULL;
7919 
7920 	if (ut_params->sec_session)
7921 		rte_security_session_destroy(ctx, ut_params->sec_session);
7922 	ut_params->sec_session = NULL;
7923 
7924 	rte_pktmbuf_free(ut_params->ibuf);
7925 	ut_params->ibuf = NULL;
7926 	if (oop) {
7927 		rte_pktmbuf_free(ut_params->obuf);
7928 		ut_params->obuf = NULL;
7929 	}
7930 
7931 	return ret;
7932 }
7933 
7934 static int
7935 test_pdcp_proto_SGL(int i, int oop,
7936 	enum rte_crypto_cipher_operation opc,
7937 	enum rte_crypto_auth_operation opa,
7938 	uint8_t *input_vec,
7939 	unsigned int input_vec_len,
7940 	uint8_t *output_vec,
7941 	unsigned int output_vec_len,
7942 	uint32_t fragsz,
7943 	uint32_t fragsz_oop)
7944 {
7945 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7946 	struct crypto_unittest_params *ut_params = &unittest_params;
7947 	uint8_t *plaintext;
7948 	struct rte_mbuf *buf, *buf_oop = NULL;
7949 	int ret = TEST_SUCCESS;
7950 	int to_trn = 0;
7951 	int to_trn_tbl[16];
7952 	int segs = 1;
7953 	unsigned int trn_data = 0;
7954 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
7955 				rte_cryptodev_get_sec_ctx(
7956 				ts_params->valid_devs[0]);
7957 
7958 	/* Verify the capabilities */
7959 	struct rte_security_capability_idx sec_cap_idx;
7960 
7961 	sec_cap_idx.action = ut_params->type;
7962 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
7963 	sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
7964 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
7965 		return -ENOTSUP;
7966 
7967 	if (fragsz > input_vec_len)
7968 		fragsz = input_vec_len;
7969 
7970 	uint16_t plaintext_len = fragsz;
7971 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
7972 
7973 	if (fragsz_oop > output_vec_len)
7974 		frag_size_oop = output_vec_len;
7975 
7976 	int ecx = 0;
7977 	if (input_vec_len % fragsz != 0) {
7978 		if (input_vec_len / fragsz + 1 > 16)
7979 			return 1;
7980 	} else if (input_vec_len / fragsz > 16)
7981 		return 1;
7982 
7983 	/* Out of place support */
7984 	if (oop) {
7985 		/*
7986 		 * For out-op-place we need to alloc another mbuf
7987 		 */
7988 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7989 		rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
7990 		buf_oop = ut_params->obuf;
7991 	}
7992 
7993 	/* Generate test mbuf data */
7994 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7995 
7996 	/* clear mbuf payload */
7997 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7998 			rte_pktmbuf_tailroom(ut_params->ibuf));
7999 
8000 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8001 						  plaintext_len);
8002 	memcpy(plaintext, input_vec, plaintext_len);
8003 	trn_data += plaintext_len;
8004 
8005 	buf = ut_params->ibuf;
8006 
8007 	/*
8008 	 * Loop until no more fragments
8009 	 */
8010 
8011 	while (trn_data < input_vec_len) {
8012 		++segs;
8013 		to_trn = (input_vec_len - trn_data < fragsz) ?
8014 				(input_vec_len - trn_data) : fragsz;
8015 
8016 		to_trn_tbl[ecx++] = to_trn;
8017 
8018 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8019 		buf = buf->next;
8020 
8021 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8022 				rte_pktmbuf_tailroom(buf));
8023 
8024 		/* OOP */
8025 		if (oop && !fragsz_oop) {
8026 			buf_oop->next =
8027 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
8028 			buf_oop = buf_oop->next;
8029 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8030 					0, rte_pktmbuf_tailroom(buf_oop));
8031 			rte_pktmbuf_append(buf_oop, to_trn);
8032 		}
8033 
8034 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8035 				to_trn);
8036 
8037 		memcpy(plaintext, input_vec + trn_data, to_trn);
8038 		trn_data += to_trn;
8039 	}
8040 
8041 	ut_params->ibuf->nb_segs = segs;
8042 
8043 	segs = 1;
8044 	if (fragsz_oop && oop) {
8045 		to_trn = 0;
8046 		ecx = 0;
8047 
8048 		trn_data = frag_size_oop;
8049 		while (trn_data < output_vec_len) {
8050 			++segs;
8051 			to_trn =
8052 				(output_vec_len - trn_data <
8053 						frag_size_oop) ?
8054 				(output_vec_len - trn_data) :
8055 						frag_size_oop;
8056 
8057 			to_trn_tbl[ecx++] = to_trn;
8058 
8059 			buf_oop->next =
8060 				rte_pktmbuf_alloc(ts_params->mbuf_pool);
8061 			buf_oop = buf_oop->next;
8062 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8063 					0, rte_pktmbuf_tailroom(buf_oop));
8064 			rte_pktmbuf_append(buf_oop, to_trn);
8065 
8066 			trn_data += to_trn;
8067 		}
8068 		ut_params->obuf->nb_segs = segs;
8069 	}
8070 
8071 	/* Setup Cipher Parameters */
8072 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8073 	ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
8074 	ut_params->cipher_xform.cipher.op = opc;
8075 	ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
8076 	ut_params->cipher_xform.cipher.key.length =
8077 					pdcp_test_params[i].cipher_key_len;
8078 	ut_params->cipher_xform.cipher.iv.length = 0;
8079 
8080 	/* Setup HMAC Parameters if ICV header is required */
8081 	if (pdcp_test_params[i].auth_alg != 0) {
8082 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8083 		ut_params->auth_xform.next = NULL;
8084 		ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
8085 		ut_params->auth_xform.auth.op = opa;
8086 		ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
8087 		ut_params->auth_xform.auth.key.length =
8088 					pdcp_test_params[i].auth_key_len;
8089 
8090 		ut_params->cipher_xform.next = &ut_params->auth_xform;
8091 	} else {
8092 		ut_params->cipher_xform.next = NULL;
8093 	}
8094 
8095 	struct rte_security_session_conf sess_conf = {
8096 		.action_type = ut_params->type,
8097 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
8098 		{.pdcp = {
8099 			.bearer = pdcp_test_bearer[i],
8100 			.domain = pdcp_test_params[i].domain,
8101 			.pkt_dir = pdcp_test_packet_direction[i],
8102 			.sn_size = pdcp_test_data_sn_size[i],
8103 			.hfn = pdcp_test_hfn[i],
8104 			.hfn_threshold = pdcp_test_hfn_threshold[i],
8105 			.hfn_ovrd = 0,
8106 		} },
8107 		.crypto_xform = &ut_params->cipher_xform
8108 	};
8109 
8110 	/* Create security session */
8111 	ut_params->sec_session = rte_security_session_create(ctx,
8112 				&sess_conf, ts_params->session_mpool,
8113 				ts_params->session_priv_mpool);
8114 
8115 	if (!ut_params->sec_session) {
8116 		printf("TestCase %s()-%d line %d failed %s: ",
8117 			__func__, i, __LINE__, "Failed to allocate session");
8118 		ret = TEST_FAILED;
8119 		goto on_err;
8120 	}
8121 
8122 	/* Generate crypto op data structure */
8123 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8124 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8125 	if (!ut_params->op) {
8126 		printf("TestCase %s()-%d line %d failed %s: ",
8127 			__func__, i, __LINE__,
8128 			"Failed to allocate symmetric crypto operation struct");
8129 		ret = TEST_FAILED;
8130 		goto on_err;
8131 	}
8132 
8133 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8134 
8135 	/* set crypto operation source mbuf */
8136 	ut_params->op->sym->m_src = ut_params->ibuf;
8137 	if (oop)
8138 		ut_params->op->sym->m_dst = ut_params->obuf;
8139 
8140 	/* Process crypto operation */
8141 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8142 		== NULL) {
8143 		printf("TestCase %s()-%d line %d failed %s: ",
8144 			__func__, i, __LINE__,
8145 			"failed to process sym crypto op");
8146 		ret = TEST_FAILED;
8147 		goto on_err;
8148 	}
8149 
8150 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8151 		printf("TestCase %s()-%d line %d failed %s: ",
8152 			__func__, i, __LINE__, "crypto op processing failed");
8153 		ret = TEST_FAILED;
8154 		goto on_err;
8155 	}
8156 
8157 	/* Validate obuf */
8158 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8159 			uint8_t *);
8160 	if (oop) {
8161 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8162 				uint8_t *);
8163 	}
8164 	if (fragsz_oop)
8165 		fragsz = frag_size_oop;
8166 	if (memcmp(ciphertext, output_vec, fragsz)) {
8167 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8168 		rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8169 		rte_hexdump(stdout, "reference", output_vec, fragsz);
8170 		ret = TEST_FAILED;
8171 		goto on_err;
8172 	}
8173 
8174 	buf = ut_params->op->sym->m_src->next;
8175 	if (oop)
8176 		buf = ut_params->op->sym->m_dst->next;
8177 
8178 	unsigned int off = fragsz;
8179 
8180 	ecx = 0;
8181 	while (buf) {
8182 		ciphertext = rte_pktmbuf_mtod(buf,
8183 				uint8_t *);
8184 		if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8185 			printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8186 			rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8187 			rte_hexdump(stdout, "reference", output_vec + off,
8188 					to_trn_tbl[ecx]);
8189 			ret = TEST_FAILED;
8190 			goto on_err;
8191 		}
8192 		off += to_trn_tbl[ecx++];
8193 		buf = buf->next;
8194 	}
8195 on_err:
8196 	rte_crypto_op_free(ut_params->op);
8197 	ut_params->op = NULL;
8198 
8199 	if (ut_params->sec_session)
8200 		rte_security_session_destroy(ctx, ut_params->sec_session);
8201 	ut_params->sec_session = NULL;
8202 
8203 	rte_pktmbuf_free(ut_params->ibuf);
8204 	ut_params->ibuf = NULL;
8205 	if (oop) {
8206 		rte_pktmbuf_free(ut_params->obuf);
8207 		ut_params->obuf = NULL;
8208 	}
8209 
8210 	return ret;
8211 }
8212 
8213 int
8214 test_pdcp_proto_cplane_encap(int i)
8215 {
8216 	return test_pdcp_proto(
8217 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8218 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8219 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8220 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8221 		pdcp_test_params[i].cipher_key_len,
8222 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8223 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8224 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8225 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8226 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8227 }
8228 
8229 int
8230 test_pdcp_proto_uplane_encap(int i)
8231 {
8232 	return test_pdcp_proto(
8233 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8234 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8235 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8236 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8237 		pdcp_test_params[i].cipher_key_len,
8238 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8239 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8240 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8241 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8242 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8243 }
8244 
8245 int
8246 test_pdcp_proto_uplane_encap_with_int(int i)
8247 {
8248 	return test_pdcp_proto(
8249 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8250 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8251 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8252 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8253 		pdcp_test_params[i].cipher_key_len,
8254 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8255 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8256 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8257 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8258 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8259 }
8260 
8261 int
8262 test_pdcp_proto_cplane_decap(int i)
8263 {
8264 	return test_pdcp_proto(
8265 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8266 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8267 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8268 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8269 		pdcp_test_params[i].cipher_key_len,
8270 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8271 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8272 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8273 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8274 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8275 }
8276 
8277 int
8278 test_pdcp_proto_uplane_decap(int i)
8279 {
8280 	return test_pdcp_proto(
8281 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8282 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8283 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8284 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8285 		pdcp_test_params[i].cipher_key_len,
8286 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8287 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8288 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8289 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8290 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8291 }
8292 
8293 int
8294 test_pdcp_proto_uplane_decap_with_int(int i)
8295 {
8296 	return test_pdcp_proto(
8297 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8298 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8299 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8300 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8301 		pdcp_test_params[i].cipher_key_len,
8302 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8303 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8304 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8305 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8306 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8307 }
8308 
8309 static int
8310 test_PDCP_PROTO_SGL_in_place_32B(void)
8311 {
8312 	/* i can be used for running any PDCP case
8313 	 * In this case it is uplane 12-bit AES-SNOW DL encap
8314 	 */
8315 	int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
8316 	return test_pdcp_proto_SGL(i, IN_PLACE,
8317 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8318 			RTE_CRYPTO_AUTH_OP_GENERATE,
8319 			pdcp_test_data_in[i],
8320 			pdcp_test_data_in_len[i],
8321 			pdcp_test_data_out[i],
8322 			pdcp_test_data_in_len[i]+4,
8323 			32, 0);
8324 }
8325 static int
8326 test_PDCP_PROTO_SGL_oop_32B_128B(void)
8327 {
8328 	/* i can be used for running any PDCP case
8329 	 * In this case it is uplane 18-bit NULL-NULL DL encap
8330 	 */
8331 	int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
8332 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8333 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8334 			RTE_CRYPTO_AUTH_OP_GENERATE,
8335 			pdcp_test_data_in[i],
8336 			pdcp_test_data_in_len[i],
8337 			pdcp_test_data_out[i],
8338 			pdcp_test_data_in_len[i]+4,
8339 			32, 128);
8340 }
8341 static int
8342 test_PDCP_PROTO_SGL_oop_32B_40B(void)
8343 {
8344 	/* i can be used for running any PDCP case
8345 	 * In this case it is uplane 18-bit AES DL encap
8346 	 */
8347 	int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
8348 			+ DOWNLINK;
8349 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8350 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8351 			RTE_CRYPTO_AUTH_OP_GENERATE,
8352 			pdcp_test_data_in[i],
8353 			pdcp_test_data_in_len[i],
8354 			pdcp_test_data_out[i],
8355 			pdcp_test_data_in_len[i],
8356 			32, 40);
8357 }
8358 static int
8359 test_PDCP_PROTO_SGL_oop_128B_32B(void)
8360 {
8361 	/* i can be used for running any PDCP case
8362 	 * In this case it is cplane 12-bit AES-ZUC DL encap
8363 	 */
8364 	int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
8365 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8366 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8367 			RTE_CRYPTO_AUTH_OP_GENERATE,
8368 			pdcp_test_data_in[i],
8369 			pdcp_test_data_in_len[i],
8370 			pdcp_test_data_out[i],
8371 			pdcp_test_data_in_len[i]+4,
8372 			128, 32);
8373 }
8374 
8375 static int
8376 test_PDCP_SDAP_PROTO_encap_all(void)
8377 {
8378 	int i = 0, size = 0;
8379 	int err, all_err = TEST_SUCCESS;
8380 	const struct pdcp_sdap_test *cur_test;
8381 
8382 	size = ARRAY_SIZE(list_pdcp_sdap_tests);
8383 
8384 	for (i = 0; i < size; i++) {
8385 		cur_test = &list_pdcp_sdap_tests[i];
8386 		err = test_pdcp_proto(
8387 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8388 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8389 			cur_test->in_len, cur_test->data_out,
8390 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8391 			cur_test->param.cipher_alg, cur_test->cipher_key,
8392 			cur_test->param.cipher_key_len,
8393 			cur_test->param.auth_alg,
8394 			cur_test->auth_key, cur_test->param.auth_key_len,
8395 			cur_test->bearer, cur_test->param.domain,
8396 			cur_test->packet_direction, cur_test->sn_size,
8397 			cur_test->hfn,
8398 			cur_test->hfn_threshold, SDAP_ENABLED);
8399 		if (err) {
8400 			printf("\t%d) %s: Encapsulation failed\n",
8401 					cur_test->test_idx,
8402 					cur_test->param.name);
8403 			err = TEST_FAILED;
8404 		} else {
8405 			printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
8406 					cur_test->param.name);
8407 			err = TEST_SUCCESS;
8408 		}
8409 		all_err += err;
8410 	}
8411 
8412 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8413 
8414 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8415 }
8416 
8417 static int
8418 test_PDCP_SDAP_PROTO_decap_all(void)
8419 {
8420 	int i = 0, size = 0;
8421 	int err, all_err = TEST_SUCCESS;
8422 	const struct pdcp_sdap_test *cur_test;
8423 
8424 	size = ARRAY_SIZE(list_pdcp_sdap_tests);
8425 
8426 	for (i = 0; i < size; i++) {
8427 		cur_test = &list_pdcp_sdap_tests[i];
8428 		err = test_pdcp_proto(
8429 			i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
8430 			RTE_CRYPTO_AUTH_OP_VERIFY,
8431 			cur_test->data_out,
8432 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8433 			cur_test->data_in, cur_test->in_len,
8434 			cur_test->param.cipher_alg,
8435 			cur_test->cipher_key, cur_test->param.cipher_key_len,
8436 			cur_test->param.auth_alg, cur_test->auth_key,
8437 			cur_test->param.auth_key_len, cur_test->bearer,
8438 			cur_test->param.domain, cur_test->packet_direction,
8439 			cur_test->sn_size, cur_test->hfn,
8440 			cur_test->hfn_threshold, SDAP_ENABLED);
8441 		if (err) {
8442 			printf("\t%d) %s: Decapsulation failed\n",
8443 					cur_test->test_idx,
8444 					cur_test->param.name);
8445 			err = TEST_FAILED;
8446 		} else {
8447 			printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
8448 					cur_test->param.name);
8449 			err = TEST_SUCCESS;
8450 		}
8451 		all_err += err;
8452 	}
8453 
8454 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8455 
8456 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8457 }
8458 
8459 static int
8460 test_PDCP_PROTO_all(void)
8461 {
8462 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8463 	struct crypto_unittest_params *ut_params = &unittest_params;
8464 	struct rte_cryptodev_info dev_info;
8465 	int status;
8466 
8467 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8468 	uint64_t feat_flags = dev_info.feature_flags;
8469 
8470 	if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
8471 		return -ENOTSUP;
8472 
8473 	/* Set action type */
8474 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
8475 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
8476 		gbl_action_type;
8477 
8478 	if (security_proto_supported(ut_params->type,
8479 			RTE_SECURITY_PROTOCOL_PDCP) < 0)
8480 		return -ENOTSUP;
8481 
8482 	status = test_PDCP_PROTO_cplane_encap_all();
8483 	status += test_PDCP_PROTO_cplane_decap_all();
8484 	status += test_PDCP_PROTO_uplane_encap_all();
8485 	status += test_PDCP_PROTO_uplane_decap_all();
8486 	status += test_PDCP_PROTO_SGL_in_place_32B();
8487 	status += test_PDCP_PROTO_SGL_oop_32B_128B();
8488 	status += test_PDCP_PROTO_SGL_oop_32B_40B();
8489 	status += test_PDCP_PROTO_SGL_oop_128B_32B();
8490 	status += test_PDCP_SDAP_PROTO_encap_all();
8491 	status += test_PDCP_SDAP_PROTO_decap_all();
8492 
8493 	if (status)
8494 		return TEST_FAILED;
8495 	else
8496 		return TEST_SUCCESS;
8497 }
8498 
8499 static int
8500 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td)
8501 {
8502 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8503 	struct crypto_unittest_params *ut_params = &unittest_params;
8504 	uint8_t *plaintext, *ciphertext;
8505 	uint8_t *iv_ptr;
8506 	int32_t cipher_len, crc_len;
8507 	uint32_t crc_data_len;
8508 	int ret = TEST_SUCCESS;
8509 
8510 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8511 					rte_cryptodev_get_sec_ctx(
8512 						ts_params->valid_devs[0]);
8513 
8514 	/* Verify the capabilities */
8515 	struct rte_security_capability_idx sec_cap_idx;
8516 	const struct rte_security_capability *sec_cap;
8517 	const struct rte_cryptodev_capabilities *crypto_cap;
8518 	const struct rte_cryptodev_symmetric_capability *sym_cap;
8519 	int j = 0;
8520 
8521 	sec_cap_idx.action = ut_params->type;
8522 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
8523 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
8524 
8525 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
8526 	if (sec_cap == NULL)
8527 		return -ENOTSUP;
8528 
8529 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
8530 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
8531 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
8532 				crypto_cap->sym.xform_type ==
8533 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
8534 				crypto_cap->sym.cipher.algo ==
8535 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
8536 			sym_cap = &crypto_cap->sym;
8537 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
8538 						d_td->key.len,
8539 						d_td->iv.len) == 0)
8540 				break;
8541 		}
8542 	}
8543 
8544 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
8545 		return -ENOTSUP;
8546 
8547 	/* Setup source mbuf payload */
8548 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8549 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8550 			rte_pktmbuf_tailroom(ut_params->ibuf));
8551 
8552 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8553 			d_td->ciphertext.len);
8554 
8555 	memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
8556 
8557 	/* Setup cipher session parameters */
8558 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8559 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
8560 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
8561 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
8562 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
8563 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
8564 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8565 	ut_params->cipher_xform.next = NULL;
8566 
8567 	/* Setup DOCSIS session parameters */
8568 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
8569 
8570 	struct rte_security_session_conf sess_conf = {
8571 		.action_type = ut_params->type,
8572 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
8573 		.docsis = ut_params->docsis_xform,
8574 		.crypto_xform = &ut_params->cipher_xform,
8575 	};
8576 
8577 	/* Create security session */
8578 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
8579 					ts_params->session_mpool,
8580 					ts_params->session_priv_mpool);
8581 
8582 	if (!ut_params->sec_session) {
8583 		printf("TestCase %s(%d) line %d: %s\n",
8584 			__func__, i, __LINE__, "failed to allocate session");
8585 		ret = TEST_FAILED;
8586 		goto on_err;
8587 	}
8588 
8589 	/* Generate crypto op data structure */
8590 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8591 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8592 	if (!ut_params->op) {
8593 		printf("TestCase %s(%d) line %d: %s\n",
8594 			__func__, i, __LINE__,
8595 			"failed to allocate symmetric crypto operation");
8596 		ret = TEST_FAILED;
8597 		goto on_err;
8598 	}
8599 
8600 	/* Setup CRC operation parameters */
8601 	crc_len = d_td->ciphertext.no_crc == false ?
8602 			(d_td->ciphertext.len -
8603 				d_td->ciphertext.crc_offset -
8604 				RTE_ETHER_CRC_LEN) :
8605 			0;
8606 	crc_len = crc_len > 0 ? crc_len : 0;
8607 	crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
8608 	ut_params->op->sym->auth.data.length = crc_len;
8609 	ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
8610 
8611 	/* Setup cipher operation parameters */
8612 	cipher_len = d_td->ciphertext.no_cipher == false ?
8613 			(d_td->ciphertext.len -
8614 				d_td->ciphertext.cipher_offset) :
8615 			0;
8616 	cipher_len = cipher_len > 0 ? cipher_len : 0;
8617 	ut_params->op->sym->cipher.data.length = cipher_len;
8618 	ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
8619 
8620 	/* Setup cipher IV */
8621 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
8622 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
8623 
8624 	/* Attach session to operation */
8625 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8626 
8627 	/* Set crypto operation mbufs */
8628 	ut_params->op->sym->m_src = ut_params->ibuf;
8629 	ut_params->op->sym->m_dst = NULL;
8630 
8631 	/* Process crypto operation */
8632 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
8633 			NULL) {
8634 		printf("TestCase %s(%d) line %d: %s\n",
8635 			__func__, i, __LINE__,
8636 			"failed to process security crypto op");
8637 		ret = TEST_FAILED;
8638 		goto on_err;
8639 	}
8640 
8641 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8642 		printf("TestCase %s(%d) line %d: %s\n",
8643 			__func__, i, __LINE__, "crypto op processing failed");
8644 		ret = TEST_FAILED;
8645 		goto on_err;
8646 	}
8647 
8648 	/* Validate plaintext */
8649 	plaintext = ciphertext;
8650 
8651 	if (memcmp(plaintext, d_td->plaintext.data,
8652 			d_td->plaintext.len - crc_data_len)) {
8653 		printf("TestCase %s(%d) line %d: %s\n",
8654 			__func__, i, __LINE__, "plaintext not as expected\n");
8655 		rte_hexdump(stdout, "expected", d_td->plaintext.data,
8656 				d_td->plaintext.len);
8657 		rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
8658 		ret = TEST_FAILED;
8659 		goto on_err;
8660 	}
8661 
8662 on_err:
8663 	rte_crypto_op_free(ut_params->op);
8664 	ut_params->op = NULL;
8665 
8666 	if (ut_params->sec_session)
8667 		rte_security_session_destroy(ctx, ut_params->sec_session);
8668 	ut_params->sec_session = NULL;
8669 
8670 	rte_pktmbuf_free(ut_params->ibuf);
8671 	ut_params->ibuf = NULL;
8672 
8673 	return ret;
8674 }
8675 
8676 static int
8677 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td)
8678 {
8679 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8680 	struct crypto_unittest_params *ut_params = &unittest_params;
8681 	uint8_t *plaintext, *ciphertext;
8682 	uint8_t *iv_ptr;
8683 	int32_t cipher_len, crc_len;
8684 	int ret = TEST_SUCCESS;
8685 
8686 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8687 					rte_cryptodev_get_sec_ctx(
8688 						ts_params->valid_devs[0]);
8689 
8690 	/* Verify the capabilities */
8691 	struct rte_security_capability_idx sec_cap_idx;
8692 	const struct rte_security_capability *sec_cap;
8693 	const struct rte_cryptodev_capabilities *crypto_cap;
8694 	const struct rte_cryptodev_symmetric_capability *sym_cap;
8695 	int j = 0;
8696 
8697 	sec_cap_idx.action = ut_params->type;
8698 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
8699 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
8700 
8701 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
8702 	if (sec_cap == NULL)
8703 		return -ENOTSUP;
8704 
8705 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
8706 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
8707 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
8708 				crypto_cap->sym.xform_type ==
8709 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
8710 				crypto_cap->sym.cipher.algo ==
8711 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
8712 			sym_cap = &crypto_cap->sym;
8713 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
8714 						d_td->key.len,
8715 						d_td->iv.len) == 0)
8716 				break;
8717 		}
8718 	}
8719 
8720 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
8721 		return -ENOTSUP;
8722 
8723 	/* Setup source mbuf payload */
8724 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8725 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8726 			rte_pktmbuf_tailroom(ut_params->ibuf));
8727 
8728 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8729 			d_td->plaintext.len);
8730 
8731 	memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
8732 
8733 	/* Setup cipher session parameters */
8734 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8735 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
8736 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
8737 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
8738 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
8739 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
8740 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8741 	ut_params->cipher_xform.next = NULL;
8742 
8743 	/* Setup DOCSIS session parameters */
8744 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
8745 
8746 	struct rte_security_session_conf sess_conf = {
8747 		.action_type = ut_params->type,
8748 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
8749 		.docsis = ut_params->docsis_xform,
8750 		.crypto_xform = &ut_params->cipher_xform,
8751 	};
8752 
8753 	/* Create security session */
8754 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
8755 					ts_params->session_mpool,
8756 					ts_params->session_priv_mpool);
8757 
8758 	if (!ut_params->sec_session) {
8759 		printf("TestCase %s(%d) line %d: %s\n",
8760 			__func__, i, __LINE__, "failed to allocate session");
8761 		ret = TEST_FAILED;
8762 		goto on_err;
8763 	}
8764 
8765 	/* Generate crypto op data structure */
8766 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8767 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8768 	if (!ut_params->op) {
8769 		printf("TestCase %s(%d) line %d: %s\n",
8770 			__func__, i, __LINE__,
8771 			"failed to allocate security crypto operation");
8772 		ret = TEST_FAILED;
8773 		goto on_err;
8774 	}
8775 
8776 	/* Setup CRC operation parameters */
8777 	crc_len = d_td->plaintext.no_crc == false ?
8778 			(d_td->plaintext.len -
8779 				d_td->plaintext.crc_offset -
8780 				RTE_ETHER_CRC_LEN) :
8781 			0;
8782 	crc_len = crc_len > 0 ? crc_len : 0;
8783 	ut_params->op->sym->auth.data.length = crc_len;
8784 	ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
8785 
8786 	/* Setup cipher operation parameters */
8787 	cipher_len = d_td->plaintext.no_cipher == false ?
8788 			(d_td->plaintext.len -
8789 				d_td->plaintext.cipher_offset) :
8790 			0;
8791 	cipher_len = cipher_len > 0 ? cipher_len : 0;
8792 	ut_params->op->sym->cipher.data.length = cipher_len;
8793 	ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
8794 
8795 	/* Setup cipher IV */
8796 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
8797 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
8798 
8799 	/* Attach session to operation */
8800 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8801 
8802 	/* Set crypto operation mbufs */
8803 	ut_params->op->sym->m_src = ut_params->ibuf;
8804 	ut_params->op->sym->m_dst = NULL;
8805 
8806 	/* Process crypto operation */
8807 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
8808 			NULL) {
8809 		printf("TestCase %s(%d) line %d: %s\n",
8810 			__func__, i, __LINE__,
8811 			"failed to process security crypto op");
8812 		ret = TEST_FAILED;
8813 		goto on_err;
8814 	}
8815 
8816 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8817 		printf("TestCase %s(%d) line %d: %s\n",
8818 			__func__, i, __LINE__, "crypto op processing failed");
8819 		ret = TEST_FAILED;
8820 		goto on_err;
8821 	}
8822 
8823 	/* Validate ciphertext */
8824 	ciphertext = plaintext;
8825 
8826 	if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
8827 		printf("TestCase %s(%d) line %d: %s\n",
8828 			__func__, i, __LINE__, "ciphertext not as expected\n");
8829 		rte_hexdump(stdout, "expected", d_td->ciphertext.data,
8830 				d_td->ciphertext.len);
8831 		rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
8832 		ret = TEST_FAILED;
8833 		goto on_err;
8834 	}
8835 
8836 on_err:
8837 	rte_crypto_op_free(ut_params->op);
8838 	ut_params->op = NULL;
8839 
8840 	if (ut_params->sec_session)
8841 		rte_security_session_destroy(ctx, ut_params->sec_session);
8842 	ut_params->sec_session = NULL;
8843 
8844 	rte_pktmbuf_free(ut_params->ibuf);
8845 	ut_params->ibuf = NULL;
8846 
8847 	return ret;
8848 }
8849 
8850 #define TEST_DOCSIS_COUNT(func) do {			\
8851 	int ret = func;					\
8852 	if (ret == TEST_SUCCESS)  {			\
8853 		printf("\t%2d)", n++);			\
8854 		printf("+++++ PASSED:" #func"\n");	\
8855 		p++;					\
8856 	} else if (ret == -ENOTSUP) {			\
8857 		printf("\t%2d)", n++);			\
8858 		printf("~~~~~ UNSUPP:" #func"\n");	\
8859 		u++;					\
8860 	} else {					\
8861 		printf("\t%2d)", n++);			\
8862 		printf("----- FAILED:" #func"\n");	\
8863 		f++;					\
8864 	}						\
8865 } while (0)
8866 
8867 static int
8868 test_DOCSIS_PROTO_uplink_all(void)
8869 {
8870 	int p = 0, u = 0, f = 0, n = 0;
8871 
8872 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1));
8873 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2));
8874 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3));
8875 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4));
8876 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5));
8877 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6));
8878 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7));
8879 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8));
8880 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9));
8881 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10));
8882 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11));
8883 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12));
8884 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13));
8885 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14));
8886 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15));
8887 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16));
8888 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17));
8889 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18));
8890 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19));
8891 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20));
8892 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21));
8893 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22));
8894 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23));
8895 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24));
8896 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25));
8897 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26));
8898 
8899 	if (f)
8900 		printf("## %s: %d passed out of %d (%d unsupported)\n",
8901 			__func__, p, n, u);
8902 
8903 	return f;
8904 };
8905 
8906 static int
8907 test_DOCSIS_PROTO_downlink_all(void)
8908 {
8909 	int p = 0, u = 0, f = 0, n = 0;
8910 
8911 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1));
8912 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2));
8913 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3));
8914 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4));
8915 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5));
8916 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6));
8917 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7));
8918 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8));
8919 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9));
8920 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10));
8921 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11));
8922 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12));
8923 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13));
8924 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14));
8925 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15));
8926 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16));
8927 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17));
8928 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18));
8929 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19));
8930 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20));
8931 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21));
8932 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22));
8933 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23));
8934 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24));
8935 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25));
8936 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26));
8937 
8938 	if (f)
8939 		printf("## %s: %d passed out of %d (%d unsupported)\n",
8940 			__func__, p, n, u);
8941 
8942 	return f;
8943 };
8944 
8945 static int
8946 test_DOCSIS_PROTO_all(void)
8947 {
8948 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8949 	struct crypto_unittest_params *ut_params = &unittest_params;
8950 	struct rte_cryptodev_info dev_info;
8951 	int status;
8952 
8953 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8954 	uint64_t feat_flags = dev_info.feature_flags;
8955 
8956 	if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
8957 		return -ENOTSUP;
8958 
8959 	/* Set action type */
8960 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
8961 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
8962 		gbl_action_type;
8963 
8964 	if (security_proto_supported(ut_params->type,
8965 			RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
8966 		return -ENOTSUP;
8967 
8968 	status = test_DOCSIS_PROTO_uplink_all();
8969 	status += test_DOCSIS_PROTO_downlink_all();
8970 
8971 	if (status)
8972 		return TEST_FAILED;
8973 	else
8974 		return TEST_SUCCESS;
8975 }
8976 #endif
8977 
8978 static int
8979 test_AES_GCM_authenticated_encryption_test_case_1(void)
8980 {
8981 	return test_authenticated_encryption(&gcm_test_case_1);
8982 }
8983 
8984 static int
8985 test_AES_GCM_authenticated_encryption_test_case_2(void)
8986 {
8987 	return test_authenticated_encryption(&gcm_test_case_2);
8988 }
8989 
8990 static int
8991 test_AES_GCM_authenticated_encryption_test_case_3(void)
8992 {
8993 	return test_authenticated_encryption(&gcm_test_case_3);
8994 }
8995 
8996 static int
8997 test_AES_GCM_authenticated_encryption_test_case_4(void)
8998 {
8999 	return test_authenticated_encryption(&gcm_test_case_4);
9000 }
9001 
9002 static int
9003 test_AES_GCM_authenticated_encryption_test_case_5(void)
9004 {
9005 	return test_authenticated_encryption(&gcm_test_case_5);
9006 }
9007 
9008 static int
9009 test_AES_GCM_authenticated_encryption_test_case_6(void)
9010 {
9011 	return test_authenticated_encryption(&gcm_test_case_6);
9012 }
9013 
9014 static int
9015 test_AES_GCM_authenticated_encryption_test_case_7(void)
9016 {
9017 	return test_authenticated_encryption(&gcm_test_case_7);
9018 }
9019 
9020 static int
9021 test_AES_GCM_authenticated_encryption_test_case_8(void)
9022 {
9023 	return test_authenticated_encryption(&gcm_test_case_8);
9024 }
9025 
9026 static int
9027 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
9028 {
9029 	return test_authenticated_encryption(&gcm_J0_test_case_1);
9030 }
9031 
9032 static int
9033 test_AES_GCM_auth_encryption_test_case_192_1(void)
9034 {
9035 	return test_authenticated_encryption(&gcm_test_case_192_1);
9036 }
9037 
9038 static int
9039 test_AES_GCM_auth_encryption_test_case_192_2(void)
9040 {
9041 	return test_authenticated_encryption(&gcm_test_case_192_2);
9042 }
9043 
9044 static int
9045 test_AES_GCM_auth_encryption_test_case_192_3(void)
9046 {
9047 	return test_authenticated_encryption(&gcm_test_case_192_3);
9048 }
9049 
9050 static int
9051 test_AES_GCM_auth_encryption_test_case_192_4(void)
9052 {
9053 	return test_authenticated_encryption(&gcm_test_case_192_4);
9054 }
9055 
9056 static int
9057 test_AES_GCM_auth_encryption_test_case_192_5(void)
9058 {
9059 	return test_authenticated_encryption(&gcm_test_case_192_5);
9060 }
9061 
9062 static int
9063 test_AES_GCM_auth_encryption_test_case_192_6(void)
9064 {
9065 	return test_authenticated_encryption(&gcm_test_case_192_6);
9066 }
9067 
9068 static int
9069 test_AES_GCM_auth_encryption_test_case_192_7(void)
9070 {
9071 	return test_authenticated_encryption(&gcm_test_case_192_7);
9072 }
9073 
9074 static int
9075 test_AES_GCM_auth_encryption_test_case_256_1(void)
9076 {
9077 	return test_authenticated_encryption(&gcm_test_case_256_1);
9078 }
9079 
9080 static int
9081 test_AES_GCM_auth_encryption_test_case_256_2(void)
9082 {
9083 	return test_authenticated_encryption(&gcm_test_case_256_2);
9084 }
9085 
9086 static int
9087 test_AES_GCM_auth_encryption_test_case_256_3(void)
9088 {
9089 	return test_authenticated_encryption(&gcm_test_case_256_3);
9090 }
9091 
9092 static int
9093 test_AES_GCM_auth_encryption_test_case_256_4(void)
9094 {
9095 	return test_authenticated_encryption(&gcm_test_case_256_4);
9096 }
9097 
9098 static int
9099 test_AES_GCM_auth_encryption_test_case_256_5(void)
9100 {
9101 	return test_authenticated_encryption(&gcm_test_case_256_5);
9102 }
9103 
9104 static int
9105 test_AES_GCM_auth_encryption_test_case_256_6(void)
9106 {
9107 	return test_authenticated_encryption(&gcm_test_case_256_6);
9108 }
9109 
9110 static int
9111 test_AES_GCM_auth_encryption_test_case_256_7(void)
9112 {
9113 	return test_authenticated_encryption(&gcm_test_case_256_7);
9114 }
9115 
9116 static int
9117 test_AES_GCM_auth_encryption_test_case_aad_1(void)
9118 {
9119 	return test_authenticated_encryption(&gcm_test_case_aad_1);
9120 }
9121 
9122 static int
9123 test_AES_GCM_auth_encryption_test_case_aad_2(void)
9124 {
9125 	return test_authenticated_encryption(&gcm_test_case_aad_2);
9126 }
9127 
9128 static int
9129 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
9130 {
9131 	struct aead_test_data tdata;
9132 	int res;
9133 
9134 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9135 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9136 	tdata.iv.data[0] += 1;
9137 	res = test_authenticated_encryption(&tdata);
9138 	if (res == -ENOTSUP)
9139 		return res;
9140 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9141 	return TEST_SUCCESS;
9142 }
9143 
9144 static int
9145 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
9146 {
9147 	struct aead_test_data tdata;
9148 	int res;
9149 
9150 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9151 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9152 	tdata.plaintext.data[0] += 1;
9153 	res = test_authenticated_encryption(&tdata);
9154 	if (res == -ENOTSUP)
9155 		return res;
9156 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9157 	return TEST_SUCCESS;
9158 }
9159 
9160 static int
9161 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
9162 {
9163 	struct aead_test_data tdata;
9164 	int res;
9165 
9166 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9167 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9168 	tdata.ciphertext.data[0] += 1;
9169 	res = test_authenticated_encryption(&tdata);
9170 	if (res == -ENOTSUP)
9171 		return res;
9172 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9173 	return TEST_SUCCESS;
9174 }
9175 
9176 static int
9177 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
9178 {
9179 	struct aead_test_data tdata;
9180 	int res;
9181 
9182 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9183 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9184 	tdata.aad.len += 1;
9185 	res = test_authenticated_encryption(&tdata);
9186 	if (res == -ENOTSUP)
9187 		return res;
9188 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9189 	return TEST_SUCCESS;
9190 }
9191 
9192 static int
9193 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
9194 {
9195 	struct aead_test_data tdata;
9196 	uint8_t aad[gcm_test_case_7.aad.len];
9197 	int res;
9198 
9199 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9200 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9201 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
9202 	aad[0] += 1;
9203 	tdata.aad.data = aad;
9204 	res = test_authenticated_encryption(&tdata);
9205 	if (res == -ENOTSUP)
9206 		return res;
9207 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9208 	return TEST_SUCCESS;
9209 }
9210 
9211 static int
9212 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
9213 {
9214 	struct aead_test_data tdata;
9215 	int res;
9216 
9217 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9218 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9219 	tdata.auth_tag.data[0] += 1;
9220 	res = test_authenticated_encryption(&tdata);
9221 	if (res == -ENOTSUP)
9222 		return res;
9223 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9224 	return TEST_SUCCESS;
9225 }
9226 
9227 static int
9228 test_authenticated_decryption(const struct aead_test_data *tdata)
9229 {
9230 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9231 	struct crypto_unittest_params *ut_params = &unittest_params;
9232 
9233 	int retval;
9234 	uint8_t *plaintext;
9235 	uint32_t i;
9236 	struct rte_cryptodev_info dev_info;
9237 
9238 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9239 	uint64_t feat_flags = dev_info.feature_flags;
9240 
9241 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
9242 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
9243 		printf("Device doesn't support RAW data-path APIs.\n");
9244 		return -ENOTSUP;
9245 	}
9246 
9247 	/* Verify the capabilities */
9248 	struct rte_cryptodev_sym_capability_idx cap_idx;
9249 	const struct rte_cryptodev_symmetric_capability *capability;
9250 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9251 	cap_idx.algo.aead = tdata->algo;
9252 	capability = rte_cryptodev_sym_capability_get(
9253 			ts_params->valid_devs[0], &cap_idx);
9254 	if (capability == NULL)
9255 		return -ENOTSUP;
9256 	if (rte_cryptodev_sym_capability_check_aead(
9257 			capability, tdata->key.len, tdata->auth_tag.len,
9258 			tdata->aad.len, tdata->iv.len))
9259 		return -ENOTSUP;
9260 
9261 	/* Create AEAD session */
9262 	retval = create_aead_session(ts_params->valid_devs[0],
9263 			tdata->algo,
9264 			RTE_CRYPTO_AEAD_OP_DECRYPT,
9265 			tdata->key.data, tdata->key.len,
9266 			tdata->aad.len, tdata->auth_tag.len,
9267 			tdata->iv.len);
9268 	if (retval < 0)
9269 		return retval;
9270 
9271 	/* alloc mbuf and set payload */
9272 	if (tdata->aad.len > MBUF_SIZE) {
9273 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
9274 		/* Populate full size of add data */
9275 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
9276 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
9277 	} else
9278 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9279 
9280 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9281 			rte_pktmbuf_tailroom(ut_params->ibuf));
9282 
9283 	/* Create AEAD operation */
9284 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
9285 	if (retval < 0)
9286 		return retval;
9287 
9288 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9289 
9290 	ut_params->op->sym->m_src = ut_params->ibuf;
9291 
9292 	/* Process crypto operation */
9293 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9294 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
9295 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9296 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
9297 				ut_params->op, 0, 0, 0, 0);
9298 	else
9299 		TEST_ASSERT_NOT_NULL(
9300 			process_crypto_request(ts_params->valid_devs[0],
9301 			ut_params->op), "failed to process sym crypto op");
9302 
9303 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9304 			"crypto op processing failed");
9305 
9306 	if (ut_params->op->sym->m_dst)
9307 		plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
9308 				uint8_t *);
9309 	else
9310 		plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
9311 				uint8_t *,
9312 				ut_params->op->sym->cipher.data.offset);
9313 
9314 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
9315 
9316 	/* Validate obuf */
9317 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
9318 			plaintext,
9319 			tdata->plaintext.data,
9320 			tdata->plaintext.len,
9321 			"Plaintext data not as expected");
9322 
9323 	TEST_ASSERT_EQUAL(ut_params->op->status,
9324 			RTE_CRYPTO_OP_STATUS_SUCCESS,
9325 			"Authentication failed");
9326 
9327 	return 0;
9328 }
9329 
9330 static int
9331 test_AES_GCM_authenticated_decryption_test_case_1(void)
9332 {
9333 	return test_authenticated_decryption(&gcm_test_case_1);
9334 }
9335 
9336 static int
9337 test_AES_GCM_authenticated_decryption_test_case_2(void)
9338 {
9339 	return test_authenticated_decryption(&gcm_test_case_2);
9340 }
9341 
9342 static int
9343 test_AES_GCM_authenticated_decryption_test_case_3(void)
9344 {
9345 	return test_authenticated_decryption(&gcm_test_case_3);
9346 }
9347 
9348 static int
9349 test_AES_GCM_authenticated_decryption_test_case_4(void)
9350 {
9351 	return test_authenticated_decryption(&gcm_test_case_4);
9352 }
9353 
9354 static int
9355 test_AES_GCM_authenticated_decryption_test_case_5(void)
9356 {
9357 	return test_authenticated_decryption(&gcm_test_case_5);
9358 }
9359 
9360 static int
9361 test_AES_GCM_authenticated_decryption_test_case_6(void)
9362 {
9363 	return test_authenticated_decryption(&gcm_test_case_6);
9364 }
9365 
9366 static int
9367 test_AES_GCM_authenticated_decryption_test_case_7(void)
9368 {
9369 	return test_authenticated_decryption(&gcm_test_case_7);
9370 }
9371 
9372 static int
9373 test_AES_GCM_authenticated_decryption_test_case_8(void)
9374 {
9375 	return test_authenticated_decryption(&gcm_test_case_8);
9376 }
9377 
9378 static int
9379 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
9380 {
9381 	return test_authenticated_decryption(&gcm_J0_test_case_1);
9382 }
9383 
9384 static int
9385 test_AES_GCM_auth_decryption_test_case_192_1(void)
9386 {
9387 	return test_authenticated_decryption(&gcm_test_case_192_1);
9388 }
9389 
9390 static int
9391 test_AES_GCM_auth_decryption_test_case_192_2(void)
9392 {
9393 	return test_authenticated_decryption(&gcm_test_case_192_2);
9394 }
9395 
9396 static int
9397 test_AES_GCM_auth_decryption_test_case_192_3(void)
9398 {
9399 	return test_authenticated_decryption(&gcm_test_case_192_3);
9400 }
9401 
9402 static int
9403 test_AES_GCM_auth_decryption_test_case_192_4(void)
9404 {
9405 	return test_authenticated_decryption(&gcm_test_case_192_4);
9406 }
9407 
9408 static int
9409 test_AES_GCM_auth_decryption_test_case_192_5(void)
9410 {
9411 	return test_authenticated_decryption(&gcm_test_case_192_5);
9412 }
9413 
9414 static int
9415 test_AES_GCM_auth_decryption_test_case_192_6(void)
9416 {
9417 	return test_authenticated_decryption(&gcm_test_case_192_6);
9418 }
9419 
9420 static int
9421 test_AES_GCM_auth_decryption_test_case_192_7(void)
9422 {
9423 	return test_authenticated_decryption(&gcm_test_case_192_7);
9424 }
9425 
9426 static int
9427 test_AES_GCM_auth_decryption_test_case_256_1(void)
9428 {
9429 	return test_authenticated_decryption(&gcm_test_case_256_1);
9430 }
9431 
9432 static int
9433 test_AES_GCM_auth_decryption_test_case_256_2(void)
9434 {
9435 	return test_authenticated_decryption(&gcm_test_case_256_2);
9436 }
9437 
9438 static int
9439 test_AES_GCM_auth_decryption_test_case_256_3(void)
9440 {
9441 	return test_authenticated_decryption(&gcm_test_case_256_3);
9442 }
9443 
9444 static int
9445 test_AES_GCM_auth_decryption_test_case_256_4(void)
9446 {
9447 	return test_authenticated_decryption(&gcm_test_case_256_4);
9448 }
9449 
9450 static int
9451 test_AES_GCM_auth_decryption_test_case_256_5(void)
9452 {
9453 	return test_authenticated_decryption(&gcm_test_case_256_5);
9454 }
9455 
9456 static int
9457 test_AES_GCM_auth_decryption_test_case_256_6(void)
9458 {
9459 	return test_authenticated_decryption(&gcm_test_case_256_6);
9460 }
9461 
9462 static int
9463 test_AES_GCM_auth_decryption_test_case_256_7(void)
9464 {
9465 	return test_authenticated_decryption(&gcm_test_case_256_7);
9466 }
9467 
9468 static int
9469 test_AES_GCM_auth_decryption_test_case_aad_1(void)
9470 {
9471 	return test_authenticated_decryption(&gcm_test_case_aad_1);
9472 }
9473 
9474 static int
9475 test_AES_GCM_auth_decryption_test_case_aad_2(void)
9476 {
9477 	return test_authenticated_decryption(&gcm_test_case_aad_2);
9478 }
9479 
9480 static int
9481 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
9482 {
9483 	struct aead_test_data tdata;
9484 	int res;
9485 
9486 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9487 	tdata.iv.data[0] += 1;
9488 	res = test_authenticated_decryption(&tdata);
9489 	if (res == -ENOTSUP)
9490 		return res;
9491 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9492 	return TEST_SUCCESS;
9493 }
9494 
9495 static int
9496 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
9497 {
9498 	struct aead_test_data tdata;
9499 	int res;
9500 
9501 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9502 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9503 	tdata.plaintext.data[0] += 1;
9504 	res = test_authenticated_decryption(&tdata);
9505 	if (res == -ENOTSUP)
9506 		return res;
9507 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9508 	return TEST_SUCCESS;
9509 }
9510 
9511 static int
9512 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
9513 {
9514 	struct aead_test_data tdata;
9515 	int res;
9516 
9517 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9518 	tdata.ciphertext.data[0] += 1;
9519 	res = test_authenticated_decryption(&tdata);
9520 	if (res == -ENOTSUP)
9521 		return res;
9522 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9523 	return TEST_SUCCESS;
9524 }
9525 
9526 static int
9527 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
9528 {
9529 	struct aead_test_data tdata;
9530 	int res;
9531 
9532 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9533 	tdata.aad.len += 1;
9534 	res = test_authenticated_decryption(&tdata);
9535 	if (res == -ENOTSUP)
9536 		return res;
9537 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9538 	return TEST_SUCCESS;
9539 }
9540 
9541 static int
9542 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
9543 {
9544 	struct aead_test_data tdata;
9545 	uint8_t aad[gcm_test_case_7.aad.len];
9546 	int res;
9547 
9548 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9549 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
9550 	aad[0] += 1;
9551 	tdata.aad.data = aad;
9552 	res = test_authenticated_decryption(&tdata);
9553 	if (res == -ENOTSUP)
9554 		return res;
9555 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9556 	return TEST_SUCCESS;
9557 }
9558 
9559 static int
9560 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
9561 {
9562 	struct aead_test_data tdata;
9563 	int res;
9564 
9565 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9566 	tdata.auth_tag.data[0] += 1;
9567 	res = test_authenticated_decryption(&tdata);
9568 	if (res == -ENOTSUP)
9569 		return res;
9570 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
9571 	return TEST_SUCCESS;
9572 }
9573 
9574 static int
9575 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
9576 {
9577 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9578 	struct crypto_unittest_params *ut_params = &unittest_params;
9579 
9580 	int retval;
9581 	uint8_t *ciphertext, *auth_tag;
9582 	uint16_t plaintext_pad_len;
9583 
9584 	/* Verify the capabilities */
9585 	struct rte_cryptodev_sym_capability_idx cap_idx;
9586 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9587 	cap_idx.algo.aead = tdata->algo;
9588 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9589 			&cap_idx) == NULL)
9590 		return -ENOTSUP;
9591 
9592 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9593 		return -ENOTSUP;
9594 
9595 	/* not supported with CPU crypto */
9596 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9597 		return -ENOTSUP;
9598 
9599 	/* Create AEAD session */
9600 	retval = create_aead_session(ts_params->valid_devs[0],
9601 			tdata->algo,
9602 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
9603 			tdata->key.data, tdata->key.len,
9604 			tdata->aad.len, tdata->auth_tag.len,
9605 			tdata->iv.len);
9606 	if (retval < 0)
9607 		return retval;
9608 
9609 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9610 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9611 
9612 	/* clear mbuf payload */
9613 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9614 			rte_pktmbuf_tailroom(ut_params->ibuf));
9615 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
9616 			rte_pktmbuf_tailroom(ut_params->obuf));
9617 
9618 	/* Create AEAD operation */
9619 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
9620 	if (retval < 0)
9621 		return retval;
9622 
9623 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9624 
9625 	ut_params->op->sym->m_src = ut_params->ibuf;
9626 	ut_params->op->sym->m_dst = ut_params->obuf;
9627 
9628 	/* Process crypto operation */
9629 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
9630 			ut_params->op), "failed to process sym crypto op");
9631 
9632 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9633 			"crypto op processing failed");
9634 
9635 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9636 
9637 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
9638 			ut_params->op->sym->cipher.data.offset);
9639 	auth_tag = ciphertext + plaintext_pad_len;
9640 
9641 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
9642 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
9643 
9644 	/* Validate obuf */
9645 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
9646 			ciphertext,
9647 			tdata->ciphertext.data,
9648 			tdata->ciphertext.len,
9649 			"Ciphertext data not as expected");
9650 
9651 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
9652 			auth_tag,
9653 			tdata->auth_tag.data,
9654 			tdata->auth_tag.len,
9655 			"Generated auth tag not as expected");
9656 
9657 	return 0;
9658 
9659 }
9660 
9661 static int
9662 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
9663 {
9664 	return test_authenticated_encryption_oop(&gcm_test_case_5);
9665 }
9666 
9667 static int
9668 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
9669 {
9670 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9671 	struct crypto_unittest_params *ut_params = &unittest_params;
9672 
9673 	int retval;
9674 	uint8_t *plaintext;
9675 
9676 	/* Verify the capabilities */
9677 	struct rte_cryptodev_sym_capability_idx cap_idx;
9678 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9679 	cap_idx.algo.aead = tdata->algo;
9680 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9681 			&cap_idx) == NULL)
9682 		return -ENOTSUP;
9683 
9684 	/* not supported with CPU crypto and raw data-path APIs*/
9685 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
9686 			global_api_test_type == CRYPTODEV_RAW_API_TEST)
9687 		return -ENOTSUP;
9688 
9689 	/* Create AEAD session */
9690 	retval = create_aead_session(ts_params->valid_devs[0],
9691 			tdata->algo,
9692 			RTE_CRYPTO_AEAD_OP_DECRYPT,
9693 			tdata->key.data, tdata->key.len,
9694 			tdata->aad.len, tdata->auth_tag.len,
9695 			tdata->iv.len);
9696 	if (retval < 0)
9697 		return retval;
9698 
9699 	/* alloc mbuf and set payload */
9700 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9701 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9702 
9703 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9704 			rte_pktmbuf_tailroom(ut_params->ibuf));
9705 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
9706 			rte_pktmbuf_tailroom(ut_params->obuf));
9707 
9708 	/* Create AEAD operation */
9709 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
9710 	if (retval < 0)
9711 		return retval;
9712 
9713 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9714 
9715 	ut_params->op->sym->m_src = ut_params->ibuf;
9716 	ut_params->op->sym->m_dst = ut_params->obuf;
9717 
9718 	/* Process crypto operation */
9719 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
9720 			ut_params->op), "failed to process sym crypto op");
9721 
9722 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9723 			"crypto op processing failed");
9724 
9725 	plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
9726 			ut_params->op->sym->cipher.data.offset);
9727 
9728 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
9729 
9730 	/* Validate obuf */
9731 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
9732 			plaintext,
9733 			tdata->plaintext.data,
9734 			tdata->plaintext.len,
9735 			"Plaintext data not as expected");
9736 
9737 	TEST_ASSERT_EQUAL(ut_params->op->status,
9738 			RTE_CRYPTO_OP_STATUS_SUCCESS,
9739 			"Authentication failed");
9740 	return 0;
9741 }
9742 
9743 static int
9744 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
9745 {
9746 	return test_authenticated_decryption_oop(&gcm_test_case_5);
9747 }
9748 
9749 static int
9750 test_authenticated_encryption_sessionless(
9751 		const struct aead_test_data *tdata)
9752 {
9753 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9754 	struct crypto_unittest_params *ut_params = &unittest_params;
9755 
9756 	int retval;
9757 	uint8_t *ciphertext, *auth_tag;
9758 	uint16_t plaintext_pad_len;
9759 	uint8_t key[tdata->key.len + 1];
9760 	struct rte_cryptodev_info dev_info;
9761 
9762 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9763 	uint64_t feat_flags = dev_info.feature_flags;
9764 
9765 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
9766 		printf("Device doesn't support Sessionless ops.\n");
9767 		return -ENOTSUP;
9768 	}
9769 
9770 	/* not supported with CPU crypto */
9771 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9772 		return -ENOTSUP;
9773 
9774 	/* Verify the capabilities */
9775 	struct rte_cryptodev_sym_capability_idx cap_idx;
9776 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9777 	cap_idx.algo.aead = tdata->algo;
9778 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9779 			&cap_idx) == NULL)
9780 		return -ENOTSUP;
9781 
9782 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9783 
9784 	/* clear mbuf payload */
9785 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9786 			rte_pktmbuf_tailroom(ut_params->ibuf));
9787 
9788 	/* Create AEAD operation */
9789 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
9790 	if (retval < 0)
9791 		return retval;
9792 
9793 	/* Create GCM xform */
9794 	memcpy(key, tdata->key.data, tdata->key.len);
9795 	retval = create_aead_xform(ut_params->op,
9796 			tdata->algo,
9797 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
9798 			key, tdata->key.len,
9799 			tdata->aad.len, tdata->auth_tag.len,
9800 			tdata->iv.len);
9801 	if (retval < 0)
9802 		return retval;
9803 
9804 	ut_params->op->sym->m_src = ut_params->ibuf;
9805 
9806 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
9807 			RTE_CRYPTO_OP_SESSIONLESS,
9808 			"crypto op session type not sessionless");
9809 
9810 	/* Process crypto operation */
9811 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
9812 			ut_params->op), "failed to process sym crypto op");
9813 
9814 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
9815 
9816 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9817 			"crypto op status not success");
9818 
9819 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9820 
9821 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
9822 			ut_params->op->sym->cipher.data.offset);
9823 	auth_tag = ciphertext + plaintext_pad_len;
9824 
9825 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
9826 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
9827 
9828 	/* Validate obuf */
9829 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
9830 			ciphertext,
9831 			tdata->ciphertext.data,
9832 			tdata->ciphertext.len,
9833 			"Ciphertext data not as expected");
9834 
9835 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
9836 			auth_tag,
9837 			tdata->auth_tag.data,
9838 			tdata->auth_tag.len,
9839 			"Generated auth tag not as expected");
9840 
9841 	return 0;
9842 
9843 }
9844 
9845 static int
9846 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
9847 {
9848 	return test_authenticated_encryption_sessionless(
9849 			&gcm_test_case_5);
9850 }
9851 
9852 static int
9853 test_authenticated_decryption_sessionless(
9854 		const struct aead_test_data *tdata)
9855 {
9856 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9857 	struct crypto_unittest_params *ut_params = &unittest_params;
9858 
9859 	int retval;
9860 	uint8_t *plaintext;
9861 	uint8_t key[tdata->key.len + 1];
9862 	struct rte_cryptodev_info dev_info;
9863 
9864 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9865 	uint64_t feat_flags = dev_info.feature_flags;
9866 
9867 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
9868 		printf("Device doesn't support Sessionless ops.\n");
9869 		return -ENOTSUP;
9870 	}
9871 
9872 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
9873 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
9874 		printf("Device doesn't support RAW data-path APIs.\n");
9875 		return -ENOTSUP;
9876 	}
9877 
9878 	/* not supported with CPU crypto */
9879 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9880 		return -ENOTSUP;
9881 
9882 	/* Verify the capabilities */
9883 	struct rte_cryptodev_sym_capability_idx cap_idx;
9884 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9885 	cap_idx.algo.aead = tdata->algo;
9886 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9887 			&cap_idx) == NULL)
9888 		return -ENOTSUP;
9889 
9890 	/* alloc mbuf and set payload */
9891 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9892 
9893 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9894 			rte_pktmbuf_tailroom(ut_params->ibuf));
9895 
9896 	/* Create AEAD operation */
9897 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
9898 	if (retval < 0)
9899 		return retval;
9900 
9901 	/* Create AEAD xform */
9902 	memcpy(key, tdata->key.data, tdata->key.len);
9903 	retval = create_aead_xform(ut_params->op,
9904 			tdata->algo,
9905 			RTE_CRYPTO_AEAD_OP_DECRYPT,
9906 			key, tdata->key.len,
9907 			tdata->aad.len, tdata->auth_tag.len,
9908 			tdata->iv.len);
9909 	if (retval < 0)
9910 		return retval;
9911 
9912 	ut_params->op->sym->m_src = ut_params->ibuf;
9913 
9914 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
9915 			RTE_CRYPTO_OP_SESSIONLESS,
9916 			"crypto op session type not sessionless");
9917 
9918 	/* Process crypto operation */
9919 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9920 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
9921 				ut_params->op, 0, 0, 0, 0);
9922 	else
9923 		TEST_ASSERT_NOT_NULL(process_crypto_request(
9924 			ts_params->valid_devs[0], ut_params->op),
9925 				"failed to process sym crypto op");
9926 
9927 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
9928 
9929 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9930 			"crypto op status not success");
9931 
9932 	plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
9933 			ut_params->op->sym->cipher.data.offset);
9934 
9935 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
9936 
9937 	/* Validate obuf */
9938 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
9939 			plaintext,
9940 			tdata->plaintext.data,
9941 			tdata->plaintext.len,
9942 			"Plaintext data not as expected");
9943 
9944 	TEST_ASSERT_EQUAL(ut_params->op->status,
9945 			RTE_CRYPTO_OP_STATUS_SUCCESS,
9946 			"Authentication failed");
9947 	return 0;
9948 }
9949 
9950 static int
9951 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
9952 {
9953 	return test_authenticated_decryption_sessionless(
9954 			&gcm_test_case_5);
9955 }
9956 
9957 static int
9958 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
9959 {
9960 	return test_authenticated_encryption(&ccm_test_case_128_1);
9961 }
9962 
9963 static int
9964 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
9965 {
9966 	return test_authenticated_encryption(&ccm_test_case_128_2);
9967 }
9968 
9969 static int
9970 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
9971 {
9972 	return test_authenticated_encryption(&ccm_test_case_128_3);
9973 }
9974 
9975 static int
9976 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
9977 {
9978 	return test_authenticated_decryption(&ccm_test_case_128_1);
9979 }
9980 
9981 static int
9982 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
9983 {
9984 	return test_authenticated_decryption(&ccm_test_case_128_2);
9985 }
9986 
9987 static int
9988 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
9989 {
9990 	return test_authenticated_decryption(&ccm_test_case_128_3);
9991 }
9992 
9993 static int
9994 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
9995 {
9996 	return test_authenticated_encryption(&ccm_test_case_192_1);
9997 }
9998 
9999 static int
10000 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
10001 {
10002 	return test_authenticated_encryption(&ccm_test_case_192_2);
10003 }
10004 
10005 static int
10006 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
10007 {
10008 	return test_authenticated_encryption(&ccm_test_case_192_3);
10009 }
10010 
10011 static int
10012 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
10013 {
10014 	return test_authenticated_decryption(&ccm_test_case_192_1);
10015 }
10016 
10017 static int
10018 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
10019 {
10020 	return test_authenticated_decryption(&ccm_test_case_192_2);
10021 }
10022 
10023 static int
10024 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
10025 {
10026 	return test_authenticated_decryption(&ccm_test_case_192_3);
10027 }
10028 
10029 static int
10030 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
10031 {
10032 	return test_authenticated_encryption(&ccm_test_case_256_1);
10033 }
10034 
10035 static int
10036 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
10037 {
10038 	return test_authenticated_encryption(&ccm_test_case_256_2);
10039 }
10040 
10041 static int
10042 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
10043 {
10044 	return test_authenticated_encryption(&ccm_test_case_256_3);
10045 }
10046 
10047 static int
10048 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
10049 {
10050 	return test_authenticated_decryption(&ccm_test_case_256_1);
10051 }
10052 
10053 static int
10054 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
10055 {
10056 	return test_authenticated_decryption(&ccm_test_case_256_2);
10057 }
10058 
10059 static int
10060 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
10061 {
10062 	return test_authenticated_decryption(&ccm_test_case_256_3);
10063 }
10064 
10065 static int
10066 test_stats(void)
10067 {
10068 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10069 	struct rte_cryptodev_stats stats;
10070 
10071 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10072 		return -ENOTSUP;
10073 
10074 	/* Verify the capabilities */
10075 	struct rte_cryptodev_sym_capability_idx cap_idx;
10076 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10077 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
10078 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10079 			&cap_idx) == NULL)
10080 		return -ENOTSUP;
10081 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10082 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10083 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10084 			&cap_idx) == NULL)
10085 		return -ENOTSUP;
10086 
10087 	if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
10088 			== -ENOTSUP)
10089 		return -ENOTSUP;
10090 
10091 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10092 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
10093 			&stats) == -ENODEV),
10094 		"rte_cryptodev_stats_get invalid dev failed");
10095 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
10096 		"rte_cryptodev_stats_get invalid Param failed");
10097 
10098 	/* Test expected values */
10099 	test_AES_CBC_HMAC_SHA1_encrypt_digest();
10100 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10101 			&stats),
10102 		"rte_cryptodev_stats_get failed");
10103 	TEST_ASSERT((stats.enqueued_count == 1),
10104 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10105 	TEST_ASSERT((stats.dequeued_count == 1),
10106 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10107 	TEST_ASSERT((stats.enqueue_err_count == 0),
10108 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10109 	TEST_ASSERT((stats.dequeue_err_count == 0),
10110 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10111 
10112 	/* invalid device but should ignore and not reset device stats*/
10113 	rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
10114 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10115 			&stats),
10116 		"rte_cryptodev_stats_get failed");
10117 	TEST_ASSERT((stats.enqueued_count == 1),
10118 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10119 
10120 	/* check that a valid reset clears stats */
10121 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10122 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10123 			&stats),
10124 					  "rte_cryptodev_stats_get failed");
10125 	TEST_ASSERT((stats.enqueued_count == 0),
10126 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10127 	TEST_ASSERT((stats.dequeued_count == 0),
10128 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10129 
10130 	return TEST_SUCCESS;
10131 }
10132 
10133 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
10134 				   struct crypto_unittest_params *ut_params,
10135 				   enum rte_crypto_auth_operation op,
10136 				   const struct HMAC_MD5_vector *test_case)
10137 {
10138 	uint8_t key[64];
10139 
10140 	memcpy(key, test_case->key.data, test_case->key.len);
10141 
10142 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10143 	ut_params->auth_xform.next = NULL;
10144 	ut_params->auth_xform.auth.op = op;
10145 
10146 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
10147 
10148 	ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
10149 	ut_params->auth_xform.auth.key.length = test_case->key.len;
10150 	ut_params->auth_xform.auth.key.data = key;
10151 
10152 	ut_params->sess = rte_cryptodev_sym_session_create(
10153 			ts_params->session_mpool);
10154 
10155 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10156 			ut_params->sess, &ut_params->auth_xform,
10157 			ts_params->session_priv_mpool);
10158 
10159 	if (ut_params->sess == NULL)
10160 		return TEST_FAILED;
10161 
10162 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10163 
10164 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10165 			rte_pktmbuf_tailroom(ut_params->ibuf));
10166 
10167 	return 0;
10168 }
10169 
10170 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
10171 			      const struct HMAC_MD5_vector *test_case,
10172 			      uint8_t **plaintext)
10173 {
10174 	uint16_t plaintext_pad_len;
10175 
10176 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10177 
10178 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
10179 				16);
10180 
10181 	*plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10182 			plaintext_pad_len);
10183 	memcpy(*plaintext, test_case->plaintext.data,
10184 			test_case->plaintext.len);
10185 
10186 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10187 			ut_params->ibuf, MD5_DIGEST_LEN);
10188 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10189 			"no room to append digest");
10190 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10191 			ut_params->ibuf, plaintext_pad_len);
10192 
10193 	if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
10194 		rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
10195 			   test_case->auth_tag.len);
10196 	}
10197 
10198 	sym_op->auth.data.offset = 0;
10199 	sym_op->auth.data.length = test_case->plaintext.len;
10200 
10201 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10202 	ut_params->op->sym->m_src = ut_params->ibuf;
10203 
10204 	return 0;
10205 }
10206 
10207 static int
10208 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
10209 {
10210 	uint16_t plaintext_pad_len;
10211 	uint8_t *plaintext, *auth_tag;
10212 
10213 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10214 	struct crypto_unittest_params *ut_params = &unittest_params;
10215 	struct rte_cryptodev_info dev_info;
10216 
10217 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10218 	uint64_t feat_flags = dev_info.feature_flags;
10219 
10220 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10221 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10222 		printf("Device doesn't support RAW data-path APIs.\n");
10223 		return -ENOTSUP;
10224 	}
10225 
10226 	/* Verify the capabilities */
10227 	struct rte_cryptodev_sym_capability_idx cap_idx;
10228 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10229 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
10230 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10231 			&cap_idx) == NULL)
10232 		return -ENOTSUP;
10233 
10234 	if (MD5_HMAC_create_session(ts_params, ut_params,
10235 			RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
10236 		return TEST_FAILED;
10237 
10238 	/* Generate Crypto op data structure */
10239 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10240 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10241 	TEST_ASSERT_NOT_NULL(ut_params->op,
10242 			"Failed to allocate symmetric crypto operation struct");
10243 
10244 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
10245 				16);
10246 
10247 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
10248 		return TEST_FAILED;
10249 
10250 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10251 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10252 			ut_params->op);
10253 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10254 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10255 				ut_params->op, 0, 1, 0, 0);
10256 	else
10257 		TEST_ASSERT_NOT_NULL(
10258 			process_crypto_request(ts_params->valid_devs[0],
10259 				ut_params->op),
10260 				"failed to process sym crypto op");
10261 
10262 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10263 			"crypto op processing failed");
10264 
10265 	if (ut_params->op->sym->m_dst) {
10266 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
10267 				uint8_t *, plaintext_pad_len);
10268 	} else {
10269 		auth_tag = plaintext + plaintext_pad_len;
10270 	}
10271 
10272 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10273 			auth_tag,
10274 			test_case->auth_tag.data,
10275 			test_case->auth_tag.len,
10276 			"HMAC_MD5 generated tag not as expected");
10277 
10278 	return TEST_SUCCESS;
10279 }
10280 
10281 static int
10282 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
10283 {
10284 	uint8_t *plaintext;
10285 
10286 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10287 	struct crypto_unittest_params *ut_params = &unittest_params;
10288 	struct rte_cryptodev_info dev_info;
10289 
10290 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10291 	uint64_t feat_flags = dev_info.feature_flags;
10292 
10293 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10294 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10295 		printf("Device doesn't support RAW data-path APIs.\n");
10296 		return -ENOTSUP;
10297 	}
10298 
10299 	/* Verify the capabilities */
10300 	struct rte_cryptodev_sym_capability_idx cap_idx;
10301 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10302 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
10303 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10304 			&cap_idx) == NULL)
10305 		return -ENOTSUP;
10306 
10307 	if (MD5_HMAC_create_session(ts_params, ut_params,
10308 			RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
10309 		return TEST_FAILED;
10310 	}
10311 
10312 	/* Generate Crypto op data structure */
10313 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10314 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10315 	TEST_ASSERT_NOT_NULL(ut_params->op,
10316 			"Failed to allocate symmetric crypto operation struct");
10317 
10318 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
10319 		return TEST_FAILED;
10320 
10321 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10322 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10323 			ut_params->op);
10324 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10325 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10326 				ut_params->op, 0, 1, 0, 0);
10327 	else
10328 		TEST_ASSERT_NOT_NULL(
10329 			process_crypto_request(ts_params->valid_devs[0],
10330 				ut_params->op),
10331 				"failed to process sym crypto op");
10332 
10333 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10334 			"HMAC_MD5 crypto op processing failed");
10335 
10336 	return TEST_SUCCESS;
10337 }
10338 
10339 static int
10340 test_MD5_HMAC_generate_case_1(void)
10341 {
10342 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
10343 }
10344 
10345 static int
10346 test_MD5_HMAC_verify_case_1(void)
10347 {
10348 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
10349 }
10350 
10351 static int
10352 test_MD5_HMAC_generate_case_2(void)
10353 {
10354 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
10355 }
10356 
10357 static int
10358 test_MD5_HMAC_verify_case_2(void)
10359 {
10360 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
10361 }
10362 
10363 static int
10364 test_multi_session(void)
10365 {
10366 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10367 	struct crypto_unittest_params *ut_params = &unittest_params;
10368 
10369 	struct rte_cryptodev_info dev_info;
10370 	struct rte_cryptodev_sym_session **sessions;
10371 
10372 	uint16_t i;
10373 
10374 	/* Verify the capabilities */
10375 	struct rte_cryptodev_sym_capability_idx cap_idx;
10376 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10377 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
10378 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10379 			&cap_idx) == NULL)
10380 		return -ENOTSUP;
10381 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10382 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10383 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10384 			&cap_idx) == NULL)
10385 		return -ENOTSUP;
10386 
10387 	test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
10388 			aes_cbc_key, hmac_sha512_key);
10389 
10390 
10391 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10392 
10393 	sessions = rte_malloc(NULL,
10394 			(sizeof(struct rte_cryptodev_sym_session *) *
10395 			MAX_NB_SESSIONS) + 1, 0);
10396 
10397 	/* Create multiple crypto sessions*/
10398 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
10399 
10400 		sessions[i] = rte_cryptodev_sym_session_create(
10401 				ts_params->session_mpool);
10402 
10403 		rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10404 				sessions[i], &ut_params->auth_xform,
10405 				ts_params->session_priv_mpool);
10406 		TEST_ASSERT_NOT_NULL(sessions[i],
10407 				"Session creation failed at session number %u",
10408 				i);
10409 
10410 		/* Attempt to send a request on each session */
10411 		TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
10412 			sessions[i],
10413 			ut_params,
10414 			ts_params,
10415 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
10416 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
10417 			aes_cbc_iv),
10418 			"Failed to perform decrypt on request number %u.", i);
10419 		/* free crypto operation structure */
10420 		if (ut_params->op)
10421 			rte_crypto_op_free(ut_params->op);
10422 
10423 		/*
10424 		 * free mbuf - both obuf and ibuf are usually the same,
10425 		 * so check if they point at the same address is necessary,
10426 		 * to avoid freeing the mbuf twice.
10427 		 */
10428 		if (ut_params->obuf) {
10429 			rte_pktmbuf_free(ut_params->obuf);
10430 			if (ut_params->ibuf == ut_params->obuf)
10431 				ut_params->ibuf = 0;
10432 			ut_params->obuf = 0;
10433 		}
10434 		if (ut_params->ibuf) {
10435 			rte_pktmbuf_free(ut_params->ibuf);
10436 			ut_params->ibuf = 0;
10437 		}
10438 	}
10439 
10440 	/* Next session create should fail */
10441 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10442 			sessions[i], &ut_params->auth_xform,
10443 			ts_params->session_priv_mpool);
10444 	TEST_ASSERT_NULL(sessions[i],
10445 			"Session creation succeeded unexpectedly!");
10446 
10447 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
10448 		rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
10449 				sessions[i]);
10450 		rte_cryptodev_sym_session_free(sessions[i]);
10451 	}
10452 
10453 	rte_free(sessions);
10454 
10455 	return TEST_SUCCESS;
10456 }
10457 
10458 struct multi_session_params {
10459 	struct crypto_unittest_params ut_params;
10460 	uint8_t *cipher_key;
10461 	uint8_t *hmac_key;
10462 	const uint8_t *cipher;
10463 	const uint8_t *digest;
10464 	uint8_t *iv;
10465 };
10466 
10467 #define MB_SESSION_NUMBER 3
10468 
10469 static int
10470 test_multi_session_random_usage(void)
10471 {
10472 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10473 	struct rte_cryptodev_info dev_info;
10474 	struct rte_cryptodev_sym_session **sessions;
10475 	uint32_t i, j;
10476 	struct multi_session_params ut_paramz[] = {
10477 
10478 		{
10479 			.cipher_key = ms_aes_cbc_key0,
10480 			.hmac_key = ms_hmac_key0,
10481 			.cipher = ms_aes_cbc_cipher0,
10482 			.digest = ms_hmac_digest0,
10483 			.iv = ms_aes_cbc_iv0
10484 		},
10485 		{
10486 			.cipher_key = ms_aes_cbc_key1,
10487 			.hmac_key = ms_hmac_key1,
10488 			.cipher = ms_aes_cbc_cipher1,
10489 			.digest = ms_hmac_digest1,
10490 			.iv = ms_aes_cbc_iv1
10491 		},
10492 		{
10493 			.cipher_key = ms_aes_cbc_key2,
10494 			.hmac_key = ms_hmac_key2,
10495 			.cipher = ms_aes_cbc_cipher2,
10496 			.digest = ms_hmac_digest2,
10497 			.iv = ms_aes_cbc_iv2
10498 		},
10499 
10500 	};
10501 
10502 	/* Verify the capabilities */
10503 	struct rte_cryptodev_sym_capability_idx cap_idx;
10504 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10505 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
10506 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10507 			&cap_idx) == NULL)
10508 		return -ENOTSUP;
10509 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10510 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10511 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10512 			&cap_idx) == NULL)
10513 		return -ENOTSUP;
10514 
10515 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10516 
10517 	sessions = rte_malloc(NULL,
10518 			(sizeof(struct rte_cryptodev_sym_session *)
10519 					* MAX_NB_SESSIONS) + 1, 0);
10520 
10521 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
10522 		sessions[i] = rte_cryptodev_sym_session_create(
10523 				ts_params->session_mpool);
10524 
10525 		rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
10526 				sizeof(struct crypto_unittest_params));
10527 
10528 		test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
10529 				&ut_paramz[i].ut_params,
10530 				ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
10531 
10532 		/* Create multiple crypto sessions*/
10533 		rte_cryptodev_sym_session_init(
10534 				ts_params->valid_devs[0],
10535 				sessions[i],
10536 				&ut_paramz[i].ut_params.auth_xform,
10537 				ts_params->session_priv_mpool);
10538 
10539 		TEST_ASSERT_NOT_NULL(sessions[i],
10540 				"Session creation failed at session number %u",
10541 				i);
10542 
10543 	}
10544 
10545 	srand(time(NULL));
10546 	for (i = 0; i < 40000; i++) {
10547 
10548 		j = rand() % MB_SESSION_NUMBER;
10549 
10550 		TEST_ASSERT_SUCCESS(
10551 			test_AES_CBC_HMAC_SHA512_decrypt_perform(
10552 					sessions[j],
10553 					&ut_paramz[j].ut_params,
10554 					ts_params, ut_paramz[j].cipher,
10555 					ut_paramz[j].digest,
10556 					ut_paramz[j].iv),
10557 			"Failed to perform decrypt on request number %u.", i);
10558 
10559 		if (ut_paramz[j].ut_params.op)
10560 			rte_crypto_op_free(ut_paramz[j].ut_params.op);
10561 
10562 		/*
10563 		 * free mbuf - both obuf and ibuf are usually the same,
10564 		 * so check if they point at the same address is necessary,
10565 		 * to avoid freeing the mbuf twice.
10566 		 */
10567 		if (ut_paramz[j].ut_params.obuf) {
10568 			rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
10569 			if (ut_paramz[j].ut_params.ibuf
10570 					== ut_paramz[j].ut_params.obuf)
10571 				ut_paramz[j].ut_params.ibuf = 0;
10572 			ut_paramz[j].ut_params.obuf = 0;
10573 		}
10574 		if (ut_paramz[j].ut_params.ibuf) {
10575 			rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
10576 			ut_paramz[j].ut_params.ibuf = 0;
10577 		}
10578 	}
10579 
10580 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
10581 		rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
10582 				sessions[i]);
10583 		rte_cryptodev_sym_session_free(sessions[i]);
10584 	}
10585 
10586 	rte_free(sessions);
10587 
10588 	return TEST_SUCCESS;
10589 }
10590 
10591 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
10592 			0xab, 0xab, 0xab, 0xab,
10593 			0xab, 0xab, 0xab, 0xab,
10594 			0xab, 0xab, 0xab, 0xab};
10595 
10596 static int
10597 test_null_invalid_operation(void)
10598 {
10599 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10600 	struct crypto_unittest_params *ut_params = &unittest_params;
10601 	int ret;
10602 
10603 	/* This test is for NULL PMD only */
10604 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
10605 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
10606 		return -ENOTSUP;
10607 
10608 	/* Setup Cipher Parameters */
10609 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10610 	ut_params->cipher_xform.next = NULL;
10611 
10612 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
10613 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
10614 
10615 	ut_params->sess = rte_cryptodev_sym_session_create(
10616 			ts_params->session_mpool);
10617 
10618 	/* Create Crypto session*/
10619 	ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10620 			ut_params->sess, &ut_params->cipher_xform,
10621 			ts_params->session_priv_mpool);
10622 	TEST_ASSERT(ret < 0,
10623 			"Session creation succeeded unexpectedly");
10624 
10625 
10626 	/* Setup HMAC Parameters */
10627 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10628 	ut_params->auth_xform.next = NULL;
10629 
10630 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
10631 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
10632 
10633 	ut_params->sess = rte_cryptodev_sym_session_create(
10634 			ts_params->session_mpool);
10635 
10636 	/* Create Crypto session*/
10637 	ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10638 			ut_params->sess, &ut_params->auth_xform,
10639 			ts_params->session_priv_mpool);
10640 	TEST_ASSERT(ret < 0,
10641 			"Session creation succeeded unexpectedly");
10642 
10643 	return TEST_SUCCESS;
10644 }
10645 
10646 
10647 #define NULL_BURST_LENGTH (32)
10648 
10649 static int
10650 test_null_burst_operation(void)
10651 {
10652 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10653 	struct crypto_unittest_params *ut_params = &unittest_params;
10654 
10655 	unsigned i, burst_len = NULL_BURST_LENGTH;
10656 
10657 	struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
10658 	struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
10659 
10660 	/* This test is for NULL PMD only */
10661 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
10662 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
10663 		return -ENOTSUP;
10664 
10665 	/* Setup Cipher Parameters */
10666 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10667 	ut_params->cipher_xform.next = &ut_params->auth_xform;
10668 
10669 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
10670 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
10671 
10672 	/* Setup HMAC Parameters */
10673 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10674 	ut_params->auth_xform.next = NULL;
10675 
10676 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
10677 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
10678 
10679 	ut_params->sess = rte_cryptodev_sym_session_create(
10680 			ts_params->session_mpool);
10681 
10682 	/* Create Crypto session*/
10683 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10684 			ut_params->sess, &ut_params->cipher_xform,
10685 			ts_params->session_priv_mpool);
10686 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10687 
10688 	TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
10689 			RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
10690 			burst_len, "failed to generate burst of crypto ops");
10691 
10692 	/* Generate an operation for each mbuf in burst */
10693 	for (i = 0; i < burst_len; i++) {
10694 		struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10695 
10696 		TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
10697 
10698 		unsigned *data = (unsigned *)rte_pktmbuf_append(m,
10699 				sizeof(unsigned));
10700 		*data = i;
10701 
10702 		rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
10703 
10704 		burst[i]->sym->m_src = m;
10705 	}
10706 
10707 	/* Process crypto operation */
10708 	TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
10709 			0, burst, burst_len),
10710 			burst_len,
10711 			"Error enqueuing burst");
10712 
10713 	TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
10714 			0, burst_dequeued, burst_len),
10715 			burst_len,
10716 			"Error dequeuing burst");
10717 
10718 
10719 	for (i = 0; i < burst_len; i++) {
10720 		TEST_ASSERT_EQUAL(
10721 			*rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
10722 			*rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
10723 					uint32_t *),
10724 			"data not as expected");
10725 
10726 		rte_pktmbuf_free(burst[i]->sym->m_src);
10727 		rte_crypto_op_free(burst[i]);
10728 	}
10729 
10730 	return TEST_SUCCESS;
10731 }
10732 
10733 static void
10734 generate_gmac_large_plaintext(uint8_t *data)
10735 {
10736 	uint16_t i;
10737 
10738 	for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
10739 		memcpy(&data[i], &data[0], 32);
10740 }
10741 
10742 static int
10743 create_gmac_operation(enum rte_crypto_auth_operation op,
10744 		const struct gmac_test_data *tdata)
10745 {
10746 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10747 	struct crypto_unittest_params *ut_params = &unittest_params;
10748 	struct rte_crypto_sym_op *sym_op;
10749 
10750 	uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10751 
10752 	/* Generate Crypto op data structure */
10753 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10754 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10755 	TEST_ASSERT_NOT_NULL(ut_params->op,
10756 			"Failed to allocate symmetric crypto operation struct");
10757 
10758 	sym_op = ut_params->op->sym;
10759 
10760 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10761 			ut_params->ibuf, tdata->gmac_tag.len);
10762 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10763 			"no room to append digest");
10764 
10765 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10766 			ut_params->ibuf, plaintext_pad_len);
10767 
10768 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
10769 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
10770 				tdata->gmac_tag.len);
10771 		debug_hexdump(stdout, "digest:",
10772 				sym_op->auth.digest.data,
10773 				tdata->gmac_tag.len);
10774 	}
10775 
10776 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
10777 			uint8_t *, IV_OFFSET);
10778 
10779 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
10780 
10781 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
10782 
10783 	sym_op->cipher.data.length = 0;
10784 	sym_op->cipher.data.offset = 0;
10785 
10786 	sym_op->auth.data.offset = 0;
10787 	sym_op->auth.data.length = tdata->plaintext.len;
10788 
10789 	return 0;
10790 }
10791 
10792 static int
10793 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
10794 		const struct gmac_test_data *tdata,
10795 		void *digest_mem, uint64_t digest_phys)
10796 {
10797 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10798 	struct crypto_unittest_params *ut_params = &unittest_params;
10799 	struct rte_crypto_sym_op *sym_op;
10800 
10801 	/* Generate Crypto op data structure */
10802 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10803 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10804 	TEST_ASSERT_NOT_NULL(ut_params->op,
10805 			"Failed to allocate symmetric crypto operation struct");
10806 
10807 	sym_op = ut_params->op->sym;
10808 
10809 	sym_op->auth.digest.data = digest_mem;
10810 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10811 			"no room to append digest");
10812 
10813 	sym_op->auth.digest.phys_addr = digest_phys;
10814 
10815 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
10816 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
10817 				tdata->gmac_tag.len);
10818 		debug_hexdump(stdout, "digest:",
10819 				sym_op->auth.digest.data,
10820 				tdata->gmac_tag.len);
10821 	}
10822 
10823 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
10824 			uint8_t *, IV_OFFSET);
10825 
10826 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
10827 
10828 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
10829 
10830 	sym_op->cipher.data.length = 0;
10831 	sym_op->cipher.data.offset = 0;
10832 
10833 	sym_op->auth.data.offset = 0;
10834 	sym_op->auth.data.length = tdata->plaintext.len;
10835 
10836 	return 0;
10837 }
10838 
10839 static int create_gmac_session(uint8_t dev_id,
10840 		const struct gmac_test_data *tdata,
10841 		enum rte_crypto_auth_operation auth_op)
10842 {
10843 	uint8_t auth_key[tdata->key.len];
10844 
10845 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10846 	struct crypto_unittest_params *ut_params = &unittest_params;
10847 
10848 	memcpy(auth_key, tdata->key.data, tdata->key.len);
10849 
10850 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10851 	ut_params->auth_xform.next = NULL;
10852 
10853 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
10854 	ut_params->auth_xform.auth.op = auth_op;
10855 	ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
10856 	ut_params->auth_xform.auth.key.length = tdata->key.len;
10857 	ut_params->auth_xform.auth.key.data = auth_key;
10858 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
10859 	ut_params->auth_xform.auth.iv.length = tdata->iv.len;
10860 
10861 
10862 	ut_params->sess = rte_cryptodev_sym_session_create(
10863 			ts_params->session_mpool);
10864 
10865 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
10866 			&ut_params->auth_xform,
10867 			ts_params->session_priv_mpool);
10868 
10869 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10870 
10871 	return 0;
10872 }
10873 
10874 static int
10875 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
10876 {
10877 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10878 	struct crypto_unittest_params *ut_params = &unittest_params;
10879 	struct rte_cryptodev_info dev_info;
10880 
10881 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10882 	uint64_t feat_flags = dev_info.feature_flags;
10883 
10884 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10885 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10886 		printf("Device doesn't support RAW data-path APIs.\n");
10887 		return -ENOTSUP;
10888 	}
10889 
10890 	int retval;
10891 
10892 	uint8_t *auth_tag, *plaintext;
10893 	uint16_t plaintext_pad_len;
10894 
10895 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
10896 			      "No GMAC length in the source data");
10897 
10898 	/* Verify the capabilities */
10899 	struct rte_cryptodev_sym_capability_idx cap_idx;
10900 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10901 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
10902 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10903 			&cap_idx) == NULL)
10904 		return -ENOTSUP;
10905 
10906 	retval = create_gmac_session(ts_params->valid_devs[0],
10907 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
10908 
10909 	if (retval < 0)
10910 		return retval;
10911 
10912 	if (tdata->plaintext.len > MBUF_SIZE)
10913 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
10914 	else
10915 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10916 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10917 			"Failed to allocate input buffer in mempool");
10918 
10919 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10920 			rte_pktmbuf_tailroom(ut_params->ibuf));
10921 
10922 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10923 	/*
10924 	 * Runtime generate the large plain text instead of use hard code
10925 	 * plain text vector. It is done to avoid create huge source file
10926 	 * with the test vector.
10927 	 */
10928 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
10929 		generate_gmac_large_plaintext(tdata->plaintext.data);
10930 
10931 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10932 				plaintext_pad_len);
10933 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
10934 
10935 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
10936 	debug_hexdump(stdout, "plaintext:", plaintext,
10937 			tdata->plaintext.len);
10938 
10939 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
10940 			tdata);
10941 
10942 	if (retval < 0)
10943 		return retval;
10944 
10945 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10946 
10947 	ut_params->op->sym->m_src = ut_params->ibuf;
10948 
10949 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10950 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10951 			ut_params->op);
10952 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10953 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10954 				ut_params->op, 0, 1, 0, 0);
10955 	else
10956 		TEST_ASSERT_NOT_NULL(
10957 			process_crypto_request(ts_params->valid_devs[0],
10958 			ut_params->op), "failed to process sym crypto op");
10959 
10960 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10961 			"crypto op processing failed");
10962 
10963 	if (ut_params->op->sym->m_dst) {
10964 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
10965 				uint8_t *, plaintext_pad_len);
10966 	} else {
10967 		auth_tag = plaintext + plaintext_pad_len;
10968 	}
10969 
10970 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
10971 
10972 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10973 			auth_tag,
10974 			tdata->gmac_tag.data,
10975 			tdata->gmac_tag.len,
10976 			"GMAC Generated auth tag not as expected");
10977 
10978 	return 0;
10979 }
10980 
10981 static int
10982 test_AES_GMAC_authentication_test_case_1(void)
10983 {
10984 	return test_AES_GMAC_authentication(&gmac_test_case_1);
10985 }
10986 
10987 static int
10988 test_AES_GMAC_authentication_test_case_2(void)
10989 {
10990 	return test_AES_GMAC_authentication(&gmac_test_case_2);
10991 }
10992 
10993 static int
10994 test_AES_GMAC_authentication_test_case_3(void)
10995 {
10996 	return test_AES_GMAC_authentication(&gmac_test_case_3);
10997 }
10998 
10999 static int
11000 test_AES_GMAC_authentication_test_case_4(void)
11001 {
11002 	return test_AES_GMAC_authentication(&gmac_test_case_4);
11003 }
11004 
11005 static int
11006 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
11007 {
11008 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11009 	struct crypto_unittest_params *ut_params = &unittest_params;
11010 	int retval;
11011 	uint32_t plaintext_pad_len;
11012 	uint8_t *plaintext;
11013 	struct rte_cryptodev_info dev_info;
11014 
11015 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11016 	uint64_t feat_flags = dev_info.feature_flags;
11017 
11018 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11019 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11020 		printf("Device doesn't support RAW data-path APIs.\n");
11021 		return -ENOTSUP;
11022 	}
11023 
11024 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11025 			      "No GMAC length in the source data");
11026 
11027 	/* Verify the capabilities */
11028 	struct rte_cryptodev_sym_capability_idx cap_idx;
11029 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11030 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11031 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11032 			&cap_idx) == NULL)
11033 		return -ENOTSUP;
11034 
11035 	retval = create_gmac_session(ts_params->valid_devs[0],
11036 			tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
11037 
11038 	if (retval < 0)
11039 		return retval;
11040 
11041 	if (tdata->plaintext.len > MBUF_SIZE)
11042 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
11043 	else
11044 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11045 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11046 			"Failed to allocate input buffer in mempool");
11047 
11048 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11049 			rte_pktmbuf_tailroom(ut_params->ibuf));
11050 
11051 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11052 
11053 	/*
11054 	 * Runtime generate the large plain text instead of use hard code
11055 	 * plain text vector. It is done to avoid create huge source file
11056 	 * with the test vector.
11057 	 */
11058 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
11059 		generate_gmac_large_plaintext(tdata->plaintext.data);
11060 
11061 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11062 				plaintext_pad_len);
11063 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11064 
11065 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
11066 	debug_hexdump(stdout, "plaintext:", plaintext,
11067 			tdata->plaintext.len);
11068 
11069 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
11070 			tdata);
11071 
11072 	if (retval < 0)
11073 		return retval;
11074 
11075 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11076 
11077 	ut_params->op->sym->m_src = ut_params->ibuf;
11078 
11079 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11080 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11081 			ut_params->op);
11082 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11083 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11084 				ut_params->op, 0, 1, 0, 0);
11085 	else
11086 		TEST_ASSERT_NOT_NULL(
11087 			process_crypto_request(ts_params->valid_devs[0],
11088 			ut_params->op), "failed to process sym crypto op");
11089 
11090 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11091 			"crypto op processing failed");
11092 
11093 	return 0;
11094 
11095 }
11096 
11097 static int
11098 test_AES_GMAC_authentication_verify_test_case_1(void)
11099 {
11100 	return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
11101 }
11102 
11103 static int
11104 test_AES_GMAC_authentication_verify_test_case_2(void)
11105 {
11106 	return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
11107 }
11108 
11109 static int
11110 test_AES_GMAC_authentication_verify_test_case_3(void)
11111 {
11112 	return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
11113 }
11114 
11115 static int
11116 test_AES_GMAC_authentication_verify_test_case_4(void)
11117 {
11118 	return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
11119 }
11120 
11121 static int
11122 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
11123 				uint32_t fragsz)
11124 {
11125 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11126 	struct crypto_unittest_params *ut_params = &unittest_params;
11127 	struct rte_cryptodev_info dev_info;
11128 	uint64_t feature_flags;
11129 	unsigned int trn_data = 0;
11130 	void *digest_mem = NULL;
11131 	uint32_t segs = 1;
11132 	unsigned int to_trn = 0;
11133 	struct rte_mbuf *buf = NULL;
11134 	uint8_t *auth_tag, *plaintext;
11135 	int retval;
11136 
11137 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11138 			      "No GMAC length in the source data");
11139 
11140 	/* Verify the capabilities */
11141 	struct rte_cryptodev_sym_capability_idx cap_idx;
11142 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11143 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11144 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11145 			&cap_idx) == NULL)
11146 		return -ENOTSUP;
11147 
11148 	/* Check for any input SGL support */
11149 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11150 	feature_flags = dev_info.feature_flags;
11151 
11152 	if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
11153 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
11154 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
11155 		return -ENOTSUP;
11156 
11157 	if (fragsz > tdata->plaintext.len)
11158 		fragsz = tdata->plaintext.len;
11159 
11160 	uint16_t plaintext_len = fragsz;
11161 
11162 	retval = create_gmac_session(ts_params->valid_devs[0],
11163 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
11164 
11165 	if (retval < 0)
11166 		return retval;
11167 
11168 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11169 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11170 			"Failed to allocate input buffer in mempool");
11171 
11172 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11173 			rte_pktmbuf_tailroom(ut_params->ibuf));
11174 
11175 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11176 				plaintext_len);
11177 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11178 
11179 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
11180 
11181 	trn_data += plaintext_len;
11182 
11183 	buf = ut_params->ibuf;
11184 
11185 	/*
11186 	 * Loop until no more fragments
11187 	 */
11188 
11189 	while (trn_data < tdata->plaintext.len) {
11190 		++segs;
11191 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
11192 				(tdata->plaintext.len - trn_data) : fragsz;
11193 
11194 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11195 		buf = buf->next;
11196 
11197 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
11198 				rte_pktmbuf_tailroom(buf));
11199 
11200 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
11201 				to_trn);
11202 
11203 		memcpy(plaintext, tdata->plaintext.data + trn_data,
11204 				to_trn);
11205 		trn_data += to_trn;
11206 		if (trn_data  == tdata->plaintext.len)
11207 			digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
11208 					tdata->gmac_tag.len);
11209 	}
11210 	ut_params->ibuf->nb_segs = segs;
11211 
11212 	/*
11213 	 * Place digest at the end of the last buffer
11214 	 */
11215 	uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
11216 
11217 	if (!digest_mem) {
11218 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11219 				+ tdata->gmac_tag.len);
11220 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
11221 				tdata->plaintext.len);
11222 	}
11223 
11224 	retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
11225 			tdata, digest_mem, digest_phys);
11226 
11227 	if (retval < 0)
11228 		return retval;
11229 
11230 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11231 
11232 	ut_params->op->sym->m_src = ut_params->ibuf;
11233 
11234 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11235 		return -ENOTSUP;
11236 
11237 	TEST_ASSERT_NOT_NULL(
11238 		process_crypto_request(ts_params->valid_devs[0],
11239 		ut_params->op), "failed to process sym crypto op");
11240 
11241 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11242 			"crypto op processing failed");
11243 
11244 	auth_tag = digest_mem;
11245 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
11246 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11247 			auth_tag,
11248 			tdata->gmac_tag.data,
11249 			tdata->gmac_tag.len,
11250 			"GMAC Generated auth tag not as expected");
11251 
11252 	return 0;
11253 }
11254 
11255 /* Segment size not multiple of block size (16B) */
11256 static int
11257 test_AES_GMAC_authentication_SGL_40B(void)
11258 {
11259 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
11260 }
11261 
11262 static int
11263 test_AES_GMAC_authentication_SGL_80B(void)
11264 {
11265 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
11266 }
11267 
11268 static int
11269 test_AES_GMAC_authentication_SGL_2048B(void)
11270 {
11271 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
11272 }
11273 
11274 /* Segment size not multiple of block size (16B) */
11275 static int
11276 test_AES_GMAC_authentication_SGL_2047B(void)
11277 {
11278 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
11279 }
11280 
11281 struct test_crypto_vector {
11282 	enum rte_crypto_cipher_algorithm crypto_algo;
11283 	unsigned int cipher_offset;
11284 	unsigned int cipher_len;
11285 
11286 	struct {
11287 		uint8_t data[64];
11288 		unsigned int len;
11289 	} cipher_key;
11290 
11291 	struct {
11292 		uint8_t data[64];
11293 		unsigned int len;
11294 	} iv;
11295 
11296 	struct {
11297 		const uint8_t *data;
11298 		unsigned int len;
11299 	} plaintext;
11300 
11301 	struct {
11302 		const uint8_t *data;
11303 		unsigned int len;
11304 	} ciphertext;
11305 
11306 	enum rte_crypto_auth_algorithm auth_algo;
11307 	unsigned int auth_offset;
11308 
11309 	struct {
11310 		uint8_t data[128];
11311 		unsigned int len;
11312 	} auth_key;
11313 
11314 	struct {
11315 		const uint8_t *data;
11316 		unsigned int len;
11317 	} aad;
11318 
11319 	struct {
11320 		uint8_t data[128];
11321 		unsigned int len;
11322 	} digest;
11323 };
11324 
11325 static const struct test_crypto_vector
11326 hmac_sha1_test_crypto_vector = {
11327 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
11328 	.plaintext = {
11329 		.data = plaintext_hash,
11330 		.len = 512
11331 	},
11332 	.auth_key = {
11333 		.data = {
11334 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
11335 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
11336 			0xDE, 0xF4, 0xDE, 0xAD
11337 		},
11338 		.len = 20
11339 	},
11340 	.digest = {
11341 		.data = {
11342 			0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
11343 			0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
11344 			0x3F, 0x91, 0x64, 0x59
11345 		},
11346 		.len = 20
11347 	}
11348 };
11349 
11350 static const struct test_crypto_vector
11351 aes128_gmac_test_vector = {
11352 	.auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
11353 	.plaintext = {
11354 		.data = plaintext_hash,
11355 		.len = 512
11356 	},
11357 	.iv = {
11358 		.data = {
11359 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
11360 			0x08, 0x09, 0x0A, 0x0B
11361 		},
11362 		.len = 12
11363 	},
11364 	.auth_key = {
11365 		.data = {
11366 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
11367 			0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
11368 		},
11369 		.len = 16
11370 	},
11371 	.digest = {
11372 		.data = {
11373 			0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
11374 			0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
11375 		},
11376 		.len = 16
11377 	}
11378 };
11379 
11380 static const struct test_crypto_vector
11381 aes128cbc_hmac_sha1_test_vector = {
11382 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
11383 	.cipher_offset = 0,
11384 	.cipher_len = 512,
11385 	.cipher_key = {
11386 		.data = {
11387 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
11388 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
11389 		},
11390 		.len = 16
11391 	},
11392 	.iv = {
11393 		.data = {
11394 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
11395 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
11396 		},
11397 		.len = 16
11398 	},
11399 	.plaintext = {
11400 		.data = plaintext_hash,
11401 		.len = 512
11402 	},
11403 	.ciphertext = {
11404 		.data = ciphertext512_aes128cbc,
11405 		.len = 512
11406 	},
11407 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
11408 	.auth_offset = 0,
11409 	.auth_key = {
11410 		.data = {
11411 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
11412 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
11413 			0xDE, 0xF4, 0xDE, 0xAD
11414 		},
11415 		.len = 20
11416 	},
11417 	.digest = {
11418 		.data = {
11419 			0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
11420 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
11421 			0x18, 0x8C, 0x1D, 0x32
11422 		},
11423 		.len = 20
11424 	}
11425 };
11426 
11427 static const struct test_crypto_vector
11428 aes128cbc_hmac_sha1_aad_test_vector = {
11429 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
11430 	.cipher_offset = 8,
11431 	.cipher_len = 496,
11432 	.cipher_key = {
11433 		.data = {
11434 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
11435 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
11436 		},
11437 		.len = 16
11438 	},
11439 	.iv = {
11440 		.data = {
11441 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
11442 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
11443 		},
11444 		.len = 16
11445 	},
11446 	.plaintext = {
11447 		.data = plaintext_hash,
11448 		.len = 512
11449 	},
11450 	.ciphertext = {
11451 		.data = ciphertext512_aes128cbc_aad,
11452 		.len = 512
11453 	},
11454 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
11455 	.auth_offset = 0,
11456 	.auth_key = {
11457 		.data = {
11458 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
11459 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
11460 			0xDE, 0xF4, 0xDE, 0xAD
11461 		},
11462 		.len = 20
11463 	},
11464 	.digest = {
11465 		.data = {
11466 			0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
11467 			0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
11468 			0x62, 0x0F, 0xFB, 0x10
11469 		},
11470 		.len = 20
11471 	}
11472 };
11473 
11474 static void
11475 data_corruption(uint8_t *data)
11476 {
11477 	data[0] += 1;
11478 }
11479 
11480 static void
11481 tag_corruption(uint8_t *data, unsigned int tag_offset)
11482 {
11483 	data[tag_offset] += 1;
11484 }
11485 
11486 static int
11487 create_auth_session(struct crypto_unittest_params *ut_params,
11488 		uint8_t dev_id,
11489 		const struct test_crypto_vector *reference,
11490 		enum rte_crypto_auth_operation auth_op)
11491 {
11492 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11493 	uint8_t auth_key[reference->auth_key.len + 1];
11494 
11495 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
11496 
11497 	/* Setup Authentication Parameters */
11498 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11499 	ut_params->auth_xform.auth.op = auth_op;
11500 	ut_params->auth_xform.next = NULL;
11501 	ut_params->auth_xform.auth.algo = reference->auth_algo;
11502 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
11503 	ut_params->auth_xform.auth.key.data = auth_key;
11504 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
11505 
11506 	/* Create Crypto session*/
11507 	ut_params->sess = rte_cryptodev_sym_session_create(
11508 			ts_params->session_mpool);
11509 
11510 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
11511 				&ut_params->auth_xform,
11512 				ts_params->session_priv_mpool);
11513 
11514 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11515 
11516 	return 0;
11517 }
11518 
11519 static int
11520 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
11521 		uint8_t dev_id,
11522 		const struct test_crypto_vector *reference,
11523 		enum rte_crypto_auth_operation auth_op,
11524 		enum rte_crypto_cipher_operation cipher_op)
11525 {
11526 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11527 	uint8_t cipher_key[reference->cipher_key.len + 1];
11528 	uint8_t auth_key[reference->auth_key.len + 1];
11529 
11530 	memcpy(cipher_key, reference->cipher_key.data,
11531 			reference->cipher_key.len);
11532 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
11533 
11534 	/* Setup Authentication Parameters */
11535 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11536 	ut_params->auth_xform.auth.op = auth_op;
11537 	ut_params->auth_xform.auth.algo = reference->auth_algo;
11538 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
11539 	ut_params->auth_xform.auth.key.data = auth_key;
11540 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
11541 
11542 	if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
11543 		ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
11544 		ut_params->auth_xform.auth.iv.length = reference->iv.len;
11545 	} else {
11546 		ut_params->auth_xform.next = &ut_params->cipher_xform;
11547 
11548 		/* Setup Cipher Parameters */
11549 		ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11550 		ut_params->cipher_xform.next = NULL;
11551 		ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
11552 		ut_params->cipher_xform.cipher.op = cipher_op;
11553 		ut_params->cipher_xform.cipher.key.data = cipher_key;
11554 		ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
11555 		ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
11556 		ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
11557 	}
11558 
11559 	/* Create Crypto session*/
11560 	ut_params->sess = rte_cryptodev_sym_session_create(
11561 			ts_params->session_mpool);
11562 
11563 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
11564 				&ut_params->auth_xform,
11565 				ts_params->session_priv_mpool);
11566 
11567 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11568 
11569 	return 0;
11570 }
11571 
11572 static int
11573 create_auth_operation(struct crypto_testsuite_params *ts_params,
11574 		struct crypto_unittest_params *ut_params,
11575 		const struct test_crypto_vector *reference,
11576 		unsigned int auth_generate)
11577 {
11578 	/* Generate Crypto op data structure */
11579 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11580 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11581 	TEST_ASSERT_NOT_NULL(ut_params->op,
11582 			"Failed to allocate pktmbuf offload");
11583 
11584 	/* Set crypto operation data parameters */
11585 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11586 
11587 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11588 
11589 	/* set crypto operation source mbuf */
11590 	sym_op->m_src = ut_params->ibuf;
11591 
11592 	/* digest */
11593 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11594 			ut_params->ibuf, reference->digest.len);
11595 
11596 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11597 			"no room to append auth tag");
11598 
11599 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11600 			ut_params->ibuf, reference->plaintext.len);
11601 
11602 	if (auth_generate)
11603 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
11604 	else
11605 		memcpy(sym_op->auth.digest.data,
11606 				reference->digest.data,
11607 				reference->digest.len);
11608 
11609 	debug_hexdump(stdout, "digest:",
11610 			sym_op->auth.digest.data,
11611 			reference->digest.len);
11612 
11613 	sym_op->auth.data.length = reference->plaintext.len;
11614 	sym_op->auth.data.offset = 0;
11615 
11616 	return 0;
11617 }
11618 
11619 static int
11620 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
11621 		struct crypto_unittest_params *ut_params,
11622 		const struct test_crypto_vector *reference,
11623 		unsigned int auth_generate)
11624 {
11625 	/* Generate Crypto op data structure */
11626 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11627 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11628 	TEST_ASSERT_NOT_NULL(ut_params->op,
11629 			"Failed to allocate pktmbuf offload");
11630 
11631 	/* Set crypto operation data parameters */
11632 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11633 
11634 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11635 
11636 	/* set crypto operation source mbuf */
11637 	sym_op->m_src = ut_params->ibuf;
11638 
11639 	/* digest */
11640 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11641 			ut_params->ibuf, reference->digest.len);
11642 
11643 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11644 			"no room to append auth tag");
11645 
11646 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11647 			ut_params->ibuf, reference->ciphertext.len);
11648 
11649 	if (auth_generate)
11650 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
11651 	else
11652 		memcpy(sym_op->auth.digest.data,
11653 				reference->digest.data,
11654 				reference->digest.len);
11655 
11656 	debug_hexdump(stdout, "digest:",
11657 			sym_op->auth.digest.data,
11658 			reference->digest.len);
11659 
11660 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
11661 			reference->iv.data, reference->iv.len);
11662 
11663 	sym_op->cipher.data.length = 0;
11664 	sym_op->cipher.data.offset = 0;
11665 
11666 	sym_op->auth.data.length = reference->plaintext.len;
11667 	sym_op->auth.data.offset = 0;
11668 
11669 	return 0;
11670 }
11671 
11672 static int
11673 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
11674 		struct crypto_unittest_params *ut_params,
11675 		const struct test_crypto_vector *reference,
11676 		unsigned int auth_generate)
11677 {
11678 	/* Generate Crypto op data structure */
11679 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11680 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11681 	TEST_ASSERT_NOT_NULL(ut_params->op,
11682 			"Failed to allocate pktmbuf offload");
11683 
11684 	/* Set crypto operation data parameters */
11685 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11686 
11687 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11688 
11689 	/* set crypto operation source mbuf */
11690 	sym_op->m_src = ut_params->ibuf;
11691 
11692 	/* digest */
11693 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11694 			ut_params->ibuf, reference->digest.len);
11695 
11696 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11697 			"no room to append auth tag");
11698 
11699 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11700 			ut_params->ibuf, reference->ciphertext.len);
11701 
11702 	if (auth_generate)
11703 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
11704 	else
11705 		memcpy(sym_op->auth.digest.data,
11706 				reference->digest.data,
11707 				reference->digest.len);
11708 
11709 	debug_hexdump(stdout, "digest:",
11710 			sym_op->auth.digest.data,
11711 			reference->digest.len);
11712 
11713 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
11714 			reference->iv.data, reference->iv.len);
11715 
11716 	sym_op->cipher.data.length = reference->cipher_len;
11717 	sym_op->cipher.data.offset = reference->cipher_offset;
11718 
11719 	sym_op->auth.data.length = reference->plaintext.len;
11720 	sym_op->auth.data.offset = reference->auth_offset;
11721 
11722 	return 0;
11723 }
11724 
11725 static int
11726 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
11727 		struct crypto_unittest_params *ut_params,
11728 		const struct test_crypto_vector *reference)
11729 {
11730 	return create_auth_operation(ts_params, ut_params, reference, 0);
11731 }
11732 
11733 static int
11734 create_auth_verify_GMAC_operation(
11735 		struct crypto_testsuite_params *ts_params,
11736 		struct crypto_unittest_params *ut_params,
11737 		const struct test_crypto_vector *reference)
11738 {
11739 	return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
11740 }
11741 
11742 static int
11743 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
11744 		struct crypto_unittest_params *ut_params,
11745 		const struct test_crypto_vector *reference)
11746 {
11747 	return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
11748 }
11749 
11750 static int
11751 test_authentication_verify_fail_when_data_corruption(
11752 		struct crypto_testsuite_params *ts_params,
11753 		struct crypto_unittest_params *ut_params,
11754 		const struct test_crypto_vector *reference,
11755 		unsigned int data_corrupted)
11756 {
11757 	int retval;
11758 
11759 	uint8_t *plaintext;
11760 	struct rte_cryptodev_info dev_info;
11761 
11762 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11763 	uint64_t feat_flags = dev_info.feature_flags;
11764 
11765 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11766 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11767 		printf("Device doesn't support RAW data-path APIs.\n");
11768 		return -ENOTSUP;
11769 	}
11770 
11771 	/* Verify the capabilities */
11772 	struct rte_cryptodev_sym_capability_idx cap_idx;
11773 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11774 	cap_idx.algo.auth = reference->auth_algo;
11775 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11776 			&cap_idx) == NULL)
11777 		return -ENOTSUP;
11778 
11779 
11780 	/* Create session */
11781 	retval = create_auth_session(ut_params,
11782 			ts_params->valid_devs[0],
11783 			reference,
11784 			RTE_CRYPTO_AUTH_OP_VERIFY);
11785 	if (retval < 0)
11786 		return retval;
11787 
11788 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11789 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11790 			"Failed to allocate input buffer in mempool");
11791 
11792 	/* clear mbuf payload */
11793 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11794 			rte_pktmbuf_tailroom(ut_params->ibuf));
11795 
11796 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11797 			reference->plaintext.len);
11798 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11799 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
11800 
11801 	debug_hexdump(stdout, "plaintext:", plaintext,
11802 		reference->plaintext.len);
11803 
11804 	/* Create operation */
11805 	retval = create_auth_verify_operation(ts_params, ut_params, reference);
11806 
11807 	if (retval < 0)
11808 		return retval;
11809 
11810 	if (data_corrupted)
11811 		data_corruption(plaintext);
11812 	else
11813 		tag_corruption(plaintext, reference->plaintext.len);
11814 
11815 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
11816 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11817 			ut_params->op);
11818 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
11819 			RTE_CRYPTO_OP_STATUS_SUCCESS,
11820 			"authentication not failed");
11821 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11822 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11823 				ut_params->op, 0, 1, 0, 0);
11824 	else {
11825 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
11826 			ut_params->op);
11827 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
11828 	}
11829 
11830 	return 0;
11831 }
11832 
11833 static int
11834 test_authentication_verify_GMAC_fail_when_corruption(
11835 		struct crypto_testsuite_params *ts_params,
11836 		struct crypto_unittest_params *ut_params,
11837 		const struct test_crypto_vector *reference,
11838 		unsigned int data_corrupted)
11839 {
11840 	int retval;
11841 	uint8_t *plaintext;
11842 	struct rte_cryptodev_info dev_info;
11843 
11844 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11845 	uint64_t feat_flags = dev_info.feature_flags;
11846 
11847 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11848 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11849 		printf("Device doesn't support RAW data-path APIs.\n");
11850 		return -ENOTSUP;
11851 	}
11852 
11853 	/* Verify the capabilities */
11854 	struct rte_cryptodev_sym_capability_idx cap_idx;
11855 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11856 	cap_idx.algo.auth = reference->auth_algo;
11857 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11858 			&cap_idx) == NULL)
11859 		return -ENOTSUP;
11860 
11861 	/* Create session */
11862 	retval = create_auth_cipher_session(ut_params,
11863 			ts_params->valid_devs[0],
11864 			reference,
11865 			RTE_CRYPTO_AUTH_OP_VERIFY,
11866 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
11867 	if (retval < 0)
11868 		return retval;
11869 
11870 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11871 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11872 			"Failed to allocate input buffer in mempool");
11873 
11874 	/* clear mbuf payload */
11875 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11876 			rte_pktmbuf_tailroom(ut_params->ibuf));
11877 
11878 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11879 			reference->plaintext.len);
11880 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11881 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
11882 
11883 	debug_hexdump(stdout, "plaintext:", plaintext,
11884 		reference->plaintext.len);
11885 
11886 	/* Create operation */
11887 	retval = create_auth_verify_GMAC_operation(ts_params,
11888 			ut_params,
11889 			reference);
11890 
11891 	if (retval < 0)
11892 		return retval;
11893 
11894 	if (data_corrupted)
11895 		data_corruption(plaintext);
11896 	else
11897 		tag_corruption(plaintext, reference->aad.len);
11898 
11899 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
11900 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11901 			ut_params->op);
11902 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
11903 			RTE_CRYPTO_OP_STATUS_SUCCESS,
11904 			"authentication not failed");
11905 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11906 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11907 				ut_params->op, 0, 1, 0, 0);
11908 	else {
11909 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
11910 			ut_params->op);
11911 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
11912 	}
11913 
11914 	return 0;
11915 }
11916 
11917 static int
11918 test_authenticated_decryption_fail_when_corruption(
11919 		struct crypto_testsuite_params *ts_params,
11920 		struct crypto_unittest_params *ut_params,
11921 		const struct test_crypto_vector *reference,
11922 		unsigned int data_corrupted)
11923 {
11924 	int retval;
11925 
11926 	uint8_t *ciphertext;
11927 	struct rte_cryptodev_info dev_info;
11928 
11929 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11930 	uint64_t feat_flags = dev_info.feature_flags;
11931 
11932 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11933 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11934 		printf("Device doesn't support RAW data-path APIs.\n");
11935 		return -ENOTSUP;
11936 	}
11937 
11938 	/* Verify the capabilities */
11939 	struct rte_cryptodev_sym_capability_idx cap_idx;
11940 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11941 	cap_idx.algo.auth = reference->auth_algo;
11942 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11943 			&cap_idx) == NULL)
11944 		return -ENOTSUP;
11945 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11946 	cap_idx.algo.cipher = reference->crypto_algo;
11947 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11948 			&cap_idx) == NULL)
11949 		return -ENOTSUP;
11950 
11951 	/* Create session */
11952 	retval = create_auth_cipher_session(ut_params,
11953 			ts_params->valid_devs[0],
11954 			reference,
11955 			RTE_CRYPTO_AUTH_OP_VERIFY,
11956 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
11957 	if (retval < 0)
11958 		return retval;
11959 
11960 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11961 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11962 			"Failed to allocate input buffer in mempool");
11963 
11964 	/* clear mbuf payload */
11965 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11966 			rte_pktmbuf_tailroom(ut_params->ibuf));
11967 
11968 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11969 			reference->ciphertext.len);
11970 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
11971 	memcpy(ciphertext, reference->ciphertext.data,
11972 			reference->ciphertext.len);
11973 
11974 	/* Create operation */
11975 	retval = create_cipher_auth_verify_operation(ts_params,
11976 			ut_params,
11977 			reference);
11978 
11979 	if (retval < 0)
11980 		return retval;
11981 
11982 	if (data_corrupted)
11983 		data_corruption(ciphertext);
11984 	else
11985 		tag_corruption(ciphertext, reference->ciphertext.len);
11986 
11987 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
11988 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11989 			ut_params->op);
11990 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
11991 			RTE_CRYPTO_OP_STATUS_SUCCESS,
11992 			"authentication not failed");
11993 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11994 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11995 				ut_params->op, 1, 1, 0, 0);
11996 	else {
11997 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
11998 			ut_params->op);
11999 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12000 	}
12001 
12002 	return 0;
12003 }
12004 
12005 static int
12006 test_authenticated_encryt_with_esn(
12007 		struct crypto_testsuite_params *ts_params,
12008 		struct crypto_unittest_params *ut_params,
12009 		const struct test_crypto_vector *reference)
12010 {
12011 	int retval;
12012 
12013 	uint8_t *authciphertext, *plaintext, *auth_tag;
12014 	uint16_t plaintext_pad_len;
12015 	uint8_t cipher_key[reference->cipher_key.len + 1];
12016 	uint8_t auth_key[reference->auth_key.len + 1];
12017 	struct rte_cryptodev_info dev_info;
12018 
12019 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12020 	uint64_t feat_flags = dev_info.feature_flags;
12021 
12022 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12023 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12024 		printf("Device doesn't support RAW data-path APIs.\n");
12025 		return -ENOTSUP;
12026 	}
12027 
12028 	/* Verify the capabilities */
12029 	struct rte_cryptodev_sym_capability_idx cap_idx;
12030 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12031 	cap_idx.algo.auth = reference->auth_algo;
12032 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12033 			&cap_idx) == NULL)
12034 		return -ENOTSUP;
12035 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12036 	cap_idx.algo.cipher = reference->crypto_algo;
12037 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12038 			&cap_idx) == NULL)
12039 		return -ENOTSUP;
12040 
12041 	/* Create session */
12042 	memcpy(cipher_key, reference->cipher_key.data,
12043 			reference->cipher_key.len);
12044 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12045 
12046 	/* Setup Cipher Parameters */
12047 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12048 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12049 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
12050 	ut_params->cipher_xform.cipher.key.data = cipher_key;
12051 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12052 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12053 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12054 
12055 	ut_params->cipher_xform.next = &ut_params->auth_xform;
12056 
12057 	/* Setup Authentication Parameters */
12058 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12059 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
12060 	ut_params->auth_xform.auth.algo = reference->auth_algo;
12061 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12062 	ut_params->auth_xform.auth.key.data = auth_key;
12063 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
12064 	ut_params->auth_xform.next = NULL;
12065 
12066 	/* Create Crypto session*/
12067 	ut_params->sess = rte_cryptodev_sym_session_create(
12068 			ts_params->session_mpool);
12069 
12070 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12071 				ut_params->sess,
12072 				&ut_params->cipher_xform,
12073 				ts_params->session_priv_mpool);
12074 
12075 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12076 
12077 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12078 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12079 			"Failed to allocate input buffer in mempool");
12080 
12081 	/* clear mbuf payload */
12082 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12083 			rte_pktmbuf_tailroom(ut_params->ibuf));
12084 
12085 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12086 			reference->plaintext.len);
12087 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12088 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12089 
12090 	/* Create operation */
12091 	retval = create_cipher_auth_operation(ts_params,
12092 			ut_params,
12093 			reference, 0);
12094 
12095 	if (retval < 0)
12096 		return retval;
12097 
12098 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12099 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12100 			ut_params->op);
12101 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12102 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12103 				ut_params->op, 1, 1, 0, 0);
12104 	else
12105 		ut_params->op = process_crypto_request(
12106 			ts_params->valid_devs[0], ut_params->op);
12107 
12108 	TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
12109 
12110 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12111 			"crypto op processing failed");
12112 
12113 	plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
12114 
12115 	authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
12116 			ut_params->op->sym->auth.data.offset);
12117 	auth_tag = authciphertext + plaintext_pad_len;
12118 	debug_hexdump(stdout, "ciphertext:", authciphertext,
12119 			reference->ciphertext.len);
12120 	debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
12121 
12122 	/* Validate obuf */
12123 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12124 			authciphertext,
12125 			reference->ciphertext.data,
12126 			reference->ciphertext.len,
12127 			"Ciphertext data not as expected");
12128 
12129 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12130 			auth_tag,
12131 			reference->digest.data,
12132 			reference->digest.len,
12133 			"Generated digest not as expected");
12134 
12135 	return TEST_SUCCESS;
12136 
12137 }
12138 
12139 static int
12140 test_authenticated_decrypt_with_esn(
12141 		struct crypto_testsuite_params *ts_params,
12142 		struct crypto_unittest_params *ut_params,
12143 		const struct test_crypto_vector *reference)
12144 {
12145 	int retval;
12146 
12147 	uint8_t *ciphertext;
12148 	uint8_t cipher_key[reference->cipher_key.len + 1];
12149 	uint8_t auth_key[reference->auth_key.len + 1];
12150 	struct rte_cryptodev_info dev_info;
12151 
12152 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12153 	uint64_t feat_flags = dev_info.feature_flags;
12154 
12155 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12156 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12157 		printf("Device doesn't support RAW data-path APIs.\n");
12158 		return -ENOTSUP;
12159 	}
12160 
12161 	/* Verify the capabilities */
12162 	struct rte_cryptodev_sym_capability_idx cap_idx;
12163 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12164 	cap_idx.algo.auth = reference->auth_algo;
12165 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12166 			&cap_idx) == NULL)
12167 		return -ENOTSUP;
12168 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12169 	cap_idx.algo.cipher = reference->crypto_algo;
12170 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12171 			&cap_idx) == NULL)
12172 		return -ENOTSUP;
12173 
12174 	/* Create session */
12175 	memcpy(cipher_key, reference->cipher_key.data,
12176 			reference->cipher_key.len);
12177 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12178 
12179 	/* Setup Authentication Parameters */
12180 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12181 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
12182 	ut_params->auth_xform.auth.algo = reference->auth_algo;
12183 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12184 	ut_params->auth_xform.auth.key.data = auth_key;
12185 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
12186 	ut_params->auth_xform.next = &ut_params->cipher_xform;
12187 
12188 	/* Setup Cipher Parameters */
12189 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12190 	ut_params->cipher_xform.next = NULL;
12191 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12192 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
12193 	ut_params->cipher_xform.cipher.key.data = cipher_key;
12194 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12195 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12196 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12197 
12198 	/* Create Crypto session*/
12199 	ut_params->sess = rte_cryptodev_sym_session_create(
12200 			ts_params->session_mpool);
12201 
12202 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12203 				ut_params->sess,
12204 				&ut_params->auth_xform,
12205 				ts_params->session_priv_mpool);
12206 
12207 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12208 
12209 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12210 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12211 			"Failed to allocate input buffer in mempool");
12212 
12213 	/* clear mbuf payload */
12214 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12215 			rte_pktmbuf_tailroom(ut_params->ibuf));
12216 
12217 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12218 			reference->ciphertext.len);
12219 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
12220 	memcpy(ciphertext, reference->ciphertext.data,
12221 			reference->ciphertext.len);
12222 
12223 	/* Create operation */
12224 	retval = create_cipher_auth_verify_operation(ts_params,
12225 			ut_params,
12226 			reference);
12227 
12228 	if (retval < 0)
12229 		return retval;
12230 
12231 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12232 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12233 			ut_params->op);
12234 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12235 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12236 				ut_params->op, 1, 1, 0, 0);
12237 	else
12238 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12239 			ut_params->op);
12240 
12241 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
12242 	TEST_ASSERT_EQUAL(ut_params->op->status,
12243 			RTE_CRYPTO_OP_STATUS_SUCCESS,
12244 			"crypto op processing passed");
12245 
12246 	ut_params->obuf = ut_params->op->sym->m_src;
12247 	TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
12248 
12249 	return 0;
12250 }
12251 
12252 static int
12253 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
12254 		const struct aead_test_data *tdata,
12255 		void *digest_mem, uint64_t digest_phys)
12256 {
12257 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12258 	struct crypto_unittest_params *ut_params = &unittest_params;
12259 
12260 	const unsigned int auth_tag_len = tdata->auth_tag.len;
12261 	const unsigned int iv_len = tdata->iv.len;
12262 	unsigned int aad_len = tdata->aad.len;
12263 	unsigned int aad_len_pad = 0;
12264 
12265 	/* Generate Crypto op data structure */
12266 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12267 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12268 	TEST_ASSERT_NOT_NULL(ut_params->op,
12269 		"Failed to allocate symmetric crypto operation struct");
12270 
12271 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12272 
12273 	sym_op->aead.digest.data = digest_mem;
12274 
12275 	TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
12276 			"no room to append digest");
12277 
12278 	sym_op->aead.digest.phys_addr = digest_phys;
12279 
12280 	if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
12281 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
12282 				auth_tag_len);
12283 		debug_hexdump(stdout, "digest:",
12284 				sym_op->aead.digest.data,
12285 				auth_tag_len);
12286 	}
12287 
12288 	/* Append aad data */
12289 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
12290 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12291 				uint8_t *, IV_OFFSET);
12292 
12293 		/* Copy IV 1 byte after the IV pointer, according to the API */
12294 		rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
12295 
12296 		aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
12297 
12298 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
12299 				ut_params->ibuf, aad_len);
12300 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
12301 				"no room to prepend aad");
12302 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
12303 				ut_params->ibuf);
12304 
12305 		memset(sym_op->aead.aad.data, 0, aad_len);
12306 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
12307 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
12308 
12309 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
12310 		debug_hexdump(stdout, "aad:",
12311 				sym_op->aead.aad.data, aad_len);
12312 	} else {
12313 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12314 				uint8_t *, IV_OFFSET);
12315 
12316 		rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
12317 
12318 		aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
12319 
12320 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
12321 				ut_params->ibuf, aad_len_pad);
12322 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
12323 				"no room to prepend aad");
12324 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
12325 				ut_params->ibuf);
12326 
12327 		memset(sym_op->aead.aad.data, 0, aad_len);
12328 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
12329 
12330 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
12331 		debug_hexdump(stdout, "aad:",
12332 				sym_op->aead.aad.data, aad_len);
12333 	}
12334 
12335 	sym_op->aead.data.length = tdata->plaintext.len;
12336 	sym_op->aead.data.offset = aad_len_pad;
12337 
12338 	return 0;
12339 }
12340 
12341 #define SGL_MAX_NO	16
12342 
12343 static int
12344 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
12345 		const int oop, uint32_t fragsz, uint32_t fragsz_oop)
12346 {
12347 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12348 	struct crypto_unittest_params *ut_params = &unittest_params;
12349 	struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
12350 	int retval;
12351 	int to_trn = 0;
12352 	int to_trn_tbl[SGL_MAX_NO];
12353 	int segs = 1;
12354 	unsigned int trn_data = 0;
12355 	uint8_t *plaintext, *ciphertext, *auth_tag;
12356 	struct rte_cryptodev_info dev_info;
12357 
12358 	/* Verify the capabilities */
12359 	struct rte_cryptodev_sym_capability_idx cap_idx;
12360 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
12361 	cap_idx.algo.aead = tdata->algo;
12362 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12363 			&cap_idx) == NULL)
12364 		return -ENOTSUP;
12365 
12366 	/* OOP not supported with CPU crypto */
12367 	if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12368 		return -ENOTSUP;
12369 
12370 	/* Detailed check for the particular SGL support flag */
12371 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12372 	if (!oop) {
12373 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
12374 		if (sgl_in && (!(dev_info.feature_flags &
12375 				RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
12376 			return -ENOTSUP;
12377 
12378 		uint64_t feat_flags = dev_info.feature_flags;
12379 
12380 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12381 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12382 			printf("Device doesn't support RAW data-path APIs.\n");
12383 			return -ENOTSUP;
12384 		}
12385 	} else {
12386 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
12387 		unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
12388 				tdata->plaintext.len;
12389 		/* Raw data path API does not support OOP */
12390 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12391 			return -ENOTSUP;
12392 		if (sgl_in && !sgl_out) {
12393 			if (!(dev_info.feature_flags &
12394 					RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
12395 				return -ENOTSUP;
12396 		} else if (!sgl_in && sgl_out) {
12397 			if (!(dev_info.feature_flags &
12398 					RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
12399 				return -ENOTSUP;
12400 		} else if (sgl_in && sgl_out) {
12401 			if (!(dev_info.feature_flags &
12402 					RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
12403 				return -ENOTSUP;
12404 		}
12405 	}
12406 
12407 	if (fragsz > tdata->plaintext.len)
12408 		fragsz = tdata->plaintext.len;
12409 
12410 	uint16_t plaintext_len = fragsz;
12411 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
12412 
12413 	if (fragsz_oop > tdata->plaintext.len)
12414 		frag_size_oop = tdata->plaintext.len;
12415 
12416 	int ecx = 0;
12417 	void *digest_mem = NULL;
12418 
12419 	uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
12420 
12421 	if (tdata->plaintext.len % fragsz != 0) {
12422 		if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
12423 			return 1;
12424 	}	else {
12425 		if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
12426 			return 1;
12427 	}
12428 
12429 	/*
12430 	 * For out-op-place we need to alloc another mbuf
12431 	 */
12432 	if (oop) {
12433 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12434 		rte_pktmbuf_append(ut_params->obuf,
12435 				frag_size_oop + prepend_len);
12436 		buf_oop = ut_params->obuf;
12437 	}
12438 
12439 	/* Create AEAD session */
12440 	retval = create_aead_session(ts_params->valid_devs[0],
12441 			tdata->algo,
12442 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
12443 			tdata->key.data, tdata->key.len,
12444 			tdata->aad.len, tdata->auth_tag.len,
12445 			tdata->iv.len);
12446 	if (retval < 0)
12447 		return retval;
12448 
12449 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12450 
12451 	/* clear mbuf payload */
12452 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12453 			rte_pktmbuf_tailroom(ut_params->ibuf));
12454 
12455 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12456 			plaintext_len);
12457 
12458 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
12459 
12460 	trn_data += plaintext_len;
12461 
12462 	buf = ut_params->ibuf;
12463 
12464 	/*
12465 	 * Loop until no more fragments
12466 	 */
12467 
12468 	while (trn_data < tdata->plaintext.len) {
12469 		++segs;
12470 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
12471 				(tdata->plaintext.len - trn_data) : fragsz;
12472 
12473 		to_trn_tbl[ecx++] = to_trn;
12474 
12475 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12476 		buf = buf->next;
12477 
12478 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
12479 				rte_pktmbuf_tailroom(buf));
12480 
12481 		/* OOP */
12482 		if (oop && !fragsz_oop) {
12483 			buf_last_oop = buf_oop->next =
12484 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
12485 			buf_oop = buf_oop->next;
12486 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
12487 					0, rte_pktmbuf_tailroom(buf_oop));
12488 			rte_pktmbuf_append(buf_oop, to_trn);
12489 		}
12490 
12491 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
12492 				to_trn);
12493 
12494 		memcpy(plaintext, tdata->plaintext.data + trn_data,
12495 				to_trn);
12496 		trn_data += to_trn;
12497 		if (trn_data  == tdata->plaintext.len) {
12498 			if (oop) {
12499 				if (!fragsz_oop)
12500 					digest_mem = rte_pktmbuf_append(buf_oop,
12501 						tdata->auth_tag.len);
12502 			} else
12503 				digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
12504 					tdata->auth_tag.len);
12505 		}
12506 	}
12507 
12508 	uint64_t digest_phys = 0;
12509 
12510 	ut_params->ibuf->nb_segs = segs;
12511 
12512 	segs = 1;
12513 	if (fragsz_oop && oop) {
12514 		to_trn = 0;
12515 		ecx = 0;
12516 
12517 		if (frag_size_oop == tdata->plaintext.len) {
12518 			digest_mem = rte_pktmbuf_append(ut_params->obuf,
12519 				tdata->auth_tag.len);
12520 
12521 			digest_phys = rte_pktmbuf_iova_offset(
12522 					ut_params->obuf,
12523 					tdata->plaintext.len + prepend_len);
12524 		}
12525 
12526 		trn_data = frag_size_oop;
12527 		while (trn_data < tdata->plaintext.len) {
12528 			++segs;
12529 			to_trn =
12530 				(tdata->plaintext.len - trn_data <
12531 						frag_size_oop) ?
12532 				(tdata->plaintext.len - trn_data) :
12533 						frag_size_oop;
12534 
12535 			to_trn_tbl[ecx++] = to_trn;
12536 
12537 			buf_last_oop = buf_oop->next =
12538 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
12539 			buf_oop = buf_oop->next;
12540 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
12541 					0, rte_pktmbuf_tailroom(buf_oop));
12542 			rte_pktmbuf_append(buf_oop, to_trn);
12543 
12544 			trn_data += to_trn;
12545 
12546 			if (trn_data  == tdata->plaintext.len) {
12547 				digest_mem = rte_pktmbuf_append(buf_oop,
12548 					tdata->auth_tag.len);
12549 			}
12550 		}
12551 
12552 		ut_params->obuf->nb_segs = segs;
12553 	}
12554 
12555 	/*
12556 	 * Place digest at the end of the last buffer
12557 	 */
12558 	if (!digest_phys)
12559 		digest_phys = rte_pktmbuf_iova(buf) + to_trn;
12560 	if (oop && buf_last_oop)
12561 		digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
12562 
12563 	if (!digest_mem && !oop) {
12564 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12565 				+ tdata->auth_tag.len);
12566 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
12567 				tdata->plaintext.len);
12568 	}
12569 
12570 	/* Create AEAD operation */
12571 	retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
12572 			tdata, digest_mem, digest_phys);
12573 
12574 	if (retval < 0)
12575 		return retval;
12576 
12577 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12578 
12579 	ut_params->op->sym->m_src = ut_params->ibuf;
12580 	if (oop)
12581 		ut_params->op->sym->m_dst = ut_params->obuf;
12582 
12583 	/* Process crypto operation */
12584 	if (oop == IN_PLACE &&
12585 			gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12586 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
12587 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12588 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12589 				ut_params->op, 0, 0, 0, 0);
12590 	else
12591 		TEST_ASSERT_NOT_NULL(
12592 			process_crypto_request(ts_params->valid_devs[0],
12593 			ut_params->op), "failed to process sym crypto op");
12594 
12595 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12596 			"crypto op processing failed");
12597 
12598 
12599 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
12600 			uint8_t *, prepend_len);
12601 	if (oop) {
12602 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
12603 				uint8_t *, prepend_len);
12604 	}
12605 
12606 	if (fragsz_oop)
12607 		fragsz = fragsz_oop;
12608 
12609 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12610 			ciphertext,
12611 			tdata->ciphertext.data,
12612 			fragsz,
12613 			"Ciphertext data not as expected");
12614 
12615 	buf = ut_params->op->sym->m_src->next;
12616 	if (oop)
12617 		buf = ut_params->op->sym->m_dst->next;
12618 
12619 	unsigned int off = fragsz;
12620 
12621 	ecx = 0;
12622 	while (buf) {
12623 		ciphertext = rte_pktmbuf_mtod(buf,
12624 				uint8_t *);
12625 
12626 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
12627 				ciphertext,
12628 				tdata->ciphertext.data + off,
12629 				to_trn_tbl[ecx],
12630 				"Ciphertext data not as expected");
12631 
12632 		off += to_trn_tbl[ecx++];
12633 		buf = buf->next;
12634 	}
12635 
12636 	auth_tag = digest_mem;
12637 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12638 			auth_tag,
12639 			tdata->auth_tag.data,
12640 			tdata->auth_tag.len,
12641 			"Generated auth tag not as expected");
12642 
12643 	return 0;
12644 }
12645 
12646 static int
12647 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
12648 {
12649 	return test_authenticated_encryption_SGL(
12650 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
12651 }
12652 
12653 static int
12654 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
12655 {
12656 	return test_authenticated_encryption_SGL(
12657 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
12658 }
12659 
12660 static int
12661 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
12662 {
12663 	return test_authenticated_encryption_SGL(
12664 			&gcm_test_case_8, OUT_OF_PLACE, 400,
12665 			gcm_test_case_8.plaintext.len);
12666 }
12667 
12668 static int
12669 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
12670 {
12671 	/* This test is not for OPENSSL PMD */
12672 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
12673 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
12674 		return -ENOTSUP;
12675 
12676 	return test_authenticated_encryption_SGL(
12677 			&gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
12678 }
12679 
12680 static int
12681 test_authentication_verify_fail_when_data_corrupted(
12682 		struct crypto_testsuite_params *ts_params,
12683 		struct crypto_unittest_params *ut_params,
12684 		const struct test_crypto_vector *reference)
12685 {
12686 	return test_authentication_verify_fail_when_data_corruption(
12687 			ts_params, ut_params, reference, 1);
12688 }
12689 
12690 static int
12691 test_authentication_verify_fail_when_tag_corrupted(
12692 		struct crypto_testsuite_params *ts_params,
12693 		struct crypto_unittest_params *ut_params,
12694 		const struct test_crypto_vector *reference)
12695 {
12696 	return test_authentication_verify_fail_when_data_corruption(
12697 			ts_params, ut_params, reference, 0);
12698 }
12699 
12700 static int
12701 test_authentication_verify_GMAC_fail_when_data_corrupted(
12702 		struct crypto_testsuite_params *ts_params,
12703 		struct crypto_unittest_params *ut_params,
12704 		const struct test_crypto_vector *reference)
12705 {
12706 	return test_authentication_verify_GMAC_fail_when_corruption(
12707 			ts_params, ut_params, reference, 1);
12708 }
12709 
12710 static int
12711 test_authentication_verify_GMAC_fail_when_tag_corrupted(
12712 		struct crypto_testsuite_params *ts_params,
12713 		struct crypto_unittest_params *ut_params,
12714 		const struct test_crypto_vector *reference)
12715 {
12716 	return test_authentication_verify_GMAC_fail_when_corruption(
12717 			ts_params, ut_params, reference, 0);
12718 }
12719 
12720 static int
12721 test_authenticated_decryption_fail_when_data_corrupted(
12722 		struct crypto_testsuite_params *ts_params,
12723 		struct crypto_unittest_params *ut_params,
12724 		const struct test_crypto_vector *reference)
12725 {
12726 	return test_authenticated_decryption_fail_when_corruption(
12727 			ts_params, ut_params, reference, 1);
12728 }
12729 
12730 static int
12731 test_authenticated_decryption_fail_when_tag_corrupted(
12732 		struct crypto_testsuite_params *ts_params,
12733 		struct crypto_unittest_params *ut_params,
12734 		const struct test_crypto_vector *reference)
12735 {
12736 	return test_authenticated_decryption_fail_when_corruption(
12737 			ts_params, ut_params, reference, 0);
12738 }
12739 
12740 static int
12741 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
12742 {
12743 	return test_authentication_verify_fail_when_data_corrupted(
12744 			&testsuite_params, &unittest_params,
12745 			&hmac_sha1_test_crypto_vector);
12746 }
12747 
12748 static int
12749 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
12750 {
12751 	return test_authentication_verify_fail_when_tag_corrupted(
12752 			&testsuite_params, &unittest_params,
12753 			&hmac_sha1_test_crypto_vector);
12754 }
12755 
12756 static int
12757 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
12758 {
12759 	return test_authentication_verify_GMAC_fail_when_data_corrupted(
12760 			&testsuite_params, &unittest_params,
12761 			&aes128_gmac_test_vector);
12762 }
12763 
12764 static int
12765 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
12766 {
12767 	return test_authentication_verify_GMAC_fail_when_tag_corrupted(
12768 			&testsuite_params, &unittest_params,
12769 			&aes128_gmac_test_vector);
12770 }
12771 
12772 static int
12773 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
12774 {
12775 	return test_authenticated_decryption_fail_when_data_corrupted(
12776 			&testsuite_params,
12777 			&unittest_params,
12778 			&aes128cbc_hmac_sha1_test_vector);
12779 }
12780 
12781 static int
12782 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
12783 {
12784 	return test_authenticated_decryption_fail_when_tag_corrupted(
12785 			&testsuite_params,
12786 			&unittest_params,
12787 			&aes128cbc_hmac_sha1_test_vector);
12788 }
12789 
12790 static int
12791 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
12792 {
12793 	return test_authenticated_encryt_with_esn(
12794 			&testsuite_params,
12795 			&unittest_params,
12796 			&aes128cbc_hmac_sha1_aad_test_vector);
12797 }
12798 
12799 static int
12800 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
12801 {
12802 	return test_authenticated_decrypt_with_esn(
12803 			&testsuite_params,
12804 			&unittest_params,
12805 			&aes128cbc_hmac_sha1_aad_test_vector);
12806 }
12807 
12808 static int
12809 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
12810 {
12811 	return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
12812 }
12813 
12814 static int
12815 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
12816 {
12817 	return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
12818 }
12819 
12820 #ifdef RTE_CRYPTO_SCHEDULER
12821 
12822 /* global AESNI worker IDs for the scheduler test */
12823 uint8_t aesni_ids[2];
12824 
12825 static int
12826 test_scheduler_attach_slave_op(void)
12827 {
12828 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12829 	uint8_t sched_id = ts_params->valid_devs[0];
12830 	uint32_t nb_devs, i, nb_devs_attached = 0;
12831 	int ret;
12832 	char vdev_name[32];
12833 
12834 	/* create 2 AESNI_MB if necessary */
12835 	nb_devs = rte_cryptodev_device_count_by_driver(
12836 			rte_cryptodev_driver_id_get(
12837 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
12838 	if (nb_devs < 2) {
12839 		for (i = nb_devs; i < 2; i++) {
12840 			snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
12841 					RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
12842 					i);
12843 			ret = rte_vdev_init(vdev_name, NULL);
12844 
12845 			TEST_ASSERT(ret == 0,
12846 				"Failed to create instance %u of"
12847 				" pmd : %s",
12848 				i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
12849 		}
12850 	}
12851 
12852 	/* attach 2 AESNI_MB cdevs */
12853 	for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2;
12854 			i++) {
12855 		struct rte_cryptodev_info info;
12856 		unsigned int session_size;
12857 
12858 		rte_cryptodev_info_get(i, &info);
12859 		if (info.driver_id != rte_cryptodev_driver_id_get(
12860 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
12861 			continue;
12862 
12863 		session_size = rte_cryptodev_sym_get_private_session_size(i);
12864 		/*
12865 		 * Create the session mempool again, since now there are new devices
12866 		 * to use the mempool.
12867 		 */
12868 		if (ts_params->session_mpool) {
12869 			rte_mempool_free(ts_params->session_mpool);
12870 			ts_params->session_mpool = NULL;
12871 		}
12872 		if (ts_params->session_priv_mpool) {
12873 			rte_mempool_free(ts_params->session_priv_mpool);
12874 			ts_params->session_priv_mpool = NULL;
12875 		}
12876 
12877 		if (info.sym.max_nb_sessions != 0 &&
12878 				info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
12879 			RTE_LOG(ERR, USER1,
12880 					"Device does not support "
12881 					"at least %u sessions\n",
12882 					MAX_NB_SESSIONS);
12883 			return TEST_FAILED;
12884 		}
12885 		/*
12886 		 * Create mempool with maximum number of sessions,
12887 		 * to include the session headers
12888 		 */
12889 		if (ts_params->session_mpool == NULL) {
12890 			ts_params->session_mpool =
12891 				rte_cryptodev_sym_session_pool_create(
12892 						"test_sess_mp",
12893 						MAX_NB_SESSIONS, 0, 0, 0,
12894 						SOCKET_ID_ANY);
12895 			TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
12896 					"session mempool allocation failed");
12897 		}
12898 
12899 		/*
12900 		 * Create mempool with maximum number of sessions,
12901 		 * to include device specific session private data
12902 		 */
12903 		if (ts_params->session_priv_mpool == NULL) {
12904 			ts_params->session_priv_mpool = rte_mempool_create(
12905 					"test_sess_mp_priv",
12906 					MAX_NB_SESSIONS,
12907 					session_size,
12908 					0, 0, NULL, NULL, NULL,
12909 					NULL, SOCKET_ID_ANY,
12910 					0);
12911 
12912 			TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
12913 					"session mempool allocation failed");
12914 		}
12915 
12916 		ts_params->qp_conf.mp_session = ts_params->session_mpool;
12917 		ts_params->qp_conf.mp_session_private =
12918 				ts_params->session_priv_mpool;
12919 
12920 		ret = rte_cryptodev_scheduler_worker_attach(sched_id,
12921 				(uint8_t)i);
12922 
12923 		TEST_ASSERT(ret == 0,
12924 			"Failed to attach device %u of pmd : %s", i,
12925 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
12926 
12927 		aesni_ids[nb_devs_attached] = (uint8_t)i;
12928 
12929 		nb_devs_attached++;
12930 	}
12931 
12932 	return 0;
12933 }
12934 
12935 static int
12936 test_scheduler_detach_slave_op(void)
12937 {
12938 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12939 	uint8_t sched_id = ts_params->valid_devs[0];
12940 	uint32_t i;
12941 	int ret;
12942 
12943 	for (i = 0; i < 2; i++) {
12944 		ret = rte_cryptodev_scheduler_worker_detach(sched_id,
12945 				aesni_ids[i]);
12946 		TEST_ASSERT(ret == 0,
12947 			"Failed to detach device %u", aesni_ids[i]);
12948 	}
12949 
12950 	return 0;
12951 }
12952 
12953 static int
12954 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
12955 {
12956 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12957 	uint8_t sched_id = ts_params->valid_devs[0];
12958 	/* set mode */
12959 	return rte_cryptodev_scheduler_mode_set(sched_id,
12960 		scheduler_mode);
12961 }
12962 
12963 static int
12964 test_scheduler_mode_roundrobin_op(void)
12965 {
12966 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
12967 			0, "Failed to set roundrobin mode");
12968 	return 0;
12969 
12970 }
12971 
12972 static int
12973 test_scheduler_mode_multicore_op(void)
12974 {
12975 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
12976 			0, "Failed to set multicore mode");
12977 
12978 	return 0;
12979 }
12980 
12981 static int
12982 test_scheduler_mode_failover_op(void)
12983 {
12984 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
12985 			0, "Failed to set failover mode");
12986 
12987 	return 0;
12988 }
12989 
12990 static int
12991 test_scheduler_mode_pkt_size_distr_op(void)
12992 {
12993 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
12994 			0, "Failed to set pktsize mode");
12995 
12996 	return 0;
12997 }
12998 
12999 static struct unit_test_suite cryptodev_scheduler_testsuite  = {
13000 	.suite_name = "Crypto Device Scheduler Unit Test Suite",
13001 	.setup = testsuite_setup,
13002 	.teardown = testsuite_teardown,
13003 	.unit_test_cases = {
13004 		/* Multi Core */
13005 		TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
13006 		TEST_CASE_ST(NULL, NULL, test_scheduler_mode_multicore_op),
13007 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13008 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13009 		TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13010 		TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
13011 
13012 		/* Round Robin */
13013 		TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
13014 		TEST_CASE_ST(NULL, NULL, test_scheduler_mode_roundrobin_op),
13015 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13016 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13017 		TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13018 		TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
13019 
13020 		/* Fail over */
13021 		TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
13022 		TEST_CASE_ST(NULL, NULL, test_scheduler_mode_failover_op),
13023 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13024 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13025 		TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13026 		TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
13027 
13028 		/* PKT SIZE */
13029 		TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
13030 		TEST_CASE_ST(NULL, NULL, test_scheduler_mode_pkt_size_distr_op),
13031 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13032 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13033 		TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13034 		TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
13035 
13036 		TEST_CASES_END() /**< NULL terminate unit test array */
13037 	}
13038 };
13039 
13040 #endif /* RTE_CRYPTO_SCHEDULER */
13041 
13042 static struct unit_test_suite cryptodev_testsuite  = {
13043 	.suite_name = "Crypto Unit Test Suite",
13044 	.setup = testsuite_setup,
13045 	.teardown = testsuite_teardown,
13046 	.unit_test_cases = {
13047 		TEST_CASE_ST(ut_setup, ut_teardown,
13048 				test_device_configure_invalid_dev_id),
13049 		TEST_CASE_ST(ut_setup, ut_teardown,
13050 				test_queue_pair_descriptor_setup),
13051 		TEST_CASE_ST(ut_setup, ut_teardown,
13052 				test_device_configure_invalid_queue_pair_ids),
13053 
13054 		TEST_CASE_ST(ut_setup, ut_teardown,
13055 				test_multi_session),
13056 		TEST_CASE_ST(ut_setup, ut_teardown,
13057 				test_multi_session_random_usage),
13058 
13059 		TEST_CASE_ST(ut_setup, ut_teardown,
13060 			test_null_invalid_operation),
13061 		TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
13062 
13063 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13064 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13065 		TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13066 		TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13067 		TEST_CASE_ST(ut_setup, ut_teardown, test_DES_cipheronly_all),
13068 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_all),
13069 		TEST_CASE_ST(ut_setup, ut_teardown, test_DES_docsis_all),
13070 		TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13071 		TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
13072 
13073 		/** AES CCM Authenticated Encryption 128 bits key */
13074 		TEST_CASE_ST(ut_setup, ut_teardown,
13075 			test_AES_CCM_authenticated_encryption_test_case_128_1),
13076 		TEST_CASE_ST(ut_setup, ut_teardown,
13077 			test_AES_CCM_authenticated_encryption_test_case_128_2),
13078 		TEST_CASE_ST(ut_setup, ut_teardown,
13079 			test_AES_CCM_authenticated_encryption_test_case_128_3),
13080 
13081 		/** AES CCM Authenticated Decryption 128 bits key*/
13082 		TEST_CASE_ST(ut_setup, ut_teardown,
13083 			test_AES_CCM_authenticated_decryption_test_case_128_1),
13084 		TEST_CASE_ST(ut_setup, ut_teardown,
13085 			test_AES_CCM_authenticated_decryption_test_case_128_2),
13086 		TEST_CASE_ST(ut_setup, ut_teardown,
13087 			test_AES_CCM_authenticated_decryption_test_case_128_3),
13088 
13089 		/** AES CCM Authenticated Encryption 192 bits key */
13090 		TEST_CASE_ST(ut_setup, ut_teardown,
13091 			test_AES_CCM_authenticated_encryption_test_case_192_1),
13092 		TEST_CASE_ST(ut_setup, ut_teardown,
13093 			test_AES_CCM_authenticated_encryption_test_case_192_2),
13094 		TEST_CASE_ST(ut_setup, ut_teardown,
13095 			test_AES_CCM_authenticated_encryption_test_case_192_3),
13096 
13097 		/** AES CCM Authenticated Decryption 192 bits key*/
13098 		TEST_CASE_ST(ut_setup, ut_teardown,
13099 			test_AES_CCM_authenticated_decryption_test_case_192_1),
13100 		TEST_CASE_ST(ut_setup, ut_teardown,
13101 			test_AES_CCM_authenticated_decryption_test_case_192_2),
13102 		TEST_CASE_ST(ut_setup, ut_teardown,
13103 			test_AES_CCM_authenticated_decryption_test_case_192_3),
13104 
13105 		/** AES CCM Authenticated Encryption 256 bits key */
13106 		TEST_CASE_ST(ut_setup, ut_teardown,
13107 			test_AES_CCM_authenticated_encryption_test_case_256_1),
13108 		TEST_CASE_ST(ut_setup, ut_teardown,
13109 			test_AES_CCM_authenticated_encryption_test_case_256_2),
13110 		TEST_CASE_ST(ut_setup, ut_teardown,
13111 			test_AES_CCM_authenticated_encryption_test_case_256_3),
13112 
13113 		/** AES CCM Authenticated Decryption 256 bits key*/
13114 		TEST_CASE_ST(ut_setup, ut_teardown,
13115 			test_AES_CCM_authenticated_decryption_test_case_256_1),
13116 		TEST_CASE_ST(ut_setup, ut_teardown,
13117 			test_AES_CCM_authenticated_decryption_test_case_256_2),
13118 		TEST_CASE_ST(ut_setup, ut_teardown,
13119 			test_AES_CCM_authenticated_decryption_test_case_256_3),
13120 
13121 		/** AES GCM Authenticated Encryption */
13122 		TEST_CASE_ST(ut_setup, ut_teardown,
13123 			test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
13124 		TEST_CASE_ST(ut_setup, ut_teardown,
13125 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
13126 		TEST_CASE_ST(ut_setup, ut_teardown,
13127 			test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
13128 		TEST_CASE_ST(ut_setup, ut_teardown,
13129 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
13130 		TEST_CASE_ST(ut_setup, ut_teardown,
13131 			test_AES_GCM_authenticated_encryption_test_case_1),
13132 		TEST_CASE_ST(ut_setup, ut_teardown,
13133 			test_AES_GCM_authenticated_encryption_test_case_2),
13134 		TEST_CASE_ST(ut_setup, ut_teardown,
13135 			test_AES_GCM_authenticated_encryption_test_case_3),
13136 		TEST_CASE_ST(ut_setup, ut_teardown,
13137 			test_AES_GCM_authenticated_encryption_test_case_4),
13138 		TEST_CASE_ST(ut_setup, ut_teardown,
13139 			test_AES_GCM_authenticated_encryption_test_case_5),
13140 		TEST_CASE_ST(ut_setup, ut_teardown,
13141 			test_AES_GCM_authenticated_encryption_test_case_6),
13142 		TEST_CASE_ST(ut_setup, ut_teardown,
13143 			test_AES_GCM_authenticated_encryption_test_case_7),
13144 		TEST_CASE_ST(ut_setup, ut_teardown,
13145 			test_AES_GCM_authenticated_encryption_test_case_8),
13146 		TEST_CASE_ST(ut_setup, ut_teardown,
13147 			test_AES_GCM_J0_authenticated_encryption_test_case_1),
13148 
13149 		/** AES GCM Authenticated Decryption */
13150 		TEST_CASE_ST(ut_setup, ut_teardown,
13151 			test_AES_GCM_authenticated_decryption_test_case_1),
13152 		TEST_CASE_ST(ut_setup, ut_teardown,
13153 			test_AES_GCM_authenticated_decryption_test_case_2),
13154 		TEST_CASE_ST(ut_setup, ut_teardown,
13155 			test_AES_GCM_authenticated_decryption_test_case_3),
13156 		TEST_CASE_ST(ut_setup, ut_teardown,
13157 			test_AES_GCM_authenticated_decryption_test_case_4),
13158 		TEST_CASE_ST(ut_setup, ut_teardown,
13159 			test_AES_GCM_authenticated_decryption_test_case_5),
13160 		TEST_CASE_ST(ut_setup, ut_teardown,
13161 			test_AES_GCM_authenticated_decryption_test_case_6),
13162 		TEST_CASE_ST(ut_setup, ut_teardown,
13163 			test_AES_GCM_authenticated_decryption_test_case_7),
13164 		TEST_CASE_ST(ut_setup, ut_teardown,
13165 			test_AES_GCM_authenticated_decryption_test_case_8),
13166 		TEST_CASE_ST(ut_setup, ut_teardown,
13167 			test_AES_GCM_J0_authenticated_decryption_test_case_1),
13168 
13169 		/** AES GCM Authenticated Encryption 192 bits key */
13170 		TEST_CASE_ST(ut_setup, ut_teardown,
13171 			test_AES_GCM_auth_encryption_test_case_192_1),
13172 		TEST_CASE_ST(ut_setup, ut_teardown,
13173 			test_AES_GCM_auth_encryption_test_case_192_2),
13174 		TEST_CASE_ST(ut_setup, ut_teardown,
13175 			test_AES_GCM_auth_encryption_test_case_192_3),
13176 		TEST_CASE_ST(ut_setup, ut_teardown,
13177 			test_AES_GCM_auth_encryption_test_case_192_4),
13178 		TEST_CASE_ST(ut_setup, ut_teardown,
13179 			test_AES_GCM_auth_encryption_test_case_192_5),
13180 		TEST_CASE_ST(ut_setup, ut_teardown,
13181 			test_AES_GCM_auth_encryption_test_case_192_6),
13182 		TEST_CASE_ST(ut_setup, ut_teardown,
13183 			test_AES_GCM_auth_encryption_test_case_192_7),
13184 
13185 		/** AES GCM Authenticated Decryption 192 bits key */
13186 		TEST_CASE_ST(ut_setup, ut_teardown,
13187 			test_AES_GCM_auth_decryption_test_case_192_1),
13188 		TEST_CASE_ST(ut_setup, ut_teardown,
13189 			test_AES_GCM_auth_decryption_test_case_192_2),
13190 		TEST_CASE_ST(ut_setup, ut_teardown,
13191 			test_AES_GCM_auth_decryption_test_case_192_3),
13192 		TEST_CASE_ST(ut_setup, ut_teardown,
13193 			test_AES_GCM_auth_decryption_test_case_192_4),
13194 		TEST_CASE_ST(ut_setup, ut_teardown,
13195 			test_AES_GCM_auth_decryption_test_case_192_5),
13196 		TEST_CASE_ST(ut_setup, ut_teardown,
13197 			test_AES_GCM_auth_decryption_test_case_192_6),
13198 		TEST_CASE_ST(ut_setup, ut_teardown,
13199 			test_AES_GCM_auth_decryption_test_case_192_7),
13200 
13201 		/** AES GCM Authenticated Encryption 256 bits key */
13202 		TEST_CASE_ST(ut_setup, ut_teardown,
13203 			test_AES_GCM_auth_encryption_test_case_256_1),
13204 		TEST_CASE_ST(ut_setup, ut_teardown,
13205 			test_AES_GCM_auth_encryption_test_case_256_2),
13206 		TEST_CASE_ST(ut_setup, ut_teardown,
13207 			test_AES_GCM_auth_encryption_test_case_256_3),
13208 		TEST_CASE_ST(ut_setup, ut_teardown,
13209 			test_AES_GCM_auth_encryption_test_case_256_4),
13210 		TEST_CASE_ST(ut_setup, ut_teardown,
13211 			test_AES_GCM_auth_encryption_test_case_256_5),
13212 		TEST_CASE_ST(ut_setup, ut_teardown,
13213 			test_AES_GCM_auth_encryption_test_case_256_6),
13214 		TEST_CASE_ST(ut_setup, ut_teardown,
13215 			test_AES_GCM_auth_encryption_test_case_256_7),
13216 
13217 		/** AES GCM Authenticated Decryption 256 bits key */
13218 		TEST_CASE_ST(ut_setup, ut_teardown,
13219 			test_AES_GCM_auth_decryption_test_case_256_1),
13220 		TEST_CASE_ST(ut_setup, ut_teardown,
13221 			test_AES_GCM_auth_decryption_test_case_256_2),
13222 		TEST_CASE_ST(ut_setup, ut_teardown,
13223 			test_AES_GCM_auth_decryption_test_case_256_3),
13224 		TEST_CASE_ST(ut_setup, ut_teardown,
13225 			test_AES_GCM_auth_decryption_test_case_256_4),
13226 		TEST_CASE_ST(ut_setup, ut_teardown,
13227 			test_AES_GCM_auth_decryption_test_case_256_5),
13228 		TEST_CASE_ST(ut_setup, ut_teardown,
13229 			test_AES_GCM_auth_decryption_test_case_256_6),
13230 		TEST_CASE_ST(ut_setup, ut_teardown,
13231 			test_AES_GCM_auth_decryption_test_case_256_7),
13232 
13233 		/** AES GCM Authenticated Encryption big aad size */
13234 		TEST_CASE_ST(ut_setup, ut_teardown,
13235 			test_AES_GCM_auth_encryption_test_case_aad_1),
13236 		TEST_CASE_ST(ut_setup, ut_teardown,
13237 			test_AES_GCM_auth_encryption_test_case_aad_2),
13238 
13239 		/** AES GCM Authenticated Decryption big aad size */
13240 		TEST_CASE_ST(ut_setup, ut_teardown,
13241 			test_AES_GCM_auth_decryption_test_case_aad_1),
13242 		TEST_CASE_ST(ut_setup, ut_teardown,
13243 			test_AES_GCM_auth_decryption_test_case_aad_2),
13244 
13245 		/** Out of place tests */
13246 		TEST_CASE_ST(ut_setup, ut_teardown,
13247 			test_AES_GCM_authenticated_encryption_oop_test_case_1),
13248 		TEST_CASE_ST(ut_setup, ut_teardown,
13249 			test_AES_GCM_authenticated_decryption_oop_test_case_1),
13250 
13251 		/** Session-less tests */
13252 		TEST_CASE_ST(ut_setup, ut_teardown,
13253 			test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
13254 		TEST_CASE_ST(ut_setup, ut_teardown,
13255 			test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
13256 
13257 		/** AES GMAC Authentication */
13258 		TEST_CASE_ST(ut_setup, ut_teardown,
13259 			test_AES_GMAC_authentication_test_case_1),
13260 		TEST_CASE_ST(ut_setup, ut_teardown,
13261 			test_AES_GMAC_authentication_verify_test_case_1),
13262 		TEST_CASE_ST(ut_setup, ut_teardown,
13263 			test_AES_GMAC_authentication_test_case_2),
13264 		TEST_CASE_ST(ut_setup, ut_teardown,
13265 			test_AES_GMAC_authentication_verify_test_case_2),
13266 		TEST_CASE_ST(ut_setup, ut_teardown,
13267 			test_AES_GMAC_authentication_test_case_3),
13268 		TEST_CASE_ST(ut_setup, ut_teardown,
13269 			test_AES_GMAC_authentication_verify_test_case_3),
13270 		TEST_CASE_ST(ut_setup, ut_teardown,
13271 			test_AES_GMAC_authentication_test_case_4),
13272 		TEST_CASE_ST(ut_setup, ut_teardown,
13273 			test_AES_GMAC_authentication_verify_test_case_4),
13274 		TEST_CASE_ST(ut_setup, ut_teardown,
13275 			test_AES_GMAC_authentication_SGL_40B),
13276 		TEST_CASE_ST(ut_setup, ut_teardown,
13277 			test_AES_GMAC_authentication_SGL_80B),
13278 		TEST_CASE_ST(ut_setup, ut_teardown,
13279 			test_AES_GMAC_authentication_SGL_2048B),
13280 		TEST_CASE_ST(ut_setup, ut_teardown,
13281 			test_AES_GMAC_authentication_SGL_2047B),
13282 
13283 		/** Chacha20-Poly1305 */
13284 		TEST_CASE_ST(ut_setup, ut_teardown,
13285 			test_chacha20_poly1305_encrypt_test_case_rfc8439),
13286 		TEST_CASE_ST(ut_setup, ut_teardown,
13287 			test_chacha20_poly1305_decrypt_test_case_rfc8439),
13288 		/** SNOW 3G encrypt only (UEA2) */
13289 		TEST_CASE_ST(ut_setup, ut_teardown,
13290 			test_snow3g_encryption_test_case_1),
13291 		TEST_CASE_ST(ut_setup, ut_teardown,
13292 			test_snow3g_encryption_test_case_2),
13293 		TEST_CASE_ST(ut_setup, ut_teardown,
13294 			test_snow3g_encryption_test_case_3),
13295 		TEST_CASE_ST(ut_setup, ut_teardown,
13296 			test_snow3g_encryption_test_case_4),
13297 		TEST_CASE_ST(ut_setup, ut_teardown,
13298 			test_snow3g_encryption_test_case_5),
13299 
13300 		TEST_CASE_ST(ut_setup, ut_teardown,
13301 			test_snow3g_encryption_test_case_1_oop),
13302 		TEST_CASE_ST(ut_setup, ut_teardown,
13303 			test_snow3g_encryption_test_case_1_oop_sgl),
13304 		TEST_CASE_ST(ut_setup, ut_teardown,
13305 			test_snow3g_encryption_test_case_1_offset_oop),
13306 		TEST_CASE_ST(ut_setup, ut_teardown,
13307 			test_snow3g_decryption_test_case_1_oop),
13308 
13309 		/** SNOW 3G generate auth, then encrypt (UEA2) */
13310 		TEST_CASE_ST(ut_setup, ut_teardown,
13311 			test_snow3g_auth_cipher_test_case_1),
13312 		TEST_CASE_ST(ut_setup, ut_teardown,
13313 			test_snow3g_auth_cipher_test_case_2),
13314 		TEST_CASE_ST(ut_setup, ut_teardown,
13315 			test_snow3g_auth_cipher_test_case_2_oop),
13316 		TEST_CASE_ST(ut_setup, ut_teardown,
13317 			test_snow3g_auth_cipher_part_digest_enc),
13318 		TEST_CASE_ST(ut_setup, ut_teardown,
13319 			test_snow3g_auth_cipher_part_digest_enc_oop),
13320 		TEST_CASE_ST(ut_setup, ut_teardown,
13321 			test_snow3g_auth_cipher_test_case_3_sgl),
13322 		TEST_CASE_ST(ut_setup, ut_teardown,
13323 			test_snow3g_auth_cipher_test_case_3_oop_sgl),
13324 		TEST_CASE_ST(ut_setup, ut_teardown,
13325 			test_snow3g_auth_cipher_part_digest_enc_sgl),
13326 		TEST_CASE_ST(ut_setup, ut_teardown,
13327 			test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
13328 
13329 		/** SNOW 3G decrypt (UEA2), then verify auth */
13330 		TEST_CASE_ST(ut_setup, ut_teardown,
13331 			test_snow3g_auth_cipher_verify_test_case_1),
13332 		TEST_CASE_ST(ut_setup, ut_teardown,
13333 			test_snow3g_auth_cipher_verify_test_case_2),
13334 		TEST_CASE_ST(ut_setup, ut_teardown,
13335 			test_snow3g_auth_cipher_verify_test_case_2_oop),
13336 		TEST_CASE_ST(ut_setup, ut_teardown,
13337 			test_snow3g_auth_cipher_verify_part_digest_enc),
13338 		TEST_CASE_ST(ut_setup, ut_teardown,
13339 			test_snow3g_auth_cipher_verify_part_digest_enc_oop),
13340 		TEST_CASE_ST(ut_setup, ut_teardown,
13341 			test_snow3g_auth_cipher_verify_test_case_3_sgl),
13342 		TEST_CASE_ST(ut_setup, ut_teardown,
13343 			test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
13344 		TEST_CASE_ST(ut_setup, ut_teardown,
13345 			test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
13346 		TEST_CASE_ST(ut_setup, ut_teardown,
13347 			test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
13348 
13349 		/** SNOW 3G decrypt only (UEA2) */
13350 		TEST_CASE_ST(ut_setup, ut_teardown,
13351 			test_snow3g_decryption_test_case_1),
13352 		TEST_CASE_ST(ut_setup, ut_teardown,
13353 			test_snow3g_decryption_test_case_2),
13354 		TEST_CASE_ST(ut_setup, ut_teardown,
13355 			test_snow3g_decryption_test_case_3),
13356 		TEST_CASE_ST(ut_setup, ut_teardown,
13357 			test_snow3g_decryption_test_case_4),
13358 		TEST_CASE_ST(ut_setup, ut_teardown,
13359 			test_snow3g_decryption_test_case_5),
13360 		TEST_CASE_ST(ut_setup, ut_teardown,
13361 			test_snow3g_decryption_with_digest_test_case_1),
13362 		TEST_CASE_ST(ut_setup, ut_teardown,
13363 			test_snow3g_hash_generate_test_case_1),
13364 		TEST_CASE_ST(ut_setup, ut_teardown,
13365 			test_snow3g_hash_generate_test_case_2),
13366 		TEST_CASE_ST(ut_setup, ut_teardown,
13367 			test_snow3g_hash_generate_test_case_3),
13368 		/* Tests with buffers which length is not byte-aligned */
13369 		TEST_CASE_ST(ut_setup, ut_teardown,
13370 			test_snow3g_hash_generate_test_case_4),
13371 		TEST_CASE_ST(ut_setup, ut_teardown,
13372 			test_snow3g_hash_generate_test_case_5),
13373 		TEST_CASE_ST(ut_setup, ut_teardown,
13374 			test_snow3g_hash_generate_test_case_6),
13375 		TEST_CASE_ST(ut_setup, ut_teardown,
13376 			test_snow3g_hash_verify_test_case_1),
13377 		TEST_CASE_ST(ut_setup, ut_teardown,
13378 			test_snow3g_hash_verify_test_case_2),
13379 		TEST_CASE_ST(ut_setup, ut_teardown,
13380 			test_snow3g_hash_verify_test_case_3),
13381 		/* Tests with buffers which length is not byte-aligned */
13382 		TEST_CASE_ST(ut_setup, ut_teardown,
13383 			test_snow3g_hash_verify_test_case_4),
13384 		TEST_CASE_ST(ut_setup, ut_teardown,
13385 			test_snow3g_hash_verify_test_case_5),
13386 		TEST_CASE_ST(ut_setup, ut_teardown,
13387 			test_snow3g_hash_verify_test_case_6),
13388 		TEST_CASE_ST(ut_setup, ut_teardown,
13389 			test_snow3g_cipher_auth_test_case_1),
13390 		TEST_CASE_ST(ut_setup, ut_teardown,
13391 			test_snow3g_auth_cipher_with_digest_test_case_1),
13392 
13393 		/** ZUC encrypt only (EEA3) */
13394 		TEST_CASE_ST(ut_setup, ut_teardown,
13395 			test_zuc_encryption_test_case_1),
13396 		TEST_CASE_ST(ut_setup, ut_teardown,
13397 			test_zuc_encryption_test_case_2),
13398 		TEST_CASE_ST(ut_setup, ut_teardown,
13399 			test_zuc_encryption_test_case_3),
13400 		TEST_CASE_ST(ut_setup, ut_teardown,
13401 			test_zuc_encryption_test_case_4),
13402 		TEST_CASE_ST(ut_setup, ut_teardown,
13403 			test_zuc_encryption_test_case_5),
13404 		TEST_CASE_ST(ut_setup, ut_teardown,
13405 			test_zuc_encryption_test_case_6_sgl),
13406 
13407 		/** ZUC authenticate (EIA3) */
13408 		TEST_CASE_ST(ut_setup, ut_teardown,
13409 			test_zuc_hash_generate_test_case_1),
13410 		TEST_CASE_ST(ut_setup, ut_teardown,
13411 			test_zuc_hash_generate_test_case_2),
13412 		TEST_CASE_ST(ut_setup, ut_teardown,
13413 			test_zuc_hash_generate_test_case_3),
13414 		TEST_CASE_ST(ut_setup, ut_teardown,
13415 			test_zuc_hash_generate_test_case_4),
13416 		TEST_CASE_ST(ut_setup, ut_teardown,
13417 			test_zuc_hash_generate_test_case_5),
13418 		TEST_CASE_ST(ut_setup, ut_teardown,
13419 			test_zuc_hash_generate_test_case_6),
13420 		TEST_CASE_ST(ut_setup, ut_teardown,
13421 			test_zuc_hash_generate_test_case_7),
13422 		TEST_CASE_ST(ut_setup, ut_teardown,
13423 			test_zuc_hash_generate_test_case_8),
13424 
13425 		/** ZUC alg-chain (EEA3/EIA3) */
13426 		TEST_CASE_ST(ut_setup, ut_teardown,
13427 			test_zuc_cipher_auth_test_case_1),
13428 		TEST_CASE_ST(ut_setup, ut_teardown,
13429 			test_zuc_cipher_auth_test_case_2),
13430 
13431 		/** ZUC generate auth, then encrypt (EEA3) */
13432 		TEST_CASE_ST(ut_setup, ut_teardown,
13433 			test_zuc_auth_cipher_test_case_1),
13434 		TEST_CASE_ST(ut_setup, ut_teardown,
13435 			test_zuc_auth_cipher_test_case_1_oop),
13436 		TEST_CASE_ST(ut_setup, ut_teardown,
13437 			test_zuc_auth_cipher_test_case_1_sgl),
13438 		TEST_CASE_ST(ut_setup, ut_teardown,
13439 			test_zuc_auth_cipher_test_case_1_oop_sgl),
13440 
13441 		/** ZUC decrypt (EEA3), then verify auth */
13442 		TEST_CASE_ST(ut_setup, ut_teardown,
13443 			test_zuc_auth_cipher_verify_test_case_1),
13444 		TEST_CASE_ST(ut_setup, ut_teardown,
13445 			test_zuc_auth_cipher_verify_test_case_1_oop),
13446 		TEST_CASE_ST(ut_setup, ut_teardown,
13447 			test_zuc_auth_cipher_verify_test_case_1_sgl),
13448 		TEST_CASE_ST(ut_setup, ut_teardown,
13449 			test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
13450 
13451 		/** HMAC_MD5 Authentication */
13452 		TEST_CASE_ST(ut_setup, ut_teardown,
13453 			test_MD5_HMAC_generate_case_1),
13454 		TEST_CASE_ST(ut_setup, ut_teardown,
13455 			test_MD5_HMAC_verify_case_1),
13456 		TEST_CASE_ST(ut_setup, ut_teardown,
13457 			test_MD5_HMAC_generate_case_2),
13458 		TEST_CASE_ST(ut_setup, ut_teardown,
13459 			test_MD5_HMAC_verify_case_2),
13460 
13461 		/** KASUMI hash only (UIA1) */
13462 		TEST_CASE_ST(ut_setup, ut_teardown,
13463 			test_kasumi_hash_generate_test_case_1),
13464 		TEST_CASE_ST(ut_setup, ut_teardown,
13465 			test_kasumi_hash_generate_test_case_2),
13466 		TEST_CASE_ST(ut_setup, ut_teardown,
13467 			test_kasumi_hash_generate_test_case_3),
13468 		TEST_CASE_ST(ut_setup, ut_teardown,
13469 			test_kasumi_hash_generate_test_case_4),
13470 		TEST_CASE_ST(ut_setup, ut_teardown,
13471 			test_kasumi_hash_generate_test_case_5),
13472 		TEST_CASE_ST(ut_setup, ut_teardown,
13473 			test_kasumi_hash_generate_test_case_6),
13474 
13475 		TEST_CASE_ST(ut_setup, ut_teardown,
13476 			test_kasumi_hash_verify_test_case_1),
13477 		TEST_CASE_ST(ut_setup, ut_teardown,
13478 			test_kasumi_hash_verify_test_case_2),
13479 		TEST_CASE_ST(ut_setup, ut_teardown,
13480 			test_kasumi_hash_verify_test_case_3),
13481 		TEST_CASE_ST(ut_setup, ut_teardown,
13482 			test_kasumi_hash_verify_test_case_4),
13483 		TEST_CASE_ST(ut_setup, ut_teardown,
13484 			test_kasumi_hash_verify_test_case_5),
13485 
13486 		/** KASUMI encrypt only (UEA1) */
13487 		TEST_CASE_ST(ut_setup, ut_teardown,
13488 			test_kasumi_encryption_test_case_1),
13489 		TEST_CASE_ST(ut_setup, ut_teardown,
13490 			test_kasumi_encryption_test_case_1_sgl),
13491 		TEST_CASE_ST(ut_setup, ut_teardown,
13492 			test_kasumi_encryption_test_case_1_oop),
13493 		TEST_CASE_ST(ut_setup, ut_teardown,
13494 			test_kasumi_encryption_test_case_1_oop_sgl),
13495 		TEST_CASE_ST(ut_setup, ut_teardown,
13496 			test_kasumi_encryption_test_case_2),
13497 		TEST_CASE_ST(ut_setup, ut_teardown,
13498 			test_kasumi_encryption_test_case_3),
13499 		TEST_CASE_ST(ut_setup, ut_teardown,
13500 			test_kasumi_encryption_test_case_4),
13501 		TEST_CASE_ST(ut_setup, ut_teardown,
13502 			test_kasumi_encryption_test_case_5),
13503 
13504 		/** KASUMI decrypt only (UEA1) */
13505 		TEST_CASE_ST(ut_setup, ut_teardown,
13506 			test_kasumi_decryption_test_case_1),
13507 		TEST_CASE_ST(ut_setup, ut_teardown,
13508 			test_kasumi_decryption_test_case_2),
13509 		TEST_CASE_ST(ut_setup, ut_teardown,
13510 			test_kasumi_decryption_test_case_3),
13511 		TEST_CASE_ST(ut_setup, ut_teardown,
13512 			test_kasumi_decryption_test_case_4),
13513 		TEST_CASE_ST(ut_setup, ut_teardown,
13514 			test_kasumi_decryption_test_case_5),
13515 		TEST_CASE_ST(ut_setup, ut_teardown,
13516 			test_kasumi_decryption_test_case_1_oop),
13517 
13518 		TEST_CASE_ST(ut_setup, ut_teardown,
13519 			test_kasumi_cipher_auth_test_case_1),
13520 
13521 		/** KASUMI generate auth, then encrypt (F8) */
13522 		TEST_CASE_ST(ut_setup, ut_teardown,
13523 			test_kasumi_auth_cipher_test_case_1),
13524 		TEST_CASE_ST(ut_setup, ut_teardown,
13525 			test_kasumi_auth_cipher_test_case_2),
13526 		TEST_CASE_ST(ut_setup, ut_teardown,
13527 			test_kasumi_auth_cipher_test_case_2_oop),
13528 		TEST_CASE_ST(ut_setup, ut_teardown,
13529 			test_kasumi_auth_cipher_test_case_2_sgl),
13530 		TEST_CASE_ST(ut_setup, ut_teardown,
13531 			test_kasumi_auth_cipher_test_case_2_oop_sgl),
13532 
13533 		/** KASUMI decrypt (F8), then verify auth */
13534 		TEST_CASE_ST(ut_setup, ut_teardown,
13535 			test_kasumi_auth_cipher_verify_test_case_1),
13536 		TEST_CASE_ST(ut_setup, ut_teardown,
13537 			test_kasumi_auth_cipher_verify_test_case_2),
13538 		TEST_CASE_ST(ut_setup, ut_teardown,
13539 			test_kasumi_auth_cipher_verify_test_case_2_oop),
13540 		TEST_CASE_ST(ut_setup, ut_teardown,
13541 			test_kasumi_auth_cipher_verify_test_case_2_sgl),
13542 		TEST_CASE_ST(ut_setup, ut_teardown,
13543 			test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
13544 
13545 		/** ESN Testcase */
13546 		TEST_CASE_ST(ut_setup, ut_teardown,
13547 			auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
13548 		TEST_CASE_ST(ut_setup, ut_teardown,
13549 			auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
13550 
13551 		/** Negative tests */
13552 		TEST_CASE_ST(ut_setup, ut_teardown,
13553 			authentication_verify_HMAC_SHA1_fail_data_corrupt),
13554 		TEST_CASE_ST(ut_setup, ut_teardown,
13555 			authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13556 		TEST_CASE_ST(ut_setup, ut_teardown,
13557 			test_AES_GCM_auth_encryption_fail_iv_corrupt),
13558 		TEST_CASE_ST(ut_setup, ut_teardown,
13559 			test_AES_GCM_auth_encryption_fail_in_data_corrupt),
13560 		TEST_CASE_ST(ut_setup, ut_teardown,
13561 			test_AES_GCM_auth_encryption_fail_out_data_corrupt),
13562 		TEST_CASE_ST(ut_setup, ut_teardown,
13563 			test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
13564 		TEST_CASE_ST(ut_setup, ut_teardown,
13565 			test_AES_GCM_auth_encryption_fail_aad_corrupt),
13566 		TEST_CASE_ST(ut_setup, ut_teardown,
13567 			test_AES_GCM_auth_encryption_fail_tag_corrupt),
13568 		TEST_CASE_ST(ut_setup, ut_teardown,
13569 			test_AES_GCM_auth_decryption_fail_iv_corrupt),
13570 		TEST_CASE_ST(ut_setup, ut_teardown,
13571 			test_AES_GCM_auth_decryption_fail_in_data_corrupt),
13572 		TEST_CASE_ST(ut_setup, ut_teardown,
13573 			test_AES_GCM_auth_decryption_fail_out_data_corrupt),
13574 		TEST_CASE_ST(ut_setup, ut_teardown,
13575 			test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
13576 		TEST_CASE_ST(ut_setup, ut_teardown,
13577 			test_AES_GCM_auth_decryption_fail_aad_corrupt),
13578 		TEST_CASE_ST(ut_setup, ut_teardown,
13579 			test_AES_GCM_auth_decryption_fail_tag_corrupt),
13580 		TEST_CASE_ST(ut_setup, ut_teardown,
13581 			authentication_verify_AES128_GMAC_fail_data_corrupt),
13582 		TEST_CASE_ST(ut_setup, ut_teardown,
13583 			authentication_verify_AES128_GMAC_fail_tag_corrupt),
13584 		TEST_CASE_ST(ut_setup, ut_teardown,
13585 			auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13586 		TEST_CASE_ST(ut_setup, ut_teardown,
13587 			auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13588 
13589 		/** Mixed CIPHER + HASH algorithms */
13590 		/** AUTH AES CMAC + CIPHER AES CTR */
13591 		TEST_CASE_ST(ut_setup, ut_teardown,
13592 			test_aes_cmac_aes_ctr_digest_enc_test_case_1),
13593 		TEST_CASE_ST(ut_setup, ut_teardown,
13594 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
13595 		TEST_CASE_ST(ut_setup, ut_teardown,
13596 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
13597 		TEST_CASE_ST(ut_setup, ut_teardown,
13598 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
13599 		TEST_CASE_ST(ut_setup, ut_teardown,
13600 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
13601 		TEST_CASE_ST(ut_setup, ut_teardown,
13602 		       test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
13603 		TEST_CASE_ST(ut_setup, ut_teardown,
13604 		       test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
13605 		TEST_CASE_ST(ut_setup, ut_teardown,
13606 		   test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
13607 
13608 		/** AUTH ZUC + CIPHER SNOW3G */
13609 		TEST_CASE_ST(ut_setup, ut_teardown,
13610 			test_auth_zuc_cipher_snow_test_case_1),
13611 		TEST_CASE_ST(ut_setup, ut_teardown,
13612 			test_verify_auth_zuc_cipher_snow_test_case_1),
13613 		/** AUTH AES CMAC + CIPHER SNOW3G */
13614 		TEST_CASE_ST(ut_setup, ut_teardown,
13615 			test_auth_aes_cmac_cipher_snow_test_case_1),
13616 		TEST_CASE_ST(ut_setup, ut_teardown,
13617 			test_verify_auth_aes_cmac_cipher_snow_test_case_1),
13618 		/** AUTH ZUC + CIPHER AES CTR */
13619 		TEST_CASE_ST(ut_setup, ut_teardown,
13620 			test_auth_zuc_cipher_aes_ctr_test_case_1),
13621 		TEST_CASE_ST(ut_setup, ut_teardown,
13622 			test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
13623 		/** AUTH SNOW3G + CIPHER AES CTR */
13624 		TEST_CASE_ST(ut_setup, ut_teardown,
13625 			test_auth_snow_cipher_aes_ctr_test_case_1),
13626 		TEST_CASE_ST(ut_setup, ut_teardown,
13627 			test_verify_auth_snow_cipher_aes_ctr_test_case_1),
13628 		/** AUTH SNOW3G + CIPHER ZUC */
13629 		TEST_CASE_ST(ut_setup, ut_teardown,
13630 			test_auth_snow_cipher_zuc_test_case_1),
13631 		TEST_CASE_ST(ut_setup, ut_teardown,
13632 			test_verify_auth_snow_cipher_zuc_test_case_1),
13633 		/** AUTH AES CMAC + CIPHER ZUC */
13634 		TEST_CASE_ST(ut_setup, ut_teardown,
13635 			test_auth_aes_cmac_cipher_zuc_test_case_1),
13636 		TEST_CASE_ST(ut_setup, ut_teardown,
13637 			test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
13638 
13639 		/** AUTH NULL + CIPHER SNOW3G */
13640 		TEST_CASE_ST(ut_setup, ut_teardown,
13641 			test_auth_null_cipher_snow_test_case_1),
13642 		TEST_CASE_ST(ut_setup, ut_teardown,
13643 			test_verify_auth_null_cipher_snow_test_case_1),
13644 		/** AUTH NULL + CIPHER ZUC */
13645 		TEST_CASE_ST(ut_setup, ut_teardown,
13646 			test_auth_null_cipher_zuc_test_case_1),
13647 		TEST_CASE_ST(ut_setup, ut_teardown,
13648 			test_verify_auth_null_cipher_zuc_test_case_1),
13649 		/** AUTH SNOW3G + CIPHER NULL */
13650 		TEST_CASE_ST(ut_setup, ut_teardown,
13651 			test_auth_snow_cipher_null_test_case_1),
13652 		TEST_CASE_ST(ut_setup, ut_teardown,
13653 			test_verify_auth_snow_cipher_null_test_case_1),
13654 		/** AUTH ZUC + CIPHER NULL */
13655 		TEST_CASE_ST(ut_setup, ut_teardown,
13656 			test_auth_zuc_cipher_null_test_case_1),
13657 		TEST_CASE_ST(ut_setup, ut_teardown,
13658 			test_verify_auth_zuc_cipher_null_test_case_1),
13659 		/** AUTH NULL + CIPHER AES CTR */
13660 		TEST_CASE_ST(ut_setup, ut_teardown,
13661 			test_auth_null_cipher_aes_ctr_test_case_1),
13662 		TEST_CASE_ST(ut_setup, ut_teardown,
13663 			test_verify_auth_null_cipher_aes_ctr_test_case_1),
13664 		/** AUTH AES CMAC + CIPHER NULL */
13665 		TEST_CASE_ST(ut_setup, ut_teardown,
13666 			test_auth_aes_cmac_cipher_null_test_case_1),
13667 		TEST_CASE_ST(ut_setup, ut_teardown,
13668 			test_verify_auth_aes_cmac_cipher_null_test_case_1),
13669 
13670 #ifdef RTE_LIB_SECURITY
13671 		TEST_CASE_ST(ut_setup_security, ut_teardown,
13672 			test_PDCP_PROTO_all),
13673 		TEST_CASE_ST(ut_setup_security, ut_teardown,
13674 			test_DOCSIS_PROTO_all),
13675 #endif
13676 		TEST_CASES_END() /**< NULL terminate unit test array */
13677 	}
13678 };
13679 
13680 static struct unit_test_suite cryptodev_virtio_testsuite = {
13681 	.suite_name = "Crypto VIRTIO Unit Test Suite",
13682 	.setup = testsuite_setup,
13683 	.teardown = testsuite_teardown,
13684 	.unit_test_cases = {
13685 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13686 
13687 		TEST_CASES_END() /**< NULL terminate unit test array */
13688 	}
13689 };
13690 
13691 static struct unit_test_suite cryptodev_caam_jr_testsuite  = {
13692 	.suite_name = "Crypto CAAM JR Unit Test Suite",
13693 	.setup = testsuite_setup,
13694 	.teardown = testsuite_teardown,
13695 	.unit_test_cases = {
13696 		TEST_CASE_ST(ut_setup, ut_teardown,
13697 			     test_device_configure_invalid_dev_id),
13698 		TEST_CASE_ST(ut_setup, ut_teardown,
13699 			     test_multi_session),
13700 
13701 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13702 		TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13703 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13704 		TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13705 		TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13706 
13707 		TEST_CASES_END() /**< NULL terminate unit test array */
13708 	}
13709 };
13710 
13711 static struct unit_test_suite cryptodev_mrvl_testsuite  = {
13712 	.suite_name = "Crypto Device Marvell Component Test Suite",
13713 	.setup = testsuite_setup,
13714 	.teardown = testsuite_teardown,
13715 	.unit_test_cases = {
13716 		TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
13717 		TEST_CASE_ST(ut_setup, ut_teardown,
13718 				test_multi_session_random_usage),
13719 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13720 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13721 		TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13722 		TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13723 		TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13724 
13725 		/** Negative tests */
13726 		TEST_CASE_ST(ut_setup, ut_teardown,
13727 			authentication_verify_HMAC_SHA1_fail_data_corrupt),
13728 		TEST_CASE_ST(ut_setup, ut_teardown,
13729 			authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13730 		TEST_CASE_ST(ut_setup, ut_teardown,
13731 			auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13732 		TEST_CASE_ST(ut_setup, ut_teardown,
13733 			auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13734 
13735 		TEST_CASES_END() /**< NULL terminate unit test array */
13736 	}
13737 };
13738 
13739 static struct unit_test_suite cryptodev_ccp_testsuite  = {
13740 	.suite_name = "Crypto Device CCP Unit Test Suite",
13741 	.setup = testsuite_setup,
13742 	.teardown = testsuite_teardown,
13743 	.unit_test_cases = {
13744 		TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
13745 		TEST_CASE_ST(ut_setup, ut_teardown,
13746 				test_multi_session_random_usage),
13747 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13748 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13749 		TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13750 		TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13751 		TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13752 
13753 		/** Negative tests */
13754 		TEST_CASE_ST(ut_setup, ut_teardown,
13755 			authentication_verify_HMAC_SHA1_fail_data_corrupt),
13756 		TEST_CASE_ST(ut_setup, ut_teardown,
13757 			authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13758 		TEST_CASE_ST(ut_setup, ut_teardown,
13759 			auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13760 		TEST_CASE_ST(ut_setup, ut_teardown,
13761 			auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13762 
13763 		TEST_CASES_END() /**< NULL terminate unit test array */
13764 	}
13765 };
13766 
13767 static int
13768 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
13769 {
13770 	gbl_driver_id =	rte_cryptodev_driver_id_get(
13771 			RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
13772 
13773 	if (gbl_driver_id == -1) {
13774 		RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n");
13775 		return TEST_SKIPPED;
13776 	}
13777 
13778 	return unit_test_suite_runner(&cryptodev_testsuite);
13779 }
13780 
13781 static int
13782 test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/)
13783 {
13784 	gbl_driver_id =	rte_cryptodev_driver_id_get(
13785 			RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
13786 
13787 	if (gbl_driver_id == -1) {
13788 		RTE_LOG(ERR, USER1, "VIRTIO PMD must be loaded.\n");
13789 		return TEST_FAILED;
13790 	}
13791 
13792 	return unit_test_suite_runner(&cryptodev_virtio_testsuite);
13793 }
13794 
13795 static int
13796 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
13797 {
13798 	gbl_driver_id =	rte_cryptodev_driver_id_get(
13799 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13800 
13801 	if (gbl_driver_id == -1) {
13802 		RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
13803 		return TEST_SKIPPED;
13804 	}
13805 
13806 	return unit_test_suite_runner(&cryptodev_testsuite);
13807 }
13808 
13809 static int
13810 test_cryptodev_cpu_aesni_mb(void)
13811 {
13812 	int32_t rc;
13813 	enum rte_security_session_action_type at;
13814 
13815 	gbl_driver_id =	rte_cryptodev_driver_id_get(
13816 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13817 
13818 	if (gbl_driver_id == -1) {
13819 		RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
13820 		return TEST_SKIPPED;
13821 	}
13822 
13823 	at = gbl_action_type;
13824 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
13825 	rc = unit_test_suite_runner(&cryptodev_testsuite);
13826 	gbl_action_type = at;
13827 	return rc;
13828 }
13829 
13830 static int
13831 test_cryptodev_openssl(void)
13832 {
13833 	gbl_driver_id = rte_cryptodev_driver_id_get(
13834 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
13835 
13836 	if (gbl_driver_id == -1) {
13837 		RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded.\n");
13838 		return TEST_SKIPPED;
13839 	}
13840 
13841 	return unit_test_suite_runner(&cryptodev_testsuite);
13842 }
13843 
13844 static int
13845 test_cryptodev_aesni_gcm(void)
13846 {
13847 	gbl_driver_id = rte_cryptodev_driver_id_get(
13848 			RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
13849 
13850 	if (gbl_driver_id == -1) {
13851 		RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded.\n");
13852 		return TEST_SKIPPED;
13853 	}
13854 
13855 	return unit_test_suite_runner(&cryptodev_testsuite);
13856 }
13857 
13858 static int
13859 test_cryptodev_cpu_aesni_gcm(void)
13860 {
13861 	int32_t rc;
13862 	enum rte_security_session_action_type at;
13863 
13864 	gbl_driver_id = rte_cryptodev_driver_id_get(
13865 			RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
13866 
13867 	if (gbl_driver_id == -1) {
13868 		RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded.\n");
13869 		return TEST_SKIPPED;
13870 	}
13871 
13872 	at = gbl_action_type;
13873 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
13874 	rc = unit_test_suite_runner(&cryptodev_testsuite);
13875 	gbl_action_type = at;
13876 	return rc;
13877 }
13878 
13879 static int
13880 test_cryptodev_null(void)
13881 {
13882 	gbl_driver_id = rte_cryptodev_driver_id_get(
13883 			RTE_STR(CRYPTODEV_NAME_NULL_PMD));
13884 
13885 	if (gbl_driver_id == -1) {
13886 		RTE_LOG(ERR, USER1, "NULL PMD must be loaded.\n");
13887 		return TEST_SKIPPED;
13888 	}
13889 
13890 	return unit_test_suite_runner(&cryptodev_testsuite);
13891 }
13892 
13893 static int
13894 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
13895 {
13896 	gbl_driver_id = rte_cryptodev_driver_id_get(
13897 			RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
13898 
13899 	if (gbl_driver_id == -1) {
13900 		RTE_LOG(ERR, USER1, "SNOW3G PMD must be loaded.\n");
13901 		return TEST_SKIPPED;
13902 	}
13903 
13904 	return unit_test_suite_runner(&cryptodev_testsuite);
13905 }
13906 
13907 static int
13908 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
13909 {
13910 	gbl_driver_id = rte_cryptodev_driver_id_get(
13911 			RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
13912 
13913 	if (gbl_driver_id == -1) {
13914 		RTE_LOG(ERR, USER1, "ZUC PMD must be loaded.\n");
13915 		return TEST_SKIPPED;
13916 	}
13917 
13918 	return unit_test_suite_runner(&cryptodev_testsuite);
13919 }
13920 
13921 static int
13922 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
13923 {
13924 	gbl_driver_id = rte_cryptodev_driver_id_get(
13925 			RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
13926 
13927 	if (gbl_driver_id == -1) {
13928 		RTE_LOG(ERR, USER1, "ZUC PMD must be loaded.\n");
13929 		return TEST_SKIPPED;
13930 	}
13931 
13932 	return unit_test_suite_runner(&cryptodev_testsuite);
13933 }
13934 
13935 static int
13936 test_cryptodev_armv8(void)
13937 {
13938 	gbl_driver_id = rte_cryptodev_driver_id_get(
13939 			RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
13940 
13941 	if (gbl_driver_id == -1) {
13942 		RTE_LOG(ERR, USER1, "ARMV8 PMD must be loaded.\n");
13943 		return TEST_SKIPPED;
13944 	}
13945 
13946 	return unit_test_suite_runner(&cryptodev_testsuite);
13947 }
13948 
13949 static int
13950 test_cryptodev_mrvl(void)
13951 {
13952 	gbl_driver_id = rte_cryptodev_driver_id_get(
13953 			RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
13954 
13955 	if (gbl_driver_id == -1) {
13956 		RTE_LOG(ERR, USER1, "MVSAM PMD must be loaded.\n");
13957 		return TEST_SKIPPED;
13958 	}
13959 
13960 	return unit_test_suite_runner(&cryptodev_mrvl_testsuite);
13961 }
13962 
13963 #ifdef RTE_CRYPTO_SCHEDULER
13964 
13965 static int
13966 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/)
13967 {
13968 	gbl_driver_id =	rte_cryptodev_driver_id_get(
13969 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
13970 
13971 	if (gbl_driver_id == -1) {
13972 		RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
13973 		return TEST_SKIPPED;
13974 	}
13975 
13976 	if (rte_cryptodev_driver_id_get(
13977 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
13978 		RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
13979 		return TEST_SKIPPED;
13980 }
13981 	return unit_test_suite_runner(&cryptodev_scheduler_testsuite);
13982 }
13983 
13984 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
13985 
13986 #endif
13987 
13988 static int
13989 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/)
13990 {
13991 	gbl_driver_id =	rte_cryptodev_driver_id_get(
13992 			RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
13993 
13994 	if (gbl_driver_id == -1) {
13995 		RTE_LOG(ERR, USER1, "DPAA2 SEC PMD must be loaded.\n");
13996 		return TEST_SKIPPED;
13997 	}
13998 
13999 	return unit_test_suite_runner(&cryptodev_testsuite);
14000 }
14001 
14002 static int
14003 test_cryptodev_dpaa_sec(void /*argv __rte_unused, int argc __rte_unused*/)
14004 {
14005 	gbl_driver_id =	rte_cryptodev_driver_id_get(
14006 			RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
14007 
14008 	if (gbl_driver_id == -1) {
14009 		RTE_LOG(ERR, USER1, "DPAA SEC PMD must be loaded.\n");
14010 		return TEST_SKIPPED;
14011 	}
14012 
14013 	return unit_test_suite_runner(&cryptodev_testsuite);
14014 }
14015 
14016 static int
14017 test_cryptodev_ccp(void)
14018 {
14019 	gbl_driver_id = rte_cryptodev_driver_id_get(
14020 			RTE_STR(CRYPTODEV_NAME_CCP_PMD));
14021 
14022 	if (gbl_driver_id == -1) {
14023 		RTE_LOG(ERR, USER1, "CCP PMD must be loaded.\n");
14024 		return TEST_FAILED;
14025 	}
14026 
14027 	return unit_test_suite_runner(&cryptodev_ccp_testsuite);
14028 }
14029 
14030 static int
14031 test_cryptodev_octeontx(void)
14032 {
14033 	gbl_driver_id =	rte_cryptodev_driver_id_get(
14034 			RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
14035 	if (gbl_driver_id == -1) {
14036 		RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded.\n");
14037 		return TEST_FAILED;
14038 	}
14039 	return unit_test_suite_runner(&cryptodev_testsuite);
14040 }
14041 
14042 static int
14043 test_cryptodev_octeontx2(void)
14044 {
14045 	gbl_driver_id =	rte_cryptodev_driver_id_get(
14046 			RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
14047 	if (gbl_driver_id == -1) {
14048 		RTE_LOG(ERR, USER1, "OCTEON TX2 PMD must be loaded.\n");
14049 		return TEST_FAILED;
14050 	}
14051 	return unit_test_suite_runner(&cryptodev_testsuite);
14052 }
14053 
14054 static int
14055 test_cryptodev_caam_jr(void /*argv __rte_unused, int argc __rte_unused*/)
14056 {
14057 	gbl_driver_id =	rte_cryptodev_driver_id_get(
14058 			RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
14059 
14060 	if (gbl_driver_id == -1) {
14061 		RTE_LOG(ERR, USER1, "CAAM_JR PMD must be loaded.\n");
14062 		return TEST_FAILED;
14063 	}
14064 
14065 	return unit_test_suite_runner(&cryptodev_caam_jr_testsuite);
14066 }
14067 
14068 static int
14069 test_cryptodev_nitrox(void)
14070 {
14071 	gbl_driver_id =	rte_cryptodev_driver_id_get(
14072 			RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
14073 
14074 	if (gbl_driver_id == -1) {
14075 		RTE_LOG(ERR, USER1, "NITROX PMD must be loaded.\n");
14076 		return TEST_FAILED;
14077 	}
14078 
14079 	return unit_test_suite_runner(&cryptodev_testsuite);
14080 }
14081 
14082 static int
14083 test_cryptodev_bcmfs(void)
14084 {
14085 	gbl_driver_id =	rte_cryptodev_driver_id_get(
14086 			RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
14087 
14088 	if (gbl_driver_id == -1) {
14089 		RTE_LOG(ERR, USER1, "BCMFS PMD must be loaded.\n");
14090 		return TEST_FAILED;
14091 	}
14092 
14093 	return unit_test_suite_runner(&cryptodev_testsuite);
14094 }
14095 
14096 static int
14097 test_cryptodev_qat_raw_api(void /*argv __rte_unused, int argc __rte_unused*/)
14098 {
14099 	int ret;
14100 
14101 	gbl_driver_id =	rte_cryptodev_driver_id_get(
14102 			RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
14103 
14104 	if (gbl_driver_id == -1) {
14105 		RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n");
14106 		return TEST_SKIPPED;
14107 	}
14108 
14109 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
14110 	ret = unit_test_suite_runner(&cryptodev_testsuite);
14111 	global_api_test_type = CRYPTODEV_API_TEST;
14112 
14113 	return ret;
14114 }
14115 
14116 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
14117 		test_cryptodev_qat_raw_api);
14118 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
14119 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
14120 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
14121 	test_cryptodev_cpu_aesni_mb);
14122 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
14123 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
14124 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
14125 	test_cryptodev_cpu_aesni_gcm);
14126 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
14127 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
14128 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
14129 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
14130 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
14131 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
14132 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
14133 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
14134 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
14135 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
14136 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
14137 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
14138 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
14139 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
14140 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);
14141