xref: /dpdk/app/test/test_cryptodev.c (revision e37bbe21)
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_LIBRTE_PMD_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_LIBRTE_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_LIBRTE_SECURITY
93 	struct rte_security_docsis_xform docsis_xform;
94 #endif
95 
96 	union {
97 		struct rte_cryptodev_sym_session *sess;
98 #ifdef RTE_LIBRTE_SECURITY
99 		struct rte_security_session *sec_session;
100 #endif
101 	};
102 #ifdef RTE_LIBRTE_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_LIBRTE_PMD_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_SLAVE(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_LIBRTE_PMD_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 	/*
786 	 * Create mempool with maximum number of sessions * 2,
787 	 * to include the session headers
788 	 */
789 	if (info.sym.max_nb_sessions != 0 &&
790 			info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
791 		RTE_LOG(ERR, USER1, "Device does not support "
792 				"at least %u sessions\n",
793 				MAX_NB_SESSIONS);
794 		return TEST_FAILED;
795 	}
796 
797 	ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
798 			"test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
799 			SOCKET_ID_ANY);
800 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
801 			"session mempool allocation failed");
802 
803 	ts_params->session_priv_mpool = rte_mempool_create(
804 			"test_sess_mp_priv",
805 			MAX_NB_SESSIONS,
806 			session_size,
807 			0, 0, NULL, NULL, NULL,
808 			NULL, SOCKET_ID_ANY,
809 			0);
810 	TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
811 			"session mempool allocation failed");
812 
813 
814 
815 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
816 			&ts_params->conf),
817 			"Failed to configure cryptodev %u with %u qps",
818 			dev_id, ts_params->conf.nb_queue_pairs);
819 
820 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
821 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
822 	ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
823 
824 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
825 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
826 			dev_id, qp_id, &ts_params->qp_conf,
827 			rte_cryptodev_socket_id(dev_id)),
828 			"Failed to setup queue pair %u on cryptodev %u",
829 			qp_id, dev_id);
830 	}
831 
832 	return TEST_SUCCESS;
833 }
834 
835 static void
836 testsuite_teardown(void)
837 {
838 	struct crypto_testsuite_params *ts_params = &testsuite_params;
839 
840 	if (ts_params->mbuf_pool != NULL) {
841 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
842 		rte_mempool_avail_count(ts_params->mbuf_pool));
843 	}
844 
845 	if (ts_params->op_mpool != NULL) {
846 		RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
847 		rte_mempool_avail_count(ts_params->op_mpool));
848 	}
849 
850 	/* Free session mempools */
851 	if (ts_params->session_priv_mpool != NULL) {
852 		rte_mempool_free(ts_params->session_priv_mpool);
853 		ts_params->session_priv_mpool = NULL;
854 	}
855 
856 	if (ts_params->session_mpool != NULL) {
857 		rte_mempool_free(ts_params->session_mpool);
858 		ts_params->session_mpool = NULL;
859 	}
860 }
861 
862 static int
863 dev_configure_and_start(uint64_t ff_disable)
864 {
865 	struct crypto_testsuite_params *ts_params = &testsuite_params;
866 	struct crypto_unittest_params *ut_params = &unittest_params;
867 
868 	uint16_t qp_id;
869 
870 	/* Clear unit test parameters before running test */
871 	memset(ut_params, 0, sizeof(*ut_params));
872 
873 	/* Reconfigure device to default parameters */
874 	ts_params->conf.socket_id = SOCKET_ID_ANY;
875 	ts_params->conf.ff_disable = ff_disable;
876 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
877 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
878 	ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
879 
880 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
881 			&ts_params->conf),
882 			"Failed to configure cryptodev %u",
883 			ts_params->valid_devs[0]);
884 
885 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
886 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
887 			ts_params->valid_devs[0], qp_id,
888 			&ts_params->qp_conf,
889 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
890 			"Failed to setup queue pair %u on cryptodev %u",
891 			qp_id, ts_params->valid_devs[0]);
892 	}
893 
894 
895 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
896 
897 	/* Start the device */
898 	TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
899 			"Failed to start cryptodev %u",
900 			ts_params->valid_devs[0]);
901 
902 	return TEST_SUCCESS;
903 }
904 
905 static int
906 ut_setup(void)
907 {
908 	/* Configure and start the device with security feature disabled */
909 	return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
910 }
911 
912 static int
913 ut_setup_security(void)
914 {
915 	/* Configure and start the device with no features disabled */
916 	return dev_configure_and_start(0);
917 }
918 
919 static void
920 ut_teardown(void)
921 {
922 	struct crypto_testsuite_params *ts_params = &testsuite_params;
923 	struct crypto_unittest_params *ut_params = &unittest_params;
924 	struct rte_cryptodev_stats stats;
925 
926 	/* free crypto session structure */
927 #ifdef RTE_LIBRTE_SECURITY
928 	if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
929 		if (ut_params->sec_session) {
930 			rte_security_session_destroy(rte_cryptodev_get_sec_ctx
931 						(ts_params->valid_devs[0]),
932 						ut_params->sec_session);
933 			ut_params->sec_session = NULL;
934 		}
935 	} else
936 #endif
937 	{
938 		if (ut_params->sess) {
939 			rte_cryptodev_sym_session_clear(
940 					ts_params->valid_devs[0],
941 					ut_params->sess);
942 			rte_cryptodev_sym_session_free(ut_params->sess);
943 			ut_params->sess = NULL;
944 		}
945 	}
946 
947 	/* free crypto operation structure */
948 	if (ut_params->op)
949 		rte_crypto_op_free(ut_params->op);
950 
951 	/*
952 	 * free mbuf - both obuf and ibuf are usually the same,
953 	 * so check if they point at the same address is necessary,
954 	 * to avoid freeing the mbuf twice.
955 	 */
956 	if (ut_params->obuf) {
957 		rte_pktmbuf_free(ut_params->obuf);
958 		if (ut_params->ibuf == ut_params->obuf)
959 			ut_params->ibuf = 0;
960 		ut_params->obuf = 0;
961 	}
962 	if (ut_params->ibuf) {
963 		rte_pktmbuf_free(ut_params->ibuf);
964 		ut_params->ibuf = 0;
965 	}
966 
967 	if (ts_params->mbuf_pool != NULL)
968 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
969 			rte_mempool_avail_count(ts_params->mbuf_pool));
970 
971 	rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
972 
973 	/* Stop the device */
974 	rte_cryptodev_stop(ts_params->valid_devs[0]);
975 }
976 
977 static int
978 test_device_configure_invalid_dev_id(void)
979 {
980 	struct crypto_testsuite_params *ts_params = &testsuite_params;
981 	uint16_t dev_id, num_devs = 0;
982 
983 	TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
984 			"Need at least %d devices for test", 1);
985 
986 	/* valid dev_id values */
987 	dev_id = ts_params->valid_devs[0];
988 
989 	/* Stop the device in case it's started so it can be configured */
990 	rte_cryptodev_stop(dev_id);
991 
992 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
993 			"Failed test for rte_cryptodev_configure: "
994 			"invalid dev_num %u", dev_id);
995 
996 	/* invalid dev_id values */
997 	dev_id = num_devs;
998 
999 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1000 			"Failed test for rte_cryptodev_configure: "
1001 			"invalid dev_num %u", dev_id);
1002 
1003 	dev_id = 0xff;
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 	return TEST_SUCCESS;
1010 }
1011 
1012 static int
1013 test_device_configure_invalid_queue_pair_ids(void)
1014 {
1015 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1016 	uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1017 
1018 	/* Stop the device in case it's started so it can be configured */
1019 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1020 
1021 	/* valid - max value queue pairs */
1022 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1023 
1024 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1025 			&ts_params->conf),
1026 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1027 			ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1028 
1029 	/* valid - one queue pairs */
1030 	ts_params->conf.nb_queue_pairs = 1;
1031 
1032 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1033 			&ts_params->conf),
1034 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1035 			ts_params->valid_devs[0],
1036 			ts_params->conf.nb_queue_pairs);
1037 
1038 
1039 	/* invalid - zero queue pairs */
1040 	ts_params->conf.nb_queue_pairs = 0;
1041 
1042 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1043 			&ts_params->conf),
1044 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1045 			" invalid qps: %u",
1046 			ts_params->valid_devs[0],
1047 			ts_params->conf.nb_queue_pairs);
1048 
1049 
1050 	/* invalid - max value supported by field queue pairs */
1051 	ts_params->conf.nb_queue_pairs = UINT16_MAX;
1052 
1053 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1054 			&ts_params->conf),
1055 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1056 			" invalid qps: %u",
1057 			ts_params->valid_devs[0],
1058 			ts_params->conf.nb_queue_pairs);
1059 
1060 
1061 	/* invalid - max value + 1 queue pairs */
1062 	ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1063 
1064 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1065 			&ts_params->conf),
1066 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1067 			" invalid qps: %u",
1068 			ts_params->valid_devs[0],
1069 			ts_params->conf.nb_queue_pairs);
1070 
1071 	/* revert to original testsuite value */
1072 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1073 
1074 	return TEST_SUCCESS;
1075 }
1076 
1077 static int
1078 test_queue_pair_descriptor_setup(void)
1079 {
1080 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1081 	struct rte_cryptodev_qp_conf qp_conf = {
1082 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
1083 	};
1084 	uint16_t qp_id;
1085 
1086 	/* Stop the device in case it's started so it can be configured */
1087 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1088 
1089 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1090 			&ts_params->conf),
1091 			"Failed to configure cryptodev %u",
1092 			ts_params->valid_devs[0]);
1093 
1094 	/*
1095 	 * Test various ring sizes on this device. memzones can't be
1096 	 * freed so are re-used if ring is released and re-created.
1097 	 */
1098 	qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1099 	qp_conf.mp_session = ts_params->session_mpool;
1100 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
1101 
1102 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1103 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1104 				ts_params->valid_devs[0], qp_id, &qp_conf,
1105 				rte_cryptodev_socket_id(
1106 						ts_params->valid_devs[0])),
1107 				"Failed test for "
1108 				"rte_cryptodev_queue_pair_setup: num_inflights "
1109 				"%u on qp %u on cryptodev %u",
1110 				qp_conf.nb_descriptors, qp_id,
1111 				ts_params->valid_devs[0]);
1112 	}
1113 
1114 	qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1115 
1116 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1117 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1118 				ts_params->valid_devs[0], qp_id, &qp_conf,
1119 				rte_cryptodev_socket_id(
1120 						ts_params->valid_devs[0])),
1121 				"Failed test for"
1122 				" rte_cryptodev_queue_pair_setup: num_inflights"
1123 				" %u on qp %u on cryptodev %u",
1124 				qp_conf.nb_descriptors, qp_id,
1125 				ts_params->valid_devs[0]);
1126 	}
1127 
1128 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
1129 
1130 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1131 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1132 				ts_params->valid_devs[0], qp_id, &qp_conf,
1133 				rte_cryptodev_socket_id(
1134 						ts_params->valid_devs[0])),
1135 				"Failed test for "
1136 				"rte_cryptodev_queue_pair_setup: num_inflights"
1137 				" %u on qp %u on cryptodev %u",
1138 				qp_conf.nb_descriptors, qp_id,
1139 				ts_params->valid_devs[0]);
1140 	}
1141 
1142 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1143 
1144 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1145 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1146 				ts_params->valid_devs[0], qp_id, &qp_conf,
1147 				rte_cryptodev_socket_id(
1148 						ts_params->valid_devs[0])),
1149 				"Failed test for"
1150 				" rte_cryptodev_queue_pair_setup:"
1151 				"num_inflights %u on qp %u on cryptodev %u",
1152 				qp_conf.nb_descriptors, qp_id,
1153 				ts_params->valid_devs[0]);
1154 	}
1155 
1156 	/* test invalid queue pair id */
1157 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;	/*valid */
1158 
1159 	qp_id = ts_params->conf.nb_queue_pairs;		/*invalid */
1160 
1161 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1162 			ts_params->valid_devs[0],
1163 			qp_id, &qp_conf,
1164 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1165 			"Failed test for rte_cryptodev_queue_pair_setup:"
1166 			"invalid qp %u on cryptodev %u",
1167 			qp_id, ts_params->valid_devs[0]);
1168 
1169 	qp_id = 0xffff; /*invalid*/
1170 
1171 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1172 			ts_params->valid_devs[0],
1173 			qp_id, &qp_conf,
1174 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1175 			"Failed test for rte_cryptodev_queue_pair_setup:"
1176 			"invalid qp %u on cryptodev %u",
1177 			qp_id, ts_params->valid_devs[0]);
1178 
1179 	return TEST_SUCCESS;
1180 }
1181 
1182 /* ***** Plaintext data for tests ***** */
1183 
1184 const char catch_22_quote_1[] =
1185 		"There was only one catch and that was Catch-22, which "
1186 		"specified that a concern for one's safety in the face of "
1187 		"dangers that were real and immediate was the process of a "
1188 		"rational mind. Orr was crazy and could be grounded. All he "
1189 		"had to do was ask; and as soon as he did, he would no longer "
1190 		"be crazy and would have to fly more missions. Orr would be "
1191 		"crazy to fly more missions and sane if he didn't, but if he "
1192 		"was sane he had to fly them. If he flew them he was crazy "
1193 		"and didn't have to; but if he didn't want to he was sane and "
1194 		"had to. Yossarian was moved very deeply by the absolute "
1195 		"simplicity of this clause of Catch-22 and let out a "
1196 		"respectful whistle. \"That's some catch, that Catch-22\", he "
1197 		"observed. \"It's the best there is,\" Doc Daneeka agreed.";
1198 
1199 const char catch_22_quote[] =
1200 		"What a lousy earth! He wondered how many people were "
1201 		"destitute that same night even in his own prosperous country, "
1202 		"how many homes were shanties, how many husbands were drunk "
1203 		"and wives socked, and how many children were bullied, abused, "
1204 		"or abandoned. How many families hungered for food they could "
1205 		"not afford to buy? How many hearts were broken? How many "
1206 		"suicides would take place that same night, how many people "
1207 		"would go insane? How many cockroaches and landlords would "
1208 		"triumph? How many winners were losers, successes failures, "
1209 		"and rich men poor men? How many wise guys were stupid? How "
1210 		"many happy endings were unhappy endings? How many honest men "
1211 		"were liars, brave men cowards, loyal men traitors, how many "
1212 		"sainted men were corrupt, how many people in positions of "
1213 		"trust had sold their souls to bodyguards, how many had never "
1214 		"had souls? How many straight-and-narrow paths were crooked "
1215 		"paths? How many best families were worst families and how "
1216 		"many good people were bad people? When you added them all up "
1217 		"and then subtracted, you might be left with only the children, "
1218 		"and perhaps with Albert Einstein and an old violinist or "
1219 		"sculptor somewhere.";
1220 
1221 #define QUOTE_480_BYTES		(480)
1222 #define QUOTE_512_BYTES		(512)
1223 #define QUOTE_768_BYTES		(768)
1224 #define QUOTE_1024_BYTES	(1024)
1225 
1226 
1227 
1228 /* ***** SHA1 Hash Tests ***** */
1229 
1230 #define HMAC_KEY_LENGTH_SHA1	(DIGEST_BYTE_LENGTH_SHA1)
1231 
1232 static uint8_t hmac_sha1_key[] = {
1233 	0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1234 	0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1235 	0xDE, 0xF4, 0xDE, 0xAD };
1236 
1237 /* ***** SHA224 Hash Tests ***** */
1238 
1239 #define HMAC_KEY_LENGTH_SHA224	(DIGEST_BYTE_LENGTH_SHA224)
1240 
1241 
1242 /* ***** AES-CBC Cipher Tests ***** */
1243 
1244 #define CIPHER_KEY_LENGTH_AES_CBC	(16)
1245 #define CIPHER_IV_LENGTH_AES_CBC	(CIPHER_KEY_LENGTH_AES_CBC)
1246 
1247 static uint8_t aes_cbc_key[] = {
1248 	0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1249 	0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1250 
1251 static uint8_t aes_cbc_iv[] = {
1252 	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1253 	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1254 
1255 
1256 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1257 
1258 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1259 	0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1260 	0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1261 	0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1262 	0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1263 	0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1264 	0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1265 	0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1266 	0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1267 	0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1268 	0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1269 	0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1270 	0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1271 	0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1272 	0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1273 	0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1274 	0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1275 	0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1276 	0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1277 	0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1278 	0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1279 	0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1280 	0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1281 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1282 	0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1283 	0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1284 	0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1285 	0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1286 	0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1287 	0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1288 	0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1289 	0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1290 	0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1291 	0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1292 	0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1293 	0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1294 	0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1295 	0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1296 	0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1297 	0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1298 	0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1299 	0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1300 	0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1301 	0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1302 	0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1303 	0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1304 	0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1305 	0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1306 	0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1307 	0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1308 	0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1309 	0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1310 	0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1311 	0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1312 	0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1313 	0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1314 	0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1315 	0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1316 	0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1317 	0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1318 	0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1319 	0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1320 	0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1321 	0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1322 	0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1323 };
1324 
1325 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1326 	0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1327 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1328 	0x18, 0x8c, 0x1d, 0x32
1329 };
1330 
1331 
1332 /* Multisession Vector context Test */
1333 /*Begin Session 0 */
1334 static uint8_t ms_aes_cbc_key0[] = {
1335 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1336 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1337 };
1338 
1339 static uint8_t ms_aes_cbc_iv0[] = {
1340 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1341 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1342 };
1343 
1344 static const uint8_t ms_aes_cbc_cipher0[] = {
1345 		0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1346 		0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1347 		0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1348 		0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1349 		0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1350 		0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1351 		0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1352 		0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1353 		0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1354 		0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1355 		0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1356 		0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1357 		0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1358 		0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1359 		0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1360 		0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1361 		0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1362 		0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1363 		0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1364 		0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1365 		0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1366 		0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1367 		0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1368 		0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1369 		0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1370 		0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1371 		0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1372 		0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1373 		0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1374 		0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1375 		0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1376 		0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1377 		0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1378 		0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1379 		0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1380 		0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1381 		0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1382 		0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1383 		0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1384 		0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1385 		0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1386 		0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1387 		0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1388 		0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1389 		0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1390 		0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1391 		0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1392 		0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1393 		0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1394 		0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1395 		0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1396 		0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1397 		0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1398 		0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1399 		0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1400 		0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1401 		0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1402 		0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1403 		0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1404 		0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1405 		0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1406 		0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1407 		0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1408 		0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1409 };
1410 
1411 
1412 static  uint8_t ms_hmac_key0[] = {
1413 		0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1414 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1415 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1416 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1417 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1418 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1419 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1420 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1421 };
1422 
1423 static const uint8_t ms_hmac_digest0[] = {
1424 		0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1425 		0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1426 		0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1427 		0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1428 		0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1429 		0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1430 		0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1431 		0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1432 		};
1433 
1434 /* End Session 0 */
1435 /* Begin session 1 */
1436 
1437 static  uint8_t ms_aes_cbc_key1[] = {
1438 		0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1439 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1440 };
1441 
1442 static  uint8_t ms_aes_cbc_iv1[] = {
1443 	0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1444 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1445 };
1446 
1447 static const uint8_t ms_aes_cbc_cipher1[] = {
1448 		0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1449 		0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1450 		0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1451 		0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1452 		0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1453 		0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1454 		0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1455 		0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1456 		0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1457 		0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1458 		0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1459 		0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1460 		0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1461 		0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1462 		0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1463 		0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1464 		0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1465 		0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1466 		0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1467 		0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1468 		0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1469 		0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1470 		0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1471 		0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1472 		0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1473 		0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1474 		0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1475 		0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1476 		0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1477 		0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1478 		0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1479 		0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1480 		0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1481 		0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1482 		0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1483 		0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1484 		0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1485 		0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1486 		0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1487 		0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1488 		0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1489 		0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1490 		0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1491 		0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1492 		0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1493 		0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1494 		0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1495 		0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1496 		0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1497 		0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1498 		0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1499 		0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1500 		0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1501 		0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1502 		0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1503 		0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1504 		0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1505 		0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1506 		0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1507 		0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1508 		0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1509 		0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1510 		0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1511 		0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1512 
1513 };
1514 
1515 static uint8_t ms_hmac_key1[] = {
1516 		0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1517 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1518 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1519 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1520 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1521 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1522 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1523 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1524 };
1525 
1526 static const uint8_t ms_hmac_digest1[] = {
1527 		0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1528 		0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
1529 		0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
1530 		0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
1531 		0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
1532 		0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
1533 		0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
1534 		0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
1535 };
1536 /* End Session 1  */
1537 /* Begin Session 2 */
1538 static  uint8_t ms_aes_cbc_key2[] = {
1539 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1540 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1541 };
1542 
1543 static  uint8_t ms_aes_cbc_iv2[] = {
1544 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1545 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1546 };
1547 
1548 static const uint8_t ms_aes_cbc_cipher2[] = {
1549 		0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
1550 		0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
1551 		0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
1552 		0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
1553 		0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
1554 		0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
1555 		0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
1556 		0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
1557 		0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
1558 		0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
1559 		0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
1560 		0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
1561 		0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
1562 		0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
1563 		0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
1564 		0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
1565 		0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
1566 		0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
1567 		0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
1568 		0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
1569 		0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
1570 		0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
1571 		0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
1572 		0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
1573 		0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
1574 		0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
1575 		0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
1576 		0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
1577 		0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
1578 		0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
1579 		0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
1580 		0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
1581 		0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
1582 		0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
1583 		0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
1584 		0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
1585 		0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
1586 		0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
1587 		0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
1588 		0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
1589 		0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
1590 		0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
1591 		0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
1592 		0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
1593 		0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
1594 		0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
1595 		0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
1596 		0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
1597 		0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
1598 		0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
1599 		0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
1600 		0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
1601 		0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
1602 		0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
1603 		0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
1604 		0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
1605 		0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
1606 		0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
1607 		0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
1608 		0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
1609 		0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
1610 		0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
1611 		0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
1612 		0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
1613 };
1614 
1615 static  uint8_t ms_hmac_key2[] = {
1616 		0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1617 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1618 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1619 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1620 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1621 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1622 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1623 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1624 };
1625 
1626 static const uint8_t ms_hmac_digest2[] = {
1627 		0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
1628 		0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
1629 		0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
1630 		0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
1631 		0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
1632 		0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
1633 		0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
1634 		0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
1635 };
1636 
1637 /* End Session 2 */
1638 
1639 
1640 static int
1641 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
1642 {
1643 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1644 	struct crypto_unittest_params *ut_params = &unittest_params;
1645 
1646 	/* Verify the capabilities */
1647 	struct rte_cryptodev_sym_capability_idx cap_idx;
1648 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1649 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
1650 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
1651 			&cap_idx) == NULL)
1652 		return -ENOTSUP;
1653 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1654 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
1655 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
1656 			&cap_idx) == NULL)
1657 		return -ENOTSUP;
1658 
1659 	/* Generate test mbuf data and space for digest */
1660 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1661 			catch_22_quote,	QUOTE_512_BYTES, 0);
1662 
1663 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1664 			DIGEST_BYTE_LENGTH_SHA1);
1665 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1666 
1667 	/* Setup Cipher Parameters */
1668 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1669 	ut_params->cipher_xform.next = &ut_params->auth_xform;
1670 
1671 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1672 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1673 	ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1674 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1675 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
1676 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1677 
1678 	/* Setup HMAC Parameters */
1679 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1680 
1681 	ut_params->auth_xform.next = NULL;
1682 
1683 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1684 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1685 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
1686 	ut_params->auth_xform.auth.key.data = hmac_sha1_key;
1687 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
1688 
1689 	ut_params->sess = rte_cryptodev_sym_session_create(
1690 			ts_params->session_mpool);
1691 
1692 	/* Create crypto session*/
1693 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
1694 			ut_params->sess, &ut_params->cipher_xform,
1695 			ts_params->session_priv_mpool);
1696 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1697 
1698 	/* Generate crypto op data structure */
1699 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1700 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1701 	TEST_ASSERT_NOT_NULL(ut_params->op,
1702 			"Failed to allocate symmetric crypto operation struct");
1703 
1704 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1705 
1706 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1707 
1708 	/* set crypto operation source mbuf */
1709 	sym_op->m_src = ut_params->ibuf;
1710 
1711 	/* Set crypto operation authentication parameters */
1712 	sym_op->auth.digest.data = ut_params->digest;
1713 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
1714 			ut_params->ibuf, QUOTE_512_BYTES);
1715 
1716 	sym_op->auth.data.offset = 0;
1717 	sym_op->auth.data.length = QUOTE_512_BYTES;
1718 
1719 	/* Copy IV at the end of the crypto operation */
1720 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
1721 			aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
1722 
1723 	/* Set crypto operation cipher parameters */
1724 	sym_op->cipher.data.offset = 0;
1725 	sym_op->cipher.data.length = QUOTE_512_BYTES;
1726 
1727 	/* Process crypto operation */
1728 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
1729 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
1730 			ut_params->op);
1731 	else
1732 		TEST_ASSERT_NOT_NULL(
1733 			process_crypto_request(ts_params->valid_devs[0],
1734 				ut_params->op),
1735 				"failed to process sym crypto op");
1736 
1737 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1738 			"crypto op processing failed");
1739 
1740 	/* Validate obuf */
1741 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
1742 			uint8_t *);
1743 
1744 	TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
1745 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1746 			QUOTE_512_BYTES,
1747 			"ciphertext data not as expected");
1748 
1749 	uint8_t *digest = ciphertext + QUOTE_512_BYTES;
1750 
1751 	TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
1752 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1753 			gbl_driver_id == rte_cryptodev_driver_id_get(
1754 					RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
1755 					TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
1756 					DIGEST_BYTE_LENGTH_SHA1,
1757 			"Generated digest data not as expected");
1758 
1759 	return TEST_SUCCESS;
1760 }
1761 
1762 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1763 
1764 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
1765 
1766 static uint8_t hmac_sha512_key[] = {
1767 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1768 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1769 	0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1770 	0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1771 	0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1772 	0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1773 	0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1774 	0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1775 
1776 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1777 	0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1778 	0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1779 	0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1780 	0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1781 	0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1782 	0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1783 	0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1784 	0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1785 
1786 
1787 
1788 static int
1789 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1790 		struct crypto_unittest_params *ut_params,
1791 		uint8_t *cipher_key,
1792 		uint8_t *hmac_key);
1793 
1794 static int
1795 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1796 		struct crypto_unittest_params *ut_params,
1797 		struct crypto_testsuite_params *ts_params,
1798 		const uint8_t *cipher,
1799 		const uint8_t *digest,
1800 		const uint8_t *iv);
1801 
1802 
1803 static int
1804 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1805 		struct crypto_unittest_params *ut_params,
1806 		uint8_t *cipher_key,
1807 		uint8_t *hmac_key)
1808 {
1809 
1810 	/* Setup Cipher Parameters */
1811 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1812 	ut_params->cipher_xform.next = NULL;
1813 
1814 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1815 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1816 	ut_params->cipher_xform.cipher.key.data = cipher_key;
1817 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1818 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
1819 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1820 
1821 	/* Setup HMAC Parameters */
1822 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1823 	ut_params->auth_xform.next = &ut_params->cipher_xform;
1824 
1825 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1826 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1827 	ut_params->auth_xform.auth.key.data = hmac_key;
1828 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1829 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1830 
1831 	return TEST_SUCCESS;
1832 }
1833 
1834 
1835 static int
1836 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1837 		struct crypto_unittest_params *ut_params,
1838 		struct crypto_testsuite_params *ts_params,
1839 		const uint8_t *cipher,
1840 		const uint8_t *digest,
1841 		const uint8_t *iv)
1842 {
1843 	/* Generate test mbuf data and digest */
1844 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1845 			(const char *)
1846 			cipher,
1847 			QUOTE_512_BYTES, 0);
1848 
1849 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1850 			DIGEST_BYTE_LENGTH_SHA512);
1851 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1852 
1853 	rte_memcpy(ut_params->digest,
1854 			digest,
1855 			DIGEST_BYTE_LENGTH_SHA512);
1856 
1857 	/* Generate Crypto op data structure */
1858 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1859 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1860 	TEST_ASSERT_NOT_NULL(ut_params->op,
1861 			"Failed to allocate symmetric crypto operation struct");
1862 
1863 	rte_crypto_op_attach_sym_session(ut_params->op, sess);
1864 
1865 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1866 
1867 	/* set crypto operation source mbuf */
1868 	sym_op->m_src = ut_params->ibuf;
1869 
1870 	sym_op->auth.digest.data = ut_params->digest;
1871 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
1872 			ut_params->ibuf, QUOTE_512_BYTES);
1873 
1874 	sym_op->auth.data.offset = 0;
1875 	sym_op->auth.data.length = QUOTE_512_BYTES;
1876 
1877 	/* Copy IV at the end of the crypto operation */
1878 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
1879 			iv, CIPHER_IV_LENGTH_AES_CBC);
1880 
1881 	sym_op->cipher.data.offset = 0;
1882 	sym_op->cipher.data.length = QUOTE_512_BYTES;
1883 
1884 	/* Process crypto operation */
1885 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
1886 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
1887 			ut_params->op);
1888 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
1889 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
1890 				ut_params->op, 1, 1, 0, 0);
1891 	else
1892 		TEST_ASSERT_NOT_NULL(
1893 				process_crypto_request(ts_params->valid_devs[0],
1894 					ut_params->op),
1895 					"failed to process sym crypto op");
1896 
1897 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1898 			"crypto op processing failed");
1899 
1900 	ut_params->obuf = ut_params->op->sym->m_src;
1901 
1902 	/* Validate obuf */
1903 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
1904 			rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
1905 			catch_22_quote,
1906 			QUOTE_512_BYTES,
1907 			"Plaintext data not as expected");
1908 
1909 	/* Validate obuf */
1910 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1911 			"Digest verification failed");
1912 
1913 	return TEST_SUCCESS;
1914 }
1915 
1916 static int
1917 test_blockcipher(enum blockcipher_test_type test_type)
1918 {
1919 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1920 	int status;
1921 
1922 	status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1923 		ts_params->op_mpool,
1924 		ts_params->session_mpool, ts_params->session_priv_mpool,
1925 		ts_params->valid_devs[0],
1926 		test_type);
1927 
1928 	if (status == -ENOTSUP)
1929 		return status;
1930 
1931 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1932 
1933 	return TEST_SUCCESS;
1934 }
1935 
1936 static int
1937 test_AES_cipheronly_all(void)
1938 {
1939 	return test_blockcipher(BLKCIPHER_AES_CIPHERONLY_TYPE);
1940 }
1941 
1942 static int
1943 test_AES_docsis_all(void)
1944 {
1945 	/* Data-path service does not support DOCSIS yet */
1946 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
1947 		return -ENOTSUP;
1948 	return test_blockcipher(BLKCIPHER_AES_DOCSIS_TYPE);
1949 }
1950 
1951 static int
1952 test_DES_docsis_all(void)
1953 {
1954 	/* Data-path service does not support DOCSIS yet */
1955 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
1956 		return -ENOTSUP;
1957 	return test_blockcipher(BLKCIPHER_DES_DOCSIS_TYPE);
1958 }
1959 
1960 static int
1961 test_DES_cipheronly_all(void)
1962 {
1963 	return test_blockcipher(BLKCIPHER_DES_CIPHERONLY_TYPE);
1964 }
1965 
1966 static int
1967 test_authonly_all(void)
1968 {
1969 	return test_blockcipher(BLKCIPHER_AUTHONLY_TYPE);
1970 }
1971 
1972 static int
1973 test_AES_chain_all(void)
1974 {
1975 	return test_blockcipher(BLKCIPHER_AES_CHAIN_TYPE);
1976 }
1977 
1978 static int
1979 test_3DES_chain_all(void)
1980 {
1981 	return test_blockcipher(BLKCIPHER_3DES_CHAIN_TYPE);
1982 }
1983 
1984 static int
1985 test_3DES_cipheronly_all(void)
1986 {
1987 	return test_blockcipher(BLKCIPHER_3DES_CIPHERONLY_TYPE);
1988 }
1989 
1990 /* ***** SNOW 3G Tests ***** */
1991 static int
1992 create_wireless_algo_hash_session(uint8_t dev_id,
1993 	const uint8_t *key, const uint8_t key_len,
1994 	const uint8_t iv_len, const uint8_t auth_len,
1995 	enum rte_crypto_auth_operation op,
1996 	enum rte_crypto_auth_algorithm algo)
1997 {
1998 	uint8_t hash_key[key_len];
1999 	int status;
2000 
2001 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2002 	struct crypto_unittest_params *ut_params = &unittest_params;
2003 
2004 	memcpy(hash_key, key, key_len);
2005 
2006 	debug_hexdump(stdout, "key:", key, key_len);
2007 
2008 	/* Setup Authentication Parameters */
2009 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2010 	ut_params->auth_xform.next = NULL;
2011 
2012 	ut_params->auth_xform.auth.op = op;
2013 	ut_params->auth_xform.auth.algo = algo;
2014 	ut_params->auth_xform.auth.key.length = key_len;
2015 	ut_params->auth_xform.auth.key.data = hash_key;
2016 	ut_params->auth_xform.auth.digest_length = auth_len;
2017 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2018 	ut_params->auth_xform.auth.iv.length = iv_len;
2019 	ut_params->sess = rte_cryptodev_sym_session_create(
2020 			ts_params->session_mpool);
2021 
2022 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2023 			&ut_params->auth_xform,
2024 			ts_params->session_priv_mpool);
2025 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2026 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2027 	return 0;
2028 }
2029 
2030 static int
2031 create_wireless_algo_cipher_session(uint8_t dev_id,
2032 			enum rte_crypto_cipher_operation op,
2033 			enum rte_crypto_cipher_algorithm algo,
2034 			const uint8_t *key, const uint8_t key_len,
2035 			uint8_t iv_len)
2036 {
2037 	uint8_t cipher_key[key_len];
2038 	int status;
2039 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2040 	struct crypto_unittest_params *ut_params = &unittest_params;
2041 
2042 	memcpy(cipher_key, key, key_len);
2043 
2044 	/* Setup Cipher Parameters */
2045 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2046 	ut_params->cipher_xform.next = NULL;
2047 
2048 	ut_params->cipher_xform.cipher.algo = algo;
2049 	ut_params->cipher_xform.cipher.op = op;
2050 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2051 	ut_params->cipher_xform.cipher.key.length = key_len;
2052 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2053 	ut_params->cipher_xform.cipher.iv.length = iv_len;
2054 
2055 	debug_hexdump(stdout, "key:", key, key_len);
2056 
2057 	/* Create Crypto session */
2058 	ut_params->sess = rte_cryptodev_sym_session_create(
2059 			ts_params->session_mpool);
2060 
2061 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2062 			&ut_params->cipher_xform,
2063 			ts_params->session_priv_mpool);
2064 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2065 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2066 	return 0;
2067 }
2068 
2069 static int
2070 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2071 			unsigned int cipher_len,
2072 			unsigned int cipher_offset)
2073 {
2074 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2075 	struct crypto_unittest_params *ut_params = &unittest_params;
2076 
2077 	/* Generate Crypto op data structure */
2078 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2079 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2080 	TEST_ASSERT_NOT_NULL(ut_params->op,
2081 				"Failed to allocate pktmbuf offload");
2082 
2083 	/* Set crypto operation data parameters */
2084 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2085 
2086 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2087 
2088 	/* set crypto operation source mbuf */
2089 	sym_op->m_src = ut_params->ibuf;
2090 
2091 	/* iv */
2092 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2093 			iv, iv_len);
2094 	sym_op->cipher.data.length = cipher_len;
2095 	sym_op->cipher.data.offset = cipher_offset;
2096 	return 0;
2097 }
2098 
2099 static int
2100 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2101 			unsigned int cipher_len,
2102 			unsigned int cipher_offset)
2103 {
2104 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2105 	struct crypto_unittest_params *ut_params = &unittest_params;
2106 
2107 	/* Generate Crypto op data structure */
2108 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2109 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2110 	TEST_ASSERT_NOT_NULL(ut_params->op,
2111 				"Failed to allocate pktmbuf offload");
2112 
2113 	/* Set crypto operation data parameters */
2114 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2115 
2116 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2117 
2118 	/* set crypto operation source mbuf */
2119 	sym_op->m_src = ut_params->ibuf;
2120 	sym_op->m_dst = ut_params->obuf;
2121 
2122 	/* iv */
2123 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2124 			iv, iv_len);
2125 	sym_op->cipher.data.length = cipher_len;
2126 	sym_op->cipher.data.offset = cipher_offset;
2127 	return 0;
2128 }
2129 
2130 static int
2131 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2132 		enum rte_crypto_cipher_operation cipher_op,
2133 		enum rte_crypto_auth_operation auth_op,
2134 		enum rte_crypto_auth_algorithm auth_algo,
2135 		enum rte_crypto_cipher_algorithm cipher_algo,
2136 		const uint8_t *key, uint8_t key_len,
2137 		uint8_t auth_iv_len, uint8_t auth_len,
2138 		uint8_t cipher_iv_len)
2139 
2140 {
2141 	uint8_t cipher_auth_key[key_len];
2142 	int status;
2143 
2144 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2145 	struct crypto_unittest_params *ut_params = &unittest_params;
2146 
2147 	memcpy(cipher_auth_key, key, key_len);
2148 
2149 	/* Setup Authentication Parameters */
2150 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2151 	ut_params->auth_xform.next = NULL;
2152 
2153 	ut_params->auth_xform.auth.op = auth_op;
2154 	ut_params->auth_xform.auth.algo = auth_algo;
2155 	ut_params->auth_xform.auth.key.length = key_len;
2156 	/* Hash key = cipher key */
2157 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2158 	ut_params->auth_xform.auth.digest_length = auth_len;
2159 	/* Auth IV will be after cipher IV */
2160 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2161 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2162 
2163 	/* Setup Cipher Parameters */
2164 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2165 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2166 
2167 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2168 	ut_params->cipher_xform.cipher.op = cipher_op;
2169 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2170 	ut_params->cipher_xform.cipher.key.length = key_len;
2171 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2172 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2173 
2174 	debug_hexdump(stdout, "key:", key, key_len);
2175 
2176 	/* Create Crypto session*/
2177 	ut_params->sess = rte_cryptodev_sym_session_create(
2178 			ts_params->session_mpool);
2179 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2180 
2181 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2182 			&ut_params->cipher_xform,
2183 			ts_params->session_priv_mpool);
2184 	if (status == -ENOTSUP)
2185 		return status;
2186 
2187 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2188 	return 0;
2189 }
2190 
2191 static int
2192 create_wireless_cipher_auth_session(uint8_t dev_id,
2193 		enum rte_crypto_cipher_operation cipher_op,
2194 		enum rte_crypto_auth_operation auth_op,
2195 		enum rte_crypto_auth_algorithm auth_algo,
2196 		enum rte_crypto_cipher_algorithm cipher_algo,
2197 		const struct wireless_test_data *tdata)
2198 {
2199 	const uint8_t key_len = tdata->key.len;
2200 	uint8_t cipher_auth_key[key_len];
2201 	int status;
2202 
2203 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2204 	struct crypto_unittest_params *ut_params = &unittest_params;
2205 	const uint8_t *key = tdata->key.data;
2206 	const uint8_t auth_len = tdata->digest.len;
2207 	uint8_t cipher_iv_len = tdata->cipher_iv.len;
2208 	uint8_t auth_iv_len = tdata->auth_iv.len;
2209 
2210 	memcpy(cipher_auth_key, key, key_len);
2211 
2212 	/* Setup Authentication Parameters */
2213 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2214 	ut_params->auth_xform.next = NULL;
2215 
2216 	ut_params->auth_xform.auth.op = auth_op;
2217 	ut_params->auth_xform.auth.algo = auth_algo;
2218 	ut_params->auth_xform.auth.key.length = key_len;
2219 	/* Hash key = cipher key */
2220 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2221 	ut_params->auth_xform.auth.digest_length = auth_len;
2222 	/* Auth IV will be after cipher IV */
2223 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2224 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2225 
2226 	/* Setup Cipher Parameters */
2227 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2228 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2229 
2230 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2231 	ut_params->cipher_xform.cipher.op = cipher_op;
2232 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2233 	ut_params->cipher_xform.cipher.key.length = key_len;
2234 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2235 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2236 
2237 
2238 	debug_hexdump(stdout, "key:", key, key_len);
2239 
2240 	/* Create Crypto session*/
2241 	ut_params->sess = rte_cryptodev_sym_session_create(
2242 			ts_params->session_mpool);
2243 
2244 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2245 			&ut_params->cipher_xform,
2246 			ts_params->session_priv_mpool);
2247 	if (status == -ENOTSUP)
2248 		return status;
2249 
2250 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2251 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2252 	return 0;
2253 }
2254 
2255 static int
2256 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2257 		const struct wireless_test_data *tdata)
2258 {
2259 	return create_wireless_cipher_auth_session(dev_id,
2260 		RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2261 		RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2262 		RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2263 }
2264 
2265 static int
2266 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2267 		enum rte_crypto_cipher_operation cipher_op,
2268 		enum rte_crypto_auth_operation auth_op,
2269 		enum rte_crypto_auth_algorithm auth_algo,
2270 		enum rte_crypto_cipher_algorithm cipher_algo,
2271 		const uint8_t *key, const uint8_t key_len,
2272 		uint8_t auth_iv_len, uint8_t auth_len,
2273 		uint8_t cipher_iv_len)
2274 {
2275 	uint8_t auth_cipher_key[key_len];
2276 	int status;
2277 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2278 	struct crypto_unittest_params *ut_params = &unittest_params;
2279 
2280 	memcpy(auth_cipher_key, key, key_len);
2281 
2282 	/* Setup Authentication Parameters */
2283 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2284 	ut_params->auth_xform.auth.op = auth_op;
2285 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2286 	ut_params->auth_xform.auth.algo = auth_algo;
2287 	ut_params->auth_xform.auth.key.length = key_len;
2288 	ut_params->auth_xform.auth.key.data = auth_cipher_key;
2289 	ut_params->auth_xform.auth.digest_length = auth_len;
2290 	/* Auth IV will be after cipher IV */
2291 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2292 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2293 
2294 	/* Setup Cipher Parameters */
2295 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2296 	ut_params->cipher_xform.next = NULL;
2297 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2298 	ut_params->cipher_xform.cipher.op = cipher_op;
2299 	ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2300 	ut_params->cipher_xform.cipher.key.length = key_len;
2301 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2302 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2303 
2304 	debug_hexdump(stdout, "key:", key, key_len);
2305 
2306 	/* Create Crypto session*/
2307 	ut_params->sess = rte_cryptodev_sym_session_create(
2308 			ts_params->session_mpool);
2309 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2310 
2311 	if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2312 		ut_params->auth_xform.next = NULL;
2313 		ut_params->cipher_xform.next = &ut_params->auth_xform;
2314 		status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2315 				&ut_params->cipher_xform,
2316 				ts_params->session_priv_mpool);
2317 
2318 	} else
2319 		status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2320 				&ut_params->auth_xform,
2321 				ts_params->session_priv_mpool);
2322 
2323 	if (status == -ENOTSUP)
2324 		return status;
2325 
2326 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2327 
2328 	return 0;
2329 }
2330 
2331 static int
2332 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2333 		unsigned int auth_tag_len,
2334 		const uint8_t *iv, unsigned int iv_len,
2335 		unsigned int data_pad_len,
2336 		enum rte_crypto_auth_operation op,
2337 		unsigned int auth_len, unsigned int auth_offset)
2338 {
2339 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2340 
2341 	struct crypto_unittest_params *ut_params = &unittest_params;
2342 
2343 	/* Generate Crypto op data structure */
2344 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2345 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2346 	TEST_ASSERT_NOT_NULL(ut_params->op,
2347 		"Failed to allocate pktmbuf offload");
2348 
2349 	/* Set crypto operation data parameters */
2350 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2351 
2352 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2353 
2354 	/* set crypto operation source mbuf */
2355 	sym_op->m_src = ut_params->ibuf;
2356 
2357 	/* iv */
2358 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2359 			iv, iv_len);
2360 	/* digest */
2361 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2362 					ut_params->ibuf, auth_tag_len);
2363 
2364 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2365 				"no room to append auth tag");
2366 	ut_params->digest = sym_op->auth.digest.data;
2367 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2368 			ut_params->ibuf, data_pad_len);
2369 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2370 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2371 	else
2372 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2373 
2374 	debug_hexdump(stdout, "digest:",
2375 		sym_op->auth.digest.data,
2376 		auth_tag_len);
2377 
2378 	sym_op->auth.data.length = auth_len;
2379 	sym_op->auth.data.offset = auth_offset;
2380 
2381 	return 0;
2382 }
2383 
2384 static int
2385 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2386 	enum rte_crypto_auth_operation op)
2387 {
2388 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2389 	struct crypto_unittest_params *ut_params = &unittest_params;
2390 
2391 	const uint8_t *auth_tag = tdata->digest.data;
2392 	const unsigned int auth_tag_len = tdata->digest.len;
2393 	unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2394 	unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2395 
2396 	const uint8_t *cipher_iv = tdata->cipher_iv.data;
2397 	const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2398 	const uint8_t *auth_iv = tdata->auth_iv.data;
2399 	const uint8_t auth_iv_len = tdata->auth_iv.len;
2400 	const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2401 	const unsigned int auth_len = tdata->validAuthLenInBits.len;
2402 
2403 	/* Generate Crypto op data structure */
2404 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2405 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2406 	TEST_ASSERT_NOT_NULL(ut_params->op,
2407 			"Failed to allocate pktmbuf offload");
2408 	/* Set crypto operation data parameters */
2409 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2410 
2411 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2412 
2413 	/* set crypto operation source mbuf */
2414 	sym_op->m_src = ut_params->ibuf;
2415 
2416 	/* digest */
2417 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2418 			ut_params->ibuf, auth_tag_len);
2419 
2420 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2421 			"no room to append auth tag");
2422 	ut_params->digest = sym_op->auth.digest.data;
2423 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2424 			ut_params->ibuf, data_pad_len);
2425 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2426 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2427 	else
2428 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2429 
2430 	debug_hexdump(stdout, "digest:",
2431 		sym_op->auth.digest.data,
2432 		auth_tag_len);
2433 
2434 	/* Copy cipher and auth IVs at the end of the crypto operation */
2435 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2436 						IV_OFFSET);
2437 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2438 	iv_ptr += cipher_iv_len;
2439 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2440 
2441 	sym_op->cipher.data.length = cipher_len;
2442 	sym_op->cipher.data.offset = 0;
2443 	sym_op->auth.data.length = auth_len;
2444 	sym_op->auth.data.offset = 0;
2445 
2446 	return 0;
2447 }
2448 
2449 static int
2450 create_zuc_cipher_hash_generate_operation(
2451 		const struct wireless_test_data *tdata)
2452 {
2453 	return create_wireless_cipher_hash_operation(tdata,
2454 		RTE_CRYPTO_AUTH_OP_GENERATE);
2455 }
2456 
2457 static int
2458 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2459 		const unsigned auth_tag_len,
2460 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2461 		unsigned data_pad_len,
2462 		enum rte_crypto_auth_operation op,
2463 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2464 		const unsigned cipher_len, const unsigned cipher_offset,
2465 		const unsigned auth_len, const unsigned auth_offset)
2466 {
2467 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2468 	struct crypto_unittest_params *ut_params = &unittest_params;
2469 
2470 	enum rte_crypto_cipher_algorithm cipher_algo =
2471 			ut_params->cipher_xform.cipher.algo;
2472 	enum rte_crypto_auth_algorithm auth_algo =
2473 			ut_params->auth_xform.auth.algo;
2474 
2475 	/* Generate Crypto op data structure */
2476 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2477 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2478 	TEST_ASSERT_NOT_NULL(ut_params->op,
2479 			"Failed to allocate pktmbuf offload");
2480 	/* Set crypto operation data parameters */
2481 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2482 
2483 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2484 
2485 	/* set crypto operation source mbuf */
2486 	sym_op->m_src = ut_params->ibuf;
2487 
2488 	/* digest */
2489 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2490 			ut_params->ibuf, auth_tag_len);
2491 
2492 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2493 			"no room to append auth tag");
2494 	ut_params->digest = sym_op->auth.digest.data;
2495 
2496 	if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2497 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2498 				ut_params->ibuf, data_pad_len);
2499 	} else {
2500 		struct rte_mbuf *m = ut_params->ibuf;
2501 		unsigned int offset = data_pad_len;
2502 
2503 		while (offset > m->data_len && m->next != NULL) {
2504 			offset -= m->data_len;
2505 			m = m->next;
2506 		}
2507 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2508 			m, offset);
2509 	}
2510 
2511 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2512 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2513 	else
2514 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2515 
2516 	debug_hexdump(stdout, "digest:",
2517 		sym_op->auth.digest.data,
2518 		auth_tag_len);
2519 
2520 	/* Copy cipher and auth IVs at the end of the crypto operation */
2521 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2522 						IV_OFFSET);
2523 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2524 	iv_ptr += cipher_iv_len;
2525 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2526 
2527 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2528 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2529 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2530 		sym_op->cipher.data.length = cipher_len;
2531 		sym_op->cipher.data.offset = cipher_offset;
2532 	} else {
2533 		sym_op->cipher.data.length = cipher_len >> 3;
2534 		sym_op->cipher.data.offset = cipher_offset >> 3;
2535 	}
2536 
2537 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2538 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2539 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2540 		sym_op->auth.data.length = auth_len;
2541 		sym_op->auth.data.offset = auth_offset;
2542 	} else {
2543 		sym_op->auth.data.length = auth_len >> 3;
2544 		sym_op->auth.data.offset = auth_offset >> 3;
2545 	}
2546 
2547 	return 0;
2548 }
2549 
2550 static int
2551 create_wireless_algo_auth_cipher_operation(
2552 		const uint8_t *auth_tag, unsigned int auth_tag_len,
2553 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2554 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2555 		unsigned int data_pad_len,
2556 		unsigned int cipher_len, unsigned int cipher_offset,
2557 		unsigned int auth_len, unsigned int auth_offset,
2558 		uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2559 {
2560 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2561 	struct crypto_unittest_params *ut_params = &unittest_params;
2562 
2563 	enum rte_crypto_cipher_algorithm cipher_algo =
2564 			ut_params->cipher_xform.cipher.algo;
2565 	enum rte_crypto_auth_algorithm auth_algo =
2566 			ut_params->auth_xform.auth.algo;
2567 
2568 	/* Generate Crypto op data structure */
2569 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2570 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2571 	TEST_ASSERT_NOT_NULL(ut_params->op,
2572 			"Failed to allocate pktmbuf offload");
2573 
2574 	/* Set crypto operation data parameters */
2575 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2576 
2577 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2578 
2579 	/* set crypto operation mbufs */
2580 	sym_op->m_src = ut_params->ibuf;
2581 	if (op_mode == OUT_OF_PLACE)
2582 		sym_op->m_dst = ut_params->obuf;
2583 
2584 	/* digest */
2585 	if (!do_sgl) {
2586 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
2587 			(op_mode == IN_PLACE ?
2588 				ut_params->ibuf : ut_params->obuf),
2589 			uint8_t *, data_pad_len);
2590 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2591 			(op_mode == IN_PLACE ?
2592 				ut_params->ibuf : ut_params->obuf),
2593 			data_pad_len);
2594 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2595 	} else {
2596 		uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
2597 		struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
2598 				sym_op->m_src : sym_op->m_dst);
2599 		while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
2600 			remaining_off -= rte_pktmbuf_data_len(sgl_buf);
2601 			sgl_buf = sgl_buf->next;
2602 		}
2603 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
2604 				uint8_t *, remaining_off);
2605 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
2606 				remaining_off);
2607 		memset(sym_op->auth.digest.data, 0, remaining_off);
2608 		while (sgl_buf->next != NULL) {
2609 			memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
2610 				0, rte_pktmbuf_data_len(sgl_buf));
2611 			sgl_buf = sgl_buf->next;
2612 		}
2613 	}
2614 
2615 	/* Copy digest for the verification */
2616 	if (verify)
2617 		memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2618 
2619 	/* Copy cipher and auth IVs at the end of the crypto operation */
2620 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
2621 			ut_params->op, uint8_t *, IV_OFFSET);
2622 
2623 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2624 	iv_ptr += cipher_iv_len;
2625 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2626 
2627 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2628 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2629 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2630 		sym_op->cipher.data.length = cipher_len;
2631 		sym_op->cipher.data.offset = cipher_offset;
2632 	} else {
2633 		sym_op->cipher.data.length = cipher_len >> 3;
2634 		sym_op->cipher.data.offset = cipher_offset >> 3;
2635 	}
2636 
2637 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2638 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2639 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2640 		sym_op->auth.data.length = auth_len;
2641 		sym_op->auth.data.offset = auth_offset;
2642 	} else {
2643 		sym_op->auth.data.length = auth_len >> 3;
2644 		sym_op->auth.data.offset = auth_offset >> 3;
2645 	}
2646 
2647 	return 0;
2648 }
2649 
2650 static int
2651 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2652 {
2653 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2654 	struct crypto_unittest_params *ut_params = &unittest_params;
2655 
2656 	int retval;
2657 	unsigned plaintext_pad_len;
2658 	unsigned plaintext_len;
2659 	uint8_t *plaintext;
2660 	struct rte_cryptodev_info dev_info;
2661 
2662 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2663 	uint64_t feat_flags = dev_info.feature_flags;
2664 
2665 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
2666 			((tdata->validAuthLenInBits.len % 8) != 0)) {
2667 		printf("Device doesn't support NON-Byte Aligned Data.\n");
2668 		return -ENOTSUP;
2669 	}
2670 
2671 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
2672 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
2673 		printf("Device doesn't support RAW data-path APIs.\n");
2674 		return -ENOTSUP;
2675 	}
2676 
2677 	/* Verify the capabilities */
2678 	struct rte_cryptodev_sym_capability_idx cap_idx;
2679 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2680 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2681 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2682 			&cap_idx) == NULL)
2683 		return -ENOTSUP;
2684 
2685 	/* Create SNOW 3G session */
2686 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2687 			tdata->key.data, tdata->key.len,
2688 			tdata->auth_iv.len, tdata->digest.len,
2689 			RTE_CRYPTO_AUTH_OP_GENERATE,
2690 			RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2691 	if (retval < 0)
2692 		return retval;
2693 
2694 	/* alloc mbuf and set payload */
2695 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2696 
2697 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2698 	rte_pktmbuf_tailroom(ut_params->ibuf));
2699 
2700 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
2701 	/* Append data which is padded to a multiple of */
2702 	/* the algorithms block size */
2703 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2704 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2705 				plaintext_pad_len);
2706 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2707 
2708 	/* Create SNOW 3G operation */
2709 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2710 			tdata->auth_iv.data, tdata->auth_iv.len,
2711 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2712 			tdata->validAuthLenInBits.len,
2713 			0);
2714 	if (retval < 0)
2715 		return retval;
2716 
2717 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2718 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2719 				ut_params->op, 0, 1, 1, 0);
2720 	else
2721 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2722 				ut_params->op);
2723 	ut_params->obuf = ut_params->op->sym->m_src;
2724 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2725 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2726 			+ plaintext_pad_len;
2727 
2728 	/* Validate obuf */
2729 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
2730 	ut_params->digest,
2731 	tdata->digest.data,
2732 	DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2733 	"SNOW 3G Generated auth tag not as expected");
2734 
2735 	return 0;
2736 }
2737 
2738 static int
2739 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
2740 {
2741 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2742 	struct crypto_unittest_params *ut_params = &unittest_params;
2743 
2744 	int retval;
2745 	unsigned plaintext_pad_len;
2746 	unsigned plaintext_len;
2747 	uint8_t *plaintext;
2748 	struct rte_cryptodev_info dev_info;
2749 
2750 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2751 	uint64_t feat_flags = dev_info.feature_flags;
2752 
2753 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
2754 			((tdata->validAuthLenInBits.len % 8) != 0)) {
2755 		printf("Device doesn't support NON-Byte Aligned Data.\n");
2756 		return -ENOTSUP;
2757 	}
2758 
2759 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
2760 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
2761 		printf("Device doesn't support RAW data-path APIs.\n");
2762 		return -ENOTSUP;
2763 	}
2764 
2765 	/* Verify the capabilities */
2766 	struct rte_cryptodev_sym_capability_idx cap_idx;
2767 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2768 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2769 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2770 			&cap_idx) == NULL)
2771 		return -ENOTSUP;
2772 
2773 	/* Create SNOW 3G session */
2774 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2775 				tdata->key.data, tdata->key.len,
2776 				tdata->auth_iv.len, tdata->digest.len,
2777 				RTE_CRYPTO_AUTH_OP_VERIFY,
2778 				RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2779 	if (retval < 0)
2780 		return retval;
2781 	/* alloc mbuf and set payload */
2782 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2783 
2784 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2785 	rte_pktmbuf_tailroom(ut_params->ibuf));
2786 
2787 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
2788 	/* Append data which is padded to a multiple of */
2789 	/* the algorithms block size */
2790 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2791 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2792 				plaintext_pad_len);
2793 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2794 
2795 	/* Create SNOW 3G operation */
2796 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
2797 			tdata->digest.len,
2798 			tdata->auth_iv.data, tdata->auth_iv.len,
2799 			plaintext_pad_len,
2800 			RTE_CRYPTO_AUTH_OP_VERIFY,
2801 			tdata->validAuthLenInBits.len,
2802 			0);
2803 	if (retval < 0)
2804 		return retval;
2805 
2806 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2807 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2808 				ut_params->op, 0, 1, 1, 0);
2809 	else
2810 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2811 				ut_params->op);
2812 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2813 	ut_params->obuf = ut_params->op->sym->m_src;
2814 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2815 				+ plaintext_pad_len;
2816 
2817 	/* Validate obuf */
2818 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2819 		return 0;
2820 	else
2821 		return -1;
2822 
2823 	return 0;
2824 }
2825 
2826 static int
2827 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
2828 {
2829 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2830 	struct crypto_unittest_params *ut_params = &unittest_params;
2831 
2832 	int retval;
2833 	unsigned plaintext_pad_len;
2834 	unsigned plaintext_len;
2835 	uint8_t *plaintext;
2836 	struct rte_cryptodev_info dev_info;
2837 
2838 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2839 	uint64_t feat_flags = dev_info.feature_flags;
2840 
2841 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
2842 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
2843 		printf("Device doesn't support RAW data-path APIs.\n");
2844 		return -ENOTSUP;
2845 	}
2846 
2847 	/* Verify the capabilities */
2848 	struct rte_cryptodev_sym_capability_idx cap_idx;
2849 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2850 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
2851 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2852 			&cap_idx) == NULL)
2853 		return -ENOTSUP;
2854 
2855 	/* Create KASUMI session */
2856 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2857 			tdata->key.data, tdata->key.len,
2858 			0, tdata->digest.len,
2859 			RTE_CRYPTO_AUTH_OP_GENERATE,
2860 			RTE_CRYPTO_AUTH_KASUMI_F9);
2861 	if (retval < 0)
2862 		return retval;
2863 
2864 	/* alloc mbuf and set payload */
2865 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2866 
2867 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2868 	rte_pktmbuf_tailroom(ut_params->ibuf));
2869 
2870 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
2871 	/* Append data which is padded to a multiple of */
2872 	/* the algorithms block size */
2873 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2874 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2875 				plaintext_pad_len);
2876 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2877 
2878 	/* Create KASUMI operation */
2879 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2880 			NULL, 0,
2881 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2882 			tdata->plaintext.len,
2883 			0);
2884 	if (retval < 0)
2885 		return retval;
2886 
2887 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2888 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2889 			ut_params->op);
2890 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2891 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2892 				ut_params->op, 0, 1, 1, 0);
2893 	else
2894 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2895 			ut_params->op);
2896 
2897 	ut_params->obuf = ut_params->op->sym->m_src;
2898 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2899 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2900 			+ plaintext_pad_len;
2901 
2902 	/* Validate obuf */
2903 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
2904 	ut_params->digest,
2905 	tdata->digest.data,
2906 	DIGEST_BYTE_LENGTH_KASUMI_F9,
2907 	"KASUMI Generated auth tag not as expected");
2908 
2909 	return 0;
2910 }
2911 
2912 static int
2913 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
2914 {
2915 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2916 	struct crypto_unittest_params *ut_params = &unittest_params;
2917 
2918 	int retval;
2919 	unsigned plaintext_pad_len;
2920 	unsigned plaintext_len;
2921 	uint8_t *plaintext;
2922 	struct rte_cryptodev_info dev_info;
2923 
2924 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2925 	uint64_t feat_flags = dev_info.feature_flags;
2926 
2927 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
2928 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
2929 		printf("Device doesn't support RAW data-path APIs.\n");
2930 		return -ENOTSUP;
2931 	}
2932 
2933 	/* Verify the capabilities */
2934 	struct rte_cryptodev_sym_capability_idx cap_idx;
2935 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2936 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
2937 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2938 			&cap_idx) == NULL)
2939 		return -ENOTSUP;
2940 
2941 	/* Create KASUMI session */
2942 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2943 				tdata->key.data, tdata->key.len,
2944 				0, tdata->digest.len,
2945 				RTE_CRYPTO_AUTH_OP_VERIFY,
2946 				RTE_CRYPTO_AUTH_KASUMI_F9);
2947 	if (retval < 0)
2948 		return retval;
2949 	/* alloc mbuf and set payload */
2950 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2951 
2952 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2953 	rte_pktmbuf_tailroom(ut_params->ibuf));
2954 
2955 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
2956 	/* Append data which is padded to a multiple */
2957 	/* of the algorithms block size */
2958 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2959 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2960 				plaintext_pad_len);
2961 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2962 
2963 	/* Create KASUMI operation */
2964 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
2965 			tdata->digest.len,
2966 			NULL, 0,
2967 			plaintext_pad_len,
2968 			RTE_CRYPTO_AUTH_OP_VERIFY,
2969 			tdata->plaintext.len,
2970 			0);
2971 	if (retval < 0)
2972 		return retval;
2973 
2974 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2975 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2976 				ut_params->op, 0, 1, 1, 0);
2977 	else
2978 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2979 				ut_params->op);
2980 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2981 	ut_params->obuf = ut_params->op->sym->m_src;
2982 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2983 				+ plaintext_pad_len;
2984 
2985 	/* Validate obuf */
2986 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2987 		return 0;
2988 	else
2989 		return -1;
2990 
2991 	return 0;
2992 }
2993 
2994 static int
2995 test_snow3g_hash_generate_test_case_1(void)
2996 {
2997 	return test_snow3g_authentication(&snow3g_hash_test_case_1);
2998 }
2999 
3000 static int
3001 test_snow3g_hash_generate_test_case_2(void)
3002 {
3003 	return test_snow3g_authentication(&snow3g_hash_test_case_2);
3004 }
3005 
3006 static int
3007 test_snow3g_hash_generate_test_case_3(void)
3008 {
3009 	return test_snow3g_authentication(&snow3g_hash_test_case_3);
3010 }
3011 
3012 static int
3013 test_snow3g_hash_generate_test_case_4(void)
3014 {
3015 	return test_snow3g_authentication(&snow3g_hash_test_case_4);
3016 }
3017 
3018 static int
3019 test_snow3g_hash_generate_test_case_5(void)
3020 {
3021 	return test_snow3g_authentication(&snow3g_hash_test_case_5);
3022 }
3023 
3024 static int
3025 test_snow3g_hash_generate_test_case_6(void)
3026 {
3027 	return test_snow3g_authentication(&snow3g_hash_test_case_6);
3028 }
3029 
3030 static int
3031 test_snow3g_hash_verify_test_case_1(void)
3032 {
3033 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3034 
3035 }
3036 
3037 static int
3038 test_snow3g_hash_verify_test_case_2(void)
3039 {
3040 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3041 }
3042 
3043 static int
3044 test_snow3g_hash_verify_test_case_3(void)
3045 {
3046 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3047 }
3048 
3049 static int
3050 test_snow3g_hash_verify_test_case_4(void)
3051 {
3052 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3053 }
3054 
3055 static int
3056 test_snow3g_hash_verify_test_case_5(void)
3057 {
3058 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3059 }
3060 
3061 static int
3062 test_snow3g_hash_verify_test_case_6(void)
3063 {
3064 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3065 }
3066 
3067 static int
3068 test_kasumi_hash_generate_test_case_1(void)
3069 {
3070 	return test_kasumi_authentication(&kasumi_hash_test_case_1);
3071 }
3072 
3073 static int
3074 test_kasumi_hash_generate_test_case_2(void)
3075 {
3076 	return test_kasumi_authentication(&kasumi_hash_test_case_2);
3077 }
3078 
3079 static int
3080 test_kasumi_hash_generate_test_case_3(void)
3081 {
3082 	return test_kasumi_authentication(&kasumi_hash_test_case_3);
3083 }
3084 
3085 static int
3086 test_kasumi_hash_generate_test_case_4(void)
3087 {
3088 	return test_kasumi_authentication(&kasumi_hash_test_case_4);
3089 }
3090 
3091 static int
3092 test_kasumi_hash_generate_test_case_5(void)
3093 {
3094 	return test_kasumi_authentication(&kasumi_hash_test_case_5);
3095 }
3096 
3097 static int
3098 test_kasumi_hash_generate_test_case_6(void)
3099 {
3100 	return test_kasumi_authentication(&kasumi_hash_test_case_6);
3101 }
3102 
3103 static int
3104 test_kasumi_hash_verify_test_case_1(void)
3105 {
3106 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3107 }
3108 
3109 static int
3110 test_kasumi_hash_verify_test_case_2(void)
3111 {
3112 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3113 }
3114 
3115 static int
3116 test_kasumi_hash_verify_test_case_3(void)
3117 {
3118 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3119 }
3120 
3121 static int
3122 test_kasumi_hash_verify_test_case_4(void)
3123 {
3124 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3125 }
3126 
3127 static int
3128 test_kasumi_hash_verify_test_case_5(void)
3129 {
3130 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3131 }
3132 
3133 static int
3134 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3135 {
3136 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3137 	struct crypto_unittest_params *ut_params = &unittest_params;
3138 
3139 	int retval;
3140 	uint8_t *plaintext, *ciphertext;
3141 	unsigned plaintext_pad_len;
3142 	unsigned plaintext_len;
3143 	struct rte_cryptodev_info dev_info;
3144 
3145 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3146 	uint64_t feat_flags = dev_info.feature_flags;
3147 
3148 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3149 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3150 		printf("Device doesn't support RAW data-path APIs.\n");
3151 		return -ENOTSUP;
3152 	}
3153 
3154 	/* Verify the capabilities */
3155 	struct rte_cryptodev_sym_capability_idx cap_idx;
3156 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3157 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3158 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3159 			&cap_idx) == NULL)
3160 		return -ENOTSUP;
3161 
3162 	/* Create KASUMI session */
3163 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3164 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3165 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3166 					tdata->key.data, tdata->key.len,
3167 					tdata->cipher_iv.len);
3168 	if (retval < 0)
3169 		return retval;
3170 
3171 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3172 
3173 	/* Clear mbuf payload */
3174 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3175 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3176 
3177 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3178 	/* Append data which is padded to a multiple */
3179 	/* of the algorithms block size */
3180 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3181 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3182 				plaintext_pad_len);
3183 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3184 
3185 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3186 
3187 	/* Create KASUMI operation */
3188 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3189 				tdata->cipher_iv.len,
3190 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3191 				tdata->validCipherOffsetInBits.len);
3192 	if (retval < 0)
3193 		return retval;
3194 
3195 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3196 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3197 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3198 	else
3199 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3200 				ut_params->op);
3201 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3202 
3203 	ut_params->obuf = ut_params->op->sym->m_dst;
3204 	if (ut_params->obuf)
3205 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3206 	else
3207 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3208 
3209 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3210 
3211 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3212 				(tdata->validCipherOffsetInBits.len >> 3);
3213 	/* Validate obuf */
3214 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3215 		ciphertext,
3216 		reference_ciphertext,
3217 		tdata->validCipherLenInBits.len,
3218 		"KASUMI Ciphertext data not as expected");
3219 	return 0;
3220 }
3221 
3222 static int
3223 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3224 {
3225 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3226 	struct crypto_unittest_params *ut_params = &unittest_params;
3227 
3228 	int retval;
3229 
3230 	unsigned int plaintext_pad_len;
3231 	unsigned int plaintext_len;
3232 
3233 	uint8_t buffer[10000];
3234 	const uint8_t *ciphertext;
3235 
3236 	struct rte_cryptodev_info dev_info;
3237 
3238 	/* Verify the capabilities */
3239 	struct rte_cryptodev_sym_capability_idx cap_idx;
3240 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3241 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3242 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3243 			&cap_idx) == NULL)
3244 		return -ENOTSUP;
3245 
3246 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3247 
3248 	uint64_t feat_flags = dev_info.feature_flags;
3249 
3250 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3251 		printf("Device doesn't support in-place scatter-gather. "
3252 				"Test Skipped.\n");
3253 		return -ENOTSUP;
3254 	}
3255 
3256 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3257 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3258 		printf("Device doesn't support RAW data-path APIs.\n");
3259 		return -ENOTSUP;
3260 	}
3261 
3262 	/* Create KASUMI session */
3263 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3264 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3265 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3266 					tdata->key.data, tdata->key.len,
3267 					tdata->cipher_iv.len);
3268 	if (retval < 0)
3269 		return retval;
3270 
3271 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3272 
3273 
3274 	/* Append data which is padded to a multiple */
3275 	/* of the algorithms block size */
3276 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3277 
3278 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3279 			plaintext_pad_len, 10, 0);
3280 
3281 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3282 
3283 	/* Create KASUMI operation */
3284 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3285 				tdata->cipher_iv.len,
3286 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3287 				tdata->validCipherOffsetInBits.len);
3288 	if (retval < 0)
3289 		return retval;
3290 
3291 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3292 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3293 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3294 	else
3295 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3296 						ut_params->op);
3297 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3298 
3299 	ut_params->obuf = ut_params->op->sym->m_dst;
3300 
3301 	if (ut_params->obuf)
3302 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3303 				plaintext_len, buffer);
3304 	else
3305 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3306 				tdata->validCipherOffsetInBits.len >> 3,
3307 				plaintext_len, buffer);
3308 
3309 	/* Validate obuf */
3310 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3311 
3312 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3313 				(tdata->validCipherOffsetInBits.len >> 3);
3314 	/* Validate obuf */
3315 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3316 		ciphertext,
3317 		reference_ciphertext,
3318 		tdata->validCipherLenInBits.len,
3319 		"KASUMI Ciphertext data not as expected");
3320 	return 0;
3321 }
3322 
3323 static int
3324 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3325 {
3326 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3327 	struct crypto_unittest_params *ut_params = &unittest_params;
3328 
3329 	int retval;
3330 	uint8_t *plaintext, *ciphertext;
3331 	unsigned plaintext_pad_len;
3332 	unsigned plaintext_len;
3333 
3334 	/* Verify the capabilities */
3335 	struct rte_cryptodev_sym_capability_idx cap_idx;
3336 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3337 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3338 	/* Data-path service does not support OOP */
3339 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3340 			&cap_idx) == NULL)
3341 		return -ENOTSUP;
3342 
3343 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3344 		return -ENOTSUP;
3345 
3346 	/* Create KASUMI session */
3347 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3348 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3349 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3350 					tdata->key.data, tdata->key.len,
3351 					tdata->cipher_iv.len);
3352 	if (retval < 0)
3353 		return retval;
3354 
3355 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3356 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3357 
3358 	/* Clear mbuf payload */
3359 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3360 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3361 
3362 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3363 	/* Append data which is padded to a multiple */
3364 	/* of the algorithms block size */
3365 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3366 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3367 				plaintext_pad_len);
3368 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3369 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3370 
3371 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3372 
3373 	/* Create KASUMI operation */
3374 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3375 				tdata->cipher_iv.len,
3376 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3377 				tdata->validCipherOffsetInBits.len);
3378 	if (retval < 0)
3379 		return retval;
3380 
3381 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3382 						ut_params->op);
3383 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3384 
3385 	ut_params->obuf = ut_params->op->sym->m_dst;
3386 	if (ut_params->obuf)
3387 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3388 	else
3389 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3390 
3391 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3392 
3393 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3394 				(tdata->validCipherOffsetInBits.len >> 3);
3395 	/* Validate obuf */
3396 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3397 		ciphertext,
3398 		reference_ciphertext,
3399 		tdata->validCipherLenInBits.len,
3400 		"KASUMI Ciphertext data not as expected");
3401 	return 0;
3402 }
3403 
3404 static int
3405 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3406 {
3407 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3408 	struct crypto_unittest_params *ut_params = &unittest_params;
3409 
3410 	int retval;
3411 	unsigned int plaintext_pad_len;
3412 	unsigned int plaintext_len;
3413 
3414 	const uint8_t *ciphertext;
3415 	uint8_t buffer[2048];
3416 
3417 	struct rte_cryptodev_info dev_info;
3418 
3419 	/* Verify the capabilities */
3420 	struct rte_cryptodev_sym_capability_idx cap_idx;
3421 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3422 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3423 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3424 			&cap_idx) == NULL)
3425 		return -ENOTSUP;
3426 
3427 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3428 		return -ENOTSUP;
3429 
3430 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3431 
3432 	uint64_t feat_flags = dev_info.feature_flags;
3433 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3434 		printf("Device doesn't support out-of-place scatter-gather "
3435 				"in both input and output mbufs. "
3436 				"Test Skipped.\n");
3437 		return -ENOTSUP;
3438 	}
3439 
3440 	/* Create KASUMI session */
3441 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3442 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3443 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3444 					tdata->key.data, tdata->key.len,
3445 					tdata->cipher_iv.len);
3446 	if (retval < 0)
3447 		return retval;
3448 
3449 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3450 	/* Append data which is padded to a multiple */
3451 	/* of the algorithms block size */
3452 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3453 
3454 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3455 			plaintext_pad_len, 10, 0);
3456 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3457 			plaintext_pad_len, 3, 0);
3458 
3459 	/* Append data which is padded to a multiple */
3460 	/* of the algorithms block size */
3461 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3462 
3463 	/* Create KASUMI operation */
3464 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3465 				tdata->cipher_iv.len,
3466 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3467 				tdata->validCipherOffsetInBits.len);
3468 	if (retval < 0)
3469 		return retval;
3470 
3471 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3472 						ut_params->op);
3473 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3474 
3475 	ut_params->obuf = ut_params->op->sym->m_dst;
3476 	if (ut_params->obuf)
3477 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3478 				plaintext_pad_len, buffer);
3479 	else
3480 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3481 				tdata->validCipherOffsetInBits.len >> 3,
3482 				plaintext_pad_len, buffer);
3483 
3484 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3485 				(tdata->validCipherOffsetInBits.len >> 3);
3486 	/* Validate obuf */
3487 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3488 		ciphertext,
3489 		reference_ciphertext,
3490 		tdata->validCipherLenInBits.len,
3491 		"KASUMI Ciphertext data not as expected");
3492 	return 0;
3493 }
3494 
3495 
3496 static int
3497 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3498 {
3499 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3500 	struct crypto_unittest_params *ut_params = &unittest_params;
3501 
3502 	int retval;
3503 	uint8_t *ciphertext, *plaintext;
3504 	unsigned ciphertext_pad_len;
3505 	unsigned ciphertext_len;
3506 
3507 	/* Verify the capabilities */
3508 	struct rte_cryptodev_sym_capability_idx cap_idx;
3509 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3510 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3511 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3512 			&cap_idx) == NULL)
3513 		return -ENOTSUP;
3514 
3515 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3516 		return -ENOTSUP;
3517 
3518 	/* Create KASUMI session */
3519 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3520 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
3521 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3522 					tdata->key.data, tdata->key.len,
3523 					tdata->cipher_iv.len);
3524 	if (retval < 0)
3525 		return retval;
3526 
3527 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3528 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3529 
3530 	/* Clear mbuf payload */
3531 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3532 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3533 
3534 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3535 	/* Append data which is padded to a multiple */
3536 	/* of the algorithms block size */
3537 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3538 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3539 				ciphertext_pad_len);
3540 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3541 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3542 
3543 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3544 
3545 	/* Create KASUMI operation */
3546 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3547 				tdata->cipher_iv.len,
3548 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3549 				tdata->validCipherOffsetInBits.len);
3550 	if (retval < 0)
3551 		return retval;
3552 
3553 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3554 						ut_params->op);
3555 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3556 
3557 	ut_params->obuf = ut_params->op->sym->m_dst;
3558 	if (ut_params->obuf)
3559 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3560 	else
3561 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3562 
3563 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3564 
3565 	const uint8_t *reference_plaintext = tdata->plaintext.data +
3566 				(tdata->validCipherOffsetInBits.len >> 3);
3567 	/* Validate obuf */
3568 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3569 		plaintext,
3570 		reference_plaintext,
3571 		tdata->validCipherLenInBits.len,
3572 		"KASUMI Plaintext data not as expected");
3573 	return 0;
3574 }
3575 
3576 static int
3577 test_kasumi_decryption(const struct kasumi_test_data *tdata)
3578 {
3579 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3580 	struct crypto_unittest_params *ut_params = &unittest_params;
3581 
3582 	int retval;
3583 	uint8_t *ciphertext, *plaintext;
3584 	unsigned ciphertext_pad_len;
3585 	unsigned ciphertext_len;
3586 	struct rte_cryptodev_info dev_info;
3587 
3588 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3589 	uint64_t feat_flags = dev_info.feature_flags;
3590 
3591 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3592 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3593 		printf("Device doesn't support RAW data-path APIs.\n");
3594 		return -ENOTSUP;
3595 	}
3596 
3597 	/* Verify the capabilities */
3598 	struct rte_cryptodev_sym_capability_idx cap_idx;
3599 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3600 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3601 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3602 			&cap_idx) == NULL)
3603 		return -ENOTSUP;
3604 
3605 	/* Create KASUMI session */
3606 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3607 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
3608 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3609 					tdata->key.data, tdata->key.len,
3610 					tdata->cipher_iv.len);
3611 	if (retval < 0)
3612 		return retval;
3613 
3614 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3615 
3616 	/* Clear mbuf payload */
3617 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3618 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3619 
3620 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3621 	/* Append data which is padded to a multiple */
3622 	/* of the algorithms block size */
3623 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3624 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3625 				ciphertext_pad_len);
3626 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3627 
3628 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3629 
3630 	/* Create KASUMI operation */
3631 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3632 					tdata->cipher_iv.len,
3633 					tdata->ciphertext.len,
3634 					tdata->validCipherOffsetInBits.len);
3635 	if (retval < 0)
3636 		return retval;
3637 
3638 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3639 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3640 				ut_params->op, 1, 0, 1, 0);
3641 	else
3642 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3643 						ut_params->op);
3644 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3645 
3646 	ut_params->obuf = ut_params->op->sym->m_dst;
3647 	if (ut_params->obuf)
3648 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3649 	else
3650 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3651 
3652 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3653 
3654 	const uint8_t *reference_plaintext = tdata->plaintext.data +
3655 				(tdata->validCipherOffsetInBits.len >> 3);
3656 	/* Validate obuf */
3657 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3658 		plaintext,
3659 		reference_plaintext,
3660 		tdata->validCipherLenInBits.len,
3661 		"KASUMI Plaintext data not as expected");
3662 	return 0;
3663 }
3664 
3665 static int
3666 test_snow3g_encryption(const struct snow3g_test_data *tdata)
3667 {
3668 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3669 	struct crypto_unittest_params *ut_params = &unittest_params;
3670 
3671 	int retval;
3672 	uint8_t *plaintext, *ciphertext;
3673 	unsigned plaintext_pad_len;
3674 	unsigned plaintext_len;
3675 	struct rte_cryptodev_info dev_info;
3676 
3677 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3678 	uint64_t feat_flags = dev_info.feature_flags;
3679 
3680 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3681 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3682 		printf("Device doesn't support RAW data-path APIs.\n");
3683 		return -ENOTSUP;
3684 	}
3685 
3686 	/* Verify the capabilities */
3687 	struct rte_cryptodev_sym_capability_idx cap_idx;
3688 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3689 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3690 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3691 			&cap_idx) == NULL)
3692 		return -ENOTSUP;
3693 
3694 	/* Create SNOW 3G session */
3695 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3696 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3697 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3698 					tdata->key.data, tdata->key.len,
3699 					tdata->cipher_iv.len);
3700 	if (retval < 0)
3701 		return retval;
3702 
3703 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3704 
3705 	/* Clear mbuf payload */
3706 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3707 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3708 
3709 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3710 	/* Append data which is padded to a multiple of */
3711 	/* the algorithms block size */
3712 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3713 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3714 				plaintext_pad_len);
3715 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3716 
3717 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3718 
3719 	/* Create SNOW 3G operation */
3720 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3721 					tdata->cipher_iv.len,
3722 					tdata->validCipherLenInBits.len,
3723 					0);
3724 	if (retval < 0)
3725 		return retval;
3726 
3727 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3728 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3729 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3730 	else
3731 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3732 						ut_params->op);
3733 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3734 
3735 	ut_params->obuf = ut_params->op->sym->m_dst;
3736 	if (ut_params->obuf)
3737 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3738 	else
3739 		ciphertext = plaintext;
3740 
3741 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3742 
3743 	/* Validate obuf */
3744 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3745 		ciphertext,
3746 		tdata->ciphertext.data,
3747 		tdata->validDataLenInBits.len,
3748 		"SNOW 3G Ciphertext data not as expected");
3749 	return 0;
3750 }
3751 
3752 
3753 static int
3754 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
3755 {
3756 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3757 	struct crypto_unittest_params *ut_params = &unittest_params;
3758 	uint8_t *plaintext, *ciphertext;
3759 
3760 	int retval;
3761 	unsigned plaintext_pad_len;
3762 	unsigned plaintext_len;
3763 
3764 	/* Verify the capabilities */
3765 	struct rte_cryptodev_sym_capability_idx cap_idx;
3766 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3767 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3768 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3769 			&cap_idx) == NULL)
3770 		return -ENOTSUP;
3771 
3772 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3773 		return -ENOTSUP;
3774 
3775 	/* Create SNOW 3G session */
3776 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3777 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3778 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3779 					tdata->key.data, tdata->key.len,
3780 					tdata->cipher_iv.len);
3781 	if (retval < 0)
3782 		return retval;
3783 
3784 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3785 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3786 
3787 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3788 			"Failed to allocate input buffer in mempool");
3789 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
3790 			"Failed to allocate output buffer in mempool");
3791 
3792 	/* Clear mbuf payload */
3793 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3794 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3795 
3796 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3797 	/* Append data which is padded to a multiple of */
3798 	/* the algorithms block size */
3799 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3800 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3801 				plaintext_pad_len);
3802 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3803 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3804 
3805 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3806 
3807 	/* Create SNOW 3G operation */
3808 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3809 					tdata->cipher_iv.len,
3810 					tdata->validCipherLenInBits.len,
3811 					0);
3812 	if (retval < 0)
3813 		return retval;
3814 
3815 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3816 						ut_params->op);
3817 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3818 
3819 	ut_params->obuf = ut_params->op->sym->m_dst;
3820 	if (ut_params->obuf)
3821 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3822 	else
3823 		ciphertext = plaintext;
3824 
3825 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3826 
3827 	/* Validate obuf */
3828 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3829 		ciphertext,
3830 		tdata->ciphertext.data,
3831 		tdata->validDataLenInBits.len,
3832 		"SNOW 3G Ciphertext data not as expected");
3833 	return 0;
3834 }
3835 
3836 static int
3837 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
3838 {
3839 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3840 	struct crypto_unittest_params *ut_params = &unittest_params;
3841 
3842 	int retval;
3843 	unsigned int plaintext_pad_len;
3844 	unsigned int plaintext_len;
3845 	uint8_t buffer[10000];
3846 	const uint8_t *ciphertext;
3847 
3848 	struct rte_cryptodev_info dev_info;
3849 
3850 	/* Verify the capabilities */
3851 	struct rte_cryptodev_sym_capability_idx cap_idx;
3852 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3853 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3854 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3855 			&cap_idx) == NULL)
3856 		return -ENOTSUP;
3857 
3858 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3859 		return -ENOTSUP;
3860 
3861 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3862 
3863 	uint64_t feat_flags = dev_info.feature_flags;
3864 
3865 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3866 		printf("Device doesn't support out-of-place scatter-gather "
3867 				"in both input and output mbufs. "
3868 				"Test Skipped.\n");
3869 		return -ENOTSUP;
3870 	}
3871 
3872 	/* Create SNOW 3G session */
3873 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3874 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3875 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3876 					tdata->key.data, tdata->key.len,
3877 					tdata->cipher_iv.len);
3878 	if (retval < 0)
3879 		return retval;
3880 
3881 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3882 	/* Append data which is padded to a multiple of */
3883 	/* the algorithms block size */
3884 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3885 
3886 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3887 			plaintext_pad_len, 10, 0);
3888 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3889 			plaintext_pad_len, 3, 0);
3890 
3891 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3892 			"Failed to allocate input buffer in mempool");
3893 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
3894 			"Failed to allocate output buffer in mempool");
3895 
3896 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3897 
3898 	/* Create SNOW 3G operation */
3899 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3900 					tdata->cipher_iv.len,
3901 					tdata->validCipherLenInBits.len,
3902 					0);
3903 	if (retval < 0)
3904 		return retval;
3905 
3906 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3907 						ut_params->op);
3908 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3909 
3910 	ut_params->obuf = ut_params->op->sym->m_dst;
3911 	if (ut_params->obuf)
3912 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3913 				plaintext_len, buffer);
3914 	else
3915 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
3916 				plaintext_len, buffer);
3917 
3918 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3919 
3920 	/* Validate obuf */
3921 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3922 		ciphertext,
3923 		tdata->ciphertext.data,
3924 		tdata->validDataLenInBits.len,
3925 		"SNOW 3G Ciphertext data not as expected");
3926 
3927 	return 0;
3928 }
3929 
3930 /* Shift right a buffer by "offset" bits, "offset" < 8 */
3931 static void
3932 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
3933 {
3934 	uint8_t curr_byte, prev_byte;
3935 	uint32_t length_in_bytes = ceil_byte_length(length + offset);
3936 	uint8_t lower_byte_mask = (1 << offset) - 1;
3937 	unsigned i;
3938 
3939 	prev_byte = buffer[0];
3940 	buffer[0] >>= offset;
3941 
3942 	for (i = 1; i < length_in_bytes; i++) {
3943 		curr_byte = buffer[i];
3944 		buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
3945 				(curr_byte >> offset);
3946 		prev_byte = curr_byte;
3947 	}
3948 }
3949 
3950 static int
3951 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
3952 {
3953 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3954 	struct crypto_unittest_params *ut_params = &unittest_params;
3955 	uint8_t *plaintext, *ciphertext;
3956 	int retval;
3957 	uint32_t plaintext_len;
3958 	uint32_t plaintext_pad_len;
3959 	uint8_t extra_offset = 4;
3960 	uint8_t *expected_ciphertext_shifted;
3961 	struct rte_cryptodev_info dev_info;
3962 
3963 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3964 	uint64_t feat_flags = dev_info.feature_flags;
3965 
3966 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3967 			((tdata->validDataLenInBits.len % 8) != 0)) {
3968 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3969 		return -ENOTSUP;
3970 	}
3971 
3972 	/* Verify the capabilities */
3973 	struct rte_cryptodev_sym_capability_idx cap_idx;
3974 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3975 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
3976 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3977 			&cap_idx) == NULL)
3978 		return -ENOTSUP;
3979 
3980 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3981 		return -ENOTSUP;
3982 
3983 	/* Create SNOW 3G session */
3984 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3985 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3986 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3987 					tdata->key.data, tdata->key.len,
3988 					tdata->cipher_iv.len);
3989 	if (retval < 0)
3990 		return retval;
3991 
3992 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3993 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3994 
3995 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3996 			"Failed to allocate input buffer in mempool");
3997 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
3998 			"Failed to allocate output buffer in mempool");
3999 
4000 	/* Clear mbuf payload */
4001 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4002 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4003 
4004 	plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4005 	/*
4006 	 * Append data which is padded to a
4007 	 * multiple of the algorithms block size
4008 	 */
4009 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4010 
4011 	plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4012 						plaintext_pad_len);
4013 
4014 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4015 
4016 	memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4017 	buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4018 
4019 #ifdef RTE_APP_TEST_DEBUG
4020 	rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4021 #endif
4022 	/* Create SNOW 3G operation */
4023 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4024 					tdata->cipher_iv.len,
4025 					tdata->validCipherLenInBits.len,
4026 					extra_offset);
4027 	if (retval < 0)
4028 		return retval;
4029 
4030 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4031 						ut_params->op);
4032 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4033 
4034 	ut_params->obuf = ut_params->op->sym->m_dst;
4035 	if (ut_params->obuf)
4036 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4037 	else
4038 		ciphertext = plaintext;
4039 
4040 #ifdef RTE_APP_TEST_DEBUG
4041 	rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4042 #endif
4043 
4044 	expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4045 
4046 	TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4047 			"failed to reserve memory for ciphertext shifted\n");
4048 
4049 	memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4050 			ceil_byte_length(tdata->ciphertext.len));
4051 	buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4052 			extra_offset);
4053 	/* Validate obuf */
4054 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4055 		ciphertext,
4056 		expected_ciphertext_shifted,
4057 		tdata->validDataLenInBits.len,
4058 		extra_offset,
4059 		"SNOW 3G Ciphertext data not as expected");
4060 	return 0;
4061 }
4062 
4063 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4064 {
4065 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4066 	struct crypto_unittest_params *ut_params = &unittest_params;
4067 
4068 	int retval;
4069 
4070 	uint8_t *plaintext, *ciphertext;
4071 	unsigned ciphertext_pad_len;
4072 	unsigned ciphertext_len;
4073 	struct rte_cryptodev_info dev_info;
4074 
4075 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4076 	uint64_t feat_flags = dev_info.feature_flags;
4077 
4078 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4079 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4080 		printf("Device doesn't support RAW data-path APIs.\n");
4081 		return -ENOTSUP;
4082 	}
4083 
4084 	/* Verify the capabilities */
4085 	struct rte_cryptodev_sym_capability_idx cap_idx;
4086 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4087 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4088 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4089 			&cap_idx) == NULL)
4090 		return -ENOTSUP;
4091 
4092 	/* Create SNOW 3G session */
4093 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4094 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4095 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4096 					tdata->key.data, tdata->key.len,
4097 					tdata->cipher_iv.len);
4098 	if (retval < 0)
4099 		return retval;
4100 
4101 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4102 
4103 	/* Clear mbuf payload */
4104 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4105 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4106 
4107 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4108 	/* Append data which is padded to a multiple of */
4109 	/* the algorithms block size */
4110 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4111 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4112 				ciphertext_pad_len);
4113 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4114 
4115 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4116 
4117 	/* Create SNOW 3G operation */
4118 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4119 					tdata->cipher_iv.len,
4120 					tdata->validCipherLenInBits.len,
4121 					tdata->cipher.offset_bits);
4122 	if (retval < 0)
4123 		return retval;
4124 
4125 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4126 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4127 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4128 	else
4129 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4130 						ut_params->op);
4131 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4132 	ut_params->obuf = ut_params->op->sym->m_dst;
4133 	if (ut_params->obuf)
4134 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4135 	else
4136 		plaintext = ciphertext;
4137 
4138 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4139 
4140 	/* Validate obuf */
4141 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4142 				tdata->plaintext.data,
4143 				tdata->validDataLenInBits.len,
4144 				"SNOW 3G Plaintext data not as expected");
4145 	return 0;
4146 }
4147 
4148 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4149 {
4150 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4151 	struct crypto_unittest_params *ut_params = &unittest_params;
4152 
4153 	int retval;
4154 
4155 	uint8_t *plaintext, *ciphertext;
4156 	unsigned ciphertext_pad_len;
4157 	unsigned ciphertext_len;
4158 
4159 	/* Verify the capabilities */
4160 	struct rte_cryptodev_sym_capability_idx cap_idx;
4161 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4162 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4163 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4164 			&cap_idx) == NULL)
4165 		return -ENOTSUP;
4166 
4167 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4168 		return -ENOTSUP;
4169 
4170 	/* Create SNOW 3G session */
4171 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4172 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4173 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4174 					tdata->key.data, tdata->key.len,
4175 					tdata->cipher_iv.len);
4176 	if (retval < 0)
4177 		return retval;
4178 
4179 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4180 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4181 
4182 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4183 			"Failed to allocate input buffer");
4184 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4185 			"Failed to allocate output buffer");
4186 
4187 	/* Clear mbuf payload */
4188 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4189 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4190 
4191 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4192 		       rte_pktmbuf_tailroom(ut_params->obuf));
4193 
4194 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4195 	/* Append data which is padded to a multiple of */
4196 	/* the algorithms block size */
4197 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4198 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4199 				ciphertext_pad_len);
4200 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4201 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4202 
4203 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4204 
4205 	/* Create SNOW 3G operation */
4206 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4207 					tdata->cipher_iv.len,
4208 					tdata->validCipherLenInBits.len,
4209 					0);
4210 	if (retval < 0)
4211 		return retval;
4212 
4213 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4214 						ut_params->op);
4215 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4216 	ut_params->obuf = ut_params->op->sym->m_dst;
4217 	if (ut_params->obuf)
4218 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4219 	else
4220 		plaintext = ciphertext;
4221 
4222 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4223 
4224 	/* Validate obuf */
4225 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4226 				tdata->plaintext.data,
4227 				tdata->validDataLenInBits.len,
4228 				"SNOW 3G Plaintext data not as expected");
4229 	return 0;
4230 }
4231 
4232 static int
4233 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4234 {
4235 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4236 	struct crypto_unittest_params *ut_params = &unittest_params;
4237 
4238 	int retval;
4239 
4240 	uint8_t *plaintext, *ciphertext;
4241 	unsigned int plaintext_pad_len;
4242 	unsigned int plaintext_len;
4243 
4244 	struct rte_cryptodev_info dev_info;
4245 	struct rte_cryptodev_sym_capability_idx cap_idx;
4246 
4247 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4248 	uint64_t feat_flags = dev_info.feature_flags;
4249 
4250 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4251 			((tdata->validAuthLenInBits.len % 8 != 0) ||
4252 			(tdata->validDataLenInBits.len % 8 != 0))) {
4253 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4254 		return -ENOTSUP;
4255 	}
4256 
4257 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4258 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4259 		printf("Device doesn't support RAW data-path APIs.\n");
4260 		return -ENOTSUP;
4261 	}
4262 
4263 	/* Check if device supports ZUC EEA3 */
4264 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4265 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4266 
4267 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4268 			&cap_idx) == NULL)
4269 		return -ENOTSUP;
4270 
4271 	/* Check if device supports ZUC EIA3 */
4272 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4273 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4274 
4275 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4276 			&cap_idx) == NULL)
4277 		return -ENOTSUP;
4278 
4279 	/* Create ZUC session */
4280 	retval = create_zuc_cipher_auth_encrypt_generate_session(
4281 			ts_params->valid_devs[0],
4282 			tdata);
4283 	if (retval < 0)
4284 		return retval;
4285 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4286 
4287 	/* clear mbuf payload */
4288 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4289 			rte_pktmbuf_tailroom(ut_params->ibuf));
4290 
4291 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4292 	/* Append data which is padded to a multiple of */
4293 	/* the algorithms block size */
4294 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4295 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4296 				plaintext_pad_len);
4297 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4298 
4299 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4300 
4301 	/* Create ZUC operation */
4302 	retval = create_zuc_cipher_hash_generate_operation(tdata);
4303 	if (retval < 0)
4304 		return retval;
4305 
4306 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4307 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4308 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4309 	else
4310 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4311 			ut_params->op);
4312 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4313 	ut_params->obuf = ut_params->op->sym->m_src;
4314 	if (ut_params->obuf)
4315 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4316 	else
4317 		ciphertext = plaintext;
4318 
4319 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4320 	/* Validate obuf */
4321 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4322 			ciphertext,
4323 			tdata->ciphertext.data,
4324 			tdata->validDataLenInBits.len,
4325 			"ZUC Ciphertext data not as expected");
4326 
4327 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4328 	    + plaintext_pad_len;
4329 
4330 	/* Validate obuf */
4331 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4332 			ut_params->digest,
4333 			tdata->digest.data,
4334 			4,
4335 			"ZUC Generated auth tag not as expected");
4336 	return 0;
4337 }
4338 
4339 static int
4340 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4341 {
4342 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4343 	struct crypto_unittest_params *ut_params = &unittest_params;
4344 
4345 	int retval;
4346 
4347 	uint8_t *plaintext, *ciphertext;
4348 	unsigned plaintext_pad_len;
4349 	unsigned plaintext_len;
4350 	struct rte_cryptodev_info dev_info;
4351 
4352 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4353 	uint64_t feat_flags = dev_info.feature_flags;
4354 
4355 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4356 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4357 		printf("Device doesn't support RAW data-path APIs.\n");
4358 		return -ENOTSUP;
4359 	}
4360 
4361 	/* Verify the capabilities */
4362 	struct rte_cryptodev_sym_capability_idx cap_idx;
4363 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4364 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4365 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4366 			&cap_idx) == NULL)
4367 		return -ENOTSUP;
4368 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4369 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4370 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4371 			&cap_idx) == NULL)
4372 		return -ENOTSUP;
4373 
4374 	/* Create SNOW 3G session */
4375 	retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4376 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4377 			RTE_CRYPTO_AUTH_OP_GENERATE,
4378 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4379 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4380 			tdata->key.data, tdata->key.len,
4381 			tdata->auth_iv.len, tdata->digest.len,
4382 			tdata->cipher_iv.len);
4383 	if (retval < 0)
4384 		return retval;
4385 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4386 
4387 	/* clear mbuf payload */
4388 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4389 			rte_pktmbuf_tailroom(ut_params->ibuf));
4390 
4391 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4392 	/* Append data which is padded to a multiple of */
4393 	/* the algorithms block size */
4394 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4395 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4396 				plaintext_pad_len);
4397 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4398 
4399 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4400 
4401 	/* Create SNOW 3G operation */
4402 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4403 			tdata->digest.len, tdata->auth_iv.data,
4404 			tdata->auth_iv.len,
4405 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4406 			tdata->cipher_iv.data, tdata->cipher_iv.len,
4407 			tdata->validCipherLenInBits.len,
4408 			0,
4409 			tdata->validAuthLenInBits.len,
4410 			0
4411 			);
4412 	if (retval < 0)
4413 		return retval;
4414 
4415 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4416 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4417 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4418 	else
4419 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4420 			ut_params->op);
4421 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4422 	ut_params->obuf = ut_params->op->sym->m_src;
4423 	if (ut_params->obuf)
4424 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4425 	else
4426 		ciphertext = plaintext;
4427 
4428 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4429 	/* Validate obuf */
4430 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4431 			ciphertext,
4432 			tdata->ciphertext.data,
4433 			tdata->validDataLenInBits.len,
4434 			"SNOW 3G Ciphertext data not as expected");
4435 
4436 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4437 	    + plaintext_pad_len;
4438 
4439 	/* Validate obuf */
4440 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4441 			ut_params->digest,
4442 			tdata->digest.data,
4443 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4444 			"SNOW 3G Generated auth tag not as expected");
4445 	return 0;
4446 }
4447 
4448 static int
4449 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
4450 	uint8_t op_mode, uint8_t verify)
4451 {
4452 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4453 	struct crypto_unittest_params *ut_params = &unittest_params;
4454 
4455 	int retval;
4456 
4457 	uint8_t *plaintext = NULL, *ciphertext = NULL;
4458 	unsigned int plaintext_pad_len;
4459 	unsigned int plaintext_len;
4460 	unsigned int ciphertext_pad_len;
4461 	unsigned int ciphertext_len;
4462 
4463 	struct rte_cryptodev_info dev_info;
4464 
4465 	/* Verify the capabilities */
4466 	struct rte_cryptodev_sym_capability_idx cap_idx;
4467 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4468 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4469 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4470 			&cap_idx) == NULL)
4471 		return -ENOTSUP;
4472 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4473 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4474 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4475 			&cap_idx) == NULL)
4476 		return -ENOTSUP;
4477 
4478 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4479 
4480 	uint64_t feat_flags = dev_info.feature_flags;
4481 
4482 	if (op_mode == OUT_OF_PLACE) {
4483 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4484 			printf("Device doesn't support digest encrypted.\n");
4485 			return -ENOTSUP;
4486 		}
4487 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4488 			return -ENOTSUP;
4489 	}
4490 
4491 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4492 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4493 		printf("Device doesn't support RAW data-path APIs.\n");
4494 		return -ENOTSUP;
4495 	}
4496 
4497 	/* Create SNOW 3G session */
4498 	retval = create_wireless_algo_auth_cipher_session(
4499 			ts_params->valid_devs[0],
4500 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4501 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4502 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4503 					: RTE_CRYPTO_AUTH_OP_GENERATE),
4504 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4505 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4506 			tdata->key.data, tdata->key.len,
4507 			tdata->auth_iv.len, tdata->digest.len,
4508 			tdata->cipher_iv.len);
4509 
4510 	if (retval < 0)
4511 		return retval;
4512 
4513 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4514 	if (op_mode == OUT_OF_PLACE)
4515 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4516 
4517 	/* clear mbuf payload */
4518 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4519 		rte_pktmbuf_tailroom(ut_params->ibuf));
4520 	if (op_mode == OUT_OF_PLACE)
4521 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4522 			rte_pktmbuf_tailroom(ut_params->obuf));
4523 
4524 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4525 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4526 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4527 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4528 
4529 	if (verify) {
4530 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4531 					ciphertext_pad_len);
4532 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4533 		if (op_mode == OUT_OF_PLACE)
4534 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4535 		debug_hexdump(stdout, "ciphertext:", ciphertext,
4536 			ciphertext_len);
4537 	} else {
4538 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4539 					plaintext_pad_len);
4540 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4541 		if (op_mode == OUT_OF_PLACE)
4542 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4543 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4544 	}
4545 
4546 	/* Create SNOW 3G operation */
4547 	retval = create_wireless_algo_auth_cipher_operation(
4548 		tdata->digest.data, tdata->digest.len,
4549 		tdata->cipher_iv.data, tdata->cipher_iv.len,
4550 		tdata->auth_iv.data, tdata->auth_iv.len,
4551 		(tdata->digest.offset_bytes == 0 ?
4552 		(verify ? ciphertext_pad_len : plaintext_pad_len)
4553 			: tdata->digest.offset_bytes),
4554 		tdata->validCipherLenInBits.len,
4555 		tdata->cipher.offset_bits,
4556 		tdata->validAuthLenInBits.len,
4557 		tdata->auth.offset_bits,
4558 		op_mode, 0, verify);
4559 
4560 	if (retval < 0)
4561 		return retval;
4562 
4563 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4564 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4565 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4566 	else
4567 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4568 			ut_params->op);
4569 
4570 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4571 
4572 	ut_params->obuf = (op_mode == IN_PLACE ?
4573 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4574 
4575 	if (verify) {
4576 		if (ut_params->obuf)
4577 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
4578 							uint8_t *);
4579 		else
4580 			plaintext = ciphertext +
4581 				(tdata->cipher.offset_bits >> 3);
4582 
4583 		debug_hexdump(stdout, "plaintext:", plaintext,
4584 			(tdata->plaintext.len >> 3) - tdata->digest.len);
4585 		debug_hexdump(stdout, "plaintext expected:",
4586 			tdata->plaintext.data,
4587 			(tdata->plaintext.len >> 3) - tdata->digest.len);
4588 	} else {
4589 		if (ut_params->obuf)
4590 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
4591 							uint8_t *);
4592 		else
4593 			ciphertext = plaintext;
4594 
4595 		debug_hexdump(stdout, "ciphertext:", ciphertext,
4596 			ciphertext_len);
4597 		debug_hexdump(stdout, "ciphertext expected:",
4598 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
4599 
4600 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4601 			+ (tdata->digest.offset_bytes == 0 ?
4602 		plaintext_pad_len : tdata->digest.offset_bytes);
4603 
4604 		debug_hexdump(stdout, "digest:", ut_params->digest,
4605 			tdata->digest.len);
4606 		debug_hexdump(stdout, "digest expected:", tdata->digest.data,
4607 				tdata->digest.len);
4608 	}
4609 
4610 	/* Validate obuf */
4611 	if (verify) {
4612 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4613 			plaintext,
4614 			tdata->plaintext.data,
4615 			tdata->plaintext.len >> 3,
4616 			"SNOW 3G Plaintext data not as expected");
4617 	} else {
4618 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4619 			ciphertext,
4620 			tdata->ciphertext.data,
4621 			tdata->validDataLenInBits.len,
4622 			"SNOW 3G Ciphertext data not as expected");
4623 
4624 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
4625 			ut_params->digest,
4626 			tdata->digest.data,
4627 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4628 			"SNOW 3G Generated auth tag not as expected");
4629 	}
4630 	return 0;
4631 }
4632 
4633 static int
4634 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
4635 	uint8_t op_mode, uint8_t verify)
4636 {
4637 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4638 	struct crypto_unittest_params *ut_params = &unittest_params;
4639 
4640 	int retval;
4641 
4642 	const uint8_t *plaintext = NULL;
4643 	const uint8_t *ciphertext = NULL;
4644 	const uint8_t *digest = NULL;
4645 	unsigned int plaintext_pad_len;
4646 	unsigned int plaintext_len;
4647 	unsigned int ciphertext_pad_len;
4648 	unsigned int ciphertext_len;
4649 	uint8_t buffer[10000];
4650 	uint8_t digest_buffer[10000];
4651 
4652 	struct rte_cryptodev_info dev_info;
4653 
4654 	/* Verify the capabilities */
4655 	struct rte_cryptodev_sym_capability_idx cap_idx;
4656 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4657 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4658 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4659 			&cap_idx) == NULL)
4660 		return -ENOTSUP;
4661 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4662 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4663 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4664 			&cap_idx) == NULL)
4665 		return -ENOTSUP;
4666 
4667 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4668 
4669 	uint64_t feat_flags = dev_info.feature_flags;
4670 
4671 	if (op_mode == IN_PLACE) {
4672 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
4673 			printf("Device doesn't support in-place scatter-gather "
4674 					"in both input and output mbufs.\n");
4675 			return -ENOTSUP;
4676 		}
4677 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4678 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4679 			printf("Device doesn't support RAW data-path APIs.\n");
4680 			return -ENOTSUP;
4681 		}
4682 	} else {
4683 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4684 			return -ENOTSUP;
4685 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4686 			printf("Device doesn't support out-of-place scatter-gather "
4687 					"in both input and output mbufs.\n");
4688 			return -ENOTSUP;
4689 		}
4690 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4691 			printf("Device doesn't support digest encrypted.\n");
4692 			return -ENOTSUP;
4693 		}
4694 	}
4695 
4696 	/* Create SNOW 3G session */
4697 	retval = create_wireless_algo_auth_cipher_session(
4698 			ts_params->valid_devs[0],
4699 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4700 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4701 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4702 					: RTE_CRYPTO_AUTH_OP_GENERATE),
4703 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4704 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4705 			tdata->key.data, tdata->key.len,
4706 			tdata->auth_iv.len, tdata->digest.len,
4707 			tdata->cipher_iv.len);
4708 
4709 	if (retval < 0)
4710 		return retval;
4711 
4712 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4713 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4714 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4715 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4716 
4717 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4718 			plaintext_pad_len, 15, 0);
4719 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4720 			"Failed to allocate input buffer in mempool");
4721 
4722 	if (op_mode == OUT_OF_PLACE) {
4723 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4724 				plaintext_pad_len, 15, 0);
4725 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
4726 				"Failed to allocate output buffer in mempool");
4727 	}
4728 
4729 	if (verify) {
4730 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
4731 			tdata->ciphertext.data);
4732 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4733 					ciphertext_len, buffer);
4734 		debug_hexdump(stdout, "ciphertext:", ciphertext,
4735 			ciphertext_len);
4736 	} else {
4737 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
4738 			tdata->plaintext.data);
4739 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
4740 					plaintext_len, buffer);
4741 		debug_hexdump(stdout, "plaintext:", plaintext,
4742 			plaintext_len);
4743 	}
4744 	memset(buffer, 0, sizeof(buffer));
4745 
4746 	/* Create SNOW 3G operation */
4747 	retval = create_wireless_algo_auth_cipher_operation(
4748 		tdata->digest.data, tdata->digest.len,
4749 		tdata->cipher_iv.data, tdata->cipher_iv.len,
4750 		tdata->auth_iv.data, tdata->auth_iv.len,
4751 		(tdata->digest.offset_bytes == 0 ?
4752 		(verify ? ciphertext_pad_len : plaintext_pad_len)
4753 			: tdata->digest.offset_bytes),
4754 		tdata->validCipherLenInBits.len,
4755 		tdata->cipher.offset_bits,
4756 		tdata->validAuthLenInBits.len,
4757 		tdata->auth.offset_bits,
4758 		op_mode, 1, verify);
4759 
4760 	if (retval < 0)
4761 		return retval;
4762 
4763 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4764 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4765 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4766 	else
4767 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4768 			ut_params->op);
4769 
4770 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4771 
4772 	ut_params->obuf = (op_mode == IN_PLACE ?
4773 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4774 
4775 	if (verify) {
4776 		if (ut_params->obuf)
4777 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
4778 					plaintext_len, buffer);
4779 		else
4780 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
4781 					plaintext_len, buffer);
4782 
4783 		debug_hexdump(stdout, "plaintext:", plaintext,
4784 			(tdata->plaintext.len >> 3) - tdata->digest.len);
4785 		debug_hexdump(stdout, "plaintext expected:",
4786 			tdata->plaintext.data,
4787 			(tdata->plaintext.len >> 3) - tdata->digest.len);
4788 	} else {
4789 		if (ut_params->obuf)
4790 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4791 					ciphertext_len, buffer);
4792 		else
4793 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4794 					ciphertext_len, buffer);
4795 
4796 		debug_hexdump(stdout, "ciphertext:", ciphertext,
4797 			ciphertext_len);
4798 		debug_hexdump(stdout, "ciphertext expected:",
4799 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
4800 
4801 		if (ut_params->obuf)
4802 			digest = rte_pktmbuf_read(ut_params->obuf,
4803 				(tdata->digest.offset_bytes == 0 ?
4804 				plaintext_pad_len : tdata->digest.offset_bytes),
4805 				tdata->digest.len, digest_buffer);
4806 		else
4807 			digest = rte_pktmbuf_read(ut_params->ibuf,
4808 				(tdata->digest.offset_bytes == 0 ?
4809 				plaintext_pad_len : tdata->digest.offset_bytes),
4810 				tdata->digest.len, digest_buffer);
4811 
4812 		debug_hexdump(stdout, "digest:", digest,
4813 			tdata->digest.len);
4814 		debug_hexdump(stdout, "digest expected:",
4815 			tdata->digest.data, tdata->digest.len);
4816 	}
4817 
4818 	/* Validate obuf */
4819 	if (verify) {
4820 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4821 			plaintext,
4822 			tdata->plaintext.data,
4823 			tdata->plaintext.len >> 3,
4824 			"SNOW 3G Plaintext data not as expected");
4825 	} else {
4826 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4827 			ciphertext,
4828 			tdata->ciphertext.data,
4829 			tdata->validDataLenInBits.len,
4830 			"SNOW 3G Ciphertext data not as expected");
4831 
4832 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
4833 			digest,
4834 			tdata->digest.data,
4835 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4836 			"SNOW 3G Generated auth tag not as expected");
4837 	}
4838 	return 0;
4839 }
4840 
4841 static int
4842 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
4843 	uint8_t op_mode, uint8_t verify)
4844 {
4845 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4846 	struct crypto_unittest_params *ut_params = &unittest_params;
4847 
4848 	int retval;
4849 
4850 	uint8_t *plaintext = NULL, *ciphertext = NULL;
4851 	unsigned int plaintext_pad_len;
4852 	unsigned int plaintext_len;
4853 	unsigned int ciphertext_pad_len;
4854 	unsigned int ciphertext_len;
4855 
4856 	struct rte_cryptodev_info dev_info;
4857 
4858 	/* Verify the capabilities */
4859 	struct rte_cryptodev_sym_capability_idx cap_idx;
4860 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4861 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
4862 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4863 			&cap_idx) == NULL)
4864 		return -ENOTSUP;
4865 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4866 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4867 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4868 			&cap_idx) == NULL)
4869 		return -ENOTSUP;
4870 
4871 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4872 
4873 	uint64_t feat_flags = dev_info.feature_flags;
4874 
4875 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4876 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4877 		printf("Device doesn't support RAW data-path APIs.\n");
4878 		return -ENOTSUP;
4879 	}
4880 
4881 	if (op_mode == OUT_OF_PLACE) {
4882 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4883 			return -ENOTSUP;
4884 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4885 			printf("Device doesn't support digest encrypted.\n");
4886 			return -ENOTSUP;
4887 		}
4888 	}
4889 
4890 	/* Create KASUMI session */
4891 	retval = create_wireless_algo_auth_cipher_session(
4892 			ts_params->valid_devs[0],
4893 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4894 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4895 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4896 					: RTE_CRYPTO_AUTH_OP_GENERATE),
4897 			RTE_CRYPTO_AUTH_KASUMI_F9,
4898 			RTE_CRYPTO_CIPHER_KASUMI_F8,
4899 			tdata->key.data, tdata->key.len,
4900 			0, tdata->digest.len,
4901 			tdata->cipher_iv.len);
4902 
4903 	if (retval < 0)
4904 		return retval;
4905 
4906 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4907 	if (op_mode == OUT_OF_PLACE)
4908 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4909 
4910 	/* clear mbuf payload */
4911 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4912 		rte_pktmbuf_tailroom(ut_params->ibuf));
4913 	if (op_mode == OUT_OF_PLACE)
4914 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4915 			rte_pktmbuf_tailroom(ut_params->obuf));
4916 
4917 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4918 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4919 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4920 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4921 
4922 	if (verify) {
4923 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4924 					ciphertext_pad_len);
4925 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4926 		if (op_mode == OUT_OF_PLACE)
4927 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4928 		debug_hexdump(stdout, "ciphertext:", ciphertext,
4929 			ciphertext_len);
4930 	} else {
4931 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4932 					plaintext_pad_len);
4933 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4934 		if (op_mode == OUT_OF_PLACE)
4935 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4936 		debug_hexdump(stdout, "plaintext:", plaintext,
4937 			plaintext_len);
4938 	}
4939 
4940 	/* Create KASUMI operation */
4941 	retval = create_wireless_algo_auth_cipher_operation(
4942 		tdata->digest.data, tdata->digest.len,
4943 		tdata->cipher_iv.data, tdata->cipher_iv.len,
4944 		NULL, 0,
4945 		(tdata->digest.offset_bytes == 0 ?
4946 		(verify ? ciphertext_pad_len : plaintext_pad_len)
4947 			: tdata->digest.offset_bytes),
4948 		tdata->validCipherLenInBits.len,
4949 		tdata->validCipherOffsetInBits.len,
4950 		tdata->validAuthLenInBits.len,
4951 		0,
4952 		op_mode, 0, verify);
4953 
4954 	if (retval < 0)
4955 		return retval;
4956 
4957 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4958 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4959 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4960 	else
4961 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4962 			ut_params->op);
4963 
4964 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4965 
4966 	ut_params->obuf = (op_mode == IN_PLACE ?
4967 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4968 
4969 
4970 	if (verify) {
4971 		if (ut_params->obuf)
4972 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
4973 							uint8_t *);
4974 		else
4975 			plaintext = ciphertext;
4976 
4977 		debug_hexdump(stdout, "plaintext:", plaintext,
4978 			(tdata->plaintext.len >> 3) - tdata->digest.len);
4979 		debug_hexdump(stdout, "plaintext expected:",
4980 			tdata->plaintext.data,
4981 			(tdata->plaintext.len >> 3) - tdata->digest.len);
4982 	} else {
4983 		if (ut_params->obuf)
4984 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
4985 							uint8_t *);
4986 		else
4987 			ciphertext = plaintext;
4988 
4989 		debug_hexdump(stdout, "ciphertext:", ciphertext,
4990 			ciphertext_len);
4991 		debug_hexdump(stdout, "ciphertext expected:",
4992 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
4993 
4994 		ut_params->digest = rte_pktmbuf_mtod(
4995 			ut_params->obuf, uint8_t *) +
4996 			(tdata->digest.offset_bytes == 0 ?
4997 			plaintext_pad_len : tdata->digest.offset_bytes);
4998 
4999 		debug_hexdump(stdout, "digest:", ut_params->digest,
5000 			tdata->digest.len);
5001 		debug_hexdump(stdout, "digest expected:",
5002 			tdata->digest.data, tdata->digest.len);
5003 	}
5004 
5005 	/* Validate obuf */
5006 	if (verify) {
5007 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5008 			plaintext,
5009 			tdata->plaintext.data,
5010 			tdata->plaintext.len >> 3,
5011 			"KASUMI Plaintext data not as expected");
5012 	} else {
5013 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5014 			ciphertext,
5015 			tdata->ciphertext.data,
5016 			tdata->ciphertext.len >> 3,
5017 			"KASUMI Ciphertext data not as expected");
5018 
5019 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5020 			ut_params->digest,
5021 			tdata->digest.data,
5022 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5023 			"KASUMI Generated auth tag not as expected");
5024 	}
5025 	return 0;
5026 }
5027 
5028 static int
5029 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5030 	uint8_t op_mode, uint8_t verify)
5031 {
5032 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5033 	struct crypto_unittest_params *ut_params = &unittest_params;
5034 
5035 	int retval;
5036 
5037 	const uint8_t *plaintext = NULL;
5038 	const uint8_t *ciphertext = NULL;
5039 	const uint8_t *digest = NULL;
5040 	unsigned int plaintext_pad_len;
5041 	unsigned int plaintext_len;
5042 	unsigned int ciphertext_pad_len;
5043 	unsigned int ciphertext_len;
5044 	uint8_t buffer[10000];
5045 	uint8_t digest_buffer[10000];
5046 
5047 	struct rte_cryptodev_info dev_info;
5048 
5049 	/* Verify the capabilities */
5050 	struct rte_cryptodev_sym_capability_idx cap_idx;
5051 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5052 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5053 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5054 			&cap_idx) == NULL)
5055 		return -ENOTSUP;
5056 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5057 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5058 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5059 			&cap_idx) == NULL)
5060 		return -ENOTSUP;
5061 
5062 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5063 
5064 	uint64_t feat_flags = dev_info.feature_flags;
5065 
5066 	if (op_mode == IN_PLACE) {
5067 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5068 			printf("Device doesn't support in-place scatter-gather "
5069 					"in both input and output mbufs.\n");
5070 			return -ENOTSUP;
5071 		}
5072 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5073 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5074 			printf("Device doesn't support RAW data-path APIs.\n");
5075 			return -ENOTSUP;
5076 		}
5077 	} else {
5078 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5079 			return -ENOTSUP;
5080 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5081 			printf("Device doesn't support out-of-place scatter-gather "
5082 					"in both input and output mbufs.\n");
5083 			return -ENOTSUP;
5084 		}
5085 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5086 			printf("Device doesn't support digest encrypted.\n");
5087 			return -ENOTSUP;
5088 		}
5089 	}
5090 
5091 	/* Create KASUMI session */
5092 	retval = create_wireless_algo_auth_cipher_session(
5093 			ts_params->valid_devs[0],
5094 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5095 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5096 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5097 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5098 			RTE_CRYPTO_AUTH_KASUMI_F9,
5099 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5100 			tdata->key.data, tdata->key.len,
5101 			0, tdata->digest.len,
5102 			tdata->cipher_iv.len);
5103 
5104 	if (retval < 0)
5105 		return retval;
5106 
5107 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5108 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5109 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5110 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5111 
5112 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5113 			plaintext_pad_len, 15, 0);
5114 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5115 			"Failed to allocate input buffer in mempool");
5116 
5117 	if (op_mode == OUT_OF_PLACE) {
5118 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5119 				plaintext_pad_len, 15, 0);
5120 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5121 				"Failed to allocate output buffer in mempool");
5122 	}
5123 
5124 	if (verify) {
5125 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5126 			tdata->ciphertext.data);
5127 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5128 					ciphertext_len, buffer);
5129 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5130 			ciphertext_len);
5131 	} else {
5132 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5133 			tdata->plaintext.data);
5134 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5135 					plaintext_len, buffer);
5136 		debug_hexdump(stdout, "plaintext:", plaintext,
5137 			plaintext_len);
5138 	}
5139 	memset(buffer, 0, sizeof(buffer));
5140 
5141 	/* Create KASUMI operation */
5142 	retval = create_wireless_algo_auth_cipher_operation(
5143 		tdata->digest.data, tdata->digest.len,
5144 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5145 		NULL, 0,
5146 		(tdata->digest.offset_bytes == 0 ?
5147 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5148 			: tdata->digest.offset_bytes),
5149 		tdata->validCipherLenInBits.len,
5150 		tdata->validCipherOffsetInBits.len,
5151 		tdata->validAuthLenInBits.len,
5152 		0,
5153 		op_mode, 1, verify);
5154 
5155 	if (retval < 0)
5156 		return retval;
5157 
5158 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5159 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5160 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5161 	else
5162 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5163 			ut_params->op);
5164 
5165 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5166 
5167 	ut_params->obuf = (op_mode == IN_PLACE ?
5168 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5169 
5170 	if (verify) {
5171 		if (ut_params->obuf)
5172 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5173 					plaintext_len, buffer);
5174 		else
5175 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5176 					plaintext_len, buffer);
5177 
5178 		debug_hexdump(stdout, "plaintext:", plaintext,
5179 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5180 		debug_hexdump(stdout, "plaintext expected:",
5181 			tdata->plaintext.data,
5182 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5183 	} else {
5184 		if (ut_params->obuf)
5185 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5186 					ciphertext_len, buffer);
5187 		else
5188 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5189 					ciphertext_len, buffer);
5190 
5191 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5192 			ciphertext_len);
5193 		debug_hexdump(stdout, "ciphertext expected:",
5194 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5195 
5196 		if (ut_params->obuf)
5197 			digest = rte_pktmbuf_read(ut_params->obuf,
5198 				(tdata->digest.offset_bytes == 0 ?
5199 				plaintext_pad_len : tdata->digest.offset_bytes),
5200 				tdata->digest.len, digest_buffer);
5201 		else
5202 			digest = rte_pktmbuf_read(ut_params->ibuf,
5203 				(tdata->digest.offset_bytes == 0 ?
5204 				plaintext_pad_len : tdata->digest.offset_bytes),
5205 				tdata->digest.len, digest_buffer);
5206 
5207 		debug_hexdump(stdout, "digest:", digest,
5208 			tdata->digest.len);
5209 		debug_hexdump(stdout, "digest expected:",
5210 			tdata->digest.data, tdata->digest.len);
5211 	}
5212 
5213 	/* Validate obuf */
5214 	if (verify) {
5215 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5216 			plaintext,
5217 			tdata->plaintext.data,
5218 			tdata->plaintext.len >> 3,
5219 			"KASUMI Plaintext data not as expected");
5220 	} else {
5221 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5222 			ciphertext,
5223 			tdata->ciphertext.data,
5224 			tdata->validDataLenInBits.len,
5225 			"KASUMI Ciphertext data not as expected");
5226 
5227 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5228 			digest,
5229 			tdata->digest.data,
5230 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5231 			"KASUMI Generated auth tag not as expected");
5232 	}
5233 	return 0;
5234 }
5235 
5236 static int
5237 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5238 {
5239 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5240 	struct crypto_unittest_params *ut_params = &unittest_params;
5241 
5242 	int retval;
5243 
5244 	uint8_t *plaintext, *ciphertext;
5245 	unsigned plaintext_pad_len;
5246 	unsigned plaintext_len;
5247 	struct rte_cryptodev_info dev_info;
5248 
5249 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5250 	uint64_t feat_flags = dev_info.feature_flags;
5251 
5252 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5253 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5254 		printf("Device doesn't support RAW data-path APIs.\n");
5255 		return -ENOTSUP;
5256 	}
5257 
5258 	/* Verify the capabilities */
5259 	struct rte_cryptodev_sym_capability_idx cap_idx;
5260 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5261 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5262 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5263 			&cap_idx) == NULL)
5264 		return -ENOTSUP;
5265 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5266 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5267 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5268 			&cap_idx) == NULL)
5269 		return -ENOTSUP;
5270 
5271 	/* Create KASUMI session */
5272 	retval = create_wireless_algo_cipher_auth_session(
5273 			ts_params->valid_devs[0],
5274 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5275 			RTE_CRYPTO_AUTH_OP_GENERATE,
5276 			RTE_CRYPTO_AUTH_KASUMI_F9,
5277 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5278 			tdata->key.data, tdata->key.len,
5279 			0, tdata->digest.len,
5280 			tdata->cipher_iv.len);
5281 	if (retval < 0)
5282 		return retval;
5283 
5284 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5285 
5286 	/* clear mbuf payload */
5287 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5288 			rte_pktmbuf_tailroom(ut_params->ibuf));
5289 
5290 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5291 	/* Append data which is padded to a multiple of */
5292 	/* the algorithms block size */
5293 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5294 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5295 				plaintext_pad_len);
5296 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5297 
5298 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5299 
5300 	/* Create KASUMI operation */
5301 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5302 				tdata->digest.len, NULL, 0,
5303 				plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5304 				tdata->cipher_iv.data, tdata->cipher_iv.len,
5305 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5306 				tdata->validCipherOffsetInBits.len,
5307 				tdata->validAuthLenInBits.len,
5308 				0
5309 				);
5310 	if (retval < 0)
5311 		return retval;
5312 
5313 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5314 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5315 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5316 	else
5317 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5318 			ut_params->op);
5319 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5320 
5321 	if (ut_params->op->sym->m_dst)
5322 		ut_params->obuf = ut_params->op->sym->m_dst;
5323 	else
5324 		ut_params->obuf = ut_params->op->sym->m_src;
5325 
5326 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5327 				tdata->validCipherOffsetInBits.len >> 3);
5328 
5329 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5330 			+ plaintext_pad_len;
5331 
5332 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5333 				(tdata->validCipherOffsetInBits.len >> 3);
5334 	/* Validate obuf */
5335 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5336 		ciphertext,
5337 		reference_ciphertext,
5338 		tdata->validCipherLenInBits.len,
5339 		"KASUMI Ciphertext data not as expected");
5340 
5341 	/* Validate obuf */
5342 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
5343 		ut_params->digest,
5344 		tdata->digest.data,
5345 		DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5346 		"KASUMI Generated auth tag not as expected");
5347 	return 0;
5348 }
5349 
5350 static int
5351 test_zuc_encryption(const struct wireless_test_data *tdata)
5352 {
5353 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5354 	struct crypto_unittest_params *ut_params = &unittest_params;
5355 
5356 	int retval;
5357 	uint8_t *plaintext, *ciphertext;
5358 	unsigned plaintext_pad_len;
5359 	unsigned plaintext_len;
5360 	struct rte_cryptodev_info dev_info;
5361 
5362 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5363 	uint64_t feat_flags = dev_info.feature_flags;
5364 
5365 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5366 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5367 		printf("Device doesn't support RAW data-path APIs.\n");
5368 		return -ENOTSUP;
5369 	}
5370 
5371 	struct rte_cryptodev_sym_capability_idx cap_idx;
5372 
5373 	/* Check if device supports ZUC EEA3 */
5374 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5375 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5376 
5377 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5378 			&cap_idx) == NULL)
5379 		return -ENOTSUP;
5380 
5381 	/* Create ZUC session */
5382 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5383 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5384 					RTE_CRYPTO_CIPHER_ZUC_EEA3,
5385 					tdata->key.data, tdata->key.len,
5386 					tdata->cipher_iv.len);
5387 	if (retval < 0)
5388 		return retval;
5389 
5390 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5391 
5392 	/* Clear mbuf payload */
5393 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5394 	       rte_pktmbuf_tailroom(ut_params->ibuf));
5395 
5396 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5397 	/* Append data which is padded to a multiple */
5398 	/* of the algorithms block size */
5399 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5400 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5401 				plaintext_pad_len);
5402 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5403 
5404 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5405 
5406 	/* Create ZUC operation */
5407 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5408 					tdata->cipher_iv.len,
5409 					tdata->plaintext.len,
5410 					0);
5411 	if (retval < 0)
5412 		return retval;
5413 
5414 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5415 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5416 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5417 	else
5418 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5419 						ut_params->op);
5420 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5421 
5422 	ut_params->obuf = ut_params->op->sym->m_dst;
5423 	if (ut_params->obuf)
5424 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5425 	else
5426 		ciphertext = plaintext;
5427 
5428 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5429 
5430 	/* Validate obuf */
5431 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5432 		ciphertext,
5433 		tdata->ciphertext.data,
5434 		tdata->validCipherLenInBits.len,
5435 		"ZUC Ciphertext data not as expected");
5436 	return 0;
5437 }
5438 
5439 static int
5440 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
5441 {
5442 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5443 	struct crypto_unittest_params *ut_params = &unittest_params;
5444 
5445 	int retval;
5446 
5447 	unsigned int plaintext_pad_len;
5448 	unsigned int plaintext_len;
5449 	const uint8_t *ciphertext;
5450 	uint8_t ciphertext_buffer[2048];
5451 	struct rte_cryptodev_info dev_info;
5452 
5453 	struct rte_cryptodev_sym_capability_idx cap_idx;
5454 
5455 	/* Check if device supports ZUC EEA3 */
5456 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5457 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5458 
5459 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5460 			&cap_idx) == NULL)
5461 		return -ENOTSUP;
5462 
5463 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5464 
5465 	uint64_t feat_flags = dev_info.feature_flags;
5466 
5467 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5468 		printf("Device doesn't support in-place scatter-gather. "
5469 				"Test Skipped.\n");
5470 		return -ENOTSUP;
5471 	}
5472 
5473 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5474 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5475 		printf("Device doesn't support RAW data-path APIs.\n");
5476 		return -ENOTSUP;
5477 	}
5478 
5479 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5480 
5481 	/* Append data which is padded to a multiple */
5482 	/* of the algorithms block size */
5483 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5484 
5485 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5486 			plaintext_pad_len, 10, 0);
5487 
5488 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5489 			tdata->plaintext.data);
5490 
5491 	/* Create ZUC session */
5492 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5493 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5494 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
5495 			tdata->key.data, tdata->key.len,
5496 			tdata->cipher_iv.len);
5497 	if (retval < 0)
5498 		return retval;
5499 
5500 	/* Clear mbuf payload */
5501 
5502 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
5503 
5504 	/* Create ZUC operation */
5505 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5506 			tdata->cipher_iv.len, tdata->plaintext.len,
5507 			0);
5508 	if (retval < 0)
5509 		return retval;
5510 
5511 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5512 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5513 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5514 	else
5515 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5516 						ut_params->op);
5517 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5518 
5519 	ut_params->obuf = ut_params->op->sym->m_dst;
5520 	if (ut_params->obuf)
5521 		ciphertext = rte_pktmbuf_read(ut_params->obuf,
5522 			0, plaintext_len, ciphertext_buffer);
5523 	else
5524 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
5525 			0, plaintext_len, ciphertext_buffer);
5526 
5527 	/* Validate obuf */
5528 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5529 
5530 	/* Validate obuf */
5531 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5532 		ciphertext,
5533 		tdata->ciphertext.data,
5534 		tdata->validCipherLenInBits.len,
5535 		"ZUC Ciphertext data not as expected");
5536 
5537 	return 0;
5538 }
5539 
5540 static int
5541 test_zuc_authentication(const struct wireless_test_data *tdata)
5542 {
5543 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5544 	struct crypto_unittest_params *ut_params = &unittest_params;
5545 
5546 	int retval;
5547 	unsigned plaintext_pad_len;
5548 	unsigned plaintext_len;
5549 	uint8_t *plaintext;
5550 
5551 	struct rte_cryptodev_sym_capability_idx cap_idx;
5552 	struct rte_cryptodev_info dev_info;
5553 
5554 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5555 	uint64_t feat_flags = dev_info.feature_flags;
5556 
5557 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
5558 			(tdata->validAuthLenInBits.len % 8 != 0)) {
5559 		printf("Device doesn't support NON-Byte Aligned Data.\n");
5560 		return -ENOTSUP;
5561 	}
5562 
5563 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5564 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5565 		printf("Device doesn't support RAW data-path APIs.\n");
5566 		return -ENOTSUP;
5567 	}
5568 
5569 	/* Check if device supports ZUC EIA3 */
5570 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5571 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
5572 
5573 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5574 			&cap_idx) == NULL)
5575 		return -ENOTSUP;
5576 
5577 	/* Create ZUC session */
5578 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
5579 			tdata->key.data, tdata->key.len,
5580 			tdata->auth_iv.len, tdata->digest.len,
5581 			RTE_CRYPTO_AUTH_OP_GENERATE,
5582 			RTE_CRYPTO_AUTH_ZUC_EIA3);
5583 	if (retval < 0)
5584 		return retval;
5585 
5586 	/* alloc mbuf and set payload */
5587 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5588 
5589 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5590 	rte_pktmbuf_tailroom(ut_params->ibuf));
5591 
5592 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5593 	/* Append data which is padded to a multiple of */
5594 	/* the algorithms block size */
5595 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5596 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5597 				plaintext_pad_len);
5598 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5599 
5600 	/* Create ZUC operation */
5601 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
5602 			tdata->auth_iv.data, tdata->auth_iv.len,
5603 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5604 			tdata->validAuthLenInBits.len,
5605 			0);
5606 	if (retval < 0)
5607 		return retval;
5608 
5609 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5610 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5611 				ut_params->op, 0, 1, 1, 0);
5612 	else
5613 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5614 				ut_params->op);
5615 	ut_params->obuf = ut_params->op->sym->m_src;
5616 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5617 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5618 			+ plaintext_pad_len;
5619 
5620 	/* Validate obuf */
5621 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
5622 	ut_params->digest,
5623 	tdata->digest.data,
5624 	tdata->digest.len,
5625 	"ZUC Generated auth tag not as expected");
5626 
5627 	return 0;
5628 }
5629 
5630 static int
5631 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
5632 	uint8_t op_mode, uint8_t verify)
5633 {
5634 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5635 	struct crypto_unittest_params *ut_params = &unittest_params;
5636 
5637 	int retval;
5638 
5639 	uint8_t *plaintext = NULL, *ciphertext = NULL;
5640 	unsigned int plaintext_pad_len;
5641 	unsigned int plaintext_len;
5642 	unsigned int ciphertext_pad_len;
5643 	unsigned int ciphertext_len;
5644 
5645 	struct rte_cryptodev_info dev_info;
5646 	struct rte_cryptodev_sym_capability_idx cap_idx;
5647 
5648 	/* Check if device supports ZUC EIA3 */
5649 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5650 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
5651 
5652 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5653 			&cap_idx) == NULL)
5654 		return -ENOTSUP;
5655 
5656 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5657 
5658 	uint64_t feat_flags = dev_info.feature_flags;
5659 
5660 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5661 		printf("Device doesn't support digest encrypted.\n");
5662 		return -ENOTSUP;
5663 	}
5664 	if (op_mode == IN_PLACE) {
5665 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5666 			printf("Device doesn't support in-place scatter-gather "
5667 					"in both input and output mbufs.\n");
5668 			return -ENOTSUP;
5669 		}
5670 
5671 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5672 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5673 			printf("Device doesn't support RAW data-path APIs.\n");
5674 			return -ENOTSUP;
5675 		}
5676 	} else {
5677 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5678 			return -ENOTSUP;
5679 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5680 			printf("Device doesn't support out-of-place scatter-gather "
5681 					"in both input and output mbufs.\n");
5682 			return -ENOTSUP;
5683 		}
5684 	}
5685 
5686 	/* Create ZUC session */
5687 	retval = create_wireless_algo_auth_cipher_session(
5688 			ts_params->valid_devs[0],
5689 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5690 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5691 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5692 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5693 			RTE_CRYPTO_AUTH_ZUC_EIA3,
5694 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
5695 			tdata->key.data, tdata->key.len,
5696 			tdata->auth_iv.len, tdata->digest.len,
5697 			tdata->cipher_iv.len);
5698 
5699 	if (retval < 0)
5700 		return retval;
5701 
5702 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5703 	if (op_mode == OUT_OF_PLACE)
5704 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5705 
5706 	/* clear mbuf payload */
5707 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5708 		rte_pktmbuf_tailroom(ut_params->ibuf));
5709 	if (op_mode == OUT_OF_PLACE)
5710 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5711 			rte_pktmbuf_tailroom(ut_params->obuf));
5712 
5713 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5714 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5715 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5716 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5717 
5718 	if (verify) {
5719 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5720 					ciphertext_pad_len);
5721 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5722 		if (op_mode == OUT_OF_PLACE)
5723 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5724 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5725 			ciphertext_len);
5726 	} else {
5727 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5728 					plaintext_pad_len);
5729 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5730 		if (op_mode == OUT_OF_PLACE)
5731 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5732 		debug_hexdump(stdout, "plaintext:", plaintext,
5733 			plaintext_len);
5734 	}
5735 
5736 	/* Create ZUC operation */
5737 	retval = create_wireless_algo_auth_cipher_operation(
5738 		tdata->digest.data, tdata->digest.len,
5739 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5740 		tdata->auth_iv.data, tdata->auth_iv.len,
5741 		(tdata->digest.offset_bytes == 0 ?
5742 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5743 			: tdata->digest.offset_bytes),
5744 		tdata->validCipherLenInBits.len,
5745 		tdata->validCipherOffsetInBits.len,
5746 		tdata->validAuthLenInBits.len,
5747 		0,
5748 		op_mode, 0, verify);
5749 
5750 	if (retval < 0)
5751 		return retval;
5752 
5753 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5754 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5755 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5756 	else
5757 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5758 			ut_params->op);
5759 
5760 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5761 
5762 	ut_params->obuf = (op_mode == IN_PLACE ?
5763 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5764 
5765 
5766 	if (verify) {
5767 		if (ut_params->obuf)
5768 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5769 							uint8_t *);
5770 		else
5771 			plaintext = ciphertext;
5772 
5773 		debug_hexdump(stdout, "plaintext:", plaintext,
5774 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5775 		debug_hexdump(stdout, "plaintext expected:",
5776 			tdata->plaintext.data,
5777 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5778 	} else {
5779 		if (ut_params->obuf)
5780 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5781 							uint8_t *);
5782 		else
5783 			ciphertext = plaintext;
5784 
5785 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5786 			ciphertext_len);
5787 		debug_hexdump(stdout, "ciphertext expected:",
5788 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5789 
5790 		ut_params->digest = rte_pktmbuf_mtod(
5791 			ut_params->obuf, uint8_t *) +
5792 			(tdata->digest.offset_bytes == 0 ?
5793 			plaintext_pad_len : tdata->digest.offset_bytes);
5794 
5795 		debug_hexdump(stdout, "digest:", ut_params->digest,
5796 			tdata->digest.len);
5797 		debug_hexdump(stdout, "digest expected:",
5798 			tdata->digest.data, tdata->digest.len);
5799 	}
5800 
5801 	/* Validate obuf */
5802 	if (verify) {
5803 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5804 			plaintext,
5805 			tdata->plaintext.data,
5806 			tdata->plaintext.len >> 3,
5807 			"ZUC Plaintext data not as expected");
5808 	} else {
5809 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5810 			ciphertext,
5811 			tdata->ciphertext.data,
5812 			tdata->ciphertext.len >> 3,
5813 			"ZUC Ciphertext data not as expected");
5814 
5815 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5816 			ut_params->digest,
5817 			tdata->digest.data,
5818 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5819 			"ZUC Generated auth tag not as expected");
5820 	}
5821 	return 0;
5822 }
5823 
5824 static int
5825 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
5826 	uint8_t op_mode, uint8_t verify)
5827 {
5828 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5829 	struct crypto_unittest_params *ut_params = &unittest_params;
5830 
5831 	int retval;
5832 
5833 	const uint8_t *plaintext = NULL;
5834 	const uint8_t *ciphertext = NULL;
5835 	const uint8_t *digest = NULL;
5836 	unsigned int plaintext_pad_len;
5837 	unsigned int plaintext_len;
5838 	unsigned int ciphertext_pad_len;
5839 	unsigned int ciphertext_len;
5840 	uint8_t buffer[10000];
5841 	uint8_t digest_buffer[10000];
5842 
5843 	struct rte_cryptodev_info dev_info;
5844 	struct rte_cryptodev_sym_capability_idx cap_idx;
5845 
5846 	/* Check if device supports ZUC EIA3 */
5847 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5848 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
5849 
5850 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5851 			&cap_idx) == NULL)
5852 		return -ENOTSUP;
5853 
5854 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5855 
5856 	uint64_t feat_flags = dev_info.feature_flags;
5857 
5858 	if (op_mode == IN_PLACE) {
5859 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5860 			printf("Device doesn't support in-place scatter-gather "
5861 					"in both input and output mbufs.\n");
5862 			return -ENOTSUP;
5863 		}
5864 
5865 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5866 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5867 			printf("Device doesn't support RAW data-path APIs.\n");
5868 			return -ENOTSUP;
5869 		}
5870 	} else {
5871 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5872 			return -ENOTSUP;
5873 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5874 			printf("Device doesn't support out-of-place scatter-gather "
5875 					"in both input and output mbufs.\n");
5876 			return -ENOTSUP;
5877 		}
5878 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5879 			printf("Device doesn't support digest encrypted.\n");
5880 			return -ENOTSUP;
5881 		}
5882 	}
5883 
5884 	/* Create ZUC session */
5885 	retval = create_wireless_algo_auth_cipher_session(
5886 			ts_params->valid_devs[0],
5887 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5888 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5889 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5890 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5891 			RTE_CRYPTO_AUTH_ZUC_EIA3,
5892 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
5893 			tdata->key.data, tdata->key.len,
5894 			tdata->auth_iv.len, tdata->digest.len,
5895 			tdata->cipher_iv.len);
5896 
5897 	if (retval < 0)
5898 		return retval;
5899 
5900 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5901 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5902 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5903 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5904 
5905 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5906 			plaintext_pad_len, 15, 0);
5907 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5908 			"Failed to allocate input buffer in mempool");
5909 
5910 	if (op_mode == OUT_OF_PLACE) {
5911 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5912 				plaintext_pad_len, 15, 0);
5913 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5914 				"Failed to allocate output buffer in mempool");
5915 	}
5916 
5917 	if (verify) {
5918 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5919 			tdata->ciphertext.data);
5920 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5921 					ciphertext_len, buffer);
5922 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5923 			ciphertext_len);
5924 	} else {
5925 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5926 			tdata->plaintext.data);
5927 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5928 					plaintext_len, buffer);
5929 		debug_hexdump(stdout, "plaintext:", plaintext,
5930 			plaintext_len);
5931 	}
5932 	memset(buffer, 0, sizeof(buffer));
5933 
5934 	/* Create ZUC operation */
5935 	retval = create_wireless_algo_auth_cipher_operation(
5936 		tdata->digest.data, tdata->digest.len,
5937 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5938 		NULL, 0,
5939 		(tdata->digest.offset_bytes == 0 ?
5940 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5941 			: tdata->digest.offset_bytes),
5942 		tdata->validCipherLenInBits.len,
5943 		tdata->validCipherOffsetInBits.len,
5944 		tdata->validAuthLenInBits.len,
5945 		0,
5946 		op_mode, 1, verify);
5947 
5948 	if (retval < 0)
5949 		return retval;
5950 
5951 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5952 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5953 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5954 	else
5955 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5956 			ut_params->op);
5957 
5958 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5959 
5960 	ut_params->obuf = (op_mode == IN_PLACE ?
5961 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5962 
5963 	if (verify) {
5964 		if (ut_params->obuf)
5965 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5966 					plaintext_len, buffer);
5967 		else
5968 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5969 					plaintext_len, buffer);
5970 
5971 		debug_hexdump(stdout, "plaintext:", plaintext,
5972 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5973 		debug_hexdump(stdout, "plaintext expected:",
5974 			tdata->plaintext.data,
5975 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5976 	} else {
5977 		if (ut_params->obuf)
5978 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5979 					ciphertext_len, buffer);
5980 		else
5981 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5982 					ciphertext_len, buffer);
5983 
5984 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5985 			ciphertext_len);
5986 		debug_hexdump(stdout, "ciphertext expected:",
5987 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5988 
5989 		if (ut_params->obuf)
5990 			digest = rte_pktmbuf_read(ut_params->obuf,
5991 				(tdata->digest.offset_bytes == 0 ?
5992 				plaintext_pad_len : tdata->digest.offset_bytes),
5993 				tdata->digest.len, digest_buffer);
5994 		else
5995 			digest = rte_pktmbuf_read(ut_params->ibuf,
5996 				(tdata->digest.offset_bytes == 0 ?
5997 				plaintext_pad_len : tdata->digest.offset_bytes),
5998 				tdata->digest.len, digest_buffer);
5999 
6000 		debug_hexdump(stdout, "digest:", digest,
6001 			tdata->digest.len);
6002 		debug_hexdump(stdout, "digest expected:",
6003 			tdata->digest.data, tdata->digest.len);
6004 	}
6005 
6006 	/* Validate obuf */
6007 	if (verify) {
6008 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6009 			plaintext,
6010 			tdata->plaintext.data,
6011 			tdata->plaintext.len >> 3,
6012 			"ZUC Plaintext data not as expected");
6013 	} else {
6014 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6015 			ciphertext,
6016 			tdata->ciphertext.data,
6017 			tdata->validDataLenInBits.len,
6018 			"ZUC Ciphertext data not as expected");
6019 
6020 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6021 			digest,
6022 			tdata->digest.data,
6023 			DIGEST_BYTE_LENGTH_KASUMI_F9,
6024 			"ZUC Generated auth tag not as expected");
6025 	}
6026 	return 0;
6027 }
6028 
6029 static int
6030 test_kasumi_encryption_test_case_1(void)
6031 {
6032 	return test_kasumi_encryption(&kasumi_test_case_1);
6033 }
6034 
6035 static int
6036 test_kasumi_encryption_test_case_1_sgl(void)
6037 {
6038 	return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6039 }
6040 
6041 static int
6042 test_kasumi_encryption_test_case_1_oop(void)
6043 {
6044 	return test_kasumi_encryption_oop(&kasumi_test_case_1);
6045 }
6046 
6047 static int
6048 test_kasumi_encryption_test_case_1_oop_sgl(void)
6049 {
6050 	return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6051 }
6052 
6053 static int
6054 test_kasumi_encryption_test_case_2(void)
6055 {
6056 	return test_kasumi_encryption(&kasumi_test_case_2);
6057 }
6058 
6059 static int
6060 test_kasumi_encryption_test_case_3(void)
6061 {
6062 	return test_kasumi_encryption(&kasumi_test_case_3);
6063 }
6064 
6065 static int
6066 test_kasumi_encryption_test_case_4(void)
6067 {
6068 	return test_kasumi_encryption(&kasumi_test_case_4);
6069 }
6070 
6071 static int
6072 test_kasumi_encryption_test_case_5(void)
6073 {
6074 	return test_kasumi_encryption(&kasumi_test_case_5);
6075 }
6076 
6077 static int
6078 test_kasumi_decryption_test_case_1(void)
6079 {
6080 	return test_kasumi_decryption(&kasumi_test_case_1);
6081 }
6082 
6083 static int
6084 test_kasumi_decryption_test_case_1_oop(void)
6085 {
6086 	return test_kasumi_decryption_oop(&kasumi_test_case_1);
6087 }
6088 
6089 static int
6090 test_kasumi_decryption_test_case_2(void)
6091 {
6092 	return test_kasumi_decryption(&kasumi_test_case_2);
6093 }
6094 
6095 static int
6096 test_kasumi_decryption_test_case_3(void)
6097 {
6098 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6099 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6100 		return -ENOTSUP;
6101 	return test_kasumi_decryption(&kasumi_test_case_3);
6102 }
6103 
6104 static int
6105 test_kasumi_decryption_test_case_4(void)
6106 {
6107 	return test_kasumi_decryption(&kasumi_test_case_4);
6108 }
6109 
6110 static int
6111 test_kasumi_decryption_test_case_5(void)
6112 {
6113 	return test_kasumi_decryption(&kasumi_test_case_5);
6114 }
6115 static int
6116 test_snow3g_encryption_test_case_1(void)
6117 {
6118 	return test_snow3g_encryption(&snow3g_test_case_1);
6119 }
6120 
6121 static int
6122 test_snow3g_encryption_test_case_1_oop(void)
6123 {
6124 	return test_snow3g_encryption_oop(&snow3g_test_case_1);
6125 }
6126 
6127 static int
6128 test_snow3g_encryption_test_case_1_oop_sgl(void)
6129 {
6130 	return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6131 }
6132 
6133 
6134 static int
6135 test_snow3g_encryption_test_case_1_offset_oop(void)
6136 {
6137 	return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6138 }
6139 
6140 static int
6141 test_snow3g_encryption_test_case_2(void)
6142 {
6143 	return test_snow3g_encryption(&snow3g_test_case_2);
6144 }
6145 
6146 static int
6147 test_snow3g_encryption_test_case_3(void)
6148 {
6149 	return test_snow3g_encryption(&snow3g_test_case_3);
6150 }
6151 
6152 static int
6153 test_snow3g_encryption_test_case_4(void)
6154 {
6155 	return test_snow3g_encryption(&snow3g_test_case_4);
6156 }
6157 
6158 static int
6159 test_snow3g_encryption_test_case_5(void)
6160 {
6161 	return test_snow3g_encryption(&snow3g_test_case_5);
6162 }
6163 
6164 static int
6165 test_snow3g_decryption_test_case_1(void)
6166 {
6167 	return test_snow3g_decryption(&snow3g_test_case_1);
6168 }
6169 
6170 static int
6171 test_snow3g_decryption_test_case_1_oop(void)
6172 {
6173 	return test_snow3g_decryption_oop(&snow3g_test_case_1);
6174 }
6175 
6176 static int
6177 test_snow3g_decryption_test_case_2(void)
6178 {
6179 	return test_snow3g_decryption(&snow3g_test_case_2);
6180 }
6181 
6182 static int
6183 test_snow3g_decryption_test_case_3(void)
6184 {
6185 	return test_snow3g_decryption(&snow3g_test_case_3);
6186 }
6187 
6188 static int
6189 test_snow3g_decryption_test_case_4(void)
6190 {
6191 	return test_snow3g_decryption(&snow3g_test_case_4);
6192 }
6193 
6194 static int
6195 test_snow3g_decryption_test_case_5(void)
6196 {
6197 	return test_snow3g_decryption(&snow3g_test_case_5);
6198 }
6199 
6200 /*
6201  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6202  * Pattern digest from snow3g_test_data must be allocated as
6203  * 4 last bytes in plaintext.
6204  */
6205 static void
6206 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6207 		struct snow3g_hash_test_data *output)
6208 {
6209 	if ((pattern != NULL) && (output != NULL)) {
6210 		output->key.len = pattern->key.len;
6211 
6212 		memcpy(output->key.data,
6213 		pattern->key.data, pattern->key.len);
6214 
6215 		output->auth_iv.len = pattern->auth_iv.len;
6216 
6217 		memcpy(output->auth_iv.data,
6218 		pattern->auth_iv.data, pattern->auth_iv.len);
6219 
6220 		output->plaintext.len = pattern->plaintext.len;
6221 
6222 		memcpy(output->plaintext.data,
6223 		pattern->plaintext.data, pattern->plaintext.len >> 3);
6224 
6225 		output->digest.len = pattern->digest.len;
6226 
6227 		memcpy(output->digest.data,
6228 		&pattern->plaintext.data[pattern->digest.offset_bytes],
6229 		pattern->digest.len);
6230 
6231 		output->validAuthLenInBits.len =
6232 		pattern->validAuthLenInBits.len;
6233 	}
6234 }
6235 
6236 /*
6237  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6238  */
6239 static int
6240 test_snow3g_decryption_with_digest_test_case_1(void)
6241 {
6242 	struct snow3g_hash_test_data snow3g_hash_data;
6243 
6244 	/*
6245 	 * Function prepare data for hash veryfication test case.
6246 	 * Digest is allocated in 4 last bytes in plaintext, pattern.
6247 	 */
6248 	snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6249 
6250 	return test_snow3g_decryption(&snow3g_test_case_7) &
6251 			test_snow3g_authentication_verify(&snow3g_hash_data);
6252 }
6253 
6254 static int
6255 test_snow3g_cipher_auth_test_case_1(void)
6256 {
6257 	return test_snow3g_cipher_auth(&snow3g_test_case_3);
6258 }
6259 
6260 static int
6261 test_snow3g_auth_cipher_test_case_1(void)
6262 {
6263 	return test_snow3g_auth_cipher(
6264 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6265 }
6266 
6267 static int
6268 test_snow3g_auth_cipher_test_case_2(void)
6269 {
6270 	return test_snow3g_auth_cipher(
6271 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6272 }
6273 
6274 static int
6275 test_snow3g_auth_cipher_test_case_2_oop(void)
6276 {
6277 	return test_snow3g_auth_cipher(
6278 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6279 }
6280 
6281 static int
6282 test_snow3g_auth_cipher_part_digest_enc(void)
6283 {
6284 	return test_snow3g_auth_cipher(
6285 		&snow3g_auth_cipher_partial_digest_encryption,
6286 			IN_PLACE, 0);
6287 }
6288 
6289 static int
6290 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6291 {
6292 	return test_snow3g_auth_cipher(
6293 		&snow3g_auth_cipher_partial_digest_encryption,
6294 			OUT_OF_PLACE, 0);
6295 }
6296 
6297 static int
6298 test_snow3g_auth_cipher_test_case_3_sgl(void)
6299 {
6300 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6301 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6302 		return -ENOTSUP;
6303 	return test_snow3g_auth_cipher_sgl(
6304 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6305 }
6306 
6307 static int
6308 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6309 {
6310 	return test_snow3g_auth_cipher_sgl(
6311 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6312 }
6313 
6314 static int
6315 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6316 {
6317 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6318 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6319 		return -ENOTSUP;
6320 	return test_snow3g_auth_cipher_sgl(
6321 		&snow3g_auth_cipher_partial_digest_encryption,
6322 			IN_PLACE, 0);
6323 }
6324 
6325 static int
6326 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6327 {
6328 	return test_snow3g_auth_cipher_sgl(
6329 		&snow3g_auth_cipher_partial_digest_encryption,
6330 			OUT_OF_PLACE, 0);
6331 }
6332 
6333 static int
6334 test_snow3g_auth_cipher_verify_test_case_1(void)
6335 {
6336 	return test_snow3g_auth_cipher(
6337 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6338 }
6339 
6340 static int
6341 test_snow3g_auth_cipher_verify_test_case_2(void)
6342 {
6343 	return test_snow3g_auth_cipher(
6344 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6345 }
6346 
6347 static int
6348 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6349 {
6350 	return test_snow3g_auth_cipher(
6351 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6352 }
6353 
6354 static int
6355 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6356 {
6357 	return test_snow3g_auth_cipher(
6358 		&snow3g_auth_cipher_partial_digest_encryption,
6359 			IN_PLACE, 1);
6360 }
6361 
6362 static int
6363 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
6364 {
6365 	return test_snow3g_auth_cipher(
6366 		&snow3g_auth_cipher_partial_digest_encryption,
6367 			OUT_OF_PLACE, 1);
6368 }
6369 
6370 static int
6371 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
6372 {
6373 	return test_snow3g_auth_cipher_sgl(
6374 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
6375 }
6376 
6377 static int
6378 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
6379 {
6380 	return test_snow3g_auth_cipher_sgl(
6381 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
6382 }
6383 
6384 static int
6385 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
6386 {
6387 	return test_snow3g_auth_cipher_sgl(
6388 		&snow3g_auth_cipher_partial_digest_encryption,
6389 			IN_PLACE, 1);
6390 }
6391 
6392 static int
6393 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
6394 {
6395 	return test_snow3g_auth_cipher_sgl(
6396 		&snow3g_auth_cipher_partial_digest_encryption,
6397 			OUT_OF_PLACE, 1);
6398 }
6399 
6400 static int
6401 test_snow3g_auth_cipher_with_digest_test_case_1(void)
6402 {
6403 	return test_snow3g_auth_cipher(
6404 		&snow3g_test_case_7, IN_PLACE, 0);
6405 }
6406 
6407 static int
6408 test_kasumi_auth_cipher_test_case_1(void)
6409 {
6410 	return test_kasumi_auth_cipher(
6411 		&kasumi_test_case_3, IN_PLACE, 0);
6412 }
6413 
6414 static int
6415 test_kasumi_auth_cipher_test_case_2(void)
6416 {
6417 	return test_kasumi_auth_cipher(
6418 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6419 }
6420 
6421 static int
6422 test_kasumi_auth_cipher_test_case_2_oop(void)
6423 {
6424 	return test_kasumi_auth_cipher(
6425 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6426 }
6427 
6428 static int
6429 test_kasumi_auth_cipher_test_case_2_sgl(void)
6430 {
6431 	return test_kasumi_auth_cipher_sgl(
6432 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6433 }
6434 
6435 static int
6436 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
6437 {
6438 	return test_kasumi_auth_cipher_sgl(
6439 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6440 }
6441 
6442 static int
6443 test_kasumi_auth_cipher_verify_test_case_1(void)
6444 {
6445 	return test_kasumi_auth_cipher(
6446 		&kasumi_test_case_3, IN_PLACE, 1);
6447 }
6448 
6449 static int
6450 test_kasumi_auth_cipher_verify_test_case_2(void)
6451 {
6452 	return test_kasumi_auth_cipher(
6453 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6454 }
6455 
6456 static int
6457 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
6458 {
6459 	return test_kasumi_auth_cipher(
6460 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6461 }
6462 
6463 static int
6464 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
6465 {
6466 	return test_kasumi_auth_cipher_sgl(
6467 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6468 }
6469 
6470 static int
6471 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
6472 {
6473 	return test_kasumi_auth_cipher_sgl(
6474 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6475 }
6476 
6477 static int
6478 test_kasumi_cipher_auth_test_case_1(void)
6479 {
6480 	return test_kasumi_cipher_auth(&kasumi_test_case_6);
6481 }
6482 
6483 static int
6484 test_zuc_encryption_test_case_1(void)
6485 {
6486 	return test_zuc_encryption(&zuc_test_case_cipher_193b);
6487 }
6488 
6489 static int
6490 test_zuc_encryption_test_case_2(void)
6491 {
6492 	return test_zuc_encryption(&zuc_test_case_cipher_800b);
6493 }
6494 
6495 static int
6496 test_zuc_encryption_test_case_3(void)
6497 {
6498 	return test_zuc_encryption(&zuc_test_case_cipher_1570b);
6499 }
6500 
6501 static int
6502 test_zuc_encryption_test_case_4(void)
6503 {
6504 	return test_zuc_encryption(&zuc_test_case_cipher_2798b);
6505 }
6506 
6507 static int
6508 test_zuc_encryption_test_case_5(void)
6509 {
6510 	return test_zuc_encryption(&zuc_test_case_cipher_4019b);
6511 }
6512 
6513 static int
6514 test_zuc_encryption_test_case_6_sgl(void)
6515 {
6516 	return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
6517 }
6518 
6519 static int
6520 test_zuc_hash_generate_test_case_1(void)
6521 {
6522 	return test_zuc_authentication(&zuc_test_case_auth_1b);
6523 }
6524 
6525 static int
6526 test_zuc_hash_generate_test_case_2(void)
6527 {
6528 	return test_zuc_authentication(&zuc_test_case_auth_90b);
6529 }
6530 
6531 static int
6532 test_zuc_hash_generate_test_case_3(void)
6533 {
6534 	return test_zuc_authentication(&zuc_test_case_auth_577b);
6535 }
6536 
6537 static int
6538 test_zuc_hash_generate_test_case_4(void)
6539 {
6540 	return test_zuc_authentication(&zuc_test_case_auth_2079b);
6541 }
6542 
6543 static int
6544 test_zuc_hash_generate_test_case_5(void)
6545 {
6546 	return test_zuc_authentication(&zuc_test_auth_5670b);
6547 }
6548 
6549 static int
6550 test_zuc_hash_generate_test_case_6(void)
6551 {
6552 	return test_zuc_authentication(&zuc_test_case_auth_128b);
6553 }
6554 
6555 static int
6556 test_zuc_hash_generate_test_case_7(void)
6557 {
6558 	return test_zuc_authentication(&zuc_test_case_auth_2080b);
6559 }
6560 
6561 static int
6562 test_zuc_hash_generate_test_case_8(void)
6563 {
6564 	return test_zuc_authentication(&zuc_test_case_auth_584b);
6565 }
6566 
6567 static int
6568 test_zuc_cipher_auth_test_case_1(void)
6569 {
6570 	return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
6571 }
6572 
6573 static int
6574 test_zuc_cipher_auth_test_case_2(void)
6575 {
6576 	return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
6577 }
6578 
6579 static int
6580 test_zuc_auth_cipher_test_case_1(void)
6581 {
6582 	return test_zuc_auth_cipher(
6583 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
6584 }
6585 
6586 static int
6587 test_zuc_auth_cipher_test_case_1_oop(void)
6588 {
6589 	return test_zuc_auth_cipher(
6590 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
6591 }
6592 
6593 static int
6594 test_zuc_auth_cipher_test_case_1_sgl(void)
6595 {
6596 	return test_zuc_auth_cipher_sgl(
6597 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
6598 }
6599 
6600 static int
6601 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
6602 {
6603 	return test_zuc_auth_cipher_sgl(
6604 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
6605 }
6606 
6607 static int
6608 test_zuc_auth_cipher_verify_test_case_1(void)
6609 {
6610 	return test_zuc_auth_cipher(
6611 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
6612 }
6613 
6614 static int
6615 test_zuc_auth_cipher_verify_test_case_1_oop(void)
6616 {
6617 	return test_zuc_auth_cipher(
6618 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
6619 }
6620 
6621 static int
6622 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
6623 {
6624 	return test_zuc_auth_cipher_sgl(
6625 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
6626 }
6627 
6628 static int
6629 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
6630 {
6631 	return test_zuc_auth_cipher_sgl(
6632 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
6633 }
6634 
6635 static int
6636 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
6637 {
6638 	uint8_t dev_id = testsuite_params.valid_devs[0];
6639 
6640 	struct rte_cryptodev_sym_capability_idx cap_idx;
6641 
6642 	/* Check if device supports particular cipher algorithm */
6643 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6644 	cap_idx.algo.cipher = tdata->cipher_algo;
6645 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
6646 		return -ENOTSUP;
6647 
6648 	/* Check if device supports particular hash algorithm */
6649 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6650 	cap_idx.algo.auth = tdata->auth_algo;
6651 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
6652 		return -ENOTSUP;
6653 
6654 	return 0;
6655 }
6656 
6657 static int
6658 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
6659 	uint8_t op_mode, uint8_t verify)
6660 {
6661 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6662 	struct crypto_unittest_params *ut_params = &unittest_params;
6663 
6664 	int retval;
6665 
6666 	uint8_t *plaintext = NULL, *ciphertext = NULL;
6667 	unsigned int plaintext_pad_len;
6668 	unsigned int plaintext_len;
6669 	unsigned int ciphertext_pad_len;
6670 	unsigned int ciphertext_len;
6671 
6672 	struct rte_cryptodev_info dev_info;
6673 
6674 	/* Check if device supports particular algorithms separately */
6675 	if (test_mixed_check_if_unsupported(tdata))
6676 		return -ENOTSUP;
6677 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6678 		return -ENOTSUP;
6679 
6680 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6681 
6682 	uint64_t feat_flags = dev_info.feature_flags;
6683 
6684 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6685 		printf("Device doesn't support digest encrypted.\n");
6686 		return -ENOTSUP;
6687 	}
6688 
6689 	if (op_mode == OUT_OF_PLACE)
6690 		return -ENOTSUP;
6691 
6692 	/* Create the session */
6693 	if (verify)
6694 		retval = create_wireless_algo_cipher_auth_session(
6695 				ts_params->valid_devs[0],
6696 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
6697 				RTE_CRYPTO_AUTH_OP_VERIFY,
6698 				tdata->auth_algo,
6699 				tdata->cipher_algo,
6700 				tdata->auth_key.data, tdata->auth_key.len,
6701 				tdata->auth_iv.len, tdata->digest_enc.len,
6702 				tdata->cipher_iv.len);
6703 	else
6704 		retval = create_wireless_algo_auth_cipher_session(
6705 				ts_params->valid_devs[0],
6706 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6707 				RTE_CRYPTO_AUTH_OP_GENERATE,
6708 				tdata->auth_algo,
6709 				tdata->cipher_algo,
6710 				tdata->auth_key.data, tdata->auth_key.len,
6711 				tdata->auth_iv.len, tdata->digest_enc.len,
6712 				tdata->cipher_iv.len);
6713 	if (retval < 0)
6714 		return retval;
6715 
6716 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6717 	if (op_mode == OUT_OF_PLACE)
6718 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6719 
6720 	/* clear mbuf payload */
6721 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6722 		rte_pktmbuf_tailroom(ut_params->ibuf));
6723 	if (op_mode == OUT_OF_PLACE) {
6724 
6725 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6726 				rte_pktmbuf_tailroom(ut_params->obuf));
6727 	}
6728 
6729 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
6730 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
6731 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6732 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6733 
6734 	if (verify) {
6735 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6736 				ciphertext_pad_len);
6737 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6738 		if (op_mode == OUT_OF_PLACE)
6739 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6740 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6741 				ciphertext_len);
6742 	} else {
6743 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6744 				plaintext_pad_len);
6745 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6746 		if (op_mode == OUT_OF_PLACE)
6747 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
6748 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
6749 	}
6750 
6751 	/* Create the operation */
6752 	retval = create_wireless_algo_auth_cipher_operation(
6753 			tdata->digest_enc.data, tdata->digest_enc.len,
6754 			tdata->cipher_iv.data, tdata->cipher_iv.len,
6755 			tdata->auth_iv.data, tdata->auth_iv.len,
6756 			(tdata->digest_enc.offset == 0 ?
6757 				plaintext_pad_len
6758 				: tdata->digest_enc.offset),
6759 			tdata->validCipherLen.len_bits,
6760 			tdata->cipher.offset_bits,
6761 			tdata->validAuthLen.len_bits,
6762 			tdata->auth.offset_bits,
6763 			op_mode, 0, verify);
6764 
6765 	if (retval < 0)
6766 		return retval;
6767 
6768 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6769 			ut_params->op);
6770 
6771 	/* Check if the op failed because the device doesn't */
6772 	/* support this particular combination of algorithms */
6773 	if (ut_params->op == NULL && ut_params->op->status ==
6774 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
6775 		printf("Device doesn't support this mixed combination. "
6776 				"Test Skipped.\n");
6777 		return -ENOTSUP;
6778 	}
6779 
6780 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6781 
6782 	ut_params->obuf = (op_mode == IN_PLACE ?
6783 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6784 
6785 	if (verify) {
6786 		if (ut_params->obuf)
6787 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6788 							uint8_t *);
6789 		else
6790 			plaintext = ciphertext +
6791 					(tdata->cipher.offset_bits >> 3);
6792 
6793 		debug_hexdump(stdout, "plaintext:", plaintext,
6794 				tdata->plaintext.len_bits >> 3);
6795 		debug_hexdump(stdout, "plaintext expected:",
6796 				tdata->plaintext.data,
6797 				tdata->plaintext.len_bits >> 3);
6798 	} else {
6799 		if (ut_params->obuf)
6800 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6801 					uint8_t *);
6802 		else
6803 			ciphertext = plaintext;
6804 
6805 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6806 				ciphertext_len);
6807 		debug_hexdump(stdout, "ciphertext expected:",
6808 				tdata->ciphertext.data,
6809 				tdata->ciphertext.len_bits >> 3);
6810 
6811 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6812 				+ (tdata->digest_enc.offset == 0 ?
6813 		plaintext_pad_len : tdata->digest_enc.offset);
6814 
6815 		debug_hexdump(stdout, "digest:", ut_params->digest,
6816 				tdata->digest_enc.len);
6817 		debug_hexdump(stdout, "digest expected:",
6818 				tdata->digest_enc.data,
6819 				tdata->digest_enc.len);
6820 	}
6821 
6822 	/* Validate obuf */
6823 	if (verify) {
6824 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6825 				plaintext,
6826 				tdata->plaintext.data,
6827 				tdata->plaintext.len_bits >> 3,
6828 				"Plaintext data not as expected");
6829 	} else {
6830 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6831 				ciphertext,
6832 				tdata->ciphertext.data,
6833 				tdata->validDataLen.len_bits,
6834 				"Ciphertext data not as expected");
6835 
6836 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6837 				ut_params->digest,
6838 				tdata->digest_enc.data,
6839 				DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
6840 				"Generated auth tag not as expected");
6841 	}
6842 
6843 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6844 			"crypto op processing failed");
6845 
6846 	return 0;
6847 }
6848 
6849 static int
6850 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
6851 	uint8_t op_mode, uint8_t verify)
6852 {
6853 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6854 	struct crypto_unittest_params *ut_params = &unittest_params;
6855 
6856 	int retval;
6857 
6858 	const uint8_t *plaintext = NULL;
6859 	const uint8_t *ciphertext = NULL;
6860 	const uint8_t *digest = NULL;
6861 	unsigned int plaintext_pad_len;
6862 	unsigned int plaintext_len;
6863 	unsigned int ciphertext_pad_len;
6864 	unsigned int ciphertext_len;
6865 	uint8_t buffer[10000];
6866 	uint8_t digest_buffer[10000];
6867 
6868 	struct rte_cryptodev_info dev_info;
6869 
6870 	/* Check if device supports particular algorithms */
6871 	if (test_mixed_check_if_unsupported(tdata))
6872 		return -ENOTSUP;
6873 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6874 		return -ENOTSUP;
6875 
6876 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6877 
6878 	uint64_t feat_flags = dev_info.feature_flags;
6879 
6880 	if (op_mode == IN_PLACE) {
6881 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6882 			printf("Device doesn't support in-place scatter-gather "
6883 					"in both input and output mbufs.\n");
6884 			return -ENOTSUP;
6885 		}
6886 	} else {
6887 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6888 			printf("Device doesn't support out-of-place scatter-gather "
6889 					"in both input and output mbufs.\n");
6890 			return -ENOTSUP;
6891 		}
6892 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6893 			printf("Device doesn't support digest encrypted.\n");
6894 			return -ENOTSUP;
6895 		}
6896 	}
6897 
6898 	/* Create the session */
6899 	if (verify)
6900 		retval = create_wireless_algo_cipher_auth_session(
6901 				ts_params->valid_devs[0],
6902 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
6903 				RTE_CRYPTO_AUTH_OP_VERIFY,
6904 				tdata->auth_algo,
6905 				tdata->cipher_algo,
6906 				tdata->auth_key.data, tdata->auth_key.len,
6907 				tdata->auth_iv.len, tdata->digest_enc.len,
6908 				tdata->cipher_iv.len);
6909 	else
6910 		retval = create_wireless_algo_auth_cipher_session(
6911 				ts_params->valid_devs[0],
6912 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6913 				RTE_CRYPTO_AUTH_OP_GENERATE,
6914 				tdata->auth_algo,
6915 				tdata->cipher_algo,
6916 				tdata->auth_key.data, tdata->auth_key.len,
6917 				tdata->auth_iv.len, tdata->digest_enc.len,
6918 				tdata->cipher_iv.len);
6919 	if (retval < 0)
6920 		return retval;
6921 
6922 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
6923 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
6924 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6925 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6926 
6927 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6928 			ciphertext_pad_len, 15, 0);
6929 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6930 			"Failed to allocate input buffer in mempool");
6931 
6932 	if (op_mode == OUT_OF_PLACE) {
6933 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6934 				plaintext_pad_len, 15, 0);
6935 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
6936 				"Failed to allocate output buffer in mempool");
6937 	}
6938 
6939 	if (verify) {
6940 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6941 			tdata->ciphertext.data);
6942 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6943 					ciphertext_len, buffer);
6944 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6945 			ciphertext_len);
6946 	} else {
6947 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6948 			tdata->plaintext.data);
6949 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6950 					plaintext_len, buffer);
6951 		debug_hexdump(stdout, "plaintext:", plaintext,
6952 			plaintext_len);
6953 	}
6954 	memset(buffer, 0, sizeof(buffer));
6955 
6956 	/* Create the operation */
6957 	retval = create_wireless_algo_auth_cipher_operation(
6958 			tdata->digest_enc.data, tdata->digest_enc.len,
6959 			tdata->cipher_iv.data, tdata->cipher_iv.len,
6960 			tdata->auth_iv.data, tdata->auth_iv.len,
6961 			(tdata->digest_enc.offset == 0 ?
6962 				plaintext_pad_len
6963 				: tdata->digest_enc.offset),
6964 			tdata->validCipherLen.len_bits,
6965 			tdata->cipher.offset_bits,
6966 			tdata->validAuthLen.len_bits,
6967 			tdata->auth.offset_bits,
6968 			op_mode, 1, verify);
6969 
6970 	if (retval < 0)
6971 		return retval;
6972 
6973 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6974 			ut_params->op);
6975 
6976 	/* Check if the op failed because the device doesn't */
6977 	/* support this particular combination of algorithms */
6978 	if (ut_params->op == NULL && ut_params->op->status ==
6979 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
6980 		printf("Device doesn't support this mixed combination. "
6981 				"Test Skipped.\n");
6982 		return -ENOTSUP;
6983 	}
6984 
6985 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6986 
6987 	ut_params->obuf = (op_mode == IN_PLACE ?
6988 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6989 
6990 	if (verify) {
6991 		if (ut_params->obuf)
6992 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6993 					plaintext_len, buffer);
6994 		else
6995 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6996 					plaintext_len, buffer);
6997 
6998 		debug_hexdump(stdout, "plaintext:", plaintext,
6999 				(tdata->plaintext.len_bits >> 3) -
7000 				tdata->digest_enc.len);
7001 		debug_hexdump(stdout, "plaintext expected:",
7002 				tdata->plaintext.data,
7003 				(tdata->plaintext.len_bits >> 3) -
7004 				tdata->digest_enc.len);
7005 	} else {
7006 		if (ut_params->obuf)
7007 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7008 					ciphertext_len, buffer);
7009 		else
7010 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7011 					ciphertext_len, buffer);
7012 
7013 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7014 			ciphertext_len);
7015 		debug_hexdump(stdout, "ciphertext expected:",
7016 			tdata->ciphertext.data,
7017 			tdata->ciphertext.len_bits >> 3);
7018 
7019 		if (ut_params->obuf)
7020 			digest = rte_pktmbuf_read(ut_params->obuf,
7021 					(tdata->digest_enc.offset == 0 ?
7022 						plaintext_pad_len :
7023 						tdata->digest_enc.offset),
7024 					tdata->digest_enc.len, digest_buffer);
7025 		else
7026 			digest = rte_pktmbuf_read(ut_params->ibuf,
7027 					(tdata->digest_enc.offset == 0 ?
7028 						plaintext_pad_len :
7029 						tdata->digest_enc.offset),
7030 					tdata->digest_enc.len, digest_buffer);
7031 
7032 		debug_hexdump(stdout, "digest:", digest,
7033 				tdata->digest_enc.len);
7034 		debug_hexdump(stdout, "digest expected:",
7035 				tdata->digest_enc.data, tdata->digest_enc.len);
7036 	}
7037 
7038 	/* Validate obuf */
7039 	if (verify) {
7040 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7041 				plaintext,
7042 				tdata->plaintext.data,
7043 				tdata->plaintext.len_bits >> 3,
7044 				"Plaintext data not as expected");
7045 	} else {
7046 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7047 				ciphertext,
7048 				tdata->ciphertext.data,
7049 				tdata->validDataLen.len_bits,
7050 				"Ciphertext data not as expected");
7051 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
7052 				digest,
7053 				tdata->digest_enc.data,
7054 				tdata->digest_enc.len,
7055 				"Generated auth tag not as expected");
7056 	}
7057 
7058 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7059 			"crypto op processing failed");
7060 
7061 	return 0;
7062 }
7063 
7064 /** AUTH AES CMAC + CIPHER AES CTR */
7065 
7066 static int
7067 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7068 {
7069 	return test_mixed_auth_cipher(
7070 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7071 }
7072 
7073 static int
7074 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7075 {
7076 	return test_mixed_auth_cipher(
7077 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7078 }
7079 
7080 static int
7081 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7082 {
7083 	return test_mixed_auth_cipher_sgl(
7084 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7085 }
7086 
7087 static int
7088 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7089 {
7090 	return test_mixed_auth_cipher_sgl(
7091 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7092 }
7093 
7094 static int
7095 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7096 {
7097 	return test_mixed_auth_cipher(
7098 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7099 }
7100 
7101 static int
7102 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7103 {
7104 	return test_mixed_auth_cipher(
7105 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7106 }
7107 
7108 static int
7109 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7110 {
7111 	return test_mixed_auth_cipher_sgl(
7112 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7113 }
7114 
7115 static int
7116 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7117 {
7118 	return test_mixed_auth_cipher_sgl(
7119 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7120 }
7121 
7122 /** MIXED AUTH + CIPHER */
7123 
7124 static int
7125 test_auth_zuc_cipher_snow_test_case_1(void)
7126 {
7127 	return test_mixed_auth_cipher(
7128 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7129 }
7130 
7131 static int
7132 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7133 {
7134 	return test_mixed_auth_cipher(
7135 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7136 }
7137 
7138 static int
7139 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7140 {
7141 	return test_mixed_auth_cipher(
7142 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7143 }
7144 
7145 static int
7146 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7147 {
7148 	return test_mixed_auth_cipher(
7149 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7150 }
7151 
7152 static int
7153 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7154 {
7155 	return test_mixed_auth_cipher(
7156 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7157 }
7158 
7159 static int
7160 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7161 {
7162 	return test_mixed_auth_cipher(
7163 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7164 }
7165 
7166 static int
7167 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7168 {
7169 	return test_mixed_auth_cipher(
7170 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7171 }
7172 
7173 static int
7174 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7175 {
7176 	return test_mixed_auth_cipher(
7177 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7178 }
7179 
7180 static int
7181 test_auth_snow_cipher_zuc_test_case_1(void)
7182 {
7183 	return test_mixed_auth_cipher(
7184 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7185 }
7186 
7187 static int
7188 test_verify_auth_snow_cipher_zuc_test_case_1(void)
7189 {
7190 	return test_mixed_auth_cipher(
7191 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7192 }
7193 
7194 static int
7195 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
7196 {
7197 	return test_mixed_auth_cipher(
7198 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7199 }
7200 
7201 static int
7202 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
7203 {
7204 	return test_mixed_auth_cipher(
7205 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7206 }
7207 
7208 static int
7209 test_auth_null_cipher_snow_test_case_1(void)
7210 {
7211 	return test_mixed_auth_cipher(
7212 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7213 }
7214 
7215 static int
7216 test_verify_auth_null_cipher_snow_test_case_1(void)
7217 {
7218 	return test_mixed_auth_cipher(
7219 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7220 }
7221 
7222 static int
7223 test_auth_null_cipher_zuc_test_case_1(void)
7224 {
7225 	return test_mixed_auth_cipher(
7226 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7227 }
7228 
7229 static int
7230 test_verify_auth_null_cipher_zuc_test_case_1(void)
7231 {
7232 	return test_mixed_auth_cipher(
7233 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7234 }
7235 
7236 static int
7237 test_auth_snow_cipher_null_test_case_1(void)
7238 {
7239 	return test_mixed_auth_cipher(
7240 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7241 }
7242 
7243 static int
7244 test_verify_auth_snow_cipher_null_test_case_1(void)
7245 {
7246 	return test_mixed_auth_cipher(
7247 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7248 }
7249 
7250 static int
7251 test_auth_zuc_cipher_null_test_case_1(void)
7252 {
7253 	return test_mixed_auth_cipher(
7254 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7255 }
7256 
7257 static int
7258 test_verify_auth_zuc_cipher_null_test_case_1(void)
7259 {
7260 	return test_mixed_auth_cipher(
7261 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7262 }
7263 
7264 static int
7265 test_auth_null_cipher_aes_ctr_test_case_1(void)
7266 {
7267 	return test_mixed_auth_cipher(
7268 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7269 }
7270 
7271 static int
7272 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
7273 {
7274 	return test_mixed_auth_cipher(
7275 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7276 }
7277 
7278 static int
7279 test_auth_aes_cmac_cipher_null_test_case_1(void)
7280 {
7281 	return test_mixed_auth_cipher(
7282 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7283 }
7284 
7285 static int
7286 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
7287 {
7288 	return test_mixed_auth_cipher(
7289 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7290 }
7291 
7292 /* ***** AEAD algorithm Tests ***** */
7293 
7294 static int
7295 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
7296 		enum rte_crypto_aead_operation op,
7297 		const uint8_t *key, const uint8_t key_len,
7298 		const uint16_t aad_len, const uint8_t auth_len,
7299 		uint8_t iv_len)
7300 {
7301 	uint8_t aead_key[key_len];
7302 
7303 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7304 	struct crypto_unittest_params *ut_params = &unittest_params;
7305 
7306 	memcpy(aead_key, key, key_len);
7307 
7308 	/* Setup AEAD Parameters */
7309 	ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7310 	ut_params->aead_xform.next = NULL;
7311 	ut_params->aead_xform.aead.algo = algo;
7312 	ut_params->aead_xform.aead.op = op;
7313 	ut_params->aead_xform.aead.key.data = aead_key;
7314 	ut_params->aead_xform.aead.key.length = key_len;
7315 	ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
7316 	ut_params->aead_xform.aead.iv.length = iv_len;
7317 	ut_params->aead_xform.aead.digest_length = auth_len;
7318 	ut_params->aead_xform.aead.aad_length = aad_len;
7319 
7320 	debug_hexdump(stdout, "key:", key, key_len);
7321 
7322 	/* Create Crypto session*/
7323 	ut_params->sess = rte_cryptodev_sym_session_create(
7324 			ts_params->session_mpool);
7325 
7326 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7327 			&ut_params->aead_xform,
7328 			ts_params->session_priv_mpool);
7329 
7330 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7331 
7332 	return 0;
7333 }
7334 
7335 static int
7336 create_aead_xform(struct rte_crypto_op *op,
7337 		enum rte_crypto_aead_algorithm algo,
7338 		enum rte_crypto_aead_operation aead_op,
7339 		uint8_t *key, const uint8_t key_len,
7340 		const uint8_t aad_len, const uint8_t auth_len,
7341 		uint8_t iv_len)
7342 {
7343 	TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
7344 			"failed to allocate space for crypto transform");
7345 
7346 	struct rte_crypto_sym_op *sym_op = op->sym;
7347 
7348 	/* Setup AEAD Parameters */
7349 	sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
7350 	sym_op->xform->next = NULL;
7351 	sym_op->xform->aead.algo = algo;
7352 	sym_op->xform->aead.op = aead_op;
7353 	sym_op->xform->aead.key.data = key;
7354 	sym_op->xform->aead.key.length = key_len;
7355 	sym_op->xform->aead.iv.offset = IV_OFFSET;
7356 	sym_op->xform->aead.iv.length = iv_len;
7357 	sym_op->xform->aead.digest_length = auth_len;
7358 	sym_op->xform->aead.aad_length = aad_len;
7359 
7360 	debug_hexdump(stdout, "key:", key, key_len);
7361 
7362 	return 0;
7363 }
7364 
7365 static int
7366 create_aead_operation(enum rte_crypto_aead_operation op,
7367 		const struct aead_test_data *tdata)
7368 {
7369 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7370 	struct crypto_unittest_params *ut_params = &unittest_params;
7371 
7372 	uint8_t *plaintext, *ciphertext;
7373 	unsigned int aad_pad_len, plaintext_pad_len;
7374 
7375 	/* Generate Crypto op data structure */
7376 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7377 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7378 	TEST_ASSERT_NOT_NULL(ut_params->op,
7379 			"Failed to allocate symmetric crypto operation struct");
7380 
7381 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7382 
7383 	/* Append aad data */
7384 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
7385 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
7386 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7387 				aad_pad_len);
7388 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7389 				"no room to append aad");
7390 
7391 		sym_op->aead.aad.phys_addr =
7392 				rte_pktmbuf_iova(ut_params->ibuf);
7393 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
7394 		memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
7395 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7396 			tdata->aad.len);
7397 
7398 		/* Append IV at the end of the crypto operation*/
7399 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7400 				uint8_t *, IV_OFFSET);
7401 
7402 		/* Copy IV 1 byte after the IV pointer, according to the API */
7403 		rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
7404 		debug_hexdump(stdout, "iv:", iv_ptr,
7405 			tdata->iv.len);
7406 	} else {
7407 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
7408 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7409 				aad_pad_len);
7410 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7411 				"no room to append aad");
7412 
7413 		sym_op->aead.aad.phys_addr =
7414 				rte_pktmbuf_iova(ut_params->ibuf);
7415 		memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
7416 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7417 			tdata->aad.len);
7418 
7419 		/* Append IV at the end of the crypto operation*/
7420 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7421 				uint8_t *, IV_OFFSET);
7422 
7423 		if (tdata->iv.len == 0) {
7424 			rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
7425 			debug_hexdump(stdout, "iv:", iv_ptr,
7426 				AES_GCM_J0_LENGTH);
7427 		} else {
7428 			rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
7429 			debug_hexdump(stdout, "iv:", iv_ptr,
7430 				tdata->iv.len);
7431 		}
7432 	}
7433 
7434 	/* Append plaintext/ciphertext */
7435 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7436 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7437 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7438 				plaintext_pad_len);
7439 		TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7440 
7441 		memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
7442 		debug_hexdump(stdout, "plaintext:", plaintext,
7443 				tdata->plaintext.len);
7444 
7445 		if (ut_params->obuf) {
7446 			ciphertext = (uint8_t *)rte_pktmbuf_append(
7447 					ut_params->obuf,
7448 					plaintext_pad_len + aad_pad_len);
7449 			TEST_ASSERT_NOT_NULL(ciphertext,
7450 					"no room to append ciphertext");
7451 
7452 			memset(ciphertext + aad_pad_len, 0,
7453 					tdata->ciphertext.len);
7454 		}
7455 	} else {
7456 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
7457 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7458 				plaintext_pad_len);
7459 		TEST_ASSERT_NOT_NULL(ciphertext,
7460 				"no room to append ciphertext");
7461 
7462 		memcpy(ciphertext, tdata->ciphertext.data,
7463 				tdata->ciphertext.len);
7464 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7465 				tdata->ciphertext.len);
7466 
7467 		if (ut_params->obuf) {
7468 			plaintext = (uint8_t *)rte_pktmbuf_append(
7469 					ut_params->obuf,
7470 					plaintext_pad_len + aad_pad_len);
7471 			TEST_ASSERT_NOT_NULL(plaintext,
7472 					"no room to append plaintext");
7473 
7474 			memset(plaintext + aad_pad_len, 0,
7475 					tdata->plaintext.len);
7476 		}
7477 	}
7478 
7479 	/* Append digest data */
7480 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7481 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7482 				ut_params->obuf ? ut_params->obuf :
7483 						ut_params->ibuf,
7484 						tdata->auth_tag.len);
7485 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7486 				"no room to append digest");
7487 		memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
7488 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
7489 				ut_params->obuf ? ut_params->obuf :
7490 						ut_params->ibuf,
7491 						plaintext_pad_len +
7492 						aad_pad_len);
7493 	} else {
7494 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7495 				ut_params->ibuf, tdata->auth_tag.len);
7496 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7497 				"no room to append digest");
7498 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
7499 				ut_params->ibuf,
7500 				plaintext_pad_len + aad_pad_len);
7501 
7502 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
7503 			tdata->auth_tag.len);
7504 		debug_hexdump(stdout, "digest:",
7505 			sym_op->aead.digest.data,
7506 			tdata->auth_tag.len);
7507 	}
7508 
7509 	sym_op->aead.data.length = tdata->plaintext.len;
7510 	sym_op->aead.data.offset = aad_pad_len;
7511 
7512 	return 0;
7513 }
7514 
7515 static int
7516 test_authenticated_encryption(const struct aead_test_data *tdata)
7517 {
7518 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7519 	struct crypto_unittest_params *ut_params = &unittest_params;
7520 
7521 	int retval;
7522 	uint8_t *ciphertext, *auth_tag;
7523 	uint16_t plaintext_pad_len;
7524 	uint32_t i;
7525 	struct rte_cryptodev_info dev_info;
7526 
7527 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7528 	uint64_t feat_flags = dev_info.feature_flags;
7529 
7530 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
7531 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
7532 		printf("Device doesn't support RAW data-path APIs.\n");
7533 		return -ENOTSUP;
7534 	}
7535 
7536 	/* Verify the capabilities */
7537 	struct rte_cryptodev_sym_capability_idx cap_idx;
7538 	const struct rte_cryptodev_symmetric_capability *capability;
7539 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7540 	cap_idx.algo.aead = tdata->algo;
7541 	capability = rte_cryptodev_sym_capability_get(
7542 			ts_params->valid_devs[0], &cap_idx);
7543 	if (capability == NULL)
7544 		return -ENOTSUP;
7545 	if (rte_cryptodev_sym_capability_check_aead(
7546 			capability, tdata->key.len, tdata->auth_tag.len,
7547 			tdata->aad.len, tdata->iv.len))
7548 		return -ENOTSUP;
7549 
7550 	/* Create AEAD session */
7551 	retval = create_aead_session(ts_params->valid_devs[0],
7552 			tdata->algo,
7553 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
7554 			tdata->key.data, tdata->key.len,
7555 			tdata->aad.len, tdata->auth_tag.len,
7556 			tdata->iv.len);
7557 	if (retval < 0)
7558 		return retval;
7559 
7560 	if (tdata->aad.len > MBUF_SIZE) {
7561 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
7562 		/* Populate full size of add data */
7563 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
7564 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
7565 	} else
7566 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7567 
7568 	/* clear mbuf payload */
7569 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7570 			rte_pktmbuf_tailroom(ut_params->ibuf));
7571 
7572 	/* Create AEAD operation */
7573 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
7574 	if (retval < 0)
7575 		return retval;
7576 
7577 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7578 
7579 	ut_params->op->sym->m_src = ut_params->ibuf;
7580 
7581 	/* Process crypto operation */
7582 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
7583 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
7584 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7585 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
7586 				ut_params->op, 0, 0, 0, 0);
7587 	else
7588 		TEST_ASSERT_NOT_NULL(
7589 			process_crypto_request(ts_params->valid_devs[0],
7590 			ut_params->op), "failed to process sym crypto op");
7591 
7592 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7593 			"crypto op processing failed");
7594 
7595 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7596 
7597 	if (ut_params->op->sym->m_dst) {
7598 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
7599 				uint8_t *);
7600 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
7601 				uint8_t *, plaintext_pad_len);
7602 	} else {
7603 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
7604 				uint8_t *,
7605 				ut_params->op->sym->cipher.data.offset);
7606 		auth_tag = ciphertext + plaintext_pad_len;
7607 	}
7608 
7609 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
7610 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
7611 
7612 	/* Validate obuf */
7613 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
7614 			ciphertext,
7615 			tdata->ciphertext.data,
7616 			tdata->ciphertext.len,
7617 			"Ciphertext data not as expected");
7618 
7619 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
7620 			auth_tag,
7621 			tdata->auth_tag.data,
7622 			tdata->auth_tag.len,
7623 			"Generated auth tag not as expected");
7624 
7625 	return 0;
7626 
7627 }
7628 
7629 #ifdef RTE_LIBRTE_SECURITY
7630 static int
7631 security_proto_supported(enum rte_security_session_action_type action,
7632 	enum rte_security_session_protocol proto)
7633 {
7634 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7635 
7636 	const struct rte_security_capability *capabilities;
7637 	const struct rte_security_capability *capability;
7638 	uint16_t i = 0;
7639 
7640 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
7641 				rte_cryptodev_get_sec_ctx(
7642 				ts_params->valid_devs[0]);
7643 
7644 
7645 	capabilities = rte_security_capabilities_get(ctx);
7646 
7647 	if (capabilities == NULL)
7648 		return -ENOTSUP;
7649 
7650 	while ((capability = &capabilities[i++])->action !=
7651 			RTE_SECURITY_ACTION_TYPE_NONE) {
7652 		if (capability->action == action &&
7653 				capability->protocol == proto)
7654 			return 0;
7655 	}
7656 
7657 	return -ENOTSUP;
7658 }
7659 
7660 /* Basic algorithm run function for async inplace mode.
7661  * Creates a session from input parameters and runs one operation
7662  * on input_vec. Checks the output of the crypto operation against
7663  * output_vec.
7664  */
7665 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
7666 			   enum rte_crypto_auth_operation opa,
7667 			   const uint8_t *input_vec, unsigned int input_vec_len,
7668 			   const uint8_t *output_vec,
7669 			   unsigned int output_vec_len,
7670 			   enum rte_crypto_cipher_algorithm cipher_alg,
7671 			   const uint8_t *cipher_key, uint32_t cipher_key_len,
7672 			   enum rte_crypto_auth_algorithm auth_alg,
7673 			   const uint8_t *auth_key, uint32_t auth_key_len,
7674 			   uint8_t bearer, enum rte_security_pdcp_domain domain,
7675 			   uint8_t packet_direction, uint8_t sn_size,
7676 			   uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
7677 {
7678 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7679 	struct crypto_unittest_params *ut_params = &unittest_params;
7680 	uint8_t *plaintext;
7681 	int ret = TEST_SUCCESS;
7682 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
7683 				rte_cryptodev_get_sec_ctx(
7684 				ts_params->valid_devs[0]);
7685 
7686 	/* Verify the capabilities */
7687 	struct rte_security_capability_idx sec_cap_idx;
7688 
7689 	sec_cap_idx.action = ut_params->type;
7690 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
7691 	sec_cap_idx.pdcp.domain = domain;
7692 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
7693 		return -ENOTSUP;
7694 
7695 	/* Generate test mbuf data */
7696 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7697 
7698 	/* clear mbuf payload */
7699 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7700 			rte_pktmbuf_tailroom(ut_params->ibuf));
7701 
7702 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7703 						  input_vec_len);
7704 	memcpy(plaintext, input_vec, input_vec_len);
7705 
7706 	/* Out of place support */
7707 	if (oop) {
7708 		/*
7709 		 * For out-op-place we need to alloc another mbuf
7710 		 */
7711 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7712 		rte_pktmbuf_append(ut_params->obuf, output_vec_len);
7713 	}
7714 
7715 	/* Setup Cipher Parameters */
7716 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7717 	ut_params->cipher_xform.cipher.algo = cipher_alg;
7718 	ut_params->cipher_xform.cipher.op = opc;
7719 	ut_params->cipher_xform.cipher.key.data = cipher_key;
7720 	ut_params->cipher_xform.cipher.key.length = cipher_key_len;
7721 	ut_params->cipher_xform.cipher.iv.length =
7722 				packet_direction ? 4 : 0;
7723 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
7724 
7725 	/* Setup HMAC Parameters if ICV header is required */
7726 	if (auth_alg != 0) {
7727 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7728 		ut_params->auth_xform.next = NULL;
7729 		ut_params->auth_xform.auth.algo = auth_alg;
7730 		ut_params->auth_xform.auth.op = opa;
7731 		ut_params->auth_xform.auth.key.data = auth_key;
7732 		ut_params->auth_xform.auth.key.length = auth_key_len;
7733 
7734 		ut_params->cipher_xform.next = &ut_params->auth_xform;
7735 	} else {
7736 		ut_params->cipher_xform.next = NULL;
7737 	}
7738 
7739 	struct rte_security_session_conf sess_conf = {
7740 		.action_type = ut_params->type,
7741 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
7742 		{.pdcp = {
7743 			.bearer = bearer,
7744 			.domain = domain,
7745 			.pkt_dir = packet_direction,
7746 			.sn_size = sn_size,
7747 			.hfn = packet_direction ? 0 : hfn,
7748 			/**
7749 			 * hfn can be set as pdcp_test_hfn[i]
7750 			 * if hfn_ovrd is not set. Here, PDCP
7751 			 * packet direction is just used to
7752 			 * run half of the cases with session
7753 			 * HFN and other half with per packet
7754 			 * HFN.
7755 			 */
7756 			.hfn_threshold = hfn_threshold,
7757 			.hfn_ovrd = packet_direction ? 1 : 0,
7758 			.sdap_enabled = sdap,
7759 		} },
7760 		.crypto_xform = &ut_params->cipher_xform
7761 	};
7762 
7763 	/* Create security session */
7764 	ut_params->sec_session = rte_security_session_create(ctx,
7765 				&sess_conf, ts_params->session_priv_mpool);
7766 
7767 	if (!ut_params->sec_session) {
7768 		printf("TestCase %s()-%d line %d failed %s: ",
7769 			__func__, i, __LINE__, "Failed to allocate session");
7770 		ret = TEST_FAILED;
7771 		goto on_err;
7772 	}
7773 
7774 	/* Generate crypto op data structure */
7775 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7776 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7777 	if (!ut_params->op) {
7778 		printf("TestCase %s()-%d line %d failed %s: ",
7779 			__func__, i, __LINE__,
7780 			"Failed to allocate symmetric crypto operation struct");
7781 		ret = TEST_FAILED;
7782 		goto on_err;
7783 	}
7784 
7785 	uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
7786 					uint32_t *, IV_OFFSET);
7787 	*per_pkt_hfn = packet_direction ? hfn : 0;
7788 
7789 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
7790 
7791 	/* set crypto operation source mbuf */
7792 	ut_params->op->sym->m_src = ut_params->ibuf;
7793 	if (oop)
7794 		ut_params->op->sym->m_dst = ut_params->obuf;
7795 
7796 	/* Process crypto operation */
7797 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
7798 		== NULL) {
7799 		printf("TestCase %s()-%d line %d failed %s: ",
7800 			__func__, i, __LINE__,
7801 			"failed to process sym crypto op");
7802 		ret = TEST_FAILED;
7803 		goto on_err;
7804 	}
7805 
7806 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
7807 		printf("TestCase %s()-%d line %d failed %s: ",
7808 			__func__, i, __LINE__, "crypto op processing failed");
7809 		ret = TEST_FAILED;
7810 		goto on_err;
7811 	}
7812 
7813 	/* Validate obuf */
7814 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
7815 			uint8_t *);
7816 	if (oop) {
7817 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
7818 				uint8_t *);
7819 	}
7820 
7821 	if (memcmp(ciphertext, output_vec, output_vec_len)) {
7822 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
7823 		rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
7824 		rte_hexdump(stdout, "reference", output_vec, output_vec_len);
7825 		ret = TEST_FAILED;
7826 		goto on_err;
7827 	}
7828 
7829 on_err:
7830 	rte_crypto_op_free(ut_params->op);
7831 	ut_params->op = NULL;
7832 
7833 	if (ut_params->sec_session)
7834 		rte_security_session_destroy(ctx, ut_params->sec_session);
7835 	ut_params->sec_session = NULL;
7836 
7837 	rte_pktmbuf_free(ut_params->ibuf);
7838 	ut_params->ibuf = NULL;
7839 	if (oop) {
7840 		rte_pktmbuf_free(ut_params->obuf);
7841 		ut_params->obuf = NULL;
7842 	}
7843 
7844 	return ret;
7845 }
7846 
7847 static int
7848 test_pdcp_proto_SGL(int i, int oop,
7849 	enum rte_crypto_cipher_operation opc,
7850 	enum rte_crypto_auth_operation opa,
7851 	uint8_t *input_vec,
7852 	unsigned int input_vec_len,
7853 	uint8_t *output_vec,
7854 	unsigned int output_vec_len,
7855 	uint32_t fragsz,
7856 	uint32_t fragsz_oop)
7857 {
7858 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7859 	struct crypto_unittest_params *ut_params = &unittest_params;
7860 	uint8_t *plaintext;
7861 	struct rte_mbuf *buf, *buf_oop = NULL;
7862 	int ret = TEST_SUCCESS;
7863 	int to_trn = 0;
7864 	int to_trn_tbl[16];
7865 	int segs = 1;
7866 	unsigned int trn_data = 0;
7867 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
7868 				rte_cryptodev_get_sec_ctx(
7869 				ts_params->valid_devs[0]);
7870 
7871 	/* Verify the capabilities */
7872 	struct rte_security_capability_idx sec_cap_idx;
7873 
7874 	sec_cap_idx.action = ut_params->type;
7875 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
7876 	sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
7877 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
7878 		return -ENOTSUP;
7879 
7880 	if (fragsz > input_vec_len)
7881 		fragsz = input_vec_len;
7882 
7883 	uint16_t plaintext_len = fragsz;
7884 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
7885 
7886 	if (fragsz_oop > output_vec_len)
7887 		frag_size_oop = output_vec_len;
7888 
7889 	int ecx = 0;
7890 	if (input_vec_len % fragsz != 0) {
7891 		if (input_vec_len / fragsz + 1 > 16)
7892 			return 1;
7893 	} else if (input_vec_len / fragsz > 16)
7894 		return 1;
7895 
7896 	/* Out of place support */
7897 	if (oop) {
7898 		/*
7899 		 * For out-op-place we need to alloc another mbuf
7900 		 */
7901 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7902 		rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
7903 		buf_oop = ut_params->obuf;
7904 	}
7905 
7906 	/* Generate test mbuf data */
7907 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7908 
7909 	/* clear mbuf payload */
7910 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7911 			rte_pktmbuf_tailroom(ut_params->ibuf));
7912 
7913 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7914 						  plaintext_len);
7915 	memcpy(plaintext, input_vec, plaintext_len);
7916 	trn_data += plaintext_len;
7917 
7918 	buf = ut_params->ibuf;
7919 
7920 	/*
7921 	 * Loop until no more fragments
7922 	 */
7923 
7924 	while (trn_data < input_vec_len) {
7925 		++segs;
7926 		to_trn = (input_vec_len - trn_data < fragsz) ?
7927 				(input_vec_len - trn_data) : fragsz;
7928 
7929 		to_trn_tbl[ecx++] = to_trn;
7930 
7931 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7932 		buf = buf->next;
7933 
7934 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
7935 				rte_pktmbuf_tailroom(buf));
7936 
7937 		/* OOP */
7938 		if (oop && !fragsz_oop) {
7939 			buf_oop->next =
7940 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
7941 			buf_oop = buf_oop->next;
7942 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
7943 					0, rte_pktmbuf_tailroom(buf_oop));
7944 			rte_pktmbuf_append(buf_oop, to_trn);
7945 		}
7946 
7947 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
7948 				to_trn);
7949 
7950 		memcpy(plaintext, input_vec + trn_data, to_trn);
7951 		trn_data += to_trn;
7952 	}
7953 
7954 	ut_params->ibuf->nb_segs = segs;
7955 
7956 	segs = 1;
7957 	if (fragsz_oop && oop) {
7958 		to_trn = 0;
7959 		ecx = 0;
7960 
7961 		trn_data = frag_size_oop;
7962 		while (trn_data < output_vec_len) {
7963 			++segs;
7964 			to_trn =
7965 				(output_vec_len - trn_data <
7966 						frag_size_oop) ?
7967 				(output_vec_len - trn_data) :
7968 						frag_size_oop;
7969 
7970 			to_trn_tbl[ecx++] = to_trn;
7971 
7972 			buf_oop->next =
7973 				rte_pktmbuf_alloc(ts_params->mbuf_pool);
7974 			buf_oop = buf_oop->next;
7975 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
7976 					0, rte_pktmbuf_tailroom(buf_oop));
7977 			rte_pktmbuf_append(buf_oop, to_trn);
7978 
7979 			trn_data += to_trn;
7980 		}
7981 		ut_params->obuf->nb_segs = segs;
7982 	}
7983 
7984 	/* Setup Cipher Parameters */
7985 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7986 	ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
7987 	ut_params->cipher_xform.cipher.op = opc;
7988 	ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
7989 	ut_params->cipher_xform.cipher.key.length =
7990 					pdcp_test_params[i].cipher_key_len;
7991 	ut_params->cipher_xform.cipher.iv.length = 0;
7992 
7993 	/* Setup HMAC Parameters if ICV header is required */
7994 	if (pdcp_test_params[i].auth_alg != 0) {
7995 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7996 		ut_params->auth_xform.next = NULL;
7997 		ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
7998 		ut_params->auth_xform.auth.op = opa;
7999 		ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
8000 		ut_params->auth_xform.auth.key.length =
8001 					pdcp_test_params[i].auth_key_len;
8002 
8003 		ut_params->cipher_xform.next = &ut_params->auth_xform;
8004 	} else {
8005 		ut_params->cipher_xform.next = NULL;
8006 	}
8007 
8008 	struct rte_security_session_conf sess_conf = {
8009 		.action_type = ut_params->type,
8010 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
8011 		{.pdcp = {
8012 			.bearer = pdcp_test_bearer[i],
8013 			.domain = pdcp_test_params[i].domain,
8014 			.pkt_dir = pdcp_test_packet_direction[i],
8015 			.sn_size = pdcp_test_data_sn_size[i],
8016 			.hfn = pdcp_test_hfn[i],
8017 			.hfn_threshold = pdcp_test_hfn_threshold[i],
8018 			.hfn_ovrd = 0,
8019 		} },
8020 		.crypto_xform = &ut_params->cipher_xform
8021 	};
8022 
8023 	/* Create security session */
8024 	ut_params->sec_session = rte_security_session_create(ctx,
8025 				&sess_conf, ts_params->session_priv_mpool);
8026 
8027 	if (!ut_params->sec_session) {
8028 		printf("TestCase %s()-%d line %d failed %s: ",
8029 			__func__, i, __LINE__, "Failed to allocate session");
8030 		ret = TEST_FAILED;
8031 		goto on_err;
8032 	}
8033 
8034 	/* Generate crypto op data structure */
8035 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8036 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8037 	if (!ut_params->op) {
8038 		printf("TestCase %s()-%d line %d failed %s: ",
8039 			__func__, i, __LINE__,
8040 			"Failed to allocate symmetric crypto operation struct");
8041 		ret = TEST_FAILED;
8042 		goto on_err;
8043 	}
8044 
8045 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8046 
8047 	/* set crypto operation source mbuf */
8048 	ut_params->op->sym->m_src = ut_params->ibuf;
8049 	if (oop)
8050 		ut_params->op->sym->m_dst = ut_params->obuf;
8051 
8052 	/* Process crypto operation */
8053 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8054 		== NULL) {
8055 		printf("TestCase %s()-%d line %d failed %s: ",
8056 			__func__, i, __LINE__,
8057 			"failed to process sym crypto op");
8058 		ret = TEST_FAILED;
8059 		goto on_err;
8060 	}
8061 
8062 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8063 		printf("TestCase %s()-%d line %d failed %s: ",
8064 			__func__, i, __LINE__, "crypto op processing failed");
8065 		ret = TEST_FAILED;
8066 		goto on_err;
8067 	}
8068 
8069 	/* Validate obuf */
8070 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8071 			uint8_t *);
8072 	if (oop) {
8073 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8074 				uint8_t *);
8075 	}
8076 	if (fragsz_oop)
8077 		fragsz = frag_size_oop;
8078 	if (memcmp(ciphertext, output_vec, fragsz)) {
8079 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8080 		rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8081 		rte_hexdump(stdout, "reference", output_vec, fragsz);
8082 		ret = TEST_FAILED;
8083 		goto on_err;
8084 	}
8085 
8086 	buf = ut_params->op->sym->m_src->next;
8087 	if (oop)
8088 		buf = ut_params->op->sym->m_dst->next;
8089 
8090 	unsigned int off = fragsz;
8091 
8092 	ecx = 0;
8093 	while (buf) {
8094 		ciphertext = rte_pktmbuf_mtod(buf,
8095 				uint8_t *);
8096 		if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8097 			printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8098 			rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8099 			rte_hexdump(stdout, "reference", output_vec + off,
8100 					to_trn_tbl[ecx]);
8101 			ret = TEST_FAILED;
8102 			goto on_err;
8103 		}
8104 		off += to_trn_tbl[ecx++];
8105 		buf = buf->next;
8106 	}
8107 on_err:
8108 	rte_crypto_op_free(ut_params->op);
8109 	ut_params->op = NULL;
8110 
8111 	if (ut_params->sec_session)
8112 		rte_security_session_destroy(ctx, ut_params->sec_session);
8113 	ut_params->sec_session = NULL;
8114 
8115 	rte_pktmbuf_free(ut_params->ibuf);
8116 	ut_params->ibuf = NULL;
8117 	if (oop) {
8118 		rte_pktmbuf_free(ut_params->obuf);
8119 		ut_params->obuf = NULL;
8120 	}
8121 
8122 	return ret;
8123 }
8124 
8125 int
8126 test_pdcp_proto_cplane_encap(int i)
8127 {
8128 	return test_pdcp_proto(
8129 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8130 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8131 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8132 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8133 		pdcp_test_params[i].cipher_key_len,
8134 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8135 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8136 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8137 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8138 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8139 }
8140 
8141 int
8142 test_pdcp_proto_uplane_encap(int i)
8143 {
8144 	return test_pdcp_proto(
8145 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8146 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8147 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8148 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8149 		pdcp_test_params[i].cipher_key_len,
8150 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8151 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8152 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8153 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8154 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8155 }
8156 
8157 int
8158 test_pdcp_proto_uplane_encap_with_int(int i)
8159 {
8160 	return test_pdcp_proto(
8161 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8162 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8163 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8164 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8165 		pdcp_test_params[i].cipher_key_len,
8166 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8167 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8168 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8169 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8170 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8171 }
8172 
8173 int
8174 test_pdcp_proto_cplane_decap(int i)
8175 {
8176 	return test_pdcp_proto(
8177 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8178 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8179 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8180 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8181 		pdcp_test_params[i].cipher_key_len,
8182 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8183 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8184 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8185 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8186 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8187 }
8188 
8189 int
8190 test_pdcp_proto_uplane_decap(int i)
8191 {
8192 	return test_pdcp_proto(
8193 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8194 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8195 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8196 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8197 		pdcp_test_params[i].cipher_key_len,
8198 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8199 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8200 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8201 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8202 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8203 }
8204 
8205 int
8206 test_pdcp_proto_uplane_decap_with_int(int i)
8207 {
8208 	return test_pdcp_proto(
8209 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8210 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8211 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8212 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8213 		pdcp_test_params[i].cipher_key_len,
8214 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8215 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8216 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8217 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8218 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8219 }
8220 
8221 static int
8222 test_PDCP_PROTO_SGL_in_place_32B(void)
8223 {
8224 	/* i can be used for running any PDCP case
8225 	 * In this case it is uplane 12-bit AES-SNOW DL encap
8226 	 */
8227 	int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
8228 	return test_pdcp_proto_SGL(i, IN_PLACE,
8229 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8230 			RTE_CRYPTO_AUTH_OP_GENERATE,
8231 			pdcp_test_data_in[i],
8232 			pdcp_test_data_in_len[i],
8233 			pdcp_test_data_out[i],
8234 			pdcp_test_data_in_len[i]+4,
8235 			32, 0);
8236 }
8237 static int
8238 test_PDCP_PROTO_SGL_oop_32B_128B(void)
8239 {
8240 	/* i can be used for running any PDCP case
8241 	 * In this case it is uplane 18-bit NULL-NULL DL encap
8242 	 */
8243 	int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
8244 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8245 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8246 			RTE_CRYPTO_AUTH_OP_GENERATE,
8247 			pdcp_test_data_in[i],
8248 			pdcp_test_data_in_len[i],
8249 			pdcp_test_data_out[i],
8250 			pdcp_test_data_in_len[i]+4,
8251 			32, 128);
8252 }
8253 static int
8254 test_PDCP_PROTO_SGL_oop_32B_40B(void)
8255 {
8256 	/* i can be used for running any PDCP case
8257 	 * In this case it is uplane 18-bit AES DL encap
8258 	 */
8259 	int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
8260 			+ DOWNLINK;
8261 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8262 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8263 			RTE_CRYPTO_AUTH_OP_GENERATE,
8264 			pdcp_test_data_in[i],
8265 			pdcp_test_data_in_len[i],
8266 			pdcp_test_data_out[i],
8267 			pdcp_test_data_in_len[i],
8268 			32, 40);
8269 }
8270 static int
8271 test_PDCP_PROTO_SGL_oop_128B_32B(void)
8272 {
8273 	/* i can be used for running any PDCP case
8274 	 * In this case it is cplane 12-bit AES-ZUC DL encap
8275 	 */
8276 	int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
8277 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8278 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8279 			RTE_CRYPTO_AUTH_OP_GENERATE,
8280 			pdcp_test_data_in[i],
8281 			pdcp_test_data_in_len[i],
8282 			pdcp_test_data_out[i],
8283 			pdcp_test_data_in_len[i]+4,
8284 			128, 32);
8285 }
8286 
8287 static int
8288 test_PDCP_SDAP_PROTO_encap_all(void)
8289 {
8290 	int i = 0, size = 0;
8291 	int err, all_err = TEST_SUCCESS;
8292 	const struct pdcp_sdap_test *cur_test;
8293 
8294 	size = ARRAY_SIZE(list_pdcp_sdap_tests);
8295 
8296 	for (i = 0; i < size; i++) {
8297 		cur_test = &list_pdcp_sdap_tests[i];
8298 		err = test_pdcp_proto(
8299 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8300 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8301 			cur_test->in_len, cur_test->data_out,
8302 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8303 			cur_test->param.cipher_alg, cur_test->cipher_key,
8304 			cur_test->param.cipher_key_len,
8305 			cur_test->param.auth_alg,
8306 			cur_test->auth_key, cur_test->param.auth_key_len,
8307 			cur_test->bearer, cur_test->param.domain,
8308 			cur_test->packet_direction, cur_test->sn_size,
8309 			cur_test->hfn,
8310 			cur_test->hfn_threshold, SDAP_ENABLED);
8311 		if (err) {
8312 			printf("\t%d) %s: Encapsulation failed\n",
8313 					cur_test->test_idx,
8314 					cur_test->param.name);
8315 			err = TEST_FAILED;
8316 		} else {
8317 			printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
8318 					cur_test->param.name);
8319 			err = TEST_SUCCESS;
8320 		}
8321 		all_err += err;
8322 	}
8323 
8324 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8325 
8326 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8327 }
8328 
8329 static int
8330 test_PDCP_SDAP_PROTO_decap_all(void)
8331 {
8332 	int i = 0, size = 0;
8333 	int err, all_err = TEST_SUCCESS;
8334 	const struct pdcp_sdap_test *cur_test;
8335 
8336 	size = ARRAY_SIZE(list_pdcp_sdap_tests);
8337 
8338 	for (i = 0; i < size; i++) {
8339 		cur_test = &list_pdcp_sdap_tests[i];
8340 		err = test_pdcp_proto(
8341 			i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
8342 			RTE_CRYPTO_AUTH_OP_VERIFY,
8343 			cur_test->data_out,
8344 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8345 			cur_test->data_in, cur_test->in_len,
8346 			cur_test->param.cipher_alg,
8347 			cur_test->cipher_key, cur_test->param.cipher_key_len,
8348 			cur_test->param.auth_alg, cur_test->auth_key,
8349 			cur_test->param.auth_key_len, cur_test->bearer,
8350 			cur_test->param.domain, cur_test->packet_direction,
8351 			cur_test->sn_size, cur_test->hfn,
8352 			cur_test->hfn_threshold, SDAP_ENABLED);
8353 		if (err) {
8354 			printf("\t%d) %s: Decapsulation failed\n",
8355 					cur_test->test_idx,
8356 					cur_test->param.name);
8357 			err = TEST_FAILED;
8358 		} else {
8359 			printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
8360 					cur_test->param.name);
8361 			err = TEST_SUCCESS;
8362 		}
8363 		all_err += err;
8364 	}
8365 
8366 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8367 
8368 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8369 }
8370 
8371 static int
8372 test_PDCP_PROTO_all(void)
8373 {
8374 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8375 	struct crypto_unittest_params *ut_params = &unittest_params;
8376 	struct rte_cryptodev_info dev_info;
8377 	int status;
8378 
8379 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8380 	uint64_t feat_flags = dev_info.feature_flags;
8381 
8382 	if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
8383 		return -ENOTSUP;
8384 
8385 	/* Set action type */
8386 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
8387 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
8388 		gbl_action_type;
8389 
8390 	if (security_proto_supported(ut_params->type,
8391 			RTE_SECURITY_PROTOCOL_PDCP) < 0)
8392 		return -ENOTSUP;
8393 
8394 	status = test_PDCP_PROTO_cplane_encap_all();
8395 	status += test_PDCP_PROTO_cplane_decap_all();
8396 	status += test_PDCP_PROTO_uplane_encap_all();
8397 	status += test_PDCP_PROTO_uplane_decap_all();
8398 	status += test_PDCP_PROTO_SGL_in_place_32B();
8399 	status += test_PDCP_PROTO_SGL_oop_32B_128B();
8400 	status += test_PDCP_PROTO_SGL_oop_32B_40B();
8401 	status += test_PDCP_PROTO_SGL_oop_128B_32B();
8402 	status += test_PDCP_SDAP_PROTO_encap_all();
8403 	status += test_PDCP_SDAP_PROTO_decap_all();
8404 
8405 	if (status)
8406 		return TEST_FAILED;
8407 	else
8408 		return TEST_SUCCESS;
8409 }
8410 
8411 static int
8412 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td)
8413 {
8414 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8415 	struct crypto_unittest_params *ut_params = &unittest_params;
8416 	uint8_t *plaintext, *ciphertext;
8417 	uint8_t *iv_ptr;
8418 	int32_t cipher_len, crc_len;
8419 	uint32_t crc_data_len;
8420 	int ret = TEST_SUCCESS;
8421 
8422 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8423 					rte_cryptodev_get_sec_ctx(
8424 						ts_params->valid_devs[0]);
8425 
8426 	/* Verify the capabilities */
8427 	struct rte_security_capability_idx sec_cap_idx;
8428 	const struct rte_security_capability *sec_cap;
8429 	const struct rte_cryptodev_capabilities *crypto_cap;
8430 	const struct rte_cryptodev_symmetric_capability *sym_cap;
8431 	int j = 0;
8432 
8433 	sec_cap_idx.action = ut_params->type;
8434 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
8435 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
8436 
8437 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
8438 	if (sec_cap == NULL)
8439 		return -ENOTSUP;
8440 
8441 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
8442 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
8443 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
8444 				crypto_cap->sym.xform_type ==
8445 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
8446 				crypto_cap->sym.cipher.algo ==
8447 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
8448 			sym_cap = &crypto_cap->sym;
8449 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
8450 						d_td->key.len,
8451 						d_td->iv.len) == 0)
8452 				break;
8453 		}
8454 	}
8455 
8456 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
8457 		return -ENOTSUP;
8458 
8459 	/* Setup source mbuf payload */
8460 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8461 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8462 			rte_pktmbuf_tailroom(ut_params->ibuf));
8463 
8464 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8465 			d_td->ciphertext.len);
8466 
8467 	memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
8468 
8469 	/* Setup cipher session parameters */
8470 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8471 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
8472 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
8473 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
8474 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
8475 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
8476 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8477 	ut_params->cipher_xform.next = NULL;
8478 
8479 	/* Setup DOCSIS session parameters */
8480 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
8481 
8482 	struct rte_security_session_conf sess_conf = {
8483 		.action_type = ut_params->type,
8484 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
8485 		.docsis = ut_params->docsis_xform,
8486 		.crypto_xform = &ut_params->cipher_xform,
8487 	};
8488 
8489 	/* Create security session */
8490 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
8491 					ts_params->session_priv_mpool);
8492 
8493 	if (!ut_params->sec_session) {
8494 		printf("TestCase %s(%d) line %d: %s\n",
8495 			__func__, i, __LINE__, "failed to allocate session");
8496 		ret = TEST_FAILED;
8497 		goto on_err;
8498 	}
8499 
8500 	/* Generate crypto op data structure */
8501 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8502 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8503 	if (!ut_params->op) {
8504 		printf("TestCase %s(%d) line %d: %s\n",
8505 			__func__, i, __LINE__,
8506 			"failed to allocate symmetric crypto operation");
8507 		ret = TEST_FAILED;
8508 		goto on_err;
8509 	}
8510 
8511 	/* Setup CRC operation parameters */
8512 	crc_len = d_td->ciphertext.no_crc == false ?
8513 			(d_td->ciphertext.len -
8514 				d_td->ciphertext.crc_offset -
8515 				RTE_ETHER_CRC_LEN) :
8516 			0;
8517 	crc_len = crc_len > 0 ? crc_len : 0;
8518 	crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
8519 	ut_params->op->sym->auth.data.length = crc_len;
8520 	ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
8521 
8522 	/* Setup cipher operation parameters */
8523 	cipher_len = d_td->ciphertext.no_cipher == false ?
8524 			(d_td->ciphertext.len -
8525 				d_td->ciphertext.cipher_offset) :
8526 			0;
8527 	cipher_len = cipher_len > 0 ? cipher_len : 0;
8528 	ut_params->op->sym->cipher.data.length = cipher_len;
8529 	ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
8530 
8531 	/* Setup cipher IV */
8532 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
8533 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
8534 
8535 	/* Attach session to operation */
8536 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8537 
8538 	/* Set crypto operation mbufs */
8539 	ut_params->op->sym->m_src = ut_params->ibuf;
8540 	ut_params->op->sym->m_dst = NULL;
8541 
8542 	/* Process crypto operation */
8543 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
8544 			NULL) {
8545 		printf("TestCase %s(%d) line %d: %s\n",
8546 			__func__, i, __LINE__,
8547 			"failed to process security crypto op");
8548 		ret = TEST_FAILED;
8549 		goto on_err;
8550 	}
8551 
8552 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8553 		printf("TestCase %s(%d) line %d: %s\n",
8554 			__func__, i, __LINE__, "crypto op processing failed");
8555 		ret = TEST_FAILED;
8556 		goto on_err;
8557 	}
8558 
8559 	/* Validate plaintext */
8560 	plaintext = ciphertext;
8561 
8562 	if (memcmp(plaintext, d_td->plaintext.data,
8563 			d_td->plaintext.len - crc_data_len)) {
8564 		printf("TestCase %s(%d) line %d: %s\n",
8565 			__func__, i, __LINE__, "plaintext not as expected\n");
8566 		rte_hexdump(stdout, "expected", d_td->plaintext.data,
8567 				d_td->plaintext.len);
8568 		rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
8569 		ret = TEST_FAILED;
8570 		goto on_err;
8571 	}
8572 
8573 on_err:
8574 	rte_crypto_op_free(ut_params->op);
8575 	ut_params->op = NULL;
8576 
8577 	if (ut_params->sec_session)
8578 		rte_security_session_destroy(ctx, ut_params->sec_session);
8579 	ut_params->sec_session = NULL;
8580 
8581 	rte_pktmbuf_free(ut_params->ibuf);
8582 	ut_params->ibuf = NULL;
8583 
8584 	return ret;
8585 }
8586 
8587 static int
8588 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td)
8589 {
8590 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8591 	struct crypto_unittest_params *ut_params = &unittest_params;
8592 	uint8_t *plaintext, *ciphertext;
8593 	uint8_t *iv_ptr;
8594 	int32_t cipher_len, crc_len;
8595 	int ret = TEST_SUCCESS;
8596 
8597 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8598 					rte_cryptodev_get_sec_ctx(
8599 						ts_params->valid_devs[0]);
8600 
8601 	/* Verify the capabilities */
8602 	struct rte_security_capability_idx sec_cap_idx;
8603 	const struct rte_security_capability *sec_cap;
8604 	const struct rte_cryptodev_capabilities *crypto_cap;
8605 	const struct rte_cryptodev_symmetric_capability *sym_cap;
8606 	int j = 0;
8607 
8608 	sec_cap_idx.action = ut_params->type;
8609 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
8610 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
8611 
8612 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
8613 	if (sec_cap == NULL)
8614 		return -ENOTSUP;
8615 
8616 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
8617 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
8618 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
8619 				crypto_cap->sym.xform_type ==
8620 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
8621 				crypto_cap->sym.cipher.algo ==
8622 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
8623 			sym_cap = &crypto_cap->sym;
8624 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
8625 						d_td->key.len,
8626 						d_td->iv.len) == 0)
8627 				break;
8628 		}
8629 	}
8630 
8631 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
8632 		return -ENOTSUP;
8633 
8634 	/* Setup source mbuf payload */
8635 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8636 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8637 			rte_pktmbuf_tailroom(ut_params->ibuf));
8638 
8639 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8640 			d_td->plaintext.len);
8641 
8642 	memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
8643 
8644 	/* Setup cipher session parameters */
8645 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8646 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
8647 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
8648 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
8649 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
8650 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
8651 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8652 	ut_params->cipher_xform.next = NULL;
8653 
8654 	/* Setup DOCSIS session parameters */
8655 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
8656 
8657 	struct rte_security_session_conf sess_conf = {
8658 		.action_type = ut_params->type,
8659 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
8660 		.docsis = ut_params->docsis_xform,
8661 		.crypto_xform = &ut_params->cipher_xform,
8662 	};
8663 
8664 	/* Create security session */
8665 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
8666 					ts_params->session_priv_mpool);
8667 
8668 	if (!ut_params->sec_session) {
8669 		printf("TestCase %s(%d) line %d: %s\n",
8670 			__func__, i, __LINE__, "failed to allocate session");
8671 		ret = TEST_FAILED;
8672 		goto on_err;
8673 	}
8674 
8675 	/* Generate crypto op data structure */
8676 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8677 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8678 	if (!ut_params->op) {
8679 		printf("TestCase %s(%d) line %d: %s\n",
8680 			__func__, i, __LINE__,
8681 			"failed to allocate security crypto operation");
8682 		ret = TEST_FAILED;
8683 		goto on_err;
8684 	}
8685 
8686 	/* Setup CRC operation parameters */
8687 	crc_len = d_td->plaintext.no_crc == false ?
8688 			(d_td->plaintext.len -
8689 				d_td->plaintext.crc_offset -
8690 				RTE_ETHER_CRC_LEN) :
8691 			0;
8692 	crc_len = crc_len > 0 ? crc_len : 0;
8693 	ut_params->op->sym->auth.data.length = crc_len;
8694 	ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
8695 
8696 	/* Setup cipher operation parameters */
8697 	cipher_len = d_td->plaintext.no_cipher == false ?
8698 			(d_td->plaintext.len -
8699 				d_td->plaintext.cipher_offset) :
8700 			0;
8701 	cipher_len = cipher_len > 0 ? cipher_len : 0;
8702 	ut_params->op->sym->cipher.data.length = cipher_len;
8703 	ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
8704 
8705 	/* Setup cipher IV */
8706 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
8707 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
8708 
8709 	/* Attach session to operation */
8710 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8711 
8712 	/* Set crypto operation mbufs */
8713 	ut_params->op->sym->m_src = ut_params->ibuf;
8714 	ut_params->op->sym->m_dst = NULL;
8715 
8716 	/* Process crypto operation */
8717 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
8718 			NULL) {
8719 		printf("TestCase %s(%d) line %d: %s\n",
8720 			__func__, i, __LINE__,
8721 			"failed to process security crypto op");
8722 		ret = TEST_FAILED;
8723 		goto on_err;
8724 	}
8725 
8726 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8727 		printf("TestCase %s(%d) line %d: %s\n",
8728 			__func__, i, __LINE__, "crypto op processing failed");
8729 		ret = TEST_FAILED;
8730 		goto on_err;
8731 	}
8732 
8733 	/* Validate ciphertext */
8734 	ciphertext = plaintext;
8735 
8736 	if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
8737 		printf("TestCase %s(%d) line %d: %s\n",
8738 			__func__, i, __LINE__, "ciphertext not as expected\n");
8739 		rte_hexdump(stdout, "expected", d_td->ciphertext.data,
8740 				d_td->ciphertext.len);
8741 		rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
8742 		ret = TEST_FAILED;
8743 		goto on_err;
8744 	}
8745 
8746 on_err:
8747 	rte_crypto_op_free(ut_params->op);
8748 	ut_params->op = NULL;
8749 
8750 	if (ut_params->sec_session)
8751 		rte_security_session_destroy(ctx, ut_params->sec_session);
8752 	ut_params->sec_session = NULL;
8753 
8754 	rte_pktmbuf_free(ut_params->ibuf);
8755 	ut_params->ibuf = NULL;
8756 
8757 	return ret;
8758 }
8759 
8760 #define TEST_DOCSIS_COUNT(func) do {			\
8761 	int ret = func;					\
8762 	if (ret == TEST_SUCCESS)  {			\
8763 		printf("\t%2d)", n++);			\
8764 		printf("+++++ PASSED:" #func"\n");	\
8765 		p++;					\
8766 	} else if (ret == -ENOTSUP) {			\
8767 		printf("\t%2d)", n++);			\
8768 		printf("~~~~~ UNSUPP:" #func"\n");	\
8769 		u++;					\
8770 	} else {					\
8771 		printf("\t%2d)", n++);			\
8772 		printf("----- FAILED:" #func"\n");	\
8773 		f++;					\
8774 	}						\
8775 } while (0)
8776 
8777 static int
8778 test_DOCSIS_PROTO_uplink_all(void)
8779 {
8780 	int p = 0, u = 0, f = 0, n = 0;
8781 
8782 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1));
8783 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2));
8784 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3));
8785 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4));
8786 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5));
8787 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6));
8788 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7));
8789 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8));
8790 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9));
8791 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10));
8792 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11));
8793 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12));
8794 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13));
8795 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14));
8796 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15));
8797 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16));
8798 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17));
8799 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18));
8800 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19));
8801 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20));
8802 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21));
8803 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22));
8804 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23));
8805 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24));
8806 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25));
8807 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26));
8808 
8809 	if (f)
8810 		printf("## %s: %d passed out of %d (%d unsupported)\n",
8811 			__func__, p, n, u);
8812 
8813 	return f;
8814 };
8815 
8816 static int
8817 test_DOCSIS_PROTO_downlink_all(void)
8818 {
8819 	int p = 0, u = 0, f = 0, n = 0;
8820 
8821 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1));
8822 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2));
8823 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3));
8824 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4));
8825 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5));
8826 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6));
8827 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7));
8828 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8));
8829 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9));
8830 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10));
8831 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11));
8832 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12));
8833 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13));
8834 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14));
8835 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15));
8836 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16));
8837 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17));
8838 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18));
8839 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19));
8840 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20));
8841 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21));
8842 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22));
8843 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23));
8844 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24));
8845 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25));
8846 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26));
8847 
8848 	if (f)
8849 		printf("## %s: %d passed out of %d (%d unsupported)\n",
8850 			__func__, p, n, u);
8851 
8852 	return f;
8853 };
8854 
8855 static int
8856 test_DOCSIS_PROTO_all(void)
8857 {
8858 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8859 	struct crypto_unittest_params *ut_params = &unittest_params;
8860 	struct rte_cryptodev_info dev_info;
8861 	int status;
8862 
8863 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8864 	uint64_t feat_flags = dev_info.feature_flags;
8865 
8866 	if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
8867 		return -ENOTSUP;
8868 
8869 	/* Set action type */
8870 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
8871 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
8872 		gbl_action_type;
8873 
8874 	if (security_proto_supported(ut_params->type,
8875 			RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
8876 		return -ENOTSUP;
8877 
8878 	status = test_DOCSIS_PROTO_uplink_all();
8879 	status += test_DOCSIS_PROTO_downlink_all();
8880 
8881 	if (status)
8882 		return TEST_FAILED;
8883 	else
8884 		return TEST_SUCCESS;
8885 }
8886 #endif
8887 
8888 static int
8889 test_AES_GCM_authenticated_encryption_test_case_1(void)
8890 {
8891 	return test_authenticated_encryption(&gcm_test_case_1);
8892 }
8893 
8894 static int
8895 test_AES_GCM_authenticated_encryption_test_case_2(void)
8896 {
8897 	return test_authenticated_encryption(&gcm_test_case_2);
8898 }
8899 
8900 static int
8901 test_AES_GCM_authenticated_encryption_test_case_3(void)
8902 {
8903 	return test_authenticated_encryption(&gcm_test_case_3);
8904 }
8905 
8906 static int
8907 test_AES_GCM_authenticated_encryption_test_case_4(void)
8908 {
8909 	return test_authenticated_encryption(&gcm_test_case_4);
8910 }
8911 
8912 static int
8913 test_AES_GCM_authenticated_encryption_test_case_5(void)
8914 {
8915 	return test_authenticated_encryption(&gcm_test_case_5);
8916 }
8917 
8918 static int
8919 test_AES_GCM_authenticated_encryption_test_case_6(void)
8920 {
8921 	return test_authenticated_encryption(&gcm_test_case_6);
8922 }
8923 
8924 static int
8925 test_AES_GCM_authenticated_encryption_test_case_7(void)
8926 {
8927 	return test_authenticated_encryption(&gcm_test_case_7);
8928 }
8929 
8930 static int
8931 test_AES_GCM_authenticated_encryption_test_case_8(void)
8932 {
8933 	return test_authenticated_encryption(&gcm_test_case_8);
8934 }
8935 
8936 static int
8937 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
8938 {
8939 	return test_authenticated_encryption(&gcm_J0_test_case_1);
8940 }
8941 
8942 static int
8943 test_AES_GCM_auth_encryption_test_case_192_1(void)
8944 {
8945 	return test_authenticated_encryption(&gcm_test_case_192_1);
8946 }
8947 
8948 static int
8949 test_AES_GCM_auth_encryption_test_case_192_2(void)
8950 {
8951 	return test_authenticated_encryption(&gcm_test_case_192_2);
8952 }
8953 
8954 static int
8955 test_AES_GCM_auth_encryption_test_case_192_3(void)
8956 {
8957 	return test_authenticated_encryption(&gcm_test_case_192_3);
8958 }
8959 
8960 static int
8961 test_AES_GCM_auth_encryption_test_case_192_4(void)
8962 {
8963 	return test_authenticated_encryption(&gcm_test_case_192_4);
8964 }
8965 
8966 static int
8967 test_AES_GCM_auth_encryption_test_case_192_5(void)
8968 {
8969 	return test_authenticated_encryption(&gcm_test_case_192_5);
8970 }
8971 
8972 static int
8973 test_AES_GCM_auth_encryption_test_case_192_6(void)
8974 {
8975 	return test_authenticated_encryption(&gcm_test_case_192_6);
8976 }
8977 
8978 static int
8979 test_AES_GCM_auth_encryption_test_case_192_7(void)
8980 {
8981 	return test_authenticated_encryption(&gcm_test_case_192_7);
8982 }
8983 
8984 static int
8985 test_AES_GCM_auth_encryption_test_case_256_1(void)
8986 {
8987 	return test_authenticated_encryption(&gcm_test_case_256_1);
8988 }
8989 
8990 static int
8991 test_AES_GCM_auth_encryption_test_case_256_2(void)
8992 {
8993 	return test_authenticated_encryption(&gcm_test_case_256_2);
8994 }
8995 
8996 static int
8997 test_AES_GCM_auth_encryption_test_case_256_3(void)
8998 {
8999 	return test_authenticated_encryption(&gcm_test_case_256_3);
9000 }
9001 
9002 static int
9003 test_AES_GCM_auth_encryption_test_case_256_4(void)
9004 {
9005 	return test_authenticated_encryption(&gcm_test_case_256_4);
9006 }
9007 
9008 static int
9009 test_AES_GCM_auth_encryption_test_case_256_5(void)
9010 {
9011 	return test_authenticated_encryption(&gcm_test_case_256_5);
9012 }
9013 
9014 static int
9015 test_AES_GCM_auth_encryption_test_case_256_6(void)
9016 {
9017 	return test_authenticated_encryption(&gcm_test_case_256_6);
9018 }
9019 
9020 static int
9021 test_AES_GCM_auth_encryption_test_case_256_7(void)
9022 {
9023 	return test_authenticated_encryption(&gcm_test_case_256_7);
9024 }
9025 
9026 static int
9027 test_AES_GCM_auth_encryption_test_case_aad_1(void)
9028 {
9029 	return test_authenticated_encryption(&gcm_test_case_aad_1);
9030 }
9031 
9032 static int
9033 test_AES_GCM_auth_encryption_test_case_aad_2(void)
9034 {
9035 	return test_authenticated_encryption(&gcm_test_case_aad_2);
9036 }
9037 
9038 static int
9039 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
9040 {
9041 	struct aead_test_data tdata;
9042 	int res;
9043 
9044 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9045 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9046 	tdata.iv.data[0] += 1;
9047 	res = test_authenticated_encryption(&tdata);
9048 	if (res == -ENOTSUP)
9049 		return res;
9050 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9051 	return TEST_SUCCESS;
9052 }
9053 
9054 static int
9055 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
9056 {
9057 	struct aead_test_data tdata;
9058 	int res;
9059 
9060 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9061 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9062 	tdata.plaintext.data[0] += 1;
9063 	res = test_authenticated_encryption(&tdata);
9064 	if (res == -ENOTSUP)
9065 		return res;
9066 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9067 	return TEST_SUCCESS;
9068 }
9069 
9070 static int
9071 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
9072 {
9073 	struct aead_test_data tdata;
9074 	int res;
9075 
9076 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9077 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9078 	tdata.ciphertext.data[0] += 1;
9079 	res = test_authenticated_encryption(&tdata);
9080 	if (res == -ENOTSUP)
9081 		return res;
9082 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9083 	return TEST_SUCCESS;
9084 }
9085 
9086 static int
9087 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
9088 {
9089 	struct aead_test_data tdata;
9090 	int res;
9091 
9092 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9093 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9094 	tdata.aad.len += 1;
9095 	res = test_authenticated_encryption(&tdata);
9096 	if (res == -ENOTSUP)
9097 		return res;
9098 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9099 	return TEST_SUCCESS;
9100 }
9101 
9102 static int
9103 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
9104 {
9105 	struct aead_test_data tdata;
9106 	uint8_t aad[gcm_test_case_7.aad.len];
9107 	int res;
9108 
9109 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9110 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9111 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
9112 	aad[0] += 1;
9113 	tdata.aad.data = aad;
9114 	res = test_authenticated_encryption(&tdata);
9115 	if (res == -ENOTSUP)
9116 		return res;
9117 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9118 	return TEST_SUCCESS;
9119 }
9120 
9121 static int
9122 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
9123 {
9124 	struct aead_test_data tdata;
9125 	int res;
9126 
9127 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9128 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9129 	tdata.auth_tag.data[0] += 1;
9130 	res = test_authenticated_encryption(&tdata);
9131 	if (res == -ENOTSUP)
9132 		return res;
9133 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9134 	return TEST_SUCCESS;
9135 }
9136 
9137 static int
9138 test_authenticated_decryption(const struct aead_test_data *tdata)
9139 {
9140 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9141 	struct crypto_unittest_params *ut_params = &unittest_params;
9142 
9143 	int retval;
9144 	uint8_t *plaintext;
9145 	uint32_t i;
9146 	struct rte_cryptodev_info dev_info;
9147 
9148 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9149 	uint64_t feat_flags = dev_info.feature_flags;
9150 
9151 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
9152 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
9153 		printf("Device doesn't support RAW data-path APIs.\n");
9154 		return -ENOTSUP;
9155 	}
9156 
9157 	/* Verify the capabilities */
9158 	struct rte_cryptodev_sym_capability_idx cap_idx;
9159 	const struct rte_cryptodev_symmetric_capability *capability;
9160 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9161 	cap_idx.algo.aead = tdata->algo;
9162 	capability = rte_cryptodev_sym_capability_get(
9163 			ts_params->valid_devs[0], &cap_idx);
9164 	if (capability == NULL)
9165 		return -ENOTSUP;
9166 	if (rte_cryptodev_sym_capability_check_aead(
9167 			capability, tdata->key.len, tdata->auth_tag.len,
9168 			tdata->aad.len, tdata->iv.len))
9169 		return -ENOTSUP;
9170 
9171 	/* Create AEAD session */
9172 	retval = create_aead_session(ts_params->valid_devs[0],
9173 			tdata->algo,
9174 			RTE_CRYPTO_AEAD_OP_DECRYPT,
9175 			tdata->key.data, tdata->key.len,
9176 			tdata->aad.len, tdata->auth_tag.len,
9177 			tdata->iv.len);
9178 	if (retval < 0)
9179 		return retval;
9180 
9181 	/* alloc mbuf and set payload */
9182 	if (tdata->aad.len > MBUF_SIZE) {
9183 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
9184 		/* Populate full size of add data */
9185 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
9186 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
9187 	} else
9188 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9189 
9190 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9191 			rte_pktmbuf_tailroom(ut_params->ibuf));
9192 
9193 	/* Create AEAD operation */
9194 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
9195 	if (retval < 0)
9196 		return retval;
9197 
9198 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9199 
9200 	ut_params->op->sym->m_src = ut_params->ibuf;
9201 
9202 	/* Process crypto operation */
9203 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9204 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
9205 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9206 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
9207 				ut_params->op, 0, 0, 0, 0);
9208 	else
9209 		TEST_ASSERT_NOT_NULL(
9210 			process_crypto_request(ts_params->valid_devs[0],
9211 			ut_params->op), "failed to process sym crypto op");
9212 
9213 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9214 			"crypto op processing failed");
9215 
9216 	if (ut_params->op->sym->m_dst)
9217 		plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
9218 				uint8_t *);
9219 	else
9220 		plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
9221 				uint8_t *,
9222 				ut_params->op->sym->cipher.data.offset);
9223 
9224 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
9225 
9226 	/* Validate obuf */
9227 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
9228 			plaintext,
9229 			tdata->plaintext.data,
9230 			tdata->plaintext.len,
9231 			"Plaintext data not as expected");
9232 
9233 	TEST_ASSERT_EQUAL(ut_params->op->status,
9234 			RTE_CRYPTO_OP_STATUS_SUCCESS,
9235 			"Authentication failed");
9236 
9237 	return 0;
9238 }
9239 
9240 static int
9241 test_AES_GCM_authenticated_decryption_test_case_1(void)
9242 {
9243 	return test_authenticated_decryption(&gcm_test_case_1);
9244 }
9245 
9246 static int
9247 test_AES_GCM_authenticated_decryption_test_case_2(void)
9248 {
9249 	return test_authenticated_decryption(&gcm_test_case_2);
9250 }
9251 
9252 static int
9253 test_AES_GCM_authenticated_decryption_test_case_3(void)
9254 {
9255 	return test_authenticated_decryption(&gcm_test_case_3);
9256 }
9257 
9258 static int
9259 test_AES_GCM_authenticated_decryption_test_case_4(void)
9260 {
9261 	return test_authenticated_decryption(&gcm_test_case_4);
9262 }
9263 
9264 static int
9265 test_AES_GCM_authenticated_decryption_test_case_5(void)
9266 {
9267 	return test_authenticated_decryption(&gcm_test_case_5);
9268 }
9269 
9270 static int
9271 test_AES_GCM_authenticated_decryption_test_case_6(void)
9272 {
9273 	return test_authenticated_decryption(&gcm_test_case_6);
9274 }
9275 
9276 static int
9277 test_AES_GCM_authenticated_decryption_test_case_7(void)
9278 {
9279 	return test_authenticated_decryption(&gcm_test_case_7);
9280 }
9281 
9282 static int
9283 test_AES_GCM_authenticated_decryption_test_case_8(void)
9284 {
9285 	return test_authenticated_decryption(&gcm_test_case_8);
9286 }
9287 
9288 static int
9289 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
9290 {
9291 	return test_authenticated_decryption(&gcm_J0_test_case_1);
9292 }
9293 
9294 static int
9295 test_AES_GCM_auth_decryption_test_case_192_1(void)
9296 {
9297 	return test_authenticated_decryption(&gcm_test_case_192_1);
9298 }
9299 
9300 static int
9301 test_AES_GCM_auth_decryption_test_case_192_2(void)
9302 {
9303 	return test_authenticated_decryption(&gcm_test_case_192_2);
9304 }
9305 
9306 static int
9307 test_AES_GCM_auth_decryption_test_case_192_3(void)
9308 {
9309 	return test_authenticated_decryption(&gcm_test_case_192_3);
9310 }
9311 
9312 static int
9313 test_AES_GCM_auth_decryption_test_case_192_4(void)
9314 {
9315 	return test_authenticated_decryption(&gcm_test_case_192_4);
9316 }
9317 
9318 static int
9319 test_AES_GCM_auth_decryption_test_case_192_5(void)
9320 {
9321 	return test_authenticated_decryption(&gcm_test_case_192_5);
9322 }
9323 
9324 static int
9325 test_AES_GCM_auth_decryption_test_case_192_6(void)
9326 {
9327 	return test_authenticated_decryption(&gcm_test_case_192_6);
9328 }
9329 
9330 static int
9331 test_AES_GCM_auth_decryption_test_case_192_7(void)
9332 {
9333 	return test_authenticated_decryption(&gcm_test_case_192_7);
9334 }
9335 
9336 static int
9337 test_AES_GCM_auth_decryption_test_case_256_1(void)
9338 {
9339 	return test_authenticated_decryption(&gcm_test_case_256_1);
9340 }
9341 
9342 static int
9343 test_AES_GCM_auth_decryption_test_case_256_2(void)
9344 {
9345 	return test_authenticated_decryption(&gcm_test_case_256_2);
9346 }
9347 
9348 static int
9349 test_AES_GCM_auth_decryption_test_case_256_3(void)
9350 {
9351 	return test_authenticated_decryption(&gcm_test_case_256_3);
9352 }
9353 
9354 static int
9355 test_AES_GCM_auth_decryption_test_case_256_4(void)
9356 {
9357 	return test_authenticated_decryption(&gcm_test_case_256_4);
9358 }
9359 
9360 static int
9361 test_AES_GCM_auth_decryption_test_case_256_5(void)
9362 {
9363 	return test_authenticated_decryption(&gcm_test_case_256_5);
9364 }
9365 
9366 static int
9367 test_AES_GCM_auth_decryption_test_case_256_6(void)
9368 {
9369 	return test_authenticated_decryption(&gcm_test_case_256_6);
9370 }
9371 
9372 static int
9373 test_AES_GCM_auth_decryption_test_case_256_7(void)
9374 {
9375 	return test_authenticated_decryption(&gcm_test_case_256_7);
9376 }
9377 
9378 static int
9379 test_AES_GCM_auth_decryption_test_case_aad_1(void)
9380 {
9381 	return test_authenticated_decryption(&gcm_test_case_aad_1);
9382 }
9383 
9384 static int
9385 test_AES_GCM_auth_decryption_test_case_aad_2(void)
9386 {
9387 	return test_authenticated_decryption(&gcm_test_case_aad_2);
9388 }
9389 
9390 static int
9391 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
9392 {
9393 	struct aead_test_data tdata;
9394 	int res;
9395 
9396 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9397 	tdata.iv.data[0] += 1;
9398 	res = test_authenticated_decryption(&tdata);
9399 	if (res == -ENOTSUP)
9400 		return res;
9401 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9402 	return TEST_SUCCESS;
9403 }
9404 
9405 static int
9406 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
9407 {
9408 	struct aead_test_data tdata;
9409 	int res;
9410 
9411 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9412 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9413 	tdata.plaintext.data[0] += 1;
9414 	res = test_authenticated_decryption(&tdata);
9415 	if (res == -ENOTSUP)
9416 		return res;
9417 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9418 	return TEST_SUCCESS;
9419 }
9420 
9421 static int
9422 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
9423 {
9424 	struct aead_test_data tdata;
9425 	int res;
9426 
9427 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9428 	tdata.ciphertext.data[0] += 1;
9429 	res = test_authenticated_decryption(&tdata);
9430 	if (res == -ENOTSUP)
9431 		return res;
9432 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9433 	return TEST_SUCCESS;
9434 }
9435 
9436 static int
9437 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
9438 {
9439 	struct aead_test_data tdata;
9440 	int res;
9441 
9442 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9443 	tdata.aad.len += 1;
9444 	res = test_authenticated_decryption(&tdata);
9445 	if (res == -ENOTSUP)
9446 		return res;
9447 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9448 	return TEST_SUCCESS;
9449 }
9450 
9451 static int
9452 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
9453 {
9454 	struct aead_test_data tdata;
9455 	uint8_t aad[gcm_test_case_7.aad.len];
9456 	int res;
9457 
9458 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9459 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
9460 	aad[0] += 1;
9461 	tdata.aad.data = aad;
9462 	res = test_authenticated_decryption(&tdata);
9463 	if (res == -ENOTSUP)
9464 		return res;
9465 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9466 	return TEST_SUCCESS;
9467 }
9468 
9469 static int
9470 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
9471 {
9472 	struct aead_test_data tdata;
9473 	int res;
9474 
9475 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9476 	tdata.auth_tag.data[0] += 1;
9477 	res = test_authenticated_decryption(&tdata);
9478 	if (res == -ENOTSUP)
9479 		return res;
9480 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
9481 	return TEST_SUCCESS;
9482 }
9483 
9484 static int
9485 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
9486 {
9487 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9488 	struct crypto_unittest_params *ut_params = &unittest_params;
9489 
9490 	int retval;
9491 	uint8_t *ciphertext, *auth_tag;
9492 	uint16_t plaintext_pad_len;
9493 
9494 	/* Verify the capabilities */
9495 	struct rte_cryptodev_sym_capability_idx cap_idx;
9496 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9497 	cap_idx.algo.aead = tdata->algo;
9498 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9499 			&cap_idx) == NULL)
9500 		return -ENOTSUP;
9501 
9502 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9503 		return -ENOTSUP;
9504 
9505 	/* not supported with CPU crypto */
9506 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9507 		return -ENOTSUP;
9508 
9509 	/* Create AEAD session */
9510 	retval = create_aead_session(ts_params->valid_devs[0],
9511 			tdata->algo,
9512 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
9513 			tdata->key.data, tdata->key.len,
9514 			tdata->aad.len, tdata->auth_tag.len,
9515 			tdata->iv.len);
9516 	if (retval < 0)
9517 		return retval;
9518 
9519 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9520 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9521 
9522 	/* clear mbuf payload */
9523 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9524 			rte_pktmbuf_tailroom(ut_params->ibuf));
9525 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
9526 			rte_pktmbuf_tailroom(ut_params->obuf));
9527 
9528 	/* Create AEAD operation */
9529 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
9530 	if (retval < 0)
9531 		return retval;
9532 
9533 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9534 
9535 	ut_params->op->sym->m_src = ut_params->ibuf;
9536 	ut_params->op->sym->m_dst = ut_params->obuf;
9537 
9538 	/* Process crypto operation */
9539 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
9540 			ut_params->op), "failed to process sym crypto op");
9541 
9542 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9543 			"crypto op processing failed");
9544 
9545 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9546 
9547 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
9548 			ut_params->op->sym->cipher.data.offset);
9549 	auth_tag = ciphertext + plaintext_pad_len;
9550 
9551 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
9552 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
9553 
9554 	/* Validate obuf */
9555 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
9556 			ciphertext,
9557 			tdata->ciphertext.data,
9558 			tdata->ciphertext.len,
9559 			"Ciphertext data not as expected");
9560 
9561 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
9562 			auth_tag,
9563 			tdata->auth_tag.data,
9564 			tdata->auth_tag.len,
9565 			"Generated auth tag not as expected");
9566 
9567 	return 0;
9568 
9569 }
9570 
9571 static int
9572 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
9573 {
9574 	return test_authenticated_encryption_oop(&gcm_test_case_5);
9575 }
9576 
9577 static int
9578 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
9579 {
9580 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9581 	struct crypto_unittest_params *ut_params = &unittest_params;
9582 
9583 	int retval;
9584 	uint8_t *plaintext;
9585 
9586 	/* Verify the capabilities */
9587 	struct rte_cryptodev_sym_capability_idx cap_idx;
9588 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9589 	cap_idx.algo.aead = tdata->algo;
9590 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9591 			&cap_idx) == NULL)
9592 		return -ENOTSUP;
9593 
9594 	/* not supported with CPU crypto and raw data-path APIs*/
9595 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
9596 			global_api_test_type == CRYPTODEV_RAW_API_TEST)
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_DECRYPT,
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 	/* alloc mbuf and set payload */
9610 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9611 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9612 
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_DECRYPT, 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 = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
9636 			ut_params->op->sym->cipher.data.offset);
9637 
9638 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
9639 
9640 	/* Validate obuf */
9641 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
9642 			plaintext,
9643 			tdata->plaintext.data,
9644 			tdata->plaintext.len,
9645 			"Plaintext data not as expected");
9646 
9647 	TEST_ASSERT_EQUAL(ut_params->op->status,
9648 			RTE_CRYPTO_OP_STATUS_SUCCESS,
9649 			"Authentication failed");
9650 	return 0;
9651 }
9652 
9653 static int
9654 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
9655 {
9656 	return test_authenticated_decryption_oop(&gcm_test_case_5);
9657 }
9658 
9659 static int
9660 test_authenticated_encryption_sessionless(
9661 		const struct aead_test_data *tdata)
9662 {
9663 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9664 	struct crypto_unittest_params *ut_params = &unittest_params;
9665 
9666 	int retval;
9667 	uint8_t *ciphertext, *auth_tag;
9668 	uint16_t plaintext_pad_len;
9669 	uint8_t key[tdata->key.len + 1];
9670 	struct rte_cryptodev_info dev_info;
9671 
9672 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9673 	uint64_t feat_flags = dev_info.feature_flags;
9674 
9675 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
9676 		printf("Device doesn't support Sessionless ops.\n");
9677 		return -ENOTSUP;
9678 	}
9679 
9680 	/* not supported with CPU crypto */
9681 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9682 		return -ENOTSUP;
9683 
9684 	/* Verify the capabilities */
9685 	struct rte_cryptodev_sym_capability_idx cap_idx;
9686 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9687 	cap_idx.algo.aead = tdata->algo;
9688 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9689 			&cap_idx) == NULL)
9690 		return -ENOTSUP;
9691 
9692 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9693 
9694 	/* clear mbuf payload */
9695 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9696 			rte_pktmbuf_tailroom(ut_params->ibuf));
9697 
9698 	/* Create AEAD operation */
9699 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
9700 	if (retval < 0)
9701 		return retval;
9702 
9703 	/* Create GCM xform */
9704 	memcpy(key, tdata->key.data, tdata->key.len);
9705 	retval = create_aead_xform(ut_params->op,
9706 			tdata->algo,
9707 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
9708 			key, tdata->key.len,
9709 			tdata->aad.len, tdata->auth_tag.len,
9710 			tdata->iv.len);
9711 	if (retval < 0)
9712 		return retval;
9713 
9714 	ut_params->op->sym->m_src = ut_params->ibuf;
9715 
9716 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
9717 			RTE_CRYPTO_OP_SESSIONLESS,
9718 			"crypto op session type not sessionless");
9719 
9720 	/* Process crypto operation */
9721 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
9722 			ut_params->op), "failed to process sym crypto op");
9723 
9724 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
9725 
9726 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9727 			"crypto op status not success");
9728 
9729 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
9730 
9731 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
9732 			ut_params->op->sym->cipher.data.offset);
9733 	auth_tag = ciphertext + plaintext_pad_len;
9734 
9735 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
9736 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
9737 
9738 	/* Validate obuf */
9739 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
9740 			ciphertext,
9741 			tdata->ciphertext.data,
9742 			tdata->ciphertext.len,
9743 			"Ciphertext data not as expected");
9744 
9745 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
9746 			auth_tag,
9747 			tdata->auth_tag.data,
9748 			tdata->auth_tag.len,
9749 			"Generated auth tag not as expected");
9750 
9751 	return 0;
9752 
9753 }
9754 
9755 static int
9756 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
9757 {
9758 	return test_authenticated_encryption_sessionless(
9759 			&gcm_test_case_5);
9760 }
9761 
9762 static int
9763 test_authenticated_decryption_sessionless(
9764 		const struct aead_test_data *tdata)
9765 {
9766 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9767 	struct crypto_unittest_params *ut_params = &unittest_params;
9768 
9769 	int retval;
9770 	uint8_t *plaintext;
9771 	uint8_t key[tdata->key.len + 1];
9772 	struct rte_cryptodev_info dev_info;
9773 
9774 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9775 	uint64_t feat_flags = dev_info.feature_flags;
9776 
9777 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
9778 		printf("Device doesn't support Sessionless ops.\n");
9779 		return -ENOTSUP;
9780 	}
9781 
9782 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
9783 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
9784 		printf("Device doesn't support RAW data-path APIs.\n");
9785 		return -ENOTSUP;
9786 	}
9787 
9788 	/* not supported with CPU crypto */
9789 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9790 		return -ENOTSUP;
9791 
9792 	/* Verify the capabilities */
9793 	struct rte_cryptodev_sym_capability_idx cap_idx;
9794 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9795 	cap_idx.algo.aead = tdata->algo;
9796 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9797 			&cap_idx) == NULL)
9798 		return -ENOTSUP;
9799 
9800 	/* alloc mbuf and set payload */
9801 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9802 
9803 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9804 			rte_pktmbuf_tailroom(ut_params->ibuf));
9805 
9806 	/* Create AEAD operation */
9807 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
9808 	if (retval < 0)
9809 		return retval;
9810 
9811 	/* Create AEAD xform */
9812 	memcpy(key, tdata->key.data, tdata->key.len);
9813 	retval = create_aead_xform(ut_params->op,
9814 			tdata->algo,
9815 			RTE_CRYPTO_AEAD_OP_DECRYPT,
9816 			key, tdata->key.len,
9817 			tdata->aad.len, tdata->auth_tag.len,
9818 			tdata->iv.len);
9819 	if (retval < 0)
9820 		return retval;
9821 
9822 	ut_params->op->sym->m_src = ut_params->ibuf;
9823 
9824 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
9825 			RTE_CRYPTO_OP_SESSIONLESS,
9826 			"crypto op session type not sessionless");
9827 
9828 	/* Process crypto operation */
9829 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9830 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
9831 				ut_params->op, 0, 0, 0, 0);
9832 	else
9833 		TEST_ASSERT_NOT_NULL(process_crypto_request(
9834 			ts_params->valid_devs[0], ut_params->op),
9835 				"failed to process sym crypto op");
9836 
9837 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
9838 
9839 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9840 			"crypto op status not success");
9841 
9842 	plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
9843 			ut_params->op->sym->cipher.data.offset);
9844 
9845 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
9846 
9847 	/* Validate obuf */
9848 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
9849 			plaintext,
9850 			tdata->plaintext.data,
9851 			tdata->plaintext.len,
9852 			"Plaintext data not as expected");
9853 
9854 	TEST_ASSERT_EQUAL(ut_params->op->status,
9855 			RTE_CRYPTO_OP_STATUS_SUCCESS,
9856 			"Authentication failed");
9857 	return 0;
9858 }
9859 
9860 static int
9861 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
9862 {
9863 	return test_authenticated_decryption_sessionless(
9864 			&gcm_test_case_5);
9865 }
9866 
9867 static int
9868 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
9869 {
9870 	return test_authenticated_encryption(&ccm_test_case_128_1);
9871 }
9872 
9873 static int
9874 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
9875 {
9876 	return test_authenticated_encryption(&ccm_test_case_128_2);
9877 }
9878 
9879 static int
9880 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
9881 {
9882 	return test_authenticated_encryption(&ccm_test_case_128_3);
9883 }
9884 
9885 static int
9886 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
9887 {
9888 	return test_authenticated_decryption(&ccm_test_case_128_1);
9889 }
9890 
9891 static int
9892 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
9893 {
9894 	return test_authenticated_decryption(&ccm_test_case_128_2);
9895 }
9896 
9897 static int
9898 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
9899 {
9900 	return test_authenticated_decryption(&ccm_test_case_128_3);
9901 }
9902 
9903 static int
9904 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
9905 {
9906 	return test_authenticated_encryption(&ccm_test_case_192_1);
9907 }
9908 
9909 static int
9910 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
9911 {
9912 	return test_authenticated_encryption(&ccm_test_case_192_2);
9913 }
9914 
9915 static int
9916 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
9917 {
9918 	return test_authenticated_encryption(&ccm_test_case_192_3);
9919 }
9920 
9921 static int
9922 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
9923 {
9924 	return test_authenticated_decryption(&ccm_test_case_192_1);
9925 }
9926 
9927 static int
9928 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
9929 {
9930 	return test_authenticated_decryption(&ccm_test_case_192_2);
9931 }
9932 
9933 static int
9934 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
9935 {
9936 	return test_authenticated_decryption(&ccm_test_case_192_3);
9937 }
9938 
9939 static int
9940 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
9941 {
9942 	return test_authenticated_encryption(&ccm_test_case_256_1);
9943 }
9944 
9945 static int
9946 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
9947 {
9948 	return test_authenticated_encryption(&ccm_test_case_256_2);
9949 }
9950 
9951 static int
9952 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
9953 {
9954 	return test_authenticated_encryption(&ccm_test_case_256_3);
9955 }
9956 
9957 static int
9958 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
9959 {
9960 	return test_authenticated_decryption(&ccm_test_case_256_1);
9961 }
9962 
9963 static int
9964 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
9965 {
9966 	return test_authenticated_decryption(&ccm_test_case_256_2);
9967 }
9968 
9969 static int
9970 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
9971 {
9972 	return test_authenticated_decryption(&ccm_test_case_256_3);
9973 }
9974 
9975 static int
9976 test_stats(void)
9977 {
9978 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9979 	struct rte_cryptodev_stats stats;
9980 
9981 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9982 		return -ENOTSUP;
9983 
9984 	/* Verify the capabilities */
9985 	struct rte_cryptodev_sym_capability_idx cap_idx;
9986 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
9987 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
9988 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9989 			&cap_idx) == NULL)
9990 		return -ENOTSUP;
9991 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9992 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
9993 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9994 			&cap_idx) == NULL)
9995 		return -ENOTSUP;
9996 
9997 	if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
9998 			== -ENOTSUP)
9999 		return -ENOTSUP;
10000 
10001 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10002 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
10003 			&stats) == -ENODEV),
10004 		"rte_cryptodev_stats_get invalid dev failed");
10005 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
10006 		"rte_cryptodev_stats_get invalid Param failed");
10007 
10008 	/* Test expected values */
10009 	test_AES_CBC_HMAC_SHA1_encrypt_digest();
10010 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10011 			&stats),
10012 		"rte_cryptodev_stats_get failed");
10013 	TEST_ASSERT((stats.enqueued_count == 1),
10014 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10015 	TEST_ASSERT((stats.dequeued_count == 1),
10016 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10017 	TEST_ASSERT((stats.enqueue_err_count == 0),
10018 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10019 	TEST_ASSERT((stats.dequeue_err_count == 0),
10020 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10021 
10022 	/* invalid device but should ignore and not reset device stats*/
10023 	rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
10024 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10025 			&stats),
10026 		"rte_cryptodev_stats_get failed");
10027 	TEST_ASSERT((stats.enqueued_count == 1),
10028 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10029 
10030 	/* check that a valid reset clears stats */
10031 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10032 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10033 			&stats),
10034 					  "rte_cryptodev_stats_get failed");
10035 	TEST_ASSERT((stats.enqueued_count == 0),
10036 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10037 	TEST_ASSERT((stats.dequeued_count == 0),
10038 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10039 
10040 	return TEST_SUCCESS;
10041 }
10042 
10043 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
10044 				   struct crypto_unittest_params *ut_params,
10045 				   enum rte_crypto_auth_operation op,
10046 				   const struct HMAC_MD5_vector *test_case)
10047 {
10048 	uint8_t key[64];
10049 
10050 	memcpy(key, test_case->key.data, test_case->key.len);
10051 
10052 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10053 	ut_params->auth_xform.next = NULL;
10054 	ut_params->auth_xform.auth.op = op;
10055 
10056 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
10057 
10058 	ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
10059 	ut_params->auth_xform.auth.key.length = test_case->key.len;
10060 	ut_params->auth_xform.auth.key.data = key;
10061 
10062 	ut_params->sess = rte_cryptodev_sym_session_create(
10063 			ts_params->session_mpool);
10064 
10065 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10066 			ut_params->sess, &ut_params->auth_xform,
10067 			ts_params->session_priv_mpool);
10068 
10069 	if (ut_params->sess == NULL)
10070 		return TEST_FAILED;
10071 
10072 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10073 
10074 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10075 			rte_pktmbuf_tailroom(ut_params->ibuf));
10076 
10077 	return 0;
10078 }
10079 
10080 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
10081 			      const struct HMAC_MD5_vector *test_case,
10082 			      uint8_t **plaintext)
10083 {
10084 	uint16_t plaintext_pad_len;
10085 
10086 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10087 
10088 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
10089 				16);
10090 
10091 	*plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10092 			plaintext_pad_len);
10093 	memcpy(*plaintext, test_case->plaintext.data,
10094 			test_case->plaintext.len);
10095 
10096 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10097 			ut_params->ibuf, MD5_DIGEST_LEN);
10098 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10099 			"no room to append digest");
10100 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10101 			ut_params->ibuf, plaintext_pad_len);
10102 
10103 	if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
10104 		rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
10105 			   test_case->auth_tag.len);
10106 	}
10107 
10108 	sym_op->auth.data.offset = 0;
10109 	sym_op->auth.data.length = test_case->plaintext.len;
10110 
10111 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10112 	ut_params->op->sym->m_src = ut_params->ibuf;
10113 
10114 	return 0;
10115 }
10116 
10117 static int
10118 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
10119 {
10120 	uint16_t plaintext_pad_len;
10121 	uint8_t *plaintext, *auth_tag;
10122 
10123 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10124 	struct crypto_unittest_params *ut_params = &unittest_params;
10125 	struct rte_cryptodev_info dev_info;
10126 
10127 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10128 	uint64_t feat_flags = dev_info.feature_flags;
10129 
10130 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10131 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10132 		printf("Device doesn't support RAW data-path APIs.\n");
10133 		return -ENOTSUP;
10134 	}
10135 
10136 	/* Verify the capabilities */
10137 	struct rte_cryptodev_sym_capability_idx cap_idx;
10138 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10139 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
10140 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10141 			&cap_idx) == NULL)
10142 		return -ENOTSUP;
10143 
10144 	if (MD5_HMAC_create_session(ts_params, ut_params,
10145 			RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
10146 		return TEST_FAILED;
10147 
10148 	/* Generate Crypto op data structure */
10149 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10150 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10151 	TEST_ASSERT_NOT_NULL(ut_params->op,
10152 			"Failed to allocate symmetric crypto operation struct");
10153 
10154 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
10155 				16);
10156 
10157 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
10158 		return TEST_FAILED;
10159 
10160 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10161 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10162 			ut_params->op);
10163 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10164 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10165 				ut_params->op, 0, 1, 0, 0);
10166 	else
10167 		TEST_ASSERT_NOT_NULL(
10168 			process_crypto_request(ts_params->valid_devs[0],
10169 				ut_params->op),
10170 				"failed to process sym crypto op");
10171 
10172 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10173 			"crypto op processing failed");
10174 
10175 	if (ut_params->op->sym->m_dst) {
10176 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
10177 				uint8_t *, plaintext_pad_len);
10178 	} else {
10179 		auth_tag = plaintext + plaintext_pad_len;
10180 	}
10181 
10182 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10183 			auth_tag,
10184 			test_case->auth_tag.data,
10185 			test_case->auth_tag.len,
10186 			"HMAC_MD5 generated tag not as expected");
10187 
10188 	return TEST_SUCCESS;
10189 }
10190 
10191 static int
10192 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
10193 {
10194 	uint8_t *plaintext;
10195 
10196 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10197 	struct crypto_unittest_params *ut_params = &unittest_params;
10198 	struct rte_cryptodev_info dev_info;
10199 
10200 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10201 	uint64_t feat_flags = dev_info.feature_flags;
10202 
10203 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10204 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10205 		printf("Device doesn't support RAW data-path APIs.\n");
10206 		return -ENOTSUP;
10207 	}
10208 
10209 	/* Verify the capabilities */
10210 	struct rte_cryptodev_sym_capability_idx cap_idx;
10211 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10212 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
10213 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10214 			&cap_idx) == NULL)
10215 		return -ENOTSUP;
10216 
10217 	if (MD5_HMAC_create_session(ts_params, ut_params,
10218 			RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
10219 		return TEST_FAILED;
10220 	}
10221 
10222 	/* Generate Crypto op data structure */
10223 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10224 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10225 	TEST_ASSERT_NOT_NULL(ut_params->op,
10226 			"Failed to allocate symmetric crypto operation struct");
10227 
10228 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
10229 		return TEST_FAILED;
10230 
10231 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10232 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10233 			ut_params->op);
10234 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10235 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10236 				ut_params->op, 0, 1, 0, 0);
10237 	else
10238 		TEST_ASSERT_NOT_NULL(
10239 			process_crypto_request(ts_params->valid_devs[0],
10240 				ut_params->op),
10241 				"failed to process sym crypto op");
10242 
10243 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10244 			"HMAC_MD5 crypto op processing failed");
10245 
10246 	return TEST_SUCCESS;
10247 }
10248 
10249 static int
10250 test_MD5_HMAC_generate_case_1(void)
10251 {
10252 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
10253 }
10254 
10255 static int
10256 test_MD5_HMAC_verify_case_1(void)
10257 {
10258 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
10259 }
10260 
10261 static int
10262 test_MD5_HMAC_generate_case_2(void)
10263 {
10264 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
10265 }
10266 
10267 static int
10268 test_MD5_HMAC_verify_case_2(void)
10269 {
10270 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
10271 }
10272 
10273 static int
10274 test_multi_session(void)
10275 {
10276 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10277 	struct crypto_unittest_params *ut_params = &unittest_params;
10278 
10279 	struct rte_cryptodev_info dev_info;
10280 	struct rte_cryptodev_sym_session **sessions;
10281 
10282 	uint16_t i;
10283 
10284 	/* Verify the capabilities */
10285 	struct rte_cryptodev_sym_capability_idx cap_idx;
10286 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10287 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
10288 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10289 			&cap_idx) == NULL)
10290 		return -ENOTSUP;
10291 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10292 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10293 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10294 			&cap_idx) == NULL)
10295 		return -ENOTSUP;
10296 
10297 	test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
10298 			aes_cbc_key, hmac_sha512_key);
10299 
10300 
10301 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10302 
10303 	sessions = rte_malloc(NULL,
10304 			(sizeof(struct rte_cryptodev_sym_session *) *
10305 			MAX_NB_SESSIONS) + 1, 0);
10306 
10307 	/* Create multiple crypto sessions*/
10308 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
10309 
10310 		sessions[i] = rte_cryptodev_sym_session_create(
10311 				ts_params->session_mpool);
10312 
10313 		rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10314 				sessions[i], &ut_params->auth_xform,
10315 				ts_params->session_priv_mpool);
10316 		TEST_ASSERT_NOT_NULL(sessions[i],
10317 				"Session creation failed at session number %u",
10318 				i);
10319 
10320 		/* Attempt to send a request on each session */
10321 		TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
10322 			sessions[i],
10323 			ut_params,
10324 			ts_params,
10325 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
10326 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
10327 			aes_cbc_iv),
10328 			"Failed to perform decrypt on request number %u.", i);
10329 		/* free crypto operation structure */
10330 		if (ut_params->op)
10331 			rte_crypto_op_free(ut_params->op);
10332 
10333 		/*
10334 		 * free mbuf - both obuf and ibuf are usually the same,
10335 		 * so check if they point at the same address is necessary,
10336 		 * to avoid freeing the mbuf twice.
10337 		 */
10338 		if (ut_params->obuf) {
10339 			rte_pktmbuf_free(ut_params->obuf);
10340 			if (ut_params->ibuf == ut_params->obuf)
10341 				ut_params->ibuf = 0;
10342 			ut_params->obuf = 0;
10343 		}
10344 		if (ut_params->ibuf) {
10345 			rte_pktmbuf_free(ut_params->ibuf);
10346 			ut_params->ibuf = 0;
10347 		}
10348 	}
10349 
10350 	/* Next session create should fail */
10351 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10352 			sessions[i], &ut_params->auth_xform,
10353 			ts_params->session_priv_mpool);
10354 	TEST_ASSERT_NULL(sessions[i],
10355 			"Session creation succeeded unexpectedly!");
10356 
10357 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
10358 		rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
10359 				sessions[i]);
10360 		rte_cryptodev_sym_session_free(sessions[i]);
10361 	}
10362 
10363 	rte_free(sessions);
10364 
10365 	return TEST_SUCCESS;
10366 }
10367 
10368 struct multi_session_params {
10369 	struct crypto_unittest_params ut_params;
10370 	uint8_t *cipher_key;
10371 	uint8_t *hmac_key;
10372 	const uint8_t *cipher;
10373 	const uint8_t *digest;
10374 	uint8_t *iv;
10375 };
10376 
10377 #define MB_SESSION_NUMBER 3
10378 
10379 static int
10380 test_multi_session_random_usage(void)
10381 {
10382 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10383 	struct rte_cryptodev_info dev_info;
10384 	struct rte_cryptodev_sym_session **sessions;
10385 	uint32_t i, j;
10386 	struct multi_session_params ut_paramz[] = {
10387 
10388 		{
10389 			.cipher_key = ms_aes_cbc_key0,
10390 			.hmac_key = ms_hmac_key0,
10391 			.cipher = ms_aes_cbc_cipher0,
10392 			.digest = ms_hmac_digest0,
10393 			.iv = ms_aes_cbc_iv0
10394 		},
10395 		{
10396 			.cipher_key = ms_aes_cbc_key1,
10397 			.hmac_key = ms_hmac_key1,
10398 			.cipher = ms_aes_cbc_cipher1,
10399 			.digest = ms_hmac_digest1,
10400 			.iv = ms_aes_cbc_iv1
10401 		},
10402 		{
10403 			.cipher_key = ms_aes_cbc_key2,
10404 			.hmac_key = ms_hmac_key2,
10405 			.cipher = ms_aes_cbc_cipher2,
10406 			.digest = ms_hmac_digest2,
10407 			.iv = ms_aes_cbc_iv2
10408 		},
10409 
10410 	};
10411 
10412 	/* Verify the capabilities */
10413 	struct rte_cryptodev_sym_capability_idx cap_idx;
10414 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10415 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
10416 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10417 			&cap_idx) == NULL)
10418 		return -ENOTSUP;
10419 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10420 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10421 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10422 			&cap_idx) == NULL)
10423 		return -ENOTSUP;
10424 
10425 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10426 
10427 	sessions = rte_malloc(NULL,
10428 			(sizeof(struct rte_cryptodev_sym_session *)
10429 					* MAX_NB_SESSIONS) + 1, 0);
10430 
10431 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
10432 		sessions[i] = rte_cryptodev_sym_session_create(
10433 				ts_params->session_mpool);
10434 
10435 		rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
10436 				sizeof(struct crypto_unittest_params));
10437 
10438 		test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
10439 				&ut_paramz[i].ut_params,
10440 				ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
10441 
10442 		/* Create multiple crypto sessions*/
10443 		rte_cryptodev_sym_session_init(
10444 				ts_params->valid_devs[0],
10445 				sessions[i],
10446 				&ut_paramz[i].ut_params.auth_xform,
10447 				ts_params->session_priv_mpool);
10448 
10449 		TEST_ASSERT_NOT_NULL(sessions[i],
10450 				"Session creation failed at session number %u",
10451 				i);
10452 
10453 	}
10454 
10455 	srand(time(NULL));
10456 	for (i = 0; i < 40000; i++) {
10457 
10458 		j = rand() % MB_SESSION_NUMBER;
10459 
10460 		TEST_ASSERT_SUCCESS(
10461 			test_AES_CBC_HMAC_SHA512_decrypt_perform(
10462 					sessions[j],
10463 					&ut_paramz[j].ut_params,
10464 					ts_params, ut_paramz[j].cipher,
10465 					ut_paramz[j].digest,
10466 					ut_paramz[j].iv),
10467 			"Failed to perform decrypt on request number %u.", i);
10468 
10469 		if (ut_paramz[j].ut_params.op)
10470 			rte_crypto_op_free(ut_paramz[j].ut_params.op);
10471 
10472 		/*
10473 		 * free mbuf - both obuf and ibuf are usually the same,
10474 		 * so check if they point at the same address is necessary,
10475 		 * to avoid freeing the mbuf twice.
10476 		 */
10477 		if (ut_paramz[j].ut_params.obuf) {
10478 			rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
10479 			if (ut_paramz[j].ut_params.ibuf
10480 					== ut_paramz[j].ut_params.obuf)
10481 				ut_paramz[j].ut_params.ibuf = 0;
10482 			ut_paramz[j].ut_params.obuf = 0;
10483 		}
10484 		if (ut_paramz[j].ut_params.ibuf) {
10485 			rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
10486 			ut_paramz[j].ut_params.ibuf = 0;
10487 		}
10488 	}
10489 
10490 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
10491 		rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
10492 				sessions[i]);
10493 		rte_cryptodev_sym_session_free(sessions[i]);
10494 	}
10495 
10496 	rte_free(sessions);
10497 
10498 	return TEST_SUCCESS;
10499 }
10500 
10501 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
10502 			0xab, 0xab, 0xab, 0xab,
10503 			0xab, 0xab, 0xab, 0xab,
10504 			0xab, 0xab, 0xab, 0xab};
10505 
10506 static int
10507 test_null_invalid_operation(void)
10508 {
10509 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10510 	struct crypto_unittest_params *ut_params = &unittest_params;
10511 	int ret;
10512 
10513 	/* This test is for NULL PMD only */
10514 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
10515 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
10516 		return -ENOTSUP;
10517 
10518 	/* Setup Cipher Parameters */
10519 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10520 	ut_params->cipher_xform.next = NULL;
10521 
10522 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
10523 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
10524 
10525 	ut_params->sess = rte_cryptodev_sym_session_create(
10526 			ts_params->session_mpool);
10527 
10528 	/* Create Crypto session*/
10529 	ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10530 			ut_params->sess, &ut_params->cipher_xform,
10531 			ts_params->session_priv_mpool);
10532 	TEST_ASSERT(ret < 0,
10533 			"Session creation succeeded unexpectedly");
10534 
10535 
10536 	/* Setup HMAC Parameters */
10537 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10538 	ut_params->auth_xform.next = NULL;
10539 
10540 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
10541 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
10542 
10543 	ut_params->sess = rte_cryptodev_sym_session_create(
10544 			ts_params->session_mpool);
10545 
10546 	/* Create Crypto session*/
10547 	ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10548 			ut_params->sess, &ut_params->auth_xform,
10549 			ts_params->session_priv_mpool);
10550 	TEST_ASSERT(ret < 0,
10551 			"Session creation succeeded unexpectedly");
10552 
10553 	return TEST_SUCCESS;
10554 }
10555 
10556 
10557 #define NULL_BURST_LENGTH (32)
10558 
10559 static int
10560 test_null_burst_operation(void)
10561 {
10562 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10563 	struct crypto_unittest_params *ut_params = &unittest_params;
10564 
10565 	unsigned i, burst_len = NULL_BURST_LENGTH;
10566 
10567 	struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
10568 	struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
10569 
10570 	/* This test is for NULL PMD only */
10571 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
10572 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
10573 		return -ENOTSUP;
10574 
10575 	/* Setup Cipher Parameters */
10576 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10577 	ut_params->cipher_xform.next = &ut_params->auth_xform;
10578 
10579 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
10580 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
10581 
10582 	/* Setup HMAC Parameters */
10583 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10584 	ut_params->auth_xform.next = NULL;
10585 
10586 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
10587 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
10588 
10589 	ut_params->sess = rte_cryptodev_sym_session_create(
10590 			ts_params->session_mpool);
10591 
10592 	/* Create Crypto session*/
10593 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10594 			ut_params->sess, &ut_params->cipher_xform,
10595 			ts_params->session_priv_mpool);
10596 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10597 
10598 	TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
10599 			RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
10600 			burst_len, "failed to generate burst of crypto ops");
10601 
10602 	/* Generate an operation for each mbuf in burst */
10603 	for (i = 0; i < burst_len; i++) {
10604 		struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10605 
10606 		TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
10607 
10608 		unsigned *data = (unsigned *)rte_pktmbuf_append(m,
10609 				sizeof(unsigned));
10610 		*data = i;
10611 
10612 		rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
10613 
10614 		burst[i]->sym->m_src = m;
10615 	}
10616 
10617 	/* Process crypto operation */
10618 	TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
10619 			0, burst, burst_len),
10620 			burst_len,
10621 			"Error enqueuing burst");
10622 
10623 	TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
10624 			0, burst_dequeued, burst_len),
10625 			burst_len,
10626 			"Error dequeuing burst");
10627 
10628 
10629 	for (i = 0; i < burst_len; i++) {
10630 		TEST_ASSERT_EQUAL(
10631 			*rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
10632 			*rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
10633 					uint32_t *),
10634 			"data not as expected");
10635 
10636 		rte_pktmbuf_free(burst[i]->sym->m_src);
10637 		rte_crypto_op_free(burst[i]);
10638 	}
10639 
10640 	return TEST_SUCCESS;
10641 }
10642 
10643 static void
10644 generate_gmac_large_plaintext(uint8_t *data)
10645 {
10646 	uint16_t i;
10647 
10648 	for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
10649 		memcpy(&data[i], &data[0], 32);
10650 }
10651 
10652 static int
10653 create_gmac_operation(enum rte_crypto_auth_operation op,
10654 		const struct gmac_test_data *tdata)
10655 {
10656 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10657 	struct crypto_unittest_params *ut_params = &unittest_params;
10658 	struct rte_crypto_sym_op *sym_op;
10659 
10660 	uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10661 
10662 	/* Generate Crypto op data structure */
10663 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10664 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10665 	TEST_ASSERT_NOT_NULL(ut_params->op,
10666 			"Failed to allocate symmetric crypto operation struct");
10667 
10668 	sym_op = ut_params->op->sym;
10669 
10670 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10671 			ut_params->ibuf, tdata->gmac_tag.len);
10672 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10673 			"no room to append digest");
10674 
10675 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10676 			ut_params->ibuf, plaintext_pad_len);
10677 
10678 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
10679 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
10680 				tdata->gmac_tag.len);
10681 		debug_hexdump(stdout, "digest:",
10682 				sym_op->auth.digest.data,
10683 				tdata->gmac_tag.len);
10684 	}
10685 
10686 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
10687 			uint8_t *, IV_OFFSET);
10688 
10689 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
10690 
10691 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
10692 
10693 	sym_op->cipher.data.length = 0;
10694 	sym_op->cipher.data.offset = 0;
10695 
10696 	sym_op->auth.data.offset = 0;
10697 	sym_op->auth.data.length = tdata->plaintext.len;
10698 
10699 	return 0;
10700 }
10701 
10702 static int
10703 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
10704 		const struct gmac_test_data *tdata,
10705 		void *digest_mem, uint64_t digest_phys)
10706 {
10707 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10708 	struct crypto_unittest_params *ut_params = &unittest_params;
10709 	struct rte_crypto_sym_op *sym_op;
10710 
10711 	/* Generate Crypto op data structure */
10712 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10713 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10714 	TEST_ASSERT_NOT_NULL(ut_params->op,
10715 			"Failed to allocate symmetric crypto operation struct");
10716 
10717 	sym_op = ut_params->op->sym;
10718 
10719 	sym_op->auth.digest.data = digest_mem;
10720 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10721 			"no room to append digest");
10722 
10723 	sym_op->auth.digest.phys_addr = digest_phys;
10724 
10725 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
10726 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
10727 				tdata->gmac_tag.len);
10728 		debug_hexdump(stdout, "digest:",
10729 				sym_op->auth.digest.data,
10730 				tdata->gmac_tag.len);
10731 	}
10732 
10733 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
10734 			uint8_t *, IV_OFFSET);
10735 
10736 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
10737 
10738 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
10739 
10740 	sym_op->cipher.data.length = 0;
10741 	sym_op->cipher.data.offset = 0;
10742 
10743 	sym_op->auth.data.offset = 0;
10744 	sym_op->auth.data.length = tdata->plaintext.len;
10745 
10746 	return 0;
10747 }
10748 
10749 static int create_gmac_session(uint8_t dev_id,
10750 		const struct gmac_test_data *tdata,
10751 		enum rte_crypto_auth_operation auth_op)
10752 {
10753 	uint8_t auth_key[tdata->key.len];
10754 
10755 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10756 	struct crypto_unittest_params *ut_params = &unittest_params;
10757 
10758 	memcpy(auth_key, tdata->key.data, tdata->key.len);
10759 
10760 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10761 	ut_params->auth_xform.next = NULL;
10762 
10763 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
10764 	ut_params->auth_xform.auth.op = auth_op;
10765 	ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
10766 	ut_params->auth_xform.auth.key.length = tdata->key.len;
10767 	ut_params->auth_xform.auth.key.data = auth_key;
10768 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
10769 	ut_params->auth_xform.auth.iv.length = tdata->iv.len;
10770 
10771 
10772 	ut_params->sess = rte_cryptodev_sym_session_create(
10773 			ts_params->session_mpool);
10774 
10775 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
10776 			&ut_params->auth_xform,
10777 			ts_params->session_priv_mpool);
10778 
10779 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
10780 
10781 	return 0;
10782 }
10783 
10784 static int
10785 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
10786 {
10787 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10788 	struct crypto_unittest_params *ut_params = &unittest_params;
10789 	struct rte_cryptodev_info dev_info;
10790 
10791 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10792 	uint64_t feat_flags = dev_info.feature_flags;
10793 
10794 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10795 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10796 		printf("Device doesn't support RAW data-path APIs.\n");
10797 		return -ENOTSUP;
10798 	}
10799 
10800 	int retval;
10801 
10802 	uint8_t *auth_tag, *plaintext;
10803 	uint16_t plaintext_pad_len;
10804 
10805 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
10806 			      "No GMAC length in the source data");
10807 
10808 	/* Verify the capabilities */
10809 	struct rte_cryptodev_sym_capability_idx cap_idx;
10810 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10811 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
10812 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10813 			&cap_idx) == NULL)
10814 		return -ENOTSUP;
10815 
10816 	retval = create_gmac_session(ts_params->valid_devs[0],
10817 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
10818 
10819 	if (retval < 0)
10820 		return retval;
10821 
10822 	if (tdata->plaintext.len > MBUF_SIZE)
10823 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
10824 	else
10825 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10826 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10827 			"Failed to allocate input buffer in mempool");
10828 
10829 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10830 			rte_pktmbuf_tailroom(ut_params->ibuf));
10831 
10832 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10833 	/*
10834 	 * Runtime generate the large plain text instead of use hard code
10835 	 * plain text vector. It is done to avoid create huge source file
10836 	 * with the test vector.
10837 	 */
10838 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
10839 		generate_gmac_large_plaintext(tdata->plaintext.data);
10840 
10841 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10842 				plaintext_pad_len);
10843 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
10844 
10845 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
10846 	debug_hexdump(stdout, "plaintext:", plaintext,
10847 			tdata->plaintext.len);
10848 
10849 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
10850 			tdata);
10851 
10852 	if (retval < 0)
10853 		return retval;
10854 
10855 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10856 
10857 	ut_params->op->sym->m_src = ut_params->ibuf;
10858 
10859 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10860 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10861 			ut_params->op);
10862 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10863 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10864 				ut_params->op, 0, 1, 0, 0);
10865 	else
10866 		TEST_ASSERT_NOT_NULL(
10867 			process_crypto_request(ts_params->valid_devs[0],
10868 			ut_params->op), "failed to process sym crypto op");
10869 
10870 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10871 			"crypto op processing failed");
10872 
10873 	if (ut_params->op->sym->m_dst) {
10874 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
10875 				uint8_t *, plaintext_pad_len);
10876 	} else {
10877 		auth_tag = plaintext + plaintext_pad_len;
10878 	}
10879 
10880 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
10881 
10882 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10883 			auth_tag,
10884 			tdata->gmac_tag.data,
10885 			tdata->gmac_tag.len,
10886 			"GMAC Generated auth tag not as expected");
10887 
10888 	return 0;
10889 }
10890 
10891 static int
10892 test_AES_GMAC_authentication_test_case_1(void)
10893 {
10894 	return test_AES_GMAC_authentication(&gmac_test_case_1);
10895 }
10896 
10897 static int
10898 test_AES_GMAC_authentication_test_case_2(void)
10899 {
10900 	return test_AES_GMAC_authentication(&gmac_test_case_2);
10901 }
10902 
10903 static int
10904 test_AES_GMAC_authentication_test_case_3(void)
10905 {
10906 	return test_AES_GMAC_authentication(&gmac_test_case_3);
10907 }
10908 
10909 static int
10910 test_AES_GMAC_authentication_test_case_4(void)
10911 {
10912 	return test_AES_GMAC_authentication(&gmac_test_case_4);
10913 }
10914 
10915 static int
10916 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
10917 {
10918 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10919 	struct crypto_unittest_params *ut_params = &unittest_params;
10920 	int retval;
10921 	uint32_t plaintext_pad_len;
10922 	uint8_t *plaintext;
10923 	struct rte_cryptodev_info dev_info;
10924 
10925 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10926 	uint64_t feat_flags = dev_info.feature_flags;
10927 
10928 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10929 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10930 		printf("Device doesn't support RAW data-path APIs.\n");
10931 		return -ENOTSUP;
10932 	}
10933 
10934 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
10935 			      "No GMAC length in the source data");
10936 
10937 	/* Verify the capabilities */
10938 	struct rte_cryptodev_sym_capability_idx cap_idx;
10939 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10940 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
10941 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10942 			&cap_idx) == NULL)
10943 		return -ENOTSUP;
10944 
10945 	retval = create_gmac_session(ts_params->valid_devs[0],
10946 			tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
10947 
10948 	if (retval < 0)
10949 		return retval;
10950 
10951 	if (tdata->plaintext.len > MBUF_SIZE)
10952 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
10953 	else
10954 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10955 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
10956 			"Failed to allocate input buffer in mempool");
10957 
10958 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10959 			rte_pktmbuf_tailroom(ut_params->ibuf));
10960 
10961 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10962 
10963 	/*
10964 	 * Runtime generate the large plain text instead of use hard code
10965 	 * plain text vector. It is done to avoid create huge source file
10966 	 * with the test vector.
10967 	 */
10968 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
10969 		generate_gmac_large_plaintext(tdata->plaintext.data);
10970 
10971 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10972 				plaintext_pad_len);
10973 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
10974 
10975 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
10976 	debug_hexdump(stdout, "plaintext:", plaintext,
10977 			tdata->plaintext.len);
10978 
10979 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
10980 			tdata);
10981 
10982 	if (retval < 0)
10983 		return retval;
10984 
10985 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10986 
10987 	ut_params->op->sym->m_src = ut_params->ibuf;
10988 
10989 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10990 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10991 			ut_params->op);
10992 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10993 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10994 				ut_params->op, 0, 1, 0, 0);
10995 	else
10996 		TEST_ASSERT_NOT_NULL(
10997 			process_crypto_request(ts_params->valid_devs[0],
10998 			ut_params->op), "failed to process sym crypto op");
10999 
11000 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11001 			"crypto op processing failed");
11002 
11003 	return 0;
11004 
11005 }
11006 
11007 static int
11008 test_AES_GMAC_authentication_verify_test_case_1(void)
11009 {
11010 	return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
11011 }
11012 
11013 static int
11014 test_AES_GMAC_authentication_verify_test_case_2(void)
11015 {
11016 	return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
11017 }
11018 
11019 static int
11020 test_AES_GMAC_authentication_verify_test_case_3(void)
11021 {
11022 	return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
11023 }
11024 
11025 static int
11026 test_AES_GMAC_authentication_verify_test_case_4(void)
11027 {
11028 	return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
11029 }
11030 
11031 static int
11032 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
11033 				uint32_t fragsz)
11034 {
11035 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11036 	struct crypto_unittest_params *ut_params = &unittest_params;
11037 	struct rte_cryptodev_info dev_info;
11038 	uint64_t feature_flags;
11039 	unsigned int trn_data = 0;
11040 	void *digest_mem = NULL;
11041 	uint32_t segs = 1;
11042 	unsigned int to_trn = 0;
11043 	struct rte_mbuf *buf = NULL;
11044 	uint8_t *auth_tag, *plaintext;
11045 	int retval;
11046 
11047 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11048 			      "No GMAC length in the source data");
11049 
11050 	/* Verify the capabilities */
11051 	struct rte_cryptodev_sym_capability_idx cap_idx;
11052 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11053 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11054 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11055 			&cap_idx) == NULL)
11056 		return -ENOTSUP;
11057 
11058 	/* Check for any input SGL support */
11059 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11060 	feature_flags = dev_info.feature_flags;
11061 
11062 	if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) &&
11063 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) &&
11064 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
11065 		return -ENOTSUP;
11066 
11067 	if (fragsz > tdata->plaintext.len)
11068 		fragsz = tdata->plaintext.len;
11069 
11070 	uint16_t plaintext_len = fragsz;
11071 
11072 	retval = create_gmac_session(ts_params->valid_devs[0],
11073 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
11074 
11075 	if (retval < 0)
11076 		return retval;
11077 
11078 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11079 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11080 			"Failed to allocate input buffer in mempool");
11081 
11082 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11083 			rte_pktmbuf_tailroom(ut_params->ibuf));
11084 
11085 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11086 				plaintext_len);
11087 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11088 
11089 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
11090 
11091 	trn_data += plaintext_len;
11092 
11093 	buf = ut_params->ibuf;
11094 
11095 	/*
11096 	 * Loop until no more fragments
11097 	 */
11098 
11099 	while (trn_data < tdata->plaintext.len) {
11100 		++segs;
11101 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
11102 				(tdata->plaintext.len - trn_data) : fragsz;
11103 
11104 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11105 		buf = buf->next;
11106 
11107 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
11108 				rte_pktmbuf_tailroom(buf));
11109 
11110 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
11111 				to_trn);
11112 
11113 		memcpy(plaintext, tdata->plaintext.data + trn_data,
11114 				to_trn);
11115 		trn_data += to_trn;
11116 		if (trn_data  == tdata->plaintext.len)
11117 			digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
11118 					tdata->gmac_tag.len);
11119 	}
11120 	ut_params->ibuf->nb_segs = segs;
11121 
11122 	/*
11123 	 * Place digest at the end of the last buffer
11124 	 */
11125 	uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
11126 
11127 	if (!digest_mem) {
11128 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11129 				+ tdata->gmac_tag.len);
11130 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
11131 				tdata->plaintext.len);
11132 	}
11133 
11134 	retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
11135 			tdata, digest_mem, digest_phys);
11136 
11137 	if (retval < 0)
11138 		return retval;
11139 
11140 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11141 
11142 	ut_params->op->sym->m_src = ut_params->ibuf;
11143 
11144 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11145 		return -ENOTSUP;
11146 
11147 	TEST_ASSERT_NOT_NULL(
11148 		process_crypto_request(ts_params->valid_devs[0],
11149 		ut_params->op), "failed to process sym crypto op");
11150 
11151 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11152 			"crypto op processing failed");
11153 
11154 	auth_tag = digest_mem;
11155 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
11156 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11157 			auth_tag,
11158 			tdata->gmac_tag.data,
11159 			tdata->gmac_tag.len,
11160 			"GMAC Generated auth tag not as expected");
11161 
11162 	return 0;
11163 }
11164 
11165 /* Segment size not multiple of block size (16B) */
11166 static int
11167 test_AES_GMAC_authentication_SGL_40B(void)
11168 {
11169 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
11170 }
11171 
11172 static int
11173 test_AES_GMAC_authentication_SGL_80B(void)
11174 {
11175 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
11176 }
11177 
11178 static int
11179 test_AES_GMAC_authentication_SGL_2048B(void)
11180 {
11181 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
11182 }
11183 
11184 /* Segment size not multiple of block size (16B) */
11185 static int
11186 test_AES_GMAC_authentication_SGL_2047B(void)
11187 {
11188 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
11189 }
11190 
11191 struct test_crypto_vector {
11192 	enum rte_crypto_cipher_algorithm crypto_algo;
11193 	unsigned int cipher_offset;
11194 	unsigned int cipher_len;
11195 
11196 	struct {
11197 		uint8_t data[64];
11198 		unsigned int len;
11199 	} cipher_key;
11200 
11201 	struct {
11202 		uint8_t data[64];
11203 		unsigned int len;
11204 	} iv;
11205 
11206 	struct {
11207 		const uint8_t *data;
11208 		unsigned int len;
11209 	} plaintext;
11210 
11211 	struct {
11212 		const uint8_t *data;
11213 		unsigned int len;
11214 	} ciphertext;
11215 
11216 	enum rte_crypto_auth_algorithm auth_algo;
11217 	unsigned int auth_offset;
11218 
11219 	struct {
11220 		uint8_t data[128];
11221 		unsigned int len;
11222 	} auth_key;
11223 
11224 	struct {
11225 		const uint8_t *data;
11226 		unsigned int len;
11227 	} aad;
11228 
11229 	struct {
11230 		uint8_t data[128];
11231 		unsigned int len;
11232 	} digest;
11233 };
11234 
11235 static const struct test_crypto_vector
11236 hmac_sha1_test_crypto_vector = {
11237 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
11238 	.plaintext = {
11239 		.data = plaintext_hash,
11240 		.len = 512
11241 	},
11242 	.auth_key = {
11243 		.data = {
11244 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
11245 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
11246 			0xDE, 0xF4, 0xDE, 0xAD
11247 		},
11248 		.len = 20
11249 	},
11250 	.digest = {
11251 		.data = {
11252 			0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
11253 			0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
11254 			0x3F, 0x91, 0x64, 0x59
11255 		},
11256 		.len = 20
11257 	}
11258 };
11259 
11260 static const struct test_crypto_vector
11261 aes128_gmac_test_vector = {
11262 	.auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
11263 	.plaintext = {
11264 		.data = plaintext_hash,
11265 		.len = 512
11266 	},
11267 	.iv = {
11268 		.data = {
11269 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
11270 			0x08, 0x09, 0x0A, 0x0B
11271 		},
11272 		.len = 12
11273 	},
11274 	.auth_key = {
11275 		.data = {
11276 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
11277 			0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
11278 		},
11279 		.len = 16
11280 	},
11281 	.digest = {
11282 		.data = {
11283 			0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
11284 			0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
11285 		},
11286 		.len = 16
11287 	}
11288 };
11289 
11290 static const struct test_crypto_vector
11291 aes128cbc_hmac_sha1_test_vector = {
11292 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
11293 	.cipher_offset = 0,
11294 	.cipher_len = 512,
11295 	.cipher_key = {
11296 		.data = {
11297 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
11298 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
11299 		},
11300 		.len = 16
11301 	},
11302 	.iv = {
11303 		.data = {
11304 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
11305 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
11306 		},
11307 		.len = 16
11308 	},
11309 	.plaintext = {
11310 		.data = plaintext_hash,
11311 		.len = 512
11312 	},
11313 	.ciphertext = {
11314 		.data = ciphertext512_aes128cbc,
11315 		.len = 512
11316 	},
11317 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
11318 	.auth_offset = 0,
11319 	.auth_key = {
11320 		.data = {
11321 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
11322 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
11323 			0xDE, 0xF4, 0xDE, 0xAD
11324 		},
11325 		.len = 20
11326 	},
11327 	.digest = {
11328 		.data = {
11329 			0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
11330 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
11331 			0x18, 0x8C, 0x1D, 0x32
11332 		},
11333 		.len = 20
11334 	}
11335 };
11336 
11337 static const struct test_crypto_vector
11338 aes128cbc_hmac_sha1_aad_test_vector = {
11339 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
11340 	.cipher_offset = 8,
11341 	.cipher_len = 496,
11342 	.cipher_key = {
11343 		.data = {
11344 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
11345 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
11346 		},
11347 		.len = 16
11348 	},
11349 	.iv = {
11350 		.data = {
11351 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
11352 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
11353 		},
11354 		.len = 16
11355 	},
11356 	.plaintext = {
11357 		.data = plaintext_hash,
11358 		.len = 512
11359 	},
11360 	.ciphertext = {
11361 		.data = ciphertext512_aes128cbc_aad,
11362 		.len = 512
11363 	},
11364 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
11365 	.auth_offset = 0,
11366 	.auth_key = {
11367 		.data = {
11368 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
11369 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
11370 			0xDE, 0xF4, 0xDE, 0xAD
11371 		},
11372 		.len = 20
11373 	},
11374 	.digest = {
11375 		.data = {
11376 			0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
11377 			0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
11378 			0x62, 0x0F, 0xFB, 0x10
11379 		},
11380 		.len = 20
11381 	}
11382 };
11383 
11384 static void
11385 data_corruption(uint8_t *data)
11386 {
11387 	data[0] += 1;
11388 }
11389 
11390 static void
11391 tag_corruption(uint8_t *data, unsigned int tag_offset)
11392 {
11393 	data[tag_offset] += 1;
11394 }
11395 
11396 static int
11397 create_auth_session(struct crypto_unittest_params *ut_params,
11398 		uint8_t dev_id,
11399 		const struct test_crypto_vector *reference,
11400 		enum rte_crypto_auth_operation auth_op)
11401 {
11402 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11403 	uint8_t auth_key[reference->auth_key.len + 1];
11404 
11405 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
11406 
11407 	/* Setup Authentication Parameters */
11408 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11409 	ut_params->auth_xform.auth.op = auth_op;
11410 	ut_params->auth_xform.next = NULL;
11411 	ut_params->auth_xform.auth.algo = reference->auth_algo;
11412 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
11413 	ut_params->auth_xform.auth.key.data = auth_key;
11414 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
11415 
11416 	/* Create Crypto session*/
11417 	ut_params->sess = rte_cryptodev_sym_session_create(
11418 			ts_params->session_mpool);
11419 
11420 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
11421 				&ut_params->auth_xform,
11422 				ts_params->session_priv_mpool);
11423 
11424 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11425 
11426 	return 0;
11427 }
11428 
11429 static int
11430 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
11431 		uint8_t dev_id,
11432 		const struct test_crypto_vector *reference,
11433 		enum rte_crypto_auth_operation auth_op,
11434 		enum rte_crypto_cipher_operation cipher_op)
11435 {
11436 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11437 	uint8_t cipher_key[reference->cipher_key.len + 1];
11438 	uint8_t auth_key[reference->auth_key.len + 1];
11439 
11440 	memcpy(cipher_key, reference->cipher_key.data,
11441 			reference->cipher_key.len);
11442 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
11443 
11444 	/* Setup Authentication Parameters */
11445 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11446 	ut_params->auth_xform.auth.op = auth_op;
11447 	ut_params->auth_xform.auth.algo = reference->auth_algo;
11448 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
11449 	ut_params->auth_xform.auth.key.data = auth_key;
11450 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
11451 
11452 	if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
11453 		ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
11454 		ut_params->auth_xform.auth.iv.length = reference->iv.len;
11455 	} else {
11456 		ut_params->auth_xform.next = &ut_params->cipher_xform;
11457 
11458 		/* Setup Cipher Parameters */
11459 		ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11460 		ut_params->cipher_xform.next = NULL;
11461 		ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
11462 		ut_params->cipher_xform.cipher.op = cipher_op;
11463 		ut_params->cipher_xform.cipher.key.data = cipher_key;
11464 		ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
11465 		ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
11466 		ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
11467 	}
11468 
11469 	/* Create Crypto session*/
11470 	ut_params->sess = rte_cryptodev_sym_session_create(
11471 			ts_params->session_mpool);
11472 
11473 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
11474 				&ut_params->auth_xform,
11475 				ts_params->session_priv_mpool);
11476 
11477 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11478 
11479 	return 0;
11480 }
11481 
11482 static int
11483 create_auth_operation(struct crypto_testsuite_params *ts_params,
11484 		struct crypto_unittest_params *ut_params,
11485 		const struct test_crypto_vector *reference,
11486 		unsigned int auth_generate)
11487 {
11488 	/* Generate Crypto op data structure */
11489 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11490 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11491 	TEST_ASSERT_NOT_NULL(ut_params->op,
11492 			"Failed to allocate pktmbuf offload");
11493 
11494 	/* Set crypto operation data parameters */
11495 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11496 
11497 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11498 
11499 	/* set crypto operation source mbuf */
11500 	sym_op->m_src = ut_params->ibuf;
11501 
11502 	/* digest */
11503 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11504 			ut_params->ibuf, reference->digest.len);
11505 
11506 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11507 			"no room to append auth tag");
11508 
11509 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11510 			ut_params->ibuf, reference->plaintext.len);
11511 
11512 	if (auth_generate)
11513 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
11514 	else
11515 		memcpy(sym_op->auth.digest.data,
11516 				reference->digest.data,
11517 				reference->digest.len);
11518 
11519 	debug_hexdump(stdout, "digest:",
11520 			sym_op->auth.digest.data,
11521 			reference->digest.len);
11522 
11523 	sym_op->auth.data.length = reference->plaintext.len;
11524 	sym_op->auth.data.offset = 0;
11525 
11526 	return 0;
11527 }
11528 
11529 static int
11530 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
11531 		struct crypto_unittest_params *ut_params,
11532 		const struct test_crypto_vector *reference,
11533 		unsigned int auth_generate)
11534 {
11535 	/* Generate Crypto op data structure */
11536 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11537 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11538 	TEST_ASSERT_NOT_NULL(ut_params->op,
11539 			"Failed to allocate pktmbuf offload");
11540 
11541 	/* Set crypto operation data parameters */
11542 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11543 
11544 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11545 
11546 	/* set crypto operation source mbuf */
11547 	sym_op->m_src = ut_params->ibuf;
11548 
11549 	/* digest */
11550 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11551 			ut_params->ibuf, reference->digest.len);
11552 
11553 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11554 			"no room to append auth tag");
11555 
11556 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11557 			ut_params->ibuf, reference->ciphertext.len);
11558 
11559 	if (auth_generate)
11560 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
11561 	else
11562 		memcpy(sym_op->auth.digest.data,
11563 				reference->digest.data,
11564 				reference->digest.len);
11565 
11566 	debug_hexdump(stdout, "digest:",
11567 			sym_op->auth.digest.data,
11568 			reference->digest.len);
11569 
11570 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
11571 			reference->iv.data, reference->iv.len);
11572 
11573 	sym_op->cipher.data.length = 0;
11574 	sym_op->cipher.data.offset = 0;
11575 
11576 	sym_op->auth.data.length = reference->plaintext.len;
11577 	sym_op->auth.data.offset = 0;
11578 
11579 	return 0;
11580 }
11581 
11582 static int
11583 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
11584 		struct crypto_unittest_params *ut_params,
11585 		const struct test_crypto_vector *reference,
11586 		unsigned int auth_generate)
11587 {
11588 	/* Generate Crypto op data structure */
11589 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11590 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11591 	TEST_ASSERT_NOT_NULL(ut_params->op,
11592 			"Failed to allocate pktmbuf offload");
11593 
11594 	/* Set crypto operation data parameters */
11595 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11596 
11597 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11598 
11599 	/* set crypto operation source mbuf */
11600 	sym_op->m_src = ut_params->ibuf;
11601 
11602 	/* digest */
11603 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11604 			ut_params->ibuf, reference->digest.len);
11605 
11606 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11607 			"no room to append auth tag");
11608 
11609 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11610 			ut_params->ibuf, reference->ciphertext.len);
11611 
11612 	if (auth_generate)
11613 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
11614 	else
11615 		memcpy(sym_op->auth.digest.data,
11616 				reference->digest.data,
11617 				reference->digest.len);
11618 
11619 	debug_hexdump(stdout, "digest:",
11620 			sym_op->auth.digest.data,
11621 			reference->digest.len);
11622 
11623 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
11624 			reference->iv.data, reference->iv.len);
11625 
11626 	sym_op->cipher.data.length = reference->cipher_len;
11627 	sym_op->cipher.data.offset = reference->cipher_offset;
11628 
11629 	sym_op->auth.data.length = reference->plaintext.len;
11630 	sym_op->auth.data.offset = reference->auth_offset;
11631 
11632 	return 0;
11633 }
11634 
11635 static int
11636 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
11637 		struct crypto_unittest_params *ut_params,
11638 		const struct test_crypto_vector *reference)
11639 {
11640 	return create_auth_operation(ts_params, ut_params, reference, 0);
11641 }
11642 
11643 static int
11644 create_auth_verify_GMAC_operation(
11645 		struct crypto_testsuite_params *ts_params,
11646 		struct crypto_unittest_params *ut_params,
11647 		const struct test_crypto_vector *reference)
11648 {
11649 	return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
11650 }
11651 
11652 static int
11653 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
11654 		struct crypto_unittest_params *ut_params,
11655 		const struct test_crypto_vector *reference)
11656 {
11657 	return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
11658 }
11659 
11660 static int
11661 test_authentication_verify_fail_when_data_corruption(
11662 		struct crypto_testsuite_params *ts_params,
11663 		struct crypto_unittest_params *ut_params,
11664 		const struct test_crypto_vector *reference,
11665 		unsigned int data_corrupted)
11666 {
11667 	int retval;
11668 
11669 	uint8_t *plaintext;
11670 	struct rte_cryptodev_info dev_info;
11671 
11672 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11673 	uint64_t feat_flags = dev_info.feature_flags;
11674 
11675 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11676 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11677 		printf("Device doesn't support RAW data-path APIs.\n");
11678 		return -ENOTSUP;
11679 	}
11680 
11681 	/* Verify the capabilities */
11682 	struct rte_cryptodev_sym_capability_idx cap_idx;
11683 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11684 	cap_idx.algo.auth = reference->auth_algo;
11685 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11686 			&cap_idx) == NULL)
11687 		return -ENOTSUP;
11688 
11689 
11690 	/* Create session */
11691 	retval = create_auth_session(ut_params,
11692 			ts_params->valid_devs[0],
11693 			reference,
11694 			RTE_CRYPTO_AUTH_OP_VERIFY);
11695 	if (retval < 0)
11696 		return retval;
11697 
11698 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11699 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11700 			"Failed to allocate input buffer in mempool");
11701 
11702 	/* clear mbuf payload */
11703 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11704 			rte_pktmbuf_tailroom(ut_params->ibuf));
11705 
11706 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11707 			reference->plaintext.len);
11708 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11709 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
11710 
11711 	debug_hexdump(stdout, "plaintext:", plaintext,
11712 		reference->plaintext.len);
11713 
11714 	/* Create operation */
11715 	retval = create_auth_verify_operation(ts_params, ut_params, reference);
11716 
11717 	if (retval < 0)
11718 		return retval;
11719 
11720 	if (data_corrupted)
11721 		data_corruption(plaintext);
11722 	else
11723 		tag_corruption(plaintext, reference->plaintext.len);
11724 
11725 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
11726 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11727 			ut_params->op);
11728 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
11729 			RTE_CRYPTO_OP_STATUS_SUCCESS,
11730 			"authentication not failed");
11731 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11732 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11733 				ut_params->op, 0, 1, 0, 0);
11734 	else {
11735 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
11736 			ut_params->op);
11737 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
11738 	}
11739 
11740 	return 0;
11741 }
11742 
11743 static int
11744 test_authentication_verify_GMAC_fail_when_corruption(
11745 		struct crypto_testsuite_params *ts_params,
11746 		struct crypto_unittest_params *ut_params,
11747 		const struct test_crypto_vector *reference,
11748 		unsigned int data_corrupted)
11749 {
11750 	int retval;
11751 	uint8_t *plaintext;
11752 	struct rte_cryptodev_info dev_info;
11753 
11754 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11755 	uint64_t feat_flags = dev_info.feature_flags;
11756 
11757 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11758 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11759 		printf("Device doesn't support RAW data-path APIs.\n");
11760 		return -ENOTSUP;
11761 	}
11762 
11763 	/* Verify the capabilities */
11764 	struct rte_cryptodev_sym_capability_idx cap_idx;
11765 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11766 	cap_idx.algo.auth = reference->auth_algo;
11767 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11768 			&cap_idx) == NULL)
11769 		return -ENOTSUP;
11770 
11771 	/* Create session */
11772 	retval = create_auth_cipher_session(ut_params,
11773 			ts_params->valid_devs[0],
11774 			reference,
11775 			RTE_CRYPTO_AUTH_OP_VERIFY,
11776 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
11777 	if (retval < 0)
11778 		return retval;
11779 
11780 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11781 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11782 			"Failed to allocate input buffer in mempool");
11783 
11784 	/* clear mbuf payload */
11785 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11786 			rte_pktmbuf_tailroom(ut_params->ibuf));
11787 
11788 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11789 			reference->plaintext.len);
11790 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11791 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
11792 
11793 	debug_hexdump(stdout, "plaintext:", plaintext,
11794 		reference->plaintext.len);
11795 
11796 	/* Create operation */
11797 	retval = create_auth_verify_GMAC_operation(ts_params,
11798 			ut_params,
11799 			reference);
11800 
11801 	if (retval < 0)
11802 		return retval;
11803 
11804 	if (data_corrupted)
11805 		data_corruption(plaintext);
11806 	else
11807 		tag_corruption(plaintext, reference->aad.len);
11808 
11809 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
11810 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11811 			ut_params->op);
11812 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
11813 			RTE_CRYPTO_OP_STATUS_SUCCESS,
11814 			"authentication not failed");
11815 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11816 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11817 				ut_params->op, 0, 1, 0, 0);
11818 	else {
11819 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
11820 			ut_params->op);
11821 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
11822 	}
11823 
11824 	return 0;
11825 }
11826 
11827 static int
11828 test_authenticated_decryption_fail_when_corruption(
11829 		struct crypto_testsuite_params *ts_params,
11830 		struct crypto_unittest_params *ut_params,
11831 		const struct test_crypto_vector *reference,
11832 		unsigned int data_corrupted)
11833 {
11834 	int retval;
11835 
11836 	uint8_t *ciphertext;
11837 	struct rte_cryptodev_info dev_info;
11838 
11839 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11840 	uint64_t feat_flags = dev_info.feature_flags;
11841 
11842 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11843 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11844 		printf("Device doesn't support RAW data-path APIs.\n");
11845 		return -ENOTSUP;
11846 	}
11847 
11848 	/* Verify the capabilities */
11849 	struct rte_cryptodev_sym_capability_idx cap_idx;
11850 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11851 	cap_idx.algo.auth = reference->auth_algo;
11852 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11853 			&cap_idx) == NULL)
11854 		return -ENOTSUP;
11855 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11856 	cap_idx.algo.cipher = reference->crypto_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 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11879 			reference->ciphertext.len);
11880 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
11881 	memcpy(ciphertext, reference->ciphertext.data,
11882 			reference->ciphertext.len);
11883 
11884 	/* Create operation */
11885 	retval = create_cipher_auth_verify_operation(ts_params,
11886 			ut_params,
11887 			reference);
11888 
11889 	if (retval < 0)
11890 		return retval;
11891 
11892 	if (data_corrupted)
11893 		data_corruption(ciphertext);
11894 	else
11895 		tag_corruption(ciphertext, reference->ciphertext.len);
11896 
11897 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
11898 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11899 			ut_params->op);
11900 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
11901 			RTE_CRYPTO_OP_STATUS_SUCCESS,
11902 			"authentication not failed");
11903 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11904 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11905 				ut_params->op, 1, 1, 0, 0);
11906 	else {
11907 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
11908 			ut_params->op);
11909 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
11910 	}
11911 
11912 	return 0;
11913 }
11914 
11915 static int
11916 test_authenticated_encryt_with_esn(
11917 		struct crypto_testsuite_params *ts_params,
11918 		struct crypto_unittest_params *ut_params,
11919 		const struct test_crypto_vector *reference)
11920 {
11921 	int retval;
11922 
11923 	uint8_t *authciphertext, *plaintext, *auth_tag;
11924 	uint16_t plaintext_pad_len;
11925 	uint8_t cipher_key[reference->cipher_key.len + 1];
11926 	uint8_t auth_key[reference->auth_key.len + 1];
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 	memcpy(cipher_key, reference->cipher_key.data,
11953 			reference->cipher_key.len);
11954 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
11955 
11956 	/* Setup Cipher Parameters */
11957 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11958 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
11959 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11960 	ut_params->cipher_xform.cipher.key.data = cipher_key;
11961 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
11962 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
11963 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
11964 
11965 	ut_params->cipher_xform.next = &ut_params->auth_xform;
11966 
11967 	/* Setup Authentication Parameters */
11968 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11969 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11970 	ut_params->auth_xform.auth.algo = reference->auth_algo;
11971 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
11972 	ut_params->auth_xform.auth.key.data = auth_key;
11973 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
11974 	ut_params->auth_xform.next = NULL;
11975 
11976 	/* Create Crypto session*/
11977 	ut_params->sess = rte_cryptodev_sym_session_create(
11978 			ts_params->session_mpool);
11979 
11980 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11981 				ut_params->sess,
11982 				&ut_params->cipher_xform,
11983 				ts_params->session_priv_mpool);
11984 
11985 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11986 
11987 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11988 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11989 			"Failed to allocate input buffer in mempool");
11990 
11991 	/* clear mbuf payload */
11992 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11993 			rte_pktmbuf_tailroom(ut_params->ibuf));
11994 
11995 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11996 			reference->plaintext.len);
11997 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11998 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
11999 
12000 	/* Create operation */
12001 	retval = create_cipher_auth_operation(ts_params,
12002 			ut_params,
12003 			reference, 0);
12004 
12005 	if (retval < 0)
12006 		return retval;
12007 
12008 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12009 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12010 			ut_params->op);
12011 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12012 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12013 				ut_params->op, 1, 1, 0, 0);
12014 	else
12015 		ut_params->op = process_crypto_request(
12016 			ts_params->valid_devs[0], ut_params->op);
12017 
12018 	TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
12019 
12020 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12021 			"crypto op processing failed");
12022 
12023 	plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
12024 
12025 	authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
12026 			ut_params->op->sym->auth.data.offset);
12027 	auth_tag = authciphertext + plaintext_pad_len;
12028 	debug_hexdump(stdout, "ciphertext:", authciphertext,
12029 			reference->ciphertext.len);
12030 	debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
12031 
12032 	/* Validate obuf */
12033 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12034 			authciphertext,
12035 			reference->ciphertext.data,
12036 			reference->ciphertext.len,
12037 			"Ciphertext data not as expected");
12038 
12039 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12040 			auth_tag,
12041 			reference->digest.data,
12042 			reference->digest.len,
12043 			"Generated digest not as expected");
12044 
12045 	return TEST_SUCCESS;
12046 
12047 }
12048 
12049 static int
12050 test_authenticated_decrypt_with_esn(
12051 		struct crypto_testsuite_params *ts_params,
12052 		struct crypto_unittest_params *ut_params,
12053 		const struct test_crypto_vector *reference)
12054 {
12055 	int retval;
12056 
12057 	uint8_t *ciphertext;
12058 	uint8_t cipher_key[reference->cipher_key.len + 1];
12059 	uint8_t auth_key[reference->auth_key.len + 1];
12060 	struct rte_cryptodev_info dev_info;
12061 
12062 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12063 	uint64_t feat_flags = dev_info.feature_flags;
12064 
12065 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12066 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12067 		printf("Device doesn't support RAW data-path APIs.\n");
12068 		return -ENOTSUP;
12069 	}
12070 
12071 	/* Verify the capabilities */
12072 	struct rte_cryptodev_sym_capability_idx cap_idx;
12073 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12074 	cap_idx.algo.auth = reference->auth_algo;
12075 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12076 			&cap_idx) == NULL)
12077 		return -ENOTSUP;
12078 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12079 	cap_idx.algo.cipher = reference->crypto_algo;
12080 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12081 			&cap_idx) == NULL)
12082 		return -ENOTSUP;
12083 
12084 	/* Create session */
12085 	memcpy(cipher_key, reference->cipher_key.data,
12086 			reference->cipher_key.len);
12087 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12088 
12089 	/* Setup Authentication Parameters */
12090 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12091 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
12092 	ut_params->auth_xform.auth.algo = reference->auth_algo;
12093 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12094 	ut_params->auth_xform.auth.key.data = auth_key;
12095 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
12096 	ut_params->auth_xform.next = &ut_params->cipher_xform;
12097 
12098 	/* Setup Cipher Parameters */
12099 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12100 	ut_params->cipher_xform.next = NULL;
12101 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12102 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
12103 	ut_params->cipher_xform.cipher.key.data = cipher_key;
12104 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12105 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12106 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12107 
12108 	/* Create Crypto session*/
12109 	ut_params->sess = rte_cryptodev_sym_session_create(
12110 			ts_params->session_mpool);
12111 
12112 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12113 				ut_params->sess,
12114 				&ut_params->auth_xform,
12115 				ts_params->session_priv_mpool);
12116 
12117 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12118 
12119 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12120 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12121 			"Failed to allocate input buffer in mempool");
12122 
12123 	/* clear mbuf payload */
12124 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12125 			rte_pktmbuf_tailroom(ut_params->ibuf));
12126 
12127 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12128 			reference->ciphertext.len);
12129 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
12130 	memcpy(ciphertext, reference->ciphertext.data,
12131 			reference->ciphertext.len);
12132 
12133 	/* Create operation */
12134 	retval = create_cipher_auth_verify_operation(ts_params,
12135 			ut_params,
12136 			reference);
12137 
12138 	if (retval < 0)
12139 		return retval;
12140 
12141 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12142 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12143 			ut_params->op);
12144 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12145 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12146 				ut_params->op, 1, 1, 0, 0);
12147 	else
12148 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12149 			ut_params->op);
12150 
12151 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
12152 	TEST_ASSERT_EQUAL(ut_params->op->status,
12153 			RTE_CRYPTO_OP_STATUS_SUCCESS,
12154 			"crypto op processing passed");
12155 
12156 	ut_params->obuf = ut_params->op->sym->m_src;
12157 	TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
12158 
12159 	return 0;
12160 }
12161 
12162 static int
12163 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
12164 		const struct aead_test_data *tdata,
12165 		void *digest_mem, uint64_t digest_phys)
12166 {
12167 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12168 	struct crypto_unittest_params *ut_params = &unittest_params;
12169 
12170 	const unsigned int auth_tag_len = tdata->auth_tag.len;
12171 	const unsigned int iv_len = tdata->iv.len;
12172 	unsigned int aad_len = tdata->aad.len;
12173 	unsigned int aad_len_pad = 0;
12174 
12175 	/* Generate Crypto op data structure */
12176 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12177 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12178 	TEST_ASSERT_NOT_NULL(ut_params->op,
12179 		"Failed to allocate symmetric crypto operation struct");
12180 
12181 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12182 
12183 	sym_op->aead.digest.data = digest_mem;
12184 
12185 	TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
12186 			"no room to append digest");
12187 
12188 	sym_op->aead.digest.phys_addr = digest_phys;
12189 
12190 	if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
12191 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
12192 				auth_tag_len);
12193 		debug_hexdump(stdout, "digest:",
12194 				sym_op->aead.digest.data,
12195 				auth_tag_len);
12196 	}
12197 
12198 	/* Append aad data */
12199 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
12200 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12201 				uint8_t *, IV_OFFSET);
12202 
12203 		/* Copy IV 1 byte after the IV pointer, according to the API */
12204 		rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
12205 
12206 		aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
12207 
12208 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
12209 				ut_params->ibuf, aad_len);
12210 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
12211 				"no room to prepend aad");
12212 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
12213 				ut_params->ibuf);
12214 
12215 		memset(sym_op->aead.aad.data, 0, aad_len);
12216 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
12217 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
12218 
12219 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
12220 		debug_hexdump(stdout, "aad:",
12221 				sym_op->aead.aad.data, aad_len);
12222 	} else {
12223 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12224 				uint8_t *, IV_OFFSET);
12225 
12226 		rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
12227 
12228 		aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
12229 
12230 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
12231 				ut_params->ibuf, aad_len_pad);
12232 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
12233 				"no room to prepend aad");
12234 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
12235 				ut_params->ibuf);
12236 
12237 		memset(sym_op->aead.aad.data, 0, aad_len);
12238 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
12239 
12240 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
12241 		debug_hexdump(stdout, "aad:",
12242 				sym_op->aead.aad.data, aad_len);
12243 	}
12244 
12245 	sym_op->aead.data.length = tdata->plaintext.len;
12246 	sym_op->aead.data.offset = aad_len_pad;
12247 
12248 	return 0;
12249 }
12250 
12251 #define SGL_MAX_NO	16
12252 
12253 static int
12254 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
12255 		const int oop, uint32_t fragsz, uint32_t fragsz_oop)
12256 {
12257 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12258 	struct crypto_unittest_params *ut_params = &unittest_params;
12259 	struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
12260 	int retval;
12261 	int to_trn = 0;
12262 	int to_trn_tbl[SGL_MAX_NO];
12263 	int segs = 1;
12264 	unsigned int trn_data = 0;
12265 	uint8_t *plaintext, *ciphertext, *auth_tag;
12266 	struct rte_cryptodev_info dev_info;
12267 
12268 	/* Verify the capabilities */
12269 	struct rte_cryptodev_sym_capability_idx cap_idx;
12270 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
12271 	cap_idx.algo.aead = tdata->algo;
12272 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12273 			&cap_idx) == NULL)
12274 		return -ENOTSUP;
12275 
12276 	/* OOP not supported with CPU crypto */
12277 	if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12278 		return -ENOTSUP;
12279 
12280 	/* Detailed check for the particular SGL support flag */
12281 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12282 	if (!oop) {
12283 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
12284 		if (sgl_in && (!(dev_info.feature_flags &
12285 				RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
12286 			return -ENOTSUP;
12287 
12288 		uint64_t feat_flags = dev_info.feature_flags;
12289 
12290 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12291 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12292 			printf("Device doesn't support RAW data-path APIs.\n");
12293 			return -ENOTSUP;
12294 		}
12295 	} else {
12296 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
12297 		unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
12298 				tdata->plaintext.len;
12299 		/* Raw data path API does not support OOP */
12300 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12301 			return -ENOTSUP;
12302 		if (sgl_in && !sgl_out) {
12303 			if (!(dev_info.feature_flags &
12304 					RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
12305 				return -ENOTSUP;
12306 		} else if (!sgl_in && sgl_out) {
12307 			if (!(dev_info.feature_flags &
12308 					RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
12309 				return -ENOTSUP;
12310 		} else if (sgl_in && sgl_out) {
12311 			if (!(dev_info.feature_flags &
12312 					RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
12313 				return -ENOTSUP;
12314 		}
12315 	}
12316 
12317 	if (fragsz > tdata->plaintext.len)
12318 		fragsz = tdata->plaintext.len;
12319 
12320 	uint16_t plaintext_len = fragsz;
12321 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
12322 
12323 	if (fragsz_oop > tdata->plaintext.len)
12324 		frag_size_oop = tdata->plaintext.len;
12325 
12326 	int ecx = 0;
12327 	void *digest_mem = NULL;
12328 
12329 	uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
12330 
12331 	if (tdata->plaintext.len % fragsz != 0) {
12332 		if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
12333 			return 1;
12334 	}	else {
12335 		if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
12336 			return 1;
12337 	}
12338 
12339 	/*
12340 	 * For out-op-place we need to alloc another mbuf
12341 	 */
12342 	if (oop) {
12343 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12344 		rte_pktmbuf_append(ut_params->obuf,
12345 				frag_size_oop + prepend_len);
12346 		buf_oop = ut_params->obuf;
12347 	}
12348 
12349 	/* Create AEAD session */
12350 	retval = create_aead_session(ts_params->valid_devs[0],
12351 			tdata->algo,
12352 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
12353 			tdata->key.data, tdata->key.len,
12354 			tdata->aad.len, tdata->auth_tag.len,
12355 			tdata->iv.len);
12356 	if (retval < 0)
12357 		return retval;
12358 
12359 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12360 
12361 	/* clear mbuf payload */
12362 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12363 			rte_pktmbuf_tailroom(ut_params->ibuf));
12364 
12365 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12366 			plaintext_len);
12367 
12368 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
12369 
12370 	trn_data += plaintext_len;
12371 
12372 	buf = ut_params->ibuf;
12373 
12374 	/*
12375 	 * Loop until no more fragments
12376 	 */
12377 
12378 	while (trn_data < tdata->plaintext.len) {
12379 		++segs;
12380 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
12381 				(tdata->plaintext.len - trn_data) : fragsz;
12382 
12383 		to_trn_tbl[ecx++] = to_trn;
12384 
12385 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12386 		buf = buf->next;
12387 
12388 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
12389 				rte_pktmbuf_tailroom(buf));
12390 
12391 		/* OOP */
12392 		if (oop && !fragsz_oop) {
12393 			buf_last_oop = buf_oop->next =
12394 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
12395 			buf_oop = buf_oop->next;
12396 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
12397 					0, rte_pktmbuf_tailroom(buf_oop));
12398 			rte_pktmbuf_append(buf_oop, to_trn);
12399 		}
12400 
12401 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
12402 				to_trn);
12403 
12404 		memcpy(plaintext, tdata->plaintext.data + trn_data,
12405 				to_trn);
12406 		trn_data += to_trn;
12407 		if (trn_data  == tdata->plaintext.len) {
12408 			if (oop) {
12409 				if (!fragsz_oop)
12410 					digest_mem = rte_pktmbuf_append(buf_oop,
12411 						tdata->auth_tag.len);
12412 			} else
12413 				digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
12414 					tdata->auth_tag.len);
12415 		}
12416 	}
12417 
12418 	uint64_t digest_phys = 0;
12419 
12420 	ut_params->ibuf->nb_segs = segs;
12421 
12422 	segs = 1;
12423 	if (fragsz_oop && oop) {
12424 		to_trn = 0;
12425 		ecx = 0;
12426 
12427 		if (frag_size_oop == tdata->plaintext.len) {
12428 			digest_mem = rte_pktmbuf_append(ut_params->obuf,
12429 				tdata->auth_tag.len);
12430 
12431 			digest_phys = rte_pktmbuf_iova_offset(
12432 					ut_params->obuf,
12433 					tdata->plaintext.len + prepend_len);
12434 		}
12435 
12436 		trn_data = frag_size_oop;
12437 		while (trn_data < tdata->plaintext.len) {
12438 			++segs;
12439 			to_trn =
12440 				(tdata->plaintext.len - trn_data <
12441 						frag_size_oop) ?
12442 				(tdata->plaintext.len - trn_data) :
12443 						frag_size_oop;
12444 
12445 			to_trn_tbl[ecx++] = to_trn;
12446 
12447 			buf_last_oop = buf_oop->next =
12448 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
12449 			buf_oop = buf_oop->next;
12450 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
12451 					0, rte_pktmbuf_tailroom(buf_oop));
12452 			rte_pktmbuf_append(buf_oop, to_trn);
12453 
12454 			trn_data += to_trn;
12455 
12456 			if (trn_data  == tdata->plaintext.len) {
12457 				digest_mem = rte_pktmbuf_append(buf_oop,
12458 					tdata->auth_tag.len);
12459 			}
12460 		}
12461 
12462 		ut_params->obuf->nb_segs = segs;
12463 	}
12464 
12465 	/*
12466 	 * Place digest at the end of the last buffer
12467 	 */
12468 	if (!digest_phys)
12469 		digest_phys = rte_pktmbuf_iova(buf) + to_trn;
12470 	if (oop && buf_last_oop)
12471 		digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
12472 
12473 	if (!digest_mem && !oop) {
12474 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12475 				+ tdata->auth_tag.len);
12476 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
12477 				tdata->plaintext.len);
12478 	}
12479 
12480 	/* Create AEAD operation */
12481 	retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
12482 			tdata, digest_mem, digest_phys);
12483 
12484 	if (retval < 0)
12485 		return retval;
12486 
12487 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12488 
12489 	ut_params->op->sym->m_src = ut_params->ibuf;
12490 	if (oop)
12491 		ut_params->op->sym->m_dst = ut_params->obuf;
12492 
12493 	/* Process crypto operation */
12494 	if (oop == IN_PLACE &&
12495 			gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12496 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
12497 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12498 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12499 				ut_params->op, 0, 0, 0, 0);
12500 	else
12501 		TEST_ASSERT_NOT_NULL(
12502 			process_crypto_request(ts_params->valid_devs[0],
12503 			ut_params->op), "failed to process sym crypto op");
12504 
12505 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12506 			"crypto op processing failed");
12507 
12508 
12509 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
12510 			uint8_t *, prepend_len);
12511 	if (oop) {
12512 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
12513 				uint8_t *, prepend_len);
12514 	}
12515 
12516 	if (fragsz_oop)
12517 		fragsz = fragsz_oop;
12518 
12519 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12520 			ciphertext,
12521 			tdata->ciphertext.data,
12522 			fragsz,
12523 			"Ciphertext data not as expected");
12524 
12525 	buf = ut_params->op->sym->m_src->next;
12526 	if (oop)
12527 		buf = ut_params->op->sym->m_dst->next;
12528 
12529 	unsigned int off = fragsz;
12530 
12531 	ecx = 0;
12532 	while (buf) {
12533 		ciphertext = rte_pktmbuf_mtod(buf,
12534 				uint8_t *);
12535 
12536 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
12537 				ciphertext,
12538 				tdata->ciphertext.data + off,
12539 				to_trn_tbl[ecx],
12540 				"Ciphertext data not as expected");
12541 
12542 		off += to_trn_tbl[ecx++];
12543 		buf = buf->next;
12544 	}
12545 
12546 	auth_tag = digest_mem;
12547 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12548 			auth_tag,
12549 			tdata->auth_tag.data,
12550 			tdata->auth_tag.len,
12551 			"Generated auth tag not as expected");
12552 
12553 	return 0;
12554 }
12555 
12556 static int
12557 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
12558 {
12559 	return test_authenticated_encryption_SGL(
12560 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
12561 }
12562 
12563 static int
12564 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
12565 {
12566 	return test_authenticated_encryption_SGL(
12567 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
12568 }
12569 
12570 static int
12571 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
12572 {
12573 	return test_authenticated_encryption_SGL(
12574 			&gcm_test_case_8, OUT_OF_PLACE, 400,
12575 			gcm_test_case_8.plaintext.len);
12576 }
12577 
12578 static int
12579 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
12580 {
12581 	/* This test is not for OPENSSL PMD */
12582 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
12583 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
12584 		return -ENOTSUP;
12585 
12586 	return test_authenticated_encryption_SGL(
12587 			&gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
12588 }
12589 
12590 static int
12591 test_authentication_verify_fail_when_data_corrupted(
12592 		struct crypto_testsuite_params *ts_params,
12593 		struct crypto_unittest_params *ut_params,
12594 		const struct test_crypto_vector *reference)
12595 {
12596 	return test_authentication_verify_fail_when_data_corruption(
12597 			ts_params, ut_params, reference, 1);
12598 }
12599 
12600 static int
12601 test_authentication_verify_fail_when_tag_corrupted(
12602 		struct crypto_testsuite_params *ts_params,
12603 		struct crypto_unittest_params *ut_params,
12604 		const struct test_crypto_vector *reference)
12605 {
12606 	return test_authentication_verify_fail_when_data_corruption(
12607 			ts_params, ut_params, reference, 0);
12608 }
12609 
12610 static int
12611 test_authentication_verify_GMAC_fail_when_data_corrupted(
12612 		struct crypto_testsuite_params *ts_params,
12613 		struct crypto_unittest_params *ut_params,
12614 		const struct test_crypto_vector *reference)
12615 {
12616 	return test_authentication_verify_GMAC_fail_when_corruption(
12617 			ts_params, ut_params, reference, 1);
12618 }
12619 
12620 static int
12621 test_authentication_verify_GMAC_fail_when_tag_corrupted(
12622 		struct crypto_testsuite_params *ts_params,
12623 		struct crypto_unittest_params *ut_params,
12624 		const struct test_crypto_vector *reference)
12625 {
12626 	return test_authentication_verify_GMAC_fail_when_corruption(
12627 			ts_params, ut_params, reference, 0);
12628 }
12629 
12630 static int
12631 test_authenticated_decryption_fail_when_data_corrupted(
12632 		struct crypto_testsuite_params *ts_params,
12633 		struct crypto_unittest_params *ut_params,
12634 		const struct test_crypto_vector *reference)
12635 {
12636 	return test_authenticated_decryption_fail_when_corruption(
12637 			ts_params, ut_params, reference, 1);
12638 }
12639 
12640 static int
12641 test_authenticated_decryption_fail_when_tag_corrupted(
12642 		struct crypto_testsuite_params *ts_params,
12643 		struct crypto_unittest_params *ut_params,
12644 		const struct test_crypto_vector *reference)
12645 {
12646 	return test_authenticated_decryption_fail_when_corruption(
12647 			ts_params, ut_params, reference, 0);
12648 }
12649 
12650 static int
12651 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
12652 {
12653 	return test_authentication_verify_fail_when_data_corrupted(
12654 			&testsuite_params, &unittest_params,
12655 			&hmac_sha1_test_crypto_vector);
12656 }
12657 
12658 static int
12659 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
12660 {
12661 	return test_authentication_verify_fail_when_tag_corrupted(
12662 			&testsuite_params, &unittest_params,
12663 			&hmac_sha1_test_crypto_vector);
12664 }
12665 
12666 static int
12667 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
12668 {
12669 	return test_authentication_verify_GMAC_fail_when_data_corrupted(
12670 			&testsuite_params, &unittest_params,
12671 			&aes128_gmac_test_vector);
12672 }
12673 
12674 static int
12675 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
12676 {
12677 	return test_authentication_verify_GMAC_fail_when_tag_corrupted(
12678 			&testsuite_params, &unittest_params,
12679 			&aes128_gmac_test_vector);
12680 }
12681 
12682 static int
12683 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
12684 {
12685 	return test_authenticated_decryption_fail_when_data_corrupted(
12686 			&testsuite_params,
12687 			&unittest_params,
12688 			&aes128cbc_hmac_sha1_test_vector);
12689 }
12690 
12691 static int
12692 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
12693 {
12694 	return test_authenticated_decryption_fail_when_tag_corrupted(
12695 			&testsuite_params,
12696 			&unittest_params,
12697 			&aes128cbc_hmac_sha1_test_vector);
12698 }
12699 
12700 static int
12701 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
12702 {
12703 	return test_authenticated_encryt_with_esn(
12704 			&testsuite_params,
12705 			&unittest_params,
12706 			&aes128cbc_hmac_sha1_aad_test_vector);
12707 }
12708 
12709 static int
12710 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
12711 {
12712 	return test_authenticated_decrypt_with_esn(
12713 			&testsuite_params,
12714 			&unittest_params,
12715 			&aes128cbc_hmac_sha1_aad_test_vector);
12716 }
12717 
12718 static int
12719 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
12720 {
12721 	return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
12722 }
12723 
12724 static int
12725 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
12726 {
12727 	return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
12728 }
12729 
12730 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
12731 
12732 /* global AESNI worker IDs for the scheduler test */
12733 uint8_t aesni_ids[2];
12734 
12735 static int
12736 test_scheduler_attach_slave_op(void)
12737 {
12738 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12739 	uint8_t sched_id = ts_params->valid_devs[0];
12740 	uint32_t nb_devs, i, nb_devs_attached = 0;
12741 	int ret;
12742 	char vdev_name[32];
12743 
12744 	/* create 2 AESNI_MB if necessary */
12745 	nb_devs = rte_cryptodev_device_count_by_driver(
12746 			rte_cryptodev_driver_id_get(
12747 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)));
12748 	if (nb_devs < 2) {
12749 		for (i = nb_devs; i < 2; i++) {
12750 			snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
12751 					RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
12752 					i);
12753 			ret = rte_vdev_init(vdev_name, NULL);
12754 
12755 			TEST_ASSERT(ret == 0,
12756 				"Failed to create instance %u of"
12757 				" pmd : %s",
12758 				i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
12759 		}
12760 	}
12761 
12762 	/* attach 2 AESNI_MB cdevs */
12763 	for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2;
12764 			i++) {
12765 		struct rte_cryptodev_info info;
12766 		unsigned int session_size;
12767 
12768 		rte_cryptodev_info_get(i, &info);
12769 		if (info.driver_id != rte_cryptodev_driver_id_get(
12770 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
12771 			continue;
12772 
12773 		session_size = rte_cryptodev_sym_get_private_session_size(i);
12774 		/*
12775 		 * Create the session mempool again, since now there are new devices
12776 		 * to use the mempool.
12777 		 */
12778 		if (ts_params->session_mpool) {
12779 			rte_mempool_free(ts_params->session_mpool);
12780 			ts_params->session_mpool = NULL;
12781 		}
12782 		if (ts_params->session_priv_mpool) {
12783 			rte_mempool_free(ts_params->session_priv_mpool);
12784 			ts_params->session_priv_mpool = NULL;
12785 		}
12786 
12787 		if (info.sym.max_nb_sessions != 0 &&
12788 				info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
12789 			RTE_LOG(ERR, USER1,
12790 					"Device does not support "
12791 					"at least %u sessions\n",
12792 					MAX_NB_SESSIONS);
12793 			return TEST_FAILED;
12794 		}
12795 		/*
12796 		 * Create mempool with maximum number of sessions,
12797 		 * to include the session headers
12798 		 */
12799 		if (ts_params->session_mpool == NULL) {
12800 			ts_params->session_mpool =
12801 				rte_cryptodev_sym_session_pool_create(
12802 						"test_sess_mp",
12803 						MAX_NB_SESSIONS, 0, 0, 0,
12804 						SOCKET_ID_ANY);
12805 			TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
12806 					"session mempool allocation failed");
12807 		}
12808 
12809 		/*
12810 		 * Create mempool with maximum number of sessions,
12811 		 * to include device specific session private data
12812 		 */
12813 		if (ts_params->session_priv_mpool == NULL) {
12814 			ts_params->session_priv_mpool = rte_mempool_create(
12815 					"test_sess_mp_priv",
12816 					MAX_NB_SESSIONS,
12817 					session_size,
12818 					0, 0, NULL, NULL, NULL,
12819 					NULL, SOCKET_ID_ANY,
12820 					0);
12821 
12822 			TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
12823 					"session mempool allocation failed");
12824 		}
12825 
12826 		ts_params->qp_conf.mp_session = ts_params->session_mpool;
12827 		ts_params->qp_conf.mp_session_private =
12828 				ts_params->session_priv_mpool;
12829 
12830 		ret = rte_cryptodev_scheduler_worker_attach(sched_id,
12831 				(uint8_t)i);
12832 
12833 		TEST_ASSERT(ret == 0,
12834 			"Failed to attach device %u of pmd : %s", i,
12835 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
12836 
12837 		aesni_ids[nb_devs_attached] = (uint8_t)i;
12838 
12839 		nb_devs_attached++;
12840 	}
12841 
12842 	return 0;
12843 }
12844 
12845 static int
12846 test_scheduler_detach_slave_op(void)
12847 {
12848 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12849 	uint8_t sched_id = ts_params->valid_devs[0];
12850 	uint32_t i;
12851 	int ret;
12852 
12853 	for (i = 0; i < 2; i++) {
12854 		ret = rte_cryptodev_scheduler_worker_detach(sched_id,
12855 				aesni_ids[i]);
12856 		TEST_ASSERT(ret == 0,
12857 			"Failed to detach device %u", aesni_ids[i]);
12858 	}
12859 
12860 	return 0;
12861 }
12862 
12863 static int
12864 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
12865 {
12866 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12867 	uint8_t sched_id = ts_params->valid_devs[0];
12868 	/* set mode */
12869 	return rte_cryptodev_scheduler_mode_set(sched_id,
12870 		scheduler_mode);
12871 }
12872 
12873 static int
12874 test_scheduler_mode_roundrobin_op(void)
12875 {
12876 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
12877 			0, "Failed to set roundrobin mode");
12878 	return 0;
12879 
12880 }
12881 
12882 static int
12883 test_scheduler_mode_multicore_op(void)
12884 {
12885 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
12886 			0, "Failed to set multicore mode");
12887 
12888 	return 0;
12889 }
12890 
12891 static int
12892 test_scheduler_mode_failover_op(void)
12893 {
12894 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
12895 			0, "Failed to set failover mode");
12896 
12897 	return 0;
12898 }
12899 
12900 static int
12901 test_scheduler_mode_pkt_size_distr_op(void)
12902 {
12903 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
12904 			0, "Failed to set pktsize mode");
12905 
12906 	return 0;
12907 }
12908 
12909 static struct unit_test_suite cryptodev_scheduler_testsuite  = {
12910 	.suite_name = "Crypto Device Scheduler Unit Test Suite",
12911 	.setup = testsuite_setup,
12912 	.teardown = testsuite_teardown,
12913 	.unit_test_cases = {
12914 		/* Multi Core */
12915 		TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
12916 		TEST_CASE_ST(NULL, NULL, test_scheduler_mode_multicore_op),
12917 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12918 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12919 		TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12920 		TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
12921 
12922 		/* Round Robin */
12923 		TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
12924 		TEST_CASE_ST(NULL, NULL, test_scheduler_mode_roundrobin_op),
12925 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12926 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12927 		TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12928 		TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
12929 
12930 		/* Fail over */
12931 		TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
12932 		TEST_CASE_ST(NULL, NULL, test_scheduler_mode_failover_op),
12933 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12934 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12935 		TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12936 		TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
12937 
12938 		/* PKT SIZE */
12939 		TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
12940 		TEST_CASE_ST(NULL, NULL, test_scheduler_mode_pkt_size_distr_op),
12941 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12942 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12943 		TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12944 		TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
12945 
12946 		TEST_CASES_END() /**< NULL terminate unit test array */
12947 	}
12948 };
12949 
12950 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */
12951 
12952 static struct unit_test_suite cryptodev_testsuite  = {
12953 	.suite_name = "Crypto Unit Test Suite",
12954 	.setup = testsuite_setup,
12955 	.teardown = testsuite_teardown,
12956 	.unit_test_cases = {
12957 		TEST_CASE_ST(ut_setup, ut_teardown,
12958 				test_device_configure_invalid_dev_id),
12959 		TEST_CASE_ST(ut_setup, ut_teardown,
12960 				test_queue_pair_descriptor_setup),
12961 		TEST_CASE_ST(ut_setup, ut_teardown,
12962 				test_device_configure_invalid_queue_pair_ids),
12963 
12964 		TEST_CASE_ST(ut_setup, ut_teardown,
12965 				test_multi_session),
12966 		TEST_CASE_ST(ut_setup, ut_teardown,
12967 				test_multi_session_random_usage),
12968 
12969 		TEST_CASE_ST(ut_setup, ut_teardown,
12970 			test_null_invalid_operation),
12971 		TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
12972 
12973 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
12974 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
12975 		TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
12976 		TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
12977 		TEST_CASE_ST(ut_setup, ut_teardown, test_DES_cipheronly_all),
12978 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_all),
12979 		TEST_CASE_ST(ut_setup, ut_teardown, test_DES_docsis_all),
12980 		TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
12981 		TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
12982 
12983 		/** AES CCM Authenticated Encryption 128 bits key */
12984 		TEST_CASE_ST(ut_setup, ut_teardown,
12985 			test_AES_CCM_authenticated_encryption_test_case_128_1),
12986 		TEST_CASE_ST(ut_setup, ut_teardown,
12987 			test_AES_CCM_authenticated_encryption_test_case_128_2),
12988 		TEST_CASE_ST(ut_setup, ut_teardown,
12989 			test_AES_CCM_authenticated_encryption_test_case_128_3),
12990 
12991 		/** AES CCM Authenticated Decryption 128 bits key*/
12992 		TEST_CASE_ST(ut_setup, ut_teardown,
12993 			test_AES_CCM_authenticated_decryption_test_case_128_1),
12994 		TEST_CASE_ST(ut_setup, ut_teardown,
12995 			test_AES_CCM_authenticated_decryption_test_case_128_2),
12996 		TEST_CASE_ST(ut_setup, ut_teardown,
12997 			test_AES_CCM_authenticated_decryption_test_case_128_3),
12998 
12999 		/** AES CCM Authenticated Encryption 192 bits key */
13000 		TEST_CASE_ST(ut_setup, ut_teardown,
13001 			test_AES_CCM_authenticated_encryption_test_case_192_1),
13002 		TEST_CASE_ST(ut_setup, ut_teardown,
13003 			test_AES_CCM_authenticated_encryption_test_case_192_2),
13004 		TEST_CASE_ST(ut_setup, ut_teardown,
13005 			test_AES_CCM_authenticated_encryption_test_case_192_3),
13006 
13007 		/** AES CCM Authenticated Decryption 192 bits key*/
13008 		TEST_CASE_ST(ut_setup, ut_teardown,
13009 			test_AES_CCM_authenticated_decryption_test_case_192_1),
13010 		TEST_CASE_ST(ut_setup, ut_teardown,
13011 			test_AES_CCM_authenticated_decryption_test_case_192_2),
13012 		TEST_CASE_ST(ut_setup, ut_teardown,
13013 			test_AES_CCM_authenticated_decryption_test_case_192_3),
13014 
13015 		/** AES CCM Authenticated Encryption 256 bits key */
13016 		TEST_CASE_ST(ut_setup, ut_teardown,
13017 			test_AES_CCM_authenticated_encryption_test_case_256_1),
13018 		TEST_CASE_ST(ut_setup, ut_teardown,
13019 			test_AES_CCM_authenticated_encryption_test_case_256_2),
13020 		TEST_CASE_ST(ut_setup, ut_teardown,
13021 			test_AES_CCM_authenticated_encryption_test_case_256_3),
13022 
13023 		/** AES CCM Authenticated Decryption 256 bits key*/
13024 		TEST_CASE_ST(ut_setup, ut_teardown,
13025 			test_AES_CCM_authenticated_decryption_test_case_256_1),
13026 		TEST_CASE_ST(ut_setup, ut_teardown,
13027 			test_AES_CCM_authenticated_decryption_test_case_256_2),
13028 		TEST_CASE_ST(ut_setup, ut_teardown,
13029 			test_AES_CCM_authenticated_decryption_test_case_256_3),
13030 
13031 		/** AES GCM Authenticated Encryption */
13032 		TEST_CASE_ST(ut_setup, ut_teardown,
13033 			test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
13034 		TEST_CASE_ST(ut_setup, ut_teardown,
13035 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
13036 		TEST_CASE_ST(ut_setup, ut_teardown,
13037 			test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
13038 		TEST_CASE_ST(ut_setup, ut_teardown,
13039 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
13040 		TEST_CASE_ST(ut_setup, ut_teardown,
13041 			test_AES_GCM_authenticated_encryption_test_case_1),
13042 		TEST_CASE_ST(ut_setup, ut_teardown,
13043 			test_AES_GCM_authenticated_encryption_test_case_2),
13044 		TEST_CASE_ST(ut_setup, ut_teardown,
13045 			test_AES_GCM_authenticated_encryption_test_case_3),
13046 		TEST_CASE_ST(ut_setup, ut_teardown,
13047 			test_AES_GCM_authenticated_encryption_test_case_4),
13048 		TEST_CASE_ST(ut_setup, ut_teardown,
13049 			test_AES_GCM_authenticated_encryption_test_case_5),
13050 		TEST_CASE_ST(ut_setup, ut_teardown,
13051 			test_AES_GCM_authenticated_encryption_test_case_6),
13052 		TEST_CASE_ST(ut_setup, ut_teardown,
13053 			test_AES_GCM_authenticated_encryption_test_case_7),
13054 		TEST_CASE_ST(ut_setup, ut_teardown,
13055 			test_AES_GCM_authenticated_encryption_test_case_8),
13056 		TEST_CASE_ST(ut_setup, ut_teardown,
13057 			test_AES_GCM_J0_authenticated_encryption_test_case_1),
13058 
13059 		/** AES GCM Authenticated Decryption */
13060 		TEST_CASE_ST(ut_setup, ut_teardown,
13061 			test_AES_GCM_authenticated_decryption_test_case_1),
13062 		TEST_CASE_ST(ut_setup, ut_teardown,
13063 			test_AES_GCM_authenticated_decryption_test_case_2),
13064 		TEST_CASE_ST(ut_setup, ut_teardown,
13065 			test_AES_GCM_authenticated_decryption_test_case_3),
13066 		TEST_CASE_ST(ut_setup, ut_teardown,
13067 			test_AES_GCM_authenticated_decryption_test_case_4),
13068 		TEST_CASE_ST(ut_setup, ut_teardown,
13069 			test_AES_GCM_authenticated_decryption_test_case_5),
13070 		TEST_CASE_ST(ut_setup, ut_teardown,
13071 			test_AES_GCM_authenticated_decryption_test_case_6),
13072 		TEST_CASE_ST(ut_setup, ut_teardown,
13073 			test_AES_GCM_authenticated_decryption_test_case_7),
13074 		TEST_CASE_ST(ut_setup, ut_teardown,
13075 			test_AES_GCM_authenticated_decryption_test_case_8),
13076 		TEST_CASE_ST(ut_setup, ut_teardown,
13077 			test_AES_GCM_J0_authenticated_decryption_test_case_1),
13078 
13079 		/** AES GCM Authenticated Encryption 192 bits key */
13080 		TEST_CASE_ST(ut_setup, ut_teardown,
13081 			test_AES_GCM_auth_encryption_test_case_192_1),
13082 		TEST_CASE_ST(ut_setup, ut_teardown,
13083 			test_AES_GCM_auth_encryption_test_case_192_2),
13084 		TEST_CASE_ST(ut_setup, ut_teardown,
13085 			test_AES_GCM_auth_encryption_test_case_192_3),
13086 		TEST_CASE_ST(ut_setup, ut_teardown,
13087 			test_AES_GCM_auth_encryption_test_case_192_4),
13088 		TEST_CASE_ST(ut_setup, ut_teardown,
13089 			test_AES_GCM_auth_encryption_test_case_192_5),
13090 		TEST_CASE_ST(ut_setup, ut_teardown,
13091 			test_AES_GCM_auth_encryption_test_case_192_6),
13092 		TEST_CASE_ST(ut_setup, ut_teardown,
13093 			test_AES_GCM_auth_encryption_test_case_192_7),
13094 
13095 		/** AES GCM Authenticated Decryption 192 bits key */
13096 		TEST_CASE_ST(ut_setup, ut_teardown,
13097 			test_AES_GCM_auth_decryption_test_case_192_1),
13098 		TEST_CASE_ST(ut_setup, ut_teardown,
13099 			test_AES_GCM_auth_decryption_test_case_192_2),
13100 		TEST_CASE_ST(ut_setup, ut_teardown,
13101 			test_AES_GCM_auth_decryption_test_case_192_3),
13102 		TEST_CASE_ST(ut_setup, ut_teardown,
13103 			test_AES_GCM_auth_decryption_test_case_192_4),
13104 		TEST_CASE_ST(ut_setup, ut_teardown,
13105 			test_AES_GCM_auth_decryption_test_case_192_5),
13106 		TEST_CASE_ST(ut_setup, ut_teardown,
13107 			test_AES_GCM_auth_decryption_test_case_192_6),
13108 		TEST_CASE_ST(ut_setup, ut_teardown,
13109 			test_AES_GCM_auth_decryption_test_case_192_7),
13110 
13111 		/** AES GCM Authenticated Encryption 256 bits key */
13112 		TEST_CASE_ST(ut_setup, ut_teardown,
13113 			test_AES_GCM_auth_encryption_test_case_256_1),
13114 		TEST_CASE_ST(ut_setup, ut_teardown,
13115 			test_AES_GCM_auth_encryption_test_case_256_2),
13116 		TEST_CASE_ST(ut_setup, ut_teardown,
13117 			test_AES_GCM_auth_encryption_test_case_256_3),
13118 		TEST_CASE_ST(ut_setup, ut_teardown,
13119 			test_AES_GCM_auth_encryption_test_case_256_4),
13120 		TEST_CASE_ST(ut_setup, ut_teardown,
13121 			test_AES_GCM_auth_encryption_test_case_256_5),
13122 		TEST_CASE_ST(ut_setup, ut_teardown,
13123 			test_AES_GCM_auth_encryption_test_case_256_6),
13124 		TEST_CASE_ST(ut_setup, ut_teardown,
13125 			test_AES_GCM_auth_encryption_test_case_256_7),
13126 
13127 		/** AES GCM Authenticated Decryption 256 bits key */
13128 		TEST_CASE_ST(ut_setup, ut_teardown,
13129 			test_AES_GCM_auth_decryption_test_case_256_1),
13130 		TEST_CASE_ST(ut_setup, ut_teardown,
13131 			test_AES_GCM_auth_decryption_test_case_256_2),
13132 		TEST_CASE_ST(ut_setup, ut_teardown,
13133 			test_AES_GCM_auth_decryption_test_case_256_3),
13134 		TEST_CASE_ST(ut_setup, ut_teardown,
13135 			test_AES_GCM_auth_decryption_test_case_256_4),
13136 		TEST_CASE_ST(ut_setup, ut_teardown,
13137 			test_AES_GCM_auth_decryption_test_case_256_5),
13138 		TEST_CASE_ST(ut_setup, ut_teardown,
13139 			test_AES_GCM_auth_decryption_test_case_256_6),
13140 		TEST_CASE_ST(ut_setup, ut_teardown,
13141 			test_AES_GCM_auth_decryption_test_case_256_7),
13142 
13143 		/** AES GCM Authenticated Encryption big aad size */
13144 		TEST_CASE_ST(ut_setup, ut_teardown,
13145 			test_AES_GCM_auth_encryption_test_case_aad_1),
13146 		TEST_CASE_ST(ut_setup, ut_teardown,
13147 			test_AES_GCM_auth_encryption_test_case_aad_2),
13148 
13149 		/** AES GCM Authenticated Decryption big aad size */
13150 		TEST_CASE_ST(ut_setup, ut_teardown,
13151 			test_AES_GCM_auth_decryption_test_case_aad_1),
13152 		TEST_CASE_ST(ut_setup, ut_teardown,
13153 			test_AES_GCM_auth_decryption_test_case_aad_2),
13154 
13155 		/** Out of place tests */
13156 		TEST_CASE_ST(ut_setup, ut_teardown,
13157 			test_AES_GCM_authenticated_encryption_oop_test_case_1),
13158 		TEST_CASE_ST(ut_setup, ut_teardown,
13159 			test_AES_GCM_authenticated_decryption_oop_test_case_1),
13160 
13161 		/** Session-less tests */
13162 		TEST_CASE_ST(ut_setup, ut_teardown,
13163 			test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
13164 		TEST_CASE_ST(ut_setup, ut_teardown,
13165 			test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
13166 
13167 		/** AES GMAC Authentication */
13168 		TEST_CASE_ST(ut_setup, ut_teardown,
13169 			test_AES_GMAC_authentication_test_case_1),
13170 		TEST_CASE_ST(ut_setup, ut_teardown,
13171 			test_AES_GMAC_authentication_verify_test_case_1),
13172 		TEST_CASE_ST(ut_setup, ut_teardown,
13173 			test_AES_GMAC_authentication_test_case_2),
13174 		TEST_CASE_ST(ut_setup, ut_teardown,
13175 			test_AES_GMAC_authentication_verify_test_case_2),
13176 		TEST_CASE_ST(ut_setup, ut_teardown,
13177 			test_AES_GMAC_authentication_test_case_3),
13178 		TEST_CASE_ST(ut_setup, ut_teardown,
13179 			test_AES_GMAC_authentication_verify_test_case_3),
13180 		TEST_CASE_ST(ut_setup, ut_teardown,
13181 			test_AES_GMAC_authentication_test_case_4),
13182 		TEST_CASE_ST(ut_setup, ut_teardown,
13183 			test_AES_GMAC_authentication_verify_test_case_4),
13184 		TEST_CASE_ST(ut_setup, ut_teardown,
13185 			test_AES_GMAC_authentication_SGL_40B),
13186 		TEST_CASE_ST(ut_setup, ut_teardown,
13187 			test_AES_GMAC_authentication_SGL_80B),
13188 		TEST_CASE_ST(ut_setup, ut_teardown,
13189 			test_AES_GMAC_authentication_SGL_2048B),
13190 		TEST_CASE_ST(ut_setup, ut_teardown,
13191 			test_AES_GMAC_authentication_SGL_2047B),
13192 
13193 		/** Chacha20-Poly1305 */
13194 		TEST_CASE_ST(ut_setup, ut_teardown,
13195 			test_chacha20_poly1305_encrypt_test_case_rfc8439),
13196 		TEST_CASE_ST(ut_setup, ut_teardown,
13197 			test_chacha20_poly1305_decrypt_test_case_rfc8439),
13198 		/** SNOW 3G encrypt only (UEA2) */
13199 		TEST_CASE_ST(ut_setup, ut_teardown,
13200 			test_snow3g_encryption_test_case_1),
13201 		TEST_CASE_ST(ut_setup, ut_teardown,
13202 			test_snow3g_encryption_test_case_2),
13203 		TEST_CASE_ST(ut_setup, ut_teardown,
13204 			test_snow3g_encryption_test_case_3),
13205 		TEST_CASE_ST(ut_setup, ut_teardown,
13206 			test_snow3g_encryption_test_case_4),
13207 		TEST_CASE_ST(ut_setup, ut_teardown,
13208 			test_snow3g_encryption_test_case_5),
13209 
13210 		TEST_CASE_ST(ut_setup, ut_teardown,
13211 			test_snow3g_encryption_test_case_1_oop),
13212 		TEST_CASE_ST(ut_setup, ut_teardown,
13213 			test_snow3g_encryption_test_case_1_oop_sgl),
13214 		TEST_CASE_ST(ut_setup, ut_teardown,
13215 			test_snow3g_encryption_test_case_1_offset_oop),
13216 		TEST_CASE_ST(ut_setup, ut_teardown,
13217 			test_snow3g_decryption_test_case_1_oop),
13218 
13219 		/** SNOW 3G generate auth, then encrypt (UEA2) */
13220 		TEST_CASE_ST(ut_setup, ut_teardown,
13221 			test_snow3g_auth_cipher_test_case_1),
13222 		TEST_CASE_ST(ut_setup, ut_teardown,
13223 			test_snow3g_auth_cipher_test_case_2),
13224 		TEST_CASE_ST(ut_setup, ut_teardown,
13225 			test_snow3g_auth_cipher_test_case_2_oop),
13226 		TEST_CASE_ST(ut_setup, ut_teardown,
13227 			test_snow3g_auth_cipher_part_digest_enc),
13228 		TEST_CASE_ST(ut_setup, ut_teardown,
13229 			test_snow3g_auth_cipher_part_digest_enc_oop),
13230 		TEST_CASE_ST(ut_setup, ut_teardown,
13231 			test_snow3g_auth_cipher_test_case_3_sgl),
13232 		TEST_CASE_ST(ut_setup, ut_teardown,
13233 			test_snow3g_auth_cipher_test_case_3_oop_sgl),
13234 		TEST_CASE_ST(ut_setup, ut_teardown,
13235 			test_snow3g_auth_cipher_part_digest_enc_sgl),
13236 		TEST_CASE_ST(ut_setup, ut_teardown,
13237 			test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
13238 
13239 		/** SNOW 3G decrypt (UEA2), then verify auth */
13240 		TEST_CASE_ST(ut_setup, ut_teardown,
13241 			test_snow3g_auth_cipher_verify_test_case_1),
13242 		TEST_CASE_ST(ut_setup, ut_teardown,
13243 			test_snow3g_auth_cipher_verify_test_case_2),
13244 		TEST_CASE_ST(ut_setup, ut_teardown,
13245 			test_snow3g_auth_cipher_verify_test_case_2_oop),
13246 		TEST_CASE_ST(ut_setup, ut_teardown,
13247 			test_snow3g_auth_cipher_verify_part_digest_enc),
13248 		TEST_CASE_ST(ut_setup, ut_teardown,
13249 			test_snow3g_auth_cipher_verify_part_digest_enc_oop),
13250 		TEST_CASE_ST(ut_setup, ut_teardown,
13251 			test_snow3g_auth_cipher_verify_test_case_3_sgl),
13252 		TEST_CASE_ST(ut_setup, ut_teardown,
13253 			test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
13254 		TEST_CASE_ST(ut_setup, ut_teardown,
13255 			test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
13256 		TEST_CASE_ST(ut_setup, ut_teardown,
13257 			test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
13258 
13259 		/** SNOW 3G decrypt only (UEA2) */
13260 		TEST_CASE_ST(ut_setup, ut_teardown,
13261 			test_snow3g_decryption_test_case_1),
13262 		TEST_CASE_ST(ut_setup, ut_teardown,
13263 			test_snow3g_decryption_test_case_2),
13264 		TEST_CASE_ST(ut_setup, ut_teardown,
13265 			test_snow3g_decryption_test_case_3),
13266 		TEST_CASE_ST(ut_setup, ut_teardown,
13267 			test_snow3g_decryption_test_case_4),
13268 		TEST_CASE_ST(ut_setup, ut_teardown,
13269 			test_snow3g_decryption_test_case_5),
13270 		TEST_CASE_ST(ut_setup, ut_teardown,
13271 			test_snow3g_decryption_with_digest_test_case_1),
13272 		TEST_CASE_ST(ut_setup, ut_teardown,
13273 			test_snow3g_hash_generate_test_case_1),
13274 		TEST_CASE_ST(ut_setup, ut_teardown,
13275 			test_snow3g_hash_generate_test_case_2),
13276 		TEST_CASE_ST(ut_setup, ut_teardown,
13277 			test_snow3g_hash_generate_test_case_3),
13278 		/* Tests with buffers which length is not byte-aligned */
13279 		TEST_CASE_ST(ut_setup, ut_teardown,
13280 			test_snow3g_hash_generate_test_case_4),
13281 		TEST_CASE_ST(ut_setup, ut_teardown,
13282 			test_snow3g_hash_generate_test_case_5),
13283 		TEST_CASE_ST(ut_setup, ut_teardown,
13284 			test_snow3g_hash_generate_test_case_6),
13285 		TEST_CASE_ST(ut_setup, ut_teardown,
13286 			test_snow3g_hash_verify_test_case_1),
13287 		TEST_CASE_ST(ut_setup, ut_teardown,
13288 			test_snow3g_hash_verify_test_case_2),
13289 		TEST_CASE_ST(ut_setup, ut_teardown,
13290 			test_snow3g_hash_verify_test_case_3),
13291 		/* Tests with buffers which length is not byte-aligned */
13292 		TEST_CASE_ST(ut_setup, ut_teardown,
13293 			test_snow3g_hash_verify_test_case_4),
13294 		TEST_CASE_ST(ut_setup, ut_teardown,
13295 			test_snow3g_hash_verify_test_case_5),
13296 		TEST_CASE_ST(ut_setup, ut_teardown,
13297 			test_snow3g_hash_verify_test_case_6),
13298 		TEST_CASE_ST(ut_setup, ut_teardown,
13299 			test_snow3g_cipher_auth_test_case_1),
13300 		TEST_CASE_ST(ut_setup, ut_teardown,
13301 			test_snow3g_auth_cipher_with_digest_test_case_1),
13302 
13303 		/** ZUC encrypt only (EEA3) */
13304 		TEST_CASE_ST(ut_setup, ut_teardown,
13305 			test_zuc_encryption_test_case_1),
13306 		TEST_CASE_ST(ut_setup, ut_teardown,
13307 			test_zuc_encryption_test_case_2),
13308 		TEST_CASE_ST(ut_setup, ut_teardown,
13309 			test_zuc_encryption_test_case_3),
13310 		TEST_CASE_ST(ut_setup, ut_teardown,
13311 			test_zuc_encryption_test_case_4),
13312 		TEST_CASE_ST(ut_setup, ut_teardown,
13313 			test_zuc_encryption_test_case_5),
13314 		TEST_CASE_ST(ut_setup, ut_teardown,
13315 			test_zuc_encryption_test_case_6_sgl),
13316 
13317 		/** ZUC authenticate (EIA3) */
13318 		TEST_CASE_ST(ut_setup, ut_teardown,
13319 			test_zuc_hash_generate_test_case_1),
13320 		TEST_CASE_ST(ut_setup, ut_teardown,
13321 			test_zuc_hash_generate_test_case_2),
13322 		TEST_CASE_ST(ut_setup, ut_teardown,
13323 			test_zuc_hash_generate_test_case_3),
13324 		TEST_CASE_ST(ut_setup, ut_teardown,
13325 			test_zuc_hash_generate_test_case_4),
13326 		TEST_CASE_ST(ut_setup, ut_teardown,
13327 			test_zuc_hash_generate_test_case_5),
13328 		TEST_CASE_ST(ut_setup, ut_teardown,
13329 			test_zuc_hash_generate_test_case_6),
13330 		TEST_CASE_ST(ut_setup, ut_teardown,
13331 			test_zuc_hash_generate_test_case_7),
13332 		TEST_CASE_ST(ut_setup, ut_teardown,
13333 			test_zuc_hash_generate_test_case_8),
13334 
13335 		/** ZUC alg-chain (EEA3/EIA3) */
13336 		TEST_CASE_ST(ut_setup, ut_teardown,
13337 			test_zuc_cipher_auth_test_case_1),
13338 		TEST_CASE_ST(ut_setup, ut_teardown,
13339 			test_zuc_cipher_auth_test_case_2),
13340 
13341 		/** ZUC generate auth, then encrypt (EEA3) */
13342 		TEST_CASE_ST(ut_setup, ut_teardown,
13343 			test_zuc_auth_cipher_test_case_1),
13344 		TEST_CASE_ST(ut_setup, ut_teardown,
13345 			test_zuc_auth_cipher_test_case_1_oop),
13346 		TEST_CASE_ST(ut_setup, ut_teardown,
13347 			test_zuc_auth_cipher_test_case_1_sgl),
13348 		TEST_CASE_ST(ut_setup, ut_teardown,
13349 			test_zuc_auth_cipher_test_case_1_oop_sgl),
13350 
13351 		/** ZUC decrypt (EEA3), then verify auth */
13352 		TEST_CASE_ST(ut_setup, ut_teardown,
13353 			test_zuc_auth_cipher_verify_test_case_1),
13354 		TEST_CASE_ST(ut_setup, ut_teardown,
13355 			test_zuc_auth_cipher_verify_test_case_1_oop),
13356 		TEST_CASE_ST(ut_setup, ut_teardown,
13357 			test_zuc_auth_cipher_verify_test_case_1_sgl),
13358 		TEST_CASE_ST(ut_setup, ut_teardown,
13359 			test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
13360 
13361 		/** HMAC_MD5 Authentication */
13362 		TEST_CASE_ST(ut_setup, ut_teardown,
13363 			test_MD5_HMAC_generate_case_1),
13364 		TEST_CASE_ST(ut_setup, ut_teardown,
13365 			test_MD5_HMAC_verify_case_1),
13366 		TEST_CASE_ST(ut_setup, ut_teardown,
13367 			test_MD5_HMAC_generate_case_2),
13368 		TEST_CASE_ST(ut_setup, ut_teardown,
13369 			test_MD5_HMAC_verify_case_2),
13370 
13371 		/** KASUMI hash only (UIA1) */
13372 		TEST_CASE_ST(ut_setup, ut_teardown,
13373 			test_kasumi_hash_generate_test_case_1),
13374 		TEST_CASE_ST(ut_setup, ut_teardown,
13375 			test_kasumi_hash_generate_test_case_2),
13376 		TEST_CASE_ST(ut_setup, ut_teardown,
13377 			test_kasumi_hash_generate_test_case_3),
13378 		TEST_CASE_ST(ut_setup, ut_teardown,
13379 			test_kasumi_hash_generate_test_case_4),
13380 		TEST_CASE_ST(ut_setup, ut_teardown,
13381 			test_kasumi_hash_generate_test_case_5),
13382 		TEST_CASE_ST(ut_setup, ut_teardown,
13383 			test_kasumi_hash_generate_test_case_6),
13384 
13385 		TEST_CASE_ST(ut_setup, ut_teardown,
13386 			test_kasumi_hash_verify_test_case_1),
13387 		TEST_CASE_ST(ut_setup, ut_teardown,
13388 			test_kasumi_hash_verify_test_case_2),
13389 		TEST_CASE_ST(ut_setup, ut_teardown,
13390 			test_kasumi_hash_verify_test_case_3),
13391 		TEST_CASE_ST(ut_setup, ut_teardown,
13392 			test_kasumi_hash_verify_test_case_4),
13393 		TEST_CASE_ST(ut_setup, ut_teardown,
13394 			test_kasumi_hash_verify_test_case_5),
13395 
13396 		/** KASUMI encrypt only (UEA1) */
13397 		TEST_CASE_ST(ut_setup, ut_teardown,
13398 			test_kasumi_encryption_test_case_1),
13399 		TEST_CASE_ST(ut_setup, ut_teardown,
13400 			test_kasumi_encryption_test_case_1_sgl),
13401 		TEST_CASE_ST(ut_setup, ut_teardown,
13402 			test_kasumi_encryption_test_case_1_oop),
13403 		TEST_CASE_ST(ut_setup, ut_teardown,
13404 			test_kasumi_encryption_test_case_1_oop_sgl),
13405 		TEST_CASE_ST(ut_setup, ut_teardown,
13406 			test_kasumi_encryption_test_case_2),
13407 		TEST_CASE_ST(ut_setup, ut_teardown,
13408 			test_kasumi_encryption_test_case_3),
13409 		TEST_CASE_ST(ut_setup, ut_teardown,
13410 			test_kasumi_encryption_test_case_4),
13411 		TEST_CASE_ST(ut_setup, ut_teardown,
13412 			test_kasumi_encryption_test_case_5),
13413 
13414 		/** KASUMI decrypt only (UEA1) */
13415 		TEST_CASE_ST(ut_setup, ut_teardown,
13416 			test_kasumi_decryption_test_case_1),
13417 		TEST_CASE_ST(ut_setup, ut_teardown,
13418 			test_kasumi_decryption_test_case_2),
13419 		TEST_CASE_ST(ut_setup, ut_teardown,
13420 			test_kasumi_decryption_test_case_3),
13421 		TEST_CASE_ST(ut_setup, ut_teardown,
13422 			test_kasumi_decryption_test_case_4),
13423 		TEST_CASE_ST(ut_setup, ut_teardown,
13424 			test_kasumi_decryption_test_case_5),
13425 		TEST_CASE_ST(ut_setup, ut_teardown,
13426 			test_kasumi_decryption_test_case_1_oop),
13427 
13428 		TEST_CASE_ST(ut_setup, ut_teardown,
13429 			test_kasumi_cipher_auth_test_case_1),
13430 
13431 		/** KASUMI generate auth, then encrypt (F8) */
13432 		TEST_CASE_ST(ut_setup, ut_teardown,
13433 			test_kasumi_auth_cipher_test_case_1),
13434 		TEST_CASE_ST(ut_setup, ut_teardown,
13435 			test_kasumi_auth_cipher_test_case_2),
13436 		TEST_CASE_ST(ut_setup, ut_teardown,
13437 			test_kasumi_auth_cipher_test_case_2_oop),
13438 		TEST_CASE_ST(ut_setup, ut_teardown,
13439 			test_kasumi_auth_cipher_test_case_2_sgl),
13440 		TEST_CASE_ST(ut_setup, ut_teardown,
13441 			test_kasumi_auth_cipher_test_case_2_oop_sgl),
13442 
13443 		/** KASUMI decrypt (F8), then verify auth */
13444 		TEST_CASE_ST(ut_setup, ut_teardown,
13445 			test_kasumi_auth_cipher_verify_test_case_1),
13446 		TEST_CASE_ST(ut_setup, ut_teardown,
13447 			test_kasumi_auth_cipher_verify_test_case_2),
13448 		TEST_CASE_ST(ut_setup, ut_teardown,
13449 			test_kasumi_auth_cipher_verify_test_case_2_oop),
13450 		TEST_CASE_ST(ut_setup, ut_teardown,
13451 			test_kasumi_auth_cipher_verify_test_case_2_sgl),
13452 		TEST_CASE_ST(ut_setup, ut_teardown,
13453 			test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
13454 
13455 		/** ESN Testcase */
13456 		TEST_CASE_ST(ut_setup, ut_teardown,
13457 			auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
13458 		TEST_CASE_ST(ut_setup, ut_teardown,
13459 			auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
13460 
13461 		/** Negative tests */
13462 		TEST_CASE_ST(ut_setup, ut_teardown,
13463 			authentication_verify_HMAC_SHA1_fail_data_corrupt),
13464 		TEST_CASE_ST(ut_setup, ut_teardown,
13465 			authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13466 		TEST_CASE_ST(ut_setup, ut_teardown,
13467 			test_AES_GCM_auth_encryption_fail_iv_corrupt),
13468 		TEST_CASE_ST(ut_setup, ut_teardown,
13469 			test_AES_GCM_auth_encryption_fail_in_data_corrupt),
13470 		TEST_CASE_ST(ut_setup, ut_teardown,
13471 			test_AES_GCM_auth_encryption_fail_out_data_corrupt),
13472 		TEST_CASE_ST(ut_setup, ut_teardown,
13473 			test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
13474 		TEST_CASE_ST(ut_setup, ut_teardown,
13475 			test_AES_GCM_auth_encryption_fail_aad_corrupt),
13476 		TEST_CASE_ST(ut_setup, ut_teardown,
13477 			test_AES_GCM_auth_encryption_fail_tag_corrupt),
13478 		TEST_CASE_ST(ut_setup, ut_teardown,
13479 			test_AES_GCM_auth_decryption_fail_iv_corrupt),
13480 		TEST_CASE_ST(ut_setup, ut_teardown,
13481 			test_AES_GCM_auth_decryption_fail_in_data_corrupt),
13482 		TEST_CASE_ST(ut_setup, ut_teardown,
13483 			test_AES_GCM_auth_decryption_fail_out_data_corrupt),
13484 		TEST_CASE_ST(ut_setup, ut_teardown,
13485 			test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
13486 		TEST_CASE_ST(ut_setup, ut_teardown,
13487 			test_AES_GCM_auth_decryption_fail_aad_corrupt),
13488 		TEST_CASE_ST(ut_setup, ut_teardown,
13489 			test_AES_GCM_auth_decryption_fail_tag_corrupt),
13490 		TEST_CASE_ST(ut_setup, ut_teardown,
13491 			authentication_verify_AES128_GMAC_fail_data_corrupt),
13492 		TEST_CASE_ST(ut_setup, ut_teardown,
13493 			authentication_verify_AES128_GMAC_fail_tag_corrupt),
13494 		TEST_CASE_ST(ut_setup, ut_teardown,
13495 			auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13496 		TEST_CASE_ST(ut_setup, ut_teardown,
13497 			auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13498 
13499 		/** Mixed CIPHER + HASH algorithms */
13500 		/** AUTH AES CMAC + CIPHER AES CTR */
13501 		TEST_CASE_ST(ut_setup, ut_teardown,
13502 			test_aes_cmac_aes_ctr_digest_enc_test_case_1),
13503 		TEST_CASE_ST(ut_setup, ut_teardown,
13504 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
13505 		TEST_CASE_ST(ut_setup, ut_teardown,
13506 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
13507 		TEST_CASE_ST(ut_setup, ut_teardown,
13508 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
13509 		TEST_CASE_ST(ut_setup, ut_teardown,
13510 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
13511 		TEST_CASE_ST(ut_setup, ut_teardown,
13512 		       test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
13513 		TEST_CASE_ST(ut_setup, ut_teardown,
13514 		       test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
13515 		TEST_CASE_ST(ut_setup, ut_teardown,
13516 		   test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
13517 
13518 		/** AUTH ZUC + CIPHER SNOW3G */
13519 		TEST_CASE_ST(ut_setup, ut_teardown,
13520 			test_auth_zuc_cipher_snow_test_case_1),
13521 		TEST_CASE_ST(ut_setup, ut_teardown,
13522 			test_verify_auth_zuc_cipher_snow_test_case_1),
13523 		/** AUTH AES CMAC + CIPHER SNOW3G */
13524 		TEST_CASE_ST(ut_setup, ut_teardown,
13525 			test_auth_aes_cmac_cipher_snow_test_case_1),
13526 		TEST_CASE_ST(ut_setup, ut_teardown,
13527 			test_verify_auth_aes_cmac_cipher_snow_test_case_1),
13528 		/** AUTH ZUC + CIPHER AES CTR */
13529 		TEST_CASE_ST(ut_setup, ut_teardown,
13530 			test_auth_zuc_cipher_aes_ctr_test_case_1),
13531 		TEST_CASE_ST(ut_setup, ut_teardown,
13532 			test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
13533 		/** AUTH SNOW3G + CIPHER AES CTR */
13534 		TEST_CASE_ST(ut_setup, ut_teardown,
13535 			test_auth_snow_cipher_aes_ctr_test_case_1),
13536 		TEST_CASE_ST(ut_setup, ut_teardown,
13537 			test_verify_auth_snow_cipher_aes_ctr_test_case_1),
13538 		/** AUTH SNOW3G + CIPHER ZUC */
13539 		TEST_CASE_ST(ut_setup, ut_teardown,
13540 			test_auth_snow_cipher_zuc_test_case_1),
13541 		TEST_CASE_ST(ut_setup, ut_teardown,
13542 			test_verify_auth_snow_cipher_zuc_test_case_1),
13543 		/** AUTH AES CMAC + CIPHER ZUC */
13544 		TEST_CASE_ST(ut_setup, ut_teardown,
13545 			test_auth_aes_cmac_cipher_zuc_test_case_1),
13546 		TEST_CASE_ST(ut_setup, ut_teardown,
13547 			test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
13548 
13549 		/** AUTH NULL + CIPHER SNOW3G */
13550 		TEST_CASE_ST(ut_setup, ut_teardown,
13551 			test_auth_null_cipher_snow_test_case_1),
13552 		TEST_CASE_ST(ut_setup, ut_teardown,
13553 			test_verify_auth_null_cipher_snow_test_case_1),
13554 		/** AUTH NULL + CIPHER ZUC */
13555 		TEST_CASE_ST(ut_setup, ut_teardown,
13556 			test_auth_null_cipher_zuc_test_case_1),
13557 		TEST_CASE_ST(ut_setup, ut_teardown,
13558 			test_verify_auth_null_cipher_zuc_test_case_1),
13559 		/** AUTH SNOW3G + CIPHER NULL */
13560 		TEST_CASE_ST(ut_setup, ut_teardown,
13561 			test_auth_snow_cipher_null_test_case_1),
13562 		TEST_CASE_ST(ut_setup, ut_teardown,
13563 			test_verify_auth_snow_cipher_null_test_case_1),
13564 		/** AUTH ZUC + CIPHER NULL */
13565 		TEST_CASE_ST(ut_setup, ut_teardown,
13566 			test_auth_zuc_cipher_null_test_case_1),
13567 		TEST_CASE_ST(ut_setup, ut_teardown,
13568 			test_verify_auth_zuc_cipher_null_test_case_1),
13569 		/** AUTH NULL + CIPHER AES CTR */
13570 		TEST_CASE_ST(ut_setup, ut_teardown,
13571 			test_auth_null_cipher_aes_ctr_test_case_1),
13572 		TEST_CASE_ST(ut_setup, ut_teardown,
13573 			test_verify_auth_null_cipher_aes_ctr_test_case_1),
13574 		/** AUTH AES CMAC + CIPHER NULL */
13575 		TEST_CASE_ST(ut_setup, ut_teardown,
13576 			test_auth_aes_cmac_cipher_null_test_case_1),
13577 		TEST_CASE_ST(ut_setup, ut_teardown,
13578 			test_verify_auth_aes_cmac_cipher_null_test_case_1),
13579 
13580 #ifdef RTE_LIBRTE_SECURITY
13581 		TEST_CASE_ST(ut_setup_security, ut_teardown,
13582 			test_PDCP_PROTO_all),
13583 		TEST_CASE_ST(ut_setup_security, ut_teardown,
13584 			test_DOCSIS_PROTO_all),
13585 #endif
13586 		TEST_CASES_END() /**< NULL terminate unit test array */
13587 	}
13588 };
13589 
13590 static struct unit_test_suite cryptodev_virtio_testsuite = {
13591 	.suite_name = "Crypto VIRTIO Unit Test Suite",
13592 	.setup = testsuite_setup,
13593 	.teardown = testsuite_teardown,
13594 	.unit_test_cases = {
13595 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13596 
13597 		TEST_CASES_END() /**< NULL terminate unit test array */
13598 	}
13599 };
13600 
13601 static struct unit_test_suite cryptodev_caam_jr_testsuite  = {
13602 	.suite_name = "Crypto CAAM JR Unit Test Suite",
13603 	.setup = testsuite_setup,
13604 	.teardown = testsuite_teardown,
13605 	.unit_test_cases = {
13606 		TEST_CASE_ST(ut_setup, ut_teardown,
13607 			     test_device_configure_invalid_dev_id),
13608 		TEST_CASE_ST(ut_setup, ut_teardown,
13609 			     test_multi_session),
13610 
13611 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13612 		TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13613 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13614 		TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13615 		TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13616 
13617 		TEST_CASES_END() /**< NULL terminate unit test array */
13618 	}
13619 };
13620 
13621 static struct unit_test_suite cryptodev_mrvl_testsuite  = {
13622 	.suite_name = "Crypto Device Marvell Component Test Suite",
13623 	.setup = testsuite_setup,
13624 	.teardown = testsuite_teardown,
13625 	.unit_test_cases = {
13626 		TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
13627 		TEST_CASE_ST(ut_setup, ut_teardown,
13628 				test_multi_session_random_usage),
13629 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13630 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13631 		TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13632 		TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13633 		TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13634 
13635 		/** Negative tests */
13636 		TEST_CASE_ST(ut_setup, ut_teardown,
13637 			authentication_verify_HMAC_SHA1_fail_data_corrupt),
13638 		TEST_CASE_ST(ut_setup, ut_teardown,
13639 			authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13640 		TEST_CASE_ST(ut_setup, ut_teardown,
13641 			auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13642 		TEST_CASE_ST(ut_setup, ut_teardown,
13643 			auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13644 
13645 		TEST_CASES_END() /**< NULL terminate unit test array */
13646 	}
13647 };
13648 
13649 static struct unit_test_suite cryptodev_ccp_testsuite  = {
13650 	.suite_name = "Crypto Device CCP Unit Test Suite",
13651 	.setup = testsuite_setup,
13652 	.teardown = testsuite_teardown,
13653 	.unit_test_cases = {
13654 		TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
13655 		TEST_CASE_ST(ut_setup, ut_teardown,
13656 				test_multi_session_random_usage),
13657 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_all),
13658 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_all),
13659 		TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_all),
13660 		TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_cipheronly_all),
13661 		TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_all),
13662 
13663 		/** Negative tests */
13664 		TEST_CASE_ST(ut_setup, ut_teardown,
13665 			authentication_verify_HMAC_SHA1_fail_data_corrupt),
13666 		TEST_CASE_ST(ut_setup, ut_teardown,
13667 			authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13668 		TEST_CASE_ST(ut_setup, ut_teardown,
13669 			auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13670 		TEST_CASE_ST(ut_setup, ut_teardown,
13671 			auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13672 
13673 		TEST_CASES_END() /**< NULL terminate unit test array */
13674 	}
13675 };
13676 
13677 static int
13678 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
13679 {
13680 	gbl_driver_id =	rte_cryptodev_driver_id_get(
13681 			RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
13682 
13683 	if (gbl_driver_id == -1) {
13684 		RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n");
13685 		return TEST_SKIPPED;
13686 	}
13687 
13688 	return unit_test_suite_runner(&cryptodev_testsuite);
13689 }
13690 
13691 static int
13692 test_cryptodev_virtio(void /*argv __rte_unused, int argc __rte_unused*/)
13693 {
13694 	gbl_driver_id =	rte_cryptodev_driver_id_get(
13695 			RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
13696 
13697 	if (gbl_driver_id == -1) {
13698 		RTE_LOG(ERR, USER1, "VIRTIO PMD must be loaded.\n");
13699 		return TEST_FAILED;
13700 	}
13701 
13702 	return unit_test_suite_runner(&cryptodev_virtio_testsuite);
13703 }
13704 
13705 static int
13706 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
13707 {
13708 	gbl_driver_id =	rte_cryptodev_driver_id_get(
13709 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13710 
13711 	if (gbl_driver_id == -1) {
13712 		RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
13713 		return TEST_SKIPPED;
13714 	}
13715 
13716 	return unit_test_suite_runner(&cryptodev_testsuite);
13717 }
13718 
13719 static int
13720 test_cryptodev_cpu_aesni_mb(void)
13721 {
13722 	int32_t rc;
13723 	enum rte_security_session_action_type at;
13724 
13725 	gbl_driver_id =	rte_cryptodev_driver_id_get(
13726 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13727 
13728 	if (gbl_driver_id == -1) {
13729 		RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
13730 		return TEST_SKIPPED;
13731 	}
13732 
13733 	at = gbl_action_type;
13734 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
13735 	rc = unit_test_suite_runner(&cryptodev_testsuite);
13736 	gbl_action_type = at;
13737 	return rc;
13738 }
13739 
13740 static int
13741 test_cryptodev_openssl(void)
13742 {
13743 	gbl_driver_id = rte_cryptodev_driver_id_get(
13744 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
13745 
13746 	if (gbl_driver_id == -1) {
13747 		RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded.\n");
13748 		return TEST_SKIPPED;
13749 	}
13750 
13751 	return unit_test_suite_runner(&cryptodev_testsuite);
13752 }
13753 
13754 static int
13755 test_cryptodev_aesni_gcm(void)
13756 {
13757 	gbl_driver_id = rte_cryptodev_driver_id_get(
13758 			RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
13759 
13760 	if (gbl_driver_id == -1) {
13761 		RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded.\n");
13762 		return TEST_SKIPPED;
13763 	}
13764 
13765 	return unit_test_suite_runner(&cryptodev_testsuite);
13766 }
13767 
13768 static int
13769 test_cryptodev_cpu_aesni_gcm(void)
13770 {
13771 	int32_t rc;
13772 	enum rte_security_session_action_type at;
13773 
13774 	gbl_driver_id = rte_cryptodev_driver_id_get(
13775 			RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
13776 
13777 	if (gbl_driver_id == -1) {
13778 		RTE_LOG(ERR, USER1, "AESNI GCM PMD must be loaded.\n");
13779 		return TEST_SKIPPED;
13780 	}
13781 
13782 	at = gbl_action_type;
13783 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
13784 	rc = unit_test_suite_runner(&cryptodev_testsuite);
13785 	gbl_action_type = at;
13786 	return rc;
13787 }
13788 
13789 static int
13790 test_cryptodev_null(void)
13791 {
13792 	gbl_driver_id = rte_cryptodev_driver_id_get(
13793 			RTE_STR(CRYPTODEV_NAME_NULL_PMD));
13794 
13795 	if (gbl_driver_id == -1) {
13796 		RTE_LOG(ERR, USER1, "NULL PMD must be loaded.\n");
13797 		return TEST_SKIPPED;
13798 	}
13799 
13800 	return unit_test_suite_runner(&cryptodev_testsuite);
13801 }
13802 
13803 static int
13804 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
13805 {
13806 	gbl_driver_id = rte_cryptodev_driver_id_get(
13807 			RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
13808 
13809 	if (gbl_driver_id == -1) {
13810 		RTE_LOG(ERR, USER1, "SNOW3G PMD must be loaded.\n");
13811 		return TEST_SKIPPED;
13812 	}
13813 
13814 	return unit_test_suite_runner(&cryptodev_testsuite);
13815 }
13816 
13817 static int
13818 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
13819 {
13820 	gbl_driver_id = rte_cryptodev_driver_id_get(
13821 			RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
13822 
13823 	if (gbl_driver_id == -1) {
13824 		RTE_LOG(ERR, USER1, "ZUC PMD must be loaded.\n");
13825 		return TEST_SKIPPED;
13826 	}
13827 
13828 	return unit_test_suite_runner(&cryptodev_testsuite);
13829 }
13830 
13831 static int
13832 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
13833 {
13834 	gbl_driver_id = rte_cryptodev_driver_id_get(
13835 			RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
13836 
13837 	if (gbl_driver_id == -1) {
13838 		RTE_LOG(ERR, USER1, "ZUC PMD must be loaded.\n");
13839 		return TEST_SKIPPED;
13840 	}
13841 
13842 	return unit_test_suite_runner(&cryptodev_testsuite);
13843 }
13844 
13845 static int
13846 test_cryptodev_armv8(void)
13847 {
13848 	gbl_driver_id = rte_cryptodev_driver_id_get(
13849 			RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
13850 
13851 	if (gbl_driver_id == -1) {
13852 		RTE_LOG(ERR, USER1, "ARMV8 PMD must be loaded.\n");
13853 		return TEST_SKIPPED;
13854 	}
13855 
13856 	return unit_test_suite_runner(&cryptodev_testsuite);
13857 }
13858 
13859 static int
13860 test_cryptodev_mrvl(void)
13861 {
13862 	gbl_driver_id = rte_cryptodev_driver_id_get(
13863 			RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
13864 
13865 	if (gbl_driver_id == -1) {
13866 		RTE_LOG(ERR, USER1, "MVSAM PMD must be loaded.\n");
13867 		return TEST_SKIPPED;
13868 	}
13869 
13870 	return unit_test_suite_runner(&cryptodev_mrvl_testsuite);
13871 }
13872 
13873 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
13874 
13875 static int
13876 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/)
13877 {
13878 	gbl_driver_id =	rte_cryptodev_driver_id_get(
13879 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
13880 
13881 	if (gbl_driver_id == -1) {
13882 		RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
13883 		return TEST_SKIPPED;
13884 	}
13885 
13886 	if (rte_cryptodev_driver_id_get(
13887 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
13888 		RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
13889 		return TEST_SKIPPED;
13890 }
13891 	return unit_test_suite_runner(&cryptodev_scheduler_testsuite);
13892 }
13893 
13894 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
13895 
13896 #endif
13897 
13898 static int
13899 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/)
13900 {
13901 	gbl_driver_id =	rte_cryptodev_driver_id_get(
13902 			RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
13903 
13904 	if (gbl_driver_id == -1) {
13905 		RTE_LOG(ERR, USER1, "DPAA2 SEC PMD must be loaded.\n");
13906 		return TEST_SKIPPED;
13907 	}
13908 
13909 	return unit_test_suite_runner(&cryptodev_testsuite);
13910 }
13911 
13912 static int
13913 test_cryptodev_dpaa_sec(void /*argv __rte_unused, int argc __rte_unused*/)
13914 {
13915 	gbl_driver_id =	rte_cryptodev_driver_id_get(
13916 			RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
13917 
13918 	if (gbl_driver_id == -1) {
13919 		RTE_LOG(ERR, USER1, "DPAA SEC PMD must be loaded.\n");
13920 		return TEST_SKIPPED;
13921 	}
13922 
13923 	return unit_test_suite_runner(&cryptodev_testsuite);
13924 }
13925 
13926 static int
13927 test_cryptodev_ccp(void)
13928 {
13929 	gbl_driver_id = rte_cryptodev_driver_id_get(
13930 			RTE_STR(CRYPTODEV_NAME_CCP_PMD));
13931 
13932 	if (gbl_driver_id == -1) {
13933 		RTE_LOG(ERR, USER1, "CCP PMD must be loaded.\n");
13934 		return TEST_FAILED;
13935 	}
13936 
13937 	return unit_test_suite_runner(&cryptodev_ccp_testsuite);
13938 }
13939 
13940 static int
13941 test_cryptodev_octeontx(void)
13942 {
13943 	gbl_driver_id =	rte_cryptodev_driver_id_get(
13944 			RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
13945 	if (gbl_driver_id == -1) {
13946 		RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded.\n");
13947 		return TEST_FAILED;
13948 	}
13949 	return unit_test_suite_runner(&cryptodev_testsuite);
13950 }
13951 
13952 static int
13953 test_cryptodev_octeontx2(void)
13954 {
13955 	gbl_driver_id =	rte_cryptodev_driver_id_get(
13956 			RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
13957 	if (gbl_driver_id == -1) {
13958 		RTE_LOG(ERR, USER1, "OCTEON TX2 PMD must be loaded.\n");
13959 		return TEST_FAILED;
13960 	}
13961 	return unit_test_suite_runner(&cryptodev_testsuite);
13962 }
13963 
13964 static int
13965 test_cryptodev_caam_jr(void /*argv __rte_unused, int argc __rte_unused*/)
13966 {
13967 	gbl_driver_id =	rte_cryptodev_driver_id_get(
13968 			RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
13969 
13970 	if (gbl_driver_id == -1) {
13971 		RTE_LOG(ERR, USER1, "CAAM_JR PMD must be loaded.\n");
13972 		return TEST_FAILED;
13973 	}
13974 
13975 	return unit_test_suite_runner(&cryptodev_caam_jr_testsuite);
13976 }
13977 
13978 static int
13979 test_cryptodev_nitrox(void)
13980 {
13981 	gbl_driver_id =	rte_cryptodev_driver_id_get(
13982 			RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
13983 
13984 	if (gbl_driver_id == -1) {
13985 		RTE_LOG(ERR, USER1, "NITROX PMD must be loaded.\n");
13986 		return TEST_FAILED;
13987 	}
13988 
13989 	return unit_test_suite_runner(&cryptodev_testsuite);
13990 }
13991 
13992 static int
13993 test_cryptodev_bcmfs(void)
13994 {
13995 	gbl_driver_id =	rte_cryptodev_driver_id_get(
13996 			RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
13997 
13998 	if (gbl_driver_id == -1) {
13999 		RTE_LOG(ERR, USER1, "BCMFS PMD must be loaded.\n");
14000 		return TEST_FAILED;
14001 	}
14002 
14003 	return unit_test_suite_runner(&cryptodev_testsuite);
14004 }
14005 
14006 static int
14007 test_cryptodev_qat_raw_api(void /*argv __rte_unused, int argc __rte_unused*/)
14008 {
14009 	int ret;
14010 
14011 	gbl_driver_id =	rte_cryptodev_driver_id_get(
14012 			RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
14013 
14014 	if (gbl_driver_id == -1) {
14015 		RTE_LOG(ERR, USER1, "QAT PMD must be loaded. Check that both "
14016 		"CONFIG_RTE_LIBRTE_PMD_QAT and CONFIG_RTE_LIBRTE_PMD_QAT_SYM "
14017 		"are enabled in config file to run this testsuite.\n");
14018 		return TEST_SKIPPED;
14019 	}
14020 
14021 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
14022 	ret = unit_test_suite_runner(&cryptodev_testsuite);
14023 	global_api_test_type = CRYPTODEV_API_TEST;
14024 
14025 	return ret;
14026 }
14027 
14028 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
14029 		test_cryptodev_qat_raw_api);
14030 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
14031 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
14032 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
14033 	test_cryptodev_cpu_aesni_mb);
14034 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
14035 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
14036 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
14037 	test_cryptodev_cpu_aesni_gcm);
14038 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
14039 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
14040 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
14041 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
14042 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
14043 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
14044 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
14045 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
14046 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
14047 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
14048 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
14049 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
14050 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
14051 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
14052 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);
14053