xref: /dpdk/app/test/test_cryptodev.c (revision c9902a15bd005b6d4fe072cf7b60fe4ee679155f)
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_string_fns.h>
20 
21 #ifdef RTE_CRYPTO_SCHEDULER
22 #include <rte_cryptodev_scheduler.h>
23 #include <rte_cryptodev_scheduler_operations.h>
24 #endif
25 
26 #include <rte_lcore.h>
27 
28 #include "test.h"
29 #include "test_cryptodev.h"
30 
31 #include "test_cryptodev_blockcipher.h"
32 #include "test_cryptodev_aes_test_vectors.h"
33 #include "test_cryptodev_des_test_vectors.h"
34 #include "test_cryptodev_hash_test_vectors.h"
35 #include "test_cryptodev_kasumi_test_vectors.h"
36 #include "test_cryptodev_kasumi_hash_test_vectors.h"
37 #include "test_cryptodev_snow3g_test_vectors.h"
38 #include "test_cryptodev_snow3g_hash_test_vectors.h"
39 #include "test_cryptodev_zuc_test_vectors.h"
40 #include "test_cryptodev_aead_test_vectors.h"
41 #include "test_cryptodev_hmac_test_vectors.h"
42 #include "test_cryptodev_mixed_test_vectors.h"
43 #ifdef RTE_LIB_SECURITY
44 #include "test_cryptodev_security_pdcp_test_vectors.h"
45 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h"
46 #include "test_cryptodev_security_pdcp_test_func.h"
47 #include "test_cryptodev_security_docsis_test_vectors.h"
48 
49 #define SDAP_DISABLED	0
50 #define SDAP_ENABLED	1
51 #endif
52 
53 #define VDEV_ARGS_SIZE 100
54 #define MAX_NB_SESSIONS 4
55 
56 #define MAX_DRV_SERVICE_CTX_SIZE 256
57 
58 #define MAX_RAW_DEQUEUE_COUNT	65535
59 
60 #define IN_PLACE 0
61 #define OUT_OF_PLACE 1
62 
63 static int gbl_driver_id;
64 
65 static enum rte_security_session_action_type gbl_action_type =
66 	RTE_SECURITY_ACTION_TYPE_NONE;
67 
68 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST;
69 
70 struct crypto_unittest_params {
71 	struct rte_crypto_sym_xform cipher_xform;
72 	struct rte_crypto_sym_xform auth_xform;
73 	struct rte_crypto_sym_xform aead_xform;
74 #ifdef RTE_LIB_SECURITY
75 	struct rte_security_docsis_xform docsis_xform;
76 #endif
77 
78 	union {
79 		struct rte_cryptodev_sym_session *sess;
80 #ifdef RTE_LIB_SECURITY
81 		struct rte_security_session *sec_session;
82 #endif
83 	};
84 #ifdef RTE_LIB_SECURITY
85 	enum rte_security_session_action_type type;
86 #endif
87 	struct rte_crypto_op *op;
88 
89 	struct rte_mbuf *obuf, *ibuf;
90 
91 	uint8_t *digest;
92 };
93 
94 #define ALIGN_POW2_ROUNDUP(num, align) \
95 	(((num) + (align) - 1) & ~((align) - 1))
96 
97 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts)	\
98 	for (j = 0; j < num_child_ts; index++, j++)			\
99 		parent_ts.unit_test_suites[index] = child_ts[j]
100 
101 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types)	\
102 	for (j = 0; j < num_blk_types; index++, j++)				\
103 		parent_ts.unit_test_suites[index] =				\
104 				build_blockcipher_test_suite(blk_types[j])
105 
106 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types)		\
107 	for (j = index; j < index + num_blk_types; j++)				\
108 		free_blockcipher_test_suite(parent_ts.unit_test_suites[j])
109 
110 /*
111  * Forward declarations.
112  */
113 static int
114 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
115 		struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
116 		uint8_t *hmac_key);
117 
118 static int
119 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
120 		struct crypto_unittest_params *ut_params,
121 		struct crypto_testsuite_params *ts_param,
122 		const uint8_t *cipher,
123 		const uint8_t *digest,
124 		const uint8_t *iv);
125 
126 static struct rte_mbuf *
127 setup_test_string(struct rte_mempool *mpool,
128 		const char *string, size_t len, uint8_t blocksize)
129 {
130 	struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
131 	size_t t_len = len - (blocksize ? (len % blocksize) : 0);
132 
133 	if (m) {
134 		char *dst;
135 
136 		memset(m->buf_addr, 0, m->buf_len);
137 		dst = rte_pktmbuf_append(m, t_len);
138 		if (!dst) {
139 			rte_pktmbuf_free(m);
140 			return NULL;
141 		}
142 		if (string != NULL)
143 			rte_memcpy(dst, string, t_len);
144 		else
145 			memset(dst, 0, t_len);
146 	}
147 
148 	return m;
149 }
150 
151 /* Get number of bytes in X bits (rounding up) */
152 static uint32_t
153 ceil_byte_length(uint32_t num_bits)
154 {
155 	if (num_bits % 8)
156 		return ((num_bits >> 3) + 1);
157 	else
158 		return (num_bits >> 3);
159 }
160 
161 static void
162 post_process_raw_dp_op(void *user_data,	uint32_t index __rte_unused,
163 		uint8_t is_op_success)
164 {
165 	struct rte_crypto_op *op = user_data;
166 	op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS :
167 			RTE_CRYPTO_OP_STATUS_ERROR;
168 }
169 
170 void
171 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
172 		struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
173 		uint8_t len_in_bits, uint8_t cipher_iv_len)
174 {
175 	struct rte_crypto_sym_op *sop = op->sym;
176 	struct rte_crypto_op *ret_op = NULL;
177 	struct rte_crypto_vec data_vec[UINT8_MAX];
178 	struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv;
179 	union rte_crypto_sym_ofs ofs;
180 	struct rte_crypto_sym_vec vec;
181 	struct rte_crypto_sgl sgl;
182 	uint32_t max_len;
183 	union rte_cryptodev_session_ctx sess;
184 	uint32_t count = 0;
185 	struct rte_crypto_raw_dp_ctx *ctx;
186 	uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0,
187 			auth_len = 0;
188 	int32_t n;
189 	uint32_t n_success;
190 	int ctx_service_size;
191 	int32_t status = 0;
192 	int enqueue_status, dequeue_status;
193 
194 	ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
195 	if (ctx_service_size < 0) {
196 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
197 		return;
198 	}
199 
200 	ctx = malloc(ctx_service_size);
201 	if (!ctx) {
202 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
203 		return;
204 	}
205 
206 	/* Both are enums, setting crypto_sess will suit any session type */
207 	sess.crypto_sess = op->sym->session;
208 
209 	if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx,
210 			op->sess_type, sess, 0) < 0) {
211 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
212 		goto exit;
213 	}
214 
215 	cipher_iv.iova = 0;
216 	cipher_iv.va = NULL;
217 	aad_auth_iv.iova = 0;
218 	aad_auth_iv.va = NULL;
219 	digest.iova = 0;
220 	digest.va = NULL;
221 	sgl.vec = data_vec;
222 	vec.num = 1;
223 	vec.sgl = &sgl;
224 	vec.iv = &cipher_iv;
225 	vec.digest = &digest;
226 	vec.aad = &aad_auth_iv;
227 	vec.status = &status;
228 
229 	ofs.raw = 0;
230 
231 	if (is_cipher && is_auth) {
232 		cipher_offset = sop->cipher.data.offset;
233 		cipher_len = sop->cipher.data.length;
234 		auth_offset = sop->auth.data.offset;
235 		auth_len = sop->auth.data.length;
236 		max_len = RTE_MAX(cipher_offset + cipher_len,
237 				auth_offset + auth_len);
238 		if (len_in_bits) {
239 			max_len = max_len >> 3;
240 			cipher_offset = cipher_offset >> 3;
241 			auth_offset = auth_offset >> 3;
242 			cipher_len = cipher_len >> 3;
243 			auth_len = auth_len >> 3;
244 		}
245 		ofs.ofs.cipher.head = cipher_offset;
246 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
247 		ofs.ofs.auth.head = auth_offset;
248 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
249 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
250 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
251 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
252 				op, void *, IV_OFFSET + cipher_iv_len);
253 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
254 				cipher_iv_len);
255 		digest.va = (void *)sop->auth.digest.data;
256 		digest.iova = sop->auth.digest.phys_addr;
257 
258 	} else if (is_cipher) {
259 		cipher_offset = sop->cipher.data.offset;
260 		cipher_len = sop->cipher.data.length;
261 		max_len = cipher_len + cipher_offset;
262 		if (len_in_bits) {
263 			max_len = max_len >> 3;
264 			cipher_offset = cipher_offset >> 3;
265 			cipher_len = cipher_len >> 3;
266 		}
267 		ofs.ofs.cipher.head = cipher_offset;
268 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
269 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
270 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
271 
272 	} else if (is_auth) {
273 		auth_offset = sop->auth.data.offset;
274 		auth_len = sop->auth.data.length;
275 		max_len = auth_len + auth_offset;
276 		if (len_in_bits) {
277 			max_len = max_len >> 3;
278 			auth_offset = auth_offset >> 3;
279 			auth_len = auth_len >> 3;
280 		}
281 		ofs.ofs.auth.head = auth_offset;
282 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
283 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
284 				op, void *, IV_OFFSET + cipher_iv_len);
285 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
286 				cipher_iv_len);
287 		digest.va = (void *)sop->auth.digest.data;
288 		digest.iova = sop->auth.digest.phys_addr;
289 
290 	} else { /* aead */
291 		cipher_offset = sop->aead.data.offset;
292 		cipher_len = sop->aead.data.length;
293 		max_len = cipher_len + cipher_offset;
294 		if (len_in_bits) {
295 			max_len = max_len >> 3;
296 			cipher_offset = cipher_offset >> 3;
297 			cipher_len = cipher_len >> 3;
298 		}
299 		ofs.ofs.cipher.head = cipher_offset;
300 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
301 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
302 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
303 		aad_auth_iv.va = (void *)sop->aead.aad.data;
304 		aad_auth_iv.iova = sop->aead.aad.phys_addr;
305 		digest.va = (void *)sop->aead.digest.data;
306 		digest.iova = sop->aead.digest.phys_addr;
307 	}
308 
309 	n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
310 			data_vec, RTE_DIM(data_vec));
311 	if (n < 0 || n > sop->m_src->nb_segs) {
312 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
313 		goto exit;
314 	}
315 
316 	sgl.num = n;
317 
318 	if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op,
319 			&enqueue_status) < 1) {
320 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
321 		goto exit;
322 	}
323 
324 	if (enqueue_status == 0) {
325 		status = rte_cryptodev_raw_enqueue_done(ctx, 1);
326 		if (status < 0) {
327 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
328 			goto exit;
329 		}
330 	} else if (enqueue_status < 0) {
331 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
332 		goto exit;
333 	}
334 
335 	n = n_success = 0;
336 	while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) {
337 		n = rte_cryptodev_raw_dequeue_burst(ctx,
338 			NULL, 1, post_process_raw_dp_op,
339 				(void **)&ret_op, 0, &n_success,
340 				&dequeue_status);
341 		if (dequeue_status < 0) {
342 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
343 			goto exit;
344 		}
345 		if (n == 0)
346 			rte_pause();
347 	}
348 
349 	if (n == 1 && dequeue_status == 0) {
350 		if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) {
351 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
352 			goto exit;
353 		}
354 	}
355 
356 	op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op ||
357 			n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
358 					RTE_CRYPTO_OP_STATUS_SUCCESS;
359 
360 exit:
361 	free(ctx);
362 }
363 
364 static void
365 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
366 {
367 	int32_t n, st;
368 	struct rte_crypto_sym_op *sop;
369 	union rte_crypto_sym_ofs ofs;
370 	struct rte_crypto_sgl sgl;
371 	struct rte_crypto_sym_vec symvec;
372 	struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
373 	struct rte_crypto_vec vec[UINT8_MAX];
374 
375 	sop = op->sym;
376 
377 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
378 		sop->aead.data.length, vec, RTE_DIM(vec));
379 
380 	if (n < 0 || n != sop->m_src->nb_segs) {
381 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
382 		return;
383 	}
384 
385 	sgl.vec = vec;
386 	sgl.num = n;
387 	symvec.sgl = &sgl;
388 	symvec.iv = &iv_ptr;
389 	symvec.digest = &digest_ptr;
390 	symvec.aad = &aad_ptr;
391 	symvec.status = &st;
392 	symvec.num = 1;
393 
394 	/* for CPU crypto the IOVA address is not required */
395 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
396 	digest_ptr.va = (void *)sop->aead.digest.data;
397 	aad_ptr.va = (void *)sop->aead.aad.data;
398 
399 	ofs.raw = 0;
400 
401 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
402 		&symvec);
403 
404 	if (n != 1)
405 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
406 	else
407 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
408 }
409 
410 static void
411 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
412 {
413 	int32_t n, st;
414 	struct rte_crypto_sym_op *sop;
415 	union rte_crypto_sym_ofs ofs;
416 	struct rte_crypto_sgl sgl;
417 	struct rte_crypto_sym_vec symvec;
418 	struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
419 	struct rte_crypto_vec vec[UINT8_MAX];
420 
421 	sop = op->sym;
422 
423 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
424 		sop->auth.data.length, vec, RTE_DIM(vec));
425 
426 	if (n < 0 || n != sop->m_src->nb_segs) {
427 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
428 		return;
429 	}
430 
431 	sgl.vec = vec;
432 	sgl.num = n;
433 	symvec.sgl = &sgl;
434 	symvec.iv = &iv_ptr;
435 	symvec.digest = &digest_ptr;
436 	symvec.status = &st;
437 	symvec.num = 1;
438 
439 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
440 	digest_ptr.va = (void *)sop->auth.digest.data;
441 
442 	ofs.raw = 0;
443 	ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
444 	ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
445 		(sop->cipher.data.offset + sop->cipher.data.length);
446 
447 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
448 		&symvec);
449 
450 	if (n != 1)
451 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
452 	else
453 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
454 }
455 
456 static struct rte_crypto_op *
457 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
458 {
459 
460 	RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
461 
462 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
463 		RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
464 		return NULL;
465 	}
466 
467 	op = NULL;
468 
469 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
470 		rte_pause();
471 
472 	if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
473 		RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
474 		return NULL;
475 	}
476 
477 	return op;
478 }
479 
480 static struct crypto_testsuite_params testsuite_params = { NULL };
481 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params;
482 static struct crypto_unittest_params unittest_params;
483 
484 static int
485 testsuite_setup(void)
486 {
487 	struct crypto_testsuite_params *ts_params = &testsuite_params;
488 	struct rte_cryptodev_info info;
489 	uint32_t i = 0, nb_devs, dev_id;
490 	uint16_t qp_id;
491 
492 	memset(ts_params, 0, sizeof(*ts_params));
493 
494 	ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
495 	if (ts_params->mbuf_pool == NULL) {
496 		/* Not already created so create */
497 		ts_params->mbuf_pool = rte_pktmbuf_pool_create(
498 				"CRYPTO_MBUFPOOL",
499 				NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
500 				rte_socket_id());
501 		if (ts_params->mbuf_pool == NULL) {
502 			RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
503 			return TEST_FAILED;
504 		}
505 	}
506 
507 	ts_params->large_mbuf_pool = rte_mempool_lookup(
508 			"CRYPTO_LARGE_MBUFPOOL");
509 	if (ts_params->large_mbuf_pool == NULL) {
510 		/* Not already created so create */
511 		ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
512 				"CRYPTO_LARGE_MBUFPOOL",
513 				1, 0, 0, UINT16_MAX,
514 				rte_socket_id());
515 		if (ts_params->large_mbuf_pool == NULL) {
516 			RTE_LOG(ERR, USER1,
517 				"Can't create CRYPTO_LARGE_MBUFPOOL\n");
518 			return TEST_FAILED;
519 		}
520 	}
521 
522 	ts_params->op_mpool = rte_crypto_op_pool_create(
523 			"MBUF_CRYPTO_SYM_OP_POOL",
524 			RTE_CRYPTO_OP_TYPE_SYMMETRIC,
525 			NUM_MBUFS, MBUF_CACHE_SIZE,
526 			DEFAULT_NUM_XFORMS *
527 			sizeof(struct rte_crypto_sym_xform) +
528 			MAXIMUM_IV_LENGTH,
529 			rte_socket_id());
530 	if (ts_params->op_mpool == NULL) {
531 		RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
532 		return TEST_FAILED;
533 	}
534 
535 	nb_devs = rte_cryptodev_count();
536 	if (nb_devs < 1) {
537 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
538 		return TEST_SKIPPED;
539 	}
540 
541 	if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) {
542 		RTE_LOG(WARNING, USER1, "No %s devices found?\n",
543 				rte_cryptodev_driver_name_get(gbl_driver_id));
544 		return TEST_SKIPPED;
545 	}
546 
547 	/* Create list of valid crypto devs */
548 	for (i = 0; i < nb_devs; i++) {
549 		rte_cryptodev_info_get(i, &info);
550 		if (info.driver_id == gbl_driver_id)
551 			ts_params->valid_devs[ts_params->valid_dev_count++] = i;
552 	}
553 
554 	if (ts_params->valid_dev_count < 1)
555 		return TEST_FAILED;
556 
557 	/* Set up all the qps on the first of the valid devices found */
558 
559 	dev_id = ts_params->valid_devs[0];
560 
561 	rte_cryptodev_info_get(dev_id, &info);
562 
563 	ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
564 	ts_params->conf.socket_id = SOCKET_ID_ANY;
565 	ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
566 
567 	unsigned int session_size =
568 		rte_cryptodev_sym_get_private_session_size(dev_id);
569 
570 #ifdef RTE_LIB_SECURITY
571 	unsigned int security_session_size = rte_security_session_get_size(
572 			rte_cryptodev_get_sec_ctx(dev_id));
573 
574 	if (session_size < security_session_size)
575 		session_size = security_session_size;
576 #endif
577 	/*
578 	 * Create mempool with maximum number of sessions.
579 	 */
580 	if (info.sym.max_nb_sessions != 0 &&
581 			info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
582 		RTE_LOG(ERR, USER1, "Device does not support "
583 				"at least %u sessions\n",
584 				MAX_NB_SESSIONS);
585 		return TEST_FAILED;
586 	}
587 
588 	ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
589 			"test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
590 			SOCKET_ID_ANY);
591 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
592 			"session mempool allocation failed");
593 
594 	ts_params->session_priv_mpool = rte_mempool_create(
595 			"test_sess_mp_priv",
596 			MAX_NB_SESSIONS,
597 			session_size,
598 			0, 0, NULL, NULL, NULL,
599 			NULL, SOCKET_ID_ANY,
600 			0);
601 	TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
602 			"session mempool allocation failed");
603 
604 
605 
606 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
607 			&ts_params->conf),
608 			"Failed to configure cryptodev %u with %u qps",
609 			dev_id, ts_params->conf.nb_queue_pairs);
610 
611 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
612 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
613 	ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
614 
615 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
616 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
617 			dev_id, qp_id, &ts_params->qp_conf,
618 			rte_cryptodev_socket_id(dev_id)),
619 			"Failed to setup queue pair %u on cryptodev %u",
620 			qp_id, dev_id);
621 	}
622 
623 	return TEST_SUCCESS;
624 }
625 
626 static void
627 testsuite_teardown(void)
628 {
629 	struct crypto_testsuite_params *ts_params = &testsuite_params;
630 	int res;
631 
632 	if (ts_params->mbuf_pool != NULL) {
633 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
634 		rte_mempool_avail_count(ts_params->mbuf_pool));
635 	}
636 
637 	if (ts_params->op_mpool != NULL) {
638 		RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
639 		rte_mempool_avail_count(ts_params->op_mpool));
640 	}
641 
642 	/* Free session mempools */
643 	if (ts_params->session_priv_mpool != NULL) {
644 		rte_mempool_free(ts_params->session_priv_mpool);
645 		ts_params->session_priv_mpool = NULL;
646 	}
647 
648 	if (ts_params->session_mpool != NULL) {
649 		rte_mempool_free(ts_params->session_mpool);
650 		ts_params->session_mpool = NULL;
651 	}
652 
653 	res = rte_cryptodev_close(ts_params->valid_devs[0]);
654 	if (res)
655 		RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res);
656 }
657 
658 static int
659 check_capabilities_supported(enum rte_crypto_sym_xform_type type,
660 		const int *algs, uint16_t num_algs)
661 {
662 	uint8_t dev_id = testsuite_params.valid_devs[0];
663 	bool some_alg_supported = FALSE;
664 	uint16_t i;
665 
666 	for (i = 0; i < num_algs && !some_alg_supported; i++) {
667 		struct rte_cryptodev_sym_capability_idx alg = {
668 			type, {algs[i]}
669 		};
670 		if (rte_cryptodev_sym_capability_get(dev_id,
671 				&alg) != NULL)
672 			some_alg_supported = TRUE;
673 	}
674 	if (!some_alg_supported)
675 		return TEST_SKIPPED;
676 
677 	return 0;
678 }
679 
680 int
681 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
682 		uint16_t num_ciphers)
683 {
684 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER,
685 			(const int *) ciphers, num_ciphers);
686 }
687 
688 int
689 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
690 		uint16_t num_auths)
691 {
692 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH,
693 			(const int *) auths, num_auths);
694 }
695 
696 int
697 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
698 		uint16_t num_aeads)
699 {
700 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD,
701 			(const int *) aeads, num_aeads);
702 }
703 
704 static int
705 null_testsuite_setup(void)
706 {
707 	struct crypto_testsuite_params *ts_params = &testsuite_params;
708 	uint8_t dev_id = ts_params->valid_devs[0];
709 	struct rte_cryptodev_info dev_info;
710 	const enum rte_crypto_cipher_algorithm ciphers[] = {
711 		RTE_CRYPTO_CIPHER_NULL
712 	};
713 	const enum rte_crypto_auth_algorithm auths[] = {
714 		RTE_CRYPTO_AUTH_NULL
715 	};
716 
717 	rte_cryptodev_info_get(dev_id, &dev_info);
718 
719 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
720 		RTE_LOG(INFO, USER1, "Feature flag requirements for NULL "
721 				"testsuite not met\n");
722 		return TEST_SKIPPED;
723 	}
724 
725 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
726 			&& check_auth_capabilities_supported(auths,
727 			RTE_DIM(auths)) != 0) {
728 		RTE_LOG(INFO, USER1, "Capability requirements for NULL "
729 				"testsuite not met\n");
730 		return TEST_SKIPPED;
731 	}
732 
733 	return 0;
734 }
735 
736 static int
737 crypto_gen_testsuite_setup(void)
738 {
739 	struct crypto_testsuite_params *ts_params = &testsuite_params;
740 	uint8_t dev_id = ts_params->valid_devs[0];
741 	struct rte_cryptodev_info dev_info;
742 
743 	rte_cryptodev_info_get(dev_id, &dev_info);
744 
745 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
746 		RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen "
747 				"testsuite not met\n");
748 		return TEST_SKIPPED;
749 	}
750 
751 	return 0;
752 }
753 
754 #ifdef RTE_LIB_SECURITY
755 static int
756 pdcp_proto_testsuite_setup(void)
757 {
758 	struct crypto_testsuite_params *ts_params = &testsuite_params;
759 	uint8_t dev_id = ts_params->valid_devs[0];
760 	struct rte_cryptodev_info dev_info;
761 	const enum rte_crypto_cipher_algorithm ciphers[] = {
762 		RTE_CRYPTO_CIPHER_NULL,
763 		RTE_CRYPTO_CIPHER_AES_CTR,
764 		RTE_CRYPTO_CIPHER_ZUC_EEA3,
765 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
766 	};
767 	const enum rte_crypto_auth_algorithm auths[] = {
768 		RTE_CRYPTO_AUTH_NULL,
769 		RTE_CRYPTO_AUTH_SNOW3G_UIA2,
770 		RTE_CRYPTO_AUTH_AES_CMAC,
771 		RTE_CRYPTO_AUTH_ZUC_EIA3
772 	};
773 
774 	rte_cryptodev_info_get(dev_id, &dev_info);
775 
776 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
777 			!(dev_info.feature_flags &
778 			RTE_CRYPTODEV_FF_SECURITY)) {
779 		RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto "
780 				"testsuite not met\n");
781 		return TEST_SKIPPED;
782 	}
783 
784 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
785 			&& check_auth_capabilities_supported(auths,
786 			RTE_DIM(auths)) != 0) {
787 		RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto "
788 				"testsuite not met\n");
789 		return TEST_SKIPPED;
790 	}
791 
792 	return 0;
793 }
794 
795 static int
796 docsis_proto_testsuite_setup(void)
797 {
798 	struct crypto_testsuite_params *ts_params = &testsuite_params;
799 	uint8_t dev_id = ts_params->valid_devs[0];
800 	struct rte_cryptodev_info dev_info;
801 	const enum rte_crypto_cipher_algorithm ciphers[] = {
802 		RTE_CRYPTO_CIPHER_AES_DOCSISBPI
803 	};
804 
805 	rte_cryptodev_info_get(dev_id, &dev_info);
806 
807 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
808 			!(dev_info.feature_flags &
809 			RTE_CRYPTODEV_FF_SECURITY)) {
810 		RTE_LOG(INFO, USER1, "Feature flag requirements for Docsis "
811 				"Proto testsuite not met\n");
812 		return TEST_SKIPPED;
813 	}
814 
815 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
816 		RTE_LOG(INFO, USER1, "Capability requirements for Docsis Proto "
817 				"testsuite not met\n");
818 		return TEST_SKIPPED;
819 	}
820 
821 	return 0;
822 }
823 #endif
824 
825 static int
826 aes_ccm_auth_testsuite_setup(void)
827 {
828 	struct crypto_testsuite_params *ts_params = &testsuite_params;
829 	uint8_t dev_id = ts_params->valid_devs[0];
830 	struct rte_cryptodev_info dev_info;
831 	const enum rte_crypto_aead_algorithm aeads[] = {
832 		RTE_CRYPTO_AEAD_AES_CCM
833 	};
834 
835 	rte_cryptodev_info_get(dev_id, &dev_info);
836 
837 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
838 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
839 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
840 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM "
841 				"testsuite not met\n");
842 		return TEST_SKIPPED;
843 	}
844 
845 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
846 		RTE_LOG(INFO, USER1, "Capability requirements for AES CCM "
847 				"testsuite not met\n");
848 		return TEST_SKIPPED;
849 	}
850 
851 	return 0;
852 }
853 
854 static int
855 aes_gcm_auth_testsuite_setup(void)
856 {
857 	struct crypto_testsuite_params *ts_params = &testsuite_params;
858 	uint8_t dev_id = ts_params->valid_devs[0];
859 	struct rte_cryptodev_info dev_info;
860 	const enum rte_crypto_aead_algorithm aeads[] = {
861 		RTE_CRYPTO_AEAD_AES_GCM
862 	};
863 
864 	rte_cryptodev_info_get(dev_id, &dev_info);
865 
866 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
867 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM "
868 				"testsuite not met\n");
869 		return TEST_SKIPPED;
870 	}
871 
872 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
873 		RTE_LOG(INFO, USER1, "Capability requirements for AES GCM "
874 				"testsuite not met\n");
875 		return TEST_SKIPPED;
876 	}
877 
878 	return 0;
879 }
880 
881 static int
882 aes_gmac_auth_testsuite_setup(void)
883 {
884 	struct crypto_testsuite_params *ts_params = &testsuite_params;
885 	uint8_t dev_id = ts_params->valid_devs[0];
886 	struct rte_cryptodev_info dev_info;
887 	const enum rte_crypto_auth_algorithm auths[] = {
888 		RTE_CRYPTO_AUTH_AES_GMAC
889 	};
890 
891 	rte_cryptodev_info_get(dev_id, &dev_info);
892 
893 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
894 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
895 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
896 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC "
897 				"testsuite not met\n");
898 		return TEST_SKIPPED;
899 	}
900 
901 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
902 		RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC "
903 				"testsuite not met\n");
904 		return TEST_SKIPPED;
905 	}
906 
907 	return 0;
908 }
909 
910 static int
911 chacha20_poly1305_testsuite_setup(void)
912 {
913 	struct crypto_testsuite_params *ts_params = &testsuite_params;
914 	uint8_t dev_id = ts_params->valid_devs[0];
915 	struct rte_cryptodev_info dev_info;
916 	const enum rte_crypto_aead_algorithm aeads[] = {
917 		RTE_CRYPTO_AEAD_CHACHA20_POLY1305
918 	};
919 
920 	rte_cryptodev_info_get(dev_id, &dev_info);
921 
922 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
923 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
924 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
925 		RTE_LOG(INFO, USER1, "Feature flag requirements for "
926 				"Chacha20-Poly1305 testsuite not met\n");
927 		return TEST_SKIPPED;
928 	}
929 
930 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
931 		RTE_LOG(INFO, USER1, "Capability requirements for "
932 				"Chacha20-Poly1305 testsuite not met\n");
933 		return TEST_SKIPPED;
934 	}
935 
936 	return 0;
937 }
938 
939 static int
940 snow3g_testsuite_setup(void)
941 {
942 	struct crypto_testsuite_params *ts_params = &testsuite_params;
943 	uint8_t dev_id = ts_params->valid_devs[0];
944 	struct rte_cryptodev_info dev_info;
945 	const enum rte_crypto_cipher_algorithm ciphers[] = {
946 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
947 
948 	};
949 	const enum rte_crypto_auth_algorithm auths[] = {
950 		RTE_CRYPTO_AUTH_SNOW3G_UIA2
951 	};
952 
953 	rte_cryptodev_info_get(dev_id, &dev_info);
954 
955 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
956 		RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G "
957 				"testsuite not met\n");
958 		return TEST_SKIPPED;
959 	}
960 
961 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
962 			&& check_auth_capabilities_supported(auths,
963 			RTE_DIM(auths)) != 0) {
964 		RTE_LOG(INFO, USER1, "Capability requirements for Snow3G "
965 				"testsuite not met\n");
966 		return TEST_SKIPPED;
967 	}
968 
969 	return 0;
970 }
971 
972 static int
973 zuc_testsuite_setup(void)
974 {
975 	struct crypto_testsuite_params *ts_params = &testsuite_params;
976 	uint8_t dev_id = ts_params->valid_devs[0];
977 	struct rte_cryptodev_info dev_info;
978 	const enum rte_crypto_cipher_algorithm ciphers[] = {
979 		RTE_CRYPTO_CIPHER_ZUC_EEA3
980 	};
981 	const enum rte_crypto_auth_algorithm auths[] = {
982 		RTE_CRYPTO_AUTH_ZUC_EIA3
983 	};
984 
985 	rte_cryptodev_info_get(dev_id, &dev_info);
986 
987 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
988 		RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC "
989 				"testsuite not met\n");
990 		return TEST_SKIPPED;
991 	}
992 
993 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
994 			&& check_auth_capabilities_supported(auths,
995 			RTE_DIM(auths)) != 0) {
996 		RTE_LOG(INFO, USER1, "Capability requirements for ZUC "
997 				"testsuite not met\n");
998 		return TEST_SKIPPED;
999 	}
1000 
1001 	return 0;
1002 }
1003 
1004 static int
1005 hmac_md5_auth_testsuite_setup(void)
1006 {
1007 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1008 	uint8_t dev_id = ts_params->valid_devs[0];
1009 	struct rte_cryptodev_info dev_info;
1010 	const enum rte_crypto_auth_algorithm auths[] = {
1011 		RTE_CRYPTO_AUTH_MD5_HMAC
1012 	};
1013 
1014 	rte_cryptodev_info_get(dev_id, &dev_info);
1015 
1016 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1017 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1018 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1019 		RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 "
1020 				"Auth testsuite not met\n");
1021 		return TEST_SKIPPED;
1022 	}
1023 
1024 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1025 		RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 "
1026 				"testsuite not met\n");
1027 		return TEST_SKIPPED;
1028 	}
1029 
1030 	return 0;
1031 }
1032 
1033 static int
1034 kasumi_testsuite_setup(void)
1035 {
1036 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1037 	uint8_t dev_id = ts_params->valid_devs[0];
1038 	struct rte_cryptodev_info dev_info;
1039 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1040 		RTE_CRYPTO_CIPHER_KASUMI_F8
1041 	};
1042 	const enum rte_crypto_auth_algorithm auths[] = {
1043 		RTE_CRYPTO_AUTH_KASUMI_F9
1044 	};
1045 
1046 	rte_cryptodev_info_get(dev_id, &dev_info);
1047 
1048 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1049 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1050 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1051 		RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi "
1052 				"testsuite not met\n");
1053 		return TEST_SKIPPED;
1054 	}
1055 
1056 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1057 			&& check_auth_capabilities_supported(auths,
1058 			RTE_DIM(auths)) != 0) {
1059 		RTE_LOG(INFO, USER1, "Capability requirements for Kasumi "
1060 				"testsuite not met\n");
1061 		return TEST_SKIPPED;
1062 	}
1063 
1064 	return 0;
1065 }
1066 
1067 static int
1068 negative_aes_gcm_testsuite_setup(void)
1069 {
1070 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1071 	uint8_t dev_id = ts_params->valid_devs[0];
1072 	struct rte_cryptodev_info dev_info;
1073 	const enum rte_crypto_aead_algorithm aeads[] = {
1074 		RTE_CRYPTO_AEAD_AES_GCM
1075 	};
1076 
1077 	rte_cryptodev_info_get(dev_id, &dev_info);
1078 
1079 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1080 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1081 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1082 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1083 				"AES GCM testsuite not met\n");
1084 		return TEST_SKIPPED;
1085 	}
1086 
1087 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1088 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1089 				"AES GCM testsuite not met\n");
1090 		return TEST_SKIPPED;
1091 	}
1092 
1093 	return 0;
1094 }
1095 
1096 static int
1097 negative_aes_gmac_testsuite_setup(void)
1098 {
1099 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1100 	uint8_t dev_id = ts_params->valid_devs[0];
1101 	struct rte_cryptodev_info dev_info;
1102 	const enum rte_crypto_auth_algorithm auths[] = {
1103 		RTE_CRYPTO_AUTH_AES_GMAC
1104 	};
1105 
1106 	rte_cryptodev_info_get(dev_id, &dev_info);
1107 
1108 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1109 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1110 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1111 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1112 				"AES GMAC testsuite not met\n");
1113 		return TEST_SKIPPED;
1114 	}
1115 
1116 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1117 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1118 				"AES GMAC testsuite not met\n");
1119 		return TEST_SKIPPED;
1120 	}
1121 
1122 	return 0;
1123 }
1124 
1125 static int
1126 mixed_cipher_hash_testsuite_setup(void)
1127 {
1128 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1129 	uint8_t dev_id = ts_params->valid_devs[0];
1130 	struct rte_cryptodev_info dev_info;
1131 	uint64_t feat_flags;
1132 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1133 		RTE_CRYPTO_CIPHER_NULL,
1134 		RTE_CRYPTO_CIPHER_AES_CTR,
1135 		RTE_CRYPTO_CIPHER_ZUC_EEA3,
1136 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1137 	};
1138 	const enum rte_crypto_auth_algorithm auths[] = {
1139 		RTE_CRYPTO_AUTH_NULL,
1140 		RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1141 		RTE_CRYPTO_AUTH_AES_CMAC,
1142 		RTE_CRYPTO_AUTH_ZUC_EIA3
1143 	};
1144 
1145 	rte_cryptodev_info_get(dev_id, &dev_info);
1146 	feat_flags = dev_info.feature_flags;
1147 
1148 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1149 			(global_api_test_type == CRYPTODEV_RAW_API_TEST)) {
1150 		RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed "
1151 				"Cipher Hash testsuite not met\n");
1152 		return TEST_SKIPPED;
1153 	}
1154 
1155 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1156 			&& check_auth_capabilities_supported(auths,
1157 			RTE_DIM(auths)) != 0) {
1158 		RTE_LOG(INFO, USER1, "Capability requirements for Mixed "
1159 				"Cipher Hash testsuite not met\n");
1160 		return TEST_SKIPPED;
1161 	}
1162 
1163 	return 0;
1164 }
1165 
1166 static int
1167 esn_testsuite_setup(void)
1168 {
1169 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1170 	uint8_t dev_id = ts_params->valid_devs[0];
1171 	struct rte_cryptodev_info dev_info;
1172 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1173 		RTE_CRYPTO_CIPHER_AES_CBC
1174 	};
1175 	const enum rte_crypto_auth_algorithm auths[] = {
1176 		RTE_CRYPTO_AUTH_SHA1_HMAC
1177 	};
1178 
1179 	rte_cryptodev_info_get(dev_id, &dev_info);
1180 
1181 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1182 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1183 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1184 		RTE_LOG(INFO, USER1, "Feature flag requirements for ESN "
1185 				"testsuite not met\n");
1186 		return TEST_SKIPPED;
1187 	}
1188 
1189 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1190 			&& check_auth_capabilities_supported(auths,
1191 			RTE_DIM(auths)) != 0) {
1192 		RTE_LOG(INFO, USER1, "Capability requirements for ESN "
1193 				"testsuite not met\n");
1194 		return TEST_SKIPPED;
1195 	}
1196 
1197 	return 0;
1198 }
1199 
1200 static int
1201 multi_session_testsuite_setup(void)
1202 {
1203 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1204 	uint8_t dev_id = ts_params->valid_devs[0];
1205 	struct rte_cryptodev_info dev_info;
1206 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1207 		RTE_CRYPTO_CIPHER_AES_CBC
1208 	};
1209 	const enum rte_crypto_auth_algorithm auths[] = {
1210 		RTE_CRYPTO_AUTH_SHA512_HMAC
1211 	};
1212 
1213 	rte_cryptodev_info_get(dev_id, &dev_info);
1214 
1215 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1216 		RTE_LOG(INFO, USER1, "Feature flag requirements for Multi "
1217 				"Session testsuite not met\n");
1218 		return TEST_SKIPPED;
1219 	}
1220 
1221 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1222 			&& check_auth_capabilities_supported(auths,
1223 			RTE_DIM(auths)) != 0) {
1224 		RTE_LOG(INFO, USER1, "Capability requirements for Multi "
1225 				"Session testsuite not met\n");
1226 		return TEST_SKIPPED;
1227 	}
1228 
1229 	return 0;
1230 }
1231 
1232 static int
1233 negative_hmac_sha1_testsuite_setup(void)
1234 {
1235 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1236 	uint8_t dev_id = ts_params->valid_devs[0];
1237 	struct rte_cryptodev_info dev_info;
1238 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1239 		RTE_CRYPTO_CIPHER_AES_CBC
1240 	};
1241 	const enum rte_crypto_auth_algorithm auths[] = {
1242 		RTE_CRYPTO_AUTH_SHA1_HMAC
1243 	};
1244 
1245 	rte_cryptodev_info_get(dev_id, &dev_info);
1246 
1247 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1248 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1249 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1250 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1251 				"HMAC SHA1 testsuite not met\n");
1252 		return TEST_SKIPPED;
1253 	}
1254 
1255 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1256 			&& check_auth_capabilities_supported(auths,
1257 			RTE_DIM(auths)) != 0) {
1258 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1259 				"HMAC SHA1 testsuite not met\n");
1260 		return TEST_SKIPPED;
1261 	}
1262 
1263 	return 0;
1264 }
1265 
1266 static int
1267 dev_configure_and_start(uint64_t ff_disable)
1268 {
1269 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1270 	struct crypto_unittest_params *ut_params = &unittest_params;
1271 
1272 	uint16_t qp_id;
1273 
1274 	/* Clear unit test parameters before running test */
1275 	memset(ut_params, 0, sizeof(*ut_params));
1276 
1277 	/* Reconfigure device to default parameters */
1278 	ts_params->conf.socket_id = SOCKET_ID_ANY;
1279 	ts_params->conf.ff_disable = ff_disable;
1280 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
1281 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
1282 	ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
1283 
1284 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1285 			&ts_params->conf),
1286 			"Failed to configure cryptodev %u",
1287 			ts_params->valid_devs[0]);
1288 
1289 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
1290 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1291 			ts_params->valid_devs[0], qp_id,
1292 			&ts_params->qp_conf,
1293 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1294 			"Failed to setup queue pair %u on cryptodev %u",
1295 			qp_id, ts_params->valid_devs[0]);
1296 	}
1297 
1298 
1299 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1300 
1301 	/* Start the device */
1302 	TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1303 			"Failed to start cryptodev %u",
1304 			ts_params->valid_devs[0]);
1305 
1306 	return TEST_SUCCESS;
1307 }
1308 
1309 int
1310 ut_setup(void)
1311 {
1312 	/* Configure and start the device with security feature disabled */
1313 	return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
1314 }
1315 
1316 static int
1317 ut_setup_security(void)
1318 {
1319 	/* Configure and start the device with no features disabled */
1320 	return dev_configure_and_start(0);
1321 }
1322 
1323 void
1324 ut_teardown(void)
1325 {
1326 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1327 	struct crypto_unittest_params *ut_params = &unittest_params;
1328 	struct rte_cryptodev_stats stats;
1329 
1330 	/* free crypto session structure */
1331 #ifdef RTE_LIB_SECURITY
1332 	if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
1333 		if (ut_params->sec_session) {
1334 			rte_security_session_destroy(rte_cryptodev_get_sec_ctx
1335 						(ts_params->valid_devs[0]),
1336 						ut_params->sec_session);
1337 			ut_params->sec_session = NULL;
1338 		}
1339 	} else
1340 #endif
1341 	{
1342 		if (ut_params->sess) {
1343 			rte_cryptodev_sym_session_clear(
1344 					ts_params->valid_devs[0],
1345 					ut_params->sess);
1346 			rte_cryptodev_sym_session_free(ut_params->sess);
1347 			ut_params->sess = NULL;
1348 		}
1349 	}
1350 
1351 	/* free crypto operation structure */
1352 	if (ut_params->op)
1353 		rte_crypto_op_free(ut_params->op);
1354 
1355 	/*
1356 	 * free mbuf - both obuf and ibuf are usually the same,
1357 	 * so check if they point at the same address is necessary,
1358 	 * to avoid freeing the mbuf twice.
1359 	 */
1360 	if (ut_params->obuf) {
1361 		rte_pktmbuf_free(ut_params->obuf);
1362 		if (ut_params->ibuf == ut_params->obuf)
1363 			ut_params->ibuf = 0;
1364 		ut_params->obuf = 0;
1365 	}
1366 	if (ut_params->ibuf) {
1367 		rte_pktmbuf_free(ut_params->ibuf);
1368 		ut_params->ibuf = 0;
1369 	}
1370 
1371 	if (ts_params->mbuf_pool != NULL)
1372 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
1373 			rte_mempool_avail_count(ts_params->mbuf_pool));
1374 
1375 	rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
1376 
1377 	/* Stop the device */
1378 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1379 }
1380 
1381 static int
1382 test_device_configure_invalid_dev_id(void)
1383 {
1384 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1385 	uint16_t dev_id, num_devs = 0;
1386 
1387 	TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
1388 			"Need at least %d devices for test", 1);
1389 
1390 	/* valid dev_id values */
1391 	dev_id = ts_params->valid_devs[0];
1392 
1393 	/* Stop the device in case it's started so it can be configured */
1394 	rte_cryptodev_stop(dev_id);
1395 
1396 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
1397 			"Failed test for rte_cryptodev_configure: "
1398 			"invalid dev_num %u", dev_id);
1399 
1400 	/* invalid dev_id values */
1401 	dev_id = num_devs;
1402 
1403 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1404 			"Failed test for rte_cryptodev_configure: "
1405 			"invalid dev_num %u", dev_id);
1406 
1407 	dev_id = 0xff;
1408 
1409 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1410 			"Failed test for rte_cryptodev_configure:"
1411 			"invalid dev_num %u", dev_id);
1412 
1413 	return TEST_SUCCESS;
1414 }
1415 
1416 static int
1417 test_device_configure_invalid_queue_pair_ids(void)
1418 {
1419 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1420 	uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1421 
1422 	/* Stop the device in case it's started so it can be configured */
1423 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1424 
1425 	/* valid - max value queue pairs */
1426 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1427 
1428 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1429 			&ts_params->conf),
1430 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1431 			ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1432 
1433 	/* valid - one queue pairs */
1434 	ts_params->conf.nb_queue_pairs = 1;
1435 
1436 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1437 			&ts_params->conf),
1438 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1439 			ts_params->valid_devs[0],
1440 			ts_params->conf.nb_queue_pairs);
1441 
1442 
1443 	/* invalid - zero queue pairs */
1444 	ts_params->conf.nb_queue_pairs = 0;
1445 
1446 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1447 			&ts_params->conf),
1448 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1449 			" invalid qps: %u",
1450 			ts_params->valid_devs[0],
1451 			ts_params->conf.nb_queue_pairs);
1452 
1453 
1454 	/* invalid - max value supported by field queue pairs */
1455 	ts_params->conf.nb_queue_pairs = UINT16_MAX;
1456 
1457 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1458 			&ts_params->conf),
1459 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1460 			" invalid qps: %u",
1461 			ts_params->valid_devs[0],
1462 			ts_params->conf.nb_queue_pairs);
1463 
1464 
1465 	/* invalid - max value + 1 queue pairs */
1466 	ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1467 
1468 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1469 			&ts_params->conf),
1470 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1471 			" invalid qps: %u",
1472 			ts_params->valid_devs[0],
1473 			ts_params->conf.nb_queue_pairs);
1474 
1475 	/* revert to original testsuite value */
1476 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1477 
1478 	return TEST_SUCCESS;
1479 }
1480 
1481 static int
1482 test_queue_pair_descriptor_setup(void)
1483 {
1484 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1485 	struct rte_cryptodev_qp_conf qp_conf = {
1486 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
1487 	};
1488 	uint16_t qp_id;
1489 
1490 	/* Stop the device in case it's started so it can be configured */
1491 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1492 
1493 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1494 			&ts_params->conf),
1495 			"Failed to configure cryptodev %u",
1496 			ts_params->valid_devs[0]);
1497 
1498 	/*
1499 	 * Test various ring sizes on this device. memzones can't be
1500 	 * freed so are re-used if ring is released and re-created.
1501 	 */
1502 	qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1503 	qp_conf.mp_session = ts_params->session_mpool;
1504 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
1505 
1506 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1507 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1508 				ts_params->valid_devs[0], qp_id, &qp_conf,
1509 				rte_cryptodev_socket_id(
1510 						ts_params->valid_devs[0])),
1511 				"Failed test for "
1512 				"rte_cryptodev_queue_pair_setup: num_inflights "
1513 				"%u on qp %u on cryptodev %u",
1514 				qp_conf.nb_descriptors, qp_id,
1515 				ts_params->valid_devs[0]);
1516 	}
1517 
1518 	qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1519 
1520 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1521 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1522 				ts_params->valid_devs[0], qp_id, &qp_conf,
1523 				rte_cryptodev_socket_id(
1524 						ts_params->valid_devs[0])),
1525 				"Failed test for"
1526 				" rte_cryptodev_queue_pair_setup: num_inflights"
1527 				" %u on qp %u on cryptodev %u",
1528 				qp_conf.nb_descriptors, qp_id,
1529 				ts_params->valid_devs[0]);
1530 	}
1531 
1532 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
1533 
1534 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1535 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1536 				ts_params->valid_devs[0], qp_id, &qp_conf,
1537 				rte_cryptodev_socket_id(
1538 						ts_params->valid_devs[0])),
1539 				"Failed test for "
1540 				"rte_cryptodev_queue_pair_setup: num_inflights"
1541 				" %u on qp %u on cryptodev %u",
1542 				qp_conf.nb_descriptors, qp_id,
1543 				ts_params->valid_devs[0]);
1544 	}
1545 
1546 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1547 
1548 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1549 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1550 				ts_params->valid_devs[0], qp_id, &qp_conf,
1551 				rte_cryptodev_socket_id(
1552 						ts_params->valid_devs[0])),
1553 				"Failed test for"
1554 				" rte_cryptodev_queue_pair_setup:"
1555 				"num_inflights %u on qp %u on cryptodev %u",
1556 				qp_conf.nb_descriptors, qp_id,
1557 				ts_params->valid_devs[0]);
1558 	}
1559 
1560 	/* test invalid queue pair id */
1561 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;	/*valid */
1562 
1563 	qp_id = ts_params->conf.nb_queue_pairs;		/*invalid */
1564 
1565 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1566 			ts_params->valid_devs[0],
1567 			qp_id, &qp_conf,
1568 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1569 			"Failed test for rte_cryptodev_queue_pair_setup:"
1570 			"invalid qp %u on cryptodev %u",
1571 			qp_id, ts_params->valid_devs[0]);
1572 
1573 	qp_id = 0xffff; /*invalid*/
1574 
1575 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1576 			ts_params->valid_devs[0],
1577 			qp_id, &qp_conf,
1578 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1579 			"Failed test for rte_cryptodev_queue_pair_setup:"
1580 			"invalid qp %u on cryptodev %u",
1581 			qp_id, ts_params->valid_devs[0]);
1582 
1583 	return TEST_SUCCESS;
1584 }
1585 
1586 /* ***** Plaintext data for tests ***** */
1587 
1588 const char catch_22_quote_1[] =
1589 		"There was only one catch and that was Catch-22, which "
1590 		"specified that a concern for one's safety in the face of "
1591 		"dangers that were real and immediate was the process of a "
1592 		"rational mind. Orr was crazy and could be grounded. All he "
1593 		"had to do was ask; and as soon as he did, he would no longer "
1594 		"be crazy and would have to fly more missions. Orr would be "
1595 		"crazy to fly more missions and sane if he didn't, but if he "
1596 		"was sane he had to fly them. If he flew them he was crazy "
1597 		"and didn't have to; but if he didn't want to he was sane and "
1598 		"had to. Yossarian was moved very deeply by the absolute "
1599 		"simplicity of this clause of Catch-22 and let out a "
1600 		"respectful whistle. \"That's some catch, that Catch-22\", he "
1601 		"observed. \"It's the best there is,\" Doc Daneeka agreed.";
1602 
1603 const char catch_22_quote[] =
1604 		"What a lousy earth! He wondered how many people were "
1605 		"destitute that same night even in his own prosperous country, "
1606 		"how many homes were shanties, how many husbands were drunk "
1607 		"and wives socked, and how many children were bullied, abused, "
1608 		"or abandoned. How many families hungered for food they could "
1609 		"not afford to buy? How many hearts were broken? How many "
1610 		"suicides would take place that same night, how many people "
1611 		"would go insane? How many cockroaches and landlords would "
1612 		"triumph? How many winners were losers, successes failures, "
1613 		"and rich men poor men? How many wise guys were stupid? How "
1614 		"many happy endings were unhappy endings? How many honest men "
1615 		"were liars, brave men cowards, loyal men traitors, how many "
1616 		"sainted men were corrupt, how many people in positions of "
1617 		"trust had sold their souls to bodyguards, how many had never "
1618 		"had souls? How many straight-and-narrow paths were crooked "
1619 		"paths? How many best families were worst families and how "
1620 		"many good people were bad people? When you added them all up "
1621 		"and then subtracted, you might be left with only the children, "
1622 		"and perhaps with Albert Einstein and an old violinist or "
1623 		"sculptor somewhere.";
1624 
1625 #define QUOTE_480_BYTES		(480)
1626 #define QUOTE_512_BYTES		(512)
1627 #define QUOTE_768_BYTES		(768)
1628 #define QUOTE_1024_BYTES	(1024)
1629 
1630 
1631 
1632 /* ***** SHA1 Hash Tests ***** */
1633 
1634 #define HMAC_KEY_LENGTH_SHA1	(DIGEST_BYTE_LENGTH_SHA1)
1635 
1636 static uint8_t hmac_sha1_key[] = {
1637 	0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1638 	0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1639 	0xDE, 0xF4, 0xDE, 0xAD };
1640 
1641 /* ***** SHA224 Hash Tests ***** */
1642 
1643 #define HMAC_KEY_LENGTH_SHA224	(DIGEST_BYTE_LENGTH_SHA224)
1644 
1645 
1646 /* ***** AES-CBC Cipher Tests ***** */
1647 
1648 #define CIPHER_KEY_LENGTH_AES_CBC	(16)
1649 #define CIPHER_IV_LENGTH_AES_CBC	(CIPHER_KEY_LENGTH_AES_CBC)
1650 
1651 static uint8_t aes_cbc_key[] = {
1652 	0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1653 	0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1654 
1655 static uint8_t aes_cbc_iv[] = {
1656 	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1657 	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1658 
1659 
1660 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1661 
1662 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1663 	0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1664 	0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1665 	0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1666 	0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1667 	0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1668 	0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1669 	0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1670 	0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1671 	0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1672 	0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1673 	0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1674 	0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1675 	0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1676 	0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1677 	0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1678 	0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1679 	0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1680 	0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1681 	0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1682 	0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1683 	0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1684 	0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1685 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1686 	0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1687 	0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1688 	0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1689 	0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1690 	0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1691 	0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1692 	0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1693 	0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1694 	0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1695 	0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1696 	0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1697 	0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1698 	0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1699 	0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1700 	0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1701 	0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1702 	0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1703 	0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1704 	0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1705 	0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1706 	0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1707 	0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1708 	0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1709 	0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1710 	0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1711 	0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1712 	0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1713 	0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1714 	0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1715 	0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1716 	0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1717 	0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1718 	0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1719 	0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1720 	0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1721 	0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1722 	0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1723 	0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1724 	0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1725 	0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1726 	0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1727 };
1728 
1729 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1730 	0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1731 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1732 	0x18, 0x8c, 0x1d, 0x32
1733 };
1734 
1735 
1736 /* Multisession Vector context Test */
1737 /*Begin Session 0 */
1738 static uint8_t ms_aes_cbc_key0[] = {
1739 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1740 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1741 };
1742 
1743 static uint8_t ms_aes_cbc_iv0[] = {
1744 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1745 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1746 };
1747 
1748 static const uint8_t ms_aes_cbc_cipher0[] = {
1749 		0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1750 		0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1751 		0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1752 		0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1753 		0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1754 		0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1755 		0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1756 		0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1757 		0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1758 		0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1759 		0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1760 		0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1761 		0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1762 		0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1763 		0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1764 		0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1765 		0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1766 		0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1767 		0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1768 		0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1769 		0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1770 		0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1771 		0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1772 		0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1773 		0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1774 		0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1775 		0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1776 		0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1777 		0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1778 		0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1779 		0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1780 		0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1781 		0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1782 		0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1783 		0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1784 		0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1785 		0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1786 		0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1787 		0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1788 		0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1789 		0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1790 		0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1791 		0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1792 		0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1793 		0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1794 		0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1795 		0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1796 		0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1797 		0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1798 		0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1799 		0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1800 		0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1801 		0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1802 		0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1803 		0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1804 		0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1805 		0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1806 		0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1807 		0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1808 		0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1809 		0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1810 		0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1811 		0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1812 		0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1813 };
1814 
1815 
1816 static  uint8_t ms_hmac_key0[] = {
1817 		0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1818 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1819 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1820 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1821 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1822 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1823 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1824 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1825 };
1826 
1827 static const uint8_t ms_hmac_digest0[] = {
1828 		0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1829 		0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1830 		0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1831 		0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1832 		0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1833 		0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1834 		0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1835 		0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1836 		};
1837 
1838 /* End Session 0 */
1839 /* Begin session 1 */
1840 
1841 static  uint8_t ms_aes_cbc_key1[] = {
1842 		0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1843 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1844 };
1845 
1846 static  uint8_t ms_aes_cbc_iv1[] = {
1847 	0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1848 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1849 };
1850 
1851 static const uint8_t ms_aes_cbc_cipher1[] = {
1852 		0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1853 		0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1854 		0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1855 		0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1856 		0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1857 		0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1858 		0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1859 		0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1860 		0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1861 		0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1862 		0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1863 		0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1864 		0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1865 		0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1866 		0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1867 		0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1868 		0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1869 		0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1870 		0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1871 		0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1872 		0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1873 		0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1874 		0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1875 		0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1876 		0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1877 		0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1878 		0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1879 		0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1880 		0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1881 		0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1882 		0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1883 		0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1884 		0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1885 		0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1886 		0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1887 		0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1888 		0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1889 		0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1890 		0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1891 		0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1892 		0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1893 		0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1894 		0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1895 		0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1896 		0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1897 		0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1898 		0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1899 		0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1900 		0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1901 		0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1902 		0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1903 		0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1904 		0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1905 		0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1906 		0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1907 		0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1908 		0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1909 		0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1910 		0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1911 		0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1912 		0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1913 		0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1914 		0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1915 		0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1916 
1917 };
1918 
1919 static uint8_t ms_hmac_key1[] = {
1920 		0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1921 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1922 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1923 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1924 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1925 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1926 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1927 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1928 };
1929 
1930 static const uint8_t ms_hmac_digest1[] = {
1931 		0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1932 		0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
1933 		0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
1934 		0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
1935 		0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
1936 		0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
1937 		0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
1938 		0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
1939 };
1940 /* End Session 1  */
1941 /* Begin Session 2 */
1942 static  uint8_t ms_aes_cbc_key2[] = {
1943 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1944 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1945 };
1946 
1947 static  uint8_t ms_aes_cbc_iv2[] = {
1948 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1949 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1950 };
1951 
1952 static const uint8_t ms_aes_cbc_cipher2[] = {
1953 		0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
1954 		0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
1955 		0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
1956 		0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
1957 		0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
1958 		0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
1959 		0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
1960 		0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
1961 		0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
1962 		0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
1963 		0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
1964 		0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
1965 		0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
1966 		0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
1967 		0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
1968 		0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
1969 		0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
1970 		0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
1971 		0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
1972 		0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
1973 		0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
1974 		0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
1975 		0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
1976 		0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
1977 		0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
1978 		0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
1979 		0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
1980 		0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
1981 		0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
1982 		0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
1983 		0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
1984 		0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
1985 		0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
1986 		0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
1987 		0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
1988 		0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
1989 		0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
1990 		0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
1991 		0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
1992 		0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
1993 		0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
1994 		0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
1995 		0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
1996 		0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
1997 		0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
1998 		0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
1999 		0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
2000 		0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
2001 		0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
2002 		0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
2003 		0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
2004 		0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
2005 		0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
2006 		0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
2007 		0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
2008 		0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
2009 		0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
2010 		0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
2011 		0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
2012 		0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
2013 		0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
2014 		0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
2015 		0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
2016 		0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
2017 };
2018 
2019 static  uint8_t ms_hmac_key2[] = {
2020 		0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2021 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2022 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2023 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2024 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2025 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2026 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2027 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2028 };
2029 
2030 static const uint8_t ms_hmac_digest2[] = {
2031 		0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
2032 		0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
2033 		0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
2034 		0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
2035 		0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
2036 		0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
2037 		0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
2038 		0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
2039 };
2040 
2041 /* End Session 2 */
2042 
2043 
2044 static int
2045 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
2046 {
2047 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2048 	struct crypto_unittest_params *ut_params = &unittest_params;
2049 
2050 	/* Verify the capabilities */
2051 	struct rte_cryptodev_sym_capability_idx cap_idx;
2052 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2053 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
2054 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2055 			&cap_idx) == NULL)
2056 		return TEST_SKIPPED;
2057 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2058 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
2059 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2060 			&cap_idx) == NULL)
2061 		return TEST_SKIPPED;
2062 
2063 	/* Generate test mbuf data and space for digest */
2064 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2065 			catch_22_quote,	QUOTE_512_BYTES, 0);
2066 
2067 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2068 			DIGEST_BYTE_LENGTH_SHA1);
2069 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2070 
2071 	/* Setup Cipher Parameters */
2072 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2073 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2074 
2075 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2076 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2077 	ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2078 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2079 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2080 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2081 
2082 	/* Setup HMAC Parameters */
2083 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2084 
2085 	ut_params->auth_xform.next = NULL;
2086 
2087 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2088 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
2089 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
2090 	ut_params->auth_xform.auth.key.data = hmac_sha1_key;
2091 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
2092 
2093 	ut_params->sess = rte_cryptodev_sym_session_create(
2094 			ts_params->session_mpool);
2095 
2096 	/* Create crypto session*/
2097 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
2098 			ut_params->sess, &ut_params->cipher_xform,
2099 			ts_params->session_priv_mpool);
2100 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2101 
2102 	/* Generate crypto op data structure */
2103 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2104 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2105 	TEST_ASSERT_NOT_NULL(ut_params->op,
2106 			"Failed to allocate symmetric crypto operation struct");
2107 
2108 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2109 
2110 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2111 
2112 	/* set crypto operation source mbuf */
2113 	sym_op->m_src = ut_params->ibuf;
2114 
2115 	/* Set crypto operation authentication parameters */
2116 	sym_op->auth.digest.data = ut_params->digest;
2117 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2118 			ut_params->ibuf, QUOTE_512_BYTES);
2119 
2120 	sym_op->auth.data.offset = 0;
2121 	sym_op->auth.data.length = QUOTE_512_BYTES;
2122 
2123 	/* Copy IV at the end of the crypto operation */
2124 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2125 			aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
2126 
2127 	/* Set crypto operation cipher parameters */
2128 	sym_op->cipher.data.offset = 0;
2129 	sym_op->cipher.data.length = QUOTE_512_BYTES;
2130 
2131 	/* Process crypto operation */
2132 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2133 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2134 			ut_params->op);
2135 	else
2136 		TEST_ASSERT_NOT_NULL(
2137 			process_crypto_request(ts_params->valid_devs[0],
2138 				ut_params->op),
2139 				"failed to process sym crypto op");
2140 
2141 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2142 			"crypto op processing failed");
2143 
2144 	/* Validate obuf */
2145 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
2146 			uint8_t *);
2147 
2148 	TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
2149 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2150 			QUOTE_512_BYTES,
2151 			"ciphertext data not as expected");
2152 
2153 	uint8_t *digest = ciphertext + QUOTE_512_BYTES;
2154 
2155 	TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
2156 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
2157 			gbl_driver_id == rte_cryptodev_driver_id_get(
2158 					RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
2159 					TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
2160 					DIGEST_BYTE_LENGTH_SHA1,
2161 			"Generated digest data not as expected");
2162 
2163 	return TEST_SUCCESS;
2164 }
2165 
2166 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
2167 
2168 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
2169 
2170 static uint8_t hmac_sha512_key[] = {
2171 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
2172 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2173 	0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2174 	0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
2175 	0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
2176 	0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2177 	0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
2178 	0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
2179 
2180 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
2181 	0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
2182 	0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
2183 	0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
2184 	0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
2185 	0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
2186 	0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
2187 	0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
2188 	0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
2189 
2190 
2191 
2192 static int
2193 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2194 		struct crypto_unittest_params *ut_params,
2195 		uint8_t *cipher_key,
2196 		uint8_t *hmac_key);
2197 
2198 static int
2199 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2200 		struct crypto_unittest_params *ut_params,
2201 		struct crypto_testsuite_params *ts_params,
2202 		const uint8_t *cipher,
2203 		const uint8_t *digest,
2204 		const uint8_t *iv);
2205 
2206 
2207 static int
2208 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2209 		struct crypto_unittest_params *ut_params,
2210 		uint8_t *cipher_key,
2211 		uint8_t *hmac_key)
2212 {
2213 
2214 	/* Setup Cipher Parameters */
2215 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2216 	ut_params->cipher_xform.next = NULL;
2217 
2218 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2219 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
2220 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2221 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2222 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2223 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2224 
2225 	/* Setup HMAC Parameters */
2226 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2227 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2228 
2229 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
2230 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
2231 	ut_params->auth_xform.auth.key.data = hmac_key;
2232 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
2233 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
2234 
2235 	return TEST_SUCCESS;
2236 }
2237 
2238 
2239 static int
2240 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2241 		struct crypto_unittest_params *ut_params,
2242 		struct crypto_testsuite_params *ts_params,
2243 		const uint8_t *cipher,
2244 		const uint8_t *digest,
2245 		const uint8_t *iv)
2246 {
2247 	/* Generate test mbuf data and digest */
2248 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2249 			(const char *)
2250 			cipher,
2251 			QUOTE_512_BYTES, 0);
2252 
2253 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2254 			DIGEST_BYTE_LENGTH_SHA512);
2255 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2256 
2257 	rte_memcpy(ut_params->digest,
2258 			digest,
2259 			DIGEST_BYTE_LENGTH_SHA512);
2260 
2261 	/* Generate Crypto op data structure */
2262 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2263 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2264 	TEST_ASSERT_NOT_NULL(ut_params->op,
2265 			"Failed to allocate symmetric crypto operation struct");
2266 
2267 	rte_crypto_op_attach_sym_session(ut_params->op, sess);
2268 
2269 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2270 
2271 	/* set crypto operation source mbuf */
2272 	sym_op->m_src = ut_params->ibuf;
2273 
2274 	sym_op->auth.digest.data = ut_params->digest;
2275 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2276 			ut_params->ibuf, QUOTE_512_BYTES);
2277 
2278 	sym_op->auth.data.offset = 0;
2279 	sym_op->auth.data.length = QUOTE_512_BYTES;
2280 
2281 	/* Copy IV at the end of the crypto operation */
2282 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2283 			iv, CIPHER_IV_LENGTH_AES_CBC);
2284 
2285 	sym_op->cipher.data.offset = 0;
2286 	sym_op->cipher.data.length = QUOTE_512_BYTES;
2287 
2288 	/* Process crypto operation */
2289 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2290 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2291 			ut_params->op);
2292 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2293 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2294 				ut_params->op, 1, 1, 0, 0);
2295 	else
2296 		TEST_ASSERT_NOT_NULL(
2297 				process_crypto_request(ts_params->valid_devs[0],
2298 					ut_params->op),
2299 					"failed to process sym crypto op");
2300 
2301 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2302 			"crypto op processing failed");
2303 
2304 	ut_params->obuf = ut_params->op->sym->m_src;
2305 
2306 	/* Validate obuf */
2307 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
2308 			rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
2309 			catch_22_quote,
2310 			QUOTE_512_BYTES,
2311 			"Plaintext data not as expected");
2312 
2313 	/* Validate obuf */
2314 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2315 			"Digest verification failed");
2316 
2317 	return TEST_SUCCESS;
2318 }
2319 
2320 /* ***** SNOW 3G Tests ***** */
2321 static int
2322 create_wireless_algo_hash_session(uint8_t dev_id,
2323 	const uint8_t *key, const uint8_t key_len,
2324 	const uint8_t iv_len, const uint8_t auth_len,
2325 	enum rte_crypto_auth_operation op,
2326 	enum rte_crypto_auth_algorithm algo)
2327 {
2328 	uint8_t hash_key[key_len];
2329 	int status;
2330 
2331 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2332 	struct crypto_unittest_params *ut_params = &unittest_params;
2333 
2334 	memcpy(hash_key, key, key_len);
2335 
2336 	debug_hexdump(stdout, "key:", key, key_len);
2337 
2338 	/* Setup Authentication Parameters */
2339 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2340 	ut_params->auth_xform.next = NULL;
2341 
2342 	ut_params->auth_xform.auth.op = op;
2343 	ut_params->auth_xform.auth.algo = algo;
2344 	ut_params->auth_xform.auth.key.length = key_len;
2345 	ut_params->auth_xform.auth.key.data = hash_key;
2346 	ut_params->auth_xform.auth.digest_length = auth_len;
2347 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2348 	ut_params->auth_xform.auth.iv.length = iv_len;
2349 	ut_params->sess = rte_cryptodev_sym_session_create(
2350 			ts_params->session_mpool);
2351 
2352 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2353 			&ut_params->auth_xform,
2354 			ts_params->session_priv_mpool);
2355 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2356 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2357 	return 0;
2358 }
2359 
2360 static int
2361 create_wireless_algo_cipher_session(uint8_t dev_id,
2362 			enum rte_crypto_cipher_operation op,
2363 			enum rte_crypto_cipher_algorithm algo,
2364 			const uint8_t *key, const uint8_t key_len,
2365 			uint8_t iv_len)
2366 {
2367 	uint8_t cipher_key[key_len];
2368 	int status;
2369 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2370 	struct crypto_unittest_params *ut_params = &unittest_params;
2371 
2372 	memcpy(cipher_key, key, key_len);
2373 
2374 	/* Setup Cipher Parameters */
2375 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2376 	ut_params->cipher_xform.next = NULL;
2377 
2378 	ut_params->cipher_xform.cipher.algo = algo;
2379 	ut_params->cipher_xform.cipher.op = op;
2380 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2381 	ut_params->cipher_xform.cipher.key.length = key_len;
2382 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2383 	ut_params->cipher_xform.cipher.iv.length = iv_len;
2384 
2385 	debug_hexdump(stdout, "key:", key, key_len);
2386 
2387 	/* Create Crypto session */
2388 	ut_params->sess = rte_cryptodev_sym_session_create(
2389 			ts_params->session_mpool);
2390 
2391 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2392 			&ut_params->cipher_xform,
2393 			ts_params->session_priv_mpool);
2394 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2395 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2396 	return 0;
2397 }
2398 
2399 static int
2400 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2401 			unsigned int cipher_len,
2402 			unsigned int cipher_offset)
2403 {
2404 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2405 	struct crypto_unittest_params *ut_params = &unittest_params;
2406 
2407 	/* Generate Crypto op data structure */
2408 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2409 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2410 	TEST_ASSERT_NOT_NULL(ut_params->op,
2411 				"Failed to allocate pktmbuf offload");
2412 
2413 	/* Set crypto operation data parameters */
2414 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2415 
2416 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2417 
2418 	/* set crypto operation source mbuf */
2419 	sym_op->m_src = ut_params->ibuf;
2420 
2421 	/* iv */
2422 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2423 			iv, iv_len);
2424 	sym_op->cipher.data.length = cipher_len;
2425 	sym_op->cipher.data.offset = cipher_offset;
2426 	return 0;
2427 }
2428 
2429 static int
2430 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2431 			unsigned int cipher_len,
2432 			unsigned int cipher_offset)
2433 {
2434 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2435 	struct crypto_unittest_params *ut_params = &unittest_params;
2436 
2437 	/* Generate Crypto op data structure */
2438 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2439 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2440 	TEST_ASSERT_NOT_NULL(ut_params->op,
2441 				"Failed to allocate pktmbuf offload");
2442 
2443 	/* Set crypto operation data parameters */
2444 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2445 
2446 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2447 
2448 	/* set crypto operation source mbuf */
2449 	sym_op->m_src = ut_params->ibuf;
2450 	sym_op->m_dst = ut_params->obuf;
2451 
2452 	/* iv */
2453 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2454 			iv, iv_len);
2455 	sym_op->cipher.data.length = cipher_len;
2456 	sym_op->cipher.data.offset = cipher_offset;
2457 	return 0;
2458 }
2459 
2460 static int
2461 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2462 		enum rte_crypto_cipher_operation cipher_op,
2463 		enum rte_crypto_auth_operation auth_op,
2464 		enum rte_crypto_auth_algorithm auth_algo,
2465 		enum rte_crypto_cipher_algorithm cipher_algo,
2466 		const uint8_t *key, uint8_t key_len,
2467 		uint8_t auth_iv_len, uint8_t auth_len,
2468 		uint8_t cipher_iv_len)
2469 
2470 {
2471 	uint8_t cipher_auth_key[key_len];
2472 	int status;
2473 
2474 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2475 	struct crypto_unittest_params *ut_params = &unittest_params;
2476 
2477 	memcpy(cipher_auth_key, key, key_len);
2478 
2479 	/* Setup Authentication Parameters */
2480 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2481 	ut_params->auth_xform.next = NULL;
2482 
2483 	ut_params->auth_xform.auth.op = auth_op;
2484 	ut_params->auth_xform.auth.algo = auth_algo;
2485 	ut_params->auth_xform.auth.key.length = key_len;
2486 	/* Hash key = cipher key */
2487 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2488 	ut_params->auth_xform.auth.digest_length = auth_len;
2489 	/* Auth IV will be after cipher IV */
2490 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2491 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2492 
2493 	/* Setup Cipher Parameters */
2494 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2495 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2496 
2497 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2498 	ut_params->cipher_xform.cipher.op = cipher_op;
2499 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2500 	ut_params->cipher_xform.cipher.key.length = key_len;
2501 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2502 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2503 
2504 	debug_hexdump(stdout, "key:", key, key_len);
2505 
2506 	/* Create Crypto session*/
2507 	ut_params->sess = rte_cryptodev_sym_session_create(
2508 			ts_params->session_mpool);
2509 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2510 
2511 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2512 			&ut_params->cipher_xform,
2513 			ts_params->session_priv_mpool);
2514 	if (status == -ENOTSUP)
2515 		return TEST_SKIPPED;
2516 
2517 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2518 	return 0;
2519 }
2520 
2521 static int
2522 create_wireless_cipher_auth_session(uint8_t dev_id,
2523 		enum rte_crypto_cipher_operation cipher_op,
2524 		enum rte_crypto_auth_operation auth_op,
2525 		enum rte_crypto_auth_algorithm auth_algo,
2526 		enum rte_crypto_cipher_algorithm cipher_algo,
2527 		const struct wireless_test_data *tdata)
2528 {
2529 	const uint8_t key_len = tdata->key.len;
2530 	uint8_t cipher_auth_key[key_len];
2531 	int status;
2532 
2533 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2534 	struct crypto_unittest_params *ut_params = &unittest_params;
2535 	const uint8_t *key = tdata->key.data;
2536 	const uint8_t auth_len = tdata->digest.len;
2537 	uint8_t cipher_iv_len = tdata->cipher_iv.len;
2538 	uint8_t auth_iv_len = tdata->auth_iv.len;
2539 
2540 	memcpy(cipher_auth_key, key, key_len);
2541 
2542 	/* Setup Authentication Parameters */
2543 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2544 	ut_params->auth_xform.next = NULL;
2545 
2546 	ut_params->auth_xform.auth.op = auth_op;
2547 	ut_params->auth_xform.auth.algo = auth_algo;
2548 	ut_params->auth_xform.auth.key.length = key_len;
2549 	/* Hash key = cipher key */
2550 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2551 	ut_params->auth_xform.auth.digest_length = auth_len;
2552 	/* Auth IV will be after cipher IV */
2553 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2554 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2555 
2556 	/* Setup Cipher Parameters */
2557 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2558 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2559 
2560 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2561 	ut_params->cipher_xform.cipher.op = cipher_op;
2562 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2563 	ut_params->cipher_xform.cipher.key.length = key_len;
2564 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2565 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2566 
2567 
2568 	debug_hexdump(stdout, "key:", key, key_len);
2569 
2570 	/* Create Crypto session*/
2571 	ut_params->sess = rte_cryptodev_sym_session_create(
2572 			ts_params->session_mpool);
2573 
2574 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2575 			&ut_params->cipher_xform,
2576 			ts_params->session_priv_mpool);
2577 	if (status == -ENOTSUP)
2578 		return TEST_SKIPPED;
2579 
2580 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2581 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2582 	return 0;
2583 }
2584 
2585 static int
2586 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2587 		const struct wireless_test_data *tdata)
2588 {
2589 	return create_wireless_cipher_auth_session(dev_id,
2590 		RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2591 		RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2592 		RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2593 }
2594 
2595 static int
2596 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2597 		enum rte_crypto_cipher_operation cipher_op,
2598 		enum rte_crypto_auth_operation auth_op,
2599 		enum rte_crypto_auth_algorithm auth_algo,
2600 		enum rte_crypto_cipher_algorithm cipher_algo,
2601 		const uint8_t *key, const uint8_t key_len,
2602 		uint8_t auth_iv_len, uint8_t auth_len,
2603 		uint8_t cipher_iv_len)
2604 {
2605 	uint8_t auth_cipher_key[key_len];
2606 	int status;
2607 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2608 	struct crypto_unittest_params *ut_params = &unittest_params;
2609 
2610 	memcpy(auth_cipher_key, key, key_len);
2611 
2612 	/* Setup Authentication Parameters */
2613 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2614 	ut_params->auth_xform.auth.op = auth_op;
2615 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2616 	ut_params->auth_xform.auth.algo = auth_algo;
2617 	ut_params->auth_xform.auth.key.length = key_len;
2618 	ut_params->auth_xform.auth.key.data = auth_cipher_key;
2619 	ut_params->auth_xform.auth.digest_length = auth_len;
2620 	/* Auth IV will be after cipher IV */
2621 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2622 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2623 
2624 	/* Setup Cipher Parameters */
2625 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2626 	ut_params->cipher_xform.next = NULL;
2627 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2628 	ut_params->cipher_xform.cipher.op = cipher_op;
2629 	ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2630 	ut_params->cipher_xform.cipher.key.length = key_len;
2631 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2632 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2633 
2634 	debug_hexdump(stdout, "key:", key, key_len);
2635 
2636 	/* Create Crypto session*/
2637 	ut_params->sess = rte_cryptodev_sym_session_create(
2638 			ts_params->session_mpool);
2639 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2640 
2641 	if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2642 		ut_params->auth_xform.next = NULL;
2643 		ut_params->cipher_xform.next = &ut_params->auth_xform;
2644 		status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2645 				&ut_params->cipher_xform,
2646 				ts_params->session_priv_mpool);
2647 
2648 	} else
2649 		status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2650 				&ut_params->auth_xform,
2651 				ts_params->session_priv_mpool);
2652 
2653 	if (status == -ENOTSUP)
2654 		return TEST_SKIPPED;
2655 
2656 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2657 
2658 	return 0;
2659 }
2660 
2661 static int
2662 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2663 		unsigned int auth_tag_len,
2664 		const uint8_t *iv, unsigned int iv_len,
2665 		unsigned int data_pad_len,
2666 		enum rte_crypto_auth_operation op,
2667 		unsigned int auth_len, unsigned int auth_offset)
2668 {
2669 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2670 
2671 	struct crypto_unittest_params *ut_params = &unittest_params;
2672 
2673 	/* Generate Crypto op data structure */
2674 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2675 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2676 	TEST_ASSERT_NOT_NULL(ut_params->op,
2677 		"Failed to allocate pktmbuf offload");
2678 
2679 	/* Set crypto operation data parameters */
2680 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2681 
2682 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2683 
2684 	/* set crypto operation source mbuf */
2685 	sym_op->m_src = ut_params->ibuf;
2686 
2687 	/* iv */
2688 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2689 			iv, iv_len);
2690 	/* digest */
2691 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2692 					ut_params->ibuf, auth_tag_len);
2693 
2694 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2695 				"no room to append auth tag");
2696 	ut_params->digest = sym_op->auth.digest.data;
2697 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2698 			ut_params->ibuf, data_pad_len);
2699 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2700 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2701 	else
2702 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2703 
2704 	debug_hexdump(stdout, "digest:",
2705 		sym_op->auth.digest.data,
2706 		auth_tag_len);
2707 
2708 	sym_op->auth.data.length = auth_len;
2709 	sym_op->auth.data.offset = auth_offset;
2710 
2711 	return 0;
2712 }
2713 
2714 static int
2715 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2716 	enum rte_crypto_auth_operation op)
2717 {
2718 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2719 	struct crypto_unittest_params *ut_params = &unittest_params;
2720 
2721 	const uint8_t *auth_tag = tdata->digest.data;
2722 	const unsigned int auth_tag_len = tdata->digest.len;
2723 	unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2724 	unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2725 
2726 	const uint8_t *cipher_iv = tdata->cipher_iv.data;
2727 	const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2728 	const uint8_t *auth_iv = tdata->auth_iv.data;
2729 	const uint8_t auth_iv_len = tdata->auth_iv.len;
2730 	const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2731 	const unsigned int auth_len = tdata->validAuthLenInBits.len;
2732 
2733 	/* Generate Crypto op data structure */
2734 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2735 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2736 	TEST_ASSERT_NOT_NULL(ut_params->op,
2737 			"Failed to allocate pktmbuf offload");
2738 	/* Set crypto operation data parameters */
2739 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2740 
2741 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2742 
2743 	/* set crypto operation source mbuf */
2744 	sym_op->m_src = ut_params->ibuf;
2745 
2746 	/* digest */
2747 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2748 			ut_params->ibuf, auth_tag_len);
2749 
2750 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2751 			"no room to append auth tag");
2752 	ut_params->digest = sym_op->auth.digest.data;
2753 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2754 			ut_params->ibuf, data_pad_len);
2755 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2756 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2757 	else
2758 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2759 
2760 	debug_hexdump(stdout, "digest:",
2761 		sym_op->auth.digest.data,
2762 		auth_tag_len);
2763 
2764 	/* Copy cipher and auth IVs at the end of the crypto operation */
2765 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2766 						IV_OFFSET);
2767 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2768 	iv_ptr += cipher_iv_len;
2769 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2770 
2771 	sym_op->cipher.data.length = cipher_len;
2772 	sym_op->cipher.data.offset = 0;
2773 	sym_op->auth.data.length = auth_len;
2774 	sym_op->auth.data.offset = 0;
2775 
2776 	return 0;
2777 }
2778 
2779 static int
2780 create_zuc_cipher_hash_generate_operation(
2781 		const struct wireless_test_data *tdata)
2782 {
2783 	return create_wireless_cipher_hash_operation(tdata,
2784 		RTE_CRYPTO_AUTH_OP_GENERATE);
2785 }
2786 
2787 static int
2788 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2789 		const unsigned auth_tag_len,
2790 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2791 		unsigned data_pad_len,
2792 		enum rte_crypto_auth_operation op,
2793 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2794 		const unsigned cipher_len, const unsigned cipher_offset,
2795 		const unsigned auth_len, const unsigned auth_offset)
2796 {
2797 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2798 	struct crypto_unittest_params *ut_params = &unittest_params;
2799 
2800 	enum rte_crypto_cipher_algorithm cipher_algo =
2801 			ut_params->cipher_xform.cipher.algo;
2802 	enum rte_crypto_auth_algorithm auth_algo =
2803 			ut_params->auth_xform.auth.algo;
2804 
2805 	/* Generate Crypto op data structure */
2806 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2807 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2808 	TEST_ASSERT_NOT_NULL(ut_params->op,
2809 			"Failed to allocate pktmbuf offload");
2810 	/* Set crypto operation data parameters */
2811 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2812 
2813 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2814 
2815 	/* set crypto operation source mbuf */
2816 	sym_op->m_src = ut_params->ibuf;
2817 
2818 	/* digest */
2819 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2820 			ut_params->ibuf, auth_tag_len);
2821 
2822 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2823 			"no room to append auth tag");
2824 	ut_params->digest = sym_op->auth.digest.data;
2825 
2826 	if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2827 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2828 				ut_params->ibuf, data_pad_len);
2829 	} else {
2830 		struct rte_mbuf *m = ut_params->ibuf;
2831 		unsigned int offset = data_pad_len;
2832 
2833 		while (offset > m->data_len && m->next != NULL) {
2834 			offset -= m->data_len;
2835 			m = m->next;
2836 		}
2837 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2838 			m, offset);
2839 	}
2840 
2841 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2842 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2843 	else
2844 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2845 
2846 	debug_hexdump(stdout, "digest:",
2847 		sym_op->auth.digest.data,
2848 		auth_tag_len);
2849 
2850 	/* Copy cipher and auth IVs at the end of the crypto operation */
2851 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2852 						IV_OFFSET);
2853 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2854 	iv_ptr += cipher_iv_len;
2855 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2856 
2857 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2858 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2859 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2860 		sym_op->cipher.data.length = cipher_len;
2861 		sym_op->cipher.data.offset = cipher_offset;
2862 	} else {
2863 		sym_op->cipher.data.length = cipher_len >> 3;
2864 		sym_op->cipher.data.offset = cipher_offset >> 3;
2865 	}
2866 
2867 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2868 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2869 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2870 		sym_op->auth.data.length = auth_len;
2871 		sym_op->auth.data.offset = auth_offset;
2872 	} else {
2873 		sym_op->auth.data.length = auth_len >> 3;
2874 		sym_op->auth.data.offset = auth_offset >> 3;
2875 	}
2876 
2877 	return 0;
2878 }
2879 
2880 static int
2881 create_wireless_algo_auth_cipher_operation(
2882 		const uint8_t *auth_tag, unsigned int auth_tag_len,
2883 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2884 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2885 		unsigned int data_pad_len,
2886 		unsigned int cipher_len, unsigned int cipher_offset,
2887 		unsigned int auth_len, unsigned int auth_offset,
2888 		uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2889 {
2890 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2891 	struct crypto_unittest_params *ut_params = &unittest_params;
2892 
2893 	enum rte_crypto_cipher_algorithm cipher_algo =
2894 			ut_params->cipher_xform.cipher.algo;
2895 	enum rte_crypto_auth_algorithm auth_algo =
2896 			ut_params->auth_xform.auth.algo;
2897 
2898 	/* Generate Crypto op data structure */
2899 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2900 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2901 	TEST_ASSERT_NOT_NULL(ut_params->op,
2902 			"Failed to allocate pktmbuf offload");
2903 
2904 	/* Set crypto operation data parameters */
2905 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2906 
2907 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2908 
2909 	/* set crypto operation mbufs */
2910 	sym_op->m_src = ut_params->ibuf;
2911 	if (op_mode == OUT_OF_PLACE)
2912 		sym_op->m_dst = ut_params->obuf;
2913 
2914 	/* digest */
2915 	if (!do_sgl) {
2916 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
2917 			(op_mode == IN_PLACE ?
2918 				ut_params->ibuf : ut_params->obuf),
2919 			uint8_t *, data_pad_len);
2920 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2921 			(op_mode == IN_PLACE ?
2922 				ut_params->ibuf : ut_params->obuf),
2923 			data_pad_len);
2924 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2925 	} else {
2926 		uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
2927 		struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
2928 				sym_op->m_src : sym_op->m_dst);
2929 		while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
2930 			remaining_off -= rte_pktmbuf_data_len(sgl_buf);
2931 			sgl_buf = sgl_buf->next;
2932 		}
2933 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
2934 				uint8_t *, remaining_off);
2935 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
2936 				remaining_off);
2937 		memset(sym_op->auth.digest.data, 0, remaining_off);
2938 		while (sgl_buf->next != NULL) {
2939 			memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
2940 				0, rte_pktmbuf_data_len(sgl_buf));
2941 			sgl_buf = sgl_buf->next;
2942 		}
2943 	}
2944 
2945 	/* Copy digest for the verification */
2946 	if (verify)
2947 		memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2948 
2949 	/* Copy cipher and auth IVs at the end of the crypto operation */
2950 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
2951 			ut_params->op, uint8_t *, IV_OFFSET);
2952 
2953 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2954 	iv_ptr += cipher_iv_len;
2955 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2956 
2957 	/* Only copy over the offset data needed from src to dst in OOP,
2958 	 * if the auth and cipher offsets are not aligned
2959 	 */
2960 	if (op_mode == OUT_OF_PLACE) {
2961 		if (cipher_offset > auth_offset)
2962 			rte_memcpy(
2963 				rte_pktmbuf_mtod_offset(
2964 					sym_op->m_dst,
2965 					uint8_t *, auth_offset >> 3),
2966 				rte_pktmbuf_mtod_offset(
2967 					sym_op->m_src,
2968 					uint8_t *, auth_offset >> 3),
2969 				((cipher_offset >> 3) - (auth_offset >> 3)));
2970 	}
2971 
2972 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2973 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2974 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2975 		sym_op->cipher.data.length = cipher_len;
2976 		sym_op->cipher.data.offset = cipher_offset;
2977 	} else {
2978 		sym_op->cipher.data.length = cipher_len >> 3;
2979 		sym_op->cipher.data.offset = cipher_offset >> 3;
2980 	}
2981 
2982 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2983 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2984 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2985 		sym_op->auth.data.length = auth_len;
2986 		sym_op->auth.data.offset = auth_offset;
2987 	} else {
2988 		sym_op->auth.data.length = auth_len >> 3;
2989 		sym_op->auth.data.offset = auth_offset >> 3;
2990 	}
2991 
2992 	return 0;
2993 }
2994 
2995 static int
2996 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2997 {
2998 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2999 	struct crypto_unittest_params *ut_params = &unittest_params;
3000 
3001 	int retval;
3002 	unsigned plaintext_pad_len;
3003 	unsigned plaintext_len;
3004 	uint8_t *plaintext;
3005 	struct rte_cryptodev_info dev_info;
3006 
3007 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3008 	uint64_t feat_flags = dev_info.feature_flags;
3009 
3010 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3011 			((tdata->validAuthLenInBits.len % 8) != 0)) {
3012 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3013 		return TEST_SKIPPED;
3014 	}
3015 
3016 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3017 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3018 		printf("Device doesn't support RAW data-path APIs.\n");
3019 		return TEST_SKIPPED;
3020 	}
3021 
3022 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3023 		return TEST_SKIPPED;
3024 
3025 	/* Verify the capabilities */
3026 	struct rte_cryptodev_sym_capability_idx cap_idx;
3027 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3028 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3029 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3030 			&cap_idx) == NULL)
3031 		return TEST_SKIPPED;
3032 
3033 	/* Create SNOW 3G session */
3034 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3035 			tdata->key.data, tdata->key.len,
3036 			tdata->auth_iv.len, tdata->digest.len,
3037 			RTE_CRYPTO_AUTH_OP_GENERATE,
3038 			RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3039 	if (retval < 0)
3040 		return retval;
3041 
3042 	/* alloc mbuf and set payload */
3043 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3044 
3045 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3046 	rte_pktmbuf_tailroom(ut_params->ibuf));
3047 
3048 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3049 	/* Append data which is padded to a multiple of */
3050 	/* the algorithms block size */
3051 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3052 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3053 				plaintext_pad_len);
3054 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3055 
3056 	/* Create SNOW 3G operation */
3057 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3058 			tdata->auth_iv.data, tdata->auth_iv.len,
3059 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3060 			tdata->validAuthLenInBits.len,
3061 			0);
3062 	if (retval < 0)
3063 		return retval;
3064 
3065 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3066 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3067 				ut_params->op, 0, 1, 1, 0);
3068 	else
3069 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3070 				ut_params->op);
3071 	ut_params->obuf = ut_params->op->sym->m_src;
3072 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3073 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3074 			+ plaintext_pad_len;
3075 
3076 	/* Validate obuf */
3077 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3078 	ut_params->digest,
3079 	tdata->digest.data,
3080 	DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3081 	"SNOW 3G Generated auth tag not as expected");
3082 
3083 	return 0;
3084 }
3085 
3086 static int
3087 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
3088 {
3089 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3090 	struct crypto_unittest_params *ut_params = &unittest_params;
3091 
3092 	int retval;
3093 	unsigned plaintext_pad_len;
3094 	unsigned plaintext_len;
3095 	uint8_t *plaintext;
3096 	struct rte_cryptodev_info dev_info;
3097 
3098 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3099 	uint64_t feat_flags = dev_info.feature_flags;
3100 
3101 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3102 			((tdata->validAuthLenInBits.len % 8) != 0)) {
3103 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3104 		return TEST_SKIPPED;
3105 	}
3106 
3107 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3108 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3109 		printf("Device doesn't support RAW data-path APIs.\n");
3110 		return TEST_SKIPPED;
3111 	}
3112 
3113 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3114 		return TEST_SKIPPED;
3115 
3116 	/* Verify the capabilities */
3117 	struct rte_cryptodev_sym_capability_idx cap_idx;
3118 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3119 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3120 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3121 			&cap_idx) == NULL)
3122 		return TEST_SKIPPED;
3123 
3124 	/* Create SNOW 3G session */
3125 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3126 				tdata->key.data, tdata->key.len,
3127 				tdata->auth_iv.len, tdata->digest.len,
3128 				RTE_CRYPTO_AUTH_OP_VERIFY,
3129 				RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3130 	if (retval < 0)
3131 		return retval;
3132 	/* alloc mbuf and set payload */
3133 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3134 
3135 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3136 	rte_pktmbuf_tailroom(ut_params->ibuf));
3137 
3138 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3139 	/* Append data which is padded to a multiple of */
3140 	/* the algorithms block size */
3141 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3142 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3143 				plaintext_pad_len);
3144 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3145 
3146 	/* Create SNOW 3G operation */
3147 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
3148 			tdata->digest.len,
3149 			tdata->auth_iv.data, tdata->auth_iv.len,
3150 			plaintext_pad_len,
3151 			RTE_CRYPTO_AUTH_OP_VERIFY,
3152 			tdata->validAuthLenInBits.len,
3153 			0);
3154 	if (retval < 0)
3155 		return retval;
3156 
3157 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3158 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3159 				ut_params->op, 0, 1, 1, 0);
3160 	else
3161 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3162 				ut_params->op);
3163 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3164 	ut_params->obuf = ut_params->op->sym->m_src;
3165 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3166 				+ plaintext_pad_len;
3167 
3168 	/* Validate obuf */
3169 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3170 		return 0;
3171 	else
3172 		return -1;
3173 
3174 	return 0;
3175 }
3176 
3177 static int
3178 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
3179 {
3180 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3181 	struct crypto_unittest_params *ut_params = &unittest_params;
3182 
3183 	int retval;
3184 	unsigned plaintext_pad_len;
3185 	unsigned plaintext_len;
3186 	uint8_t *plaintext;
3187 	struct rte_cryptodev_info dev_info;
3188 
3189 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3190 	uint64_t feat_flags = dev_info.feature_flags;
3191 
3192 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3193 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3194 		printf("Device doesn't support RAW data-path APIs.\n");
3195 		return TEST_SKIPPED;
3196 	}
3197 
3198 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3199 		return TEST_SKIPPED;
3200 
3201 	/* Verify the capabilities */
3202 	struct rte_cryptodev_sym_capability_idx cap_idx;
3203 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3204 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3205 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3206 			&cap_idx) == NULL)
3207 		return TEST_SKIPPED;
3208 
3209 	/* Create KASUMI session */
3210 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3211 			tdata->key.data, tdata->key.len,
3212 			0, tdata->digest.len,
3213 			RTE_CRYPTO_AUTH_OP_GENERATE,
3214 			RTE_CRYPTO_AUTH_KASUMI_F9);
3215 	if (retval < 0)
3216 		return retval;
3217 
3218 	/* alloc mbuf and set payload */
3219 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3220 
3221 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3222 	rte_pktmbuf_tailroom(ut_params->ibuf));
3223 
3224 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3225 	/* Append data which is padded to a multiple of */
3226 	/* the algorithms block size */
3227 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3228 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3229 				plaintext_pad_len);
3230 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3231 
3232 	/* Create KASUMI operation */
3233 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3234 			NULL, 0,
3235 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3236 			tdata->plaintext.len,
3237 			0);
3238 	if (retval < 0)
3239 		return retval;
3240 
3241 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3242 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
3243 			ut_params->op);
3244 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3245 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3246 				ut_params->op, 0, 1, 1, 0);
3247 	else
3248 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3249 			ut_params->op);
3250 
3251 	ut_params->obuf = ut_params->op->sym->m_src;
3252 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3253 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3254 			+ plaintext_pad_len;
3255 
3256 	/* Validate obuf */
3257 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3258 	ut_params->digest,
3259 	tdata->digest.data,
3260 	DIGEST_BYTE_LENGTH_KASUMI_F9,
3261 	"KASUMI Generated auth tag not as expected");
3262 
3263 	return 0;
3264 }
3265 
3266 static int
3267 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
3268 {
3269 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3270 	struct crypto_unittest_params *ut_params = &unittest_params;
3271 
3272 	int retval;
3273 	unsigned plaintext_pad_len;
3274 	unsigned plaintext_len;
3275 	uint8_t *plaintext;
3276 	struct rte_cryptodev_info dev_info;
3277 
3278 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3279 	uint64_t feat_flags = dev_info.feature_flags;
3280 
3281 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3282 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3283 		printf("Device doesn't support RAW data-path APIs.\n");
3284 		return TEST_SKIPPED;
3285 	}
3286 
3287 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3288 		return TEST_SKIPPED;
3289 
3290 	/* Verify the capabilities */
3291 	struct rte_cryptodev_sym_capability_idx cap_idx;
3292 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3293 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3294 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3295 			&cap_idx) == NULL)
3296 		return TEST_SKIPPED;
3297 
3298 	/* Create KASUMI session */
3299 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3300 				tdata->key.data, tdata->key.len,
3301 				0, tdata->digest.len,
3302 				RTE_CRYPTO_AUTH_OP_VERIFY,
3303 				RTE_CRYPTO_AUTH_KASUMI_F9);
3304 	if (retval < 0)
3305 		return retval;
3306 	/* alloc mbuf and set payload */
3307 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3308 
3309 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3310 	rte_pktmbuf_tailroom(ut_params->ibuf));
3311 
3312 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3313 	/* Append data which is padded to a multiple */
3314 	/* of the algorithms block size */
3315 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3316 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3317 				plaintext_pad_len);
3318 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3319 
3320 	/* Create KASUMI operation */
3321 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
3322 			tdata->digest.len,
3323 			NULL, 0,
3324 			plaintext_pad_len,
3325 			RTE_CRYPTO_AUTH_OP_VERIFY,
3326 			tdata->plaintext.len,
3327 			0);
3328 	if (retval < 0)
3329 		return retval;
3330 
3331 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3332 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3333 				ut_params->op, 0, 1, 1, 0);
3334 	else
3335 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3336 				ut_params->op);
3337 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3338 	ut_params->obuf = ut_params->op->sym->m_src;
3339 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3340 				+ plaintext_pad_len;
3341 
3342 	/* Validate obuf */
3343 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3344 		return 0;
3345 	else
3346 		return -1;
3347 
3348 	return 0;
3349 }
3350 
3351 static int
3352 test_snow3g_hash_generate_test_case_1(void)
3353 {
3354 	return test_snow3g_authentication(&snow3g_hash_test_case_1);
3355 }
3356 
3357 static int
3358 test_snow3g_hash_generate_test_case_2(void)
3359 {
3360 	return test_snow3g_authentication(&snow3g_hash_test_case_2);
3361 }
3362 
3363 static int
3364 test_snow3g_hash_generate_test_case_3(void)
3365 {
3366 	return test_snow3g_authentication(&snow3g_hash_test_case_3);
3367 }
3368 
3369 static int
3370 test_snow3g_hash_generate_test_case_4(void)
3371 {
3372 	return test_snow3g_authentication(&snow3g_hash_test_case_4);
3373 }
3374 
3375 static int
3376 test_snow3g_hash_generate_test_case_5(void)
3377 {
3378 	return test_snow3g_authentication(&snow3g_hash_test_case_5);
3379 }
3380 
3381 static int
3382 test_snow3g_hash_generate_test_case_6(void)
3383 {
3384 	return test_snow3g_authentication(&snow3g_hash_test_case_6);
3385 }
3386 
3387 static int
3388 test_snow3g_hash_verify_test_case_1(void)
3389 {
3390 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3391 
3392 }
3393 
3394 static int
3395 test_snow3g_hash_verify_test_case_2(void)
3396 {
3397 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3398 }
3399 
3400 static int
3401 test_snow3g_hash_verify_test_case_3(void)
3402 {
3403 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3404 }
3405 
3406 static int
3407 test_snow3g_hash_verify_test_case_4(void)
3408 {
3409 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3410 }
3411 
3412 static int
3413 test_snow3g_hash_verify_test_case_5(void)
3414 {
3415 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3416 }
3417 
3418 static int
3419 test_snow3g_hash_verify_test_case_6(void)
3420 {
3421 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3422 }
3423 
3424 static int
3425 test_kasumi_hash_generate_test_case_1(void)
3426 {
3427 	return test_kasumi_authentication(&kasumi_hash_test_case_1);
3428 }
3429 
3430 static int
3431 test_kasumi_hash_generate_test_case_2(void)
3432 {
3433 	return test_kasumi_authentication(&kasumi_hash_test_case_2);
3434 }
3435 
3436 static int
3437 test_kasumi_hash_generate_test_case_3(void)
3438 {
3439 	return test_kasumi_authentication(&kasumi_hash_test_case_3);
3440 }
3441 
3442 static int
3443 test_kasumi_hash_generate_test_case_4(void)
3444 {
3445 	return test_kasumi_authentication(&kasumi_hash_test_case_4);
3446 }
3447 
3448 static int
3449 test_kasumi_hash_generate_test_case_5(void)
3450 {
3451 	return test_kasumi_authentication(&kasumi_hash_test_case_5);
3452 }
3453 
3454 static int
3455 test_kasumi_hash_generate_test_case_6(void)
3456 {
3457 	return test_kasumi_authentication(&kasumi_hash_test_case_6);
3458 }
3459 
3460 static int
3461 test_kasumi_hash_verify_test_case_1(void)
3462 {
3463 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3464 }
3465 
3466 static int
3467 test_kasumi_hash_verify_test_case_2(void)
3468 {
3469 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3470 }
3471 
3472 static int
3473 test_kasumi_hash_verify_test_case_3(void)
3474 {
3475 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3476 }
3477 
3478 static int
3479 test_kasumi_hash_verify_test_case_4(void)
3480 {
3481 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3482 }
3483 
3484 static int
3485 test_kasumi_hash_verify_test_case_5(void)
3486 {
3487 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3488 }
3489 
3490 static int
3491 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3492 {
3493 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3494 	struct crypto_unittest_params *ut_params = &unittest_params;
3495 
3496 	int retval;
3497 	uint8_t *plaintext, *ciphertext;
3498 	unsigned plaintext_pad_len;
3499 	unsigned plaintext_len;
3500 	struct rte_cryptodev_info dev_info;
3501 
3502 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3503 	uint64_t feat_flags = dev_info.feature_flags;
3504 
3505 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3506 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3507 		printf("Device doesn't support RAW data-path APIs.\n");
3508 		return TEST_SKIPPED;
3509 	}
3510 
3511 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3512 		return TEST_SKIPPED;
3513 
3514 	/* Verify the capabilities */
3515 	struct rte_cryptodev_sym_capability_idx cap_idx;
3516 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3517 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3518 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3519 			&cap_idx) == NULL)
3520 		return TEST_SKIPPED;
3521 
3522 	/* Create KASUMI session */
3523 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3524 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3525 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3526 					tdata->key.data, tdata->key.len,
3527 					tdata->cipher_iv.len);
3528 	if (retval < 0)
3529 		return retval;
3530 
3531 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3532 
3533 	/* Clear mbuf payload */
3534 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3535 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3536 
3537 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3538 	/* Append data which is padded to a multiple */
3539 	/* of the algorithms block size */
3540 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3541 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3542 				plaintext_pad_len);
3543 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3544 
3545 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3546 
3547 	/* Create KASUMI operation */
3548 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3549 				tdata->cipher_iv.len,
3550 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3551 				tdata->validCipherOffsetInBits.len);
3552 	if (retval < 0)
3553 		return retval;
3554 
3555 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3556 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3557 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3558 	else
3559 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3560 				ut_params->op);
3561 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3562 
3563 	ut_params->obuf = ut_params->op->sym->m_dst;
3564 	if (ut_params->obuf)
3565 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3566 	else
3567 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3568 
3569 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3570 
3571 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3572 				(tdata->validCipherOffsetInBits.len >> 3);
3573 	/* Validate obuf */
3574 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3575 		ciphertext,
3576 		reference_ciphertext,
3577 		tdata->validCipherLenInBits.len,
3578 		"KASUMI Ciphertext data not as expected");
3579 	return 0;
3580 }
3581 
3582 static int
3583 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3584 {
3585 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3586 	struct crypto_unittest_params *ut_params = &unittest_params;
3587 
3588 	int retval;
3589 
3590 	unsigned int plaintext_pad_len;
3591 	unsigned int plaintext_len;
3592 
3593 	uint8_t buffer[10000];
3594 	const uint8_t *ciphertext;
3595 
3596 	struct rte_cryptodev_info dev_info;
3597 
3598 	/* Verify the capabilities */
3599 	struct rte_cryptodev_sym_capability_idx cap_idx;
3600 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3601 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3602 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3603 			&cap_idx) == NULL)
3604 		return TEST_SKIPPED;
3605 
3606 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3607 
3608 	uint64_t feat_flags = dev_info.feature_flags;
3609 
3610 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3611 		printf("Device doesn't support in-place scatter-gather. "
3612 				"Test Skipped.\n");
3613 		return TEST_SKIPPED;
3614 	}
3615 
3616 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3617 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3618 		printf("Device doesn't support RAW data-path APIs.\n");
3619 		return TEST_SKIPPED;
3620 	}
3621 
3622 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3623 		return TEST_SKIPPED;
3624 
3625 	/* Create KASUMI session */
3626 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3627 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3628 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3629 					tdata->key.data, tdata->key.len,
3630 					tdata->cipher_iv.len);
3631 	if (retval < 0)
3632 		return retval;
3633 
3634 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3635 
3636 
3637 	/* Append data which is padded to a multiple */
3638 	/* of the algorithms block size */
3639 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3640 
3641 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3642 			plaintext_pad_len, 10, 0);
3643 
3644 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3645 
3646 	/* Create KASUMI operation */
3647 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3648 				tdata->cipher_iv.len,
3649 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3650 				tdata->validCipherOffsetInBits.len);
3651 	if (retval < 0)
3652 		return retval;
3653 
3654 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3655 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3656 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3657 	else
3658 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3659 						ut_params->op);
3660 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3661 
3662 	ut_params->obuf = ut_params->op->sym->m_dst;
3663 
3664 	if (ut_params->obuf)
3665 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3666 				plaintext_len, buffer);
3667 	else
3668 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3669 				tdata->validCipherOffsetInBits.len >> 3,
3670 				plaintext_len, buffer);
3671 
3672 	/* Validate obuf */
3673 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3674 
3675 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3676 				(tdata->validCipherOffsetInBits.len >> 3);
3677 	/* Validate obuf */
3678 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3679 		ciphertext,
3680 		reference_ciphertext,
3681 		tdata->validCipherLenInBits.len,
3682 		"KASUMI Ciphertext data not as expected");
3683 	return 0;
3684 }
3685 
3686 static int
3687 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3688 {
3689 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3690 	struct crypto_unittest_params *ut_params = &unittest_params;
3691 
3692 	int retval;
3693 	uint8_t *plaintext, *ciphertext;
3694 	unsigned plaintext_pad_len;
3695 	unsigned plaintext_len;
3696 
3697 	/* Verify the capabilities */
3698 	struct rte_cryptodev_sym_capability_idx cap_idx;
3699 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3700 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3701 	/* Data-path service does not support OOP */
3702 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3703 			&cap_idx) == NULL)
3704 		return TEST_SKIPPED;
3705 
3706 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3707 		return TEST_SKIPPED;
3708 
3709 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3710 		return TEST_SKIPPED;
3711 
3712 	/* Create KASUMI session */
3713 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3714 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3715 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3716 					tdata->key.data, tdata->key.len,
3717 					tdata->cipher_iv.len);
3718 	if (retval < 0)
3719 		return retval;
3720 
3721 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3722 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3723 
3724 	/* Clear mbuf payload */
3725 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3726 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3727 
3728 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3729 	/* Append data which is padded to a multiple */
3730 	/* of the algorithms block size */
3731 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3732 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3733 				plaintext_pad_len);
3734 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3735 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3736 
3737 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3738 
3739 	/* Create KASUMI operation */
3740 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3741 				tdata->cipher_iv.len,
3742 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3743 				tdata->validCipherOffsetInBits.len);
3744 	if (retval < 0)
3745 		return retval;
3746 
3747 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3748 						ut_params->op);
3749 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3750 
3751 	ut_params->obuf = ut_params->op->sym->m_dst;
3752 	if (ut_params->obuf)
3753 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3754 	else
3755 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3756 
3757 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3758 
3759 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3760 				(tdata->validCipherOffsetInBits.len >> 3);
3761 	/* Validate obuf */
3762 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3763 		ciphertext,
3764 		reference_ciphertext,
3765 		tdata->validCipherLenInBits.len,
3766 		"KASUMI Ciphertext data not as expected");
3767 	return 0;
3768 }
3769 
3770 static int
3771 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3772 {
3773 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3774 	struct crypto_unittest_params *ut_params = &unittest_params;
3775 
3776 	int retval;
3777 	unsigned int plaintext_pad_len;
3778 	unsigned int plaintext_len;
3779 
3780 	const uint8_t *ciphertext;
3781 	uint8_t buffer[2048];
3782 
3783 	struct rte_cryptodev_info dev_info;
3784 
3785 	/* Verify the capabilities */
3786 	struct rte_cryptodev_sym_capability_idx cap_idx;
3787 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3788 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3789 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3790 			&cap_idx) == NULL)
3791 		return TEST_SKIPPED;
3792 
3793 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3794 		return TEST_SKIPPED;
3795 
3796 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3797 		return TEST_SKIPPED;
3798 
3799 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3800 
3801 	uint64_t feat_flags = dev_info.feature_flags;
3802 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3803 		printf("Device doesn't support out-of-place scatter-gather "
3804 				"in both input and output mbufs. "
3805 				"Test Skipped.\n");
3806 		return TEST_SKIPPED;
3807 	}
3808 
3809 	/* Create KASUMI session */
3810 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3811 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3812 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3813 					tdata->key.data, tdata->key.len,
3814 					tdata->cipher_iv.len);
3815 	if (retval < 0)
3816 		return retval;
3817 
3818 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3819 	/* Append data which is padded to a multiple */
3820 	/* of the algorithms block size */
3821 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3822 
3823 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3824 			plaintext_pad_len, 10, 0);
3825 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3826 			plaintext_pad_len, 3, 0);
3827 
3828 	/* Append data which is padded to a multiple */
3829 	/* of the algorithms block size */
3830 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3831 
3832 	/* Create KASUMI operation */
3833 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3834 				tdata->cipher_iv.len,
3835 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3836 				tdata->validCipherOffsetInBits.len);
3837 	if (retval < 0)
3838 		return retval;
3839 
3840 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3841 						ut_params->op);
3842 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3843 
3844 	ut_params->obuf = ut_params->op->sym->m_dst;
3845 	if (ut_params->obuf)
3846 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3847 				plaintext_pad_len, buffer);
3848 	else
3849 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3850 				tdata->validCipherOffsetInBits.len >> 3,
3851 				plaintext_pad_len, buffer);
3852 
3853 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3854 				(tdata->validCipherOffsetInBits.len >> 3);
3855 	/* Validate obuf */
3856 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3857 		ciphertext,
3858 		reference_ciphertext,
3859 		tdata->validCipherLenInBits.len,
3860 		"KASUMI Ciphertext data not as expected");
3861 	return 0;
3862 }
3863 
3864 
3865 static int
3866 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3867 {
3868 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3869 	struct crypto_unittest_params *ut_params = &unittest_params;
3870 
3871 	int retval;
3872 	uint8_t *ciphertext, *plaintext;
3873 	unsigned ciphertext_pad_len;
3874 	unsigned ciphertext_len;
3875 
3876 	/* Verify the capabilities */
3877 	struct rte_cryptodev_sym_capability_idx cap_idx;
3878 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3879 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3880 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3881 			&cap_idx) == NULL)
3882 		return TEST_SKIPPED;
3883 
3884 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3885 		return TEST_SKIPPED;
3886 
3887 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3888 		return TEST_SKIPPED;
3889 
3890 	/* Create KASUMI session */
3891 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3892 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
3893 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3894 					tdata->key.data, tdata->key.len,
3895 					tdata->cipher_iv.len);
3896 	if (retval < 0)
3897 		return retval;
3898 
3899 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3900 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3901 
3902 	/* Clear mbuf payload */
3903 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3904 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3905 
3906 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3907 	/* Append data which is padded to a multiple */
3908 	/* of the algorithms block size */
3909 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3910 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3911 				ciphertext_pad_len);
3912 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3913 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3914 
3915 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3916 
3917 	/* Create KASUMI operation */
3918 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3919 				tdata->cipher_iv.len,
3920 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3921 				tdata->validCipherOffsetInBits.len);
3922 	if (retval < 0)
3923 		return retval;
3924 
3925 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3926 						ut_params->op);
3927 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3928 
3929 	ut_params->obuf = ut_params->op->sym->m_dst;
3930 	if (ut_params->obuf)
3931 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3932 	else
3933 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
3934 
3935 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
3936 
3937 	const uint8_t *reference_plaintext = tdata->plaintext.data +
3938 				(tdata->validCipherOffsetInBits.len >> 3);
3939 	/* Validate obuf */
3940 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3941 		plaintext,
3942 		reference_plaintext,
3943 		tdata->validCipherLenInBits.len,
3944 		"KASUMI Plaintext data not as expected");
3945 	return 0;
3946 }
3947 
3948 static int
3949 test_kasumi_decryption(const struct kasumi_test_data *tdata)
3950 {
3951 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3952 	struct crypto_unittest_params *ut_params = &unittest_params;
3953 
3954 	int retval;
3955 	uint8_t *ciphertext, *plaintext;
3956 	unsigned ciphertext_pad_len;
3957 	unsigned ciphertext_len;
3958 	struct rte_cryptodev_info dev_info;
3959 
3960 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3961 	uint64_t feat_flags = dev_info.feature_flags;
3962 
3963 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3964 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3965 		printf("Device doesn't support RAW data-path APIs.\n");
3966 		return TEST_SKIPPED;
3967 	}
3968 
3969 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3970 		return TEST_SKIPPED;
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_KASUMI_F8;
3976 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3977 			&cap_idx) == NULL)
3978 		return TEST_SKIPPED;
3979 
3980 	/* Create KASUMI session */
3981 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3982 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
3983 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3984 					tdata->key.data, tdata->key.len,
3985 					tdata->cipher_iv.len);
3986 	if (retval < 0)
3987 		return retval;
3988 
3989 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3990 
3991 	/* Clear mbuf payload */
3992 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3993 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3994 
3995 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3996 	/* Append data which is padded to a multiple */
3997 	/* of the algorithms block size */
3998 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3999 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4000 				ciphertext_pad_len);
4001 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4002 
4003 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4004 
4005 	/* Create KASUMI operation */
4006 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4007 					tdata->cipher_iv.len,
4008 					tdata->ciphertext.len,
4009 					tdata->validCipherOffsetInBits.len);
4010 	if (retval < 0)
4011 		return retval;
4012 
4013 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4014 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4015 				ut_params->op, 1, 0, 1, 0);
4016 	else
4017 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4018 						ut_params->op);
4019 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4020 
4021 	ut_params->obuf = ut_params->op->sym->m_dst;
4022 	if (ut_params->obuf)
4023 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4024 	else
4025 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4026 
4027 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4028 
4029 	const uint8_t *reference_plaintext = tdata->plaintext.data +
4030 				(tdata->validCipherOffsetInBits.len >> 3);
4031 	/* Validate obuf */
4032 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4033 		plaintext,
4034 		reference_plaintext,
4035 		tdata->validCipherLenInBits.len,
4036 		"KASUMI Plaintext data not as expected");
4037 	return 0;
4038 }
4039 
4040 static int
4041 test_snow3g_encryption(const struct snow3g_test_data *tdata)
4042 {
4043 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4044 	struct crypto_unittest_params *ut_params = &unittest_params;
4045 
4046 	int retval;
4047 	uint8_t *plaintext, *ciphertext;
4048 	unsigned plaintext_pad_len;
4049 	unsigned plaintext_len;
4050 	struct rte_cryptodev_info dev_info;
4051 
4052 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4053 	uint64_t feat_flags = dev_info.feature_flags;
4054 
4055 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4056 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4057 		printf("Device doesn't support RAW data-path APIs.\n");
4058 		return TEST_SKIPPED;
4059 	}
4060 
4061 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4062 		return TEST_SKIPPED;
4063 
4064 	/* Verify the capabilities */
4065 	struct rte_cryptodev_sym_capability_idx cap_idx;
4066 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4067 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4068 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4069 			&cap_idx) == NULL)
4070 		return TEST_SKIPPED;
4071 
4072 	/* Create SNOW 3G session */
4073 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4074 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4075 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4076 					tdata->key.data, tdata->key.len,
4077 					tdata->cipher_iv.len);
4078 	if (retval < 0)
4079 		return retval;
4080 
4081 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4082 
4083 	/* Clear mbuf payload */
4084 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4085 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4086 
4087 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4088 	/* Append data which is padded to a multiple of */
4089 	/* the algorithms block size */
4090 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4091 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4092 				plaintext_pad_len);
4093 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4094 
4095 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4096 
4097 	/* Create SNOW 3G operation */
4098 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4099 					tdata->cipher_iv.len,
4100 					tdata->validCipherLenInBits.len,
4101 					0);
4102 	if (retval < 0)
4103 		return retval;
4104 
4105 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4106 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4107 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4108 	else
4109 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4110 						ut_params->op);
4111 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4112 
4113 	ut_params->obuf = ut_params->op->sym->m_dst;
4114 	if (ut_params->obuf)
4115 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4116 	else
4117 		ciphertext = plaintext;
4118 
4119 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4120 
4121 	/* Validate obuf */
4122 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4123 		ciphertext,
4124 		tdata->ciphertext.data,
4125 		tdata->validDataLenInBits.len,
4126 		"SNOW 3G Ciphertext data not as expected");
4127 	return 0;
4128 }
4129 
4130 
4131 static int
4132 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
4133 {
4134 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4135 	struct crypto_unittest_params *ut_params = &unittest_params;
4136 	uint8_t *plaintext, *ciphertext;
4137 
4138 	int retval;
4139 	unsigned plaintext_pad_len;
4140 	unsigned plaintext_len;
4141 
4142 	/* Verify the capabilities */
4143 	struct rte_cryptodev_sym_capability_idx cap_idx;
4144 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4145 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4146 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4147 			&cap_idx) == NULL)
4148 		return TEST_SKIPPED;
4149 
4150 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4151 		return TEST_SKIPPED;
4152 
4153 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4154 		return TEST_SKIPPED;
4155 
4156 	/* Create SNOW 3G session */
4157 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4158 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4159 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4160 					tdata->key.data, tdata->key.len,
4161 					tdata->cipher_iv.len);
4162 	if (retval < 0)
4163 		return retval;
4164 
4165 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4166 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4167 
4168 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4169 			"Failed to allocate input buffer in mempool");
4170 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4171 			"Failed to allocate output buffer in mempool");
4172 
4173 	/* Clear mbuf payload */
4174 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4175 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4176 
4177 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4178 	/* Append data which is padded to a multiple of */
4179 	/* the algorithms block size */
4180 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4181 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4182 				plaintext_pad_len);
4183 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4184 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4185 
4186 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4187 
4188 	/* Create SNOW 3G operation */
4189 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4190 					tdata->cipher_iv.len,
4191 					tdata->validCipherLenInBits.len,
4192 					0);
4193 	if (retval < 0)
4194 		return retval;
4195 
4196 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4197 						ut_params->op);
4198 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4199 
4200 	ut_params->obuf = ut_params->op->sym->m_dst;
4201 	if (ut_params->obuf)
4202 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4203 	else
4204 		ciphertext = plaintext;
4205 
4206 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4207 
4208 	/* Validate obuf */
4209 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4210 		ciphertext,
4211 		tdata->ciphertext.data,
4212 		tdata->validDataLenInBits.len,
4213 		"SNOW 3G Ciphertext data not as expected");
4214 	return 0;
4215 }
4216 
4217 static int
4218 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
4219 {
4220 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4221 	struct crypto_unittest_params *ut_params = &unittest_params;
4222 
4223 	int retval;
4224 	unsigned int plaintext_pad_len;
4225 	unsigned int plaintext_len;
4226 	uint8_t buffer[10000];
4227 	const uint8_t *ciphertext;
4228 
4229 	struct rte_cryptodev_info dev_info;
4230 
4231 	/* Verify the capabilities */
4232 	struct rte_cryptodev_sym_capability_idx cap_idx;
4233 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4234 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4235 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4236 			&cap_idx) == NULL)
4237 		return TEST_SKIPPED;
4238 
4239 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4240 		return TEST_SKIPPED;
4241 
4242 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4243 		return TEST_SKIPPED;
4244 
4245 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4246 
4247 	uint64_t feat_flags = dev_info.feature_flags;
4248 
4249 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4250 		printf("Device doesn't support out-of-place scatter-gather "
4251 				"in both input and output mbufs. "
4252 				"Test Skipped.\n");
4253 		return TEST_SKIPPED;
4254 	}
4255 
4256 	/* Create SNOW 3G session */
4257 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4258 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4259 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4260 					tdata->key.data, tdata->key.len,
4261 					tdata->cipher_iv.len);
4262 	if (retval < 0)
4263 		return retval;
4264 
4265 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4266 	/* Append data which is padded to a multiple of */
4267 	/* the algorithms block size */
4268 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4269 
4270 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4271 			plaintext_pad_len, 10, 0);
4272 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4273 			plaintext_pad_len, 3, 0);
4274 
4275 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4276 			"Failed to allocate input buffer in mempool");
4277 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4278 			"Failed to allocate output buffer in mempool");
4279 
4280 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4281 
4282 	/* Create SNOW 3G operation */
4283 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4284 					tdata->cipher_iv.len,
4285 					tdata->validCipherLenInBits.len,
4286 					0);
4287 	if (retval < 0)
4288 		return retval;
4289 
4290 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4291 						ut_params->op);
4292 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4293 
4294 	ut_params->obuf = ut_params->op->sym->m_dst;
4295 	if (ut_params->obuf)
4296 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4297 				plaintext_len, buffer);
4298 	else
4299 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4300 				plaintext_len, buffer);
4301 
4302 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4303 
4304 	/* Validate obuf */
4305 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4306 		ciphertext,
4307 		tdata->ciphertext.data,
4308 		tdata->validDataLenInBits.len,
4309 		"SNOW 3G Ciphertext data not as expected");
4310 
4311 	return 0;
4312 }
4313 
4314 /* Shift right a buffer by "offset" bits, "offset" < 8 */
4315 static void
4316 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
4317 {
4318 	uint8_t curr_byte, prev_byte;
4319 	uint32_t length_in_bytes = ceil_byte_length(length + offset);
4320 	uint8_t lower_byte_mask = (1 << offset) - 1;
4321 	unsigned i;
4322 
4323 	prev_byte = buffer[0];
4324 	buffer[0] >>= offset;
4325 
4326 	for (i = 1; i < length_in_bytes; i++) {
4327 		curr_byte = buffer[i];
4328 		buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
4329 				(curr_byte >> offset);
4330 		prev_byte = curr_byte;
4331 	}
4332 }
4333 
4334 static int
4335 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
4336 {
4337 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4338 	struct crypto_unittest_params *ut_params = &unittest_params;
4339 	uint8_t *plaintext, *ciphertext;
4340 	int retval;
4341 	uint32_t plaintext_len;
4342 	uint32_t plaintext_pad_len;
4343 	uint8_t extra_offset = 4;
4344 	uint8_t *expected_ciphertext_shifted;
4345 	struct rte_cryptodev_info dev_info;
4346 
4347 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4348 	uint64_t feat_flags = dev_info.feature_flags;
4349 
4350 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4351 			((tdata->validDataLenInBits.len % 8) != 0)) {
4352 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4353 		return TEST_SKIPPED;
4354 	}
4355 
4356 	/* Verify the capabilities */
4357 	struct rte_cryptodev_sym_capability_idx cap_idx;
4358 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4359 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4360 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4361 			&cap_idx) == NULL)
4362 		return TEST_SKIPPED;
4363 
4364 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4365 		return TEST_SKIPPED;
4366 
4367 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4368 		return TEST_SKIPPED;
4369 
4370 	/* Create SNOW 3G session */
4371 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4372 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4373 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4374 					tdata->key.data, tdata->key.len,
4375 					tdata->cipher_iv.len);
4376 	if (retval < 0)
4377 		return retval;
4378 
4379 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4380 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4381 
4382 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4383 			"Failed to allocate input buffer in mempool");
4384 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4385 			"Failed to allocate output buffer in mempool");
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 + extra_offset);
4392 	/*
4393 	 * Append data which is padded to a
4394 	 * multiple of the algorithms block size
4395 	 */
4396 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4397 
4398 	plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4399 						plaintext_pad_len);
4400 
4401 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4402 
4403 	memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4404 	buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4405 
4406 #ifdef RTE_APP_TEST_DEBUG
4407 	rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4408 #endif
4409 	/* Create SNOW 3G operation */
4410 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4411 					tdata->cipher_iv.len,
4412 					tdata->validCipherLenInBits.len,
4413 					extra_offset);
4414 	if (retval < 0)
4415 		return retval;
4416 
4417 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4418 						ut_params->op);
4419 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4420 
4421 	ut_params->obuf = ut_params->op->sym->m_dst;
4422 	if (ut_params->obuf)
4423 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4424 	else
4425 		ciphertext = plaintext;
4426 
4427 #ifdef RTE_APP_TEST_DEBUG
4428 	rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4429 #endif
4430 
4431 	expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4432 
4433 	TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4434 			"failed to reserve memory for ciphertext shifted\n");
4435 
4436 	memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4437 			ceil_byte_length(tdata->ciphertext.len));
4438 	buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4439 			extra_offset);
4440 	/* Validate obuf */
4441 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4442 		ciphertext,
4443 		expected_ciphertext_shifted,
4444 		tdata->validDataLenInBits.len,
4445 		extra_offset,
4446 		"SNOW 3G Ciphertext data not as expected");
4447 	return 0;
4448 }
4449 
4450 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
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, *ciphertext;
4458 	unsigned ciphertext_pad_len;
4459 	unsigned ciphertext_len;
4460 	struct rte_cryptodev_info dev_info;
4461 
4462 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4463 	uint64_t feat_flags = dev_info.feature_flags;
4464 
4465 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4466 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4467 		printf("Device doesn't support RAW data-path APIs.\n");
4468 		return TEST_SKIPPED;
4469 	}
4470 
4471 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4472 		return TEST_SKIPPED;
4473 
4474 	/* Verify the capabilities */
4475 	struct rte_cryptodev_sym_capability_idx cap_idx;
4476 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4477 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4478 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4479 			&cap_idx) == NULL)
4480 		return TEST_SKIPPED;
4481 
4482 	/* Create SNOW 3G session */
4483 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4484 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4485 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4486 					tdata->key.data, tdata->key.len,
4487 					tdata->cipher_iv.len);
4488 	if (retval < 0)
4489 		return retval;
4490 
4491 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4492 
4493 	/* Clear mbuf payload */
4494 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4495 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4496 
4497 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4498 	/* Append data which is padded to a multiple of */
4499 	/* the algorithms block size */
4500 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4501 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4502 				ciphertext_pad_len);
4503 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4504 
4505 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4506 
4507 	/* Create SNOW 3G operation */
4508 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4509 					tdata->cipher_iv.len,
4510 					tdata->validCipherLenInBits.len,
4511 					tdata->cipher.offset_bits);
4512 	if (retval < 0)
4513 		return retval;
4514 
4515 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4516 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4517 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4518 	else
4519 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4520 						ut_params->op);
4521 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4522 	ut_params->obuf = ut_params->op->sym->m_dst;
4523 	if (ut_params->obuf)
4524 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4525 	else
4526 		plaintext = ciphertext;
4527 
4528 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4529 
4530 	/* Validate obuf */
4531 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4532 				tdata->plaintext.data,
4533 				tdata->validDataLenInBits.len,
4534 				"SNOW 3G Plaintext data not as expected");
4535 	return 0;
4536 }
4537 
4538 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4539 {
4540 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4541 	struct crypto_unittest_params *ut_params = &unittest_params;
4542 
4543 	int retval;
4544 
4545 	uint8_t *plaintext, *ciphertext;
4546 	unsigned ciphertext_pad_len;
4547 	unsigned ciphertext_len;
4548 
4549 	/* Verify the capabilities */
4550 	struct rte_cryptodev_sym_capability_idx cap_idx;
4551 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4552 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4553 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4554 			&cap_idx) == NULL)
4555 		return TEST_SKIPPED;
4556 
4557 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4558 		return TEST_SKIPPED;
4559 
4560 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4561 		return TEST_SKIPPED;
4562 
4563 	/* Create SNOW 3G session */
4564 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4565 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4566 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4567 					tdata->key.data, tdata->key.len,
4568 					tdata->cipher_iv.len);
4569 	if (retval < 0)
4570 		return retval;
4571 
4572 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4573 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4574 
4575 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4576 			"Failed to allocate input buffer");
4577 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4578 			"Failed to allocate output buffer");
4579 
4580 	/* Clear mbuf payload */
4581 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4582 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4583 
4584 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4585 		       rte_pktmbuf_tailroom(ut_params->obuf));
4586 
4587 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4588 	/* Append data which is padded to a multiple of */
4589 	/* the algorithms block size */
4590 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4591 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4592 				ciphertext_pad_len);
4593 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4594 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4595 
4596 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4597 
4598 	/* Create SNOW 3G operation */
4599 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4600 					tdata->cipher_iv.len,
4601 					tdata->validCipherLenInBits.len,
4602 					0);
4603 	if (retval < 0)
4604 		return retval;
4605 
4606 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4607 						ut_params->op);
4608 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4609 	ut_params->obuf = ut_params->op->sym->m_dst;
4610 	if (ut_params->obuf)
4611 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4612 	else
4613 		plaintext = ciphertext;
4614 
4615 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4616 
4617 	/* Validate obuf */
4618 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4619 				tdata->plaintext.data,
4620 				tdata->validDataLenInBits.len,
4621 				"SNOW 3G Plaintext data not as expected");
4622 	return 0;
4623 }
4624 
4625 static int
4626 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4627 {
4628 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4629 	struct crypto_unittest_params *ut_params = &unittest_params;
4630 
4631 	int retval;
4632 
4633 	uint8_t *plaintext, *ciphertext;
4634 	unsigned int plaintext_pad_len;
4635 	unsigned int plaintext_len;
4636 
4637 	struct rte_cryptodev_info dev_info;
4638 	struct rte_cryptodev_sym_capability_idx cap_idx;
4639 
4640 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4641 	uint64_t feat_flags = dev_info.feature_flags;
4642 
4643 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4644 			((tdata->validAuthLenInBits.len % 8 != 0) ||
4645 			(tdata->validDataLenInBits.len % 8 != 0))) {
4646 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4647 		return TEST_SKIPPED;
4648 	}
4649 
4650 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4651 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4652 		printf("Device doesn't support RAW data-path APIs.\n");
4653 		return TEST_SKIPPED;
4654 	}
4655 
4656 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4657 		return TEST_SKIPPED;
4658 
4659 	/* Check if device supports ZUC EEA3 */
4660 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4661 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4662 
4663 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4664 			&cap_idx) == NULL)
4665 		return TEST_SKIPPED;
4666 
4667 	/* Check if device supports ZUC EIA3 */
4668 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4669 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4670 
4671 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4672 			&cap_idx) == NULL)
4673 		return TEST_SKIPPED;
4674 
4675 	/* Create ZUC session */
4676 	retval = create_zuc_cipher_auth_encrypt_generate_session(
4677 			ts_params->valid_devs[0],
4678 			tdata);
4679 	if (retval != 0)
4680 		return retval;
4681 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4682 
4683 	/* clear mbuf payload */
4684 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4685 			rte_pktmbuf_tailroom(ut_params->ibuf));
4686 
4687 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4688 	/* Append data which is padded to a multiple of */
4689 	/* the algorithms block size */
4690 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4691 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4692 				plaintext_pad_len);
4693 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4694 
4695 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4696 
4697 	/* Create ZUC operation */
4698 	retval = create_zuc_cipher_hash_generate_operation(tdata);
4699 	if (retval < 0)
4700 		return retval;
4701 
4702 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4703 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4704 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4705 	else
4706 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4707 			ut_params->op);
4708 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4709 	ut_params->obuf = ut_params->op->sym->m_src;
4710 	if (ut_params->obuf)
4711 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4712 	else
4713 		ciphertext = plaintext;
4714 
4715 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4716 	/* Validate obuf */
4717 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4718 			ciphertext,
4719 			tdata->ciphertext.data,
4720 			tdata->validDataLenInBits.len,
4721 			"ZUC Ciphertext data not as expected");
4722 
4723 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4724 	    + plaintext_pad_len;
4725 
4726 	/* Validate obuf */
4727 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4728 			ut_params->digest,
4729 			tdata->digest.data,
4730 			4,
4731 			"ZUC Generated auth tag not as expected");
4732 	return 0;
4733 }
4734 
4735 static int
4736 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4737 {
4738 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4739 	struct crypto_unittest_params *ut_params = &unittest_params;
4740 
4741 	int retval;
4742 
4743 	uint8_t *plaintext, *ciphertext;
4744 	unsigned plaintext_pad_len;
4745 	unsigned plaintext_len;
4746 	struct rte_cryptodev_info dev_info;
4747 
4748 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4749 	uint64_t feat_flags = dev_info.feature_flags;
4750 
4751 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4752 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4753 		printf("Device doesn't support RAW data-path APIs.\n");
4754 		return TEST_SKIPPED;
4755 	}
4756 
4757 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4758 		return TEST_SKIPPED;
4759 
4760 	/* Verify the capabilities */
4761 	struct rte_cryptodev_sym_capability_idx cap_idx;
4762 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4763 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4764 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4765 			&cap_idx) == NULL)
4766 		return TEST_SKIPPED;
4767 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4768 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4769 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4770 			&cap_idx) == NULL)
4771 		return TEST_SKIPPED;
4772 
4773 	/* Create SNOW 3G session */
4774 	retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4775 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4776 			RTE_CRYPTO_AUTH_OP_GENERATE,
4777 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4778 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4779 			tdata->key.data, tdata->key.len,
4780 			tdata->auth_iv.len, tdata->digest.len,
4781 			tdata->cipher_iv.len);
4782 	if (retval != 0)
4783 		return retval;
4784 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4785 
4786 	/* clear mbuf payload */
4787 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4788 			rte_pktmbuf_tailroom(ut_params->ibuf));
4789 
4790 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4791 	/* Append data which is padded to a multiple of */
4792 	/* the algorithms block size */
4793 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4794 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4795 				plaintext_pad_len);
4796 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4797 
4798 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4799 
4800 	/* Create SNOW 3G operation */
4801 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4802 			tdata->digest.len, tdata->auth_iv.data,
4803 			tdata->auth_iv.len,
4804 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4805 			tdata->cipher_iv.data, tdata->cipher_iv.len,
4806 			tdata->validCipherLenInBits.len,
4807 			0,
4808 			tdata->validAuthLenInBits.len,
4809 			0
4810 			);
4811 	if (retval < 0)
4812 		return retval;
4813 
4814 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4815 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4816 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4817 	else
4818 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4819 			ut_params->op);
4820 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4821 	ut_params->obuf = ut_params->op->sym->m_src;
4822 	if (ut_params->obuf)
4823 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4824 	else
4825 		ciphertext = plaintext;
4826 
4827 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4828 	/* Validate obuf */
4829 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4830 			ciphertext,
4831 			tdata->ciphertext.data,
4832 			tdata->validDataLenInBits.len,
4833 			"SNOW 3G Ciphertext data not as expected");
4834 
4835 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4836 	    + plaintext_pad_len;
4837 
4838 	/* Validate obuf */
4839 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4840 			ut_params->digest,
4841 			tdata->digest.data,
4842 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4843 			"SNOW 3G Generated auth tag not as expected");
4844 	return 0;
4845 }
4846 
4847 static int
4848 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
4849 	uint8_t op_mode, uint8_t verify)
4850 {
4851 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4852 	struct crypto_unittest_params *ut_params = &unittest_params;
4853 
4854 	int retval;
4855 
4856 	uint8_t *plaintext = NULL, *ciphertext = NULL;
4857 	unsigned int plaintext_pad_len;
4858 	unsigned int plaintext_len;
4859 	unsigned int ciphertext_pad_len;
4860 	unsigned int ciphertext_len;
4861 
4862 	struct rte_cryptodev_info dev_info;
4863 
4864 	/* Verify the capabilities */
4865 	struct rte_cryptodev_sym_capability_idx cap_idx;
4866 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4867 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4868 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4869 			&cap_idx) == NULL)
4870 		return TEST_SKIPPED;
4871 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4872 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4873 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4874 			&cap_idx) == NULL)
4875 		return TEST_SKIPPED;
4876 
4877 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4878 		return TEST_SKIPPED;
4879 
4880 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4881 
4882 	uint64_t feat_flags = dev_info.feature_flags;
4883 
4884 	if (op_mode == OUT_OF_PLACE) {
4885 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4886 			printf("Device doesn't support digest encrypted.\n");
4887 			return TEST_SKIPPED;
4888 		}
4889 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4890 			return TEST_SKIPPED;
4891 	}
4892 
4893 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4894 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4895 		printf("Device doesn't support RAW data-path APIs.\n");
4896 		return TEST_SKIPPED;
4897 	}
4898 
4899 	/* Create SNOW 3G session */
4900 	retval = create_wireless_algo_auth_cipher_session(
4901 			ts_params->valid_devs[0],
4902 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
4903 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
4904 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
4905 					: RTE_CRYPTO_AUTH_OP_GENERATE),
4906 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4907 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4908 			tdata->key.data, tdata->key.len,
4909 			tdata->auth_iv.len, tdata->digest.len,
4910 			tdata->cipher_iv.len);
4911 	if (retval != 0)
4912 		return retval;
4913 
4914 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4915 	if (op_mode == OUT_OF_PLACE)
4916 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4917 
4918 	/* clear mbuf payload */
4919 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4920 		rte_pktmbuf_tailroom(ut_params->ibuf));
4921 	if (op_mode == OUT_OF_PLACE)
4922 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4923 			rte_pktmbuf_tailroom(ut_params->obuf));
4924 
4925 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4926 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4927 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4928 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4929 
4930 	if (verify) {
4931 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4932 					ciphertext_pad_len);
4933 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4934 		if (op_mode == OUT_OF_PLACE)
4935 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4936 		debug_hexdump(stdout, "ciphertext:", ciphertext,
4937 			ciphertext_len);
4938 	} else {
4939 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4940 					plaintext_pad_len);
4941 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4942 		if (op_mode == OUT_OF_PLACE)
4943 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4944 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4945 	}
4946 
4947 	/* Create SNOW 3G operation */
4948 	retval = create_wireless_algo_auth_cipher_operation(
4949 		tdata->digest.data, tdata->digest.len,
4950 		tdata->cipher_iv.data, tdata->cipher_iv.len,
4951 		tdata->auth_iv.data, tdata->auth_iv.len,
4952 		(tdata->digest.offset_bytes == 0 ?
4953 		(verify ? ciphertext_pad_len : plaintext_pad_len)
4954 			: tdata->digest.offset_bytes),
4955 		tdata->validCipherLenInBits.len,
4956 		tdata->cipher.offset_bits,
4957 		tdata->validAuthLenInBits.len,
4958 		tdata->auth.offset_bits,
4959 		op_mode, 0, verify);
4960 
4961 	if (retval < 0)
4962 		return retval;
4963 
4964 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4965 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4966 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4967 	else
4968 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4969 			ut_params->op);
4970 
4971 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4972 
4973 	ut_params->obuf = (op_mode == IN_PLACE ?
4974 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
4975 
4976 	if (verify) {
4977 		if (ut_params->obuf)
4978 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
4979 							uint8_t *);
4980 		else
4981 			plaintext = ciphertext +
4982 				(tdata->cipher.offset_bits >> 3);
4983 
4984 		debug_hexdump(stdout, "plaintext:", plaintext,
4985 			(tdata->plaintext.len >> 3) - tdata->digest.len);
4986 		debug_hexdump(stdout, "plaintext expected:",
4987 			tdata->plaintext.data,
4988 			(tdata->plaintext.len >> 3) - tdata->digest.len);
4989 	} else {
4990 		if (ut_params->obuf)
4991 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
4992 							uint8_t *);
4993 		else
4994 			ciphertext = plaintext;
4995 
4996 		debug_hexdump(stdout, "ciphertext:", ciphertext,
4997 			ciphertext_len);
4998 		debug_hexdump(stdout, "ciphertext expected:",
4999 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5000 
5001 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5002 			+ (tdata->digest.offset_bytes == 0 ?
5003 		plaintext_pad_len : tdata->digest.offset_bytes);
5004 
5005 		debug_hexdump(stdout, "digest:", ut_params->digest,
5006 			tdata->digest.len);
5007 		debug_hexdump(stdout, "digest expected:", tdata->digest.data,
5008 				tdata->digest.len);
5009 	}
5010 
5011 	/* Validate obuf */
5012 	if (verify) {
5013 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5014 			plaintext,
5015 			tdata->plaintext.data,
5016 			(tdata->plaintext.len - tdata->cipher.offset_bits -
5017 			 (tdata->digest.len << 3)),
5018 			tdata->cipher.offset_bits,
5019 			"SNOW 3G Plaintext data not as expected");
5020 	} else {
5021 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5022 			ciphertext,
5023 			tdata->ciphertext.data,
5024 			(tdata->validDataLenInBits.len -
5025 			 tdata->cipher.offset_bits),
5026 			tdata->cipher.offset_bits,
5027 			"SNOW 3G Ciphertext data not as expected");
5028 
5029 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5030 			ut_params->digest,
5031 			tdata->digest.data,
5032 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5033 			"SNOW 3G Generated auth tag not as expected");
5034 	}
5035 	return 0;
5036 }
5037 
5038 static int
5039 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
5040 	uint8_t op_mode, uint8_t verify)
5041 {
5042 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5043 	struct crypto_unittest_params *ut_params = &unittest_params;
5044 
5045 	int retval;
5046 
5047 	const uint8_t *plaintext = NULL;
5048 	const uint8_t *ciphertext = NULL;
5049 	const uint8_t *digest = NULL;
5050 	unsigned int plaintext_pad_len;
5051 	unsigned int plaintext_len;
5052 	unsigned int ciphertext_pad_len;
5053 	unsigned int ciphertext_len;
5054 	uint8_t buffer[10000];
5055 	uint8_t digest_buffer[10000];
5056 
5057 	struct rte_cryptodev_info dev_info;
5058 
5059 	/* Verify the capabilities */
5060 	struct rte_cryptodev_sym_capability_idx cap_idx;
5061 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5062 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5063 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5064 			&cap_idx) == NULL)
5065 		return TEST_SKIPPED;
5066 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5067 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5068 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5069 			&cap_idx) == NULL)
5070 		return TEST_SKIPPED;
5071 
5072 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5073 		return TEST_SKIPPED;
5074 
5075 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5076 
5077 	uint64_t feat_flags = dev_info.feature_flags;
5078 
5079 	if (op_mode == IN_PLACE) {
5080 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5081 			printf("Device doesn't support in-place scatter-gather "
5082 					"in both input and output mbufs.\n");
5083 			return TEST_SKIPPED;
5084 		}
5085 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5086 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5087 			printf("Device doesn't support RAW data-path APIs.\n");
5088 			return TEST_SKIPPED;
5089 		}
5090 	} else {
5091 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5092 			return TEST_SKIPPED;
5093 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5094 			printf("Device doesn't support out-of-place scatter-gather "
5095 					"in both input and output mbufs.\n");
5096 			return TEST_SKIPPED;
5097 		}
5098 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5099 			printf("Device doesn't support digest encrypted.\n");
5100 			return TEST_SKIPPED;
5101 		}
5102 	}
5103 
5104 	/* Create SNOW 3G session */
5105 	retval = create_wireless_algo_auth_cipher_session(
5106 			ts_params->valid_devs[0],
5107 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5108 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5109 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5110 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5111 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5112 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5113 			tdata->key.data, tdata->key.len,
5114 			tdata->auth_iv.len, tdata->digest.len,
5115 			tdata->cipher_iv.len);
5116 
5117 	if (retval != 0)
5118 		return retval;
5119 
5120 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5121 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5122 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5123 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5124 
5125 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5126 			plaintext_pad_len, 15, 0);
5127 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5128 			"Failed to allocate input buffer in mempool");
5129 
5130 	if (op_mode == OUT_OF_PLACE) {
5131 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5132 				plaintext_pad_len, 15, 0);
5133 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5134 				"Failed to allocate output buffer in mempool");
5135 	}
5136 
5137 	if (verify) {
5138 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5139 			tdata->ciphertext.data);
5140 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5141 					ciphertext_len, buffer);
5142 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5143 			ciphertext_len);
5144 	} else {
5145 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5146 			tdata->plaintext.data);
5147 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5148 					plaintext_len, buffer);
5149 		debug_hexdump(stdout, "plaintext:", plaintext,
5150 			plaintext_len);
5151 	}
5152 	memset(buffer, 0, sizeof(buffer));
5153 
5154 	/* Create SNOW 3G operation */
5155 	retval = create_wireless_algo_auth_cipher_operation(
5156 		tdata->digest.data, tdata->digest.len,
5157 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5158 		tdata->auth_iv.data, tdata->auth_iv.len,
5159 		(tdata->digest.offset_bytes == 0 ?
5160 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5161 			: tdata->digest.offset_bytes),
5162 		tdata->validCipherLenInBits.len,
5163 		tdata->cipher.offset_bits,
5164 		tdata->validAuthLenInBits.len,
5165 		tdata->auth.offset_bits,
5166 		op_mode, 1, verify);
5167 
5168 	if (retval < 0)
5169 		return retval;
5170 
5171 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5172 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5173 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5174 	else
5175 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5176 			ut_params->op);
5177 
5178 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5179 
5180 	ut_params->obuf = (op_mode == IN_PLACE ?
5181 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5182 
5183 	if (verify) {
5184 		if (ut_params->obuf)
5185 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5186 					plaintext_len, buffer);
5187 		else
5188 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5189 					plaintext_len, buffer);
5190 
5191 		debug_hexdump(stdout, "plaintext:", plaintext,
5192 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5193 		debug_hexdump(stdout, "plaintext expected:",
5194 			tdata->plaintext.data,
5195 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5196 	} else {
5197 		if (ut_params->obuf)
5198 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5199 					ciphertext_len, buffer);
5200 		else
5201 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5202 					ciphertext_len, buffer);
5203 
5204 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5205 			ciphertext_len);
5206 		debug_hexdump(stdout, "ciphertext expected:",
5207 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5208 
5209 		if (ut_params->obuf)
5210 			digest = rte_pktmbuf_read(ut_params->obuf,
5211 				(tdata->digest.offset_bytes == 0 ?
5212 				plaintext_pad_len : tdata->digest.offset_bytes),
5213 				tdata->digest.len, digest_buffer);
5214 		else
5215 			digest = rte_pktmbuf_read(ut_params->ibuf,
5216 				(tdata->digest.offset_bytes == 0 ?
5217 				plaintext_pad_len : tdata->digest.offset_bytes),
5218 				tdata->digest.len, digest_buffer);
5219 
5220 		debug_hexdump(stdout, "digest:", digest,
5221 			tdata->digest.len);
5222 		debug_hexdump(stdout, "digest expected:",
5223 			tdata->digest.data, tdata->digest.len);
5224 	}
5225 
5226 	/* Validate obuf */
5227 	if (verify) {
5228 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5229 			plaintext,
5230 			tdata->plaintext.data,
5231 			(tdata->plaintext.len - tdata->cipher.offset_bits -
5232 			 (tdata->digest.len << 3)),
5233 			tdata->cipher.offset_bits,
5234 			"SNOW 3G Plaintext data not as expected");
5235 	} else {
5236 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5237 			ciphertext,
5238 			tdata->ciphertext.data,
5239 			(tdata->validDataLenInBits.len -
5240 			 tdata->cipher.offset_bits),
5241 			tdata->cipher.offset_bits,
5242 			"SNOW 3G Ciphertext data not as expected");
5243 
5244 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5245 			digest,
5246 			tdata->digest.data,
5247 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5248 			"SNOW 3G Generated auth tag not as expected");
5249 	}
5250 	return 0;
5251 }
5252 
5253 static int
5254 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
5255 	uint8_t op_mode, uint8_t verify)
5256 {
5257 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5258 	struct crypto_unittest_params *ut_params = &unittest_params;
5259 
5260 	int retval;
5261 
5262 	uint8_t *plaintext = NULL, *ciphertext = NULL;
5263 	unsigned int plaintext_pad_len;
5264 	unsigned int plaintext_len;
5265 	unsigned int ciphertext_pad_len;
5266 	unsigned int ciphertext_len;
5267 
5268 	struct rte_cryptodev_info dev_info;
5269 
5270 	/* Verify the capabilities */
5271 	struct rte_cryptodev_sym_capability_idx cap_idx;
5272 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5273 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5274 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5275 			&cap_idx) == NULL)
5276 		return TEST_SKIPPED;
5277 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5278 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5279 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5280 			&cap_idx) == NULL)
5281 		return TEST_SKIPPED;
5282 
5283 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5284 
5285 	uint64_t feat_flags = dev_info.feature_flags;
5286 
5287 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5288 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5289 		printf("Device doesn't support RAW data-path APIs.\n");
5290 		return TEST_SKIPPED;
5291 	}
5292 
5293 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5294 		return TEST_SKIPPED;
5295 
5296 	if (op_mode == OUT_OF_PLACE) {
5297 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5298 			return TEST_SKIPPED;
5299 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5300 			printf("Device doesn't support digest encrypted.\n");
5301 			return TEST_SKIPPED;
5302 		}
5303 	}
5304 
5305 	/* Create KASUMI session */
5306 	retval = create_wireless_algo_auth_cipher_session(
5307 			ts_params->valid_devs[0],
5308 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5309 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5310 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5311 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5312 			RTE_CRYPTO_AUTH_KASUMI_F9,
5313 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5314 			tdata->key.data, tdata->key.len,
5315 			0, tdata->digest.len,
5316 			tdata->cipher_iv.len);
5317 
5318 	if (retval != 0)
5319 		return retval;
5320 
5321 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5322 	if (op_mode == OUT_OF_PLACE)
5323 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5324 
5325 	/* clear mbuf payload */
5326 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5327 		rte_pktmbuf_tailroom(ut_params->ibuf));
5328 	if (op_mode == OUT_OF_PLACE)
5329 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5330 			rte_pktmbuf_tailroom(ut_params->obuf));
5331 
5332 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5333 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5334 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5335 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5336 
5337 	if (verify) {
5338 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5339 					ciphertext_pad_len);
5340 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5341 		if (op_mode == OUT_OF_PLACE)
5342 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5343 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5344 			ciphertext_len);
5345 	} else {
5346 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5347 					plaintext_pad_len);
5348 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5349 		if (op_mode == OUT_OF_PLACE)
5350 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5351 		debug_hexdump(stdout, "plaintext:", plaintext,
5352 			plaintext_len);
5353 	}
5354 
5355 	/* Create KASUMI operation */
5356 	retval = create_wireless_algo_auth_cipher_operation(
5357 		tdata->digest.data, tdata->digest.len,
5358 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5359 		NULL, 0,
5360 		(tdata->digest.offset_bytes == 0 ?
5361 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5362 			: tdata->digest.offset_bytes),
5363 		tdata->validCipherLenInBits.len,
5364 		tdata->validCipherOffsetInBits.len,
5365 		tdata->validAuthLenInBits.len,
5366 		0,
5367 		op_mode, 0, verify);
5368 
5369 	if (retval < 0)
5370 		return retval;
5371 
5372 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5373 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5374 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5375 	else
5376 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5377 			ut_params->op);
5378 
5379 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5380 
5381 	ut_params->obuf = (op_mode == IN_PLACE ?
5382 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5383 
5384 
5385 	if (verify) {
5386 		if (ut_params->obuf)
5387 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5388 							uint8_t *);
5389 		else
5390 			plaintext = ciphertext;
5391 
5392 		debug_hexdump(stdout, "plaintext:", plaintext,
5393 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5394 		debug_hexdump(stdout, "plaintext expected:",
5395 			tdata->plaintext.data,
5396 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5397 	} else {
5398 		if (ut_params->obuf)
5399 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5400 							uint8_t *);
5401 		else
5402 			ciphertext = plaintext;
5403 
5404 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5405 			ciphertext_len);
5406 		debug_hexdump(stdout, "ciphertext expected:",
5407 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5408 
5409 		ut_params->digest = rte_pktmbuf_mtod(
5410 			ut_params->obuf, uint8_t *) +
5411 			(tdata->digest.offset_bytes == 0 ?
5412 			plaintext_pad_len : tdata->digest.offset_bytes);
5413 
5414 		debug_hexdump(stdout, "digest:", ut_params->digest,
5415 			tdata->digest.len);
5416 		debug_hexdump(stdout, "digest expected:",
5417 			tdata->digest.data, tdata->digest.len);
5418 	}
5419 
5420 	/* Validate obuf */
5421 	if (verify) {
5422 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5423 			plaintext,
5424 			tdata->plaintext.data,
5425 			tdata->plaintext.len >> 3,
5426 			"KASUMI Plaintext data not as expected");
5427 	} else {
5428 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5429 			ciphertext,
5430 			tdata->ciphertext.data,
5431 			tdata->ciphertext.len >> 3,
5432 			"KASUMI Ciphertext data not as expected");
5433 
5434 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5435 			ut_params->digest,
5436 			tdata->digest.data,
5437 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5438 			"KASUMI Generated auth tag not as expected");
5439 	}
5440 	return 0;
5441 }
5442 
5443 static int
5444 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5445 	uint8_t op_mode, uint8_t verify)
5446 {
5447 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5448 	struct crypto_unittest_params *ut_params = &unittest_params;
5449 
5450 	int retval;
5451 
5452 	const uint8_t *plaintext = NULL;
5453 	const uint8_t *ciphertext = NULL;
5454 	const uint8_t *digest = NULL;
5455 	unsigned int plaintext_pad_len;
5456 	unsigned int plaintext_len;
5457 	unsigned int ciphertext_pad_len;
5458 	unsigned int ciphertext_len;
5459 	uint8_t buffer[10000];
5460 	uint8_t digest_buffer[10000];
5461 
5462 	struct rte_cryptodev_info dev_info;
5463 
5464 	/* Verify the capabilities */
5465 	struct rte_cryptodev_sym_capability_idx cap_idx;
5466 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5467 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5468 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5469 			&cap_idx) == NULL)
5470 		return TEST_SKIPPED;
5471 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5472 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5473 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5474 			&cap_idx) == NULL)
5475 		return TEST_SKIPPED;
5476 
5477 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5478 		return TEST_SKIPPED;
5479 
5480 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5481 
5482 	uint64_t feat_flags = dev_info.feature_flags;
5483 
5484 	if (op_mode == IN_PLACE) {
5485 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5486 			printf("Device doesn't support in-place scatter-gather "
5487 					"in both input and output mbufs.\n");
5488 			return TEST_SKIPPED;
5489 		}
5490 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5491 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5492 			printf("Device doesn't support RAW data-path APIs.\n");
5493 			return TEST_SKIPPED;
5494 		}
5495 	} else {
5496 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5497 			return TEST_SKIPPED;
5498 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5499 			printf("Device doesn't support out-of-place scatter-gather "
5500 					"in both input and output mbufs.\n");
5501 			return TEST_SKIPPED;
5502 		}
5503 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5504 			printf("Device doesn't support digest encrypted.\n");
5505 			return TEST_SKIPPED;
5506 		}
5507 	}
5508 
5509 	/* Create KASUMI session */
5510 	retval = create_wireless_algo_auth_cipher_session(
5511 			ts_params->valid_devs[0],
5512 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5513 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5514 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5515 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5516 			RTE_CRYPTO_AUTH_KASUMI_F9,
5517 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5518 			tdata->key.data, tdata->key.len,
5519 			0, tdata->digest.len,
5520 			tdata->cipher_iv.len);
5521 
5522 	if (retval != 0)
5523 		return retval;
5524 
5525 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5526 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5527 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5528 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5529 
5530 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5531 			plaintext_pad_len, 15, 0);
5532 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5533 			"Failed to allocate input buffer in mempool");
5534 
5535 	if (op_mode == OUT_OF_PLACE) {
5536 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5537 				plaintext_pad_len, 15, 0);
5538 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5539 				"Failed to allocate output buffer in mempool");
5540 	}
5541 
5542 	if (verify) {
5543 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5544 			tdata->ciphertext.data);
5545 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5546 					ciphertext_len, buffer);
5547 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5548 			ciphertext_len);
5549 	} else {
5550 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5551 			tdata->plaintext.data);
5552 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5553 					plaintext_len, buffer);
5554 		debug_hexdump(stdout, "plaintext:", plaintext,
5555 			plaintext_len);
5556 	}
5557 	memset(buffer, 0, sizeof(buffer));
5558 
5559 	/* Create KASUMI operation */
5560 	retval = create_wireless_algo_auth_cipher_operation(
5561 		tdata->digest.data, tdata->digest.len,
5562 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5563 		NULL, 0,
5564 		(tdata->digest.offset_bytes == 0 ?
5565 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5566 			: tdata->digest.offset_bytes),
5567 		tdata->validCipherLenInBits.len,
5568 		tdata->validCipherOffsetInBits.len,
5569 		tdata->validAuthLenInBits.len,
5570 		0,
5571 		op_mode, 1, verify);
5572 
5573 	if (retval < 0)
5574 		return retval;
5575 
5576 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5577 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5578 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5579 	else
5580 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5581 			ut_params->op);
5582 
5583 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5584 
5585 	ut_params->obuf = (op_mode == IN_PLACE ?
5586 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5587 
5588 	if (verify) {
5589 		if (ut_params->obuf)
5590 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5591 					plaintext_len, buffer);
5592 		else
5593 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5594 					plaintext_len, buffer);
5595 
5596 		debug_hexdump(stdout, "plaintext:", plaintext,
5597 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5598 		debug_hexdump(stdout, "plaintext expected:",
5599 			tdata->plaintext.data,
5600 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5601 	} else {
5602 		if (ut_params->obuf)
5603 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5604 					ciphertext_len, buffer);
5605 		else
5606 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5607 					ciphertext_len, buffer);
5608 
5609 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5610 			ciphertext_len);
5611 		debug_hexdump(stdout, "ciphertext expected:",
5612 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5613 
5614 		if (ut_params->obuf)
5615 			digest = rte_pktmbuf_read(ut_params->obuf,
5616 				(tdata->digest.offset_bytes == 0 ?
5617 				plaintext_pad_len : tdata->digest.offset_bytes),
5618 				tdata->digest.len, digest_buffer);
5619 		else
5620 			digest = rte_pktmbuf_read(ut_params->ibuf,
5621 				(tdata->digest.offset_bytes == 0 ?
5622 				plaintext_pad_len : tdata->digest.offset_bytes),
5623 				tdata->digest.len, digest_buffer);
5624 
5625 		debug_hexdump(stdout, "digest:", digest,
5626 			tdata->digest.len);
5627 		debug_hexdump(stdout, "digest expected:",
5628 			tdata->digest.data, tdata->digest.len);
5629 	}
5630 
5631 	/* Validate obuf */
5632 	if (verify) {
5633 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5634 			plaintext,
5635 			tdata->plaintext.data,
5636 			tdata->plaintext.len >> 3,
5637 			"KASUMI Plaintext data not as expected");
5638 	} else {
5639 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5640 			ciphertext,
5641 			tdata->ciphertext.data,
5642 			tdata->validDataLenInBits.len,
5643 			"KASUMI Ciphertext data not as expected");
5644 
5645 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5646 			digest,
5647 			tdata->digest.data,
5648 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5649 			"KASUMI Generated auth tag not as expected");
5650 	}
5651 	return 0;
5652 }
5653 
5654 static int
5655 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5656 {
5657 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5658 	struct crypto_unittest_params *ut_params = &unittest_params;
5659 
5660 	int retval;
5661 
5662 	uint8_t *plaintext, *ciphertext;
5663 	unsigned plaintext_pad_len;
5664 	unsigned plaintext_len;
5665 	struct rte_cryptodev_info dev_info;
5666 
5667 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5668 	uint64_t feat_flags = dev_info.feature_flags;
5669 
5670 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5671 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5672 		printf("Device doesn't support RAW data-path APIs.\n");
5673 		return TEST_SKIPPED;
5674 	}
5675 
5676 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5677 		return TEST_SKIPPED;
5678 
5679 	/* Verify the capabilities */
5680 	struct rte_cryptodev_sym_capability_idx cap_idx;
5681 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5682 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5683 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5684 			&cap_idx) == NULL)
5685 		return TEST_SKIPPED;
5686 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5687 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5688 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5689 			&cap_idx) == NULL)
5690 		return TEST_SKIPPED;
5691 
5692 	/* Create KASUMI session */
5693 	retval = create_wireless_algo_cipher_auth_session(
5694 			ts_params->valid_devs[0],
5695 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5696 			RTE_CRYPTO_AUTH_OP_GENERATE,
5697 			RTE_CRYPTO_AUTH_KASUMI_F9,
5698 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5699 			tdata->key.data, tdata->key.len,
5700 			0, tdata->digest.len,
5701 			tdata->cipher_iv.len);
5702 	if (retval != 0)
5703 		return retval;
5704 
5705 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5706 
5707 	/* clear mbuf payload */
5708 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5709 			rte_pktmbuf_tailroom(ut_params->ibuf));
5710 
5711 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5712 	/* Append data which is padded to a multiple of */
5713 	/* the algorithms block size */
5714 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5715 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5716 				plaintext_pad_len);
5717 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5718 
5719 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5720 
5721 	/* Create KASUMI operation */
5722 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5723 				tdata->digest.len, NULL, 0,
5724 				plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5725 				tdata->cipher_iv.data, tdata->cipher_iv.len,
5726 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5727 				tdata->validCipherOffsetInBits.len,
5728 				tdata->validAuthLenInBits.len,
5729 				0
5730 				);
5731 	if (retval < 0)
5732 		return retval;
5733 
5734 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5735 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5736 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5737 	else
5738 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5739 			ut_params->op);
5740 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5741 
5742 	if (ut_params->op->sym->m_dst)
5743 		ut_params->obuf = ut_params->op->sym->m_dst;
5744 	else
5745 		ut_params->obuf = ut_params->op->sym->m_src;
5746 
5747 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5748 				tdata->validCipherOffsetInBits.len >> 3);
5749 
5750 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5751 			+ plaintext_pad_len;
5752 
5753 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5754 				(tdata->validCipherOffsetInBits.len >> 3);
5755 	/* Validate obuf */
5756 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5757 		ciphertext,
5758 		reference_ciphertext,
5759 		tdata->validCipherLenInBits.len,
5760 		"KASUMI Ciphertext data not as expected");
5761 
5762 	/* Validate obuf */
5763 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
5764 		ut_params->digest,
5765 		tdata->digest.data,
5766 		DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5767 		"KASUMI Generated auth tag not as expected");
5768 	return 0;
5769 }
5770 
5771 static int
5772 test_zuc_encryption(const struct wireless_test_data *tdata)
5773 {
5774 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5775 	struct crypto_unittest_params *ut_params = &unittest_params;
5776 
5777 	int retval;
5778 	uint8_t *plaintext, *ciphertext;
5779 	unsigned plaintext_pad_len;
5780 	unsigned plaintext_len;
5781 	struct rte_cryptodev_info dev_info;
5782 
5783 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5784 	uint64_t feat_flags = dev_info.feature_flags;
5785 
5786 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5787 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5788 		printf("Device doesn't support RAW data-path APIs.\n");
5789 		return TEST_SKIPPED;
5790 	}
5791 
5792 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5793 		return TEST_SKIPPED;
5794 
5795 	struct rte_cryptodev_sym_capability_idx cap_idx;
5796 
5797 	/* Check if device supports ZUC EEA3 */
5798 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5799 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5800 
5801 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5802 			&cap_idx) == NULL)
5803 		return TEST_SKIPPED;
5804 
5805 	/* Create ZUC session */
5806 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5807 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5808 					RTE_CRYPTO_CIPHER_ZUC_EEA3,
5809 					tdata->key.data, tdata->key.len,
5810 					tdata->cipher_iv.len);
5811 	if (retval < 0)
5812 		return retval;
5813 
5814 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5815 
5816 	/* Clear mbuf payload */
5817 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5818 	       rte_pktmbuf_tailroom(ut_params->ibuf));
5819 
5820 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5821 	/* Append data which is padded to a multiple */
5822 	/* of the algorithms block size */
5823 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5824 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5825 				plaintext_pad_len);
5826 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5827 
5828 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5829 
5830 	/* Create ZUC operation */
5831 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5832 					tdata->cipher_iv.len,
5833 					tdata->plaintext.len,
5834 					0);
5835 	if (retval < 0)
5836 		return retval;
5837 
5838 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5839 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5840 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5841 	else
5842 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5843 						ut_params->op);
5844 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5845 
5846 	ut_params->obuf = ut_params->op->sym->m_dst;
5847 	if (ut_params->obuf)
5848 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5849 	else
5850 		ciphertext = plaintext;
5851 
5852 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5853 
5854 	/* Validate obuf */
5855 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5856 		ciphertext,
5857 		tdata->ciphertext.data,
5858 		tdata->validCipherLenInBits.len,
5859 		"ZUC Ciphertext data not as expected");
5860 	return 0;
5861 }
5862 
5863 static int
5864 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
5865 {
5866 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5867 	struct crypto_unittest_params *ut_params = &unittest_params;
5868 
5869 	int retval;
5870 
5871 	unsigned int plaintext_pad_len;
5872 	unsigned int plaintext_len;
5873 	const uint8_t *ciphertext;
5874 	uint8_t ciphertext_buffer[2048];
5875 	struct rte_cryptodev_info dev_info;
5876 
5877 	struct rte_cryptodev_sym_capability_idx cap_idx;
5878 
5879 	/* Check if device supports ZUC EEA3 */
5880 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5881 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5882 
5883 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5884 			&cap_idx) == NULL)
5885 		return TEST_SKIPPED;
5886 
5887 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5888 		return TEST_SKIPPED;
5889 
5890 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5891 
5892 	uint64_t feat_flags = dev_info.feature_flags;
5893 
5894 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5895 		printf("Device doesn't support in-place scatter-gather. "
5896 				"Test Skipped.\n");
5897 		return TEST_SKIPPED;
5898 	}
5899 
5900 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5901 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5902 		printf("Device doesn't support RAW data-path APIs.\n");
5903 		return TEST_SKIPPED;
5904 	}
5905 
5906 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5907 
5908 	/* Append data which is padded to a multiple */
5909 	/* of the algorithms block size */
5910 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5911 
5912 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5913 			plaintext_pad_len, 10, 0);
5914 
5915 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5916 			tdata->plaintext.data);
5917 
5918 	/* Create ZUC session */
5919 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5920 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5921 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
5922 			tdata->key.data, tdata->key.len,
5923 			tdata->cipher_iv.len);
5924 	if (retval < 0)
5925 		return retval;
5926 
5927 	/* Clear mbuf payload */
5928 
5929 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
5930 
5931 	/* Create ZUC operation */
5932 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5933 			tdata->cipher_iv.len, tdata->plaintext.len,
5934 			0);
5935 	if (retval < 0)
5936 		return retval;
5937 
5938 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5939 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5940 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5941 	else
5942 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5943 						ut_params->op);
5944 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5945 
5946 	ut_params->obuf = ut_params->op->sym->m_dst;
5947 	if (ut_params->obuf)
5948 		ciphertext = rte_pktmbuf_read(ut_params->obuf,
5949 			0, plaintext_len, ciphertext_buffer);
5950 	else
5951 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
5952 			0, plaintext_len, ciphertext_buffer);
5953 
5954 	/* Validate obuf */
5955 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5956 
5957 	/* Validate obuf */
5958 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5959 		ciphertext,
5960 		tdata->ciphertext.data,
5961 		tdata->validCipherLenInBits.len,
5962 		"ZUC Ciphertext data not as expected");
5963 
5964 	return 0;
5965 }
5966 
5967 static int
5968 test_zuc_authentication(const struct wireless_test_data *tdata)
5969 {
5970 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5971 	struct crypto_unittest_params *ut_params = &unittest_params;
5972 
5973 	int retval;
5974 	unsigned plaintext_pad_len;
5975 	unsigned plaintext_len;
5976 	uint8_t *plaintext;
5977 
5978 	struct rte_cryptodev_sym_capability_idx cap_idx;
5979 	struct rte_cryptodev_info dev_info;
5980 
5981 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5982 	uint64_t feat_flags = dev_info.feature_flags;
5983 
5984 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
5985 			(tdata->validAuthLenInBits.len % 8 != 0)) {
5986 		printf("Device doesn't support NON-Byte Aligned Data.\n");
5987 		return TEST_SKIPPED;
5988 	}
5989 
5990 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5991 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5992 		printf("Device doesn't support RAW data-path APIs.\n");
5993 		return TEST_SKIPPED;
5994 	}
5995 
5996 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5997 		return TEST_SKIPPED;
5998 
5999 	/* Check if device supports ZUC EIA3 */
6000 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6001 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6002 
6003 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6004 			&cap_idx) == NULL)
6005 		return TEST_SKIPPED;
6006 
6007 	/* Create ZUC session */
6008 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
6009 			tdata->key.data, tdata->key.len,
6010 			tdata->auth_iv.len, tdata->digest.len,
6011 			RTE_CRYPTO_AUTH_OP_GENERATE,
6012 			RTE_CRYPTO_AUTH_ZUC_EIA3);
6013 	if (retval < 0)
6014 		return retval;
6015 
6016 	/* alloc mbuf and set payload */
6017 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6018 
6019 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6020 	rte_pktmbuf_tailroom(ut_params->ibuf));
6021 
6022 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6023 	/* Append data which is padded to a multiple of */
6024 	/* the algorithms block size */
6025 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6026 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6027 				plaintext_pad_len);
6028 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6029 
6030 	/* Create ZUC operation */
6031 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
6032 			tdata->auth_iv.data, tdata->auth_iv.len,
6033 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
6034 			tdata->validAuthLenInBits.len,
6035 			0);
6036 	if (retval < 0)
6037 		return retval;
6038 
6039 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6040 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6041 				ut_params->op, 0, 1, 1, 0);
6042 	else
6043 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6044 				ut_params->op);
6045 	ut_params->obuf = ut_params->op->sym->m_src;
6046 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6047 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6048 			+ plaintext_pad_len;
6049 
6050 	/* Validate obuf */
6051 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
6052 	ut_params->digest,
6053 	tdata->digest.data,
6054 	tdata->digest.len,
6055 	"ZUC Generated auth tag not as expected");
6056 
6057 	return 0;
6058 }
6059 
6060 static int
6061 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
6062 	uint8_t op_mode, uint8_t verify)
6063 {
6064 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6065 	struct crypto_unittest_params *ut_params = &unittest_params;
6066 
6067 	int retval;
6068 
6069 	uint8_t *plaintext = NULL, *ciphertext = NULL;
6070 	unsigned int plaintext_pad_len;
6071 	unsigned int plaintext_len;
6072 	unsigned int ciphertext_pad_len;
6073 	unsigned int ciphertext_len;
6074 
6075 	struct rte_cryptodev_info dev_info;
6076 	struct rte_cryptodev_sym_capability_idx cap_idx;
6077 
6078 	/* Check if device supports ZUC EIA3 */
6079 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6080 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6081 
6082 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6083 			&cap_idx) == NULL)
6084 		return TEST_SKIPPED;
6085 
6086 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6087 
6088 	uint64_t feat_flags = dev_info.feature_flags;
6089 
6090 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6091 		printf("Device doesn't support digest encrypted.\n");
6092 		return TEST_SKIPPED;
6093 	}
6094 	if (op_mode == IN_PLACE) {
6095 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6096 			printf("Device doesn't support in-place scatter-gather "
6097 					"in both input and output mbufs.\n");
6098 			return TEST_SKIPPED;
6099 		}
6100 
6101 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6102 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6103 			printf("Device doesn't support RAW data-path APIs.\n");
6104 			return TEST_SKIPPED;
6105 		}
6106 	} else {
6107 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6108 			return TEST_SKIPPED;
6109 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6110 			printf("Device doesn't support out-of-place scatter-gather "
6111 					"in both input and output mbufs.\n");
6112 			return TEST_SKIPPED;
6113 		}
6114 	}
6115 
6116 	/* Create ZUC session */
6117 	retval = create_wireless_algo_auth_cipher_session(
6118 			ts_params->valid_devs[0],
6119 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6120 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6121 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6122 					: RTE_CRYPTO_AUTH_OP_GENERATE),
6123 			RTE_CRYPTO_AUTH_ZUC_EIA3,
6124 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6125 			tdata->key.data, tdata->key.len,
6126 			tdata->auth_iv.len, tdata->digest.len,
6127 			tdata->cipher_iv.len);
6128 
6129 	if (retval != 0)
6130 		return retval;
6131 
6132 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6133 	if (op_mode == OUT_OF_PLACE)
6134 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6135 
6136 	/* clear mbuf payload */
6137 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6138 		rte_pktmbuf_tailroom(ut_params->ibuf));
6139 	if (op_mode == OUT_OF_PLACE)
6140 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6141 			rte_pktmbuf_tailroom(ut_params->obuf));
6142 
6143 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6144 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6145 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6146 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6147 
6148 	if (verify) {
6149 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6150 					ciphertext_pad_len);
6151 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6152 		if (op_mode == OUT_OF_PLACE)
6153 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6154 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6155 			ciphertext_len);
6156 	} else {
6157 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6158 					plaintext_pad_len);
6159 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6160 		if (op_mode == OUT_OF_PLACE)
6161 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
6162 		debug_hexdump(stdout, "plaintext:", plaintext,
6163 			plaintext_len);
6164 	}
6165 
6166 	/* Create ZUC operation */
6167 	retval = create_wireless_algo_auth_cipher_operation(
6168 		tdata->digest.data, tdata->digest.len,
6169 		tdata->cipher_iv.data, tdata->cipher_iv.len,
6170 		tdata->auth_iv.data, tdata->auth_iv.len,
6171 		(tdata->digest.offset_bytes == 0 ?
6172 		(verify ? ciphertext_pad_len : plaintext_pad_len)
6173 			: tdata->digest.offset_bytes),
6174 		tdata->validCipherLenInBits.len,
6175 		tdata->validCipherOffsetInBits.len,
6176 		tdata->validAuthLenInBits.len,
6177 		0,
6178 		op_mode, 0, verify);
6179 
6180 	if (retval < 0)
6181 		return retval;
6182 
6183 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6184 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6185 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6186 	else
6187 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6188 			ut_params->op);
6189 
6190 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6191 
6192 	ut_params->obuf = (op_mode == IN_PLACE ?
6193 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6194 
6195 
6196 	if (verify) {
6197 		if (ut_params->obuf)
6198 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6199 							uint8_t *);
6200 		else
6201 			plaintext = ciphertext;
6202 
6203 		debug_hexdump(stdout, "plaintext:", plaintext,
6204 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6205 		debug_hexdump(stdout, "plaintext expected:",
6206 			tdata->plaintext.data,
6207 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6208 	} else {
6209 		if (ut_params->obuf)
6210 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6211 							uint8_t *);
6212 		else
6213 			ciphertext = plaintext;
6214 
6215 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6216 			ciphertext_len);
6217 		debug_hexdump(stdout, "ciphertext expected:",
6218 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6219 
6220 		ut_params->digest = rte_pktmbuf_mtod(
6221 			ut_params->obuf, uint8_t *) +
6222 			(tdata->digest.offset_bytes == 0 ?
6223 			plaintext_pad_len : tdata->digest.offset_bytes);
6224 
6225 		debug_hexdump(stdout, "digest:", ut_params->digest,
6226 			tdata->digest.len);
6227 		debug_hexdump(stdout, "digest expected:",
6228 			tdata->digest.data, tdata->digest.len);
6229 	}
6230 
6231 	/* Validate obuf */
6232 	if (verify) {
6233 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6234 			plaintext,
6235 			tdata->plaintext.data,
6236 			tdata->plaintext.len >> 3,
6237 			"ZUC Plaintext data not as expected");
6238 	} else {
6239 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6240 			ciphertext,
6241 			tdata->ciphertext.data,
6242 			tdata->ciphertext.len >> 3,
6243 			"ZUC Ciphertext data not as expected");
6244 
6245 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6246 			ut_params->digest,
6247 			tdata->digest.data,
6248 			DIGEST_BYTE_LENGTH_KASUMI_F9,
6249 			"ZUC Generated auth tag not as expected");
6250 	}
6251 	return 0;
6252 }
6253 
6254 static int
6255 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
6256 	uint8_t op_mode, uint8_t verify)
6257 {
6258 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6259 	struct crypto_unittest_params *ut_params = &unittest_params;
6260 
6261 	int retval;
6262 
6263 	const uint8_t *plaintext = NULL;
6264 	const uint8_t *ciphertext = NULL;
6265 	const uint8_t *digest = NULL;
6266 	unsigned int plaintext_pad_len;
6267 	unsigned int plaintext_len;
6268 	unsigned int ciphertext_pad_len;
6269 	unsigned int ciphertext_len;
6270 	uint8_t buffer[10000];
6271 	uint8_t digest_buffer[10000];
6272 
6273 	struct rte_cryptodev_info dev_info;
6274 	struct rte_cryptodev_sym_capability_idx cap_idx;
6275 
6276 	/* Check if device supports ZUC EIA3 */
6277 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6278 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6279 
6280 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6281 			&cap_idx) == NULL)
6282 		return TEST_SKIPPED;
6283 
6284 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6285 
6286 	uint64_t feat_flags = dev_info.feature_flags;
6287 
6288 	if (op_mode == IN_PLACE) {
6289 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6290 			printf("Device doesn't support in-place scatter-gather "
6291 					"in both input and output mbufs.\n");
6292 			return TEST_SKIPPED;
6293 		}
6294 
6295 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6296 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6297 			printf("Device doesn't support RAW data-path APIs.\n");
6298 			return TEST_SKIPPED;
6299 		}
6300 	} else {
6301 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6302 			return TEST_SKIPPED;
6303 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6304 			printf("Device doesn't support out-of-place scatter-gather "
6305 					"in both input and output mbufs.\n");
6306 			return TEST_SKIPPED;
6307 		}
6308 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6309 			printf("Device doesn't support digest encrypted.\n");
6310 			return TEST_SKIPPED;
6311 		}
6312 	}
6313 
6314 	/* Create ZUC session */
6315 	retval = create_wireless_algo_auth_cipher_session(
6316 			ts_params->valid_devs[0],
6317 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6318 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6319 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6320 					: RTE_CRYPTO_AUTH_OP_GENERATE),
6321 			RTE_CRYPTO_AUTH_ZUC_EIA3,
6322 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6323 			tdata->key.data, tdata->key.len,
6324 			tdata->auth_iv.len, tdata->digest.len,
6325 			tdata->cipher_iv.len);
6326 
6327 	if (retval != 0)
6328 		return retval;
6329 
6330 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6331 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6332 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6333 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6334 
6335 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6336 			plaintext_pad_len, 15, 0);
6337 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6338 			"Failed to allocate input buffer in mempool");
6339 
6340 	if (op_mode == OUT_OF_PLACE) {
6341 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6342 				plaintext_pad_len, 15, 0);
6343 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
6344 				"Failed to allocate output buffer in mempool");
6345 	}
6346 
6347 	if (verify) {
6348 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6349 			tdata->ciphertext.data);
6350 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6351 					ciphertext_len, buffer);
6352 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6353 			ciphertext_len);
6354 	} else {
6355 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6356 			tdata->plaintext.data);
6357 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6358 					plaintext_len, buffer);
6359 		debug_hexdump(stdout, "plaintext:", plaintext,
6360 			plaintext_len);
6361 	}
6362 	memset(buffer, 0, sizeof(buffer));
6363 
6364 	/* Create ZUC operation */
6365 	retval = create_wireless_algo_auth_cipher_operation(
6366 		tdata->digest.data, tdata->digest.len,
6367 		tdata->cipher_iv.data, tdata->cipher_iv.len,
6368 		NULL, 0,
6369 		(tdata->digest.offset_bytes == 0 ?
6370 		(verify ? ciphertext_pad_len : plaintext_pad_len)
6371 			: tdata->digest.offset_bytes),
6372 		tdata->validCipherLenInBits.len,
6373 		tdata->validCipherOffsetInBits.len,
6374 		tdata->validAuthLenInBits.len,
6375 		0,
6376 		op_mode, 1, verify);
6377 
6378 	if (retval < 0)
6379 		return retval;
6380 
6381 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6382 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6383 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6384 	else
6385 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6386 			ut_params->op);
6387 
6388 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6389 
6390 	ut_params->obuf = (op_mode == IN_PLACE ?
6391 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6392 
6393 	if (verify) {
6394 		if (ut_params->obuf)
6395 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6396 					plaintext_len, buffer);
6397 		else
6398 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6399 					plaintext_len, buffer);
6400 
6401 		debug_hexdump(stdout, "plaintext:", plaintext,
6402 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6403 		debug_hexdump(stdout, "plaintext expected:",
6404 			tdata->plaintext.data,
6405 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6406 	} else {
6407 		if (ut_params->obuf)
6408 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6409 					ciphertext_len, buffer);
6410 		else
6411 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6412 					ciphertext_len, buffer);
6413 
6414 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6415 			ciphertext_len);
6416 		debug_hexdump(stdout, "ciphertext expected:",
6417 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6418 
6419 		if (ut_params->obuf)
6420 			digest = rte_pktmbuf_read(ut_params->obuf,
6421 				(tdata->digest.offset_bytes == 0 ?
6422 				plaintext_pad_len : tdata->digest.offset_bytes),
6423 				tdata->digest.len, digest_buffer);
6424 		else
6425 			digest = rte_pktmbuf_read(ut_params->ibuf,
6426 				(tdata->digest.offset_bytes == 0 ?
6427 				plaintext_pad_len : tdata->digest.offset_bytes),
6428 				tdata->digest.len, digest_buffer);
6429 
6430 		debug_hexdump(stdout, "digest:", digest,
6431 			tdata->digest.len);
6432 		debug_hexdump(stdout, "digest expected:",
6433 			tdata->digest.data, tdata->digest.len);
6434 	}
6435 
6436 	/* Validate obuf */
6437 	if (verify) {
6438 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6439 			plaintext,
6440 			tdata->plaintext.data,
6441 			tdata->plaintext.len >> 3,
6442 			"ZUC Plaintext data not as expected");
6443 	} else {
6444 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6445 			ciphertext,
6446 			tdata->ciphertext.data,
6447 			tdata->validDataLenInBits.len,
6448 			"ZUC Ciphertext data not as expected");
6449 
6450 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6451 			digest,
6452 			tdata->digest.data,
6453 			DIGEST_BYTE_LENGTH_KASUMI_F9,
6454 			"ZUC Generated auth tag not as expected");
6455 	}
6456 	return 0;
6457 }
6458 
6459 static int
6460 test_kasumi_encryption_test_case_1(void)
6461 {
6462 	return test_kasumi_encryption(&kasumi_test_case_1);
6463 }
6464 
6465 static int
6466 test_kasumi_encryption_test_case_1_sgl(void)
6467 {
6468 	return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6469 }
6470 
6471 static int
6472 test_kasumi_encryption_test_case_1_oop(void)
6473 {
6474 	return test_kasumi_encryption_oop(&kasumi_test_case_1);
6475 }
6476 
6477 static int
6478 test_kasumi_encryption_test_case_1_oop_sgl(void)
6479 {
6480 	return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6481 }
6482 
6483 static int
6484 test_kasumi_encryption_test_case_2(void)
6485 {
6486 	return test_kasumi_encryption(&kasumi_test_case_2);
6487 }
6488 
6489 static int
6490 test_kasumi_encryption_test_case_3(void)
6491 {
6492 	return test_kasumi_encryption(&kasumi_test_case_3);
6493 }
6494 
6495 static int
6496 test_kasumi_encryption_test_case_4(void)
6497 {
6498 	return test_kasumi_encryption(&kasumi_test_case_4);
6499 }
6500 
6501 static int
6502 test_kasumi_encryption_test_case_5(void)
6503 {
6504 	return test_kasumi_encryption(&kasumi_test_case_5);
6505 }
6506 
6507 static int
6508 test_kasumi_decryption_test_case_1(void)
6509 {
6510 	return test_kasumi_decryption(&kasumi_test_case_1);
6511 }
6512 
6513 static int
6514 test_kasumi_decryption_test_case_1_oop(void)
6515 {
6516 	return test_kasumi_decryption_oop(&kasumi_test_case_1);
6517 }
6518 
6519 static int
6520 test_kasumi_decryption_test_case_2(void)
6521 {
6522 	return test_kasumi_decryption(&kasumi_test_case_2);
6523 }
6524 
6525 static int
6526 test_kasumi_decryption_test_case_3(void)
6527 {
6528 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6529 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6530 		return TEST_SKIPPED;
6531 	return test_kasumi_decryption(&kasumi_test_case_3);
6532 }
6533 
6534 static int
6535 test_kasumi_decryption_test_case_4(void)
6536 {
6537 	return test_kasumi_decryption(&kasumi_test_case_4);
6538 }
6539 
6540 static int
6541 test_kasumi_decryption_test_case_5(void)
6542 {
6543 	return test_kasumi_decryption(&kasumi_test_case_5);
6544 }
6545 static int
6546 test_snow3g_encryption_test_case_1(void)
6547 {
6548 	return test_snow3g_encryption(&snow3g_test_case_1);
6549 }
6550 
6551 static int
6552 test_snow3g_encryption_test_case_1_oop(void)
6553 {
6554 	return test_snow3g_encryption_oop(&snow3g_test_case_1);
6555 }
6556 
6557 static int
6558 test_snow3g_encryption_test_case_1_oop_sgl(void)
6559 {
6560 	return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6561 }
6562 
6563 
6564 static int
6565 test_snow3g_encryption_test_case_1_offset_oop(void)
6566 {
6567 	return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6568 }
6569 
6570 static int
6571 test_snow3g_encryption_test_case_2(void)
6572 {
6573 	return test_snow3g_encryption(&snow3g_test_case_2);
6574 }
6575 
6576 static int
6577 test_snow3g_encryption_test_case_3(void)
6578 {
6579 	return test_snow3g_encryption(&snow3g_test_case_3);
6580 }
6581 
6582 static int
6583 test_snow3g_encryption_test_case_4(void)
6584 {
6585 	return test_snow3g_encryption(&snow3g_test_case_4);
6586 }
6587 
6588 static int
6589 test_snow3g_encryption_test_case_5(void)
6590 {
6591 	return test_snow3g_encryption(&snow3g_test_case_5);
6592 }
6593 
6594 static int
6595 test_snow3g_decryption_test_case_1(void)
6596 {
6597 	return test_snow3g_decryption(&snow3g_test_case_1);
6598 }
6599 
6600 static int
6601 test_snow3g_decryption_test_case_1_oop(void)
6602 {
6603 	return test_snow3g_decryption_oop(&snow3g_test_case_1);
6604 }
6605 
6606 static int
6607 test_snow3g_decryption_test_case_2(void)
6608 {
6609 	return test_snow3g_decryption(&snow3g_test_case_2);
6610 }
6611 
6612 static int
6613 test_snow3g_decryption_test_case_3(void)
6614 {
6615 	return test_snow3g_decryption(&snow3g_test_case_3);
6616 }
6617 
6618 static int
6619 test_snow3g_decryption_test_case_4(void)
6620 {
6621 	return test_snow3g_decryption(&snow3g_test_case_4);
6622 }
6623 
6624 static int
6625 test_snow3g_decryption_test_case_5(void)
6626 {
6627 	return test_snow3g_decryption(&snow3g_test_case_5);
6628 }
6629 
6630 /*
6631  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6632  * Pattern digest from snow3g_test_data must be allocated as
6633  * 4 last bytes in plaintext.
6634  */
6635 static void
6636 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6637 		struct snow3g_hash_test_data *output)
6638 {
6639 	if ((pattern != NULL) && (output != NULL)) {
6640 		output->key.len = pattern->key.len;
6641 
6642 		memcpy(output->key.data,
6643 		pattern->key.data, pattern->key.len);
6644 
6645 		output->auth_iv.len = pattern->auth_iv.len;
6646 
6647 		memcpy(output->auth_iv.data,
6648 		pattern->auth_iv.data, pattern->auth_iv.len);
6649 
6650 		output->plaintext.len = pattern->plaintext.len;
6651 
6652 		memcpy(output->plaintext.data,
6653 		pattern->plaintext.data, pattern->plaintext.len >> 3);
6654 
6655 		output->digest.len = pattern->digest.len;
6656 
6657 		memcpy(output->digest.data,
6658 		&pattern->plaintext.data[pattern->digest.offset_bytes],
6659 		pattern->digest.len);
6660 
6661 		output->validAuthLenInBits.len =
6662 		pattern->validAuthLenInBits.len;
6663 	}
6664 }
6665 
6666 /*
6667  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6668  */
6669 static int
6670 test_snow3g_decryption_with_digest_test_case_1(void)
6671 {
6672 	struct snow3g_hash_test_data snow3g_hash_data;
6673 	struct rte_cryptodev_info dev_info;
6674 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6675 
6676 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6677 	uint64_t feat_flags = dev_info.feature_flags;
6678 
6679 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6680 		printf("Device doesn't support encrypted digest operations.\n");
6681 		return TEST_SKIPPED;
6682 	}
6683 
6684 	/*
6685 	 * Function prepare data for hash veryfication test case.
6686 	 * Digest is allocated in 4 last bytes in plaintext, pattern.
6687 	 */
6688 	snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6689 
6690 	return test_snow3g_decryption(&snow3g_test_case_7) &
6691 			test_snow3g_authentication_verify(&snow3g_hash_data);
6692 }
6693 
6694 static int
6695 test_snow3g_cipher_auth_test_case_1(void)
6696 {
6697 	return test_snow3g_cipher_auth(&snow3g_test_case_3);
6698 }
6699 
6700 static int
6701 test_snow3g_auth_cipher_test_case_1(void)
6702 {
6703 	return test_snow3g_auth_cipher(
6704 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6705 }
6706 
6707 static int
6708 test_snow3g_auth_cipher_test_case_2(void)
6709 {
6710 	return test_snow3g_auth_cipher(
6711 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6712 }
6713 
6714 static int
6715 test_snow3g_auth_cipher_test_case_2_oop(void)
6716 {
6717 	return test_snow3g_auth_cipher(
6718 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6719 }
6720 
6721 static int
6722 test_snow3g_auth_cipher_part_digest_enc(void)
6723 {
6724 	return test_snow3g_auth_cipher(
6725 		&snow3g_auth_cipher_partial_digest_encryption,
6726 			IN_PLACE, 0);
6727 }
6728 
6729 static int
6730 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6731 {
6732 	return test_snow3g_auth_cipher(
6733 		&snow3g_auth_cipher_partial_digest_encryption,
6734 			OUT_OF_PLACE, 0);
6735 }
6736 
6737 static int
6738 test_snow3g_auth_cipher_test_case_3_sgl(void)
6739 {
6740 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6741 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6742 		return TEST_SKIPPED;
6743 	return test_snow3g_auth_cipher_sgl(
6744 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6745 }
6746 
6747 static int
6748 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6749 {
6750 	return test_snow3g_auth_cipher_sgl(
6751 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6752 }
6753 
6754 static int
6755 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6756 {
6757 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6758 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6759 		return TEST_SKIPPED;
6760 	return test_snow3g_auth_cipher_sgl(
6761 		&snow3g_auth_cipher_partial_digest_encryption,
6762 			IN_PLACE, 0);
6763 }
6764 
6765 static int
6766 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6767 {
6768 	return test_snow3g_auth_cipher_sgl(
6769 		&snow3g_auth_cipher_partial_digest_encryption,
6770 			OUT_OF_PLACE, 0);
6771 }
6772 
6773 static int
6774 test_snow3g_auth_cipher_verify_test_case_1(void)
6775 {
6776 	return test_snow3g_auth_cipher(
6777 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6778 }
6779 
6780 static int
6781 test_snow3g_auth_cipher_verify_test_case_2(void)
6782 {
6783 	return test_snow3g_auth_cipher(
6784 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6785 }
6786 
6787 static int
6788 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6789 {
6790 	return test_snow3g_auth_cipher(
6791 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6792 }
6793 
6794 static int
6795 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6796 {
6797 	return test_snow3g_auth_cipher(
6798 		&snow3g_auth_cipher_partial_digest_encryption,
6799 			IN_PLACE, 1);
6800 }
6801 
6802 static int
6803 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
6804 {
6805 	return test_snow3g_auth_cipher(
6806 		&snow3g_auth_cipher_partial_digest_encryption,
6807 			OUT_OF_PLACE, 1);
6808 }
6809 
6810 static int
6811 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
6812 {
6813 	return test_snow3g_auth_cipher_sgl(
6814 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
6815 }
6816 
6817 static int
6818 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
6819 {
6820 	return test_snow3g_auth_cipher_sgl(
6821 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
6822 }
6823 
6824 static int
6825 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
6826 {
6827 	return test_snow3g_auth_cipher_sgl(
6828 		&snow3g_auth_cipher_partial_digest_encryption,
6829 			IN_PLACE, 1);
6830 }
6831 
6832 static int
6833 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
6834 {
6835 	return test_snow3g_auth_cipher_sgl(
6836 		&snow3g_auth_cipher_partial_digest_encryption,
6837 			OUT_OF_PLACE, 1);
6838 }
6839 
6840 static int
6841 test_snow3g_auth_cipher_with_digest_test_case_1(void)
6842 {
6843 	return test_snow3g_auth_cipher(
6844 		&snow3g_test_case_7, IN_PLACE, 0);
6845 }
6846 
6847 static int
6848 test_kasumi_auth_cipher_test_case_1(void)
6849 {
6850 	return test_kasumi_auth_cipher(
6851 		&kasumi_test_case_3, IN_PLACE, 0);
6852 }
6853 
6854 static int
6855 test_kasumi_auth_cipher_test_case_2(void)
6856 {
6857 	return test_kasumi_auth_cipher(
6858 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6859 }
6860 
6861 static int
6862 test_kasumi_auth_cipher_test_case_2_oop(void)
6863 {
6864 	return test_kasumi_auth_cipher(
6865 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6866 }
6867 
6868 static int
6869 test_kasumi_auth_cipher_test_case_2_sgl(void)
6870 {
6871 	return test_kasumi_auth_cipher_sgl(
6872 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6873 }
6874 
6875 static int
6876 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
6877 {
6878 	return test_kasumi_auth_cipher_sgl(
6879 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6880 }
6881 
6882 static int
6883 test_kasumi_auth_cipher_verify_test_case_1(void)
6884 {
6885 	return test_kasumi_auth_cipher(
6886 		&kasumi_test_case_3, IN_PLACE, 1);
6887 }
6888 
6889 static int
6890 test_kasumi_auth_cipher_verify_test_case_2(void)
6891 {
6892 	return test_kasumi_auth_cipher(
6893 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6894 }
6895 
6896 static int
6897 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
6898 {
6899 	return test_kasumi_auth_cipher(
6900 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6901 }
6902 
6903 static int
6904 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
6905 {
6906 	return test_kasumi_auth_cipher_sgl(
6907 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
6908 }
6909 
6910 static int
6911 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
6912 {
6913 	return test_kasumi_auth_cipher_sgl(
6914 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6915 }
6916 
6917 static int
6918 test_kasumi_cipher_auth_test_case_1(void)
6919 {
6920 	return test_kasumi_cipher_auth(&kasumi_test_case_6);
6921 }
6922 
6923 static int
6924 test_zuc_encryption_test_case_1(void)
6925 {
6926 	return test_zuc_encryption(&zuc_test_case_cipher_193b);
6927 }
6928 
6929 static int
6930 test_zuc_encryption_test_case_2(void)
6931 {
6932 	return test_zuc_encryption(&zuc_test_case_cipher_800b);
6933 }
6934 
6935 static int
6936 test_zuc_encryption_test_case_3(void)
6937 {
6938 	return test_zuc_encryption(&zuc_test_case_cipher_1570b);
6939 }
6940 
6941 static int
6942 test_zuc_encryption_test_case_4(void)
6943 {
6944 	return test_zuc_encryption(&zuc_test_case_cipher_2798b);
6945 }
6946 
6947 static int
6948 test_zuc_encryption_test_case_5(void)
6949 {
6950 	return test_zuc_encryption(&zuc_test_case_cipher_4019b);
6951 }
6952 
6953 static int
6954 test_zuc_encryption_test_case_6_sgl(void)
6955 {
6956 	return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
6957 }
6958 
6959 static int
6960 test_zuc_hash_generate_test_case_1(void)
6961 {
6962 	return test_zuc_authentication(&zuc_test_case_auth_1b);
6963 }
6964 
6965 static int
6966 test_zuc_hash_generate_test_case_2(void)
6967 {
6968 	return test_zuc_authentication(&zuc_test_case_auth_90b);
6969 }
6970 
6971 static int
6972 test_zuc_hash_generate_test_case_3(void)
6973 {
6974 	return test_zuc_authentication(&zuc_test_case_auth_577b);
6975 }
6976 
6977 static int
6978 test_zuc_hash_generate_test_case_4(void)
6979 {
6980 	return test_zuc_authentication(&zuc_test_case_auth_2079b);
6981 }
6982 
6983 static int
6984 test_zuc_hash_generate_test_case_5(void)
6985 {
6986 	return test_zuc_authentication(&zuc_test_auth_5670b);
6987 }
6988 
6989 static int
6990 test_zuc_hash_generate_test_case_6(void)
6991 {
6992 	return test_zuc_authentication(&zuc_test_case_auth_128b);
6993 }
6994 
6995 static int
6996 test_zuc_hash_generate_test_case_7(void)
6997 {
6998 	return test_zuc_authentication(&zuc_test_case_auth_2080b);
6999 }
7000 
7001 static int
7002 test_zuc_hash_generate_test_case_8(void)
7003 {
7004 	return test_zuc_authentication(&zuc_test_case_auth_584b);
7005 }
7006 
7007 static int
7008 test_zuc_cipher_auth_test_case_1(void)
7009 {
7010 	return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
7011 }
7012 
7013 static int
7014 test_zuc_cipher_auth_test_case_2(void)
7015 {
7016 	return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
7017 }
7018 
7019 static int
7020 test_zuc_auth_cipher_test_case_1(void)
7021 {
7022 	return test_zuc_auth_cipher(
7023 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7024 }
7025 
7026 static int
7027 test_zuc_auth_cipher_test_case_1_oop(void)
7028 {
7029 	return test_zuc_auth_cipher(
7030 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7031 }
7032 
7033 static int
7034 test_zuc_auth_cipher_test_case_1_sgl(void)
7035 {
7036 	return test_zuc_auth_cipher_sgl(
7037 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7038 }
7039 
7040 static int
7041 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
7042 {
7043 	return test_zuc_auth_cipher_sgl(
7044 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7045 }
7046 
7047 static int
7048 test_zuc_auth_cipher_verify_test_case_1(void)
7049 {
7050 	return test_zuc_auth_cipher(
7051 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7052 }
7053 
7054 static int
7055 test_zuc_auth_cipher_verify_test_case_1_oop(void)
7056 {
7057 	return test_zuc_auth_cipher(
7058 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7059 }
7060 
7061 static int
7062 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
7063 {
7064 	return test_zuc_auth_cipher_sgl(
7065 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7066 }
7067 
7068 static int
7069 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
7070 {
7071 	return test_zuc_auth_cipher_sgl(
7072 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7073 }
7074 
7075 static int
7076 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
7077 {
7078 	uint8_t dev_id = testsuite_params.valid_devs[0];
7079 
7080 	struct rte_cryptodev_sym_capability_idx cap_idx;
7081 
7082 	/* Check if device supports particular cipher algorithm */
7083 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7084 	cap_idx.algo.cipher = tdata->cipher_algo;
7085 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7086 		return TEST_SKIPPED;
7087 
7088 	/* Check if device supports particular hash algorithm */
7089 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7090 	cap_idx.algo.auth = tdata->auth_algo;
7091 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7092 		return TEST_SKIPPED;
7093 
7094 	return 0;
7095 }
7096 
7097 static int
7098 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
7099 	uint8_t op_mode, uint8_t verify)
7100 {
7101 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7102 	struct crypto_unittest_params *ut_params = &unittest_params;
7103 
7104 	int retval;
7105 
7106 	uint8_t *plaintext = NULL, *ciphertext = NULL;
7107 	unsigned int plaintext_pad_len;
7108 	unsigned int plaintext_len;
7109 	unsigned int ciphertext_pad_len;
7110 	unsigned int ciphertext_len;
7111 
7112 	struct rte_cryptodev_info dev_info;
7113 	struct rte_crypto_op *op;
7114 
7115 	/* Check if device supports particular algorithms separately */
7116 	if (test_mixed_check_if_unsupported(tdata))
7117 		return TEST_SKIPPED;
7118 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7119 		return TEST_SKIPPED;
7120 
7121 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7122 
7123 	uint64_t feat_flags = dev_info.feature_flags;
7124 
7125 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7126 		printf("Device doesn't support digest encrypted.\n");
7127 		return TEST_SKIPPED;
7128 	}
7129 
7130 	/* Create the session */
7131 	if (verify)
7132 		retval = create_wireless_algo_cipher_auth_session(
7133 				ts_params->valid_devs[0],
7134 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
7135 				RTE_CRYPTO_AUTH_OP_VERIFY,
7136 				tdata->auth_algo,
7137 				tdata->cipher_algo,
7138 				tdata->auth_key.data, tdata->auth_key.len,
7139 				tdata->auth_iv.len, tdata->digest_enc.len,
7140 				tdata->cipher_iv.len);
7141 	else
7142 		retval = create_wireless_algo_auth_cipher_session(
7143 				ts_params->valid_devs[0],
7144 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7145 				RTE_CRYPTO_AUTH_OP_GENERATE,
7146 				tdata->auth_algo,
7147 				tdata->cipher_algo,
7148 				tdata->auth_key.data, tdata->auth_key.len,
7149 				tdata->auth_iv.len, tdata->digest_enc.len,
7150 				tdata->cipher_iv.len);
7151 	if (retval != 0)
7152 		return retval;
7153 
7154 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7155 	if (op_mode == OUT_OF_PLACE)
7156 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7157 
7158 	/* clear mbuf payload */
7159 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7160 		rte_pktmbuf_tailroom(ut_params->ibuf));
7161 	if (op_mode == OUT_OF_PLACE) {
7162 
7163 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
7164 				rte_pktmbuf_tailroom(ut_params->obuf));
7165 	}
7166 
7167 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7168 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7169 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7170 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7171 
7172 	if (verify) {
7173 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7174 				ciphertext_pad_len);
7175 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
7176 		if (op_mode == OUT_OF_PLACE)
7177 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
7178 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7179 				ciphertext_len);
7180 	} else {
7181 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7182 				plaintext_pad_len);
7183 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7184 		if (op_mode == OUT_OF_PLACE)
7185 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
7186 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
7187 	}
7188 
7189 	/* Create the operation */
7190 	retval = create_wireless_algo_auth_cipher_operation(
7191 			tdata->digest_enc.data, tdata->digest_enc.len,
7192 			tdata->cipher_iv.data, tdata->cipher_iv.len,
7193 			tdata->auth_iv.data, tdata->auth_iv.len,
7194 			(tdata->digest_enc.offset == 0 ?
7195 				plaintext_pad_len
7196 				: tdata->digest_enc.offset),
7197 			tdata->validCipherLen.len_bits,
7198 			tdata->cipher.offset_bits,
7199 			tdata->validAuthLen.len_bits,
7200 			tdata->auth.offset_bits,
7201 			op_mode, 0, verify);
7202 
7203 	if (retval < 0)
7204 		return retval;
7205 
7206 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7207 
7208 	/* Check if the op failed because the device doesn't */
7209 	/* support this particular combination of algorithms */
7210 	if (op == NULL && ut_params->op->status ==
7211 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7212 		printf("Device doesn't support this mixed combination. "
7213 				"Test Skipped.\n");
7214 		return TEST_SKIPPED;
7215 	}
7216 	ut_params->op = op;
7217 
7218 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7219 
7220 	ut_params->obuf = (op_mode == IN_PLACE ?
7221 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7222 
7223 	if (verify) {
7224 		if (ut_params->obuf)
7225 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
7226 							uint8_t *);
7227 		else
7228 			plaintext = ciphertext +
7229 					(tdata->cipher.offset_bits >> 3);
7230 
7231 		debug_hexdump(stdout, "plaintext:", plaintext,
7232 				tdata->plaintext.len_bits >> 3);
7233 		debug_hexdump(stdout, "plaintext expected:",
7234 				tdata->plaintext.data,
7235 				tdata->plaintext.len_bits >> 3);
7236 	} else {
7237 		if (ut_params->obuf)
7238 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
7239 					uint8_t *);
7240 		else
7241 			ciphertext = plaintext;
7242 
7243 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7244 				ciphertext_len);
7245 		debug_hexdump(stdout, "ciphertext expected:",
7246 				tdata->ciphertext.data,
7247 				tdata->ciphertext.len_bits >> 3);
7248 
7249 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
7250 				+ (tdata->digest_enc.offset == 0 ?
7251 		plaintext_pad_len : tdata->digest_enc.offset);
7252 
7253 		debug_hexdump(stdout, "digest:", ut_params->digest,
7254 				tdata->digest_enc.len);
7255 		debug_hexdump(stdout, "digest expected:",
7256 				tdata->digest_enc.data,
7257 				tdata->digest_enc.len);
7258 	}
7259 
7260 	/* Validate obuf */
7261 	if (verify) {
7262 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7263 				plaintext,
7264 				tdata->plaintext.data,
7265 				tdata->plaintext.len_bits >> 3,
7266 				"Plaintext data not as expected");
7267 	} else {
7268 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7269 				ciphertext,
7270 				tdata->ciphertext.data,
7271 				tdata->validDataLen.len_bits,
7272 				"Ciphertext data not as expected");
7273 
7274 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
7275 				ut_params->digest,
7276 				tdata->digest_enc.data,
7277 				DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
7278 				"Generated auth tag not as expected");
7279 	}
7280 
7281 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7282 			"crypto op processing failed");
7283 
7284 	return 0;
7285 }
7286 
7287 static int
7288 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
7289 	uint8_t op_mode, uint8_t verify)
7290 {
7291 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7292 	struct crypto_unittest_params *ut_params = &unittest_params;
7293 
7294 	int retval;
7295 
7296 	const uint8_t *plaintext = NULL;
7297 	const uint8_t *ciphertext = NULL;
7298 	const uint8_t *digest = NULL;
7299 	unsigned int plaintext_pad_len;
7300 	unsigned int plaintext_len;
7301 	unsigned int ciphertext_pad_len;
7302 	unsigned int ciphertext_len;
7303 	uint8_t buffer[10000];
7304 	uint8_t digest_buffer[10000];
7305 
7306 	struct rte_cryptodev_info dev_info;
7307 	struct rte_crypto_op *op;
7308 
7309 	/* Check if device supports particular algorithms */
7310 	if (test_mixed_check_if_unsupported(tdata))
7311 		return TEST_SKIPPED;
7312 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7313 		return TEST_SKIPPED;
7314 
7315 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7316 
7317 	uint64_t feat_flags = dev_info.feature_flags;
7318 
7319 	if (op_mode == IN_PLACE) {
7320 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
7321 			printf("Device doesn't support in-place scatter-gather "
7322 					"in both input and output mbufs.\n");
7323 			return TEST_SKIPPED;
7324 		}
7325 	} else {
7326 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
7327 			printf("Device doesn't support out-of-place scatter-gather "
7328 					"in both input and output mbufs.\n");
7329 			return TEST_SKIPPED;
7330 		}
7331 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7332 			printf("Device doesn't support digest encrypted.\n");
7333 			return TEST_SKIPPED;
7334 		}
7335 	}
7336 
7337 	/* Create the session */
7338 	if (verify)
7339 		retval = create_wireless_algo_cipher_auth_session(
7340 				ts_params->valid_devs[0],
7341 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
7342 				RTE_CRYPTO_AUTH_OP_VERIFY,
7343 				tdata->auth_algo,
7344 				tdata->cipher_algo,
7345 				tdata->auth_key.data, tdata->auth_key.len,
7346 				tdata->auth_iv.len, tdata->digest_enc.len,
7347 				tdata->cipher_iv.len);
7348 	else
7349 		retval = create_wireless_algo_auth_cipher_session(
7350 				ts_params->valid_devs[0],
7351 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7352 				RTE_CRYPTO_AUTH_OP_GENERATE,
7353 				tdata->auth_algo,
7354 				tdata->cipher_algo,
7355 				tdata->auth_key.data, tdata->auth_key.len,
7356 				tdata->auth_iv.len, tdata->digest_enc.len,
7357 				tdata->cipher_iv.len);
7358 	if (retval != 0)
7359 		return retval;
7360 
7361 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7362 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7363 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7364 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7365 
7366 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
7367 			ciphertext_pad_len, 15, 0);
7368 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7369 			"Failed to allocate input buffer in mempool");
7370 
7371 	if (op_mode == OUT_OF_PLACE) {
7372 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
7373 				plaintext_pad_len, 15, 0);
7374 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
7375 				"Failed to allocate output buffer in mempool");
7376 	}
7377 
7378 	if (verify) {
7379 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
7380 			tdata->ciphertext.data);
7381 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7382 					ciphertext_len, buffer);
7383 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7384 			ciphertext_len);
7385 	} else {
7386 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
7387 			tdata->plaintext.data);
7388 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7389 					plaintext_len, buffer);
7390 		debug_hexdump(stdout, "plaintext:", plaintext,
7391 			plaintext_len);
7392 	}
7393 	memset(buffer, 0, sizeof(buffer));
7394 
7395 	/* Create the operation */
7396 	retval = create_wireless_algo_auth_cipher_operation(
7397 			tdata->digest_enc.data, tdata->digest_enc.len,
7398 			tdata->cipher_iv.data, tdata->cipher_iv.len,
7399 			tdata->auth_iv.data, tdata->auth_iv.len,
7400 			(tdata->digest_enc.offset == 0 ?
7401 				plaintext_pad_len
7402 				: tdata->digest_enc.offset),
7403 			tdata->validCipherLen.len_bits,
7404 			tdata->cipher.offset_bits,
7405 			tdata->validAuthLen.len_bits,
7406 			tdata->auth.offset_bits,
7407 			op_mode, 1, verify);
7408 
7409 	if (retval < 0)
7410 		return retval;
7411 
7412 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7413 
7414 	/* Check if the op failed because the device doesn't */
7415 	/* support this particular combination of algorithms */
7416 	if (op == NULL && ut_params->op->status ==
7417 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7418 		printf("Device doesn't support this mixed combination. "
7419 				"Test Skipped.\n");
7420 		return TEST_SKIPPED;
7421 	}
7422 	ut_params->op = op;
7423 
7424 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7425 
7426 	ut_params->obuf = (op_mode == IN_PLACE ?
7427 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7428 
7429 	if (verify) {
7430 		if (ut_params->obuf)
7431 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
7432 					plaintext_len, buffer);
7433 		else
7434 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7435 					plaintext_len, buffer);
7436 
7437 		debug_hexdump(stdout, "plaintext:", plaintext,
7438 				(tdata->plaintext.len_bits >> 3) -
7439 				tdata->digest_enc.len);
7440 		debug_hexdump(stdout, "plaintext expected:",
7441 				tdata->plaintext.data,
7442 				(tdata->plaintext.len_bits >> 3) -
7443 				tdata->digest_enc.len);
7444 	} else {
7445 		if (ut_params->obuf)
7446 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7447 					ciphertext_len, buffer);
7448 		else
7449 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7450 					ciphertext_len, buffer);
7451 
7452 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7453 			ciphertext_len);
7454 		debug_hexdump(stdout, "ciphertext expected:",
7455 			tdata->ciphertext.data,
7456 			tdata->ciphertext.len_bits >> 3);
7457 
7458 		if (ut_params->obuf)
7459 			digest = rte_pktmbuf_read(ut_params->obuf,
7460 					(tdata->digest_enc.offset == 0 ?
7461 						plaintext_pad_len :
7462 						tdata->digest_enc.offset),
7463 					tdata->digest_enc.len, digest_buffer);
7464 		else
7465 			digest = rte_pktmbuf_read(ut_params->ibuf,
7466 					(tdata->digest_enc.offset == 0 ?
7467 						plaintext_pad_len :
7468 						tdata->digest_enc.offset),
7469 					tdata->digest_enc.len, digest_buffer);
7470 
7471 		debug_hexdump(stdout, "digest:", digest,
7472 				tdata->digest_enc.len);
7473 		debug_hexdump(stdout, "digest expected:",
7474 				tdata->digest_enc.data, tdata->digest_enc.len);
7475 	}
7476 
7477 	/* Validate obuf */
7478 	if (verify) {
7479 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7480 				plaintext,
7481 				tdata->plaintext.data,
7482 				tdata->plaintext.len_bits >> 3,
7483 				"Plaintext data not as expected");
7484 	} else {
7485 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7486 				ciphertext,
7487 				tdata->ciphertext.data,
7488 				tdata->validDataLen.len_bits,
7489 				"Ciphertext data not as expected");
7490 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
7491 				digest,
7492 				tdata->digest_enc.data,
7493 				tdata->digest_enc.len,
7494 				"Generated auth tag not as expected");
7495 	}
7496 
7497 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7498 			"crypto op processing failed");
7499 
7500 	return 0;
7501 }
7502 
7503 /** AUTH AES CMAC + CIPHER AES CTR */
7504 
7505 static int
7506 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7507 {
7508 	return test_mixed_auth_cipher(
7509 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7510 }
7511 
7512 static int
7513 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7514 {
7515 	return test_mixed_auth_cipher(
7516 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7517 }
7518 
7519 static int
7520 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7521 {
7522 	return test_mixed_auth_cipher_sgl(
7523 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7524 }
7525 
7526 static int
7527 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7528 {
7529 	return test_mixed_auth_cipher_sgl(
7530 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7531 }
7532 
7533 static int
7534 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7535 {
7536 	return test_mixed_auth_cipher(
7537 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7538 }
7539 
7540 static int
7541 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7542 {
7543 	return test_mixed_auth_cipher(
7544 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7545 }
7546 
7547 static int
7548 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7549 {
7550 	return test_mixed_auth_cipher_sgl(
7551 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7552 }
7553 
7554 static int
7555 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7556 {
7557 	return test_mixed_auth_cipher_sgl(
7558 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7559 }
7560 
7561 /** MIXED AUTH + CIPHER */
7562 
7563 static int
7564 test_auth_zuc_cipher_snow_test_case_1(void)
7565 {
7566 	return test_mixed_auth_cipher(
7567 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7568 }
7569 
7570 static int
7571 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7572 {
7573 	return test_mixed_auth_cipher(
7574 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7575 }
7576 
7577 static int
7578 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7579 {
7580 	return test_mixed_auth_cipher(
7581 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7582 }
7583 
7584 static int
7585 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7586 {
7587 	return test_mixed_auth_cipher(
7588 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7589 }
7590 
7591 static int
7592 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7593 {
7594 	return test_mixed_auth_cipher(
7595 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7596 }
7597 
7598 static int
7599 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7600 {
7601 	return test_mixed_auth_cipher(
7602 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7603 }
7604 
7605 static int
7606 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7607 {
7608 	return test_mixed_auth_cipher(
7609 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7610 }
7611 
7612 static int
7613 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7614 {
7615 	return test_mixed_auth_cipher(
7616 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7617 }
7618 
7619 static int
7620 test_auth_snow_cipher_zuc_test_case_1(void)
7621 {
7622 	return test_mixed_auth_cipher(
7623 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7624 }
7625 
7626 static int
7627 test_verify_auth_snow_cipher_zuc_test_case_1(void)
7628 {
7629 	return test_mixed_auth_cipher(
7630 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7631 }
7632 
7633 static int
7634 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
7635 {
7636 	return test_mixed_auth_cipher(
7637 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7638 }
7639 
7640 static int
7641 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
7642 {
7643 	return test_mixed_auth_cipher(
7644 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7645 }
7646 
7647 static int
7648 test_auth_null_cipher_snow_test_case_1(void)
7649 {
7650 	return test_mixed_auth_cipher(
7651 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7652 }
7653 
7654 static int
7655 test_verify_auth_null_cipher_snow_test_case_1(void)
7656 {
7657 	return test_mixed_auth_cipher(
7658 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7659 }
7660 
7661 static int
7662 test_auth_null_cipher_zuc_test_case_1(void)
7663 {
7664 	return test_mixed_auth_cipher(
7665 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7666 }
7667 
7668 static int
7669 test_verify_auth_null_cipher_zuc_test_case_1(void)
7670 {
7671 	return test_mixed_auth_cipher(
7672 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7673 }
7674 
7675 static int
7676 test_auth_snow_cipher_null_test_case_1(void)
7677 {
7678 	return test_mixed_auth_cipher(
7679 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7680 }
7681 
7682 static int
7683 test_verify_auth_snow_cipher_null_test_case_1(void)
7684 {
7685 	return test_mixed_auth_cipher(
7686 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7687 }
7688 
7689 static int
7690 test_auth_zuc_cipher_null_test_case_1(void)
7691 {
7692 	return test_mixed_auth_cipher(
7693 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7694 }
7695 
7696 static int
7697 test_verify_auth_zuc_cipher_null_test_case_1(void)
7698 {
7699 	return test_mixed_auth_cipher(
7700 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7701 }
7702 
7703 static int
7704 test_auth_null_cipher_aes_ctr_test_case_1(void)
7705 {
7706 	return test_mixed_auth_cipher(
7707 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7708 }
7709 
7710 static int
7711 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
7712 {
7713 	return test_mixed_auth_cipher(
7714 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7715 }
7716 
7717 static int
7718 test_auth_aes_cmac_cipher_null_test_case_1(void)
7719 {
7720 	return test_mixed_auth_cipher(
7721 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7722 }
7723 
7724 static int
7725 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
7726 {
7727 	return test_mixed_auth_cipher(
7728 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7729 }
7730 
7731 /* ***** AEAD algorithm Tests ***** */
7732 
7733 static int
7734 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
7735 		enum rte_crypto_aead_operation op,
7736 		const uint8_t *key, const uint8_t key_len,
7737 		const uint16_t aad_len, const uint8_t auth_len,
7738 		uint8_t iv_len)
7739 {
7740 	uint8_t aead_key[key_len];
7741 
7742 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7743 	struct crypto_unittest_params *ut_params = &unittest_params;
7744 
7745 	memcpy(aead_key, key, key_len);
7746 
7747 	/* Setup AEAD Parameters */
7748 	ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7749 	ut_params->aead_xform.next = NULL;
7750 	ut_params->aead_xform.aead.algo = algo;
7751 	ut_params->aead_xform.aead.op = op;
7752 	ut_params->aead_xform.aead.key.data = aead_key;
7753 	ut_params->aead_xform.aead.key.length = key_len;
7754 	ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
7755 	ut_params->aead_xform.aead.iv.length = iv_len;
7756 	ut_params->aead_xform.aead.digest_length = auth_len;
7757 	ut_params->aead_xform.aead.aad_length = aad_len;
7758 
7759 	debug_hexdump(stdout, "key:", key, key_len);
7760 
7761 	/* Create Crypto session*/
7762 	ut_params->sess = rte_cryptodev_sym_session_create(
7763 			ts_params->session_mpool);
7764 
7765 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7766 			&ut_params->aead_xform,
7767 			ts_params->session_priv_mpool);
7768 
7769 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7770 
7771 	return 0;
7772 }
7773 
7774 static int
7775 create_aead_xform(struct rte_crypto_op *op,
7776 		enum rte_crypto_aead_algorithm algo,
7777 		enum rte_crypto_aead_operation aead_op,
7778 		uint8_t *key, const uint8_t key_len,
7779 		const uint8_t aad_len, const uint8_t auth_len,
7780 		uint8_t iv_len)
7781 {
7782 	TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
7783 			"failed to allocate space for crypto transform");
7784 
7785 	struct rte_crypto_sym_op *sym_op = op->sym;
7786 
7787 	/* Setup AEAD Parameters */
7788 	sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
7789 	sym_op->xform->next = NULL;
7790 	sym_op->xform->aead.algo = algo;
7791 	sym_op->xform->aead.op = aead_op;
7792 	sym_op->xform->aead.key.data = key;
7793 	sym_op->xform->aead.key.length = key_len;
7794 	sym_op->xform->aead.iv.offset = IV_OFFSET;
7795 	sym_op->xform->aead.iv.length = iv_len;
7796 	sym_op->xform->aead.digest_length = auth_len;
7797 	sym_op->xform->aead.aad_length = aad_len;
7798 
7799 	debug_hexdump(stdout, "key:", key, key_len);
7800 
7801 	return 0;
7802 }
7803 
7804 static int
7805 create_aead_operation(enum rte_crypto_aead_operation op,
7806 		const struct aead_test_data *tdata)
7807 {
7808 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7809 	struct crypto_unittest_params *ut_params = &unittest_params;
7810 
7811 	uint8_t *plaintext, *ciphertext;
7812 	unsigned int aad_pad_len, plaintext_pad_len;
7813 
7814 	/* Generate Crypto op data structure */
7815 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7816 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7817 	TEST_ASSERT_NOT_NULL(ut_params->op,
7818 			"Failed to allocate symmetric crypto operation struct");
7819 
7820 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7821 
7822 	/* Append aad data */
7823 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
7824 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
7825 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7826 				aad_pad_len);
7827 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7828 				"no room to append aad");
7829 
7830 		sym_op->aead.aad.phys_addr =
7831 				rte_pktmbuf_iova(ut_params->ibuf);
7832 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
7833 		memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
7834 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7835 			tdata->aad.len);
7836 
7837 		/* Append IV at the end of the crypto operation*/
7838 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7839 				uint8_t *, IV_OFFSET);
7840 
7841 		/* Copy IV 1 byte after the IV pointer, according to the API */
7842 		rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
7843 		debug_hexdump(stdout, "iv:", iv_ptr,
7844 			tdata->iv.len);
7845 	} else {
7846 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
7847 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7848 				aad_pad_len);
7849 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7850 				"no room to append aad");
7851 
7852 		sym_op->aead.aad.phys_addr =
7853 				rte_pktmbuf_iova(ut_params->ibuf);
7854 		memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
7855 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7856 			tdata->aad.len);
7857 
7858 		/* Append IV at the end of the crypto operation*/
7859 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7860 				uint8_t *, IV_OFFSET);
7861 
7862 		if (tdata->iv.len == 0) {
7863 			rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
7864 			debug_hexdump(stdout, "iv:", iv_ptr,
7865 				AES_GCM_J0_LENGTH);
7866 		} else {
7867 			rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
7868 			debug_hexdump(stdout, "iv:", iv_ptr,
7869 				tdata->iv.len);
7870 		}
7871 	}
7872 
7873 	/* Append plaintext/ciphertext */
7874 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7875 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
7876 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7877 				plaintext_pad_len);
7878 		TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7879 
7880 		memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
7881 		debug_hexdump(stdout, "plaintext:", plaintext,
7882 				tdata->plaintext.len);
7883 
7884 		if (ut_params->obuf) {
7885 			ciphertext = (uint8_t *)rte_pktmbuf_append(
7886 					ut_params->obuf,
7887 					plaintext_pad_len + aad_pad_len);
7888 			TEST_ASSERT_NOT_NULL(ciphertext,
7889 					"no room to append ciphertext");
7890 
7891 			memset(ciphertext + aad_pad_len, 0,
7892 					tdata->ciphertext.len);
7893 		}
7894 	} else {
7895 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
7896 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7897 				plaintext_pad_len);
7898 		TEST_ASSERT_NOT_NULL(ciphertext,
7899 				"no room to append ciphertext");
7900 
7901 		memcpy(ciphertext, tdata->ciphertext.data,
7902 				tdata->ciphertext.len);
7903 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7904 				tdata->ciphertext.len);
7905 
7906 		if (ut_params->obuf) {
7907 			plaintext = (uint8_t *)rte_pktmbuf_append(
7908 					ut_params->obuf,
7909 					plaintext_pad_len + aad_pad_len);
7910 			TEST_ASSERT_NOT_NULL(plaintext,
7911 					"no room to append plaintext");
7912 
7913 			memset(plaintext + aad_pad_len, 0,
7914 					tdata->plaintext.len);
7915 		}
7916 	}
7917 
7918 	/* Append digest data */
7919 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
7920 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7921 				ut_params->obuf ? ut_params->obuf :
7922 						ut_params->ibuf,
7923 						tdata->auth_tag.len);
7924 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7925 				"no room to append digest");
7926 		memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
7927 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
7928 				ut_params->obuf ? ut_params->obuf :
7929 						ut_params->ibuf,
7930 						plaintext_pad_len +
7931 						aad_pad_len);
7932 	} else {
7933 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
7934 				ut_params->ibuf, tdata->auth_tag.len);
7935 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
7936 				"no room to append digest");
7937 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
7938 				ut_params->ibuf,
7939 				plaintext_pad_len + aad_pad_len);
7940 
7941 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
7942 			tdata->auth_tag.len);
7943 		debug_hexdump(stdout, "digest:",
7944 			sym_op->aead.digest.data,
7945 			tdata->auth_tag.len);
7946 	}
7947 
7948 	sym_op->aead.data.length = tdata->plaintext.len;
7949 	sym_op->aead.data.offset = aad_pad_len;
7950 
7951 	return 0;
7952 }
7953 
7954 static int
7955 test_authenticated_encryption(const struct aead_test_data *tdata)
7956 {
7957 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7958 	struct crypto_unittest_params *ut_params = &unittest_params;
7959 
7960 	int retval;
7961 	uint8_t *ciphertext, *auth_tag;
7962 	uint16_t plaintext_pad_len;
7963 	uint32_t i;
7964 	struct rte_cryptodev_info dev_info;
7965 
7966 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7967 	uint64_t feat_flags = dev_info.feature_flags;
7968 
7969 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
7970 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
7971 		printf("Device doesn't support RAW data-path APIs.\n");
7972 		return TEST_SKIPPED;
7973 	}
7974 
7975 	/* Verify the capabilities */
7976 	struct rte_cryptodev_sym_capability_idx cap_idx;
7977 	const struct rte_cryptodev_symmetric_capability *capability;
7978 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7979 	cap_idx.algo.aead = tdata->algo;
7980 	capability = rte_cryptodev_sym_capability_get(
7981 			ts_params->valid_devs[0], &cap_idx);
7982 	if (capability == NULL)
7983 		return TEST_SKIPPED;
7984 	if (rte_cryptodev_sym_capability_check_aead(
7985 			capability, tdata->key.len, tdata->auth_tag.len,
7986 			tdata->aad.len, tdata->iv.len))
7987 		return TEST_SKIPPED;
7988 
7989 	/* Create AEAD session */
7990 	retval = create_aead_session(ts_params->valid_devs[0],
7991 			tdata->algo,
7992 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
7993 			tdata->key.data, tdata->key.len,
7994 			tdata->aad.len, tdata->auth_tag.len,
7995 			tdata->iv.len);
7996 	if (retval < 0)
7997 		return retval;
7998 
7999 	if (tdata->aad.len > MBUF_SIZE) {
8000 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8001 		/* Populate full size of add data */
8002 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
8003 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
8004 	} else
8005 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8006 
8007 	/* clear mbuf payload */
8008 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8009 			rte_pktmbuf_tailroom(ut_params->ibuf));
8010 
8011 	/* Create AEAD operation */
8012 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8013 	if (retval < 0)
8014 		return retval;
8015 
8016 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8017 
8018 	ut_params->op->sym->m_src = ut_params->ibuf;
8019 
8020 	/* Process crypto operation */
8021 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8022 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
8023 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
8024 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8025 				ut_params->op, 0, 0, 0, 0);
8026 	else
8027 		TEST_ASSERT_NOT_NULL(
8028 			process_crypto_request(ts_params->valid_devs[0],
8029 			ut_params->op), "failed to process sym crypto op");
8030 
8031 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8032 			"crypto op processing failed");
8033 
8034 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8035 
8036 	if (ut_params->op->sym->m_dst) {
8037 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8038 				uint8_t *);
8039 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8040 				uint8_t *, plaintext_pad_len);
8041 	} else {
8042 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8043 				uint8_t *,
8044 				ut_params->op->sym->cipher.data.offset);
8045 		auth_tag = ciphertext + plaintext_pad_len;
8046 	}
8047 
8048 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8049 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8050 
8051 	/* Validate obuf */
8052 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
8053 			ciphertext,
8054 			tdata->ciphertext.data,
8055 			tdata->ciphertext.len,
8056 			"Ciphertext data not as expected");
8057 
8058 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
8059 			auth_tag,
8060 			tdata->auth_tag.data,
8061 			tdata->auth_tag.len,
8062 			"Generated auth tag not as expected");
8063 
8064 	return 0;
8065 
8066 }
8067 
8068 #ifdef RTE_LIB_SECURITY
8069 static int
8070 security_proto_supported(enum rte_security_session_action_type action,
8071 	enum rte_security_session_protocol proto)
8072 {
8073 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8074 
8075 	const struct rte_security_capability *capabilities;
8076 	const struct rte_security_capability *capability;
8077 	uint16_t i = 0;
8078 
8079 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8080 				rte_cryptodev_get_sec_ctx(
8081 				ts_params->valid_devs[0]);
8082 
8083 
8084 	capabilities = rte_security_capabilities_get(ctx);
8085 
8086 	if (capabilities == NULL)
8087 		return -ENOTSUP;
8088 
8089 	while ((capability = &capabilities[i++])->action !=
8090 			RTE_SECURITY_ACTION_TYPE_NONE) {
8091 		if (capability->action == action &&
8092 				capability->protocol == proto)
8093 			return 0;
8094 	}
8095 
8096 	return -ENOTSUP;
8097 }
8098 
8099 /* Basic algorithm run function for async inplace mode.
8100  * Creates a session from input parameters and runs one operation
8101  * on input_vec. Checks the output of the crypto operation against
8102  * output_vec.
8103  */
8104 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
8105 			   enum rte_crypto_auth_operation opa,
8106 			   const uint8_t *input_vec, unsigned int input_vec_len,
8107 			   const uint8_t *output_vec,
8108 			   unsigned int output_vec_len,
8109 			   enum rte_crypto_cipher_algorithm cipher_alg,
8110 			   const uint8_t *cipher_key, uint32_t cipher_key_len,
8111 			   enum rte_crypto_auth_algorithm auth_alg,
8112 			   const uint8_t *auth_key, uint32_t auth_key_len,
8113 			   uint8_t bearer, enum rte_security_pdcp_domain domain,
8114 			   uint8_t packet_direction, uint8_t sn_size,
8115 			   uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
8116 {
8117 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8118 	struct crypto_unittest_params *ut_params = &unittest_params;
8119 	uint8_t *plaintext;
8120 	int ret = TEST_SUCCESS;
8121 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8122 				rte_cryptodev_get_sec_ctx(
8123 				ts_params->valid_devs[0]);
8124 
8125 	/* Verify the capabilities */
8126 	struct rte_security_capability_idx sec_cap_idx;
8127 
8128 	sec_cap_idx.action = ut_params->type;
8129 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8130 	sec_cap_idx.pdcp.domain = domain;
8131 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8132 		return TEST_SKIPPED;
8133 
8134 	/* Generate test mbuf data */
8135 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8136 
8137 	/* clear mbuf payload */
8138 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8139 			rte_pktmbuf_tailroom(ut_params->ibuf));
8140 
8141 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8142 						  input_vec_len);
8143 	memcpy(plaintext, input_vec, input_vec_len);
8144 
8145 	/* Out of place support */
8146 	if (oop) {
8147 		/*
8148 		 * For out-op-place we need to alloc another mbuf
8149 		 */
8150 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8151 		rte_pktmbuf_append(ut_params->obuf, output_vec_len);
8152 	}
8153 
8154 	/* Setup Cipher Parameters */
8155 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8156 	ut_params->cipher_xform.cipher.algo = cipher_alg;
8157 	ut_params->cipher_xform.cipher.op = opc;
8158 	ut_params->cipher_xform.cipher.key.data = cipher_key;
8159 	ut_params->cipher_xform.cipher.key.length = cipher_key_len;
8160 	ut_params->cipher_xform.cipher.iv.length =
8161 				packet_direction ? 4 : 0;
8162 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8163 
8164 	/* Setup HMAC Parameters if ICV header is required */
8165 	if (auth_alg != 0) {
8166 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8167 		ut_params->auth_xform.next = NULL;
8168 		ut_params->auth_xform.auth.algo = auth_alg;
8169 		ut_params->auth_xform.auth.op = opa;
8170 		ut_params->auth_xform.auth.key.data = auth_key;
8171 		ut_params->auth_xform.auth.key.length = auth_key_len;
8172 
8173 		ut_params->cipher_xform.next = &ut_params->auth_xform;
8174 	} else {
8175 		ut_params->cipher_xform.next = NULL;
8176 	}
8177 
8178 	struct rte_security_session_conf sess_conf = {
8179 		.action_type = ut_params->type,
8180 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
8181 		{.pdcp = {
8182 			.bearer = bearer,
8183 			.domain = domain,
8184 			.pkt_dir = packet_direction,
8185 			.sn_size = sn_size,
8186 			.hfn = packet_direction ? 0 : hfn,
8187 			/**
8188 			 * hfn can be set as pdcp_test_hfn[i]
8189 			 * if hfn_ovrd is not set. Here, PDCP
8190 			 * packet direction is just used to
8191 			 * run half of the cases with session
8192 			 * HFN and other half with per packet
8193 			 * HFN.
8194 			 */
8195 			.hfn_threshold = hfn_threshold,
8196 			.hfn_ovrd = packet_direction ? 1 : 0,
8197 			.sdap_enabled = sdap,
8198 		} },
8199 		.crypto_xform = &ut_params->cipher_xform
8200 	};
8201 
8202 	/* Create security session */
8203 	ut_params->sec_session = rte_security_session_create(ctx,
8204 				&sess_conf, ts_params->session_mpool,
8205 				ts_params->session_priv_mpool);
8206 
8207 	if (!ut_params->sec_session) {
8208 		printf("TestCase %s()-%d line %d failed %s: ",
8209 			__func__, i, __LINE__, "Failed to allocate session");
8210 		ret = TEST_FAILED;
8211 		goto on_err;
8212 	}
8213 
8214 	/* Generate crypto op data structure */
8215 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8216 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8217 	if (!ut_params->op) {
8218 		printf("TestCase %s()-%d line %d failed %s: ",
8219 			__func__, i, __LINE__,
8220 			"Failed to allocate symmetric crypto operation struct");
8221 		ret = TEST_FAILED;
8222 		goto on_err;
8223 	}
8224 
8225 	uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
8226 					uint32_t *, IV_OFFSET);
8227 	*per_pkt_hfn = packet_direction ? hfn : 0;
8228 
8229 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8230 
8231 	/* set crypto operation source mbuf */
8232 	ut_params->op->sym->m_src = ut_params->ibuf;
8233 	if (oop)
8234 		ut_params->op->sym->m_dst = ut_params->obuf;
8235 
8236 	/* Process crypto operation */
8237 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8238 		== NULL) {
8239 		printf("TestCase %s()-%d line %d failed %s: ",
8240 			__func__, i, __LINE__,
8241 			"failed to process sym crypto op");
8242 		ret = TEST_FAILED;
8243 		goto on_err;
8244 	}
8245 
8246 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8247 		printf("TestCase %s()-%d line %d failed %s: ",
8248 			__func__, i, __LINE__, "crypto op processing failed");
8249 		ret = TEST_FAILED;
8250 		goto on_err;
8251 	}
8252 
8253 	/* Validate obuf */
8254 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8255 			uint8_t *);
8256 	if (oop) {
8257 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8258 				uint8_t *);
8259 	}
8260 
8261 	if (memcmp(ciphertext, output_vec, output_vec_len)) {
8262 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8263 		rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
8264 		rte_hexdump(stdout, "reference", output_vec, output_vec_len);
8265 		ret = TEST_FAILED;
8266 		goto on_err;
8267 	}
8268 
8269 on_err:
8270 	rte_crypto_op_free(ut_params->op);
8271 	ut_params->op = NULL;
8272 
8273 	if (ut_params->sec_session)
8274 		rte_security_session_destroy(ctx, ut_params->sec_session);
8275 	ut_params->sec_session = NULL;
8276 
8277 	rte_pktmbuf_free(ut_params->ibuf);
8278 	ut_params->ibuf = NULL;
8279 	if (oop) {
8280 		rte_pktmbuf_free(ut_params->obuf);
8281 		ut_params->obuf = NULL;
8282 	}
8283 
8284 	return ret;
8285 }
8286 
8287 static int
8288 test_pdcp_proto_SGL(int i, int oop,
8289 	enum rte_crypto_cipher_operation opc,
8290 	enum rte_crypto_auth_operation opa,
8291 	uint8_t *input_vec,
8292 	unsigned int input_vec_len,
8293 	uint8_t *output_vec,
8294 	unsigned int output_vec_len,
8295 	uint32_t fragsz,
8296 	uint32_t fragsz_oop)
8297 {
8298 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8299 	struct crypto_unittest_params *ut_params = &unittest_params;
8300 	uint8_t *plaintext;
8301 	struct rte_mbuf *buf, *buf_oop = NULL;
8302 	int ret = TEST_SUCCESS;
8303 	int to_trn = 0;
8304 	int to_trn_tbl[16];
8305 	int segs = 1;
8306 	unsigned int trn_data = 0;
8307 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8308 				rte_cryptodev_get_sec_ctx(
8309 				ts_params->valid_devs[0]);
8310 
8311 	/* Verify the capabilities */
8312 	struct rte_security_capability_idx sec_cap_idx;
8313 
8314 	sec_cap_idx.action = ut_params->type;
8315 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8316 	sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
8317 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8318 		return TEST_SKIPPED;
8319 
8320 	if (fragsz > input_vec_len)
8321 		fragsz = input_vec_len;
8322 
8323 	uint16_t plaintext_len = fragsz;
8324 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
8325 
8326 	if (fragsz_oop > output_vec_len)
8327 		frag_size_oop = output_vec_len;
8328 
8329 	int ecx = 0;
8330 	if (input_vec_len % fragsz != 0) {
8331 		if (input_vec_len / fragsz + 1 > 16)
8332 			return 1;
8333 	} else if (input_vec_len / fragsz > 16)
8334 		return 1;
8335 
8336 	/* Out of place support */
8337 	if (oop) {
8338 		/*
8339 		 * For out-op-place we need to alloc another mbuf
8340 		 */
8341 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8342 		rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
8343 		buf_oop = ut_params->obuf;
8344 	}
8345 
8346 	/* Generate test mbuf data */
8347 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8348 
8349 	/* clear mbuf payload */
8350 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8351 			rte_pktmbuf_tailroom(ut_params->ibuf));
8352 
8353 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8354 						  plaintext_len);
8355 	memcpy(plaintext, input_vec, plaintext_len);
8356 	trn_data += plaintext_len;
8357 
8358 	buf = ut_params->ibuf;
8359 
8360 	/*
8361 	 * Loop until no more fragments
8362 	 */
8363 
8364 	while (trn_data < input_vec_len) {
8365 		++segs;
8366 		to_trn = (input_vec_len - trn_data < fragsz) ?
8367 				(input_vec_len - trn_data) : fragsz;
8368 
8369 		to_trn_tbl[ecx++] = to_trn;
8370 
8371 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8372 		buf = buf->next;
8373 
8374 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8375 				rte_pktmbuf_tailroom(buf));
8376 
8377 		/* OOP */
8378 		if (oop && !fragsz_oop) {
8379 			buf_oop->next =
8380 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
8381 			buf_oop = buf_oop->next;
8382 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8383 					0, rte_pktmbuf_tailroom(buf_oop));
8384 			rte_pktmbuf_append(buf_oop, to_trn);
8385 		}
8386 
8387 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8388 				to_trn);
8389 
8390 		memcpy(plaintext, input_vec + trn_data, to_trn);
8391 		trn_data += to_trn;
8392 	}
8393 
8394 	ut_params->ibuf->nb_segs = segs;
8395 
8396 	segs = 1;
8397 	if (fragsz_oop && oop) {
8398 		to_trn = 0;
8399 		ecx = 0;
8400 
8401 		trn_data = frag_size_oop;
8402 		while (trn_data < output_vec_len) {
8403 			++segs;
8404 			to_trn =
8405 				(output_vec_len - trn_data <
8406 						frag_size_oop) ?
8407 				(output_vec_len - trn_data) :
8408 						frag_size_oop;
8409 
8410 			to_trn_tbl[ecx++] = to_trn;
8411 
8412 			buf_oop->next =
8413 				rte_pktmbuf_alloc(ts_params->mbuf_pool);
8414 			buf_oop = buf_oop->next;
8415 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8416 					0, rte_pktmbuf_tailroom(buf_oop));
8417 			rte_pktmbuf_append(buf_oop, to_trn);
8418 
8419 			trn_data += to_trn;
8420 		}
8421 		ut_params->obuf->nb_segs = segs;
8422 	}
8423 
8424 	/* Setup Cipher Parameters */
8425 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8426 	ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
8427 	ut_params->cipher_xform.cipher.op = opc;
8428 	ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
8429 	ut_params->cipher_xform.cipher.key.length =
8430 					pdcp_test_params[i].cipher_key_len;
8431 	ut_params->cipher_xform.cipher.iv.length = 0;
8432 
8433 	/* Setup HMAC Parameters if ICV header is required */
8434 	if (pdcp_test_params[i].auth_alg != 0) {
8435 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8436 		ut_params->auth_xform.next = NULL;
8437 		ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
8438 		ut_params->auth_xform.auth.op = opa;
8439 		ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
8440 		ut_params->auth_xform.auth.key.length =
8441 					pdcp_test_params[i].auth_key_len;
8442 
8443 		ut_params->cipher_xform.next = &ut_params->auth_xform;
8444 	} else {
8445 		ut_params->cipher_xform.next = NULL;
8446 	}
8447 
8448 	struct rte_security_session_conf sess_conf = {
8449 		.action_type = ut_params->type,
8450 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
8451 		{.pdcp = {
8452 			.bearer = pdcp_test_bearer[i],
8453 			.domain = pdcp_test_params[i].domain,
8454 			.pkt_dir = pdcp_test_packet_direction[i],
8455 			.sn_size = pdcp_test_data_sn_size[i],
8456 			.hfn = pdcp_test_hfn[i],
8457 			.hfn_threshold = pdcp_test_hfn_threshold[i],
8458 			.hfn_ovrd = 0,
8459 		} },
8460 		.crypto_xform = &ut_params->cipher_xform
8461 	};
8462 
8463 	/* Create security session */
8464 	ut_params->sec_session = rte_security_session_create(ctx,
8465 				&sess_conf, ts_params->session_mpool,
8466 				ts_params->session_priv_mpool);
8467 
8468 	if (!ut_params->sec_session) {
8469 		printf("TestCase %s()-%d line %d failed %s: ",
8470 			__func__, i, __LINE__, "Failed to allocate session");
8471 		ret = TEST_FAILED;
8472 		goto on_err;
8473 	}
8474 
8475 	/* Generate crypto op data structure */
8476 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8477 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8478 	if (!ut_params->op) {
8479 		printf("TestCase %s()-%d line %d failed %s: ",
8480 			__func__, i, __LINE__,
8481 			"Failed to allocate symmetric crypto operation struct");
8482 		ret = TEST_FAILED;
8483 		goto on_err;
8484 	}
8485 
8486 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8487 
8488 	/* set crypto operation source mbuf */
8489 	ut_params->op->sym->m_src = ut_params->ibuf;
8490 	if (oop)
8491 		ut_params->op->sym->m_dst = ut_params->obuf;
8492 
8493 	/* Process crypto operation */
8494 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8495 		== NULL) {
8496 		printf("TestCase %s()-%d line %d failed %s: ",
8497 			__func__, i, __LINE__,
8498 			"failed to process sym crypto op");
8499 		ret = TEST_FAILED;
8500 		goto on_err;
8501 	}
8502 
8503 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8504 		printf("TestCase %s()-%d line %d failed %s: ",
8505 			__func__, i, __LINE__, "crypto op processing failed");
8506 		ret = TEST_FAILED;
8507 		goto on_err;
8508 	}
8509 
8510 	/* Validate obuf */
8511 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8512 			uint8_t *);
8513 	if (oop) {
8514 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8515 				uint8_t *);
8516 	}
8517 	if (fragsz_oop)
8518 		fragsz = frag_size_oop;
8519 	if (memcmp(ciphertext, output_vec, fragsz)) {
8520 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8521 		rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8522 		rte_hexdump(stdout, "reference", output_vec, fragsz);
8523 		ret = TEST_FAILED;
8524 		goto on_err;
8525 	}
8526 
8527 	buf = ut_params->op->sym->m_src->next;
8528 	if (oop)
8529 		buf = ut_params->op->sym->m_dst->next;
8530 
8531 	unsigned int off = fragsz;
8532 
8533 	ecx = 0;
8534 	while (buf) {
8535 		ciphertext = rte_pktmbuf_mtod(buf,
8536 				uint8_t *);
8537 		if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8538 			printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8539 			rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8540 			rte_hexdump(stdout, "reference", output_vec + off,
8541 					to_trn_tbl[ecx]);
8542 			ret = TEST_FAILED;
8543 			goto on_err;
8544 		}
8545 		off += to_trn_tbl[ecx++];
8546 		buf = buf->next;
8547 	}
8548 on_err:
8549 	rte_crypto_op_free(ut_params->op);
8550 	ut_params->op = NULL;
8551 
8552 	if (ut_params->sec_session)
8553 		rte_security_session_destroy(ctx, ut_params->sec_session);
8554 	ut_params->sec_session = NULL;
8555 
8556 	rte_pktmbuf_free(ut_params->ibuf);
8557 	ut_params->ibuf = NULL;
8558 	if (oop) {
8559 		rte_pktmbuf_free(ut_params->obuf);
8560 		ut_params->obuf = NULL;
8561 	}
8562 
8563 	return ret;
8564 }
8565 
8566 int
8567 test_pdcp_proto_cplane_encap(int i)
8568 {
8569 	return test_pdcp_proto(
8570 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8571 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8572 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8573 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8574 		pdcp_test_params[i].cipher_key_len,
8575 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8576 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8577 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8578 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8579 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8580 }
8581 
8582 int
8583 test_pdcp_proto_uplane_encap(int i)
8584 {
8585 	return test_pdcp_proto(
8586 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8587 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8588 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8589 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8590 		pdcp_test_params[i].cipher_key_len,
8591 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8592 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8593 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8594 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8595 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8596 }
8597 
8598 int
8599 test_pdcp_proto_uplane_encap_with_int(int i)
8600 {
8601 	return test_pdcp_proto(
8602 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8603 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8604 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8605 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8606 		pdcp_test_params[i].cipher_key_len,
8607 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8608 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8609 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8610 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8611 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8612 }
8613 
8614 int
8615 test_pdcp_proto_cplane_decap(int i)
8616 {
8617 	return test_pdcp_proto(
8618 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8619 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8620 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8621 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8622 		pdcp_test_params[i].cipher_key_len,
8623 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8624 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8625 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8626 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8627 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8628 }
8629 
8630 int
8631 test_pdcp_proto_uplane_decap(int i)
8632 {
8633 	return test_pdcp_proto(
8634 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8635 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8636 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8637 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8638 		pdcp_test_params[i].cipher_key_len,
8639 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8640 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8641 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8642 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8643 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8644 }
8645 
8646 int
8647 test_pdcp_proto_uplane_decap_with_int(int i)
8648 {
8649 	return test_pdcp_proto(
8650 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8651 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8652 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8653 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8654 		pdcp_test_params[i].cipher_key_len,
8655 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8656 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8657 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8658 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8659 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8660 }
8661 
8662 static int
8663 test_PDCP_PROTO_SGL_in_place_32B(void)
8664 {
8665 	/* i can be used for running any PDCP case
8666 	 * In this case it is uplane 12-bit AES-SNOW DL encap
8667 	 */
8668 	int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
8669 	return test_pdcp_proto_SGL(i, IN_PLACE,
8670 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8671 			RTE_CRYPTO_AUTH_OP_GENERATE,
8672 			pdcp_test_data_in[i],
8673 			pdcp_test_data_in_len[i],
8674 			pdcp_test_data_out[i],
8675 			pdcp_test_data_in_len[i]+4,
8676 			32, 0);
8677 }
8678 static int
8679 test_PDCP_PROTO_SGL_oop_32B_128B(void)
8680 {
8681 	/* i can be used for running any PDCP case
8682 	 * In this case it is uplane 18-bit NULL-NULL DL encap
8683 	 */
8684 	int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
8685 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8686 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8687 			RTE_CRYPTO_AUTH_OP_GENERATE,
8688 			pdcp_test_data_in[i],
8689 			pdcp_test_data_in_len[i],
8690 			pdcp_test_data_out[i],
8691 			pdcp_test_data_in_len[i]+4,
8692 			32, 128);
8693 }
8694 static int
8695 test_PDCP_PROTO_SGL_oop_32B_40B(void)
8696 {
8697 	/* i can be used for running any PDCP case
8698 	 * In this case it is uplane 18-bit AES DL encap
8699 	 */
8700 	int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
8701 			+ DOWNLINK;
8702 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8703 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8704 			RTE_CRYPTO_AUTH_OP_GENERATE,
8705 			pdcp_test_data_in[i],
8706 			pdcp_test_data_in_len[i],
8707 			pdcp_test_data_out[i],
8708 			pdcp_test_data_in_len[i],
8709 			32, 40);
8710 }
8711 static int
8712 test_PDCP_PROTO_SGL_oop_128B_32B(void)
8713 {
8714 	/* i can be used for running any PDCP case
8715 	 * In this case it is cplane 12-bit AES-ZUC DL encap
8716 	 */
8717 	int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
8718 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8719 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8720 			RTE_CRYPTO_AUTH_OP_GENERATE,
8721 			pdcp_test_data_in[i],
8722 			pdcp_test_data_in_len[i],
8723 			pdcp_test_data_out[i],
8724 			pdcp_test_data_in_len[i]+4,
8725 			128, 32);
8726 }
8727 
8728 static int
8729 test_PDCP_SDAP_PROTO_encap_all(void)
8730 {
8731 	int i = 0, size = 0;
8732 	int err, all_err = TEST_SUCCESS;
8733 	const struct pdcp_sdap_test *cur_test;
8734 
8735 	size = RTE_DIM(list_pdcp_sdap_tests);
8736 
8737 	for (i = 0; i < size; i++) {
8738 		cur_test = &list_pdcp_sdap_tests[i];
8739 		err = test_pdcp_proto(
8740 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8741 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8742 			cur_test->in_len, cur_test->data_out,
8743 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8744 			cur_test->param.cipher_alg, cur_test->cipher_key,
8745 			cur_test->param.cipher_key_len,
8746 			cur_test->param.auth_alg,
8747 			cur_test->auth_key, cur_test->param.auth_key_len,
8748 			cur_test->bearer, cur_test->param.domain,
8749 			cur_test->packet_direction, cur_test->sn_size,
8750 			cur_test->hfn,
8751 			cur_test->hfn_threshold, SDAP_ENABLED);
8752 		if (err) {
8753 			printf("\t%d) %s: Encapsulation failed\n",
8754 					cur_test->test_idx,
8755 					cur_test->param.name);
8756 			err = TEST_FAILED;
8757 		} else {
8758 			printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
8759 					cur_test->param.name);
8760 			err = TEST_SUCCESS;
8761 		}
8762 		all_err += err;
8763 	}
8764 
8765 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8766 
8767 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8768 }
8769 
8770 static int
8771 test_PDCP_PROTO_short_mac(void)
8772 {
8773 	int i = 0, size = 0;
8774 	int err, all_err = TEST_SUCCESS;
8775 	const struct pdcp_short_mac_test *cur_test;
8776 
8777 	size = RTE_DIM(list_pdcp_smac_tests);
8778 
8779 	for (i = 0; i < size; i++) {
8780 		cur_test = &list_pdcp_smac_tests[i];
8781 		err = test_pdcp_proto(
8782 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8783 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8784 			cur_test->in_len, cur_test->data_out,
8785 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8786 			RTE_CRYPTO_CIPHER_NULL, NULL,
8787 			0, cur_test->param.auth_alg,
8788 			cur_test->auth_key, cur_test->param.auth_key_len,
8789 			0, cur_test->param.domain, 0, 0,
8790 			0, 0, 0);
8791 		if (err) {
8792 			printf("\t%d) %s: Short MAC test failed\n",
8793 					cur_test->test_idx,
8794 					cur_test->param.name);
8795 			err = TEST_FAILED;
8796 		} else {
8797 			printf("\t%d) %s: Short MAC test PASS\n",
8798 					cur_test->test_idx,
8799 					cur_test->param.name);
8800 			rte_hexdump(stdout, "MAC I",
8801 				    cur_test->data_out + cur_test->in_len + 2,
8802 				    2);
8803 			err = TEST_SUCCESS;
8804 		}
8805 		all_err += err;
8806 	}
8807 
8808 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8809 
8810 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8811 
8812 }
8813 
8814 static int
8815 test_PDCP_SDAP_PROTO_decap_all(void)
8816 {
8817 	int i = 0, size = 0;
8818 	int err, all_err = TEST_SUCCESS;
8819 	const struct pdcp_sdap_test *cur_test;
8820 
8821 	size = RTE_DIM(list_pdcp_sdap_tests);
8822 
8823 	for (i = 0; i < size; i++) {
8824 		cur_test = &list_pdcp_sdap_tests[i];
8825 		err = test_pdcp_proto(
8826 			i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
8827 			RTE_CRYPTO_AUTH_OP_VERIFY,
8828 			cur_test->data_out,
8829 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8830 			cur_test->data_in, cur_test->in_len,
8831 			cur_test->param.cipher_alg,
8832 			cur_test->cipher_key, cur_test->param.cipher_key_len,
8833 			cur_test->param.auth_alg, cur_test->auth_key,
8834 			cur_test->param.auth_key_len, cur_test->bearer,
8835 			cur_test->param.domain, cur_test->packet_direction,
8836 			cur_test->sn_size, cur_test->hfn,
8837 			cur_test->hfn_threshold, SDAP_ENABLED);
8838 		if (err) {
8839 			printf("\t%d) %s: Decapsulation failed\n",
8840 					cur_test->test_idx,
8841 					cur_test->param.name);
8842 			err = TEST_FAILED;
8843 		} else {
8844 			printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
8845 					cur_test->param.name);
8846 			err = TEST_SUCCESS;
8847 		}
8848 		all_err += err;
8849 	}
8850 
8851 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8852 
8853 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8854 }
8855 
8856 static int
8857 test_PDCP_PROTO_all(void)
8858 {
8859 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8860 	struct crypto_unittest_params *ut_params = &unittest_params;
8861 	struct rte_cryptodev_info dev_info;
8862 	int status;
8863 
8864 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8865 	uint64_t feat_flags = dev_info.feature_flags;
8866 
8867 	if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
8868 		return TEST_SKIPPED;
8869 
8870 	/* Set action type */
8871 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
8872 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
8873 		gbl_action_type;
8874 
8875 	if (security_proto_supported(ut_params->type,
8876 			RTE_SECURITY_PROTOCOL_PDCP) < 0)
8877 		return TEST_SKIPPED;
8878 
8879 	status = test_PDCP_PROTO_cplane_encap_all();
8880 	status += test_PDCP_PROTO_cplane_decap_all();
8881 	status += test_PDCP_PROTO_uplane_encap_all();
8882 	status += test_PDCP_PROTO_uplane_decap_all();
8883 	status += test_PDCP_PROTO_SGL_in_place_32B();
8884 	status += test_PDCP_PROTO_SGL_oop_32B_128B();
8885 	status += test_PDCP_PROTO_SGL_oop_32B_40B();
8886 	status += test_PDCP_PROTO_SGL_oop_128B_32B();
8887 	status += test_PDCP_SDAP_PROTO_encap_all();
8888 	status += test_PDCP_SDAP_PROTO_decap_all();
8889 	status += test_PDCP_PROTO_short_mac();
8890 
8891 	if (status)
8892 		return TEST_FAILED;
8893 	else
8894 		return TEST_SUCCESS;
8895 }
8896 
8897 static int
8898 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td)
8899 {
8900 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8901 	struct crypto_unittest_params *ut_params = &unittest_params;
8902 	uint8_t *plaintext, *ciphertext;
8903 	uint8_t *iv_ptr;
8904 	int32_t cipher_len, crc_len;
8905 	uint32_t crc_data_len;
8906 	int ret = TEST_SUCCESS;
8907 
8908 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8909 					rte_cryptodev_get_sec_ctx(
8910 						ts_params->valid_devs[0]);
8911 
8912 	/* Verify the capabilities */
8913 	struct rte_security_capability_idx sec_cap_idx;
8914 	const struct rte_security_capability *sec_cap;
8915 	const struct rte_cryptodev_capabilities *crypto_cap;
8916 	const struct rte_cryptodev_symmetric_capability *sym_cap;
8917 	int j = 0;
8918 
8919 	sec_cap_idx.action = ut_params->type;
8920 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
8921 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
8922 
8923 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
8924 	if (sec_cap == NULL)
8925 		return TEST_SKIPPED;
8926 
8927 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
8928 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
8929 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
8930 				crypto_cap->sym.xform_type ==
8931 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
8932 				crypto_cap->sym.cipher.algo ==
8933 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
8934 			sym_cap = &crypto_cap->sym;
8935 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
8936 						d_td->key.len,
8937 						d_td->iv.len) == 0)
8938 				break;
8939 		}
8940 	}
8941 
8942 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
8943 		return TEST_SKIPPED;
8944 
8945 	/* Setup source mbuf payload */
8946 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8947 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8948 			rte_pktmbuf_tailroom(ut_params->ibuf));
8949 
8950 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8951 			d_td->ciphertext.len);
8952 
8953 	memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
8954 
8955 	/* Setup cipher session parameters */
8956 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8957 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
8958 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
8959 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
8960 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
8961 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
8962 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8963 	ut_params->cipher_xform.next = NULL;
8964 
8965 	/* Setup DOCSIS session parameters */
8966 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
8967 
8968 	struct rte_security_session_conf sess_conf = {
8969 		.action_type = ut_params->type,
8970 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
8971 		.docsis = ut_params->docsis_xform,
8972 		.crypto_xform = &ut_params->cipher_xform,
8973 	};
8974 
8975 	/* Create security session */
8976 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
8977 					ts_params->session_mpool,
8978 					ts_params->session_priv_mpool);
8979 
8980 	if (!ut_params->sec_session) {
8981 		printf("TestCase %s(%d) line %d: %s\n",
8982 			__func__, i, __LINE__, "failed to allocate session");
8983 		ret = TEST_FAILED;
8984 		goto on_err;
8985 	}
8986 
8987 	/* Generate crypto op data structure */
8988 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8989 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8990 	if (!ut_params->op) {
8991 		printf("TestCase %s(%d) line %d: %s\n",
8992 			__func__, i, __LINE__,
8993 			"failed to allocate symmetric crypto operation");
8994 		ret = TEST_FAILED;
8995 		goto on_err;
8996 	}
8997 
8998 	/* Setup CRC operation parameters */
8999 	crc_len = d_td->ciphertext.no_crc == false ?
9000 			(d_td->ciphertext.len -
9001 				d_td->ciphertext.crc_offset -
9002 				RTE_ETHER_CRC_LEN) :
9003 			0;
9004 	crc_len = crc_len > 0 ? crc_len : 0;
9005 	crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
9006 	ut_params->op->sym->auth.data.length = crc_len;
9007 	ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
9008 
9009 	/* Setup cipher operation parameters */
9010 	cipher_len = d_td->ciphertext.no_cipher == false ?
9011 			(d_td->ciphertext.len -
9012 				d_td->ciphertext.cipher_offset) :
9013 			0;
9014 	cipher_len = cipher_len > 0 ? cipher_len : 0;
9015 	ut_params->op->sym->cipher.data.length = cipher_len;
9016 	ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
9017 
9018 	/* Setup cipher IV */
9019 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9020 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9021 
9022 	/* Attach session to operation */
9023 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
9024 
9025 	/* Set crypto operation mbufs */
9026 	ut_params->op->sym->m_src = ut_params->ibuf;
9027 	ut_params->op->sym->m_dst = NULL;
9028 
9029 	/* Process crypto operation */
9030 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9031 			NULL) {
9032 		printf("TestCase %s(%d) line %d: %s\n",
9033 			__func__, i, __LINE__,
9034 			"failed to process security crypto op");
9035 		ret = TEST_FAILED;
9036 		goto on_err;
9037 	}
9038 
9039 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9040 		printf("TestCase %s(%d) line %d: %s\n",
9041 			__func__, i, __LINE__, "crypto op processing failed");
9042 		ret = TEST_FAILED;
9043 		goto on_err;
9044 	}
9045 
9046 	/* Validate plaintext */
9047 	plaintext = ciphertext;
9048 
9049 	if (memcmp(plaintext, d_td->plaintext.data,
9050 			d_td->plaintext.len - crc_data_len)) {
9051 		printf("TestCase %s(%d) line %d: %s\n",
9052 			__func__, i, __LINE__, "plaintext not as expected\n");
9053 		rte_hexdump(stdout, "expected", d_td->plaintext.data,
9054 				d_td->plaintext.len);
9055 		rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
9056 		ret = TEST_FAILED;
9057 		goto on_err;
9058 	}
9059 
9060 on_err:
9061 	rte_crypto_op_free(ut_params->op);
9062 	ut_params->op = NULL;
9063 
9064 	if (ut_params->sec_session)
9065 		rte_security_session_destroy(ctx, ut_params->sec_session);
9066 	ut_params->sec_session = NULL;
9067 
9068 	rte_pktmbuf_free(ut_params->ibuf);
9069 	ut_params->ibuf = NULL;
9070 
9071 	return ret;
9072 }
9073 
9074 static int
9075 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td)
9076 {
9077 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9078 	struct crypto_unittest_params *ut_params = &unittest_params;
9079 	uint8_t *plaintext, *ciphertext;
9080 	uint8_t *iv_ptr;
9081 	int32_t cipher_len, crc_len;
9082 	int ret = TEST_SUCCESS;
9083 
9084 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9085 					rte_cryptodev_get_sec_ctx(
9086 						ts_params->valid_devs[0]);
9087 
9088 	/* Verify the capabilities */
9089 	struct rte_security_capability_idx sec_cap_idx;
9090 	const struct rte_security_capability *sec_cap;
9091 	const struct rte_cryptodev_capabilities *crypto_cap;
9092 	const struct rte_cryptodev_symmetric_capability *sym_cap;
9093 	int j = 0;
9094 
9095 	sec_cap_idx.action = ut_params->type;
9096 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9097 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9098 
9099 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9100 	if (sec_cap == NULL)
9101 		return TEST_SKIPPED;
9102 
9103 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9104 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9105 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9106 				crypto_cap->sym.xform_type ==
9107 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
9108 				crypto_cap->sym.cipher.algo ==
9109 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9110 			sym_cap = &crypto_cap->sym;
9111 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9112 						d_td->key.len,
9113 						d_td->iv.len) == 0)
9114 				break;
9115 		}
9116 	}
9117 
9118 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9119 		return TEST_SKIPPED;
9120 
9121 	/* Setup source mbuf payload */
9122 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9123 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9124 			rte_pktmbuf_tailroom(ut_params->ibuf));
9125 
9126 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9127 			d_td->plaintext.len);
9128 
9129 	memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
9130 
9131 	/* Setup cipher session parameters */
9132 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9133 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9134 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9135 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9136 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9137 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9138 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9139 	ut_params->cipher_xform.next = NULL;
9140 
9141 	/* Setup DOCSIS session parameters */
9142 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9143 
9144 	struct rte_security_session_conf sess_conf = {
9145 		.action_type = ut_params->type,
9146 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9147 		.docsis = ut_params->docsis_xform,
9148 		.crypto_xform = &ut_params->cipher_xform,
9149 	};
9150 
9151 	/* Create security session */
9152 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9153 					ts_params->session_mpool,
9154 					ts_params->session_priv_mpool);
9155 
9156 	if (!ut_params->sec_session) {
9157 		printf("TestCase %s(%d) line %d: %s\n",
9158 			__func__, i, __LINE__, "failed to allocate session");
9159 		ret = TEST_FAILED;
9160 		goto on_err;
9161 	}
9162 
9163 	/* Generate crypto op data structure */
9164 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9165 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9166 	if (!ut_params->op) {
9167 		printf("TestCase %s(%d) line %d: %s\n",
9168 			__func__, i, __LINE__,
9169 			"failed to allocate security crypto operation");
9170 		ret = TEST_FAILED;
9171 		goto on_err;
9172 	}
9173 
9174 	/* Setup CRC operation parameters */
9175 	crc_len = d_td->plaintext.no_crc == false ?
9176 			(d_td->plaintext.len -
9177 				d_td->plaintext.crc_offset -
9178 				RTE_ETHER_CRC_LEN) :
9179 			0;
9180 	crc_len = crc_len > 0 ? crc_len : 0;
9181 	ut_params->op->sym->auth.data.length = crc_len;
9182 	ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
9183 
9184 	/* Setup cipher operation parameters */
9185 	cipher_len = d_td->plaintext.no_cipher == false ?
9186 			(d_td->plaintext.len -
9187 				d_td->plaintext.cipher_offset) :
9188 			0;
9189 	cipher_len = cipher_len > 0 ? cipher_len : 0;
9190 	ut_params->op->sym->cipher.data.length = cipher_len;
9191 	ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
9192 
9193 	/* Setup cipher IV */
9194 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9195 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9196 
9197 	/* Attach session to operation */
9198 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
9199 
9200 	/* Set crypto operation mbufs */
9201 	ut_params->op->sym->m_src = ut_params->ibuf;
9202 	ut_params->op->sym->m_dst = NULL;
9203 
9204 	/* Process crypto operation */
9205 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9206 			NULL) {
9207 		printf("TestCase %s(%d) line %d: %s\n",
9208 			__func__, i, __LINE__,
9209 			"failed to process security crypto op");
9210 		ret = TEST_FAILED;
9211 		goto on_err;
9212 	}
9213 
9214 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9215 		printf("TestCase %s(%d) line %d: %s\n",
9216 			__func__, i, __LINE__, "crypto op processing failed");
9217 		ret = TEST_FAILED;
9218 		goto on_err;
9219 	}
9220 
9221 	/* Validate ciphertext */
9222 	ciphertext = plaintext;
9223 
9224 	if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
9225 		printf("TestCase %s(%d) line %d: %s\n",
9226 			__func__, i, __LINE__, "ciphertext not as expected\n");
9227 		rte_hexdump(stdout, "expected", d_td->ciphertext.data,
9228 				d_td->ciphertext.len);
9229 		rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
9230 		ret = TEST_FAILED;
9231 		goto on_err;
9232 	}
9233 
9234 on_err:
9235 	rte_crypto_op_free(ut_params->op);
9236 	ut_params->op = NULL;
9237 
9238 	if (ut_params->sec_session)
9239 		rte_security_session_destroy(ctx, ut_params->sec_session);
9240 	ut_params->sec_session = NULL;
9241 
9242 	rte_pktmbuf_free(ut_params->ibuf);
9243 	ut_params->ibuf = NULL;
9244 
9245 	return ret;
9246 }
9247 
9248 #define TEST_DOCSIS_COUNT(func) do {			\
9249 	int ret = func;					\
9250 	if (ret == TEST_SUCCESS)  {			\
9251 		printf("\t%2d)", n++);			\
9252 		printf("+++++ PASSED:" #func"\n");	\
9253 		p++;					\
9254 	} else if (ret == TEST_SKIPPED) {		\
9255 		printf("\t%2d)", n++);			\
9256 		printf("~~~~~ SKIPPED:" #func"\n");	\
9257 		s++;					\
9258 	} else {					\
9259 		printf("\t%2d)", n++);			\
9260 		printf("----- FAILED:" #func"\n");	\
9261 		f++;					\
9262 	}						\
9263 } while (0)
9264 
9265 static int
9266 test_DOCSIS_PROTO_uplink_all(void)
9267 {
9268 	int p = 0, s = 0, f = 0, n = 0;
9269 
9270 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1));
9271 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2));
9272 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3));
9273 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4));
9274 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5));
9275 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6));
9276 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7));
9277 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8));
9278 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9));
9279 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10));
9280 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11));
9281 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12));
9282 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13));
9283 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14));
9284 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15));
9285 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16));
9286 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17));
9287 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18));
9288 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19));
9289 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20));
9290 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21));
9291 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22));
9292 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23));
9293 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24));
9294 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25));
9295 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26));
9296 
9297 	if (f)
9298 		printf("## %s: %d passed out of %d (%d skipped)\n",
9299 			__func__, p, n, s);
9300 
9301 	return f;
9302 };
9303 
9304 static int
9305 test_DOCSIS_PROTO_downlink_all(void)
9306 {
9307 	int p = 0, s = 0, f = 0, n = 0;
9308 
9309 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1));
9310 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2));
9311 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3));
9312 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4));
9313 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5));
9314 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6));
9315 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7));
9316 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8));
9317 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9));
9318 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10));
9319 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11));
9320 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12));
9321 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13));
9322 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14));
9323 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15));
9324 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16));
9325 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17));
9326 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18));
9327 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19));
9328 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20));
9329 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21));
9330 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22));
9331 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23));
9332 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24));
9333 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25));
9334 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26));
9335 
9336 	if (f)
9337 		printf("## %s: %d passed out of %d (%d skipped)\n",
9338 			__func__, p, n, s);
9339 
9340 	return f;
9341 };
9342 
9343 static int
9344 test_DOCSIS_PROTO_all(void)
9345 {
9346 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9347 	struct crypto_unittest_params *ut_params = &unittest_params;
9348 	struct rte_cryptodev_info dev_info;
9349 	int status;
9350 
9351 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9352 	uint64_t feat_flags = dev_info.feature_flags;
9353 
9354 	if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
9355 		return TEST_SKIPPED;
9356 
9357 	/* Set action type */
9358 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9359 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9360 		gbl_action_type;
9361 
9362 	if (security_proto_supported(ut_params->type,
9363 			RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
9364 		return TEST_SKIPPED;
9365 
9366 	status = test_DOCSIS_PROTO_uplink_all();
9367 	status += test_DOCSIS_PROTO_downlink_all();
9368 
9369 	if (status)
9370 		return TEST_FAILED;
9371 	else
9372 		return TEST_SUCCESS;
9373 }
9374 #endif
9375 
9376 static int
9377 test_AES_GCM_authenticated_encryption_test_case_1(void)
9378 {
9379 	return test_authenticated_encryption(&gcm_test_case_1);
9380 }
9381 
9382 static int
9383 test_AES_GCM_authenticated_encryption_test_case_2(void)
9384 {
9385 	return test_authenticated_encryption(&gcm_test_case_2);
9386 }
9387 
9388 static int
9389 test_AES_GCM_authenticated_encryption_test_case_3(void)
9390 {
9391 	return test_authenticated_encryption(&gcm_test_case_3);
9392 }
9393 
9394 static int
9395 test_AES_GCM_authenticated_encryption_test_case_4(void)
9396 {
9397 	return test_authenticated_encryption(&gcm_test_case_4);
9398 }
9399 
9400 static int
9401 test_AES_GCM_authenticated_encryption_test_case_5(void)
9402 {
9403 	return test_authenticated_encryption(&gcm_test_case_5);
9404 }
9405 
9406 static int
9407 test_AES_GCM_authenticated_encryption_test_case_6(void)
9408 {
9409 	return test_authenticated_encryption(&gcm_test_case_6);
9410 }
9411 
9412 static int
9413 test_AES_GCM_authenticated_encryption_test_case_7(void)
9414 {
9415 	return test_authenticated_encryption(&gcm_test_case_7);
9416 }
9417 
9418 static int
9419 test_AES_GCM_authenticated_encryption_test_case_8(void)
9420 {
9421 	return test_authenticated_encryption(&gcm_test_case_8);
9422 }
9423 
9424 static int
9425 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
9426 {
9427 	return test_authenticated_encryption(&gcm_J0_test_case_1);
9428 }
9429 
9430 static int
9431 test_AES_GCM_auth_encryption_test_case_192_1(void)
9432 {
9433 	return test_authenticated_encryption(&gcm_test_case_192_1);
9434 }
9435 
9436 static int
9437 test_AES_GCM_auth_encryption_test_case_192_2(void)
9438 {
9439 	return test_authenticated_encryption(&gcm_test_case_192_2);
9440 }
9441 
9442 static int
9443 test_AES_GCM_auth_encryption_test_case_192_3(void)
9444 {
9445 	return test_authenticated_encryption(&gcm_test_case_192_3);
9446 }
9447 
9448 static int
9449 test_AES_GCM_auth_encryption_test_case_192_4(void)
9450 {
9451 	return test_authenticated_encryption(&gcm_test_case_192_4);
9452 }
9453 
9454 static int
9455 test_AES_GCM_auth_encryption_test_case_192_5(void)
9456 {
9457 	return test_authenticated_encryption(&gcm_test_case_192_5);
9458 }
9459 
9460 static int
9461 test_AES_GCM_auth_encryption_test_case_192_6(void)
9462 {
9463 	return test_authenticated_encryption(&gcm_test_case_192_6);
9464 }
9465 
9466 static int
9467 test_AES_GCM_auth_encryption_test_case_192_7(void)
9468 {
9469 	return test_authenticated_encryption(&gcm_test_case_192_7);
9470 }
9471 
9472 static int
9473 test_AES_GCM_auth_encryption_test_case_256_1(void)
9474 {
9475 	return test_authenticated_encryption(&gcm_test_case_256_1);
9476 }
9477 
9478 static int
9479 test_AES_GCM_auth_encryption_test_case_256_2(void)
9480 {
9481 	return test_authenticated_encryption(&gcm_test_case_256_2);
9482 }
9483 
9484 static int
9485 test_AES_GCM_auth_encryption_test_case_256_3(void)
9486 {
9487 	return test_authenticated_encryption(&gcm_test_case_256_3);
9488 }
9489 
9490 static int
9491 test_AES_GCM_auth_encryption_test_case_256_4(void)
9492 {
9493 	return test_authenticated_encryption(&gcm_test_case_256_4);
9494 }
9495 
9496 static int
9497 test_AES_GCM_auth_encryption_test_case_256_5(void)
9498 {
9499 	return test_authenticated_encryption(&gcm_test_case_256_5);
9500 }
9501 
9502 static int
9503 test_AES_GCM_auth_encryption_test_case_256_6(void)
9504 {
9505 	return test_authenticated_encryption(&gcm_test_case_256_6);
9506 }
9507 
9508 static int
9509 test_AES_GCM_auth_encryption_test_case_256_7(void)
9510 {
9511 	return test_authenticated_encryption(&gcm_test_case_256_7);
9512 }
9513 
9514 static int
9515 test_AES_GCM_auth_encryption_test_case_aad_1(void)
9516 {
9517 	return test_authenticated_encryption(&gcm_test_case_aad_1);
9518 }
9519 
9520 static int
9521 test_AES_GCM_auth_encryption_test_case_aad_2(void)
9522 {
9523 	return test_authenticated_encryption(&gcm_test_case_aad_2);
9524 }
9525 
9526 static int
9527 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
9528 {
9529 	struct aead_test_data tdata;
9530 	int res;
9531 
9532 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9533 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9534 	tdata.iv.data[0] += 1;
9535 	res = test_authenticated_encryption(&tdata);
9536 	if (res == TEST_SKIPPED)
9537 		return res;
9538 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9539 	return TEST_SUCCESS;
9540 }
9541 
9542 static int
9543 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
9544 {
9545 	struct aead_test_data tdata;
9546 	int res;
9547 
9548 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9549 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9550 	tdata.plaintext.data[0] += 1;
9551 	res = test_authenticated_encryption(&tdata);
9552 	if (res == TEST_SKIPPED)
9553 		return res;
9554 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9555 	return TEST_SUCCESS;
9556 }
9557 
9558 static int
9559 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
9560 {
9561 	struct aead_test_data tdata;
9562 	int res;
9563 
9564 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9565 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9566 	tdata.ciphertext.data[0] += 1;
9567 	res = test_authenticated_encryption(&tdata);
9568 	if (res == TEST_SKIPPED)
9569 		return res;
9570 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9571 	return TEST_SUCCESS;
9572 }
9573 
9574 static int
9575 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
9576 {
9577 	struct aead_test_data tdata;
9578 	int res;
9579 
9580 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9581 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9582 	tdata.aad.len += 1;
9583 	res = test_authenticated_encryption(&tdata);
9584 	if (res == TEST_SKIPPED)
9585 		return res;
9586 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9587 	return TEST_SUCCESS;
9588 }
9589 
9590 static int
9591 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
9592 {
9593 	struct aead_test_data tdata;
9594 	uint8_t aad[gcm_test_case_7.aad.len];
9595 	int res;
9596 
9597 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9598 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9599 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
9600 	aad[0] += 1;
9601 	tdata.aad.data = aad;
9602 	res = test_authenticated_encryption(&tdata);
9603 	if (res == TEST_SKIPPED)
9604 		return res;
9605 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9606 	return TEST_SUCCESS;
9607 }
9608 
9609 static int
9610 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
9611 {
9612 	struct aead_test_data tdata;
9613 	int res;
9614 
9615 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9616 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9617 	tdata.auth_tag.data[0] += 1;
9618 	res = test_authenticated_encryption(&tdata);
9619 	if (res == TEST_SKIPPED)
9620 		return res;
9621 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
9622 	return TEST_SUCCESS;
9623 }
9624 
9625 static int
9626 test_authenticated_decryption(const struct aead_test_data *tdata)
9627 {
9628 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9629 	struct crypto_unittest_params *ut_params = &unittest_params;
9630 
9631 	int retval;
9632 	uint8_t *plaintext;
9633 	uint32_t i;
9634 	struct rte_cryptodev_info dev_info;
9635 
9636 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9637 	uint64_t feat_flags = dev_info.feature_flags;
9638 
9639 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
9640 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
9641 		printf("Device doesn't support RAW data-path APIs.\n");
9642 		return TEST_SKIPPED;
9643 	}
9644 
9645 	/* Verify the capabilities */
9646 	struct rte_cryptodev_sym_capability_idx cap_idx;
9647 	const struct rte_cryptodev_symmetric_capability *capability;
9648 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9649 	cap_idx.algo.aead = tdata->algo;
9650 	capability = rte_cryptodev_sym_capability_get(
9651 			ts_params->valid_devs[0], &cap_idx);
9652 	if (capability == NULL)
9653 		return TEST_SKIPPED;
9654 	if (rte_cryptodev_sym_capability_check_aead(
9655 			capability, tdata->key.len, tdata->auth_tag.len,
9656 			tdata->aad.len, tdata->iv.len))
9657 		return TEST_SKIPPED;
9658 
9659 	/* Create AEAD session */
9660 	retval = create_aead_session(ts_params->valid_devs[0],
9661 			tdata->algo,
9662 			RTE_CRYPTO_AEAD_OP_DECRYPT,
9663 			tdata->key.data, tdata->key.len,
9664 			tdata->aad.len, tdata->auth_tag.len,
9665 			tdata->iv.len);
9666 	if (retval < 0)
9667 		return retval;
9668 
9669 	/* alloc mbuf and set payload */
9670 	if (tdata->aad.len > MBUF_SIZE) {
9671 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
9672 		/* Populate full size of add data */
9673 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
9674 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
9675 	} else
9676 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9677 
9678 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9679 			rte_pktmbuf_tailroom(ut_params->ibuf));
9680 
9681 	/* Create AEAD operation */
9682 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
9683 	if (retval < 0)
9684 		return retval;
9685 
9686 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
9687 
9688 	ut_params->op->sym->m_src = ut_params->ibuf;
9689 
9690 	/* Process crypto operation */
9691 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9692 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
9693 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9694 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
9695 				ut_params->op, 0, 0, 0, 0);
9696 	else
9697 		TEST_ASSERT_NOT_NULL(
9698 			process_crypto_request(ts_params->valid_devs[0],
9699 			ut_params->op), "failed to process sym crypto op");
9700 
9701 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
9702 			"crypto op processing failed");
9703 
9704 	if (ut_params->op->sym->m_dst)
9705 		plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
9706 				uint8_t *);
9707 	else
9708 		plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
9709 				uint8_t *,
9710 				ut_params->op->sym->cipher.data.offset);
9711 
9712 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
9713 
9714 	/* Validate obuf */
9715 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
9716 			plaintext,
9717 			tdata->plaintext.data,
9718 			tdata->plaintext.len,
9719 			"Plaintext data not as expected");
9720 
9721 	TEST_ASSERT_EQUAL(ut_params->op->status,
9722 			RTE_CRYPTO_OP_STATUS_SUCCESS,
9723 			"Authentication failed");
9724 
9725 	return 0;
9726 }
9727 
9728 static int
9729 test_AES_GCM_authenticated_decryption_test_case_1(void)
9730 {
9731 	return test_authenticated_decryption(&gcm_test_case_1);
9732 }
9733 
9734 static int
9735 test_AES_GCM_authenticated_decryption_test_case_2(void)
9736 {
9737 	return test_authenticated_decryption(&gcm_test_case_2);
9738 }
9739 
9740 static int
9741 test_AES_GCM_authenticated_decryption_test_case_3(void)
9742 {
9743 	return test_authenticated_decryption(&gcm_test_case_3);
9744 }
9745 
9746 static int
9747 test_AES_GCM_authenticated_decryption_test_case_4(void)
9748 {
9749 	return test_authenticated_decryption(&gcm_test_case_4);
9750 }
9751 
9752 static int
9753 test_AES_GCM_authenticated_decryption_test_case_5(void)
9754 {
9755 	return test_authenticated_decryption(&gcm_test_case_5);
9756 }
9757 
9758 static int
9759 test_AES_GCM_authenticated_decryption_test_case_6(void)
9760 {
9761 	return test_authenticated_decryption(&gcm_test_case_6);
9762 }
9763 
9764 static int
9765 test_AES_GCM_authenticated_decryption_test_case_7(void)
9766 {
9767 	return test_authenticated_decryption(&gcm_test_case_7);
9768 }
9769 
9770 static int
9771 test_AES_GCM_authenticated_decryption_test_case_8(void)
9772 {
9773 	return test_authenticated_decryption(&gcm_test_case_8);
9774 }
9775 
9776 static int
9777 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
9778 {
9779 	return test_authenticated_decryption(&gcm_J0_test_case_1);
9780 }
9781 
9782 static int
9783 test_AES_GCM_auth_decryption_test_case_192_1(void)
9784 {
9785 	return test_authenticated_decryption(&gcm_test_case_192_1);
9786 }
9787 
9788 static int
9789 test_AES_GCM_auth_decryption_test_case_192_2(void)
9790 {
9791 	return test_authenticated_decryption(&gcm_test_case_192_2);
9792 }
9793 
9794 static int
9795 test_AES_GCM_auth_decryption_test_case_192_3(void)
9796 {
9797 	return test_authenticated_decryption(&gcm_test_case_192_3);
9798 }
9799 
9800 static int
9801 test_AES_GCM_auth_decryption_test_case_192_4(void)
9802 {
9803 	return test_authenticated_decryption(&gcm_test_case_192_4);
9804 }
9805 
9806 static int
9807 test_AES_GCM_auth_decryption_test_case_192_5(void)
9808 {
9809 	return test_authenticated_decryption(&gcm_test_case_192_5);
9810 }
9811 
9812 static int
9813 test_AES_GCM_auth_decryption_test_case_192_6(void)
9814 {
9815 	return test_authenticated_decryption(&gcm_test_case_192_6);
9816 }
9817 
9818 static int
9819 test_AES_GCM_auth_decryption_test_case_192_7(void)
9820 {
9821 	return test_authenticated_decryption(&gcm_test_case_192_7);
9822 }
9823 
9824 static int
9825 test_AES_GCM_auth_decryption_test_case_256_1(void)
9826 {
9827 	return test_authenticated_decryption(&gcm_test_case_256_1);
9828 }
9829 
9830 static int
9831 test_AES_GCM_auth_decryption_test_case_256_2(void)
9832 {
9833 	return test_authenticated_decryption(&gcm_test_case_256_2);
9834 }
9835 
9836 static int
9837 test_AES_GCM_auth_decryption_test_case_256_3(void)
9838 {
9839 	return test_authenticated_decryption(&gcm_test_case_256_3);
9840 }
9841 
9842 static int
9843 test_AES_GCM_auth_decryption_test_case_256_4(void)
9844 {
9845 	return test_authenticated_decryption(&gcm_test_case_256_4);
9846 }
9847 
9848 static int
9849 test_AES_GCM_auth_decryption_test_case_256_5(void)
9850 {
9851 	return test_authenticated_decryption(&gcm_test_case_256_5);
9852 }
9853 
9854 static int
9855 test_AES_GCM_auth_decryption_test_case_256_6(void)
9856 {
9857 	return test_authenticated_decryption(&gcm_test_case_256_6);
9858 }
9859 
9860 static int
9861 test_AES_GCM_auth_decryption_test_case_256_7(void)
9862 {
9863 	return test_authenticated_decryption(&gcm_test_case_256_7);
9864 }
9865 
9866 static int
9867 test_AES_GCM_auth_decryption_test_case_aad_1(void)
9868 {
9869 	return test_authenticated_decryption(&gcm_test_case_aad_1);
9870 }
9871 
9872 static int
9873 test_AES_GCM_auth_decryption_test_case_aad_2(void)
9874 {
9875 	return test_authenticated_decryption(&gcm_test_case_aad_2);
9876 }
9877 
9878 static int
9879 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
9880 {
9881 	struct aead_test_data tdata;
9882 	int res;
9883 
9884 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9885 	tdata.iv.data[0] += 1;
9886 	res = test_authenticated_decryption(&tdata);
9887 	if (res == TEST_SKIPPED)
9888 		return res;
9889 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9890 	return TEST_SUCCESS;
9891 }
9892 
9893 static int
9894 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
9895 {
9896 	struct aead_test_data tdata;
9897 	int res;
9898 
9899 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
9900 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9901 	tdata.plaintext.data[0] += 1;
9902 	res = test_authenticated_decryption(&tdata);
9903 	if (res == TEST_SKIPPED)
9904 		return res;
9905 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9906 	return TEST_SUCCESS;
9907 }
9908 
9909 static int
9910 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
9911 {
9912 	struct aead_test_data tdata;
9913 	int res;
9914 
9915 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9916 	tdata.ciphertext.data[0] += 1;
9917 	res = test_authenticated_decryption(&tdata);
9918 	if (res == TEST_SKIPPED)
9919 		return res;
9920 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9921 	return TEST_SUCCESS;
9922 }
9923 
9924 static int
9925 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
9926 {
9927 	struct aead_test_data tdata;
9928 	int res;
9929 
9930 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9931 	tdata.aad.len += 1;
9932 	res = test_authenticated_decryption(&tdata);
9933 	if (res == TEST_SKIPPED)
9934 		return res;
9935 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9936 	return TEST_SUCCESS;
9937 }
9938 
9939 static int
9940 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
9941 {
9942 	struct aead_test_data tdata;
9943 	uint8_t aad[gcm_test_case_7.aad.len];
9944 	int res;
9945 
9946 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9947 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
9948 	aad[0] += 1;
9949 	tdata.aad.data = aad;
9950 	res = test_authenticated_decryption(&tdata);
9951 	if (res == TEST_SKIPPED)
9952 		return res;
9953 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
9954 	return TEST_SUCCESS;
9955 }
9956 
9957 static int
9958 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
9959 {
9960 	struct aead_test_data tdata;
9961 	int res;
9962 
9963 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
9964 	tdata.auth_tag.data[0] += 1;
9965 	res = test_authenticated_decryption(&tdata);
9966 	if (res == TEST_SKIPPED)
9967 		return res;
9968 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
9969 	return TEST_SUCCESS;
9970 }
9971 
9972 static int
9973 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
9974 {
9975 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9976 	struct crypto_unittest_params *ut_params = &unittest_params;
9977 
9978 	int retval;
9979 	uint8_t *ciphertext, *auth_tag;
9980 	uint16_t plaintext_pad_len;
9981 
9982 	/* Verify the capabilities */
9983 	struct rte_cryptodev_sym_capability_idx cap_idx;
9984 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
9985 	cap_idx.algo.aead = tdata->algo;
9986 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
9987 			&cap_idx) == NULL)
9988 		return TEST_SKIPPED;
9989 
9990 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
9991 		return TEST_SKIPPED;
9992 
9993 	/* not supported with CPU crypto */
9994 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
9995 		return TEST_SKIPPED;
9996 
9997 	/* Create AEAD session */
9998 	retval = create_aead_session(ts_params->valid_devs[0],
9999 			tdata->algo,
10000 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
10001 			tdata->key.data, tdata->key.len,
10002 			tdata->aad.len, tdata->auth_tag.len,
10003 			tdata->iv.len);
10004 	if (retval < 0)
10005 		return retval;
10006 
10007 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10008 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10009 
10010 	/* clear mbuf payload */
10011 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10012 			rte_pktmbuf_tailroom(ut_params->ibuf));
10013 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10014 			rte_pktmbuf_tailroom(ut_params->obuf));
10015 
10016 	/* Create AEAD operation */
10017 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10018 	if (retval < 0)
10019 		return retval;
10020 
10021 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10022 
10023 	ut_params->op->sym->m_src = ut_params->ibuf;
10024 	ut_params->op->sym->m_dst = ut_params->obuf;
10025 
10026 	/* Process crypto operation */
10027 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10028 			ut_params->op), "failed to process sym crypto op");
10029 
10030 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10031 			"crypto op processing failed");
10032 
10033 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10034 
10035 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10036 			ut_params->op->sym->cipher.data.offset);
10037 	auth_tag = ciphertext + plaintext_pad_len;
10038 
10039 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10040 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10041 
10042 	/* Validate obuf */
10043 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10044 			ciphertext,
10045 			tdata->ciphertext.data,
10046 			tdata->ciphertext.len,
10047 			"Ciphertext data not as expected");
10048 
10049 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10050 			auth_tag,
10051 			tdata->auth_tag.data,
10052 			tdata->auth_tag.len,
10053 			"Generated auth tag not as expected");
10054 
10055 	return 0;
10056 
10057 }
10058 
10059 static int
10060 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
10061 {
10062 	return test_authenticated_encryption_oop(&gcm_test_case_5);
10063 }
10064 
10065 static int
10066 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
10067 {
10068 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10069 	struct crypto_unittest_params *ut_params = &unittest_params;
10070 
10071 	int retval;
10072 	uint8_t *plaintext;
10073 
10074 	/* Verify the capabilities */
10075 	struct rte_cryptodev_sym_capability_idx cap_idx;
10076 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10077 	cap_idx.algo.aead = tdata->algo;
10078 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10079 			&cap_idx) == NULL)
10080 		return TEST_SKIPPED;
10081 
10082 	/* not supported with CPU crypto and raw data-path APIs*/
10083 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
10084 			global_api_test_type == CRYPTODEV_RAW_API_TEST)
10085 		return TEST_SKIPPED;
10086 
10087 	/* Create AEAD session */
10088 	retval = create_aead_session(ts_params->valid_devs[0],
10089 			tdata->algo,
10090 			RTE_CRYPTO_AEAD_OP_DECRYPT,
10091 			tdata->key.data, tdata->key.len,
10092 			tdata->aad.len, tdata->auth_tag.len,
10093 			tdata->iv.len);
10094 	if (retval < 0)
10095 		return retval;
10096 
10097 	/* alloc mbuf and set payload */
10098 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10099 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10100 
10101 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10102 			rte_pktmbuf_tailroom(ut_params->ibuf));
10103 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10104 			rte_pktmbuf_tailroom(ut_params->obuf));
10105 
10106 	/* Create AEAD operation */
10107 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10108 	if (retval < 0)
10109 		return retval;
10110 
10111 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10112 
10113 	ut_params->op->sym->m_src = ut_params->ibuf;
10114 	ut_params->op->sym->m_dst = ut_params->obuf;
10115 
10116 	/* Process crypto operation */
10117 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10118 			ut_params->op), "failed to process sym crypto op");
10119 
10120 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10121 			"crypto op processing failed");
10122 
10123 	plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10124 			ut_params->op->sym->cipher.data.offset);
10125 
10126 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10127 
10128 	/* Validate obuf */
10129 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10130 			plaintext,
10131 			tdata->plaintext.data,
10132 			tdata->plaintext.len,
10133 			"Plaintext data not as expected");
10134 
10135 	TEST_ASSERT_EQUAL(ut_params->op->status,
10136 			RTE_CRYPTO_OP_STATUS_SUCCESS,
10137 			"Authentication failed");
10138 	return 0;
10139 }
10140 
10141 static int
10142 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
10143 {
10144 	return test_authenticated_decryption_oop(&gcm_test_case_5);
10145 }
10146 
10147 static int
10148 test_authenticated_encryption_sessionless(
10149 		const struct aead_test_data *tdata)
10150 {
10151 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10152 	struct crypto_unittest_params *ut_params = &unittest_params;
10153 
10154 	int retval;
10155 	uint8_t *ciphertext, *auth_tag;
10156 	uint16_t plaintext_pad_len;
10157 	uint8_t key[tdata->key.len + 1];
10158 	struct rte_cryptodev_info dev_info;
10159 
10160 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10161 	uint64_t feat_flags = dev_info.feature_flags;
10162 
10163 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10164 		printf("Device doesn't support Sessionless ops.\n");
10165 		return TEST_SKIPPED;
10166 	}
10167 
10168 	/* not supported with CPU crypto */
10169 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10170 		return TEST_SKIPPED;
10171 
10172 	/* Verify the capabilities */
10173 	struct rte_cryptodev_sym_capability_idx cap_idx;
10174 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10175 	cap_idx.algo.aead = tdata->algo;
10176 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10177 			&cap_idx) == NULL)
10178 		return TEST_SKIPPED;
10179 
10180 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10181 
10182 	/* clear mbuf payload */
10183 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10184 			rte_pktmbuf_tailroom(ut_params->ibuf));
10185 
10186 	/* Create AEAD operation */
10187 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10188 	if (retval < 0)
10189 		return retval;
10190 
10191 	/* Create GCM xform */
10192 	memcpy(key, tdata->key.data, tdata->key.len);
10193 	retval = create_aead_xform(ut_params->op,
10194 			tdata->algo,
10195 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
10196 			key, tdata->key.len,
10197 			tdata->aad.len, tdata->auth_tag.len,
10198 			tdata->iv.len);
10199 	if (retval < 0)
10200 		return retval;
10201 
10202 	ut_params->op->sym->m_src = ut_params->ibuf;
10203 
10204 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10205 			RTE_CRYPTO_OP_SESSIONLESS,
10206 			"crypto op session type not sessionless");
10207 
10208 	/* Process crypto operation */
10209 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10210 			ut_params->op), "failed to process sym crypto op");
10211 
10212 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10213 
10214 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10215 			"crypto op status not success");
10216 
10217 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10218 
10219 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10220 			ut_params->op->sym->cipher.data.offset);
10221 	auth_tag = ciphertext + plaintext_pad_len;
10222 
10223 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10224 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10225 
10226 	/* Validate obuf */
10227 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10228 			ciphertext,
10229 			tdata->ciphertext.data,
10230 			tdata->ciphertext.len,
10231 			"Ciphertext data not as expected");
10232 
10233 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10234 			auth_tag,
10235 			tdata->auth_tag.data,
10236 			tdata->auth_tag.len,
10237 			"Generated auth tag not as expected");
10238 
10239 	return 0;
10240 
10241 }
10242 
10243 static int
10244 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
10245 {
10246 	return test_authenticated_encryption_sessionless(
10247 			&gcm_test_case_5);
10248 }
10249 
10250 static int
10251 test_authenticated_decryption_sessionless(
10252 		const struct aead_test_data *tdata)
10253 {
10254 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10255 	struct crypto_unittest_params *ut_params = &unittest_params;
10256 
10257 	int retval;
10258 	uint8_t *plaintext;
10259 	uint8_t key[tdata->key.len + 1];
10260 	struct rte_cryptodev_info dev_info;
10261 
10262 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10263 	uint64_t feat_flags = dev_info.feature_flags;
10264 
10265 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10266 		printf("Device doesn't support Sessionless ops.\n");
10267 		return TEST_SKIPPED;
10268 	}
10269 
10270 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10271 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10272 		printf("Device doesn't support RAW data-path APIs.\n");
10273 		return TEST_SKIPPED;
10274 	}
10275 
10276 	/* not supported with CPU crypto */
10277 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10278 		return TEST_SKIPPED;
10279 
10280 	/* Verify the capabilities */
10281 	struct rte_cryptodev_sym_capability_idx cap_idx;
10282 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10283 	cap_idx.algo.aead = tdata->algo;
10284 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10285 			&cap_idx) == NULL)
10286 		return TEST_SKIPPED;
10287 
10288 	/* alloc mbuf and set payload */
10289 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10290 
10291 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10292 			rte_pktmbuf_tailroom(ut_params->ibuf));
10293 
10294 	/* Create AEAD operation */
10295 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10296 	if (retval < 0)
10297 		return retval;
10298 
10299 	/* Create AEAD xform */
10300 	memcpy(key, tdata->key.data, tdata->key.len);
10301 	retval = create_aead_xform(ut_params->op,
10302 			tdata->algo,
10303 			RTE_CRYPTO_AEAD_OP_DECRYPT,
10304 			key, tdata->key.len,
10305 			tdata->aad.len, tdata->auth_tag.len,
10306 			tdata->iv.len);
10307 	if (retval < 0)
10308 		return retval;
10309 
10310 	ut_params->op->sym->m_src = ut_params->ibuf;
10311 
10312 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10313 			RTE_CRYPTO_OP_SESSIONLESS,
10314 			"crypto op session type not sessionless");
10315 
10316 	/* Process crypto operation */
10317 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10318 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10319 				ut_params->op, 0, 0, 0, 0);
10320 	else
10321 		TEST_ASSERT_NOT_NULL(process_crypto_request(
10322 			ts_params->valid_devs[0], ut_params->op),
10323 				"failed to process sym crypto op");
10324 
10325 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10326 
10327 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10328 			"crypto op status not success");
10329 
10330 	plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10331 			ut_params->op->sym->cipher.data.offset);
10332 
10333 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10334 
10335 	/* Validate obuf */
10336 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10337 			plaintext,
10338 			tdata->plaintext.data,
10339 			tdata->plaintext.len,
10340 			"Plaintext data not as expected");
10341 
10342 	TEST_ASSERT_EQUAL(ut_params->op->status,
10343 			RTE_CRYPTO_OP_STATUS_SUCCESS,
10344 			"Authentication failed");
10345 	return 0;
10346 }
10347 
10348 static int
10349 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
10350 {
10351 	return test_authenticated_decryption_sessionless(
10352 			&gcm_test_case_5);
10353 }
10354 
10355 static int
10356 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
10357 {
10358 	return test_authenticated_encryption(&ccm_test_case_128_1);
10359 }
10360 
10361 static int
10362 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
10363 {
10364 	return test_authenticated_encryption(&ccm_test_case_128_2);
10365 }
10366 
10367 static int
10368 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
10369 {
10370 	return test_authenticated_encryption(&ccm_test_case_128_3);
10371 }
10372 
10373 static int
10374 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
10375 {
10376 	return test_authenticated_decryption(&ccm_test_case_128_1);
10377 }
10378 
10379 static int
10380 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
10381 {
10382 	return test_authenticated_decryption(&ccm_test_case_128_2);
10383 }
10384 
10385 static int
10386 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
10387 {
10388 	return test_authenticated_decryption(&ccm_test_case_128_3);
10389 }
10390 
10391 static int
10392 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
10393 {
10394 	return test_authenticated_encryption(&ccm_test_case_192_1);
10395 }
10396 
10397 static int
10398 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
10399 {
10400 	return test_authenticated_encryption(&ccm_test_case_192_2);
10401 }
10402 
10403 static int
10404 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
10405 {
10406 	return test_authenticated_encryption(&ccm_test_case_192_3);
10407 }
10408 
10409 static int
10410 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
10411 {
10412 	return test_authenticated_decryption(&ccm_test_case_192_1);
10413 }
10414 
10415 static int
10416 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
10417 {
10418 	return test_authenticated_decryption(&ccm_test_case_192_2);
10419 }
10420 
10421 static int
10422 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
10423 {
10424 	return test_authenticated_decryption(&ccm_test_case_192_3);
10425 }
10426 
10427 static int
10428 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
10429 {
10430 	return test_authenticated_encryption(&ccm_test_case_256_1);
10431 }
10432 
10433 static int
10434 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
10435 {
10436 	return test_authenticated_encryption(&ccm_test_case_256_2);
10437 }
10438 
10439 static int
10440 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
10441 {
10442 	return test_authenticated_encryption(&ccm_test_case_256_3);
10443 }
10444 
10445 static int
10446 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
10447 {
10448 	return test_authenticated_decryption(&ccm_test_case_256_1);
10449 }
10450 
10451 static int
10452 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
10453 {
10454 	return test_authenticated_decryption(&ccm_test_case_256_2);
10455 }
10456 
10457 static int
10458 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
10459 {
10460 	return test_authenticated_decryption(&ccm_test_case_256_3);
10461 }
10462 
10463 static int
10464 test_stats(void)
10465 {
10466 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10467 	struct rte_cryptodev_stats stats;
10468 
10469 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10470 		return TEST_SKIPPED;
10471 
10472 	/* Verify the capabilities */
10473 	struct rte_cryptodev_sym_capability_idx cap_idx;
10474 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10475 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
10476 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10477 			&cap_idx) == NULL)
10478 		return TEST_SKIPPED;
10479 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10480 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10481 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10482 			&cap_idx) == NULL)
10483 		return TEST_SKIPPED;
10484 
10485 	if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
10486 			== -ENOTSUP)
10487 		return TEST_SKIPPED;
10488 
10489 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10490 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
10491 			&stats) == -ENODEV),
10492 		"rte_cryptodev_stats_get invalid dev failed");
10493 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
10494 		"rte_cryptodev_stats_get invalid Param failed");
10495 
10496 	/* Test expected values */
10497 	test_AES_CBC_HMAC_SHA1_encrypt_digest();
10498 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10499 			&stats),
10500 		"rte_cryptodev_stats_get failed");
10501 	TEST_ASSERT((stats.enqueued_count == 1),
10502 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10503 	TEST_ASSERT((stats.dequeued_count == 1),
10504 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10505 	TEST_ASSERT((stats.enqueue_err_count == 0),
10506 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10507 	TEST_ASSERT((stats.dequeue_err_count == 0),
10508 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10509 
10510 	/* invalid device but should ignore and not reset device stats*/
10511 	rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
10512 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10513 			&stats),
10514 		"rte_cryptodev_stats_get failed");
10515 	TEST_ASSERT((stats.enqueued_count == 1),
10516 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10517 
10518 	/* check that a valid reset clears stats */
10519 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
10520 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
10521 			&stats),
10522 					  "rte_cryptodev_stats_get failed");
10523 	TEST_ASSERT((stats.enqueued_count == 0),
10524 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10525 	TEST_ASSERT((stats.dequeued_count == 0),
10526 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
10527 
10528 	return TEST_SUCCESS;
10529 }
10530 
10531 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
10532 				   struct crypto_unittest_params *ut_params,
10533 				   enum rte_crypto_auth_operation op,
10534 				   const struct HMAC_MD5_vector *test_case)
10535 {
10536 	uint8_t key[64];
10537 
10538 	memcpy(key, test_case->key.data, test_case->key.len);
10539 
10540 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10541 	ut_params->auth_xform.next = NULL;
10542 	ut_params->auth_xform.auth.op = op;
10543 
10544 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
10545 
10546 	ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
10547 	ut_params->auth_xform.auth.key.length = test_case->key.len;
10548 	ut_params->auth_xform.auth.key.data = key;
10549 
10550 	ut_params->sess = rte_cryptodev_sym_session_create(
10551 			ts_params->session_mpool);
10552 
10553 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10554 			ut_params->sess, &ut_params->auth_xform,
10555 			ts_params->session_priv_mpool);
10556 
10557 	if (ut_params->sess == NULL)
10558 		return TEST_FAILED;
10559 
10560 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10561 
10562 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10563 			rte_pktmbuf_tailroom(ut_params->ibuf));
10564 
10565 	return 0;
10566 }
10567 
10568 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
10569 			      const struct HMAC_MD5_vector *test_case,
10570 			      uint8_t **plaintext)
10571 {
10572 	uint16_t plaintext_pad_len;
10573 
10574 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
10575 
10576 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
10577 				16);
10578 
10579 	*plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10580 			plaintext_pad_len);
10581 	memcpy(*plaintext, test_case->plaintext.data,
10582 			test_case->plaintext.len);
10583 
10584 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
10585 			ut_params->ibuf, MD5_DIGEST_LEN);
10586 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
10587 			"no room to append digest");
10588 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
10589 			ut_params->ibuf, plaintext_pad_len);
10590 
10591 	if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
10592 		rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
10593 			   test_case->auth_tag.len);
10594 	}
10595 
10596 	sym_op->auth.data.offset = 0;
10597 	sym_op->auth.data.length = test_case->plaintext.len;
10598 
10599 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10600 	ut_params->op->sym->m_src = ut_params->ibuf;
10601 
10602 	return 0;
10603 }
10604 
10605 static int
10606 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
10607 {
10608 	uint16_t plaintext_pad_len;
10609 	uint8_t *plaintext, *auth_tag;
10610 
10611 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10612 	struct crypto_unittest_params *ut_params = &unittest_params;
10613 	struct rte_cryptodev_info dev_info;
10614 
10615 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10616 	uint64_t feat_flags = dev_info.feature_flags;
10617 
10618 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10619 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10620 		printf("Device doesn't support RAW data-path APIs.\n");
10621 		return TEST_SKIPPED;
10622 	}
10623 
10624 	/* Verify the capabilities */
10625 	struct rte_cryptodev_sym_capability_idx cap_idx;
10626 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10627 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
10628 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10629 			&cap_idx) == NULL)
10630 		return TEST_SKIPPED;
10631 
10632 	if (MD5_HMAC_create_session(ts_params, ut_params,
10633 			RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
10634 		return TEST_FAILED;
10635 
10636 	/* Generate Crypto op data structure */
10637 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10638 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10639 	TEST_ASSERT_NOT_NULL(ut_params->op,
10640 			"Failed to allocate symmetric crypto operation struct");
10641 
10642 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
10643 				16);
10644 
10645 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
10646 		return TEST_FAILED;
10647 
10648 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10649 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10650 			ut_params->op);
10651 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10652 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10653 				ut_params->op, 0, 1, 0, 0);
10654 	else
10655 		TEST_ASSERT_NOT_NULL(
10656 			process_crypto_request(ts_params->valid_devs[0],
10657 				ut_params->op),
10658 				"failed to process sym crypto op");
10659 
10660 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10661 			"crypto op processing failed");
10662 
10663 	if (ut_params->op->sym->m_dst) {
10664 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
10665 				uint8_t *, plaintext_pad_len);
10666 	} else {
10667 		auth_tag = plaintext + plaintext_pad_len;
10668 	}
10669 
10670 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10671 			auth_tag,
10672 			test_case->auth_tag.data,
10673 			test_case->auth_tag.len,
10674 			"HMAC_MD5 generated tag not as expected");
10675 
10676 	return TEST_SUCCESS;
10677 }
10678 
10679 static int
10680 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
10681 {
10682 	uint8_t *plaintext;
10683 
10684 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10685 	struct crypto_unittest_params *ut_params = &unittest_params;
10686 	struct rte_cryptodev_info dev_info;
10687 
10688 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10689 	uint64_t feat_flags = dev_info.feature_flags;
10690 
10691 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10692 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10693 		printf("Device doesn't support RAW data-path APIs.\n");
10694 		return TEST_SKIPPED;
10695 	}
10696 
10697 	/* Verify the capabilities */
10698 	struct rte_cryptodev_sym_capability_idx cap_idx;
10699 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10700 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
10701 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10702 			&cap_idx) == NULL)
10703 		return TEST_SKIPPED;
10704 
10705 	if (MD5_HMAC_create_session(ts_params, ut_params,
10706 			RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
10707 		return TEST_FAILED;
10708 	}
10709 
10710 	/* Generate Crypto op data structure */
10711 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10712 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10713 	TEST_ASSERT_NOT_NULL(ut_params->op,
10714 			"Failed to allocate symmetric crypto operation struct");
10715 
10716 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
10717 		return TEST_FAILED;
10718 
10719 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10720 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
10721 			ut_params->op);
10722 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10723 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10724 				ut_params->op, 0, 1, 0, 0);
10725 	else
10726 		TEST_ASSERT_NOT_NULL(
10727 			process_crypto_request(ts_params->valid_devs[0],
10728 				ut_params->op),
10729 				"failed to process sym crypto op");
10730 
10731 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10732 			"HMAC_MD5 crypto op processing failed");
10733 
10734 	return TEST_SUCCESS;
10735 }
10736 
10737 static int
10738 test_MD5_HMAC_generate_case_1(void)
10739 {
10740 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
10741 }
10742 
10743 static int
10744 test_MD5_HMAC_verify_case_1(void)
10745 {
10746 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
10747 }
10748 
10749 static int
10750 test_MD5_HMAC_generate_case_2(void)
10751 {
10752 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
10753 }
10754 
10755 static int
10756 test_MD5_HMAC_verify_case_2(void)
10757 {
10758 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
10759 }
10760 
10761 static int
10762 test_multi_session(void)
10763 {
10764 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10765 	struct crypto_unittest_params *ut_params = &unittest_params;
10766 
10767 	struct rte_cryptodev_info dev_info;
10768 	struct rte_cryptodev_sym_session **sessions;
10769 
10770 	uint16_t i;
10771 
10772 	/* Verify the capabilities */
10773 	struct rte_cryptodev_sym_capability_idx cap_idx;
10774 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10775 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
10776 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10777 			&cap_idx) == NULL)
10778 		return TEST_SKIPPED;
10779 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10780 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10781 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10782 			&cap_idx) == NULL)
10783 		return TEST_SKIPPED;
10784 
10785 	test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
10786 			aes_cbc_key, hmac_sha512_key);
10787 
10788 
10789 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10790 
10791 	sessions = rte_malloc(NULL,
10792 			sizeof(struct rte_cryptodev_sym_session *) *
10793 			(MAX_NB_SESSIONS + 1), 0);
10794 
10795 	/* Create multiple crypto sessions*/
10796 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
10797 
10798 		sessions[i] = rte_cryptodev_sym_session_create(
10799 				ts_params->session_mpool);
10800 
10801 		rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10802 				sessions[i], &ut_params->auth_xform,
10803 				ts_params->session_priv_mpool);
10804 		TEST_ASSERT_NOT_NULL(sessions[i],
10805 				"Session creation failed at session number %u",
10806 				i);
10807 
10808 		/* Attempt to send a request on each session */
10809 		TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
10810 			sessions[i],
10811 			ut_params,
10812 			ts_params,
10813 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
10814 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
10815 			aes_cbc_iv),
10816 			"Failed to perform decrypt on request number %u.", i);
10817 		/* free crypto operation structure */
10818 		if (ut_params->op)
10819 			rte_crypto_op_free(ut_params->op);
10820 
10821 		/*
10822 		 * free mbuf - both obuf and ibuf are usually the same,
10823 		 * so check if they point at the same address is necessary,
10824 		 * to avoid freeing the mbuf twice.
10825 		 */
10826 		if (ut_params->obuf) {
10827 			rte_pktmbuf_free(ut_params->obuf);
10828 			if (ut_params->ibuf == ut_params->obuf)
10829 				ut_params->ibuf = 0;
10830 			ut_params->obuf = 0;
10831 		}
10832 		if (ut_params->ibuf) {
10833 			rte_pktmbuf_free(ut_params->ibuf);
10834 			ut_params->ibuf = 0;
10835 		}
10836 	}
10837 
10838 	sessions[i] = NULL;
10839 	/* Next session create should fail */
10840 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
10841 			sessions[i], &ut_params->auth_xform,
10842 			ts_params->session_priv_mpool);
10843 	TEST_ASSERT_NULL(sessions[i],
10844 			"Session creation succeeded unexpectedly!");
10845 
10846 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
10847 		rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
10848 				sessions[i]);
10849 		rte_cryptodev_sym_session_free(sessions[i]);
10850 	}
10851 
10852 	rte_free(sessions);
10853 
10854 	return TEST_SUCCESS;
10855 }
10856 
10857 struct multi_session_params {
10858 	struct crypto_unittest_params ut_params;
10859 	uint8_t *cipher_key;
10860 	uint8_t *hmac_key;
10861 	const uint8_t *cipher;
10862 	const uint8_t *digest;
10863 	uint8_t *iv;
10864 };
10865 
10866 #define MB_SESSION_NUMBER 3
10867 
10868 static int
10869 test_multi_session_random_usage(void)
10870 {
10871 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10872 	struct rte_cryptodev_info dev_info;
10873 	struct rte_cryptodev_sym_session **sessions;
10874 	uint32_t i, j;
10875 	struct multi_session_params ut_paramz[] = {
10876 
10877 		{
10878 			.cipher_key = ms_aes_cbc_key0,
10879 			.hmac_key = ms_hmac_key0,
10880 			.cipher = ms_aes_cbc_cipher0,
10881 			.digest = ms_hmac_digest0,
10882 			.iv = ms_aes_cbc_iv0
10883 		},
10884 		{
10885 			.cipher_key = ms_aes_cbc_key1,
10886 			.hmac_key = ms_hmac_key1,
10887 			.cipher = ms_aes_cbc_cipher1,
10888 			.digest = ms_hmac_digest1,
10889 			.iv = ms_aes_cbc_iv1
10890 		},
10891 		{
10892 			.cipher_key = ms_aes_cbc_key2,
10893 			.hmac_key = ms_hmac_key2,
10894 			.cipher = ms_aes_cbc_cipher2,
10895 			.digest = ms_hmac_digest2,
10896 			.iv = ms_aes_cbc_iv2
10897 		},
10898 
10899 	};
10900 
10901 	/* Verify the capabilities */
10902 	struct rte_cryptodev_sym_capability_idx cap_idx;
10903 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
10904 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
10905 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10906 			&cap_idx) == NULL)
10907 		return TEST_SKIPPED;
10908 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10909 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
10910 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10911 			&cap_idx) == NULL)
10912 		return TEST_SKIPPED;
10913 
10914 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10915 
10916 	sessions = rte_malloc(NULL,
10917 			(sizeof(struct rte_cryptodev_sym_session *)
10918 					* MAX_NB_SESSIONS) + 1, 0);
10919 
10920 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
10921 		sessions[i] = rte_cryptodev_sym_session_create(
10922 				ts_params->session_mpool);
10923 
10924 		rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
10925 				sizeof(struct crypto_unittest_params));
10926 
10927 		test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
10928 				&ut_paramz[i].ut_params,
10929 				ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
10930 
10931 		/* Create multiple crypto sessions*/
10932 		rte_cryptodev_sym_session_init(
10933 				ts_params->valid_devs[0],
10934 				sessions[i],
10935 				&ut_paramz[i].ut_params.auth_xform,
10936 				ts_params->session_priv_mpool);
10937 
10938 		TEST_ASSERT_NOT_NULL(sessions[i],
10939 				"Session creation failed at session number %u",
10940 				i);
10941 
10942 	}
10943 
10944 	srand(time(NULL));
10945 	for (i = 0; i < 40000; i++) {
10946 
10947 		j = rand() % MB_SESSION_NUMBER;
10948 
10949 		TEST_ASSERT_SUCCESS(
10950 			test_AES_CBC_HMAC_SHA512_decrypt_perform(
10951 					sessions[j],
10952 					&ut_paramz[j].ut_params,
10953 					ts_params, ut_paramz[j].cipher,
10954 					ut_paramz[j].digest,
10955 					ut_paramz[j].iv),
10956 			"Failed to perform decrypt on request number %u.", i);
10957 
10958 		if (ut_paramz[j].ut_params.op)
10959 			rte_crypto_op_free(ut_paramz[j].ut_params.op);
10960 
10961 		/*
10962 		 * free mbuf - both obuf and ibuf are usually the same,
10963 		 * so check if they point at the same address is necessary,
10964 		 * to avoid freeing the mbuf twice.
10965 		 */
10966 		if (ut_paramz[j].ut_params.obuf) {
10967 			rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
10968 			if (ut_paramz[j].ut_params.ibuf
10969 					== ut_paramz[j].ut_params.obuf)
10970 				ut_paramz[j].ut_params.ibuf = 0;
10971 			ut_paramz[j].ut_params.obuf = 0;
10972 		}
10973 		if (ut_paramz[j].ut_params.ibuf) {
10974 			rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
10975 			ut_paramz[j].ut_params.ibuf = 0;
10976 		}
10977 	}
10978 
10979 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
10980 		rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
10981 				sessions[i]);
10982 		rte_cryptodev_sym_session_free(sessions[i]);
10983 	}
10984 
10985 	rte_free(sessions);
10986 
10987 	return TEST_SUCCESS;
10988 }
10989 
10990 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
10991 			0xab, 0xab, 0xab, 0xab,
10992 			0xab, 0xab, 0xab, 0xab,
10993 			0xab, 0xab, 0xab, 0xab};
10994 
10995 static int
10996 test_null_invalid_operation(void)
10997 {
10998 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10999 	struct crypto_unittest_params *ut_params = &unittest_params;
11000 	int ret;
11001 
11002 	/* This test is for NULL PMD only */
11003 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
11004 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11005 		return TEST_SKIPPED;
11006 
11007 	/* Setup Cipher Parameters */
11008 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11009 	ut_params->cipher_xform.next = NULL;
11010 
11011 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
11012 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11013 
11014 	ut_params->sess = rte_cryptodev_sym_session_create(
11015 			ts_params->session_mpool);
11016 
11017 	/* Create Crypto session*/
11018 	ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11019 			ut_params->sess, &ut_params->cipher_xform,
11020 			ts_params->session_priv_mpool);
11021 	TEST_ASSERT(ret < 0,
11022 			"Session creation succeeded unexpectedly");
11023 
11024 
11025 	/* Setup HMAC Parameters */
11026 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11027 	ut_params->auth_xform.next = NULL;
11028 
11029 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
11030 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11031 
11032 	ut_params->sess = rte_cryptodev_sym_session_create(
11033 			ts_params->session_mpool);
11034 
11035 	/* Create Crypto session*/
11036 	ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11037 			ut_params->sess, &ut_params->auth_xform,
11038 			ts_params->session_priv_mpool);
11039 	TEST_ASSERT(ret < 0,
11040 			"Session creation succeeded unexpectedly");
11041 
11042 	return TEST_SUCCESS;
11043 }
11044 
11045 
11046 #define NULL_BURST_LENGTH (32)
11047 
11048 static int
11049 test_null_burst_operation(void)
11050 {
11051 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11052 	struct crypto_unittest_params *ut_params = &unittest_params;
11053 
11054 	unsigned i, burst_len = NULL_BURST_LENGTH;
11055 
11056 	struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
11057 	struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
11058 
11059 	/* This test is for NULL PMD only */
11060 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
11061 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11062 		return TEST_SKIPPED;
11063 
11064 	/* Setup Cipher Parameters */
11065 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11066 	ut_params->cipher_xform.next = &ut_params->auth_xform;
11067 
11068 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
11069 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11070 
11071 	/* Setup HMAC Parameters */
11072 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11073 	ut_params->auth_xform.next = NULL;
11074 
11075 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
11076 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11077 
11078 	ut_params->sess = rte_cryptodev_sym_session_create(
11079 			ts_params->session_mpool);
11080 
11081 	/* Create Crypto session*/
11082 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11083 			ut_params->sess, &ut_params->cipher_xform,
11084 			ts_params->session_priv_mpool);
11085 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11086 
11087 	TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
11088 			RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
11089 			burst_len, "failed to generate burst of crypto ops");
11090 
11091 	/* Generate an operation for each mbuf in burst */
11092 	for (i = 0; i < burst_len; i++) {
11093 		struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11094 
11095 		TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
11096 
11097 		unsigned *data = (unsigned *)rte_pktmbuf_append(m,
11098 				sizeof(unsigned));
11099 		*data = i;
11100 
11101 		rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
11102 
11103 		burst[i]->sym->m_src = m;
11104 	}
11105 
11106 	/* Process crypto operation */
11107 	TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
11108 			0, burst, burst_len),
11109 			burst_len,
11110 			"Error enqueuing burst");
11111 
11112 	TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
11113 			0, burst_dequeued, burst_len),
11114 			burst_len,
11115 			"Error dequeuing burst");
11116 
11117 
11118 	for (i = 0; i < burst_len; i++) {
11119 		TEST_ASSERT_EQUAL(
11120 			*rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
11121 			*rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
11122 					uint32_t *),
11123 			"data not as expected");
11124 
11125 		rte_pktmbuf_free(burst[i]->sym->m_src);
11126 		rte_crypto_op_free(burst[i]);
11127 	}
11128 
11129 	return TEST_SUCCESS;
11130 }
11131 
11132 static uint16_t
11133 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11134 		  uint16_t nb_ops, void *user_param)
11135 {
11136 	RTE_SET_USED(dev_id);
11137 	RTE_SET_USED(qp_id);
11138 	RTE_SET_USED(ops);
11139 	RTE_SET_USED(user_param);
11140 
11141 	printf("crypto enqueue callback called\n");
11142 	return nb_ops;
11143 }
11144 
11145 static uint16_t
11146 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11147 		  uint16_t nb_ops, void *user_param)
11148 {
11149 	RTE_SET_USED(dev_id);
11150 	RTE_SET_USED(qp_id);
11151 	RTE_SET_USED(ops);
11152 	RTE_SET_USED(user_param);
11153 
11154 	printf("crypto dequeue callback called\n");
11155 	return nb_ops;
11156 }
11157 
11158 /*
11159  * Thread using enqueue/dequeue callback with RCU.
11160  */
11161 static int
11162 test_enqdeq_callback_thread(void *arg)
11163 {
11164 	RTE_SET_USED(arg);
11165 	/* DP thread calls rte_cryptodev_enqueue_burst()/
11166 	 * rte_cryptodev_dequeue_burst() and invokes callback.
11167 	 */
11168 	test_null_burst_operation();
11169 	return 0;
11170 }
11171 
11172 static int
11173 test_enq_callback_setup(void)
11174 {
11175 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11176 	struct rte_cryptodev_info dev_info;
11177 	struct rte_cryptodev_qp_conf qp_conf = {
11178 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
11179 	};
11180 
11181 	struct rte_cryptodev_cb *cb;
11182 	uint16_t qp_id = 0;
11183 
11184 	/* Stop the device in case it's started so it can be configured */
11185 	rte_cryptodev_stop(ts_params->valid_devs[0]);
11186 
11187 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11188 
11189 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11190 			&ts_params->conf),
11191 			"Failed to configure cryptodev %u",
11192 			ts_params->valid_devs[0]);
11193 
11194 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11195 	qp_conf.mp_session = ts_params->session_mpool;
11196 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
11197 
11198 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11199 			ts_params->valid_devs[0], qp_id, &qp_conf,
11200 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11201 			"Failed test for "
11202 			"rte_cryptodev_queue_pair_setup: num_inflights "
11203 			"%u on qp %u on cryptodev %u",
11204 			qp_conf.nb_descriptors, qp_id,
11205 			ts_params->valid_devs[0]);
11206 
11207 	/* Test with invalid crypto device */
11208 	cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
11209 			qp_id, test_enq_callback, NULL);
11210 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11211 			"cryptodev %u did not fail",
11212 			qp_id, RTE_CRYPTO_MAX_DEVS);
11213 
11214 	/* Test with invalid queue pair */
11215 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11216 			dev_info.max_nb_queue_pairs + 1,
11217 			test_enq_callback, NULL);
11218 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11219 			"cryptodev %u did not fail",
11220 			dev_info.max_nb_queue_pairs + 1,
11221 			ts_params->valid_devs[0]);
11222 
11223 	/* Test with NULL callback */
11224 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11225 			qp_id, NULL, NULL);
11226 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11227 			"cryptodev %u did not fail",
11228 			qp_id, ts_params->valid_devs[0]);
11229 
11230 	/* Test with valid configuration */
11231 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11232 			qp_id, test_enq_callback, NULL);
11233 	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11234 			"qp %u on cryptodev %u",
11235 			qp_id, ts_params->valid_devs[0]);
11236 
11237 	rte_cryptodev_start(ts_params->valid_devs[0]);
11238 
11239 	/* Launch a thread */
11240 	rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11241 				rte_get_next_lcore(-1, 1, 0));
11242 
11243 	/* Wait until reader exited. */
11244 	rte_eal_mp_wait_lcore();
11245 
11246 	/* Test with invalid crypto device */
11247 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11248 			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11249 			"Expected call to fail as crypto device is invalid");
11250 
11251 	/* Test with invalid queue pair */
11252 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11253 			ts_params->valid_devs[0],
11254 			dev_info.max_nb_queue_pairs + 1, cb),
11255 			"Expected call to fail as queue pair is invalid");
11256 
11257 	/* Test with NULL callback */
11258 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11259 			ts_params->valid_devs[0], qp_id, NULL),
11260 			"Expected call to fail as callback is NULL");
11261 
11262 	/* Test with valid configuration */
11263 	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
11264 			ts_params->valid_devs[0], qp_id, cb),
11265 			"Failed test to remove callback on "
11266 			"qp %u on cryptodev %u",
11267 			qp_id, ts_params->valid_devs[0]);
11268 
11269 	return TEST_SUCCESS;
11270 }
11271 
11272 static int
11273 test_deq_callback_setup(void)
11274 {
11275 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11276 	struct rte_cryptodev_info dev_info;
11277 	struct rte_cryptodev_qp_conf qp_conf = {
11278 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
11279 	};
11280 
11281 	struct rte_cryptodev_cb *cb;
11282 	uint16_t qp_id = 0;
11283 
11284 	/* Stop the device in case it's started so it can be configured */
11285 	rte_cryptodev_stop(ts_params->valid_devs[0]);
11286 
11287 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11288 
11289 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11290 			&ts_params->conf),
11291 			"Failed to configure cryptodev %u",
11292 			ts_params->valid_devs[0]);
11293 
11294 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11295 	qp_conf.mp_session = ts_params->session_mpool;
11296 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
11297 
11298 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11299 			ts_params->valid_devs[0], qp_id, &qp_conf,
11300 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11301 			"Failed test for "
11302 			"rte_cryptodev_queue_pair_setup: num_inflights "
11303 			"%u on qp %u on cryptodev %u",
11304 			qp_conf.nb_descriptors, qp_id,
11305 			ts_params->valid_devs[0]);
11306 
11307 	/* Test with invalid crypto device */
11308 	cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
11309 			qp_id, test_deq_callback, NULL);
11310 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11311 			"cryptodev %u did not fail",
11312 			qp_id, RTE_CRYPTO_MAX_DEVS);
11313 
11314 	/* Test with invalid queue pair */
11315 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11316 			dev_info.max_nb_queue_pairs + 1,
11317 			test_deq_callback, NULL);
11318 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11319 			"cryptodev %u did not fail",
11320 			dev_info.max_nb_queue_pairs + 1,
11321 			ts_params->valid_devs[0]);
11322 
11323 	/* Test with NULL callback */
11324 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11325 			qp_id, NULL, NULL);
11326 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11327 			"cryptodev %u did not fail",
11328 			qp_id, ts_params->valid_devs[0]);
11329 
11330 	/* Test with valid configuration */
11331 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11332 			qp_id, test_deq_callback, NULL);
11333 	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11334 			"qp %u on cryptodev %u",
11335 			qp_id, ts_params->valid_devs[0]);
11336 
11337 	rte_cryptodev_start(ts_params->valid_devs[0]);
11338 
11339 	/* Launch a thread */
11340 	rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11341 				rte_get_next_lcore(-1, 1, 0));
11342 
11343 	/* Wait until reader exited. */
11344 	rte_eal_mp_wait_lcore();
11345 
11346 	/* Test with invalid crypto device */
11347 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11348 			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11349 			"Expected call to fail as crypto device is invalid");
11350 
11351 	/* Test with invalid queue pair */
11352 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11353 			ts_params->valid_devs[0],
11354 			dev_info.max_nb_queue_pairs + 1, cb),
11355 			"Expected call to fail as queue pair is invalid");
11356 
11357 	/* Test with NULL callback */
11358 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11359 			ts_params->valid_devs[0], qp_id, NULL),
11360 			"Expected call to fail as callback is NULL");
11361 
11362 	/* Test with valid configuration */
11363 	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
11364 			ts_params->valid_devs[0], qp_id, cb),
11365 			"Failed test to remove callback on "
11366 			"qp %u on cryptodev %u",
11367 			qp_id, ts_params->valid_devs[0]);
11368 
11369 	return TEST_SUCCESS;
11370 }
11371 
11372 static void
11373 generate_gmac_large_plaintext(uint8_t *data)
11374 {
11375 	uint16_t i;
11376 
11377 	for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
11378 		memcpy(&data[i], &data[0], 32);
11379 }
11380 
11381 static int
11382 create_gmac_operation(enum rte_crypto_auth_operation op,
11383 		const struct gmac_test_data *tdata)
11384 {
11385 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11386 	struct crypto_unittest_params *ut_params = &unittest_params;
11387 	struct rte_crypto_sym_op *sym_op;
11388 
11389 	uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11390 
11391 	/* Generate Crypto op data structure */
11392 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11393 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11394 	TEST_ASSERT_NOT_NULL(ut_params->op,
11395 			"Failed to allocate symmetric crypto operation struct");
11396 
11397 	sym_op = ut_params->op->sym;
11398 
11399 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11400 			ut_params->ibuf, tdata->gmac_tag.len);
11401 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11402 			"no room to append digest");
11403 
11404 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11405 			ut_params->ibuf, plaintext_pad_len);
11406 
11407 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11408 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11409 				tdata->gmac_tag.len);
11410 		debug_hexdump(stdout, "digest:",
11411 				sym_op->auth.digest.data,
11412 				tdata->gmac_tag.len);
11413 	}
11414 
11415 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11416 			uint8_t *, IV_OFFSET);
11417 
11418 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11419 
11420 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11421 
11422 	sym_op->cipher.data.length = 0;
11423 	sym_op->cipher.data.offset = 0;
11424 
11425 	sym_op->auth.data.offset = 0;
11426 	sym_op->auth.data.length = tdata->plaintext.len;
11427 
11428 	return 0;
11429 }
11430 
11431 static int
11432 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
11433 		const struct gmac_test_data *tdata,
11434 		void *digest_mem, uint64_t digest_phys)
11435 {
11436 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11437 	struct crypto_unittest_params *ut_params = &unittest_params;
11438 	struct rte_crypto_sym_op *sym_op;
11439 
11440 	/* Generate Crypto op data structure */
11441 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11442 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11443 	TEST_ASSERT_NOT_NULL(ut_params->op,
11444 			"Failed to allocate symmetric crypto operation struct");
11445 
11446 	sym_op = ut_params->op->sym;
11447 
11448 	sym_op->auth.digest.data = digest_mem;
11449 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11450 			"no room to append digest");
11451 
11452 	sym_op->auth.digest.phys_addr = digest_phys;
11453 
11454 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11455 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11456 				tdata->gmac_tag.len);
11457 		debug_hexdump(stdout, "digest:",
11458 				sym_op->auth.digest.data,
11459 				tdata->gmac_tag.len);
11460 	}
11461 
11462 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11463 			uint8_t *, IV_OFFSET);
11464 
11465 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11466 
11467 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11468 
11469 	sym_op->cipher.data.length = 0;
11470 	sym_op->cipher.data.offset = 0;
11471 
11472 	sym_op->auth.data.offset = 0;
11473 	sym_op->auth.data.length = tdata->plaintext.len;
11474 
11475 	return 0;
11476 }
11477 
11478 static int create_gmac_session(uint8_t dev_id,
11479 		const struct gmac_test_data *tdata,
11480 		enum rte_crypto_auth_operation auth_op)
11481 {
11482 	uint8_t auth_key[tdata->key.len];
11483 
11484 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11485 	struct crypto_unittest_params *ut_params = &unittest_params;
11486 
11487 	memcpy(auth_key, tdata->key.data, tdata->key.len);
11488 
11489 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11490 	ut_params->auth_xform.next = NULL;
11491 
11492 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
11493 	ut_params->auth_xform.auth.op = auth_op;
11494 	ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
11495 	ut_params->auth_xform.auth.key.length = tdata->key.len;
11496 	ut_params->auth_xform.auth.key.data = auth_key;
11497 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
11498 	ut_params->auth_xform.auth.iv.length = tdata->iv.len;
11499 
11500 
11501 	ut_params->sess = rte_cryptodev_sym_session_create(
11502 			ts_params->session_mpool);
11503 
11504 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
11505 			&ut_params->auth_xform,
11506 			ts_params->session_priv_mpool);
11507 
11508 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11509 
11510 	return 0;
11511 }
11512 
11513 static int
11514 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
11515 {
11516 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11517 	struct crypto_unittest_params *ut_params = &unittest_params;
11518 	struct rte_cryptodev_info dev_info;
11519 
11520 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11521 	uint64_t feat_flags = dev_info.feature_flags;
11522 
11523 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11524 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11525 		printf("Device doesn't support RAW data-path APIs.\n");
11526 		return TEST_SKIPPED;
11527 	}
11528 
11529 	int retval;
11530 
11531 	uint8_t *auth_tag, *plaintext;
11532 	uint16_t plaintext_pad_len;
11533 
11534 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11535 			      "No GMAC length in the source data");
11536 
11537 	/* Verify the capabilities */
11538 	struct rte_cryptodev_sym_capability_idx cap_idx;
11539 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11540 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11541 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11542 			&cap_idx) == NULL)
11543 		return TEST_SKIPPED;
11544 
11545 	retval = create_gmac_session(ts_params->valid_devs[0],
11546 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
11547 
11548 	if (retval < 0)
11549 		return retval;
11550 
11551 	if (tdata->plaintext.len > MBUF_SIZE)
11552 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
11553 	else
11554 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11555 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11556 			"Failed to allocate input buffer in mempool");
11557 
11558 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11559 			rte_pktmbuf_tailroom(ut_params->ibuf));
11560 
11561 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11562 	/*
11563 	 * Runtime generate the large plain text instead of use hard code
11564 	 * plain text vector. It is done to avoid create huge source file
11565 	 * with the test vector.
11566 	 */
11567 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
11568 		generate_gmac_large_plaintext(tdata->plaintext.data);
11569 
11570 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11571 				plaintext_pad_len);
11572 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11573 
11574 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
11575 	debug_hexdump(stdout, "plaintext:", plaintext,
11576 			tdata->plaintext.len);
11577 
11578 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
11579 			tdata);
11580 
11581 	if (retval < 0)
11582 		return retval;
11583 
11584 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11585 
11586 	ut_params->op->sym->m_src = ut_params->ibuf;
11587 
11588 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11589 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11590 			ut_params->op);
11591 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11592 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11593 				ut_params->op, 0, 1, 0, 0);
11594 	else
11595 		TEST_ASSERT_NOT_NULL(
11596 			process_crypto_request(ts_params->valid_devs[0],
11597 			ut_params->op), "failed to process sym crypto op");
11598 
11599 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11600 			"crypto op processing failed");
11601 
11602 	if (ut_params->op->sym->m_dst) {
11603 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11604 				uint8_t *, plaintext_pad_len);
11605 	} else {
11606 		auth_tag = plaintext + plaintext_pad_len;
11607 	}
11608 
11609 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
11610 
11611 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11612 			auth_tag,
11613 			tdata->gmac_tag.data,
11614 			tdata->gmac_tag.len,
11615 			"GMAC Generated auth tag not as expected");
11616 
11617 	return 0;
11618 }
11619 
11620 static int
11621 test_AES_GMAC_authentication_test_case_1(void)
11622 {
11623 	return test_AES_GMAC_authentication(&gmac_test_case_1);
11624 }
11625 
11626 static int
11627 test_AES_GMAC_authentication_test_case_2(void)
11628 {
11629 	return test_AES_GMAC_authentication(&gmac_test_case_2);
11630 }
11631 
11632 static int
11633 test_AES_GMAC_authentication_test_case_3(void)
11634 {
11635 	return test_AES_GMAC_authentication(&gmac_test_case_3);
11636 }
11637 
11638 static int
11639 test_AES_GMAC_authentication_test_case_4(void)
11640 {
11641 	return test_AES_GMAC_authentication(&gmac_test_case_4);
11642 }
11643 
11644 static int
11645 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
11646 {
11647 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11648 	struct crypto_unittest_params *ut_params = &unittest_params;
11649 	int retval;
11650 	uint32_t plaintext_pad_len;
11651 	uint8_t *plaintext;
11652 	struct rte_cryptodev_info dev_info;
11653 
11654 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11655 	uint64_t feat_flags = dev_info.feature_flags;
11656 
11657 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11658 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11659 		printf("Device doesn't support RAW data-path APIs.\n");
11660 		return TEST_SKIPPED;
11661 	}
11662 
11663 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11664 			      "No GMAC length in the source data");
11665 
11666 	/* Verify the capabilities */
11667 	struct rte_cryptodev_sym_capability_idx cap_idx;
11668 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11669 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11670 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11671 			&cap_idx) == NULL)
11672 		return TEST_SKIPPED;
11673 
11674 	retval = create_gmac_session(ts_params->valid_devs[0],
11675 			tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
11676 
11677 	if (retval < 0)
11678 		return retval;
11679 
11680 	if (tdata->plaintext.len > MBUF_SIZE)
11681 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
11682 	else
11683 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11684 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11685 			"Failed to allocate input buffer in mempool");
11686 
11687 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11688 			rte_pktmbuf_tailroom(ut_params->ibuf));
11689 
11690 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11691 
11692 	/*
11693 	 * Runtime generate the large plain text instead of use hard code
11694 	 * plain text vector. It is done to avoid create huge source file
11695 	 * with the test vector.
11696 	 */
11697 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
11698 		generate_gmac_large_plaintext(tdata->plaintext.data);
11699 
11700 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11701 				plaintext_pad_len);
11702 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11703 
11704 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
11705 	debug_hexdump(stdout, "plaintext:", plaintext,
11706 			tdata->plaintext.len);
11707 
11708 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
11709 			tdata);
11710 
11711 	if (retval < 0)
11712 		return retval;
11713 
11714 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11715 
11716 	ut_params->op->sym->m_src = ut_params->ibuf;
11717 
11718 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11719 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11720 			ut_params->op);
11721 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11722 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11723 				ut_params->op, 0, 1, 0, 0);
11724 	else
11725 		TEST_ASSERT_NOT_NULL(
11726 			process_crypto_request(ts_params->valid_devs[0],
11727 			ut_params->op), "failed to process sym crypto op");
11728 
11729 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11730 			"crypto op processing failed");
11731 
11732 	return 0;
11733 
11734 }
11735 
11736 static int
11737 test_AES_GMAC_authentication_verify_test_case_1(void)
11738 {
11739 	return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
11740 }
11741 
11742 static int
11743 test_AES_GMAC_authentication_verify_test_case_2(void)
11744 {
11745 	return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
11746 }
11747 
11748 static int
11749 test_AES_GMAC_authentication_verify_test_case_3(void)
11750 {
11751 	return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
11752 }
11753 
11754 static int
11755 test_AES_GMAC_authentication_verify_test_case_4(void)
11756 {
11757 	return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
11758 }
11759 
11760 static int
11761 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
11762 				uint32_t fragsz)
11763 {
11764 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11765 	struct crypto_unittest_params *ut_params = &unittest_params;
11766 	struct rte_cryptodev_info dev_info;
11767 	uint64_t feature_flags;
11768 	unsigned int trn_data = 0;
11769 	void *digest_mem = NULL;
11770 	uint32_t segs = 1;
11771 	unsigned int to_trn = 0;
11772 	struct rte_mbuf *buf = NULL;
11773 	uint8_t *auth_tag, *plaintext;
11774 	int retval;
11775 
11776 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
11777 			      "No GMAC length in the source data");
11778 
11779 	/* Verify the capabilities */
11780 	struct rte_cryptodev_sym_capability_idx cap_idx;
11781 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11782 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
11783 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11784 			&cap_idx) == NULL)
11785 		return TEST_SKIPPED;
11786 
11787 	/* Check for any input SGL support */
11788 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11789 	feature_flags = dev_info.feature_flags;
11790 
11791 	if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
11792 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
11793 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
11794 		return TEST_SKIPPED;
11795 
11796 	if (fragsz > tdata->plaintext.len)
11797 		fragsz = tdata->plaintext.len;
11798 
11799 	uint16_t plaintext_len = fragsz;
11800 
11801 	retval = create_gmac_session(ts_params->valid_devs[0],
11802 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
11803 
11804 	if (retval < 0)
11805 		return retval;
11806 
11807 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11808 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
11809 			"Failed to allocate input buffer in mempool");
11810 
11811 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11812 			rte_pktmbuf_tailroom(ut_params->ibuf));
11813 
11814 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11815 				plaintext_len);
11816 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
11817 
11818 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
11819 
11820 	trn_data += plaintext_len;
11821 
11822 	buf = ut_params->ibuf;
11823 
11824 	/*
11825 	 * Loop until no more fragments
11826 	 */
11827 
11828 	while (trn_data < tdata->plaintext.len) {
11829 		++segs;
11830 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
11831 				(tdata->plaintext.len - trn_data) : fragsz;
11832 
11833 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11834 		buf = buf->next;
11835 
11836 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
11837 				rte_pktmbuf_tailroom(buf));
11838 
11839 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
11840 				to_trn);
11841 
11842 		memcpy(plaintext, tdata->plaintext.data + trn_data,
11843 				to_trn);
11844 		trn_data += to_trn;
11845 		if (trn_data  == tdata->plaintext.len)
11846 			digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
11847 					tdata->gmac_tag.len);
11848 	}
11849 	ut_params->ibuf->nb_segs = segs;
11850 
11851 	/*
11852 	 * Place digest at the end of the last buffer
11853 	 */
11854 	uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
11855 
11856 	if (!digest_mem) {
11857 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11858 				+ tdata->gmac_tag.len);
11859 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
11860 				tdata->plaintext.len);
11861 	}
11862 
11863 	retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
11864 			tdata, digest_mem, digest_phys);
11865 
11866 	if (retval < 0)
11867 		return retval;
11868 
11869 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11870 
11871 	ut_params->op->sym->m_src = ut_params->ibuf;
11872 
11873 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11874 		return TEST_SKIPPED;
11875 
11876 	TEST_ASSERT_NOT_NULL(
11877 		process_crypto_request(ts_params->valid_devs[0],
11878 		ut_params->op), "failed to process sym crypto op");
11879 
11880 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11881 			"crypto op processing failed");
11882 
11883 	auth_tag = digest_mem;
11884 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
11885 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11886 			auth_tag,
11887 			tdata->gmac_tag.data,
11888 			tdata->gmac_tag.len,
11889 			"GMAC Generated auth tag not as expected");
11890 
11891 	return 0;
11892 }
11893 
11894 /* Segment size not multiple of block size (16B) */
11895 static int
11896 test_AES_GMAC_authentication_SGL_40B(void)
11897 {
11898 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
11899 }
11900 
11901 static int
11902 test_AES_GMAC_authentication_SGL_80B(void)
11903 {
11904 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
11905 }
11906 
11907 static int
11908 test_AES_GMAC_authentication_SGL_2048B(void)
11909 {
11910 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
11911 }
11912 
11913 /* Segment size not multiple of block size (16B) */
11914 static int
11915 test_AES_GMAC_authentication_SGL_2047B(void)
11916 {
11917 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
11918 }
11919 
11920 struct test_crypto_vector {
11921 	enum rte_crypto_cipher_algorithm crypto_algo;
11922 	unsigned int cipher_offset;
11923 	unsigned int cipher_len;
11924 
11925 	struct {
11926 		uint8_t data[64];
11927 		unsigned int len;
11928 	} cipher_key;
11929 
11930 	struct {
11931 		uint8_t data[64];
11932 		unsigned int len;
11933 	} iv;
11934 
11935 	struct {
11936 		const uint8_t *data;
11937 		unsigned int len;
11938 	} plaintext;
11939 
11940 	struct {
11941 		const uint8_t *data;
11942 		unsigned int len;
11943 	} ciphertext;
11944 
11945 	enum rte_crypto_auth_algorithm auth_algo;
11946 	unsigned int auth_offset;
11947 
11948 	struct {
11949 		uint8_t data[128];
11950 		unsigned int len;
11951 	} auth_key;
11952 
11953 	struct {
11954 		const uint8_t *data;
11955 		unsigned int len;
11956 	} aad;
11957 
11958 	struct {
11959 		uint8_t data[128];
11960 		unsigned int len;
11961 	} digest;
11962 };
11963 
11964 static const struct test_crypto_vector
11965 hmac_sha1_test_crypto_vector = {
11966 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
11967 	.plaintext = {
11968 		.data = plaintext_hash,
11969 		.len = 512
11970 	},
11971 	.auth_key = {
11972 		.data = {
11973 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
11974 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
11975 			0xDE, 0xF4, 0xDE, 0xAD
11976 		},
11977 		.len = 20
11978 	},
11979 	.digest = {
11980 		.data = {
11981 			0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
11982 			0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
11983 			0x3F, 0x91, 0x64, 0x59
11984 		},
11985 		.len = 20
11986 	}
11987 };
11988 
11989 static const struct test_crypto_vector
11990 aes128_gmac_test_vector = {
11991 	.auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
11992 	.plaintext = {
11993 		.data = plaintext_hash,
11994 		.len = 512
11995 	},
11996 	.iv = {
11997 		.data = {
11998 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
11999 			0x08, 0x09, 0x0A, 0x0B
12000 		},
12001 		.len = 12
12002 	},
12003 	.auth_key = {
12004 		.data = {
12005 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12006 			0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
12007 		},
12008 		.len = 16
12009 	},
12010 	.digest = {
12011 		.data = {
12012 			0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
12013 			0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
12014 		},
12015 		.len = 16
12016 	}
12017 };
12018 
12019 static const struct test_crypto_vector
12020 aes128cbc_hmac_sha1_test_vector = {
12021 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12022 	.cipher_offset = 0,
12023 	.cipher_len = 512,
12024 	.cipher_key = {
12025 		.data = {
12026 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12027 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12028 		},
12029 		.len = 16
12030 	},
12031 	.iv = {
12032 		.data = {
12033 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12034 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12035 		},
12036 		.len = 16
12037 	},
12038 	.plaintext = {
12039 		.data = plaintext_hash,
12040 		.len = 512
12041 	},
12042 	.ciphertext = {
12043 		.data = ciphertext512_aes128cbc,
12044 		.len = 512
12045 	},
12046 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12047 	.auth_offset = 0,
12048 	.auth_key = {
12049 		.data = {
12050 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12051 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12052 			0xDE, 0xF4, 0xDE, 0xAD
12053 		},
12054 		.len = 20
12055 	},
12056 	.digest = {
12057 		.data = {
12058 			0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
12059 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12060 			0x18, 0x8C, 0x1D, 0x32
12061 		},
12062 		.len = 20
12063 	}
12064 };
12065 
12066 static const struct test_crypto_vector
12067 aes128cbc_hmac_sha1_aad_test_vector = {
12068 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12069 	.cipher_offset = 8,
12070 	.cipher_len = 496,
12071 	.cipher_key = {
12072 		.data = {
12073 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12074 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12075 		},
12076 		.len = 16
12077 	},
12078 	.iv = {
12079 		.data = {
12080 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12081 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12082 		},
12083 		.len = 16
12084 	},
12085 	.plaintext = {
12086 		.data = plaintext_hash,
12087 		.len = 512
12088 	},
12089 	.ciphertext = {
12090 		.data = ciphertext512_aes128cbc_aad,
12091 		.len = 512
12092 	},
12093 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12094 	.auth_offset = 0,
12095 	.auth_key = {
12096 		.data = {
12097 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12098 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12099 			0xDE, 0xF4, 0xDE, 0xAD
12100 		},
12101 		.len = 20
12102 	},
12103 	.digest = {
12104 		.data = {
12105 			0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
12106 			0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
12107 			0x62, 0x0F, 0xFB, 0x10
12108 		},
12109 		.len = 20
12110 	}
12111 };
12112 
12113 static void
12114 data_corruption(uint8_t *data)
12115 {
12116 	data[0] += 1;
12117 }
12118 
12119 static void
12120 tag_corruption(uint8_t *data, unsigned int tag_offset)
12121 {
12122 	data[tag_offset] += 1;
12123 }
12124 
12125 static int
12126 create_auth_session(struct crypto_unittest_params *ut_params,
12127 		uint8_t dev_id,
12128 		const struct test_crypto_vector *reference,
12129 		enum rte_crypto_auth_operation auth_op)
12130 {
12131 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12132 	uint8_t auth_key[reference->auth_key.len + 1];
12133 
12134 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12135 
12136 	/* Setup Authentication Parameters */
12137 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12138 	ut_params->auth_xform.auth.op = auth_op;
12139 	ut_params->auth_xform.next = NULL;
12140 	ut_params->auth_xform.auth.algo = reference->auth_algo;
12141 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12142 	ut_params->auth_xform.auth.key.data = auth_key;
12143 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
12144 
12145 	/* Create Crypto session*/
12146 	ut_params->sess = rte_cryptodev_sym_session_create(
12147 			ts_params->session_mpool);
12148 
12149 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12150 				&ut_params->auth_xform,
12151 				ts_params->session_priv_mpool);
12152 
12153 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12154 
12155 	return 0;
12156 }
12157 
12158 static int
12159 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
12160 		uint8_t dev_id,
12161 		const struct test_crypto_vector *reference,
12162 		enum rte_crypto_auth_operation auth_op,
12163 		enum rte_crypto_cipher_operation cipher_op)
12164 {
12165 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12166 	uint8_t cipher_key[reference->cipher_key.len + 1];
12167 	uint8_t auth_key[reference->auth_key.len + 1];
12168 
12169 	memcpy(cipher_key, reference->cipher_key.data,
12170 			reference->cipher_key.len);
12171 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12172 
12173 	/* Setup Authentication Parameters */
12174 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12175 	ut_params->auth_xform.auth.op = auth_op;
12176 	ut_params->auth_xform.auth.algo = reference->auth_algo;
12177 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12178 	ut_params->auth_xform.auth.key.data = auth_key;
12179 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
12180 
12181 	if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
12182 		ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12183 		ut_params->auth_xform.auth.iv.length = reference->iv.len;
12184 	} else {
12185 		ut_params->auth_xform.next = &ut_params->cipher_xform;
12186 
12187 		/* Setup Cipher Parameters */
12188 		ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12189 		ut_params->cipher_xform.next = NULL;
12190 		ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12191 		ut_params->cipher_xform.cipher.op = cipher_op;
12192 		ut_params->cipher_xform.cipher.key.data = cipher_key;
12193 		ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12194 		ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12195 		ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12196 	}
12197 
12198 	/* Create Crypto session*/
12199 	ut_params->sess = rte_cryptodev_sym_session_create(
12200 			ts_params->session_mpool);
12201 
12202 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12203 				&ut_params->auth_xform,
12204 				ts_params->session_priv_mpool);
12205 
12206 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12207 
12208 	return 0;
12209 }
12210 
12211 static int
12212 create_auth_operation(struct crypto_testsuite_params *ts_params,
12213 		struct crypto_unittest_params *ut_params,
12214 		const struct test_crypto_vector *reference,
12215 		unsigned int auth_generate)
12216 {
12217 	/* Generate Crypto op data structure */
12218 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12219 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12220 	TEST_ASSERT_NOT_NULL(ut_params->op,
12221 			"Failed to allocate pktmbuf offload");
12222 
12223 	/* Set crypto operation data parameters */
12224 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12225 
12226 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12227 
12228 	/* set crypto operation source mbuf */
12229 	sym_op->m_src = ut_params->ibuf;
12230 
12231 	/* digest */
12232 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12233 			ut_params->ibuf, reference->digest.len);
12234 
12235 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12236 			"no room to append auth tag");
12237 
12238 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12239 			ut_params->ibuf, reference->plaintext.len);
12240 
12241 	if (auth_generate)
12242 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
12243 	else
12244 		memcpy(sym_op->auth.digest.data,
12245 				reference->digest.data,
12246 				reference->digest.len);
12247 
12248 	debug_hexdump(stdout, "digest:",
12249 			sym_op->auth.digest.data,
12250 			reference->digest.len);
12251 
12252 	sym_op->auth.data.length = reference->plaintext.len;
12253 	sym_op->auth.data.offset = 0;
12254 
12255 	return 0;
12256 }
12257 
12258 static int
12259 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
12260 		struct crypto_unittest_params *ut_params,
12261 		const struct test_crypto_vector *reference,
12262 		unsigned int auth_generate)
12263 {
12264 	/* Generate Crypto op data structure */
12265 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12266 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12267 	TEST_ASSERT_NOT_NULL(ut_params->op,
12268 			"Failed to allocate pktmbuf offload");
12269 
12270 	/* Set crypto operation data parameters */
12271 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12272 
12273 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12274 
12275 	/* set crypto operation source mbuf */
12276 	sym_op->m_src = ut_params->ibuf;
12277 
12278 	/* digest */
12279 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12280 			ut_params->ibuf, reference->digest.len);
12281 
12282 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12283 			"no room to append auth tag");
12284 
12285 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12286 			ut_params->ibuf, reference->ciphertext.len);
12287 
12288 	if (auth_generate)
12289 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
12290 	else
12291 		memcpy(sym_op->auth.digest.data,
12292 				reference->digest.data,
12293 				reference->digest.len);
12294 
12295 	debug_hexdump(stdout, "digest:",
12296 			sym_op->auth.digest.data,
12297 			reference->digest.len);
12298 
12299 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12300 			reference->iv.data, reference->iv.len);
12301 
12302 	sym_op->cipher.data.length = 0;
12303 	sym_op->cipher.data.offset = 0;
12304 
12305 	sym_op->auth.data.length = reference->plaintext.len;
12306 	sym_op->auth.data.offset = 0;
12307 
12308 	return 0;
12309 }
12310 
12311 static int
12312 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
12313 		struct crypto_unittest_params *ut_params,
12314 		const struct test_crypto_vector *reference,
12315 		unsigned int auth_generate)
12316 {
12317 	/* Generate Crypto op data structure */
12318 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12319 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12320 	TEST_ASSERT_NOT_NULL(ut_params->op,
12321 			"Failed to allocate pktmbuf offload");
12322 
12323 	/* Set crypto operation data parameters */
12324 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12325 
12326 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12327 
12328 	/* set crypto operation source mbuf */
12329 	sym_op->m_src = ut_params->ibuf;
12330 
12331 	/* digest */
12332 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12333 			ut_params->ibuf, reference->digest.len);
12334 
12335 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12336 			"no room to append auth tag");
12337 
12338 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12339 			ut_params->ibuf, reference->ciphertext.len);
12340 
12341 	if (auth_generate)
12342 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
12343 	else
12344 		memcpy(sym_op->auth.digest.data,
12345 				reference->digest.data,
12346 				reference->digest.len);
12347 
12348 	debug_hexdump(stdout, "digest:",
12349 			sym_op->auth.digest.data,
12350 			reference->digest.len);
12351 
12352 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12353 			reference->iv.data, reference->iv.len);
12354 
12355 	sym_op->cipher.data.length = reference->cipher_len;
12356 	sym_op->cipher.data.offset = reference->cipher_offset;
12357 
12358 	sym_op->auth.data.length = reference->plaintext.len;
12359 	sym_op->auth.data.offset = reference->auth_offset;
12360 
12361 	return 0;
12362 }
12363 
12364 static int
12365 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12366 		struct crypto_unittest_params *ut_params,
12367 		const struct test_crypto_vector *reference)
12368 {
12369 	return create_auth_operation(ts_params, ut_params, reference, 0);
12370 }
12371 
12372 static int
12373 create_auth_verify_GMAC_operation(
12374 		struct crypto_testsuite_params *ts_params,
12375 		struct crypto_unittest_params *ut_params,
12376 		const struct test_crypto_vector *reference)
12377 {
12378 	return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
12379 }
12380 
12381 static int
12382 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12383 		struct crypto_unittest_params *ut_params,
12384 		const struct test_crypto_vector *reference)
12385 {
12386 	return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
12387 }
12388 
12389 static int
12390 test_authentication_verify_fail_when_data_corruption(
12391 		struct crypto_testsuite_params *ts_params,
12392 		struct crypto_unittest_params *ut_params,
12393 		const struct test_crypto_vector *reference,
12394 		unsigned int data_corrupted)
12395 {
12396 	int retval;
12397 
12398 	uint8_t *plaintext;
12399 	struct rte_cryptodev_info dev_info;
12400 
12401 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12402 	uint64_t feat_flags = dev_info.feature_flags;
12403 
12404 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12405 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12406 		printf("Device doesn't support RAW data-path APIs.\n");
12407 		return TEST_SKIPPED;
12408 	}
12409 
12410 	/* Verify the capabilities */
12411 	struct rte_cryptodev_sym_capability_idx cap_idx;
12412 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12413 	cap_idx.algo.auth = reference->auth_algo;
12414 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12415 			&cap_idx) == NULL)
12416 		return TEST_SKIPPED;
12417 
12418 
12419 	/* Create session */
12420 	retval = create_auth_session(ut_params,
12421 			ts_params->valid_devs[0],
12422 			reference,
12423 			RTE_CRYPTO_AUTH_OP_VERIFY);
12424 	if (retval < 0)
12425 		return retval;
12426 
12427 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12428 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12429 			"Failed to allocate input buffer in mempool");
12430 
12431 	/* clear mbuf payload */
12432 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12433 			rte_pktmbuf_tailroom(ut_params->ibuf));
12434 
12435 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12436 			reference->plaintext.len);
12437 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12438 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12439 
12440 	debug_hexdump(stdout, "plaintext:", plaintext,
12441 		reference->plaintext.len);
12442 
12443 	/* Create operation */
12444 	retval = create_auth_verify_operation(ts_params, ut_params, reference);
12445 
12446 	if (retval < 0)
12447 		return retval;
12448 
12449 	if (data_corrupted)
12450 		data_corruption(plaintext);
12451 	else
12452 		tag_corruption(plaintext, reference->plaintext.len);
12453 
12454 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12455 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12456 			ut_params->op);
12457 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12458 			RTE_CRYPTO_OP_STATUS_SUCCESS,
12459 			"authentication not failed");
12460 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12461 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12462 				ut_params->op, 0, 1, 0, 0);
12463 	else {
12464 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12465 			ut_params->op);
12466 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12467 	}
12468 
12469 	return 0;
12470 }
12471 
12472 static int
12473 test_authentication_verify_GMAC_fail_when_corruption(
12474 		struct crypto_testsuite_params *ts_params,
12475 		struct crypto_unittest_params *ut_params,
12476 		const struct test_crypto_vector *reference,
12477 		unsigned int data_corrupted)
12478 {
12479 	int retval;
12480 	uint8_t *plaintext;
12481 	struct rte_cryptodev_info dev_info;
12482 
12483 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12484 	uint64_t feat_flags = dev_info.feature_flags;
12485 
12486 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12487 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12488 		printf("Device doesn't support RAW data-path APIs.\n");
12489 		return TEST_SKIPPED;
12490 	}
12491 
12492 	/* Verify the capabilities */
12493 	struct rte_cryptodev_sym_capability_idx cap_idx;
12494 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12495 	cap_idx.algo.auth = reference->auth_algo;
12496 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12497 			&cap_idx) == NULL)
12498 		return TEST_SKIPPED;
12499 
12500 	/* Create session */
12501 	retval = create_auth_cipher_session(ut_params,
12502 			ts_params->valid_devs[0],
12503 			reference,
12504 			RTE_CRYPTO_AUTH_OP_VERIFY,
12505 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
12506 	if (retval < 0)
12507 		return retval;
12508 
12509 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12510 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12511 			"Failed to allocate input buffer in mempool");
12512 
12513 	/* clear mbuf payload */
12514 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12515 			rte_pktmbuf_tailroom(ut_params->ibuf));
12516 
12517 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12518 			reference->plaintext.len);
12519 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12520 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12521 
12522 	debug_hexdump(stdout, "plaintext:", plaintext,
12523 		reference->plaintext.len);
12524 
12525 	/* Create operation */
12526 	retval = create_auth_verify_GMAC_operation(ts_params,
12527 			ut_params,
12528 			reference);
12529 
12530 	if (retval < 0)
12531 		return retval;
12532 
12533 	if (data_corrupted)
12534 		data_corruption(plaintext);
12535 	else
12536 		tag_corruption(plaintext, reference->aad.len);
12537 
12538 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12539 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12540 			ut_params->op);
12541 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12542 			RTE_CRYPTO_OP_STATUS_SUCCESS,
12543 			"authentication not failed");
12544 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12545 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12546 				ut_params->op, 0, 1, 0, 0);
12547 	else {
12548 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12549 			ut_params->op);
12550 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12551 	}
12552 
12553 	return 0;
12554 }
12555 
12556 static int
12557 test_authenticated_decryption_fail_when_corruption(
12558 		struct crypto_testsuite_params *ts_params,
12559 		struct crypto_unittest_params *ut_params,
12560 		const struct test_crypto_vector *reference,
12561 		unsigned int data_corrupted)
12562 {
12563 	int retval;
12564 
12565 	uint8_t *ciphertext;
12566 	struct rte_cryptodev_info dev_info;
12567 
12568 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12569 	uint64_t feat_flags = dev_info.feature_flags;
12570 
12571 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12572 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12573 		printf("Device doesn't support RAW data-path APIs.\n");
12574 		return TEST_SKIPPED;
12575 	}
12576 
12577 	/* Verify the capabilities */
12578 	struct rte_cryptodev_sym_capability_idx cap_idx;
12579 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12580 	cap_idx.algo.auth = reference->auth_algo;
12581 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12582 			&cap_idx) == NULL)
12583 		return TEST_SKIPPED;
12584 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12585 	cap_idx.algo.cipher = reference->crypto_algo;
12586 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12587 			&cap_idx) == NULL)
12588 		return TEST_SKIPPED;
12589 
12590 	/* Create session */
12591 	retval = create_auth_cipher_session(ut_params,
12592 			ts_params->valid_devs[0],
12593 			reference,
12594 			RTE_CRYPTO_AUTH_OP_VERIFY,
12595 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
12596 	if (retval < 0)
12597 		return retval;
12598 
12599 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12600 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12601 			"Failed to allocate input buffer in mempool");
12602 
12603 	/* clear mbuf payload */
12604 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12605 			rte_pktmbuf_tailroom(ut_params->ibuf));
12606 
12607 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12608 			reference->ciphertext.len);
12609 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
12610 	memcpy(ciphertext, reference->ciphertext.data,
12611 			reference->ciphertext.len);
12612 
12613 	/* Create operation */
12614 	retval = create_cipher_auth_verify_operation(ts_params,
12615 			ut_params,
12616 			reference);
12617 
12618 	if (retval < 0)
12619 		return retval;
12620 
12621 	if (data_corrupted)
12622 		data_corruption(ciphertext);
12623 	else
12624 		tag_corruption(ciphertext, reference->ciphertext.len);
12625 
12626 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
12627 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12628 			ut_params->op);
12629 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
12630 			RTE_CRYPTO_OP_STATUS_SUCCESS,
12631 			"authentication not failed");
12632 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12633 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12634 				ut_params->op, 1, 1, 0, 0);
12635 	else {
12636 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12637 			ut_params->op);
12638 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
12639 	}
12640 
12641 	return 0;
12642 }
12643 
12644 static int
12645 test_authenticated_encrypt_with_esn(
12646 		struct crypto_testsuite_params *ts_params,
12647 		struct crypto_unittest_params *ut_params,
12648 		const struct test_crypto_vector *reference)
12649 {
12650 	int retval;
12651 
12652 	uint8_t *authciphertext, *plaintext, *auth_tag;
12653 	uint16_t plaintext_pad_len;
12654 	uint8_t cipher_key[reference->cipher_key.len + 1];
12655 	uint8_t auth_key[reference->auth_key.len + 1];
12656 	struct rte_cryptodev_info dev_info;
12657 
12658 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12659 	uint64_t feat_flags = dev_info.feature_flags;
12660 
12661 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12662 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12663 		printf("Device doesn't support RAW data-path APIs.\n");
12664 		return TEST_SKIPPED;
12665 	}
12666 
12667 	/* Verify the capabilities */
12668 	struct rte_cryptodev_sym_capability_idx cap_idx;
12669 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12670 	cap_idx.algo.auth = reference->auth_algo;
12671 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12672 			&cap_idx) == NULL)
12673 		return TEST_SKIPPED;
12674 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12675 	cap_idx.algo.cipher = reference->crypto_algo;
12676 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12677 			&cap_idx) == NULL)
12678 		return TEST_SKIPPED;
12679 
12680 	/* Create session */
12681 	memcpy(cipher_key, reference->cipher_key.data,
12682 			reference->cipher_key.len);
12683 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12684 
12685 	/* Setup Cipher Parameters */
12686 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12687 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12688 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
12689 	ut_params->cipher_xform.cipher.key.data = cipher_key;
12690 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12691 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12692 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12693 
12694 	ut_params->cipher_xform.next = &ut_params->auth_xform;
12695 
12696 	/* Setup Authentication Parameters */
12697 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12698 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
12699 	ut_params->auth_xform.auth.algo = reference->auth_algo;
12700 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12701 	ut_params->auth_xform.auth.key.data = auth_key;
12702 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
12703 	ut_params->auth_xform.next = NULL;
12704 
12705 	/* Create Crypto session*/
12706 	ut_params->sess = rte_cryptodev_sym_session_create(
12707 			ts_params->session_mpool);
12708 
12709 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12710 				ut_params->sess,
12711 				&ut_params->cipher_xform,
12712 				ts_params->session_priv_mpool);
12713 
12714 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12715 
12716 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12717 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12718 			"Failed to allocate input buffer in mempool");
12719 
12720 	/* clear mbuf payload */
12721 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12722 			rte_pktmbuf_tailroom(ut_params->ibuf));
12723 
12724 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12725 			reference->plaintext.len);
12726 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12727 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
12728 
12729 	/* Create operation */
12730 	retval = create_cipher_auth_operation(ts_params,
12731 			ut_params,
12732 			reference, 0);
12733 
12734 	if (retval < 0)
12735 		return retval;
12736 
12737 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12738 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12739 			ut_params->op);
12740 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12741 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12742 				ut_params->op, 1, 1, 0, 0);
12743 	else
12744 		ut_params->op = process_crypto_request(
12745 			ts_params->valid_devs[0], ut_params->op);
12746 
12747 	TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
12748 
12749 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12750 			"crypto op processing failed");
12751 
12752 	plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
12753 
12754 	authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
12755 			ut_params->op->sym->auth.data.offset);
12756 	auth_tag = authciphertext + plaintext_pad_len;
12757 	debug_hexdump(stdout, "ciphertext:", authciphertext,
12758 			reference->ciphertext.len);
12759 	debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
12760 
12761 	/* Validate obuf */
12762 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12763 			authciphertext,
12764 			reference->ciphertext.data,
12765 			reference->ciphertext.len,
12766 			"Ciphertext data not as expected");
12767 
12768 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12769 			auth_tag,
12770 			reference->digest.data,
12771 			reference->digest.len,
12772 			"Generated digest not as expected");
12773 
12774 	return TEST_SUCCESS;
12775 
12776 }
12777 
12778 static int
12779 test_authenticated_decrypt_with_esn(
12780 		struct crypto_testsuite_params *ts_params,
12781 		struct crypto_unittest_params *ut_params,
12782 		const struct test_crypto_vector *reference)
12783 {
12784 	int retval;
12785 
12786 	uint8_t *ciphertext;
12787 	uint8_t cipher_key[reference->cipher_key.len + 1];
12788 	uint8_t auth_key[reference->auth_key.len + 1];
12789 	struct rte_cryptodev_info dev_info;
12790 
12791 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12792 	uint64_t feat_flags = dev_info.feature_flags;
12793 
12794 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12795 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12796 		printf("Device doesn't support RAW data-path APIs.\n");
12797 		return TEST_SKIPPED;
12798 	}
12799 
12800 	/* Verify the capabilities */
12801 	struct rte_cryptodev_sym_capability_idx cap_idx;
12802 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12803 	cap_idx.algo.auth = reference->auth_algo;
12804 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12805 			&cap_idx) == NULL)
12806 		return TEST_SKIPPED;
12807 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12808 	cap_idx.algo.cipher = reference->crypto_algo;
12809 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12810 			&cap_idx) == NULL)
12811 		return TEST_SKIPPED;
12812 
12813 	/* Create session */
12814 	memcpy(cipher_key, reference->cipher_key.data,
12815 			reference->cipher_key.len);
12816 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12817 
12818 	/* Setup Authentication Parameters */
12819 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12820 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
12821 	ut_params->auth_xform.auth.algo = reference->auth_algo;
12822 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12823 	ut_params->auth_xform.auth.key.data = auth_key;
12824 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
12825 	ut_params->auth_xform.next = &ut_params->cipher_xform;
12826 
12827 	/* Setup Cipher Parameters */
12828 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12829 	ut_params->cipher_xform.next = NULL;
12830 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12831 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
12832 	ut_params->cipher_xform.cipher.key.data = cipher_key;
12833 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12834 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12835 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12836 
12837 	/* Create Crypto session*/
12838 	ut_params->sess = rte_cryptodev_sym_session_create(
12839 			ts_params->session_mpool);
12840 
12841 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12842 				ut_params->sess,
12843 				&ut_params->auth_xform,
12844 				ts_params->session_priv_mpool);
12845 
12846 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12847 
12848 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12849 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12850 			"Failed to allocate input buffer in mempool");
12851 
12852 	/* clear mbuf payload */
12853 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12854 			rte_pktmbuf_tailroom(ut_params->ibuf));
12855 
12856 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12857 			reference->ciphertext.len);
12858 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
12859 	memcpy(ciphertext, reference->ciphertext.data,
12860 			reference->ciphertext.len);
12861 
12862 	/* Create operation */
12863 	retval = create_cipher_auth_verify_operation(ts_params,
12864 			ut_params,
12865 			reference);
12866 
12867 	if (retval < 0)
12868 		return retval;
12869 
12870 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12871 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12872 			ut_params->op);
12873 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12874 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12875 				ut_params->op, 1, 1, 0, 0);
12876 	else
12877 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
12878 			ut_params->op);
12879 
12880 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
12881 	TEST_ASSERT_EQUAL(ut_params->op->status,
12882 			RTE_CRYPTO_OP_STATUS_SUCCESS,
12883 			"crypto op processing passed");
12884 
12885 	ut_params->obuf = ut_params->op->sym->m_src;
12886 	TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
12887 
12888 	return 0;
12889 }
12890 
12891 static int
12892 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
12893 		const struct aead_test_data *tdata,
12894 		void *digest_mem, uint64_t digest_phys)
12895 {
12896 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12897 	struct crypto_unittest_params *ut_params = &unittest_params;
12898 
12899 	const unsigned int auth_tag_len = tdata->auth_tag.len;
12900 	const unsigned int iv_len = tdata->iv.len;
12901 	unsigned int aad_len = tdata->aad.len;
12902 	unsigned int aad_len_pad = 0;
12903 
12904 	/* Generate Crypto op data structure */
12905 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12906 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12907 	TEST_ASSERT_NOT_NULL(ut_params->op,
12908 		"Failed to allocate symmetric crypto operation struct");
12909 
12910 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12911 
12912 	sym_op->aead.digest.data = digest_mem;
12913 
12914 	TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
12915 			"no room to append digest");
12916 
12917 	sym_op->aead.digest.phys_addr = digest_phys;
12918 
12919 	if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
12920 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
12921 				auth_tag_len);
12922 		debug_hexdump(stdout, "digest:",
12923 				sym_op->aead.digest.data,
12924 				auth_tag_len);
12925 	}
12926 
12927 	/* Append aad data */
12928 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
12929 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12930 				uint8_t *, IV_OFFSET);
12931 
12932 		/* Copy IV 1 byte after the IV pointer, according to the API */
12933 		rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
12934 
12935 		aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
12936 
12937 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
12938 				ut_params->ibuf, aad_len);
12939 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
12940 				"no room to prepend aad");
12941 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
12942 				ut_params->ibuf);
12943 
12944 		memset(sym_op->aead.aad.data, 0, aad_len);
12945 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
12946 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
12947 
12948 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
12949 		debug_hexdump(stdout, "aad:",
12950 				sym_op->aead.aad.data, aad_len);
12951 	} else {
12952 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12953 				uint8_t *, IV_OFFSET);
12954 
12955 		rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
12956 
12957 		aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
12958 
12959 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
12960 				ut_params->ibuf, aad_len_pad);
12961 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
12962 				"no room to prepend aad");
12963 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
12964 				ut_params->ibuf);
12965 
12966 		memset(sym_op->aead.aad.data, 0, aad_len);
12967 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
12968 
12969 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
12970 		debug_hexdump(stdout, "aad:",
12971 				sym_op->aead.aad.data, aad_len);
12972 	}
12973 
12974 	sym_op->aead.data.length = tdata->plaintext.len;
12975 	sym_op->aead.data.offset = aad_len_pad;
12976 
12977 	return 0;
12978 }
12979 
12980 #define SGL_MAX_NO	16
12981 
12982 static int
12983 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
12984 		const int oop, uint32_t fragsz, uint32_t fragsz_oop)
12985 {
12986 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12987 	struct crypto_unittest_params *ut_params = &unittest_params;
12988 	struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
12989 	int retval;
12990 	int to_trn = 0;
12991 	int to_trn_tbl[SGL_MAX_NO];
12992 	int segs = 1;
12993 	unsigned int trn_data = 0;
12994 	uint8_t *plaintext, *ciphertext, *auth_tag;
12995 	struct rte_cryptodev_info dev_info;
12996 
12997 	/* Verify the capabilities */
12998 	struct rte_cryptodev_sym_capability_idx cap_idx;
12999 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
13000 	cap_idx.algo.aead = tdata->algo;
13001 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13002 			&cap_idx) == NULL)
13003 		return TEST_SKIPPED;
13004 
13005 	/* OOP not supported with CPU crypto */
13006 	if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13007 		return TEST_SKIPPED;
13008 
13009 	/* Detailed check for the particular SGL support flag */
13010 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13011 	if (!oop) {
13012 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
13013 		if (sgl_in && (!(dev_info.feature_flags &
13014 				RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
13015 			return TEST_SKIPPED;
13016 
13017 		uint64_t feat_flags = dev_info.feature_flags;
13018 
13019 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13020 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13021 			printf("Device doesn't support RAW data-path APIs.\n");
13022 			return TEST_SKIPPED;
13023 		}
13024 	} else {
13025 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
13026 		unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
13027 				tdata->plaintext.len;
13028 		/* Raw data path API does not support OOP */
13029 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13030 			return TEST_SKIPPED;
13031 		if (sgl_in && !sgl_out) {
13032 			if (!(dev_info.feature_flags &
13033 					RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
13034 				return TEST_SKIPPED;
13035 		} else if (!sgl_in && sgl_out) {
13036 			if (!(dev_info.feature_flags &
13037 					RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
13038 				return TEST_SKIPPED;
13039 		} else if (sgl_in && sgl_out) {
13040 			if (!(dev_info.feature_flags &
13041 					RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
13042 				return TEST_SKIPPED;
13043 		}
13044 	}
13045 
13046 	if (fragsz > tdata->plaintext.len)
13047 		fragsz = tdata->plaintext.len;
13048 
13049 	uint16_t plaintext_len = fragsz;
13050 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
13051 
13052 	if (fragsz_oop > tdata->plaintext.len)
13053 		frag_size_oop = tdata->plaintext.len;
13054 
13055 	int ecx = 0;
13056 	void *digest_mem = NULL;
13057 
13058 	uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
13059 
13060 	if (tdata->plaintext.len % fragsz != 0) {
13061 		if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
13062 			return 1;
13063 	}	else {
13064 		if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
13065 			return 1;
13066 	}
13067 
13068 	/*
13069 	 * For out-op-place we need to alloc another mbuf
13070 	 */
13071 	if (oop) {
13072 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13073 		rte_pktmbuf_append(ut_params->obuf,
13074 				frag_size_oop + prepend_len);
13075 		buf_oop = ut_params->obuf;
13076 	}
13077 
13078 	/* Create AEAD session */
13079 	retval = create_aead_session(ts_params->valid_devs[0],
13080 			tdata->algo,
13081 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
13082 			tdata->key.data, tdata->key.len,
13083 			tdata->aad.len, tdata->auth_tag.len,
13084 			tdata->iv.len);
13085 	if (retval < 0)
13086 		return retval;
13087 
13088 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13089 
13090 	/* clear mbuf payload */
13091 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13092 			rte_pktmbuf_tailroom(ut_params->ibuf));
13093 
13094 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13095 			plaintext_len);
13096 
13097 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
13098 
13099 	trn_data += plaintext_len;
13100 
13101 	buf = ut_params->ibuf;
13102 
13103 	/*
13104 	 * Loop until no more fragments
13105 	 */
13106 
13107 	while (trn_data < tdata->plaintext.len) {
13108 		++segs;
13109 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
13110 				(tdata->plaintext.len - trn_data) : fragsz;
13111 
13112 		to_trn_tbl[ecx++] = to_trn;
13113 
13114 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13115 		buf = buf->next;
13116 
13117 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
13118 				rte_pktmbuf_tailroom(buf));
13119 
13120 		/* OOP */
13121 		if (oop && !fragsz_oop) {
13122 			buf_last_oop = buf_oop->next =
13123 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
13124 			buf_oop = buf_oop->next;
13125 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13126 					0, rte_pktmbuf_tailroom(buf_oop));
13127 			rte_pktmbuf_append(buf_oop, to_trn);
13128 		}
13129 
13130 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
13131 				to_trn);
13132 
13133 		memcpy(plaintext, tdata->plaintext.data + trn_data,
13134 				to_trn);
13135 		trn_data += to_trn;
13136 		if (trn_data  == tdata->plaintext.len) {
13137 			if (oop) {
13138 				if (!fragsz_oop)
13139 					digest_mem = rte_pktmbuf_append(buf_oop,
13140 						tdata->auth_tag.len);
13141 			} else
13142 				digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
13143 					tdata->auth_tag.len);
13144 		}
13145 	}
13146 
13147 	uint64_t digest_phys = 0;
13148 
13149 	ut_params->ibuf->nb_segs = segs;
13150 
13151 	segs = 1;
13152 	if (fragsz_oop && oop) {
13153 		to_trn = 0;
13154 		ecx = 0;
13155 
13156 		if (frag_size_oop == tdata->plaintext.len) {
13157 			digest_mem = rte_pktmbuf_append(ut_params->obuf,
13158 				tdata->auth_tag.len);
13159 
13160 			digest_phys = rte_pktmbuf_iova_offset(
13161 					ut_params->obuf,
13162 					tdata->plaintext.len + prepend_len);
13163 		}
13164 
13165 		trn_data = frag_size_oop;
13166 		while (trn_data < tdata->plaintext.len) {
13167 			++segs;
13168 			to_trn =
13169 				(tdata->plaintext.len - trn_data <
13170 						frag_size_oop) ?
13171 				(tdata->plaintext.len - trn_data) :
13172 						frag_size_oop;
13173 
13174 			to_trn_tbl[ecx++] = to_trn;
13175 
13176 			buf_last_oop = buf_oop->next =
13177 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
13178 			buf_oop = buf_oop->next;
13179 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13180 					0, rte_pktmbuf_tailroom(buf_oop));
13181 			rte_pktmbuf_append(buf_oop, to_trn);
13182 
13183 			trn_data += to_trn;
13184 
13185 			if (trn_data  == tdata->plaintext.len) {
13186 				digest_mem = rte_pktmbuf_append(buf_oop,
13187 					tdata->auth_tag.len);
13188 			}
13189 		}
13190 
13191 		ut_params->obuf->nb_segs = segs;
13192 	}
13193 
13194 	/*
13195 	 * Place digest at the end of the last buffer
13196 	 */
13197 	if (!digest_phys)
13198 		digest_phys = rte_pktmbuf_iova(buf) + to_trn;
13199 	if (oop && buf_last_oop)
13200 		digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
13201 
13202 	if (!digest_mem && !oop) {
13203 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13204 				+ tdata->auth_tag.len);
13205 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
13206 				tdata->plaintext.len);
13207 	}
13208 
13209 	/* Create AEAD operation */
13210 	retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
13211 			tdata, digest_mem, digest_phys);
13212 
13213 	if (retval < 0)
13214 		return retval;
13215 
13216 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13217 
13218 	ut_params->op->sym->m_src = ut_params->ibuf;
13219 	if (oop)
13220 		ut_params->op->sym->m_dst = ut_params->obuf;
13221 
13222 	/* Process crypto operation */
13223 	if (oop == IN_PLACE &&
13224 			gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13225 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
13226 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13227 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13228 				ut_params->op, 0, 0, 0, 0);
13229 	else
13230 		TEST_ASSERT_NOT_NULL(
13231 			process_crypto_request(ts_params->valid_devs[0],
13232 			ut_params->op), "failed to process sym crypto op");
13233 
13234 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13235 			"crypto op processing failed");
13236 
13237 
13238 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
13239 			uint8_t *, prepend_len);
13240 	if (oop) {
13241 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
13242 				uint8_t *, prepend_len);
13243 	}
13244 
13245 	if (fragsz_oop)
13246 		fragsz = fragsz_oop;
13247 
13248 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13249 			ciphertext,
13250 			tdata->ciphertext.data,
13251 			fragsz,
13252 			"Ciphertext data not as expected");
13253 
13254 	buf = ut_params->op->sym->m_src->next;
13255 	if (oop)
13256 		buf = ut_params->op->sym->m_dst->next;
13257 
13258 	unsigned int off = fragsz;
13259 
13260 	ecx = 0;
13261 	while (buf) {
13262 		ciphertext = rte_pktmbuf_mtod(buf,
13263 				uint8_t *);
13264 
13265 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
13266 				ciphertext,
13267 				tdata->ciphertext.data + off,
13268 				to_trn_tbl[ecx],
13269 				"Ciphertext data not as expected");
13270 
13271 		off += to_trn_tbl[ecx++];
13272 		buf = buf->next;
13273 	}
13274 
13275 	auth_tag = digest_mem;
13276 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13277 			auth_tag,
13278 			tdata->auth_tag.data,
13279 			tdata->auth_tag.len,
13280 			"Generated auth tag not as expected");
13281 
13282 	return 0;
13283 }
13284 
13285 static int
13286 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
13287 {
13288 	return test_authenticated_encryption_SGL(
13289 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
13290 }
13291 
13292 static int
13293 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
13294 {
13295 	return test_authenticated_encryption_SGL(
13296 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
13297 }
13298 
13299 static int
13300 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
13301 {
13302 	return test_authenticated_encryption_SGL(
13303 			&gcm_test_case_8, OUT_OF_PLACE, 400,
13304 			gcm_test_case_8.plaintext.len);
13305 }
13306 
13307 static int
13308 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
13309 {
13310 	/* This test is not for OPENSSL PMD */
13311 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
13312 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
13313 		return TEST_SKIPPED;
13314 
13315 	return test_authenticated_encryption_SGL(
13316 			&gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
13317 }
13318 
13319 static int
13320 test_authentication_verify_fail_when_data_corrupted(
13321 		struct crypto_testsuite_params *ts_params,
13322 		struct crypto_unittest_params *ut_params,
13323 		const struct test_crypto_vector *reference)
13324 {
13325 	return test_authentication_verify_fail_when_data_corruption(
13326 			ts_params, ut_params, reference, 1);
13327 }
13328 
13329 static int
13330 test_authentication_verify_fail_when_tag_corrupted(
13331 		struct crypto_testsuite_params *ts_params,
13332 		struct crypto_unittest_params *ut_params,
13333 		const struct test_crypto_vector *reference)
13334 {
13335 	return test_authentication_verify_fail_when_data_corruption(
13336 			ts_params, ut_params, reference, 0);
13337 }
13338 
13339 static int
13340 test_authentication_verify_GMAC_fail_when_data_corrupted(
13341 		struct crypto_testsuite_params *ts_params,
13342 		struct crypto_unittest_params *ut_params,
13343 		const struct test_crypto_vector *reference)
13344 {
13345 	return test_authentication_verify_GMAC_fail_when_corruption(
13346 			ts_params, ut_params, reference, 1);
13347 }
13348 
13349 static int
13350 test_authentication_verify_GMAC_fail_when_tag_corrupted(
13351 		struct crypto_testsuite_params *ts_params,
13352 		struct crypto_unittest_params *ut_params,
13353 		const struct test_crypto_vector *reference)
13354 {
13355 	return test_authentication_verify_GMAC_fail_when_corruption(
13356 			ts_params, ut_params, reference, 0);
13357 }
13358 
13359 static int
13360 test_authenticated_decryption_fail_when_data_corrupted(
13361 		struct crypto_testsuite_params *ts_params,
13362 		struct crypto_unittest_params *ut_params,
13363 		const struct test_crypto_vector *reference)
13364 {
13365 	return test_authenticated_decryption_fail_when_corruption(
13366 			ts_params, ut_params, reference, 1);
13367 }
13368 
13369 static int
13370 test_authenticated_decryption_fail_when_tag_corrupted(
13371 		struct crypto_testsuite_params *ts_params,
13372 		struct crypto_unittest_params *ut_params,
13373 		const struct test_crypto_vector *reference)
13374 {
13375 	return test_authenticated_decryption_fail_when_corruption(
13376 			ts_params, ut_params, reference, 0);
13377 }
13378 
13379 static int
13380 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
13381 {
13382 	return test_authentication_verify_fail_when_data_corrupted(
13383 			&testsuite_params, &unittest_params,
13384 			&hmac_sha1_test_crypto_vector);
13385 }
13386 
13387 static int
13388 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
13389 {
13390 	return test_authentication_verify_fail_when_tag_corrupted(
13391 			&testsuite_params, &unittest_params,
13392 			&hmac_sha1_test_crypto_vector);
13393 }
13394 
13395 static int
13396 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
13397 {
13398 	return test_authentication_verify_GMAC_fail_when_data_corrupted(
13399 			&testsuite_params, &unittest_params,
13400 			&aes128_gmac_test_vector);
13401 }
13402 
13403 static int
13404 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
13405 {
13406 	return test_authentication_verify_GMAC_fail_when_tag_corrupted(
13407 			&testsuite_params, &unittest_params,
13408 			&aes128_gmac_test_vector);
13409 }
13410 
13411 static int
13412 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
13413 {
13414 	return test_authenticated_decryption_fail_when_data_corrupted(
13415 			&testsuite_params,
13416 			&unittest_params,
13417 			&aes128cbc_hmac_sha1_test_vector);
13418 }
13419 
13420 static int
13421 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
13422 {
13423 	return test_authenticated_decryption_fail_when_tag_corrupted(
13424 			&testsuite_params,
13425 			&unittest_params,
13426 			&aes128cbc_hmac_sha1_test_vector);
13427 }
13428 
13429 static int
13430 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13431 {
13432 	return test_authenticated_encrypt_with_esn(
13433 			&testsuite_params,
13434 			&unittest_params,
13435 			&aes128cbc_hmac_sha1_aad_test_vector);
13436 }
13437 
13438 static int
13439 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
13440 {
13441 	return test_authenticated_decrypt_with_esn(
13442 			&testsuite_params,
13443 			&unittest_params,
13444 			&aes128cbc_hmac_sha1_aad_test_vector);
13445 }
13446 
13447 static int
13448 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
13449 {
13450 	return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
13451 }
13452 
13453 static int
13454 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
13455 {
13456 	return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
13457 }
13458 
13459 #ifdef RTE_CRYPTO_SCHEDULER
13460 
13461 /* global AESNI worker IDs for the scheduler test */
13462 uint8_t aesni_ids[2];
13463 
13464 static int
13465 scheduler_testsuite_setup(void)
13466 {
13467 	uint32_t i = 0;
13468 	int32_t nb_devs, ret;
13469 	char vdev_args[VDEV_ARGS_SIZE] = {""};
13470 	char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
13471 		"ordering=enable,name=cryptodev_test_scheduler,corelist="};
13472 	uint16_t worker_core_count = 0;
13473 	uint16_t socket_id = 0;
13474 
13475 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
13476 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
13477 
13478 		/* Identify the Worker Cores
13479 		 * Use 2 worker cores for the device args
13480 		 */
13481 		RTE_LCORE_FOREACH_WORKER(i) {
13482 			if (worker_core_count > 1)
13483 				break;
13484 			snprintf(vdev_args, sizeof(vdev_args),
13485 					"%s%d", temp_str, i);
13486 			strcpy(temp_str, vdev_args);
13487 			strlcat(temp_str, ";", sizeof(temp_str));
13488 			worker_core_count++;
13489 			socket_id = rte_lcore_to_socket_id(i);
13490 		}
13491 		if (worker_core_count != 2) {
13492 			RTE_LOG(ERR, USER1,
13493 				"Cryptodev scheduler test require at least "
13494 				"two worker cores to run. "
13495 				"Please use the correct coremask.\n");
13496 			return TEST_FAILED;
13497 		}
13498 		strcpy(temp_str, vdev_args);
13499 		snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
13500 				temp_str, socket_id);
13501 		RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
13502 		nb_devs = rte_cryptodev_device_count_by_driver(
13503 				rte_cryptodev_driver_id_get(
13504 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
13505 		if (nb_devs < 1) {
13506 			ret = rte_vdev_init(
13507 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
13508 					vdev_args);
13509 			TEST_ASSERT(ret == 0,
13510 				"Failed to create instance %u of pmd : %s",
13511 				i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
13512 		}
13513 	}
13514 	return testsuite_setup();
13515 }
13516 
13517 static int
13518 test_scheduler_attach_worker_op(void)
13519 {
13520 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13521 	uint8_t sched_id = ts_params->valid_devs[0];
13522 	uint32_t i, nb_devs_attached = 0;
13523 	int ret;
13524 	char vdev_name[32];
13525 	unsigned int count = rte_cryptodev_count();
13526 
13527 	/* create 2 AESNI_MB vdevs on top of existing devices */
13528 	for (i = count; i < count + 2; i++) {
13529 		snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
13530 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
13531 				i);
13532 		ret = rte_vdev_init(vdev_name, NULL);
13533 
13534 		TEST_ASSERT(ret == 0,
13535 			"Failed to create instance %u of"
13536 			" pmd : %s",
13537 			i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13538 
13539 		if (ret < 0) {
13540 			RTE_LOG(ERR, USER1,
13541 				"Failed to create 2 AESNI MB PMDs.\n");
13542 			return TEST_SKIPPED;
13543 		}
13544 	}
13545 
13546 	/* attach 2 AESNI_MB cdevs */
13547 	for (i = count; i < count + 2; i++) {
13548 		struct rte_cryptodev_info info;
13549 		unsigned int session_size;
13550 
13551 		rte_cryptodev_info_get(i, &info);
13552 		if (info.driver_id != rte_cryptodev_driver_id_get(
13553 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
13554 			continue;
13555 
13556 		session_size = rte_cryptodev_sym_get_private_session_size(i);
13557 		/*
13558 		 * Create the session mempool again, since now there are new devices
13559 		 * to use the mempool.
13560 		 */
13561 		if (ts_params->session_mpool) {
13562 			rte_mempool_free(ts_params->session_mpool);
13563 			ts_params->session_mpool = NULL;
13564 		}
13565 		if (ts_params->session_priv_mpool) {
13566 			rte_mempool_free(ts_params->session_priv_mpool);
13567 			ts_params->session_priv_mpool = NULL;
13568 		}
13569 
13570 		if (info.sym.max_nb_sessions != 0 &&
13571 				info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
13572 			RTE_LOG(ERR, USER1,
13573 					"Device does not support "
13574 					"at least %u sessions\n",
13575 					MAX_NB_SESSIONS);
13576 			return TEST_FAILED;
13577 		}
13578 		/*
13579 		 * Create mempool with maximum number of sessions,
13580 		 * to include the session headers
13581 		 */
13582 		if (ts_params->session_mpool == NULL) {
13583 			ts_params->session_mpool =
13584 				rte_cryptodev_sym_session_pool_create(
13585 						"test_sess_mp",
13586 						MAX_NB_SESSIONS, 0, 0, 0,
13587 						SOCKET_ID_ANY);
13588 			TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
13589 					"session mempool allocation failed");
13590 		}
13591 
13592 		/*
13593 		 * Create mempool with maximum number of sessions,
13594 		 * to include device specific session private data
13595 		 */
13596 		if (ts_params->session_priv_mpool == NULL) {
13597 			ts_params->session_priv_mpool = rte_mempool_create(
13598 					"test_sess_mp_priv",
13599 					MAX_NB_SESSIONS,
13600 					session_size,
13601 					0, 0, NULL, NULL, NULL,
13602 					NULL, SOCKET_ID_ANY,
13603 					0);
13604 
13605 			TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
13606 					"session mempool allocation failed");
13607 		}
13608 
13609 		ts_params->qp_conf.mp_session = ts_params->session_mpool;
13610 		ts_params->qp_conf.mp_session_private =
13611 				ts_params->session_priv_mpool;
13612 
13613 		ret = rte_cryptodev_scheduler_worker_attach(sched_id,
13614 				(uint8_t)i);
13615 
13616 		TEST_ASSERT(ret == 0,
13617 			"Failed to attach device %u of pmd : %s", i,
13618 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
13619 
13620 		aesni_ids[nb_devs_attached] = (uint8_t)i;
13621 
13622 		nb_devs_attached++;
13623 	}
13624 
13625 	return 0;
13626 }
13627 
13628 static int
13629 test_scheduler_detach_worker_op(void)
13630 {
13631 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13632 	uint8_t sched_id = ts_params->valid_devs[0];
13633 	uint32_t i;
13634 	int ret;
13635 
13636 	for (i = 0; i < 2; i++) {
13637 		ret = rte_cryptodev_scheduler_worker_detach(sched_id,
13638 				aesni_ids[i]);
13639 		TEST_ASSERT(ret == 0,
13640 			"Failed to detach device %u", aesni_ids[i]);
13641 	}
13642 
13643 	return 0;
13644 }
13645 
13646 static int
13647 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
13648 {
13649 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13650 	uint8_t sched_id = ts_params->valid_devs[0];
13651 	/* set mode */
13652 	return rte_cryptodev_scheduler_mode_set(sched_id,
13653 		scheduler_mode);
13654 }
13655 
13656 static int
13657 test_scheduler_mode_roundrobin_op(void)
13658 {
13659 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
13660 			0, "Failed to set roundrobin mode");
13661 	return 0;
13662 
13663 }
13664 
13665 static int
13666 test_scheduler_mode_multicore_op(void)
13667 {
13668 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
13669 			0, "Failed to set multicore mode");
13670 
13671 	return 0;
13672 }
13673 
13674 static int
13675 test_scheduler_mode_failover_op(void)
13676 {
13677 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
13678 			0, "Failed to set failover mode");
13679 
13680 	return 0;
13681 }
13682 
13683 static int
13684 test_scheduler_mode_pkt_size_distr_op(void)
13685 {
13686 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
13687 			0, "Failed to set pktsize mode");
13688 
13689 	return 0;
13690 }
13691 
13692 static int
13693 scheduler_multicore_testsuite_setup(void)
13694 {
13695 	if (test_scheduler_attach_worker_op() < 0)
13696 		return TEST_SKIPPED;
13697 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0)
13698 		return TEST_SKIPPED;
13699 	return 0;
13700 }
13701 
13702 static int
13703 scheduler_roundrobin_testsuite_setup(void)
13704 {
13705 	if (test_scheduler_attach_worker_op() < 0)
13706 		return TEST_SKIPPED;
13707 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0)
13708 		return TEST_SKIPPED;
13709 	return 0;
13710 }
13711 
13712 static int
13713 scheduler_failover_testsuite_setup(void)
13714 {
13715 	if (test_scheduler_attach_worker_op() < 0)
13716 		return TEST_SKIPPED;
13717 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0)
13718 		return TEST_SKIPPED;
13719 	return 0;
13720 }
13721 
13722 static int
13723 scheduler_pkt_size_distr_testsuite_setup(void)
13724 {
13725 	if (test_scheduler_attach_worker_op() < 0)
13726 		return TEST_SKIPPED;
13727 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0)
13728 		return TEST_SKIPPED;
13729 	return 0;
13730 }
13731 
13732 static void
13733 scheduler_mode_testsuite_teardown(void)
13734 {
13735 	test_scheduler_detach_worker_op();
13736 }
13737 
13738 #endif /* RTE_CRYPTO_SCHEDULER */
13739 
13740 static struct unit_test_suite end_testsuite = {
13741 	.suite_name = NULL,
13742 	.setup = NULL,
13743 	.teardown = NULL,
13744 	.unit_test_suites = NULL
13745 };
13746 
13747 #ifdef RTE_LIB_SECURITY
13748 static struct unit_test_suite pdcp_proto_testsuite  = {
13749 	.suite_name = "PDCP Proto Unit Test Suite",
13750 	.setup = pdcp_proto_testsuite_setup,
13751 	.unit_test_cases = {
13752 		TEST_CASE_ST(ut_setup_security, ut_teardown,
13753 			test_PDCP_PROTO_all),
13754 		TEST_CASES_END() /**< NULL terminate unit test array */
13755 	}
13756 };
13757 
13758 static struct unit_test_suite docsis_proto_testsuite  = {
13759 	.suite_name = "Docsis Proto Unit Test Suite",
13760 	.setup = docsis_proto_testsuite_setup,
13761 	.unit_test_cases = {
13762 		TEST_CASE_ST(ut_setup_security, ut_teardown,
13763 			test_DOCSIS_PROTO_all),
13764 		TEST_CASES_END() /**< NULL terminate unit test array */
13765 	}
13766 };
13767 #endif
13768 
13769 static struct unit_test_suite cryptodev_gen_testsuite  = {
13770 	.suite_name = "Crypto General Unit Test Suite",
13771 	.setup = crypto_gen_testsuite_setup,
13772 	.unit_test_cases = {
13773 		TEST_CASE_ST(ut_setup, ut_teardown,
13774 				test_device_configure_invalid_dev_id),
13775 		TEST_CASE_ST(ut_setup, ut_teardown,
13776 				test_queue_pair_descriptor_setup),
13777 		TEST_CASE_ST(ut_setup, ut_teardown,
13778 				test_device_configure_invalid_queue_pair_ids),
13779 		TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
13780 		TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup),
13781 		TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup),
13782 		TEST_CASES_END() /**< NULL terminate unit test array */
13783 	}
13784 };
13785 
13786 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = {
13787 	.suite_name = "Negative HMAC SHA1 Unit Test Suite",
13788 	.setup = negative_hmac_sha1_testsuite_setup,
13789 	.unit_test_cases = {
13790 		/** Negative tests */
13791 		TEST_CASE_ST(ut_setup, ut_teardown,
13792 			authentication_verify_HMAC_SHA1_fail_data_corrupt),
13793 		TEST_CASE_ST(ut_setup, ut_teardown,
13794 			authentication_verify_HMAC_SHA1_fail_tag_corrupt),
13795 		TEST_CASE_ST(ut_setup, ut_teardown,
13796 			auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
13797 		TEST_CASE_ST(ut_setup, ut_teardown,
13798 			auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
13799 
13800 		TEST_CASES_END() /**< NULL terminate unit test array */
13801 	}
13802 };
13803 
13804 static struct unit_test_suite cryptodev_multi_session_testsuite = {
13805 	.suite_name = "Multi Session Unit Test Suite",
13806 	.setup = multi_session_testsuite_setup,
13807 	.unit_test_cases = {
13808 		TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
13809 		TEST_CASE_ST(ut_setup, ut_teardown,
13810 				test_multi_session_random_usage),
13811 
13812 		TEST_CASES_END() /**< NULL terminate unit test array */
13813 	}
13814 };
13815 
13816 static struct unit_test_suite cryptodev_null_testsuite  = {
13817 	.suite_name = "NULL Test Suite",
13818 	.setup = null_testsuite_setup,
13819 	.unit_test_cases = {
13820 		TEST_CASE_ST(ut_setup, ut_teardown,
13821 			test_null_invalid_operation),
13822 		TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
13823 		TEST_CASES_END()
13824 	}
13825 };
13826 
13827 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite  = {
13828 	.suite_name = "AES CCM Authenticated Test Suite",
13829 	.setup = aes_ccm_auth_testsuite_setup,
13830 	.unit_test_cases = {
13831 		/** AES CCM Authenticated Encryption 128 bits key*/
13832 		TEST_CASE_ST(ut_setup, ut_teardown,
13833 			test_AES_CCM_authenticated_encryption_test_case_128_1),
13834 		TEST_CASE_ST(ut_setup, ut_teardown,
13835 			test_AES_CCM_authenticated_encryption_test_case_128_2),
13836 		TEST_CASE_ST(ut_setup, ut_teardown,
13837 			test_AES_CCM_authenticated_encryption_test_case_128_3),
13838 
13839 		/** AES CCM Authenticated Decryption 128 bits key*/
13840 		TEST_CASE_ST(ut_setup, ut_teardown,
13841 			test_AES_CCM_authenticated_decryption_test_case_128_1),
13842 		TEST_CASE_ST(ut_setup, ut_teardown,
13843 			test_AES_CCM_authenticated_decryption_test_case_128_2),
13844 		TEST_CASE_ST(ut_setup, ut_teardown,
13845 			test_AES_CCM_authenticated_decryption_test_case_128_3),
13846 
13847 		/** AES CCM Authenticated Encryption 192 bits key */
13848 		TEST_CASE_ST(ut_setup, ut_teardown,
13849 			test_AES_CCM_authenticated_encryption_test_case_192_1),
13850 		TEST_CASE_ST(ut_setup, ut_teardown,
13851 			test_AES_CCM_authenticated_encryption_test_case_192_2),
13852 		TEST_CASE_ST(ut_setup, ut_teardown,
13853 			test_AES_CCM_authenticated_encryption_test_case_192_3),
13854 
13855 		/** AES CCM Authenticated Decryption 192 bits key*/
13856 		TEST_CASE_ST(ut_setup, ut_teardown,
13857 			test_AES_CCM_authenticated_decryption_test_case_192_1),
13858 		TEST_CASE_ST(ut_setup, ut_teardown,
13859 			test_AES_CCM_authenticated_decryption_test_case_192_2),
13860 		TEST_CASE_ST(ut_setup, ut_teardown,
13861 			test_AES_CCM_authenticated_decryption_test_case_192_3),
13862 
13863 		/** AES CCM Authenticated Encryption 256 bits key */
13864 		TEST_CASE_ST(ut_setup, ut_teardown,
13865 			test_AES_CCM_authenticated_encryption_test_case_256_1),
13866 		TEST_CASE_ST(ut_setup, ut_teardown,
13867 			test_AES_CCM_authenticated_encryption_test_case_256_2),
13868 		TEST_CASE_ST(ut_setup, ut_teardown,
13869 			test_AES_CCM_authenticated_encryption_test_case_256_3),
13870 
13871 		/** AES CCM Authenticated Decryption 256 bits key*/
13872 		TEST_CASE_ST(ut_setup, ut_teardown,
13873 			test_AES_CCM_authenticated_decryption_test_case_256_1),
13874 		TEST_CASE_ST(ut_setup, ut_teardown,
13875 			test_AES_CCM_authenticated_decryption_test_case_256_2),
13876 		TEST_CASE_ST(ut_setup, ut_teardown,
13877 			test_AES_CCM_authenticated_decryption_test_case_256_3),
13878 		TEST_CASES_END()
13879 	}
13880 };
13881 
13882 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite  = {
13883 	.suite_name = "AES GCM Authenticated Test Suite",
13884 	.setup = aes_gcm_auth_testsuite_setup,
13885 	.unit_test_cases = {
13886 		/** AES GCM Authenticated Encryption */
13887 		TEST_CASE_ST(ut_setup, ut_teardown,
13888 			test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
13889 		TEST_CASE_ST(ut_setup, ut_teardown,
13890 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
13891 		TEST_CASE_ST(ut_setup, ut_teardown,
13892 			test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
13893 		TEST_CASE_ST(ut_setup, ut_teardown,
13894 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
13895 		TEST_CASE_ST(ut_setup, ut_teardown,
13896 			test_AES_GCM_authenticated_encryption_test_case_1),
13897 		TEST_CASE_ST(ut_setup, ut_teardown,
13898 			test_AES_GCM_authenticated_encryption_test_case_2),
13899 		TEST_CASE_ST(ut_setup, ut_teardown,
13900 			test_AES_GCM_authenticated_encryption_test_case_3),
13901 		TEST_CASE_ST(ut_setup, ut_teardown,
13902 			test_AES_GCM_authenticated_encryption_test_case_4),
13903 		TEST_CASE_ST(ut_setup, ut_teardown,
13904 			test_AES_GCM_authenticated_encryption_test_case_5),
13905 		TEST_CASE_ST(ut_setup, ut_teardown,
13906 			test_AES_GCM_authenticated_encryption_test_case_6),
13907 		TEST_CASE_ST(ut_setup, ut_teardown,
13908 			test_AES_GCM_authenticated_encryption_test_case_7),
13909 		TEST_CASE_ST(ut_setup, ut_teardown,
13910 			test_AES_GCM_authenticated_encryption_test_case_8),
13911 		TEST_CASE_ST(ut_setup, ut_teardown,
13912 			test_AES_GCM_J0_authenticated_encryption_test_case_1),
13913 
13914 		/** AES GCM Authenticated Decryption */
13915 		TEST_CASE_ST(ut_setup, ut_teardown,
13916 			test_AES_GCM_authenticated_decryption_test_case_1),
13917 		TEST_CASE_ST(ut_setup, ut_teardown,
13918 			test_AES_GCM_authenticated_decryption_test_case_2),
13919 		TEST_CASE_ST(ut_setup, ut_teardown,
13920 			test_AES_GCM_authenticated_decryption_test_case_3),
13921 		TEST_CASE_ST(ut_setup, ut_teardown,
13922 			test_AES_GCM_authenticated_decryption_test_case_4),
13923 		TEST_CASE_ST(ut_setup, ut_teardown,
13924 			test_AES_GCM_authenticated_decryption_test_case_5),
13925 		TEST_CASE_ST(ut_setup, ut_teardown,
13926 			test_AES_GCM_authenticated_decryption_test_case_6),
13927 		TEST_CASE_ST(ut_setup, ut_teardown,
13928 			test_AES_GCM_authenticated_decryption_test_case_7),
13929 		TEST_CASE_ST(ut_setup, ut_teardown,
13930 			test_AES_GCM_authenticated_decryption_test_case_8),
13931 		TEST_CASE_ST(ut_setup, ut_teardown,
13932 			test_AES_GCM_J0_authenticated_decryption_test_case_1),
13933 
13934 		/** AES GCM Authenticated Encryption 192 bits key */
13935 		TEST_CASE_ST(ut_setup, ut_teardown,
13936 			test_AES_GCM_auth_encryption_test_case_192_1),
13937 		TEST_CASE_ST(ut_setup, ut_teardown,
13938 			test_AES_GCM_auth_encryption_test_case_192_2),
13939 		TEST_CASE_ST(ut_setup, ut_teardown,
13940 			test_AES_GCM_auth_encryption_test_case_192_3),
13941 		TEST_CASE_ST(ut_setup, ut_teardown,
13942 			test_AES_GCM_auth_encryption_test_case_192_4),
13943 		TEST_CASE_ST(ut_setup, ut_teardown,
13944 			test_AES_GCM_auth_encryption_test_case_192_5),
13945 		TEST_CASE_ST(ut_setup, ut_teardown,
13946 			test_AES_GCM_auth_encryption_test_case_192_6),
13947 		TEST_CASE_ST(ut_setup, ut_teardown,
13948 			test_AES_GCM_auth_encryption_test_case_192_7),
13949 
13950 		/** AES GCM Authenticated Decryption 192 bits key */
13951 		TEST_CASE_ST(ut_setup, ut_teardown,
13952 			test_AES_GCM_auth_decryption_test_case_192_1),
13953 		TEST_CASE_ST(ut_setup, ut_teardown,
13954 			test_AES_GCM_auth_decryption_test_case_192_2),
13955 		TEST_CASE_ST(ut_setup, ut_teardown,
13956 			test_AES_GCM_auth_decryption_test_case_192_3),
13957 		TEST_CASE_ST(ut_setup, ut_teardown,
13958 			test_AES_GCM_auth_decryption_test_case_192_4),
13959 		TEST_CASE_ST(ut_setup, ut_teardown,
13960 			test_AES_GCM_auth_decryption_test_case_192_5),
13961 		TEST_CASE_ST(ut_setup, ut_teardown,
13962 			test_AES_GCM_auth_decryption_test_case_192_6),
13963 		TEST_CASE_ST(ut_setup, ut_teardown,
13964 			test_AES_GCM_auth_decryption_test_case_192_7),
13965 
13966 		/** AES GCM Authenticated Encryption 256 bits key */
13967 		TEST_CASE_ST(ut_setup, ut_teardown,
13968 			test_AES_GCM_auth_encryption_test_case_256_1),
13969 		TEST_CASE_ST(ut_setup, ut_teardown,
13970 			test_AES_GCM_auth_encryption_test_case_256_2),
13971 		TEST_CASE_ST(ut_setup, ut_teardown,
13972 			test_AES_GCM_auth_encryption_test_case_256_3),
13973 		TEST_CASE_ST(ut_setup, ut_teardown,
13974 			test_AES_GCM_auth_encryption_test_case_256_4),
13975 		TEST_CASE_ST(ut_setup, ut_teardown,
13976 			test_AES_GCM_auth_encryption_test_case_256_5),
13977 		TEST_CASE_ST(ut_setup, ut_teardown,
13978 			test_AES_GCM_auth_encryption_test_case_256_6),
13979 		TEST_CASE_ST(ut_setup, ut_teardown,
13980 			test_AES_GCM_auth_encryption_test_case_256_7),
13981 
13982 		/** AES GCM Authenticated Decryption 256 bits key */
13983 		TEST_CASE_ST(ut_setup, ut_teardown,
13984 			test_AES_GCM_auth_decryption_test_case_256_1),
13985 		TEST_CASE_ST(ut_setup, ut_teardown,
13986 			test_AES_GCM_auth_decryption_test_case_256_2),
13987 		TEST_CASE_ST(ut_setup, ut_teardown,
13988 			test_AES_GCM_auth_decryption_test_case_256_3),
13989 		TEST_CASE_ST(ut_setup, ut_teardown,
13990 			test_AES_GCM_auth_decryption_test_case_256_4),
13991 		TEST_CASE_ST(ut_setup, ut_teardown,
13992 			test_AES_GCM_auth_decryption_test_case_256_5),
13993 		TEST_CASE_ST(ut_setup, ut_teardown,
13994 			test_AES_GCM_auth_decryption_test_case_256_6),
13995 		TEST_CASE_ST(ut_setup, ut_teardown,
13996 			test_AES_GCM_auth_decryption_test_case_256_7),
13997 
13998 		/** AES GCM Authenticated Encryption big aad size */
13999 		TEST_CASE_ST(ut_setup, ut_teardown,
14000 			test_AES_GCM_auth_encryption_test_case_aad_1),
14001 		TEST_CASE_ST(ut_setup, ut_teardown,
14002 			test_AES_GCM_auth_encryption_test_case_aad_2),
14003 
14004 		/** AES GCM Authenticated Decryption big aad size */
14005 		TEST_CASE_ST(ut_setup, ut_teardown,
14006 			test_AES_GCM_auth_decryption_test_case_aad_1),
14007 		TEST_CASE_ST(ut_setup, ut_teardown,
14008 			test_AES_GCM_auth_decryption_test_case_aad_2),
14009 
14010 		/** Out of place tests */
14011 		TEST_CASE_ST(ut_setup, ut_teardown,
14012 			test_AES_GCM_authenticated_encryption_oop_test_case_1),
14013 		TEST_CASE_ST(ut_setup, ut_teardown,
14014 			test_AES_GCM_authenticated_decryption_oop_test_case_1),
14015 
14016 		/** Session-less tests */
14017 		TEST_CASE_ST(ut_setup, ut_teardown,
14018 			test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
14019 		TEST_CASE_ST(ut_setup, ut_teardown,
14020 			test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
14021 
14022 		TEST_CASES_END()
14023 	}
14024 };
14025 
14026 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite  = {
14027 	.suite_name = "AES GMAC Authentication Test Suite",
14028 	.setup = aes_gmac_auth_testsuite_setup,
14029 	.unit_test_cases = {
14030 		TEST_CASE_ST(ut_setup, ut_teardown,
14031 			test_AES_GMAC_authentication_test_case_1),
14032 		TEST_CASE_ST(ut_setup, ut_teardown,
14033 			test_AES_GMAC_authentication_verify_test_case_1),
14034 		TEST_CASE_ST(ut_setup, ut_teardown,
14035 			test_AES_GMAC_authentication_test_case_2),
14036 		TEST_CASE_ST(ut_setup, ut_teardown,
14037 			test_AES_GMAC_authentication_verify_test_case_2),
14038 		TEST_CASE_ST(ut_setup, ut_teardown,
14039 			test_AES_GMAC_authentication_test_case_3),
14040 		TEST_CASE_ST(ut_setup, ut_teardown,
14041 			test_AES_GMAC_authentication_verify_test_case_3),
14042 		TEST_CASE_ST(ut_setup, ut_teardown,
14043 			test_AES_GMAC_authentication_test_case_4),
14044 		TEST_CASE_ST(ut_setup, ut_teardown,
14045 			test_AES_GMAC_authentication_verify_test_case_4),
14046 		TEST_CASE_ST(ut_setup, ut_teardown,
14047 			test_AES_GMAC_authentication_SGL_40B),
14048 		TEST_CASE_ST(ut_setup, ut_teardown,
14049 			test_AES_GMAC_authentication_SGL_80B),
14050 		TEST_CASE_ST(ut_setup, ut_teardown,
14051 			test_AES_GMAC_authentication_SGL_2048B),
14052 		TEST_CASE_ST(ut_setup, ut_teardown,
14053 			test_AES_GMAC_authentication_SGL_2047B),
14054 
14055 		TEST_CASES_END()
14056 	}
14057 };
14058 
14059 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite  = {
14060 	.suite_name = "Chacha20-Poly1305 Test Suite",
14061 	.setup = chacha20_poly1305_testsuite_setup,
14062 	.unit_test_cases = {
14063 		TEST_CASE_ST(ut_setup, ut_teardown,
14064 			test_chacha20_poly1305_encrypt_test_case_rfc8439),
14065 		TEST_CASE_ST(ut_setup, ut_teardown,
14066 			test_chacha20_poly1305_decrypt_test_case_rfc8439),
14067 		TEST_CASES_END()
14068 	}
14069 };
14070 
14071 static struct unit_test_suite cryptodev_snow3g_testsuite  = {
14072 	.suite_name = "SNOW 3G Test Suite",
14073 	.setup = snow3g_testsuite_setup,
14074 	.unit_test_cases = {
14075 		/** SNOW 3G encrypt only (UEA2) */
14076 		TEST_CASE_ST(ut_setup, ut_teardown,
14077 			test_snow3g_encryption_test_case_1),
14078 		TEST_CASE_ST(ut_setup, ut_teardown,
14079 			test_snow3g_encryption_test_case_2),
14080 		TEST_CASE_ST(ut_setup, ut_teardown,
14081 			test_snow3g_encryption_test_case_3),
14082 		TEST_CASE_ST(ut_setup, ut_teardown,
14083 			test_snow3g_encryption_test_case_4),
14084 		TEST_CASE_ST(ut_setup, ut_teardown,
14085 			test_snow3g_encryption_test_case_5),
14086 
14087 		TEST_CASE_ST(ut_setup, ut_teardown,
14088 			test_snow3g_encryption_test_case_1_oop),
14089 		TEST_CASE_ST(ut_setup, ut_teardown,
14090 			test_snow3g_encryption_test_case_1_oop_sgl),
14091 		TEST_CASE_ST(ut_setup, ut_teardown,
14092 			test_snow3g_encryption_test_case_1_offset_oop),
14093 		TEST_CASE_ST(ut_setup, ut_teardown,
14094 			test_snow3g_decryption_test_case_1_oop),
14095 
14096 		/** SNOW 3G generate auth, then encrypt (UEA2) */
14097 		TEST_CASE_ST(ut_setup, ut_teardown,
14098 			test_snow3g_auth_cipher_test_case_1),
14099 		TEST_CASE_ST(ut_setup, ut_teardown,
14100 			test_snow3g_auth_cipher_test_case_2),
14101 		TEST_CASE_ST(ut_setup, ut_teardown,
14102 			test_snow3g_auth_cipher_test_case_2_oop),
14103 		TEST_CASE_ST(ut_setup, ut_teardown,
14104 			test_snow3g_auth_cipher_part_digest_enc),
14105 		TEST_CASE_ST(ut_setup, ut_teardown,
14106 			test_snow3g_auth_cipher_part_digest_enc_oop),
14107 		TEST_CASE_ST(ut_setup, ut_teardown,
14108 			test_snow3g_auth_cipher_test_case_3_sgl),
14109 		TEST_CASE_ST(ut_setup, ut_teardown,
14110 			test_snow3g_auth_cipher_test_case_3_oop_sgl),
14111 		TEST_CASE_ST(ut_setup, ut_teardown,
14112 			test_snow3g_auth_cipher_part_digest_enc_sgl),
14113 		TEST_CASE_ST(ut_setup, ut_teardown,
14114 			test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
14115 
14116 		/** SNOW 3G decrypt (UEA2), then verify auth */
14117 		TEST_CASE_ST(ut_setup, ut_teardown,
14118 			test_snow3g_auth_cipher_verify_test_case_1),
14119 		TEST_CASE_ST(ut_setup, ut_teardown,
14120 			test_snow3g_auth_cipher_verify_test_case_2),
14121 		TEST_CASE_ST(ut_setup, ut_teardown,
14122 			test_snow3g_auth_cipher_verify_test_case_2_oop),
14123 		TEST_CASE_ST(ut_setup, ut_teardown,
14124 			test_snow3g_auth_cipher_verify_part_digest_enc),
14125 		TEST_CASE_ST(ut_setup, ut_teardown,
14126 			test_snow3g_auth_cipher_verify_part_digest_enc_oop),
14127 		TEST_CASE_ST(ut_setup, ut_teardown,
14128 			test_snow3g_auth_cipher_verify_test_case_3_sgl),
14129 		TEST_CASE_ST(ut_setup, ut_teardown,
14130 			test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
14131 		TEST_CASE_ST(ut_setup, ut_teardown,
14132 			test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
14133 		TEST_CASE_ST(ut_setup, ut_teardown,
14134 			test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
14135 
14136 		/** SNOW 3G decrypt only (UEA2) */
14137 		TEST_CASE_ST(ut_setup, ut_teardown,
14138 			test_snow3g_decryption_test_case_1),
14139 		TEST_CASE_ST(ut_setup, ut_teardown,
14140 			test_snow3g_decryption_test_case_2),
14141 		TEST_CASE_ST(ut_setup, ut_teardown,
14142 			test_snow3g_decryption_test_case_3),
14143 		TEST_CASE_ST(ut_setup, ut_teardown,
14144 			test_snow3g_decryption_test_case_4),
14145 		TEST_CASE_ST(ut_setup, ut_teardown,
14146 			test_snow3g_decryption_test_case_5),
14147 		TEST_CASE_ST(ut_setup, ut_teardown,
14148 			test_snow3g_decryption_with_digest_test_case_1),
14149 		TEST_CASE_ST(ut_setup, ut_teardown,
14150 			test_snow3g_hash_generate_test_case_1),
14151 		TEST_CASE_ST(ut_setup, ut_teardown,
14152 			test_snow3g_hash_generate_test_case_2),
14153 		TEST_CASE_ST(ut_setup, ut_teardown,
14154 			test_snow3g_hash_generate_test_case_3),
14155 
14156 		/* Tests with buffers which length is not byte-aligned */
14157 		TEST_CASE_ST(ut_setup, ut_teardown,
14158 			test_snow3g_hash_generate_test_case_4),
14159 		TEST_CASE_ST(ut_setup, ut_teardown,
14160 			test_snow3g_hash_generate_test_case_5),
14161 		TEST_CASE_ST(ut_setup, ut_teardown,
14162 			test_snow3g_hash_generate_test_case_6),
14163 		TEST_CASE_ST(ut_setup, ut_teardown,
14164 			test_snow3g_hash_verify_test_case_1),
14165 		TEST_CASE_ST(ut_setup, ut_teardown,
14166 			test_snow3g_hash_verify_test_case_2),
14167 		TEST_CASE_ST(ut_setup, ut_teardown,
14168 			test_snow3g_hash_verify_test_case_3),
14169 
14170 		/* Tests with buffers which length is not byte-aligned */
14171 		TEST_CASE_ST(ut_setup, ut_teardown,
14172 			test_snow3g_hash_verify_test_case_4),
14173 		TEST_CASE_ST(ut_setup, ut_teardown,
14174 			test_snow3g_hash_verify_test_case_5),
14175 		TEST_CASE_ST(ut_setup, ut_teardown,
14176 			test_snow3g_hash_verify_test_case_6),
14177 		TEST_CASE_ST(ut_setup, ut_teardown,
14178 			test_snow3g_cipher_auth_test_case_1),
14179 		TEST_CASE_ST(ut_setup, ut_teardown,
14180 			test_snow3g_auth_cipher_with_digest_test_case_1),
14181 		TEST_CASES_END()
14182 	}
14183 };
14184 
14185 static struct unit_test_suite cryptodev_zuc_testsuite  = {
14186 	.suite_name = "ZUC Test Suite",
14187 	.setup = zuc_testsuite_setup,
14188 	.unit_test_cases = {
14189 		/** ZUC encrypt only (EEA3) */
14190 		TEST_CASE_ST(ut_setup, ut_teardown,
14191 			test_zuc_encryption_test_case_1),
14192 		TEST_CASE_ST(ut_setup, ut_teardown,
14193 			test_zuc_encryption_test_case_2),
14194 		TEST_CASE_ST(ut_setup, ut_teardown,
14195 			test_zuc_encryption_test_case_3),
14196 		TEST_CASE_ST(ut_setup, ut_teardown,
14197 			test_zuc_encryption_test_case_4),
14198 		TEST_CASE_ST(ut_setup, ut_teardown,
14199 			test_zuc_encryption_test_case_5),
14200 		TEST_CASE_ST(ut_setup, ut_teardown,
14201 			test_zuc_encryption_test_case_6_sgl),
14202 
14203 		/** ZUC authenticate (EIA3) */
14204 		TEST_CASE_ST(ut_setup, ut_teardown,
14205 			test_zuc_hash_generate_test_case_1),
14206 		TEST_CASE_ST(ut_setup, ut_teardown,
14207 			test_zuc_hash_generate_test_case_2),
14208 		TEST_CASE_ST(ut_setup, ut_teardown,
14209 			test_zuc_hash_generate_test_case_3),
14210 		TEST_CASE_ST(ut_setup, ut_teardown,
14211 			test_zuc_hash_generate_test_case_4),
14212 		TEST_CASE_ST(ut_setup, ut_teardown,
14213 			test_zuc_hash_generate_test_case_5),
14214 		TEST_CASE_ST(ut_setup, ut_teardown,
14215 			test_zuc_hash_generate_test_case_6),
14216 		TEST_CASE_ST(ut_setup, ut_teardown,
14217 			test_zuc_hash_generate_test_case_7),
14218 		TEST_CASE_ST(ut_setup, ut_teardown,
14219 			test_zuc_hash_generate_test_case_8),
14220 
14221 		/** ZUC alg-chain (EEA3/EIA3) */
14222 		TEST_CASE_ST(ut_setup, ut_teardown,
14223 			test_zuc_cipher_auth_test_case_1),
14224 		TEST_CASE_ST(ut_setup, ut_teardown,
14225 			test_zuc_cipher_auth_test_case_2),
14226 
14227 		/** ZUC generate auth, then encrypt (EEA3) */
14228 		TEST_CASE_ST(ut_setup, ut_teardown,
14229 			test_zuc_auth_cipher_test_case_1),
14230 		TEST_CASE_ST(ut_setup, ut_teardown,
14231 			test_zuc_auth_cipher_test_case_1_oop),
14232 		TEST_CASE_ST(ut_setup, ut_teardown,
14233 			test_zuc_auth_cipher_test_case_1_sgl),
14234 		TEST_CASE_ST(ut_setup, ut_teardown,
14235 			test_zuc_auth_cipher_test_case_1_oop_sgl),
14236 
14237 		/** ZUC decrypt (EEA3), then verify auth */
14238 		TEST_CASE_ST(ut_setup, ut_teardown,
14239 			test_zuc_auth_cipher_verify_test_case_1),
14240 		TEST_CASE_ST(ut_setup, ut_teardown,
14241 			test_zuc_auth_cipher_verify_test_case_1_oop),
14242 		TEST_CASE_ST(ut_setup, ut_teardown,
14243 			test_zuc_auth_cipher_verify_test_case_1_sgl),
14244 		TEST_CASE_ST(ut_setup, ut_teardown,
14245 			test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
14246 		TEST_CASES_END()
14247 	}
14248 };
14249 
14250 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite  = {
14251 	.suite_name = "HMAC_MD5 Authentication Test Suite",
14252 	.setup = hmac_md5_auth_testsuite_setup,
14253 	.unit_test_cases = {
14254 		TEST_CASE_ST(ut_setup, ut_teardown,
14255 			test_MD5_HMAC_generate_case_1),
14256 		TEST_CASE_ST(ut_setup, ut_teardown,
14257 			test_MD5_HMAC_verify_case_1),
14258 		TEST_CASE_ST(ut_setup, ut_teardown,
14259 			test_MD5_HMAC_generate_case_2),
14260 		TEST_CASE_ST(ut_setup, ut_teardown,
14261 			test_MD5_HMAC_verify_case_2),
14262 		TEST_CASES_END()
14263 	}
14264 };
14265 
14266 static struct unit_test_suite cryptodev_kasumi_testsuite  = {
14267 	.suite_name = "Kasumi Test Suite",
14268 	.setup = kasumi_testsuite_setup,
14269 	.unit_test_cases = {
14270 		/** KASUMI hash only (UIA1) */
14271 		TEST_CASE_ST(ut_setup, ut_teardown,
14272 			test_kasumi_hash_generate_test_case_1),
14273 		TEST_CASE_ST(ut_setup, ut_teardown,
14274 			test_kasumi_hash_generate_test_case_2),
14275 		TEST_CASE_ST(ut_setup, ut_teardown,
14276 			test_kasumi_hash_generate_test_case_3),
14277 		TEST_CASE_ST(ut_setup, ut_teardown,
14278 			test_kasumi_hash_generate_test_case_4),
14279 		TEST_CASE_ST(ut_setup, ut_teardown,
14280 			test_kasumi_hash_generate_test_case_5),
14281 		TEST_CASE_ST(ut_setup, ut_teardown,
14282 			test_kasumi_hash_generate_test_case_6),
14283 
14284 		TEST_CASE_ST(ut_setup, ut_teardown,
14285 			test_kasumi_hash_verify_test_case_1),
14286 		TEST_CASE_ST(ut_setup, ut_teardown,
14287 			test_kasumi_hash_verify_test_case_2),
14288 		TEST_CASE_ST(ut_setup, ut_teardown,
14289 			test_kasumi_hash_verify_test_case_3),
14290 		TEST_CASE_ST(ut_setup, ut_teardown,
14291 			test_kasumi_hash_verify_test_case_4),
14292 		TEST_CASE_ST(ut_setup, ut_teardown,
14293 			test_kasumi_hash_verify_test_case_5),
14294 
14295 		/** KASUMI encrypt only (UEA1) */
14296 		TEST_CASE_ST(ut_setup, ut_teardown,
14297 			test_kasumi_encryption_test_case_1),
14298 		TEST_CASE_ST(ut_setup, ut_teardown,
14299 			test_kasumi_encryption_test_case_1_sgl),
14300 		TEST_CASE_ST(ut_setup, ut_teardown,
14301 			test_kasumi_encryption_test_case_1_oop),
14302 		TEST_CASE_ST(ut_setup, ut_teardown,
14303 			test_kasumi_encryption_test_case_1_oop_sgl),
14304 		TEST_CASE_ST(ut_setup, ut_teardown,
14305 			test_kasumi_encryption_test_case_2),
14306 		TEST_CASE_ST(ut_setup, ut_teardown,
14307 			test_kasumi_encryption_test_case_3),
14308 		TEST_CASE_ST(ut_setup, ut_teardown,
14309 			test_kasumi_encryption_test_case_4),
14310 		TEST_CASE_ST(ut_setup, ut_teardown,
14311 			test_kasumi_encryption_test_case_5),
14312 
14313 		/** KASUMI decrypt only (UEA1) */
14314 		TEST_CASE_ST(ut_setup, ut_teardown,
14315 			test_kasumi_decryption_test_case_1),
14316 		TEST_CASE_ST(ut_setup, ut_teardown,
14317 			test_kasumi_decryption_test_case_2),
14318 		TEST_CASE_ST(ut_setup, ut_teardown,
14319 			test_kasumi_decryption_test_case_3),
14320 		TEST_CASE_ST(ut_setup, ut_teardown,
14321 			test_kasumi_decryption_test_case_4),
14322 		TEST_CASE_ST(ut_setup, ut_teardown,
14323 			test_kasumi_decryption_test_case_5),
14324 		TEST_CASE_ST(ut_setup, ut_teardown,
14325 			test_kasumi_decryption_test_case_1_oop),
14326 		TEST_CASE_ST(ut_setup, ut_teardown,
14327 			test_kasumi_cipher_auth_test_case_1),
14328 
14329 		/** KASUMI generate auth, then encrypt (F8) */
14330 		TEST_CASE_ST(ut_setup, ut_teardown,
14331 			test_kasumi_auth_cipher_test_case_1),
14332 		TEST_CASE_ST(ut_setup, ut_teardown,
14333 			test_kasumi_auth_cipher_test_case_2),
14334 		TEST_CASE_ST(ut_setup, ut_teardown,
14335 			test_kasumi_auth_cipher_test_case_2_oop),
14336 		TEST_CASE_ST(ut_setup, ut_teardown,
14337 			test_kasumi_auth_cipher_test_case_2_sgl),
14338 		TEST_CASE_ST(ut_setup, ut_teardown,
14339 			test_kasumi_auth_cipher_test_case_2_oop_sgl),
14340 
14341 		/** KASUMI decrypt (F8), then verify auth */
14342 		TEST_CASE_ST(ut_setup, ut_teardown,
14343 			test_kasumi_auth_cipher_verify_test_case_1),
14344 		TEST_CASE_ST(ut_setup, ut_teardown,
14345 			test_kasumi_auth_cipher_verify_test_case_2),
14346 		TEST_CASE_ST(ut_setup, ut_teardown,
14347 			test_kasumi_auth_cipher_verify_test_case_2_oop),
14348 		TEST_CASE_ST(ut_setup, ut_teardown,
14349 			test_kasumi_auth_cipher_verify_test_case_2_sgl),
14350 		TEST_CASE_ST(ut_setup, ut_teardown,
14351 			test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
14352 
14353 		TEST_CASES_END()
14354 	}
14355 };
14356 
14357 static struct unit_test_suite cryptodev_esn_testsuite  = {
14358 	.suite_name = "ESN Test Suite",
14359 	.setup = esn_testsuite_setup,
14360 	.unit_test_cases = {
14361 		TEST_CASE_ST(ut_setup, ut_teardown,
14362 			auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
14363 		TEST_CASE_ST(ut_setup, ut_teardown,
14364 			auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
14365 		TEST_CASES_END()
14366 	}
14367 };
14368 
14369 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite  = {
14370 	.suite_name = "Negative AES GCM Test Suite",
14371 	.setup = negative_aes_gcm_testsuite_setup,
14372 	.unit_test_cases = {
14373 		TEST_CASE_ST(ut_setup, ut_teardown,
14374 			test_AES_GCM_auth_encryption_fail_iv_corrupt),
14375 		TEST_CASE_ST(ut_setup, ut_teardown,
14376 			test_AES_GCM_auth_encryption_fail_in_data_corrupt),
14377 		TEST_CASE_ST(ut_setup, ut_teardown,
14378 			test_AES_GCM_auth_encryption_fail_out_data_corrupt),
14379 		TEST_CASE_ST(ut_setup, ut_teardown,
14380 			test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
14381 		TEST_CASE_ST(ut_setup, ut_teardown,
14382 			test_AES_GCM_auth_encryption_fail_aad_corrupt),
14383 		TEST_CASE_ST(ut_setup, ut_teardown,
14384 			test_AES_GCM_auth_encryption_fail_tag_corrupt),
14385 		TEST_CASE_ST(ut_setup, ut_teardown,
14386 			test_AES_GCM_auth_decryption_fail_iv_corrupt),
14387 		TEST_CASE_ST(ut_setup, ut_teardown,
14388 			test_AES_GCM_auth_decryption_fail_in_data_corrupt),
14389 		TEST_CASE_ST(ut_setup, ut_teardown,
14390 			test_AES_GCM_auth_decryption_fail_out_data_corrupt),
14391 		TEST_CASE_ST(ut_setup, ut_teardown,
14392 			test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
14393 		TEST_CASE_ST(ut_setup, ut_teardown,
14394 			test_AES_GCM_auth_decryption_fail_aad_corrupt),
14395 		TEST_CASE_ST(ut_setup, ut_teardown,
14396 			test_AES_GCM_auth_decryption_fail_tag_corrupt),
14397 
14398 		TEST_CASES_END()
14399 	}
14400 };
14401 
14402 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite  = {
14403 	.suite_name = "Negative AES GMAC Test Suite",
14404 	.setup = negative_aes_gmac_testsuite_setup,
14405 	.unit_test_cases = {
14406 		TEST_CASE_ST(ut_setup, ut_teardown,
14407 			authentication_verify_AES128_GMAC_fail_data_corrupt),
14408 		TEST_CASE_ST(ut_setup, ut_teardown,
14409 			authentication_verify_AES128_GMAC_fail_tag_corrupt),
14410 
14411 		TEST_CASES_END()
14412 	}
14413 };
14414 
14415 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite  = {
14416 	.suite_name = "Mixed CIPHER + HASH algorithms Test Suite",
14417 	.setup = mixed_cipher_hash_testsuite_setup,
14418 	.unit_test_cases = {
14419 		/** AUTH AES CMAC + CIPHER AES CTR */
14420 		TEST_CASE_ST(ut_setup, ut_teardown,
14421 			test_aes_cmac_aes_ctr_digest_enc_test_case_1),
14422 		TEST_CASE_ST(ut_setup, ut_teardown,
14423 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
14424 		TEST_CASE_ST(ut_setup, ut_teardown,
14425 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
14426 		TEST_CASE_ST(ut_setup, ut_teardown,
14427 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
14428 		TEST_CASE_ST(ut_setup, ut_teardown,
14429 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
14430 		TEST_CASE_ST(ut_setup, ut_teardown,
14431 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
14432 		TEST_CASE_ST(ut_setup, ut_teardown,
14433 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
14434 		TEST_CASE_ST(ut_setup, ut_teardown,
14435 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
14436 
14437 		/** AUTH ZUC + CIPHER SNOW3G */
14438 		TEST_CASE_ST(ut_setup, ut_teardown,
14439 			test_auth_zuc_cipher_snow_test_case_1),
14440 		TEST_CASE_ST(ut_setup, ut_teardown,
14441 			test_verify_auth_zuc_cipher_snow_test_case_1),
14442 		/** AUTH AES CMAC + CIPHER SNOW3G */
14443 		TEST_CASE_ST(ut_setup, ut_teardown,
14444 			test_auth_aes_cmac_cipher_snow_test_case_1),
14445 		TEST_CASE_ST(ut_setup, ut_teardown,
14446 			test_verify_auth_aes_cmac_cipher_snow_test_case_1),
14447 		/** AUTH ZUC + CIPHER AES CTR */
14448 		TEST_CASE_ST(ut_setup, ut_teardown,
14449 			test_auth_zuc_cipher_aes_ctr_test_case_1),
14450 		TEST_CASE_ST(ut_setup, ut_teardown,
14451 			test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
14452 		/** AUTH SNOW3G + CIPHER AES CTR */
14453 		TEST_CASE_ST(ut_setup, ut_teardown,
14454 			test_auth_snow_cipher_aes_ctr_test_case_1),
14455 		TEST_CASE_ST(ut_setup, ut_teardown,
14456 			test_verify_auth_snow_cipher_aes_ctr_test_case_1),
14457 		/** AUTH SNOW3G + CIPHER ZUC */
14458 		TEST_CASE_ST(ut_setup, ut_teardown,
14459 			test_auth_snow_cipher_zuc_test_case_1),
14460 		TEST_CASE_ST(ut_setup, ut_teardown,
14461 			test_verify_auth_snow_cipher_zuc_test_case_1),
14462 		/** AUTH AES CMAC + CIPHER ZUC */
14463 		TEST_CASE_ST(ut_setup, ut_teardown,
14464 			test_auth_aes_cmac_cipher_zuc_test_case_1),
14465 		TEST_CASE_ST(ut_setup, ut_teardown,
14466 			test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
14467 
14468 		/** AUTH NULL + CIPHER SNOW3G */
14469 		TEST_CASE_ST(ut_setup, ut_teardown,
14470 			test_auth_null_cipher_snow_test_case_1),
14471 		TEST_CASE_ST(ut_setup, ut_teardown,
14472 			test_verify_auth_null_cipher_snow_test_case_1),
14473 		/** AUTH NULL + CIPHER ZUC */
14474 		TEST_CASE_ST(ut_setup, ut_teardown,
14475 			test_auth_null_cipher_zuc_test_case_1),
14476 		TEST_CASE_ST(ut_setup, ut_teardown,
14477 			test_verify_auth_null_cipher_zuc_test_case_1),
14478 		/** AUTH SNOW3G + CIPHER NULL */
14479 		TEST_CASE_ST(ut_setup, ut_teardown,
14480 			test_auth_snow_cipher_null_test_case_1),
14481 		TEST_CASE_ST(ut_setup, ut_teardown,
14482 			test_verify_auth_snow_cipher_null_test_case_1),
14483 		/** AUTH ZUC + CIPHER NULL */
14484 		TEST_CASE_ST(ut_setup, ut_teardown,
14485 			test_auth_zuc_cipher_null_test_case_1),
14486 		TEST_CASE_ST(ut_setup, ut_teardown,
14487 			test_verify_auth_zuc_cipher_null_test_case_1),
14488 		/** AUTH NULL + CIPHER AES CTR */
14489 		TEST_CASE_ST(ut_setup, ut_teardown,
14490 			test_auth_null_cipher_aes_ctr_test_case_1),
14491 		TEST_CASE_ST(ut_setup, ut_teardown,
14492 			test_verify_auth_null_cipher_aes_ctr_test_case_1),
14493 		/** AUTH AES CMAC + CIPHER NULL */
14494 		TEST_CASE_ST(ut_setup, ut_teardown,
14495 			test_auth_aes_cmac_cipher_null_test_case_1),
14496 		TEST_CASE_ST(ut_setup, ut_teardown,
14497 			test_verify_auth_aes_cmac_cipher_null_test_case_1),
14498 		TEST_CASES_END()
14499 	}
14500 };
14501 
14502 static int
14503 run_cryptodev_testsuite(const char *pmd_name)
14504 {
14505 	uint8_t ret, j, i = 0, blk_start_idx = 0;
14506 	const enum blockcipher_test_type blk_suites[] = {
14507 		BLKCIPHER_AES_CHAIN_TYPE,
14508 		BLKCIPHER_AES_CIPHERONLY_TYPE,
14509 		BLKCIPHER_AES_DOCSIS_TYPE,
14510 		BLKCIPHER_3DES_CHAIN_TYPE,
14511 		BLKCIPHER_3DES_CIPHERONLY_TYPE,
14512 		BLKCIPHER_DES_CIPHERONLY_TYPE,
14513 		BLKCIPHER_DES_DOCSIS_TYPE,
14514 		BLKCIPHER_AUTHONLY_TYPE};
14515 	struct unit_test_suite *static_suites[] = {
14516 		&cryptodev_multi_session_testsuite,
14517 		&cryptodev_null_testsuite,
14518 		&cryptodev_aes_ccm_auth_testsuite,
14519 		&cryptodev_aes_gcm_auth_testsuite,
14520 		&cryptodev_aes_gmac_auth_testsuite,
14521 		&cryptodev_snow3g_testsuite,
14522 		&cryptodev_chacha20_poly1305_testsuite,
14523 		&cryptodev_zuc_testsuite,
14524 		&cryptodev_hmac_md5_auth_testsuite,
14525 		&cryptodev_kasumi_testsuite,
14526 		&cryptodev_esn_testsuite,
14527 		&cryptodev_negative_aes_gcm_testsuite,
14528 		&cryptodev_negative_aes_gmac_testsuite,
14529 		&cryptodev_mixed_cipher_hash_testsuite,
14530 		&cryptodev_negative_hmac_sha1_testsuite,
14531 		&cryptodev_gen_testsuite,
14532 #ifdef RTE_LIB_SECURITY
14533 		&pdcp_proto_testsuite,
14534 		&docsis_proto_testsuite,
14535 #endif
14536 		&end_testsuite
14537 	};
14538 	static struct unit_test_suite ts = {
14539 		.suite_name = "Cryptodev Unit Test Suite",
14540 		.setup = testsuite_setup,
14541 		.teardown = testsuite_teardown,
14542 		.unit_test_cases = {TEST_CASES_END()}
14543 	};
14544 
14545 	gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name);
14546 
14547 	if (gbl_driver_id == -1) {
14548 		RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name);
14549 		return TEST_SKIPPED;
14550 	}
14551 
14552 	ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
14553 			(RTE_DIM(blk_suites) + RTE_DIM(static_suites)));
14554 
14555 	ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites));
14556 	ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
14557 	ret = unit_test_suite_runner(&ts);
14558 
14559 	FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites));
14560 	free(ts.unit_test_suites);
14561 	return ret;
14562 }
14563 
14564 static int
14565 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name)
14566 {
14567 	struct rte_cryptodev_info dev_info;
14568 	uint8_t i, nb_devs;
14569 	int driver_id;
14570 
14571 	driver_id = rte_cryptodev_driver_id_get(pmd_name);
14572 	if (driver_id == -1) {
14573 		RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name);
14574 		return TEST_SKIPPED;
14575 	}
14576 
14577 	nb_devs = rte_cryptodev_count();
14578 	if (nb_devs < 1) {
14579 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
14580 		return TEST_SKIPPED;
14581 	}
14582 
14583 	for (i = 0; i < nb_devs; i++) {
14584 		rte_cryptodev_info_get(i, &dev_info);
14585 		if (dev_info.driver_id == driver_id) {
14586 			if (!(dev_info.feature_flags & flag)) {
14587 				RTE_LOG(INFO, USER1, "%s not supported\n",
14588 						flag_name);
14589 				return TEST_SKIPPED;
14590 			}
14591 			return 0; /* found */
14592 		}
14593 	}
14594 
14595 	RTE_LOG(INFO, USER1, "%s not supported\n", flag_name);
14596 	return TEST_SKIPPED;
14597 }
14598 
14599 static int
14600 test_cryptodev_qat(void)
14601 {
14602 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
14603 }
14604 
14605 static int
14606 test_cryptodev_virtio(void)
14607 {
14608 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
14609 }
14610 
14611 static int
14612 test_cryptodev_aesni_mb(void)
14613 {
14614 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14615 }
14616 
14617 static int
14618 test_cryptodev_cpu_aesni_mb(void)
14619 {
14620 	int32_t rc;
14621 	enum rte_security_session_action_type at = gbl_action_type;
14622 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
14623 	rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14624 	gbl_action_type = at;
14625 	return rc;
14626 }
14627 
14628 static int
14629 test_cryptodev_openssl(void)
14630 {
14631 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
14632 }
14633 
14634 static int
14635 test_cryptodev_aesni_gcm(void)
14636 {
14637 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
14638 }
14639 
14640 static int
14641 test_cryptodev_cpu_aesni_gcm(void)
14642 {
14643 	int32_t rc;
14644 	enum rte_security_session_action_type at = gbl_action_type;
14645 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
14646 	rc  = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
14647 	gbl_action_type = at;
14648 	return rc;
14649 }
14650 
14651 static int
14652 test_cryptodev_mlx5(void)
14653 {
14654 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD));
14655 }
14656 
14657 static int
14658 test_cryptodev_null(void)
14659 {
14660 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD));
14661 }
14662 
14663 static int
14664 test_cryptodev_sw_snow3g(void)
14665 {
14666 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
14667 }
14668 
14669 static int
14670 test_cryptodev_sw_kasumi(void)
14671 {
14672 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
14673 }
14674 
14675 static int
14676 test_cryptodev_sw_zuc(void)
14677 {
14678 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
14679 }
14680 
14681 static int
14682 test_cryptodev_armv8(void)
14683 {
14684 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
14685 }
14686 
14687 static int
14688 test_cryptodev_mrvl(void)
14689 {
14690 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
14691 }
14692 
14693 #ifdef RTE_CRYPTO_SCHEDULER
14694 
14695 static int
14696 test_cryptodev_scheduler(void)
14697 {
14698 	uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0;
14699 	const enum blockcipher_test_type blk_suites[] = {
14700 		BLKCIPHER_AES_CHAIN_TYPE,
14701 		BLKCIPHER_AES_CIPHERONLY_TYPE,
14702 		BLKCIPHER_AUTHONLY_TYPE
14703 	};
14704 	static struct unit_test_suite scheduler_multicore = {
14705 		.suite_name = "Scheduler Multicore Unit Test Suite",
14706 		.setup = scheduler_multicore_testsuite_setup,
14707 		.teardown = scheduler_mode_testsuite_teardown,
14708 		.unit_test_cases = {TEST_CASES_END()}
14709 	};
14710 	static struct unit_test_suite scheduler_round_robin = {
14711 		.suite_name = "Scheduler Round Robin Unit Test Suite",
14712 		.setup = scheduler_roundrobin_testsuite_setup,
14713 		.teardown = scheduler_mode_testsuite_teardown,
14714 		.unit_test_cases = {TEST_CASES_END()}
14715 	};
14716 	static struct unit_test_suite scheduler_failover = {
14717 		.suite_name = "Scheduler Failover Unit Test Suite",
14718 		.setup = scheduler_failover_testsuite_setup,
14719 		.teardown = scheduler_mode_testsuite_teardown,
14720 		.unit_test_cases = {TEST_CASES_END()}
14721 	};
14722 	static struct unit_test_suite scheduler_pkt_size_distr = {
14723 		.suite_name = "Scheduler Pkt Size Distr Unit Test Suite",
14724 		.setup = scheduler_pkt_size_distr_testsuite_setup,
14725 		.teardown = scheduler_mode_testsuite_teardown,
14726 		.unit_test_cases = {TEST_CASES_END()}
14727 	};
14728 	struct unit_test_suite *sched_mode_suites[] = {
14729 		&scheduler_multicore,
14730 		&scheduler_round_robin,
14731 		&scheduler_failover,
14732 		&scheduler_pkt_size_distr
14733 	};
14734 	static struct unit_test_suite scheduler_config = {
14735 		.suite_name = "Crypto Device Scheduler Config Unit Test Suite",
14736 		.unit_test_cases = {
14737 			TEST_CASE(test_scheduler_attach_worker_op),
14738 			TEST_CASE(test_scheduler_mode_multicore_op),
14739 			TEST_CASE(test_scheduler_mode_roundrobin_op),
14740 			TEST_CASE(test_scheduler_mode_failover_op),
14741 			TEST_CASE(test_scheduler_mode_pkt_size_distr_op),
14742 			TEST_CASE(test_scheduler_detach_worker_op),
14743 
14744 			TEST_CASES_END() /**< NULL terminate array */
14745 		}
14746 	};
14747 	struct unit_test_suite *static_suites[] = {
14748 		&scheduler_config,
14749 		&end_testsuite
14750 	};
14751 	static struct unit_test_suite ts = {
14752 		.suite_name = "Scheduler Unit Test Suite",
14753 		.setup = scheduler_testsuite_setup,
14754 		.teardown = testsuite_teardown,
14755 		.unit_test_cases = {TEST_CASES_END()}
14756 	};
14757 
14758 	gbl_driver_id =	rte_cryptodev_driver_id_get(
14759 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
14760 
14761 	if (gbl_driver_id == -1) {
14762 		RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
14763 		return TEST_SKIPPED;
14764 	}
14765 
14766 	if (rte_cryptodev_driver_id_get(
14767 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
14768 		RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
14769 		return TEST_SKIPPED;
14770 	}
14771 
14772 	for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
14773 		uint8_t blk_i = 0;
14774 		sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof
14775 				(struct unit_test_suite *) *
14776 				(RTE_DIM(blk_suites) + 1));
14777 		ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]),
14778 				blk_suites, RTE_DIM(blk_suites));
14779 		sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite;
14780 	}
14781 
14782 	ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
14783 			(RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites)));
14784 	ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites,
14785 			RTE_DIM(sched_mode_suites));
14786 	ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
14787 	ret = unit_test_suite_runner(&ts);
14788 
14789 	for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
14790 		FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx,
14791 				(*sched_mode_suites[sched_i]),
14792 				RTE_DIM(blk_suites));
14793 		free(sched_mode_suites[sched_i]->unit_test_suites);
14794 	}
14795 	free(ts.unit_test_suites);
14796 	return ret;
14797 }
14798 
14799 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
14800 
14801 #endif
14802 
14803 static int
14804 test_cryptodev_dpaa2_sec(void)
14805 {
14806 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
14807 }
14808 
14809 static int
14810 test_cryptodev_dpaa_sec(void)
14811 {
14812 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
14813 }
14814 
14815 static int
14816 test_cryptodev_ccp(void)
14817 {
14818 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD));
14819 }
14820 
14821 static int
14822 test_cryptodev_octeontx(void)
14823 {
14824 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
14825 }
14826 
14827 static int
14828 test_cryptodev_octeontx2(void)
14829 {
14830 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
14831 }
14832 
14833 static int
14834 test_cryptodev_caam_jr(void)
14835 {
14836 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
14837 }
14838 
14839 static int
14840 test_cryptodev_nitrox(void)
14841 {
14842 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
14843 }
14844 
14845 static int
14846 test_cryptodev_bcmfs(void)
14847 {
14848 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
14849 }
14850 
14851 static int
14852 test_cryptodev_qat_raw_api(void)
14853 {
14854 	static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD);
14855 	int ret;
14856 
14857 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
14858 			"RAW API");
14859 	if (ret)
14860 		return ret;
14861 
14862 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
14863 	ret = run_cryptodev_testsuite(pmd_name);
14864 	global_api_test_type = CRYPTODEV_API_TEST;
14865 
14866 	return ret;
14867 }
14868 
14869 static int
14870 test_cryptodev_cn9k(void)
14871 {
14872 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
14873 }
14874 
14875 static int
14876 test_cryptodev_cn10k(void)
14877 {
14878 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
14879 }
14880 
14881 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
14882 		test_cryptodev_qat_raw_api);
14883 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
14884 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
14885 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
14886 	test_cryptodev_cpu_aesni_mb);
14887 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
14888 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
14889 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
14890 	test_cryptodev_cpu_aesni_gcm);
14891 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5);
14892 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
14893 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
14894 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
14895 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
14896 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
14897 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
14898 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
14899 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
14900 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
14901 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
14902 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
14903 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
14904 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
14905 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
14906 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);
14907 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k);
14908 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k);
14909